-
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
Merged
jhills20
merged 22 commits into
main
from
codex/add-nest_handoff_history-field-and-functionality
Nov 17, 2025
+795
−68
Merged
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
e895a77
Nest handoff history by default
jhills20 94447af
Document nested handoff history defaults
jhills20 98d154c
Improve nested handoff conversation history
jhills20 52f0a1e
Remove metadata from nested handoff history
jhills20 71df74b
Fix mypy issues in nested handoff helper
jhills20 17aa135
Add handoff history mapper
jhills20 6d7f9e4
Merge branch 'main' into codex/add-nest_handoff_history-field-and-fun…
jhills20 3364202
fixes
jhills20 b22eeb2
update changelog
jhills20 fff4d34
update default
jhills20 c6e0f50
fix for lint
jhills20 f3c7048
fix tests
jhills20 19a7cf8
lint updates
jhills20 411d396
update
jhills20 0276722
ruff
jhills20 8746b81
rufff
jhills20 3694c7e
more linting
jhills20 298ef8a
fix
jhills20 adf0c66
Update release.md
jhills20 0a70cf4
Merge branch 'main' into codex/add-nest_handoff_history-field-and-fun…
jhills20 6590319
Update release.md
jhills20 7fe0da0
Merge branch 'main' into codex/add-nest_handoff_history-field-and-fun…
jhills20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,7 @@ | |
| UserError, | ||
| ) | ||
| from .guardrail import InputGuardrail, InputGuardrailResult, OutputGuardrail, OutputGuardrailResult | ||
| from .handoffs import Handoff, HandoffInputData | ||
| from .handoffs import Handoff, HandoffInputData, nest_handoff_history | ||
| from .items import ( | ||
| HandoffCallItem, | ||
| HandoffOutputItem, | ||
|
|
@@ -998,8 +998,14 @@ async def execute_handoffs( | |
| input_filter = handoff.input_filter or ( | ||
| run_config.handoff_input_filter if run_config else None | ||
| ) | ||
| if input_filter: | ||
| logger.debug("Filtering inputs for handoff") | ||
| handoff_nest_setting = handoff.nest_handoff_history | ||
| should_nest_history = ( | ||
| handoff_nest_setting | ||
| if handoff_nest_setting is not None | ||
| else run_config.nest_handoff_history | ||
| ) | ||
| handoff_input_data: HandoffInputData | None = None | ||
| if input_filter or should_nest_history: | ||
| handoff_input_data = HandoffInputData( | ||
| input_history=tuple(original_input) | ||
| if isinstance(original_input, list) | ||
|
|
@@ -1008,6 +1014,17 @@ async def execute_handoffs( | |
| new_items=tuple(new_step_items), | ||
| run_context=context_wrapper, | ||
| ) | ||
|
|
||
| if input_filter and handoff_input_data is not None: | ||
| 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, | ||
| ) | ||
|
Comment on lines
+1233
to
+1241
Collaborator
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. weird syntax - also can you use f-strings and get rid of getattr? |
||
| if not callable(input_filter): | ||
| _error_tracing.attach_error_to_span( | ||
| span_handoff, | ||
|
|
@@ -1037,6 +1054,18 @@ async def execute_handoffs( | |
| ) | ||
| pre_step_items = list(filtered.pre_handoff_items) | ||
| new_step_items = list(filtered.new_items) | ||
| elif should_nest_history and handoff_input_data is not None: | ||
| nested = nest_handoff_history( | ||
| handoff_input_data, | ||
| history_mapper=run_config.handoff_history_mapper, | ||
| ) | ||
| original_input = ( | ||
| nested.input_history | ||
| if isinstance(nested.input_history, str) | ||
| else list(nested.input_history) | ||
| ) | ||
| pre_step_items = list(nested.pre_handoff_items) | ||
| new_step_items = list(nested.new_items) | ||
|
|
||
| return SingleStepResult( | ||
| original_input=original_input, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from ..handoffs import HandoffInputData | ||
| from ..handoffs import ( | ||
| HandoffInputData, | ||
| default_handoff_history_mapper, | ||
| nest_handoff_history, | ||
| ) | ||
| from ..items import ( | ||
| HandoffCallItem, | ||
| HandoffOutputItem, | ||
|
|
@@ -13,6 +17,12 @@ | |
|
|
||
| """Contains common handoff input filters, for convenience. """ | ||
|
|
||
| __all__ = [ | ||
| "remove_all_tools", | ||
| "nest_handoff_history", | ||
| "default_handoff_history_mapper", | ||
| ] | ||
|
Comment on lines
+20
to
+24
Collaborator
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. can remove this, not super useful |
||
|
|
||
|
|
||
| def remove_all_tools(handoff_input_data: HandoffInputData) -> HandoffInputData: | ||
| """Filters out all tool items: file search, web search and function calls+output.""" | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.