Skip to content

Conversation

@ihower
Copy link
Contributor

@ihower ihower commented Dec 11, 2025

Based on PR #2169. I propose an alternative API design.

The on_stream API is updated so it no longer wrap events in AgentToolStreamEvent.
It now receives the raw StreamEvent and the caller agent’s tool invocation ToolContext.

To let on_stream know which agent and tool triggered the nested run, ToolContext is extended to include a new caller_agent field.

Reasons

  • Agents do not need to know in advance that they might be used as sub-agents.
  • The same on_stream handler function can work for both direct runs and agent-as-tool runs. In other words, the same streaming code for an agent can be reused whether you run the agent on its own or invoke it as a sub-agent. If needed, the caller_tool_context also lets developers know that the stream is happening inside another agent’s tool invocation and provides access to the caller agent’s context information.
  • Passing the raw StreamEvent keeps the API simpler and removes the need for the extra AgentToolStreamEvent wrapper.

The example agents_as_tools_streaming.py now shows two cases:
Scenario 1 (direct streaming) and Scenario 2 (agent-as-tool streaming).

@ihower ihower changed the title feat: Add on_stream to agents as tools (alternate API design) feat: Add on_stream to agents as tools (proposed alternative API design) Dec 11, 2025
"""


class AgentToolStreamEvent(TypedDict):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this suggestion, but I think having a single dict enables us to enhance the argument list more easily. This object currently has only agent's name and tool's call_id but these properties could be richer to have other metadata as well (like Rohan mentioned having Agent instead in my PR).

@seratch seratch added enhancement New feature or request feature:core labels Dec 12, 2025
@ihower ihower closed this Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request feature:core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants