Skip to content

feat(events): add turnId to SSE events for per-LLM-turn grouping#5307

Open
ilyesJammouci wants to merge 3 commits intogoogle:mainfrom
ilyesJammouci:feat/turn-id-streaming-events-4793
Open

feat(events): add turnId to SSE events for per-LLM-turn grouping#5307
ilyesJammouci wants to merge 3 commits intogoogle:mainfrom
ilyesJammouci:feat/turn-id-streaming-events-4793

Conversation

@ilyesJammouci
Copy link
Copy Markdown

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:

  1. Generate one turn_id per LLM call step.
  2. Keep the same turn_id for partial chunks and final model event of that call.
  3. Propagate that turn_id to tool-derived follow-up events.
  4. Start a new turn_id when a new LLM call begins.

The first two images come from the same LLM call, so they share the same turnId.
image
image
This image comes from a different LLM call, so it has a different turnId.
image

Testing

  1. 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

  2. Locally validate SSE behavior via Web UI:

  • Start the app with adk web src/google/adk/agent.
  • Open an agent that triggers a multi-step flow (text → tool call → text) with streaming enabled.
  • Verify streamed payloads include turnId.
  • Confirm all partial and final events from the same LLM call share the same turnId, and that each new LLM call uses a different turnId.

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.

Add a turn/response group identifier to streaming events

1 participant