Python: [Bug]: ag-ui endpoint drops a text delta that equals the whole text streamed so far · Issue #9336 · microsoft/agent-framework · GitHub
Skip to content

Python: [Bug]: ag-ui endpoint drops a text delta that equals the whole text streamed so far #9336

Closed

Description

Observed Behavior

While streaming through the ag-ui endpoint, a text delta is silently dropped when its text happens to equal the accumulated text of the current message. If the model streams "2" and then another "2" (it is answering "22"), the second delta never gets emitted and the client only sees "2".

Expected Behavior

Repeated short tokens are normal deltas and should be appended. The full replay guard added for #4194 should not fire on them.

Steps to Reproduce

  1. Call _emit_text twice with identical text chunks on the same flow.
  2. The second call returns no events.
  3. flow.accumulated_text still holds only the first chunk.

Minimal Reproduction

from agent_framework import Content
from agent_framework_ag_ui._run_common import FlowState, _emit_text

flow = FlowState()
_emit_text(Content.from_text("2"), flow)
events = _emit_text(Content.from_text("2"), flow)  # dropped

assert events == []
assert flow.accumulated_text == "2"  # expected "22"

Easy to hit with real token streams. Any answer that starts with a doubled digit or a repeated short token ("22", "55", "haha") triggers it since numbers and repeated words often come out as separate identical chunks.

Error Messages and Stack Traces

No error, the delta is just skipped with a debug log "Skipping duplicate full-text delta for message_id=...".

Package Versions

agent-framework-core and ag-ui built from main (dcbbf79)

Python Version

Python 3.14.8

Operating System

macOS

Regression

No

Additional Context

The guard exists to skip full message replays some providers send after streaming deltas (it mirrors the tool arguments fix in #4194). But a genuine repeated delta and a full replay look identical once the duplicate equals everything streamed so far. One way out: track how many deltas were already emitted for the message and only apply the replay guard when the text arrived in more than one chunk. That keeps the replay protection and stops eating repeated tokens. I can send a PR for this.

Acknowledgements

  • I searched existing issues and did not find a duplicate.

Metadata

Metadata

Labels

pythonUsage: [Issues, PRs], Target: Python

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions