fix: accumulate text across tool calls for output_key in streaming mode#5599
fix: accumulate text across tool calls for output_key in streaming mode#5599theonlychant wants to merge 4 commits intogoogle:mainfrom
Conversation
|
Hello, I tried your patch and it's not working yet. I see that it's accumulating the text but the last response in event.is_final_response() still replaced the state with the last stream part |
My apologies friend I forgot to add that part in the patch you can check now, I've just pushed a fix to my branch |
|
this works perfectly! Thanks |
You're welcome glad to help |
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem
When using
LlmAgentwithoutput_keyandStreamingMode.SSE, text streamedbefore tool calls is lost. The
__maybe_save_output_to_state()method onlyprocesses
is_final_response()events, which only fires after all toolexecutions complete. This causes 60–70% of agent responses to be discarded in
scenarios where agents make tool calls mid-response.
Example: An agent that streams intro text → calls a tool → streams progress
→ calls a tool → streams conclusion will only save the conclusion to
output_key.Solution
Accumulate text parts across all streaming events (not just the final response)
and persist the full combined text to
output_keystate. This ensures introtext, progress updates, and conclusions are all preserved regardless of tool
call interleaving.
Testing Plan
Unit Tests:
Manual End-to-End (E2E) Tests:
Run the reproduction script from issue #5590. Before this fix, match ratio was
~34.9% (only conclusion saved). After this fix, all text parts across tool calls
are accumulated correctly.
Expected output after fix:
Checklist