How the ADK runner, apps and events fit together
Explain the roles of app, agent, runner and event in the pinned release and point to where execution starts, where the session enters and how final output is chosen.
By Invicly Tech, , in Google ADK with Python for AI Agents. About 10 minutes to read.
In short
In ADK the agent describes behaviour, the optional App groups the root agent with app-wide settings such as plugins, and the Runner executes one user message at a time against a session. Execution starts when you call runner.run_async with a user ID, a session ID and the new message, and the runner yields events as it goes. Your code picks the answer by checking event.is_final_response().
Think of it like this: The agent is the recipe, the App is the restaurant's rule book, the Runner is the kitchen, and events are the order tickets clipped in sequence.
Explained simply
An ADK program has a few parts with clear jobs. The agent says how to behave: its instruction, model and tools. The App is an optional wrapper that gives the agent a name and app-wide settings such as plugins. The Runner is the engine that actually runs the agent when a message arrives.
The runner never works in a vacuum. Every run belongs to a user and a session. The session is one conversation, stored by a session service. When you call the runner you pass the user ID, the session ID and the new message. The runner loads that session so the agent can see the earlier conversation.
As the agent works, the runner produces events: a tool call, a tool result, a piece of text. It saves each event to the session and then hands it to your code. Your code loops over the events and decides what to show.
Usually you show only the final answer. ADK gives every event a helper, is_final_response(), that is true for a finished reply and false for tool calls, tool results and half-finished streaming text. That one check is how your app picks the answer.
Press Play on a diagram to walk through it one step at a time.
- 1Your code
Picks user and session IDs, reads events
- 2Runner
Runs one invocation, saves and yields events
- 3App (optional)
Name, root agent, plugins, app-wide config
- 4Agent
Instruction, model, tools, sub-agents
- 5Services
Session, artifact and memory storage
- Your code to Runner: run_async(user_id, session_id, new_message)1run_async(user_id, session_id, new_message)
- Runner to Session service: get_session(app, user, session)2get_session(app, user, session)
- Runner to Session service: append user message event3append user message event
- Runner to Agent: run with session history4run with session history
- Agent to Runner: yield events5yield events
- Runner to Session service: append each event6append each event
- Runner to Your code: yield events to caller7yield events to caller
- Identity
- id
- invocation_id
- author
- timestamp
- content
- text part
- function_call part
- function_response part
- actions
- state_delta
- artifact_delta
- transfer_to_agent
- escalate
- 2.x graph fields
- node_info
- output
- Flags
- partial
- turn_complete
- error_code
In depth
App, agent and runner in the pinned release
In google-adk 2.15.1 you can build a runner two ways. Runner(app=app, session_service=...) takes an App, which holds the name and root agent plus optional plugins, context caching, event compaction and resumability settings. Runner(agent=root_agent, app_name="support_app", session_service=...) skips the App. Both are keyword-only. Use App once you need plugins or app-wide config; it also keeps the app name in one place.
The runner can also take artifact_service, memory_service and credential_service. If you call a context method such as save_artifact without an artifact service, ADK raises an error, so wire every service your tools use. InMemoryRunner builds in-memory versions of the services for you and is ideal for scripts and tests.
- Runner(app=..., session_service=...)
- Runner(agent=..., app_name=..., session_service=...)
- Optional: artifact_service, memory_service, plugins
- InMemoryRunner(agent=..., app_name=...) for local runs
Starting a run
Execution starts at runner.run_async(user_id=..., session_id=..., new_message=...). The message is a google.genai types.Content with role user and one or more parts. Optional arguments include state_delta, to apply state changes along with the message, and run_config, to set options such as a cap on model calls.
The session must exist first. Create it with session_service.create_session(app_name=..., user_id=...), which returns a session with a generated ID, or pass auto_create_session=True to the runner. Missing sessions raise SessionNotFoundError, which is useful: it is the signal your API should turn into a 404. There is also a synchronous runner.run for scripts, and an async run_debug helper that takes plain strings.
- 1create_session
Returns session.id
- 2Build Content
role user, text part
- 3run_async
user_id, session_id, message
- 4Load session
History and state
- 5Append message
Saved as the first event
Reading the event stream
Every event has an author (the agent name, or user), an invocation_id shared by all events from one message, an id, a timestamp, content and actions. content holds parts: text, a function call or a function response. actions holds side effects: state_delta and artifact_delta for saved changes, transfer_to_agent when control moves to another agent, and escalate when a loop should stop. ADK 2.x adds node_info, which shows which graph node produced the event, and output.
Helpers make the stream easy to read: get_function_calls() and get_function_responses() return lists, and partial is true for streaming chunks. Usage data such as token counts appears in usage_metadata on model events.
- author and invocation_id: who and which request
- content.parts: text, function_call, function_response
- actions.state_delta: state changes
- partial: streaming chunk, not complete
How the final output is chosen
is_final_response() returns true when the event has no function calls, no function responses, is not partial and does not end with a code execution result. It also returns true if a tool set skip_summarization, if there are long-running tool IDs, or if the event carries an error. That last case matters: show an error message rather than waiting forever.
When a coordinator hands off to a sub-agent, each agent may produce a final response. If your UI should show only the top agent's answer, filter by event.author as well.
Comparing with older Runner examples
Older examples often differ in small ways. Some call run_async with positional arguments; 2.15.1 requires keywords. Some call session_service.create_session without await; it is async. Some never mention App, which is still optional. Some subclass BaseAgent and override _run_async_impl to control flow; in 2.x that override no longer drives execution, and graph workflows or callbacks replace it. Some store events in custom tables with fixed columns, which break on the new node_info and output fields.
Learn it in 5 short steps
About 30m each. Track them with a timer in your plan.
- 1Name the app, agent and runner roles~30m
- 2Start a run with a user and session ID~30m
- 3Read the event stream~30m
- 4Pick out the final response~30m
- 5Compare this with older Runner examples~30m
Key points
- Construct the runner with either app=App(...) or agent= plus app_name=, and always a session_service.
- run_async needs keyword arguments user_id, session_id and new_message; the session must already exist unless auto_create_session=True.
- The runner saves each event through the session service before yielding it, so stored history matches what you saw.
- Pick the answer with event.is_final_response(); with several agents, also check event.author.
- ADK 2.x events also carry node_info and output fields from the graph runtime.
Key terms
Tap a card to flip it. 0/5 known
Examples
from google.adk.apps import App
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
app = App(name="support_app", root_agent=root_agent)
sessions = InMemorySessionService()
runner = Runner(app=app, session_service=sessions)
session = await sessions.create_session(app_name="support_app", user_id="user-a")
async for event in runner.run_async(
user_id="user-a", session_id=session.id, new_message=msg
):
if event.is_final_response():
print(event.content.parts[0].text)Inside an async function; msg is a google.genai types.Content with role user.
A runner with an App and explicit services
This setup is what you will reuse in later modules. Step 1: wrap the root agent in an App. Step 2: create the services. Step 3: pass them to the runner. Expected evidence: running a question prints one final answer, and get_session afterwards shows the events stored. Swap InMemorySessionService for DatabaseSessionService later without changing the loop.
from google.adk.apps import App
from google.adk.artifacts import InMemoryArtifactService
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
app = App(name="support_app", root_agent=root_agent)
runner = Runner(
app=app,
session_service=InMemorySessionService(),
artifact_service=InMemoryArtifactService(),
)Logging a compact trace of every event
When debugging, print one line per event: author, kind and whether it is final. Run a question that needs a tool. Expected output: a call line, a response line and a final text line, all with the same invocation ID prefix. If you only see a final line, the model answered without the tool; check the instruction.
async for ev in runner.run_async(user_id=uid, session_id=sid, new_message=msg):
if ev.get_function_calls():
kind = "call " + ev.get_function_calls()[0].name
elif ev.get_function_responses():
kind = "tool result"
else:
kind = "text"
print(ev.invocation_id[:8], ev.author, kind, ev.is_final_response())Quick reference
- Runner(app=App(name=..., root_agent=...), session_service=...)
- run_async(user_id=..., session_id=..., new_message=types.Content(...)) yields events
- Session must exist first, or pass auto_create_session=True to the runner
- Unknown session for that user: SessionNotFoundError
- event.is_final_response() picks the answer; filter by event.author with sub-agents
- event.actions.state_delta shows the state changes made by that step
- InMemoryRunner: built-in in-memory services; await runner.run_debug("hi") for quick tests
Common mistakes
- Calling run_async with a session ID that was never created, which raises SessionNotFoundError.
- Using a different app_name for create_session than the runner uses, so the session is not found.
- Copying 1.x samples that build their own loop over agent.run_async instead of using the runner.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Create an InMemoryRunner for your agent, create a session for user-a and print its ID and empty state.
- Exercise 2medium
Run one question and print only the final answer text, ignoring all other events.
- Exercise 3hard
After a run, fetch the session again and assert that the stored events match the ones yielded, plus the user message.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Do I need an App?
- No. It is optional. Use it once you want plugins, context caching, event compaction or resumability, or simply to keep the app name in one place.
- Why does the stored session have one more event than I received?
- The runner stores your user message as an event but does not yield it back by default. Pass yield_user_message=True if you want it in the stream.
- Can I use the runner from synchronous code?
- Yes, runner.run is a synchronous wrapper for scripts. In web servers prefer run_async so you do not block other requests.