Skip to content

Added support for "return" handoffs (#1) #869

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

niv-hertz
Copy link
Contributor

Related to issue: #847

@niv-hertz
Copy link
Contributor Author

Could also solve the problem specified in: #858

@rm-openai - Would love your review

Copy link
Collaborator

@rm-openai rm-openai left a comment

Choose a reason for hiding this comment

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

I thought about this for a while, and ultimately I think this doesn't belong in handoffs because the definition of a handoff is something that takes over control. Whether it chooses to return control should be up to the new agent.

That said, the problem identified is a real one. I think the right way to do it is via a FunctionTool that also receives the full conversation history. i.e. you do something like

@function_tool
def my_function(context, history, ... other args):

That function could then use an agent or not, but either way it has access to the conversation history.

Thoughts?

EDIT: Also, this should be really easy now bc of the ToolContext you added - can just add a history field with all the prev items in there.

@niv-hertz
Copy link
Contributor Author

niv-hertz commented Jun 16, 2025

@rm-openai - Generally, I agree - this was actually my goto as well. There are, however two gaps with that implementation:

  1. This doesn't affect the turns counting. Which you may want to control on a general scope, instead of on a per-function call level.
  2. There's no easy support for streaming. One of the huge benefits of handing off, is that streaming is pretty much covered for you.

If you have any good solution for either of these with the function calls \ agent as tool approach, I'd love your input :)

EDIT: I also thought about using the existing handoffs mechanism, and as you suggested, giving the new agent the choice of whether to return control or not. But that seemed unnatural to me for two reasons:

  1. The sub-agent is not aware of the wider instructions that the orchestrator has, so the choice of whether to return control or not, is not one it can properly make.
  2. The Handoff object requires a reference to the agent (in the _on_invoke_handoff function), and the agent also contains a reference to the Handoff object. So if you want two agents to be able to handoff to each other, you're forced to implement some sort of circular reference (or hack around it) which is not good practice.

EDIT 2: Another option is to support something parallel to Handoffs, like SupervisedHandoff/Assignment/Sub-Workers

@niv-hertz niv-hertz requested a review from rm-openai June 18, 2025 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants