fix: add reasoning-stripping handoff helpers#2749
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d847b32ccf
ℹ️ 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".
| filtered_pre_handoff_items = _remove_reasoning_from_items(handoff_input_data.pre_handoff_items) | ||
| filtered_new_items = _remove_reasoning_from_items(handoff_input_data.new_items) |
There was a problem hiding this comment.
Strip assistant IDs from message run items after reasoning removal
remove_reasoning_items removes ReasoningItem entries from new_items but never sanitizes assistant message IDs in those same run items. In handoffs where a turn emits both reasoning and an assistant message, execute_handoffs uses filtered.new_items for the next model input, and MessageOutputItem.to_input_item() preserves the message id; after reasoning is dropped, that ID can still be orphaned and trigger the Responses API validation error this helper is intended to avoid. The same orphaned-ID cleanup needs to be applied to message run items (or to derived input_items) when reasoning is removed from new_items.
Useful? React with 👍 / 👎.
| return HandoffInputData( | ||
| input_history=filtered_history, | ||
| pre_handoff_items=filtered_pre_handoff_items, | ||
| new_items=filtered_new_items, | ||
| run_context=handoff_input_data.run_context, |
There was a problem hiding this comment.
Preserve input_items when constructing filtered handoff data
remove_reasoning_items constructs a fresh HandoffInputData but does not carry over input_items. If this helper is composed with another filter that sets input_items (the field that controls what is sent to the next model while keeping full session history), this function silently resets it to None, causing the runtime to fall back to new_items and undo the caller’s filtering intent. Return via handoff_input_data.clone(...) or explicitly pass through input_items.
Useful? React with 👍 / 👎.
|
The issue is resolved by #2700 |
Summary
This PR adds built-in helpers for handing off from reasoning models to non-reasoning models.
Changes:
strip_reasoning_items(...)to removereasoningitems from plain input historyremove_reasoning_items(...)as a reusable handoff filterWhy
Issue #569 reports failures when reasoning-model output history is passed to a non-reasoning model.
This PR takes the narrow, low-risk path discussed in the issue by adding built-in filtering helpers rather than changing default history conversion behavior across the SDK.
Testing
ruff check src/agents/extensions/handoff_filters.py tests/test_extension_filters.pyPYTHONPATH=src /Users/lvxianping/project/llm_study/bug_ass/openai-agents-python/.venv/bin/python -m pytest tests/test_extension_filters.py -qRelated