Summary
When using agent.as_tool(stream=MemoryStream()) to wrap a sub-agent as a tool, the MemoryStream passed via the stream parameter does not capture the sub-agent's events. After the run completes, await stream.history.get_events() returns an empty list for the sub-agent streams, while the parent agent's stream correctly records all events (including the ToolCallEvents for the sub-agent invocations).
Reproduction
See notebooks/04_events.ipynb — the tutorial creates separate MemoryStream instances for a surveyor and critic sub-agent:
surveyor_stream = MemoryStream()
critic_stream = MemoryStream()
surveyor = Agent("surveyor", config=config, tools=[exa], prompt="...")
critic = Agent("critic", config=config, prompt="...")
researcher = Agent(
"researcher",
config=config,
tools=[
exa,
surveyor.as_tool(description="Survey literature", stream=surveyor_stream),
critic.as_tool(description="Evaluate a hypothesis", stream=critic_stream),
],
...
)
reply = await researcher.ask("...", stream=research_stream)
# Parent stream has events ✓
# surveyor_stream and critic_stream are empty ✗
Question
Is this the intended behavior? The stream parameter on as_tool() suggests it should capture the sub-agent's events, but it may serve a different purpose (e.g., persistent_stream for cross-call history reuse rather than event capture). If this is by design, it would help to clarify in the docs what the stream parameter does vs. how to actually observe sub-agent events.
Summary
When using
agent.as_tool(stream=MemoryStream())to wrap a sub-agent as a tool, theMemoryStreampassed via thestreamparameter does not capture the sub-agent's events. After the run completes,await stream.history.get_events()returns an empty list for the sub-agent streams, while the parent agent's stream correctly records all events (including theToolCallEvents for the sub-agent invocations).Reproduction
See
notebooks/04_events.ipynb— the tutorial creates separateMemoryStreaminstances for a surveyor and critic sub-agent:Question
Is this the intended behavior? The
streamparameter onas_tool()suggests it should capture the sub-agent's events, but it may serve a different purpose (e.g.,persistent_streamfor cross-call history reuse rather than event capture). If this is by design, it would help to clarify in the docs what thestreamparameter does vs. how to actually observe sub-agent events.