feat(events): add turnId to SSE events for per-LLM-turn grouping#5307
Open
ilyesJammouci wants to merge 3 commits intogoogle:mainfrom
Open
feat(events): add turnId to SSE events for per-LLM-turn grouping#5307ilyesJammouci wants to merge 3 commits intogoogle:mainfrom
ilyesJammouci wants to merge 3 commits intogoogle:mainfrom
Conversation
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.
Closes: #4793
Problem
With runner.run_async() + StreamingMode.SSE, one invocation can contain multiple LLM calls (for example: text → tool call → text).
invocation_id is shared by all events, and id changes on each yield, so clients cannot reliably group partial chunks and final output from the same LLM call.turn.
Solution
This PR adds an additive turn_id field to Event (serialized as turnId) and propagates it through streaming flow:
The first two images come from the same LLM call, so they share the same turnId.



This image comes from a different LLM call, so it has a different turnId.
Testing
Run local unit tests: pytest test_base_llm_flow.py test_base_llm_flow_partial_handling.py test_progressive_sse_streaming.py test_functions_simple.py test_functions_parallel.py -q
Locally validate SSE behavior via Web UI: