fix: append streamed content deltas instead of replacing previous content#151
Open
Osamaali313 wants to merge 1 commit into
Open
fix: append streamed content deltas instead of replacing previous content#151Osamaali313 wants to merge 1 commit into
Osamaali313 wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
agno streams
RunContentas token-level deltas —RunContentEventis documented as "Main event for each delta of the RunOutput", and providers emit per-chunk delta text (e.g. the Anthropic provider yieldsRunContentEvent(content=text_delta)).The stream handler instead treated
chunk.contentas cumulative: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):
['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
lastContenttracking:Non-repeating content is unchanged; repeated words/tokens are no longer dropped. The JSON-content branch already appended its block, so only its dead
lastContentassignment is removed.