Skip to main content
The Runner is the execution engine that runs agents. It manages the step loop, LLM calls, tool execution, state persistence, and telemetry. You create a Runner, hand it an Agent, and get back an AgentResult.

Quick example

Three API modes

Blocks until complete. Best for scripts, tests, and simple integrations.

Run lifecycle

Every agent run follows this state machine:

Terminal states

The step loop

Each “step” is one iteration of the agent’s decision cycle:
1

Build LLM request

The runner constructs an LLMRequest with the conversation history, tool schemas, and model configuration.
2

Call the LLM

The request is sent through the LLM runtime (with retry, circuit breaker, rate limiting, and caching policies).
3

Process response

If the LLM returns text only → the run is complete. If it returns tool calls → proceed to tool execution.
4

Execute tools

Each tool call is validated, policy-checked, executed, and its output is sanitized and fed back to the LLM.
5

Loop or finish

The runner returns to Step 1 for the next LLM turn. This continues until the model produces a text-only response or a limit is hit.

Runner configuration

Run handles and lifecycle control

For advanced control, use run_handle():

Thread-based memory

Pass a thread_id to maintain conversation context across runs:

Resume from checkpoint

Compact long threads

AgentResult reference

ToolExecutionRecord fields

AgentResult.tool_executions entries include:

Next steps

Streaming

Real-time event streaming for chat UIs.

Memory

Thread-based state persistence and resume.