astream() yields Event objects as they occur:
Sub-agent streaming via AgentTool
When usingAgentTool, sub-agent events stream through the parent in real-time via ctx.event_callback. Events carry branch and agent_name fields so you can distinguish which sub-agent is producing output:
How it works
- Before tool execution,
LlmAgentcreates anasyncio.Queueand setsctx.event_callback = queue.put_nowaiton the tool context. AgentToolcallsctx.event_callback(event)for each child event as it streams.LlmAgentyields events from the queue concurrently while tools run, so events appear in real-time.- The
event_callbackpropagates throughctx.derive(), so nested sub-agents also push events up to the root.
ctx.event_callback to push events — it’s not limited to AgentTool.