Skip to content

Python: Fix AG-UI reasoning role and multimodal media parsing to follow specification - #5389

Merged
Evan Mattson (moonbox3) merged 5 commits into
microsoft:mainfrom
moonbox3:agent/fix-5340-2
Apr 24, 2026
Merged

Python: Fix AG-UI reasoning role and multimodal media parsing to follow specification#5389
Evan Mattson (moonbox3) merged 5 commits into
microsoft:mainfrom
moonbox3:agent/fix-5340-2

Conversation

@moonbox3

Copy link
Copy Markdown
Contributor

Motivation and Context

The AG-UI adapter emitted role="assistant" on ReasoningMessageStartEvent instead of the spec-required role="reasoning", causing reasoning messages to render incorrectly in AG-UI clients. Additionally, _parse_multimodal_media_part read the deprecated "data" field instead of the current spec's "value" field, silently dropping all user-submitted multimodal media.

Fixes#5340

Description

Changed ReasoningMessageStartEvent role from "assistant" to "reasoning" in both the flow and non-flow code paths of _emit_text_reasoning in _run_common.py. Updated _parse_multimodal_media_part in _message_adapters.py to read source_dict.get("value") first (with fallback to "data" for backward compatibility) for base64/data source types and the unknown-type fallback branch. Bumped the ag-ui-protocol dependency from pined 0.1.13 to >=0.1.16,<0.2 to 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

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Note: PR autogenerated by moonbox3's agent

Copilotand others added 2 commits April 21, 2026 06:58
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.
Fixesmicrosoft#5340
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 21, 2026 07:04
@moonbox3Evan Mattson (moonbox3) added the python Usage: [Issues, PRs], Target: Python label Apr 21, 2026

@moonbox3Evan Mattson (moonbox3) left a comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 4 | Confidence: 96% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach


Automated review by moonbox3's agents

@moonbox3

Evan Mattson (moonbox3) commented Apr 21, 2026

Copy link
Copy Markdown
ContributorAuthor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/ag-ui/agent_framework_ag_ui
_message_adapters.py5834891%102–103, 112–115, 118–122, 124–129, 132, 141–147, 187, 329, 450–452, 506, 509, 511, 514, 517, 533, 550, 572, 672, 688–689, 760, 782, 852, 887–888, 956, 999
_run_common.py3071096%381–382, 388–393, 701–702
TOTAL29072345988%

Python Unit Test Overview

