Skip to content

Python: fix(ag-ui): preserve streamed text message id#6269

Merged
eavanvalkenburg merged 2 commits into
microsoft:mainfrom
cyphercodes:fix/ag-ui-snapshot-text-id
Jul 8, 2026
Merged

Python: fix(ag-ui): preserve streamed text message id#6269
eavanvalkenburg merged 2 commits into
microsoft:mainfrom
cyphercodes:fix/ag-ui-snapshot-text-id

Conversation

@cyphercodes

Copy link
Copy Markdown
Contributor

Motivation and Context

Fixes #6266.

Mixed AG-UI snapshots with both pending tool calls and streamed trailing text were assigning the streamed text message_id to the tool-call-only assistant message. The text message then received a generated ID, which broke reconciliation for the already-streamed text.

Description

When a snapshot contains both tool calls and accumulated text, this changes the tool-call-only assistant message to use a generated ID and preserves flow.message_id for the text assistant message.

A regression test covers the mixed tool-call/text snapshot and verifies that the text message keeps the streamed message ID while the tool-call message remains distinct.

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.

Validation:

  • uv run --group dev pytest packages/ag-ui/tests/ag_ui/test_run.py::TestBuildMessagesSnapshot -q
  • uv run --group dev poe syntax -P ag-ui
  • uv run --group dev poe pyright -P ag-ui
  • uv run --group dev poe test -P ag-ui

Copilot AI review requested due to automatic review settings June 2, 2026 15:53
@moonbox3 moonbox3 added the python Usage: [Issues, PRs], Target: Python label Jun 2, 2026

Copilot AI 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

Note

Copilot was unable to run its full agentic suite in this review.

Updates message snapshot generation so that, when both tool calls and streamed text are present, the streamed text message keeps the original flow.message_id while the tool-call message gets a different ID.

Changes:

  • Adjust _build_messages_snapshot message ID assignment to preserve streamed text message IDs in mixed tool-call/text snapshots.
  • Add a regression test covering the mixed tool-call + text case to ensure IDs are preserved/isolated correctly.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py Changes assistant/tool-call vs assistant/text message ID selection logic in snapshots.
python/packages/ag-ui/tests/ag_ui/test_run.py Adds a test asserting streamed text message ID is preserved when tool calls are also present.

Comment thread python/packages/ag-ui/tests/ag_ui/test_run.py
Comment thread python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py
@github-actions github-actions Bot changed the title fix(ag-ui): preserve streamed text message id Python: fix(ag-ui): preserve streamed text message id Jun 2, 2026
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/ag-ui/agent_framework_ag_ui
   _agent_run.py7858888%175–182, 229–230, 237, 346, 350, 352, 369, 396–397, 518, 521, 523, 538, 574, 576, 578, 581–585, 599, 607–612, 621–622, 659–662, 673, 681, 712, 727, 741, 753, 800–804, 868, 874–875, 880, 884–885, 935–937, 949–951, 1049, 1057, 1116, 1146–1147, 1314, 1360, 1377, 1394–1395, 1402, 1499, 1524, 1532, 1534, 1537, 1543, 1598, 1601, 1611–1612, 1619, 1665
TOTAL44416533887% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
8799 33 💤 0 ❌ 0 🔥 2m 19s ⏱️

@moonbox3

moonbox3 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

@cyphercodes thanks for the fix. Please make sure you accept the CLA.

@moonbox3 moonbox3 self-assigned this Jun 5, 2026
@moonbox3 moonbox3 added the ag-ui label Jun 5, 2026
@moonbox3

moonbox3 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

@cyphercodes quick ping on this - please accept the CLA, so we can get the fix in. Thanks.

@TaoChenOSU TaoChenOSU added ag-ui Usage: [Issues, PRs], Target: AG-UI protocol integration and removed ui integration labels Jun 22, 2026
@antsok

antsok commented Jul 3, 2026

Copy link
Copy Markdown

@cyphercodes it would be great to have this completed. Thanks !

@cyphercodes

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree company="CypherCodes"

@cyphercodes

Copy link
Copy Markdown
Contributor Author

CLA completed now; the license/cla check is green.

@eavanvalkenburg eavanvalkenburg enabled auto-merge July 8, 2026 08:06
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Jul 8, 2026
Merged via the queue into microsoft:main with commit 0661c69 Jul 8, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ag-ui Usage: [Issues, PRs], Target: AG-UI protocol integration python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: MessagesSnapshotEvent reassigns the streamed text message ID to the tool-call message on mixed turns

6 participants