Skip to content

Python: fix AG-UI pending tool history replay - #5973

Closed
Yufeng He (he-yufeng) wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/ag-ui-tool-history-pending-results
Closed

Python: fix AG-UI pending tool history replay#5973
Yufeng He (he-yufeng) wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/ag-ui-tool-history-pending-results

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

Summary

  • close pending AG-UI tool calls before accepting another assistant tool-call message
  • close any pending tool calls left at the end of replayed history
  • keep the existing user-follow-up synthetic result path on the same helper

To verify

  • uv run pytest packages/ag-ui/tests/ag_ui/test_message_adapters.py -q -p no:cacheprovider
  • uv run pytest packages/ag-ui/tests/ag_ui/test_message_adapters.py packages/ag-ui/tests/ag_ui/test_agent_wrapper_comprehensive.py -q -p no:cacheprovider
  • uv run ruff check packages/ag-ui/agent_framework_ag_ui/_message_adapters.py packages/ag-ui/tests/ag_ui/test_message_adapters.py
  • uv run mypy --config-file packages/ag-ui/pyproject.toml packages/ag-ui/agent_framework_ag_ui/_message_adapters.py
  • git diff --check

Fixes #5855

Copilot AI review requested due to automatic review settings May 20, 2026 15:13

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.

This PR fixes AG-UI replay edge cases by ensuring pending assistant tool calls are proactively closed (via synthetic tool results) before subsequent assistant messages and at the end of replayed history.

Changes:

  • Inject synthetic tool results when a new assistant message arrives while tool calls are still pending.
  • Inject synthetic tool results when replayed history ends with pending tool calls.
  • Add tests covering “assistant-before-next-assistant” and “end-of-history” pending tool-call scenarios.

Reviewed changes

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

File Description
python/packages/ag-ui/agent_framework_ag_ui/_message_adapters.py Adds a helper to flush pending tool calls and extends sanitization to handle pending calls before the next assistant message and at end-of-history.
python/packages/ag-ui/tests/ag_ui/test_message_adapters.py Adds regression tests for the new pending-tool-call sanitization behavior.

def flush_pending_tool_results(result: str) -> None:
nonlocal pending_confirm_changes_id, pending_tool_call_ids

if not pending_tool_call_ids:

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.

Let's address this one, please.

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.

Ping

Comment thread python/packages/ag-ui/agent_framework_ag_ui/_message_adapters.py
Comment thread python/packages/ag-ui/agent_framework_ag_ui/_message_adapters.py
Comment thread python/packages/ag-ui/agent_framework_ag_ui/_message_adapters.py
Comment thread python/packages/ag-ui/agent_framework_ag_ui/_message_adapters.py
@moonbox3

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/ag-ui/agent_framework_ag_ui
   _message_adapters.py5935091%39–40, 128–129, 138–141, 144–148, 150–155, 158, 167–173, 200, 349, 470–472, 526, 529, 531, 534, 537, 553, 570, 592, 692, 708–709, 780, 802, 872, 907–908, 976, 1019
TOTAL35221410588% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
6992 30 💤 0 ❌ 0 🔥 1m 46s ⏱️

@moonbox3

Copy link
Copy Markdown
Contributor

Please re-open if you decide to take this forward. Closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: AG-UI history replay can send invalid assistant/tool sequence to OpenAI (tool_calls without matching tool messages)

3 participants