TestsSkippedFailuresErrorsTime
581530 💤0 ❌0 🔥1m 33s ⏱️

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.value first (with fallback to deprecated source.data) for base64/data/unknown source types.
  • Update ag-ui-protocol dependency (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
FileDescription
python/packages/ag-ui/agent_framework_ag_ui/_run_common.pySets reasoning message start role to "reasoning" in both flow and non-flow paths.
python/packages/ag-ui/agent_framework_ag_ui/_message_adapters.pyPrefers source.value over source.data when parsing multimodal media payloads.
python/packages/ag-ui/pyproject.tomlRelaxes ag-ui-protocol pin to >=0.1.16,<0.2 to pick up upstream fix.
python/uv.lockLocks ag-ui-protocol to 0.1.17 and updates metadata specifier accordingly.
python/packages/ag-ui/tests/ag_ui/test_run.pyUpdates existing reasoning role assertion and adds targeted flow/non-flow role regression tests.
python/packages/ag-ui/tests/ag_ui/test_message_adapters.pyAdds regression tests ensuring value is used (and preferred) for multimodal media parsing.
python/samples/04-hosting/foundry-hosted-agents/responses/02_local_tools/main.pyImport ordering adjustment (moves Annotated import into the stdlib section).
python/samples/02-agents/conversations/file_history_provider.pyAdds inline Pyright ignore for optional orjson import.
python/samples/02-agents/conversations/file_history_provider_conversation_persistence.pyAdds inline Pyright ignore for optional orjson import.
.maf-runtime-readyAdds a new repo-root marker file.

Comment thread.maf-runtime-ready Outdated

@moonbox3Evan Mattson (moonbox3) left a comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Fixesmicrosoft#5340
@Rickyneer

Richard (Rickyneer) commented Apr 22, 2026

Copy link
Copy Markdown

To: Evan Mattson (@moonbox3)
Thank you for the fast response to my issue.

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.
The place in which you patched the multimodal media parsing code, is not the only code that needs to be modified. An identical snippet of code that does the exact same thing (I recall in a function that is called _legacy_binary_parsing or something similar, also in the same file), which I think was for creating snapshot events, also looks for the wrong field "data" which should be field "value". This results in ag-ui compatible clients to crash when trying to ingest the snapshot event.
Maybe it's better to put both of these same code snippets behind a single function so it'll be easier to update in the future?
I hope to hear your opinion on this.

Thank you in advance.

@moonbox3

Copy link
Copy Markdown
ContributorAuthor

To: Evan Mattson (@moonbox3) Thank you for the fast response to my issue.

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. The place in which you patched the multimodal media parsing code, is not the only code that needs to be modified. An identical snippet of code that does the exact same thing (I recall in a function that is called _legacy_binary_parsing or something similar, also in the same file), which I think was for creating snapshot events, also looks for the wrong field "data" which should be field "value". This results in ag-ui compatible clients to crash when trying to ingest the snapshot event. Maybe it's better to put both of these same code snippets behind a single function so it'll be easier to update in the future? I hope to hear your opinion on this.

Thank you in advance.

Thanks for the callout here, Richard (@Rickyneer). You're right that we can improve this. Making the fix now.

Resolve conflicts in:
- python/packages/ag-ui/pyproject.toml: keep ag-ui-protocol>=0.1.16,<0.2 (the
fix this PR ships) alongside upstream's agent-framework-core>=1.1.1 bump.
- python/packages/ag-ui/tests/ag_ui/test_run.py: keep both TestReasoningEventRole
and the new session_id tests from upstream.
The snapshot normalization path used a second copy of the multimodal source
parsing logic that still read the deprecated 'data' field. When clients sent
base64 media with source={"type": "base64", "value": ...}, the snapshot event
emitted by the server dropped the payload, causing AG-UI-compatible clients
to crash on ingest.
Extract the shared source-field extraction into _extract_multimodal_source_fields
so both _parse_multimodal_media_part and the snapshot _legacy_binary_part stay
in sync with the AG-UI spec. Add snapshot-path regression tests covering
value-only, value-preferred-over-data, and the legacy data-field fallback.
Addresses review feedback on microsoft#5389 from @Rickyneer.
@moonbox3
Evan Mattson (moonbox3) added this pull request to the merge queueApr 24, 2026
Merged via the queue into microsoft:main with commit 932ceddApr 24, 2026
33 checks passed
Evan Mattson (moonbox3) added a commit to moonbox3/agent-framework that referenced this pull request Apr 24, 2026
Previous commit incorrectly renamed the [1.1.1] header to [1.2.0], which
wiped the historical 1.1.1 entries and wrongly attributed them to 1.2.0.
This restores [1.1.1] to its origin/main content and adds a new [1.2.0]
section above containing only the commits in python-1.1.1..HEAD:
- microsoft#4238 functional workflow API
- microsoft#5142 GitHub Copilot OpenTelemetry
- microsoft#2403 A2A bridge support
- microsoft#5070 oauth_consent_request events in Foundry clients
- microsoft#5447 FoundryAgent hosted agent sessions
- microsoft#5459 hosting server dependency upgrade + types
- microsoft#5389 AG-UI reasoning/multimodal parsing fix
- microsoft#5440 stop [TOOLBOXES] warning spam
- microsoft#5455 user agent prefix fix
Also corrects the [1.2.0] compare base to python-1.1.1 (not 1.1.0) and
adds the missing [1.1.1] reference link.
Evan Mattson (moonbox3) added a commit that referenced this pull request Apr 24, 2026
* Bump Python package versions for 1.2.0 release
Released tier bumps 1.1.1 -> 1.2.0 (core, openai, foundry, root) to
reflect additive public APIs landed since 1.1.0: functional workflow API
(#4238) and FunctionTool SKIP_PARSING sentinel (#5424). All beta packages
stamped 1.0.0b260424, alpha packages 1.0.0a260424. All 26 non-core
agent-framework-core floors raised to >=1.2.0,<2. CHANGELOG consolidates
the never-tagged 1.1.1 entries with the post-merge additions into [1.2.0].
* Update CHANGELOG footer links for 1.2.0
Advance [Unreleased] comparison base from python-1.1.0 to python-1.2.0
and add a [1.2.0] reference link comparing python-1.1.0...python-1.2.0
so the heading links resolve correctly.
* Fix CHANGELOG: restore [1.1.1] section and add proper [1.2.0]
Previous commit incorrectly renamed the [1.1.1] header to [1.2.0], which
wiped the historical 1.1.1 entries and wrongly attributed them to 1.2.0.
This restores [1.1.1] to its origin/main content and adds a new [1.2.0]
section above containing only the commits in python-1.1.1..HEAD:
- #4238 functional workflow API
- #5142 GitHub Copilot OpenTelemetry
- #2403 A2A bridge support
- #5070 oauth_consent_request events in Foundry clients
- #5447 FoundryAgent hosted agent sessions
- #5459 hosting server dependency upgrade + types
- #5389 AG-UI reasoning/multimodal parsing fix
- #5440 stop [TOOLBOXES] warning spam
- #5455 user agent prefix fix
Also corrects the [1.2.0] compare base to python-1.1.1 (not 1.1.0) and
adds the missing [1.1.1] reference link.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pythonUsage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: AG-UI reasoning and multimodal media parsing doesn't correctly follow the specification

6 participants

@moonbox3@Rickyneer@TaoChenOSU@eavanvalkenburg@giles17