Skip to content

Runner.run_async ignores yield_user_message=True for composite-agent roots #8407

In review

Description

@sumedh-aerram

Composite roots persist the incoming user event but omit it from the public stream even when yield_user_message=True. Direct LlmAgent and node roots already honor the flag.

Run this offline reproduction; it uses no credentials or external services:

"""Offline: yield_user_message must work for composite roots too."""
import asyncio
import logging
import warnings
from google.adk.agents import LlmAgent, SequentialAgent
from google.adk.models.base_llm import BaseLlm
from google.adk.models.llm_response import LlmResponse
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.genai import types

class FakeModel(BaseLlm):
    model: str = 'offline'
    async def generate_content_async(self, llm_request, stream=False):
        yield LlmResponse(content=types.ModelContent(parts=[types.Part(text='reply')]))

async def main():
    for composite in (False, True):
        child = LlmAgent(name='child', model=FakeModel())
        agent = SequentialAgent(name='pipeline', sub_agents=[child]) if composite else child
        service = InMemorySessionService()
        session = await service.create_session(app_name='app', user_id='u')
        runner = Runner(app_name='app', agent=agent, session_service=service)
        events = [e async for e in runner.run_async(user_id='u', session_id=session.id,
            new_message=types.UserContent(parts=[types.Part(text='hello')]), yield_user_message=True)]
        saved = await service.get_session(app_name='app', user_id='u', session_id=session.id)
        print(f'{type(agent).__name__}: yielded={[e.author for e in events]} stored={[e.author for e in saved.events]}')
        await runner.close()

logging.disable(logging.CRITICAL)
warnings.simplefilter('ignore', DeprecationWarning)
asyncio.run(main())

Expected vs actual: With yield_user_message=True, both roots should yield and store authors ['user', 'child']. Before the fix, SequentialAgent yields only ['child'], though it stores both events. After the fix, both roots yield and store both events.

Environment: ADK main (2.15.x), Python 3.11.

Activity

  1. surajksharma07 commented on Dec 1, 2026

    @surajksharma07
    Collaborator

    @sumedh-aerram Reproduced on main (2.15.1), and it's not just SequentialAgent: ParallelAgent and LoopAgent roots also yield only ['child'] while storing ['user', 'child']. They all go through _run_with_trace, which never looks at yield_user_message.

    A workaround that held up for me: count session.events before the new/resumed invocation setup, then yield the newly stored user event(s) right before _exec_with_plugin starts, reusing the stored event so the id matches. LlmAgent and node roots stay as they are, and the default False is unchanged.

    Could you check whether that matches what you're seeing? Also, did you run into this in a real app, or spot it while reading the code? One gap on my side: a resume of an already-finished invocation returns early, so nothing gets yielded there.

    Since #8408 is already open, please give it a thorough test first (resume, state-delta-only resume, before_run short-circuit) before marking it ready.

  2. sumedh-aerram commented on Dec 1, 2026

    @sumedh-aerram
    Author

    @surajksharma07 Thanks for reproducing this. You're right that ParallelAgent and LoopAgent roots are affected too; all three go through _run_with_trace, and #8408 now covers them. It uses the approach you described: count session.events before the new or resumed invocation setup, then yield the stored user event(s) right before _exec_with_plugin, so the ids match. LlmAgent and node roots and the default False are unchanged.

    Tested for all three composite roots (LlmAgent and node roots as controls):

    • new turns, on_user_message_callback rewrites, and a before_run short-circuit (user event first, as on the node path);
    • resume with a function response, with no new input, and state-delta only, including a real pause through a long-running tool, where the yielded event id matches the stored one;
    • resume of a finished invocation: no model call, and only a stored delta event (if any) is yielded.

    Without the fix 21 of the 126 new cases fail; the full unit suite shows no new failures.

    One thing I noticed while testing, which happens on main too: once a composite child is waiting on a tool result, a state-delta-only resume applies the delta and then raises ValueError: No agent to transfer to for resuming agent from function response child. It's separate from this PR, so I left it alone; happy to open an issue if useful.

    To your question: I found this while reviewing the runner code paths, not in a production app.

  3. surajksharma07 commented on Dec 1, 2026

    @surajksharma07
    Collaborator

    Thanks @sumedh-aerram, 263a489 covers it, including the finished-invocation gap I mentioned. The yield now comes before the end_of_agents return, so a stored delta event still goes out and no model call happens. The change is small and in the right place: count before setup, yield the stored user events before _exec_with_plugin, same objects so the ids match. #8408 merges cleanly with main (30737fa), and main/2.15.1 still drop the user event for composite roots.

    On the ValueError: yes, please open an issue. I reproduced it on main with a SequentialAgent child paused on a LongRunningFunctionTool and then resumed with only state_delta={"k": "v"}. The delta is applied, then it raises "No agent to transfer to for resuming agent from function response child".

    It looks like the content-less user event from the delta-only resume becomes the last event on the branch. LlmAgent's resume lookup (llm_agent.py ~1022-1038) treats any user-authored last event as a function response, finds no matching call, and raises. Skipping user events that carry no function response there would probably fix it.

    I'll flag #8408 for review so the 2 pending workflows get approved. Nothing else needed from you on this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions