Python: Fix AG-UI reasoning role and multimodal media parsing to follow specification#5389
Python: Fix AG-UI reasoning role and multimodal media parsing to follow specification#5389moonbox3 wants to merge 3 commits intomicrosoft:mainfrom
Conversation
Fix two spec compliance issues in the AG-UI integration: 1. ReasoningMessageStartEvent now uses role='reasoning' instead of role='assistant', matching the AG-UI specification for reasoning messages. 2. _parse_multimodal_media_part now reads the 'value' field from source dicts (with fallback to 'data' for backward compatibility), matching the current AG-UI InputContentSource specification. Bump ag-ui-protocol dependency from ==0.1.13 to >=0.1.16,<0.2 to pick up the SDK fix that accepts role='reasoning' in ReasoningMessageStartEvent. Fix pre-existing pyright reportMissingImports errors for orjson in sample files, and fix import ordering in foundry-hosted-agents sample. Fixes microsoft#5340 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ow specification Fixes microsoft#5340
moonbox3
left a comment
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 96% | Result: All clear
Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach
Automated review by moonbox3's agents
Python Test Coverage Report •
Python Unit Test Overview
|
|||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
Fixes the Python AG-UI adapter to align with the AG-UI specification for reasoning event roles and multimodal media payload parsing, and updates the AG-UI protocol dependency/tests accordingly.
Changes:
- Emit
ReasoningMessageStartEvent(role="reasoning")(instead of"assistant") in both streaming and non-streaming reasoning paths. - Parse multimodal media payloads from
source.valuefirst (with fallback to deprecatedsource.data) for base64/data/unknown source types. - Update
ag-ui-protocoldependency (and lockfile) and add regression tests for both fixes.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
python/packages/ag-ui/agent_framework_ag_ui/_run_common.py |
Sets reasoning message start role to "reasoning" in both flow and non-flow paths. |
python/packages/ag-ui/agent_framework_ag_ui/_message_adapters.py |
Prefers source.value over source.data when parsing multimodal media payloads. |
python/packages/ag-ui/pyproject.toml |
Relaxes ag-ui-protocol pin to >=0.1.16,<0.2 to pick up upstream fix. |
python/uv.lock |
Locks ag-ui-protocol to 0.1.17 and updates metadata specifier accordingly. |
python/packages/ag-ui/tests/ag_ui/test_run.py |
Updates existing reasoning role assertion and adds targeted flow/non-flow role regression tests. |
python/packages/ag-ui/tests/ag_ui/test_message_adapters.py |
Adds regression tests ensuring value is used (and preferred) for multimodal media parsing. |
python/samples/04-hosting/foundry-hosted-agents/responses/02_local_tools/main.py |
Import ordering adjustment (moves Annotated import into the stdlib section). |
python/samples/02-agents/conversations/file_history_provider.py |
Adds inline Pyright ignore for optional orjson import. |
python/samples/02-agents/conversations/file_history_provider_conversation_persistence.py |
Adds inline Pyright ignore for optional orjson import. |
.maf-runtime-ready |
Adds a new repo-root marker file. |
moonbox3
left a comment
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 94% | Result: All clear
Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach
Automated review by moonbox3's agents
Address PR review feedback: the .maf-runtime-ready file is not referenced anywhere in the repo and was left over from automation. Fixes microsoft#5340
408b9d0 to
372f31f
Compare
|
To: @moonbox3 I do want to note that this does not fix the issue completely and with this fix, another part of the bug has popped up. Thank you in advance. |
Motivation and Context
The AG-UI adapter emitted
role="assistant"onReasoningMessageStartEventinstead of the spec-requiredrole="reasoning", causing reasoning messages to render incorrectly in AG-UI clients. Additionally,_parse_multimodal_media_partread the deprecated"data"field instead of the current spec's"value"field, silently dropping all user-submitted multimodal media.Fixes #5340
Description
Changed
ReasoningMessageStartEventrole from"assistant"to"reasoning"in both the flow and non-flow code paths of_emit_text_reasoningin_run_common.py. Updated_parse_multimodal_media_partin_message_adapters.pyto readsource_dict.get("value")first (with fallback to"data"for backward compatibility) for base64/data source types and the unknown-type fallback branch. Bumped theag-ui-protocoldependency from pined0.1.13to>=0.1.16,<0.2to pick up the upstream SDK fix for the reasoning role type. Added targeted regression tests for both the reasoning role and multimodal value-field parsing.Contribution Checklist