-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: Implement agent handoff tracking to skip after_agent_callback #4255
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -297,8 +297,10 @@ async def run_async( | |
| if ctx.end_invocation: | ||
| return | ||
|
|
||
| if event := await self._handle_after_agent_callback(ctx): | ||
| yield event | ||
| # Skip after_agent_callback if the agent has handed off to another agent | ||
| if not ctx.agent_handoff_occurred: | ||
| if event := await self._handle_after_agent_callback(ctx): | ||
| yield event | ||
|
Comment on lines
+301
to
+303
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| @final | ||
| async def run_live( | ||
|
|
@@ -327,8 +329,10 @@ async def run_live( | |
| async for event in agen: | ||
| yield event | ||
|
|
||
| if event := await self._handle_after_agent_callback(ctx): | ||
| yield event | ||
| # Skip after_agent_callback if the agent has handed off to another agent | ||
| if not ctx.agent_handoff_occurred: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to my comment in A possible solution is to reset this flag at the beginning of each agent's run. You could add |
||
| if event := await self._handle_after_agent_callback(ctx): | ||
| yield event | ||
|
Comment on lines
+333
to
+335
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| async def _run_async_impl( | ||
| self, ctx: InvocationContext | ||
|
|
||
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.
There's a potential logic issue here. When
agent1hands off toagent2,ctx.agent_handoff_occurredis set toTrue. This correctly skips theafter_agent_callbackforagent1. However,agent2inherits the context with this flag set toTrue, so itsafter_agent_callbackwill also be skipped, which is likely unintended. The callback should only be skipped for the agent that initiates the handoff.A possible solution is to reset this flag at the beginning of each agent's run. You could add
ctx.agent_handoff_occurred = Falseat the start of therun_asyncmethod in this file, afterctxis created. Since this change is outside the current diff, I cannot provide a direct code suggestion for it.