-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Python: fix(orchestrations): preserve multimodal content during agent handoff #7823
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
Changes from all commits
f79a409
a3a23c6
8b7eb22
ea2703d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,22 +28,41 @@ def clean_conversation_for_handoff(conversation: list[Message]) -> list[Message] | |
| Args: | ||
| conversation: Full conversation history, including tool-control content | ||
| Returns: | ||
| Cleaned conversation history with only text content, suitable for handoff routing | ||
| Cleaned conversation history with semantic multimodal content preserved, suitable for handoff routing | ||
| """ | ||
| ALLOWED_CONTENT_TYPES = { | ||
| "text", | ||
| "data", | ||
| "uri", | ||
| "hosted_file", | ||
| "hosted_vector_store", | ||
| } | ||
|
manideep-malyala marked this conversation as resolved.
|
||
|
|
||
| cleaned: list[Message] = [] | ||
| for msg in conversation: | ||
| # Keep only plain text history for handoff routing. Tool-control content | ||
| # Keep non-tool history for handoff routing. Tool-control content | ||
| # (function_call/function_result/approval payloads) is runtime-only and | ||
| # must not be replayed in future model turns. | ||
| text_parts = [content.text for content in msg.contents if content.type == "text" and content.text] | ||
| # TODO(@taochen): This is a simplified check that considers any non-text content as a tool call. | ||
| # We need to enhance this logic to specifically identify tool related contents. | ||
| if not text_parts: | ||
| retained_contents = [] | ||
| for content in msg.contents: | ||
| ctype = getattr(content, "type", "text") | ||
|
|
||
| # Skip disallowed types (tools, usage, errors, etc.) | ||
| if ctype not in ALLOWED_CONTENT_TYPES: | ||
| continue | ||
|
|
||
| # Skip empty text parts | ||
| if ctype == "text" and not getattr(content, "text", None): | ||
| continue | ||
|
|
||
| retained_contents.append(content) | ||
|
|
||
| if not retained_contents: | ||
| continue | ||
|
|
||
| msg_copy = Message( | ||
| role=msg.role, | ||
| contents=[" ".join(text_parts)], | ||
| contents=retained_contents, | ||
|
Comment on lines
63
to
+65
Contributor
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. What happens when an agent returns
Author
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. Evan Mattson (@moonbox3) Thanks for the feedback! I've updated the handoff logic to only retain multimodal content for |
||
| author_name=msg.author_name, | ||
| additional_properties=dict(msg.additional_properties) if msg.additional_properties else None, | ||
| ) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.