-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: Add on_stream to agents as tools #2169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
src/agents/agent.py
Outdated
| event: StreamEvent | ||
| """The streaming event from the nested agent run.""" | ||
|
|
||
| agent_name: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of agent_name, why not pass the Agent object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this is true. i will revisit the properties in this object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed by 7f1672a
| maybe_result = on_stream(payload) | ||
| if inspect.isawaitable(maybe_result): | ||
| await maybe_result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be kinda bad since on_stream will block you from going to the next event. fine for now, but we should consider a queue based pattern where we write to a queue from here and the consumer reads from the queue, and we aren't blocking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call; actually i made these executions async in the TS SDK. so will make this more efficient and consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improved by 94d2239
573e483 to
24088d3
Compare
24088d3 to
94d2239
Compare
|
@codex review this PR again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/agents/agent.py
Outdated
| payload: AgentToolStreamEvent = { | ||
| "event": event, | ||
| "agent": self, | ||
| "tool_call": getattr(context, "tool_call", None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use current agent for tool stream events
When a tool-invoked agent hands off to another agent, run_result.stream_events() will emit AgentUpdatedStreamEvent and subsequent events belong to the new agent, but the payload always sets agent to self (the original tool agent). In runs that include handoffs, this misattributes events and can break on_stream handlers that route or label output by the emitting agent, because they will never see the actual current agent after a handoff. Consider populating agent from the streaming run state (e.g., run_result.current_agent or updates from AgentUpdatedStreamEvent) instead of the initial agent.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed by dbcb6e3
|
@codex review again |
|
Codex Review: Didn't find any major issues. Hooray! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This pull request adds a new feature equivalent to openai/openai-agents-js#749