fix: StreamingResponseAggregator drops/duplicates function calls in streaming mode - #6568
Open
brucearctor wants to merge 1 commit into
Open
fix: StreamingResponseAggregator drops/duplicates function calls in streaming mode#6568brucearctor wants to merge 1 commit into
brucearctor wants to merge 1 commit into
Conversation
…treaming mode Fixes two issues in StreamingResponseAggregator that cause incorrect agent behavior when using StreamingMode.SSE with multi-agent workflows (transfer_to_agent + tools): 1. Progressive SSE path: close() could emit duplicate FunctionCall parts when streaming chunks overlap, causing the agent loop to re-execute the same tool call indefinitely. Fixed by deduplicating FC parts by their id in close(). 2. Legacy SSE path: close() only emitted text parts — FunctionCall parts received during streaming were silently dropped. This caused the agent loop to exit prematurely without executing tools. Fixed by tracking FC parts in _function_call_parts and including them in close(). Fixes google#6566
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.
Summary
Fixes two bugs in
StreamingResponseAggregatorthat cause incorrect agent behavior when usingStreamingMode.SSEwith multi-agent workflows (transfer_to_agent+ tools).Fixes #6566
Problem
Bug 1: Progressive SSE — Duplicate function call parts → infinite loop
close()could emit duplicateFunctionCallparts when streaming chunks overlap. This caused the agent loop inbase_llm_flow.run_asyncto re-execute the same tool call indefinitely (57+ LLM calls instead of 18).Bug 2: Legacy SSE — Function calls silently dropped → premature exit
close()only emitted text parts.FunctionCallparts received during streaming were silently dropped. The agent loop would exit prematurely without executing tools sinceis_final_response()saw no function calls.Fix
streaming_utils.pyProgressive path (
close()): DeduplicateFunctionCallparts by theiridbefore building the finalLlmResponse.Legacy path:
_function_call_partstracking inprocess_response()close()outputTests (
test_streaming_utils.py)test_progressive_close_deduplicates_function_calls: Verifies duplicate FC IDs are collapsedtest_legacy_close_preserves_function_calls: Verifies FCs survive legacy aggregationtest_pure_function_call_behavior_differs_by_modefor new legacy behaviorReproduction
Minimal repro script in #6566 — uses two agents +
transfer_to_agent+ tools to trigger the infinite loop.