Skip to content

Python: Fix AG-UI workflow handoff replay results#7102

Merged
moonbox3 merged 4 commits into
microsoft:mainfrom
moonbox3:6981-fix
Jul 14, 2026
Merged

Python: Fix AG-UI workflow handoff replay results#7102
moonbox3 merged 4 commits into
microsoft:mainfrom
moonbox3:6981-fix

Conversation

@moonbox3

Copy link
Copy Markdown
Contributor

Motivation & Context

AG-UI-hosted handoff workflows expose their internal handoff function calls as standard tool events, but the matching synthetic handoff result can appear only in the participant's finalized response. Without that result in the AG-UI stream, an outer Agent using AGUIChatClient records an orphaned function call and replays provider-invalid history on the next turn. OpenAI then rejects the request with a missing tool output error.

Description & Review Guide

  • What are the major changes?
    • Reconcile finalized function results only for calls exposed during the current workflow run and not already completed.
    • Ignore replayed function-result messages unless they correspond to pending workflow interrupts, preserving explicit resume semantics.
    • Add runner-level and two-turn client/endpoint regression coverage using a real handoff workflow and scripted providers.
    • Prevent finalized results in the latest assistant message from emitting duplicate tool-end and tool-result events.
  • What is the impact of these changes?
    • Client-managed AG-UI history remains provider-valid across handoffs and later turns.
    • Thin clients and existing request-info/approval interrupt flows retain their current behavior.
  • What do you want reviewers to focus on?
    • Whether call-ID reconciliation remains limited to results for calls actually exposed during the current run.
    • Whether the explicit workflow resume boundary remains intact.

Related Issue

Fixes #6981

No other open PR was found for this issue.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after the language prefix) — a workflow keeps the label and title prefix in sync automatically.

moonbox3 added 2 commits July 14, 2026 12:49
Decisions:
- Reconcile finalized function results only for call IDs exposed in the current run, and skip results already emitted or never exposed.
- Treat message-derived function results as workflow responses only when their IDs match pending interrupts.

Files:
- Updated _workflow_run.py reconciliation and resume filtering.
- Added runner and public two-turn handoff acceptance coverage.
- Expanded finalized-response call-ID, privacy, and deduplication tests.

Verification:
- uv run poe test -P ag-ui
- uv run poe syntax -P ag-ui -C
- uv run poe pyright -P ag-ui
- uv run poe test-typing -P ag-ui

Notes:
- No blockers. The handoff sample remains unchanged; local PRD and issue files are not included.
Copilot AI review requested due to automatic review settings July 14, 2026 04:57
@giles17 giles17 added the python Usage: [Issues, PRs], Target: Python label Jul 14, 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

This PR fixes AG-UI workflow handoff replay by ensuring tool-call transcripts remain provider-valid across turns when a workflow’s synthetic handoff result is only present in the finalized response (not in the streamed event sequence). It updates the workflow stream runner to reconcile finalized tool results for tool calls that were actually exposed during the current run, while preserving explicit workflow resume semantics.

Changes:

  • Reconcile finalized function_result items for tool calls exposed during the run, emitting missing TOOL_CALL_RESULT events without re-emitting tool calls/results.
  • Restrict message-derived workflow interrupt responses to only those matching currently pending workflow interrupts (avoids replayed history being treated as a resume).
  • Add regression coverage: runner-level tests for finalized-result reconciliation and an end-to-end two-turn handoff replay test using a real HandoffBuilder workflow and AGUIChatClient.

Reviewed changes

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

File Description
python/packages/ag-ui/agent_framework_ag_ui/_workflow_run.py Adds finalized-result reconciliation for exposed tool calls and tightens interrupt-response extraction to pending-only.
python/packages/ag-ui/tests/ag_ui/test_workflow_run.py Expands runner tests to verify correct emission/deduplication and call-id matching for finalized tool results.
python/packages/ag-ui/tests/ag_ui/test_handoff_replay.py Adds end-to-end acceptance tests validating replayable handoff transcripts across a second turn.

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/ag-ui/agent_framework_ag_ui
   _workflow_run.py6837389%78, 92, 94, 96, 99, 226–229, 278, 289, 294, 319, 355–358, 386, 391, 419, 429, 440, 445, 448, 461, 471, 474, 479, 482, 497–499, 504, 506–507, 511, 513, 530, 536–537, 547–548, 552–553, 577–578, 611, 619, 688, 708, 724, 739, 840–854, 886–887, 908–909, 980, 1042
TOTAL44440524888% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
8961 33 💤 0 ❌ 0 🔥 2m 23s ⏱️

@moonbox3 moonbox3 marked this pull request as ready for review July 14, 2026 05:03

@github-actions github-actions Bot 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.

Automated Code Review

Reviewers: 5 | Confidence: 80% | Result: All clear

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


Automated review by moonbox3's agents

@moonbox3 moonbox3 self-assigned this Jul 14, 2026
@moonbox3 moonbox3 added the ag-ui Usage: [Issues, PRs], Target: AG-UI protocol integration label Jul 14, 2026
@moonbox3 moonbox3 moved this to In Review in Agent Framework Jul 14, 2026
@moonbox3 moonbox3 enabled auto-merge July 14, 2026 08:08
@moonbox3 moonbox3 added this pull request to the merge queue Jul 14, 2026
Merged via the queue into microsoft:main with commit b123480 Jul 14, 2026
36 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in Agent Framework Jul 14, 2026
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

Status: Done

Development

Successfully merging this pull request may close these issues.

Python: [Python]: AG-UI workflow server fails to respond after initial client message

5 participants