Skip to content
Blog

Handling Streaming Chunks and Partial Responses in ADK Runners

Partial events, token chunks, and final responses in ADK: how the Runner treats partial=True, how to accumulate text from run_async, and when state deltas get committed.

Published on • November 24, 2026

AI Assistant

A user watches a chat box the way you watch a compile: any second without a new character looks like a hang. ADK’s answer is that streaming is not a separate API — the same Runner.run_async generator that carries tool calls and state updates also carries token-level chunks, distinguished only by a boolean on each event.

The subtlety is that partial events are not full events. They are display-only: the Runner forwards them upstream immediately but refuses to process their actions, so committing state off a chunk would be wrong. This post covers where chunks come from, how the Runner treats them, and the accumulation pattern that gets you a correct final string.

Where chunks come from

With a streaming generation API, the model produces its response token by token. The framework — often within BaseLlmFlow — yields multiple Event objects for a single conceptual response, most of them marked partial=True. Eventually it yields a final event marked non-partial: partial=False, or implicitly via turn_complete=True.

Non-streaming is the degenerate case: one event, partial=False, processed fully. Note that partial is optional: False or None/absent both mean “this part of the content is complete” — though the overall turn may still be unfinished if turn_complete is also false.

The Go console launcher makes the same distinction at the transport level: its -streaming_mode flag takes none or sse and is auto-detected from the terminal — sse on a TTY, none when piped — so go run agent.go console -streaming_mode none forces batch output while go run agent.go -streaming_mode sse forces token-by-token output.

What the Runner does with partial=True

The Runner’s behavior differs by event kind, and this is the contract to design against:

EventRunner behavior
partial=True chunkForwards immediately upstream (for UI display), skips processing its actions
Non-partial event with actionsFully processed: state_delta and artifact_delta committed via SessionService
Final non-partial text eventDisplayable as the turn’s answer via is_final_response()

That split is deliberate: state changes are applied atomically and exactly once based on the complete response, while the UI still renders text progressively as it is generated.

Consuming the stream correctly

Runner.run_async is the primary entry point (the synchronous Runner.run exists for convenience and just wraps run_async). The standard consumer keeps an accumulator for chunks and flushes it when the final event arrives:

full_response_text = ""

async for event in runner.run_async(
    user_id=user_id, session_id=session.id, new_message=user_message
):
    # Accumulate streaming text
    if event.partial and event.content and event.content.parts:
        if event.content.parts[0].text:
            full_response_text += event.content.parts[0].text

    # Tool traffic is never a partial chunk
    if event.get_function_calls():
        print("Tool call:", [c.name for c in event.get_function_calls()])
        continue

    # Flush on the final, displayable event
    if event.is_final_response():
        final = full_response_text + (
            event.content.parts[0].text
            if event.content and event.content.parts and event.content.parts[0].text
            else ""
        )
        print("Display:", final.strip())
        full_response_text = ""   # reset for the next turn

Notice what you do not do: append state_delta yourself, or persist chunks to session history. The framework only commits the final event’s actions — chunk events never reach SessionService as durable records.

Knowing each phase by shape

PhaseTypical event shape
User inputauthor: "user", content.parts[0].text, actions empty
Streaming chunkpartial: true, turn_complete: false, text part only
Tool call requestcontent.parts[0].function_call with .name and .args
Tool resultcontent.parts[0].function_response, content.role: "user"
Final answerpartial: false, turn_complete: true, is_final_response() == True
State-only updatecontent: null, actions.state_delta populated

Streaming over HTTP

The same semantics surface on the API server. POST /run batches all events into one JSON array; POST /run_sse streams them as Server-Sent Events, and adding "streaming": true to the request body turns on token-level streaming — each data: line is a complete event object whose partial flag tells you whether to append or flush:

curl -X POST http://localhost:8000/run_sse \
  -H "Content-Type: application/json" \
  -d '{"appName":"my_sample_agent","userId":"u_123","sessionId":"s_123",
       "newMessage":{"role":"user","parts":[{"text":"Write a long story"}]},
       "streaming": true}'

Client-side parsing patterns for EventSource and chunk framing are the same as any SSE consumer — see streaming-inference-fastapi-sse.md.

Pitfalls

  • Runner.run blocks; run_async streams. The synchronous method exists only for scripts and tests — it wraps run_async and manages the event loop for you, so use the async path in any server.
  • Blocking sync tools stall the loop. Python ADK calls synchronous tool functions inline on the asyncio event loop; blocking I/O inside one freezes every pending stream. In live mode you can set RunConfig.tool_thread_pool_config to move tool execution to a background thread pool.
  • State reads before commit are dirty. Code later in the same invocation may see uncommitted changes; only code resuming after the yield is guaranteed the committed value. If the invocation fails before that event is processed, the uncommitted change is lost.
  • Do not parse JSON from chunks. A partial event is by definition incomplete; accumulate and parse on the final event (the same rule as output_schema handling).
  • Accumulators must reset per turn. Forgetting the flush on is_final_response() leaks the previous answer into the next one.
  • Chunk events are not history. The session’s durable events list holds the committed, non-partial records — if your UI rebuilds from session.events after a reload, it will see the final text, not the chunks you forwarded.

Takeaway: Treat ADK’s stream as one generator with two channels — partial=True events are ephemeral text you forward and accumulate but never commit, while the single non-partial event carries the actions the Runner persists — and build your consumer around event.partial for display, get_function_calls()/get_function_responses() for tool traffic, and is_final_response() as the flush signal, whether you are looping over run_async or parsing /run_sse frames.

Sources