fix: preserve multimodal content during handoffs with nest_handoff_hi… #2233
+440
−2
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.
Fix: Preserve multimodal content during same-turn handoffs
Fix #2220
Summary
This PR fixes an issue where multimodal content (images, files, audio) uploaded by users was being lost when the agent performed a handoff to another agent in the same turn with
nest_handoff_history=True(the default behavior).Problem: When a user uploaded an image and the first agent handed off to a specialist agent, the target agent lost access to the uploaded image because the
nest_handoff_historyfunction converted all content to a plain text summary, discarding the multimodal data.Solution: Modified
nest_handoff_historyto:Changes
Core Fix
_MULTIMODAL_CONTENT_TYPESconstant to identify multimodal types_PRESERVED_MULTIMODAL_MARKERconstant to mark preserved messages and prevent duplicationdefault_handoff_history_mapper()to extract, preserve, and carry forward multimodal content_extract_multimodal_content()function to scan user messages for images, files, and audio_collect_preserved_multimodal_content()function to collect already-preserved content from previous handoffs_stringify_content_list()function to provide human-readable summaries of multimodal contentTests
Testing
✅ All 20 existing extension filter tests pass
✅ All 14 handoff tool tests pass
✅ All 17 run step processing tests pass
✅ All 7 new multimodal preservation tests pass (including chained handoffs test)
✅ Code passes
ruff formatandruff check✅ Code passes
mypy --ignore-missing-imports --no-warn-unused-ignoresTest Plan:
pytest tests/test_extension_filters.py -vpytest tests/test_handoff_tool.py tests/test_run_step_processing.py -vruff format && ruff checkmypy src/agents/handoffs/history.py tests/test_extension_filters.py --ignore-missing-importsImpact
Backward Compatible: Yes. Text-only conversations work exactly as before. Multimodal content is now additionally preserved when present.
Example Usage:
Related Issue
Resolves the issue reported about multimodal content being lost during same-turn handoffs with
nest_handoff_history=True.Checklist
ruff formatruff checkmypy