-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Nest handoff history by default #1996
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?
Nest handoff history by default #1996
Conversation
rm-openai
left a comment
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.
All of kaz's feedback seems right. In addition, I'd say two major things:
- This setting should be on the
Handoffobject - Since you're updating the default, this is a breaking change, so please update the changelog.
jhills20
left a comment
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.
moved to Handoff, added handoff history .py file for non extension parts of handoff filter, added changelog
| - By default handoff history is now packaged into a single assistant message instead of exposing the raw user/assistant turns, giving downstream agents a concise, predictable recap | ||
| - The existing single-message handoff transcript now by default starts with "For context, here is the conversation so far between the user and the previous agent:" before the `<CONVERSATION HISTORY>` block, so downstream agents get a clearly labeled recap |
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.
we;ve release 0.5.0 so you'll need to move this to a 0.6.0 section
| filter_name = getattr(input_filter, "__qualname__", repr(input_filter)) | ||
| from_agent = getattr(agent, "name", agent.__class__.__name__) | ||
| to_agent = getattr(new_agent, "name", new_agent.__class__.__name__) | ||
| logger.debug( | ||
| "Filtering handoff inputs with %s for %s -> %s", | ||
| filter_name, | ||
| from_agent, | ||
| to_agent, | ||
| ) |
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.
weird syntax - also can you use f-strings and get rid of getattr?
| __all__ = [ | ||
| "remove_all_tools", | ||
| "nest_handoff_history", | ||
| "default_handoff_history_mapper", | ||
| ] |
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.
can remove this, not super useful
|
|
||
| When a handoff occurs, it's as though the new agent takes over the conversation, and gets to see the entire previous conversation history. If you want to change this, you can set an [`input_filter`][agents.handoffs.Handoff.input_filter]. An input filter is a function that receives the existing input via a [`HandoffInputData`][agents.handoffs.HandoffInputData], and must return a new `HandoffInputData`. | ||
|
|
||
| By default the runner now collapses the prior transcript into a single assistant summary message (see [`RunConfig.nest_handoff_history`][agents.run.RunConfig.nest_handoff_history]). The summary appears inside a `<CONVERSATION HISTORY>` block that keeps appending new turns when multiple handoffs happen during the same run. You can provide your own mapping function via [`RunConfig.handoff_history_mapper`][agents.run.RunConfig.handoff_history_mapper] to replace the generated message without writing a full `input_filter`. That default only applies when neither the handoff nor the run supplies an explicit `input_filter`, so existing code that already customizes the payload (including the examples in this repository) keeps its current behavior without changes. You can override the nesting behaviour for a single handoff by passing `nest_handoff_history=True` or `False` to [`handoff(...)`][agents.handoffs.handoff], which sets [`Handoff.nest_handoff_history`][agents.handoffs.Handoff.nest_handoff_history]. If you just need to change the wrapper text for the generated summary, call [`set_conversation_history_wrappers`][agents.handoffs.set_conversation_history_wrappers] (and optionally [`reset_conversation_history_wrappers`][agents.handoffs.reset_conversation_history_wrappers]) before running your agents. |
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.
to make merging the code changes easier, can you make a separate pull request for document changes? with this, we can merge code first, and then merge document changes after thre release including the changes.
Summary
nest_handoff_historyflag toRunConfigand call a new helper that condenses the prior transcript into a developer-role summary when handing offTesting
uv run pytest tests/test_extension_filters.pyuv run pytest tests/test_agent_runner.py -k handoffuv run pytest tests/test_agent_runner_streamed.py -k handoffhttps://chatgpt.com/codex/tasks/task_i_68ff73bda0f4832496f3d1fa9103905f