Synchronous vs Asynchronous Agent Execution with Runner.run and Runner.run_async
Runner.run_async is ADK's primary entry point; Runner.run is a sync convenience backed by a background thread. Learn the exact signatures, internals, and when each fits.
Published on • November 24, 2026
AI Assistant

ADK gives you two ways to drive an agent from your own code: Runner.run_async, an async generator that is the framework’s main entry point, and Runner.run, a synchronous generator the docstring calls “only for local testing and convenience purpose.” They yield the same Event objects — but underneath, one runs on your event loop and the other spins up a background thread to do it.
This tutorial compares the two APIs exactly as google.adk.runners.Runner implements them: signatures, internals, consumption patterns, and the pitfalls that show up when blocking code meets an async runtime. The loop both methods feed is explained in adk-event-loop-deep-dive.md.
Constructing the Runner
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
runner = Runner(
app_name="my_agent", # required when passing agent= directly
agent=root_agent, # exactly one of app=, agent=, node=
session_service=InMemorySessionService(),
)
Exactly one of app, agent, or node must be provided; with agent, app_name is required (ADK also warns if app_name doesn’t match the agent’s package directory, since sessions are keyed by it).
run_async: The Primary Entry Point
async def run_async(
self,
*,
user_id: str,
session_id: str,
invocation_id: str | None = None,
new_message: types.Content | None = None,
state_delta: dict[str, Any] | None = None,
run_config: RunConfig | None = None,
yield_user_message: bool = False,
abort_signal: asyncio.Event | None = None,
) -> AsyncGenerator[Event, None]:
Notable behaviors straight from the implementation:
- It’s an
async generator— consume it withasync for, and events arrive as the agent produces them (immediately, underStreamingMode.SSE). - Pass
invocation_id(with nonew_message) to resume an interrupted invocation; passabort_signalto cancel it. state_deltalets you seed session state with the turn.- Post-invocation event compaction finishes before the generator closes, but it does not block subsequent
run_asynccalls — later turns of the same session can run concurrently. - Raises
ValueErrorif the session isn’t found, or if bothinvocation_idandnew_messageareNone.
async for event in runner.run_async(
user_id="user_1",
session_id="session_1",
new_message=types.Content(role="user", parts=[types.Part(text="Summarize this")]),
run_config=config,
):
if event.is_final_response():
print(event.content.parts[0].text)
run: Sync Convenience, Backed by a Thread
def run(
self,
*,
user_id: str,
session_id: str,
new_message: types.Content,
state_delta: dict[str, Any] | None = None,
run_config: RunConfig | None = None,
) -> Generator[Event, None, None]:
Internally, run is a bridge, not a second implementation:
- It starts a background thread whose contextvars are copied from the caller (so the invocation joins your OpenTelemetry trace) and runs
asyncio.run(self.run_async(...))there. - Events are pushed into a
queue.Queue;runblocks onqueue.get()on the calling thread and re-yields them. - Agent exceptions are forwarded over the queue and re-raised on the calling thread once prior events have been yielded.
- If you stop iterating early, the background task is cancelled (so
after_runcallbacks still execute) and the thread is joined beforerunreturns.
Side by Side
Runner.run | Runner.run_async | |
|---|---|---|
| Return type | Generator[Event, None, None] | AsyncGenerator[Event, None] |
| Event loop | Spawns thread + asyncio.run | Uses your running loop |
invocation_id / resume | Not accepted | Supported |
abort_signal | Not accepted | asyncio.Event to cancel |
| Errors | Re-raised on calling thread | Propagate in async for |
| Intended use | Scripts, tests, local convenience | Production, servers, streaming UIs |
Blocking Pitfalls
queue.get()blocks the calling thread. Iteratingrun()inside code that already owns an event loop stalls that loop for the duration of each wait — userun_asyncthere.- Sync tools stall the loop. Python ADK calls synchronous tool functions inline on the asyncio event loop; long blocking I/O belongs in async tools, or behind
RunConfig.tool_thread_pool_configin live mode. - Early
breakis safe but deliberate. Both methods cancel the root task if you stop consuming, so a partial read means the invocation doesn’t finish — state committed up to the last yielded event stands. - Blocking I/O and the GIL. Thread pools help with I/O-bound and GIL-releasing work; pure CPU-bound sync code still blocks its thread either way.
# Quick script or test: sync is fine
for event in runner.run(
user_id="user_1", session_id="session_1", new_message=msg,
):
...
# Web server / FastAPI route: always async
async for event in runner.run_async(
user_id="user_1", session_id="session_1", new_message=msg,
):
...
Takeaway: Treat run_async as the API — it is the framework’s main entry, supports resume and abort, and composes with your asyncio server — and reach for run only in scripts and tests, remembering that it is a thread-and-queue bridge whose blocking consumption and narrower parameter set make it unsuitable for production event loops.