Skip to content

fix: append streamed content deltas instead of replacing previous content#151

Open
Osamaali313 wants to merge 1 commit into
agno-agi:mainfrom
Osamaali313:fix/stream-content-delta-append
Open

fix: append streamed content deltas instead of replacing previous content#151
Osamaali313 wants to merge 1 commit into
agno-agi:mainfrom
Osamaali313:fix/stream-content-delta-append

Conversation

@Osamaali313

Copy link
Copy Markdown

Problem

agno streams RunContent as token-level deltasRunContentEvent is documented as "Main event for each delta of the RunOutput", and providers emit per-chunk delta text (e.g. the Anthropic provider yields RunContentEvent(content=text_delta)).

The stream handler instead treated chunk.content as cumulative:

const uniqueContent = chunk.content.replace(lastContent, '')
lastMessage.content += uniqueContent
lastContent = chunk.content

String.replace(lastContent, '') removes the first occurrence of the previous delta from the current delta. Whenever a delta repeats text from the previous one — common with repeated words or tokens — the current delta is mangled.

Reproduction

Running the exact reducer over a delta stream (agno deltas, left→right):

streamed deltas rendered (before) expected
['na', ' na', ' na'] "na " "na na na"
['go', ' go'] "go " "go go"
['the', ' the'] "the " "the the"
['Hello', ' world'] "Hello world" "Hello world" (unaffected)

Fix

Append each delta directly and drop the unused lastContent tracking:

lastMessage.content += chunk.content

Non-repeating content is unchanged; repeated words/tokens are no longer dropped. The JSON-content branch already appended its block, so only its dead lastContent assignment is removed.

…tent

agno streams RunContent as token-level deltas (RunContentEvent is documented as "each delta"; providers yield per-chunk delta text). The handler treated chunk.content as cumulative and did chunk.content.replace(lastContent, ''), which strips the first occurrence of the previous delta from the current delta. Whenever a delta repeats text from the previous one (common with repeated words/tokens), output was corrupted: deltas ["na", " na", " na"] produced "na " instead of "na na na".

Append each delta directly (lastMessage.content += chunk.content) and drop the now-unused lastContent tracking.
Copilot AI review requested due to automatic review settings June 24, 2026 21:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants