-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(handoffs): filter duplicate items from model input when nest_handoff_history is enabled #2254
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
…off_history is enabled (openai#2171)
…ation-2171 fix(handoffs): filter duplicate items from model input when nest_handoff_history is enabled (openai#2171)
|
@seratch Please review for any fixes |
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
openai-agents-python/src/agents/run.py
Lines 747 to 751 in effc877
| guardrail_result.output.tripwire_triggered | |
| for guardrail_result in input_guardrail_results | |
| ): | |
| await self._save_result_to_session( | |
| session, [], turn_result.new_step_items |
For handoffs, new_step_items now holds the filtered model input while session_step_items keeps the full turn, but _save_result_to_session is still called with turn_result.new_step_items. With nest_handoff_history enabled this means tool call/output items removed from input_items are never persisted to the session even though they’re retained in session_step_items, contradicting the stated goal that session history remains unfiltered.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Thanks for sharing this. We're going to move the nested handoff feature to an opt-in starting in 0.7.0: #2211 We'll continue improving the quality, but for now, I'll focus on completing other priorities. |
|
Makes sense! Thanks for the context |
Fixes #2171
Problem
When
nest_handoff_historyis enabled, the next agent receives duplicate conversation items:Before this fix:
<CONVERSATION HISTORY>containing tool calls as textfunction_callitems (duplicated)function_call_outputitems (duplicated)This causes the model to see the same information twice, wasting tokens and potentially causing confusion.
Solution
Introduced separation between items sent to the model vs items preserved for session history:
function_callandfunction_call_outputitems already in the summaryKey changes:
input_itemsfield toHandoffInputDatafor filtered model inputsession_step_itemsfield toSingleStepResultfor full session historygenerated_itemsproperty to use session items when availableBehavior
Testing