Skip to content

Python: (ag-ui): fix Workflow.as_agent() streaming regression#3875

Merged
moonbox3 merged 4 commits intomicrosoft:mainfrom
moonbox3:3853-fix
Feb 12, 2026
Merged

Python: (ag-ui): fix Workflow.as_agent() streaming regression#3875
moonbox3 merged 4 commits intomicrosoft:mainfrom
moonbox3:3853-fix

Conversation

@moonbox3
Copy link
Contributor

Motivation and Context

add_agent_framework_fastapi_endpoint failed for workflow-backed agents because AG-UI tried to await an async generator returned by WorkflowAgent.run(stream=True).

In #3379, AG-UI switched to agent.run(stream=True) and assumed streaming results were either:

  • ResponseStream, or
  • Awaitable[ResponseStream]

But WorkflowAgent.run(stream=True) returns an AsyncIterable (async generator), which is not awaitable.

What changed

  • Added stream normalization in AG-UI to accept:
    • ResponseStream
    • AsyncIterable
    • Awaitable resolving to either
  • Updated run_agent_stream to use this normalization before iterating.
  • Kept strict typing clean in _run.py (pyright/mypy-safe).

Tests
Added regression coverage for both unit and endpoint paths:

  • _normalize_response_stream accepts async-iterable streams and rejects invalid values.
  • FastAPI endpoint test with a SupportsAgentRun implementation returning an async generator for stream=True.

Description

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.

@moonbox3 moonbox3 self-assigned this Feb 12, 2026
@moonbox3 moonbox3 marked this pull request as ready for review February 12, 2026 07:13
Copilot AI review requested due to automatic review settings February 12, 2026 07:13
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Feb 12, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/ag-ui/agent_framework_ag_ui
   _run.py51012375%156–163, 209–210, 217, 340, 359–360, 375–376, 391, 419–421, 446, 449–452, 454–455, 458–464, 467–469, 472, 488–490, 497, 503–505, 509, 514–516, 518–519, 535–539, 550, 562, 566, 568–569, 585, 612–613, 668–670, 682–684, 887, 898–899, 906, 955–957, 974, 980, 988, 990, 998, 1028–1034, 1037–1040, 1042–1051, 1054, 1062–1065, 1072, 1075–1076, 1081, 1087–1089, 1093, 1098–1101, 1115–1117
TOTAL20445324484% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3908 225 💤 0 ❌ 0 🔥 1m 10s ⏱️

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a streaming regression in the Python AG-UI integration so workflow-backed agents (e.g., Workflow.as_agent()) that return an async generator for run(stream=True) can be streamed correctly through add_agent_framework_fastapi_endpoint.

Changes:

  • Added _normalize_response_stream in agent_framework_ag_ui/_run.py to accept ResponseStream, AsyncIterable, or an Awaitable resolving to either.
  • Updated run_agent_stream to normalize streaming outputs before iterating.
  • Added regression tests covering both the normalization helper and a FastAPI endpoint path using an async-generator streaming agent.

Reviewed changes

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

File Description
python/packages/ag-ui/agent_framework_ag_ui/_run.py Normalizes agent streaming return types and updates streaming execution path; includes some additional typing-safety adjustments.
python/packages/ag-ui/tests/ag_ui/test_run.py Adds unit tests for _normalize_response_stream (accept async iterables, reject invalid values).
python/packages/ag-ui/tests/ag_ui/test_endpoint.py Adds endpoint regression test ensuring FastAPI streaming works when run(stream=True) returns an async generator.

@moonbox3 moonbox3 added this pull request to the merge queue Feb 12, 2026
Merged via the queue into microsoft:main with commit 2203fa0 Feb 12, 2026
25 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in Agent Framework Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: WorkflowAgent incompatible with add_agent_framework_fastapi_endpoint - streaming interface mismatch

4 participants