ADK Event Loop Deep Dive: How Events, Actions, and State Transitions Flow
A guided tour of ADK's event loop: how the Runner and your agents trade Events, when state_delta commits, why dirty reads happen, and how partial streaming events work.
Published on • November 24, 2026
AI Assistant

Every ADK conversation runs on one mechanism: an event loop that shuttles Event objects between the Runner and your execution logic — agents, tools, and callbacks. If you understand this loop, ADK’s streaming behavior, state persistence rules, and debugging quirks stop being surprises and start being predictable contracts.
This deep dive follows the loop as documented in the ADK runtime: the Runner’s orchestrating role, the yield/pause/resume discipline your code obeys, and the three behaviors (commit timing, dirty reads, partial events) that trip up most newcomers. The orchestration patterns built on top of this loop are covered separately in google-adk-2-graph-workflows-deterministic-orchestration.md and adk-agent-swarm-multi-agent-systems.md.
The Loop Contract
At its heart, the Runner and your code hold a five-step conversation:
- The
Runnerreceives a user query, appends it to session history via theSessionService, and kicks offagent.run_async(...). - Your execution logic runs until it has something to report — a response, a tool call, a state change — and yields an
Event. - The
Runnerreceives the event, processes itsactions(state_delta,artifact_delta) through the services, and forwards the event upstream (to your UI). - Your logic resumes only after the Runner has committed the event — and therefore sees the updated state.
- Repeat until the agent has no more events to yield for that query.
Inside the Runner
The conceptual Runner loop, as published in the ADK docs:
async def run_async(new_query, ...) -> AsyncGenerator[Event, None]:
# 1. Append new_query to session event history (via SessionService)
await session_service.append_event(session, Event(author='user', content=new_query))
# 2. Kick off event loop by calling the agent
agent_event_generator = agent_to_run.run_async(context)
async for event in agent_event_generator:
# 3. Process the generated event and commit changes
await session_service.append_event(session, event) # commits state/artifact deltas
# 4. Yield event for upstream processing (e.g., UI rendering)
yield event
# Runner implicitly signals the agent generator can continue
The Runner’s job is bookkeeping and commit; it never computes your business logic.
Inside Execution Logic
Your agent, tool, or callback code obeys a strict discipline — build an event, yield it, pause, resume, read committed state:
# 1. Modify state
ctx.session.state['status'] = 'processing'
event1 = Event(
author=self.name,
actions=EventActions(state_delta={'status': 'processing'}),
content=types.Content(parts=[types.Part(text="State updated.")]),
)
# 2. Yield event with the delta — execution PAUSES here
yield event1
# 3. Resume ONLY after Runner processed it: state is guaranteed committed
assert ctx.session.state['status'] == 'processing'
Custom BaseAgent subclasses implement this as async def _run_async_impl(self, ctx: InvocationContext) -> AsyncGenerator[Event, None] — the mechanics are also spelled out in custom-base-agents-non-llm-adk.md.
The Cast of Components
| Component | Role in the loop |
|---|---|
Runner (google.adk.runners) | Entry point; appends user input, commits event actions, yields upstream |
| Execution logic | BaseAgent/LlmAgent, tools, callbacks — produce events |
Event | Atomic message: content plus intended side effects (actions) |
SessionService | Applies state_delta, appends events to history |
ArtifactService / MemoryService | Persist artifacts; optional cross-session memory |
Session | One conversation: state dict + events history |
Invocation | Everything for one user query, tied to one invocation_id |
State keys prefixed temp: live and die within a single invocation; everything else survives in the session.
One Invocation, Traced
For a query where the LLM calls a tool, the loop cycles like this:
| Step | Who | Action |
|---|---|---|
| 1 | Agent | LLM returns a FunctionCall; agent yields it as an event |
| 2 | Runner | Records it in history, forwards to UI; agent pauses |
| 3 | Agent | Resumes, executes the tool, wraps result in FunctionResponse event (possibly with state_delta) |
| 4 | Runner | Commits state/artifact deltas, forwards upstream |
| 5 | Agent | Final LLM call; yields the text event (marked is_final_response()) |
| 6 | Runner | Commits and forwards; agent generator finishes; invocation ends |
Commit Timing and Dirty Reads
The rule: a state write is only guaranteed persisted after the event carrying its state_delta has been yielded and processed by the Runner. Code running after that resume can rely on it.
The wrinkle: within the same invocation, later code can often see uncommitted local changes — a “dirty read”:
# before_agent_callback
callback_context.state['field_1'] = 'value_1' # local only, not yet committed
# tool running later in the same invocation
val = tool_context.state['field_1'] # 'value_1' — readable but uncommitted
Dirty reads let callbacks and tools coordinate cheaply inside one step. The caveat: if the invocation fails before the event carrying the delta is yielded and processed, that change is lost. For critical transitions, always attach the write to an event that gets committed.
partial=True: Streaming Without Losing State
With StreamingMode.SSE, the framework yields multiple events for one conceptual response, most marked partial=True. The Runner forwards partial events immediately (for typewriter UIs) but skips their actions; only the final non-partial event has its state_delta and artifact_delta committed. That is why UI text can appear token-by-token while state changes apply atomically, exactly once, from the complete response.
Async Is Primary
The runtime is built on asyncio: Runner.run_async is the main entry point, while the synchronous Runner.run is a convenience wrapper that drives run_async for you. Blocking synchronous tools stall the event loop (Python ADK calls them inline), which is why RunConfig.tool_thread_pool_config exists for offloading tool work. The sync-vs-async trade-off gets its own treatment in runner-run-vs-run-async-adk.md.
Takeaway: Think of ADK as a coroutine handoff — your code yields an Event, pauses, and resumes only after the Runner has committed that event’s actions, which is why committed state is reliable after a yield while earlier same-invocation reads are dirty, partial events stream without persisting state, and every design decision about blocking I/O, streaming, and state writes flows from that one contract.