adk-runner
Agent execution runtime for ADK-Rust.
Stability: Stable — follows semantic versioning, so breaking changes wait for the next major release. See STABILITY.md.
Overview
adk-runner provides the execution runtime for ADK-Rust:
Runner— runs an agent tree against a session and streams its eventsRunnerConfigBuilder— typestate builder (Runner::builder()) that enforcesapp_name,agent, andsession_serviceat compile time- Session integration — loads the session, appends every event, and applies state deltas as they arrive
- Services — gives agents and tools the artifact service (scoped to the session), the memory service, and the request context
- Agent transfers — runs transfer targets, enforcing each source agent's transfer restrictions
- Steering —
Runner::steersends a screened message to a run in flight, which its agent takes at the next safe point - Prewarm —
Runner::prewarmopens the model's connection, starts the servers an agent starts on its first turn and reads the session before the first message, under the kill switch and a time budget - Archived sessions — a turn on a session archived with
SessionService::archivefails withsession.archivedbefore anything is saved - Governance — the run's tool policy, kill switch, budgets, spend ledger, action ledger, approval store, and audit trail
- Context compaction — summarizes older session events after a run, and installs the auto-compaction agents apply before every model call
Launcher— a minimal stdin/stdout console loop
Installation
[]
= "3.0.0"
Or use the umbrella crate, whose default minimal tier includes the runner:
[]
= "3.0.0"
Feature Flags
| Feature | Default | Enables |
|---|---|---|
artifacts |
yes | artifact_service through adk-artifact |
plugins |
yes | plugin_manager through adk-plugin |
skills |
no | Runner::with_skill_injector, Runner::with_auto_skills_mut, and skill injection through adk-skill |
context-compaction |
no | The compaction module: CompactionStrategy, TruncationCompaction, SummarisationCompaction, and RunnerConfigBuilder::context_compaction, a strategy auto-compaction applies in place of a summary |
sandbox-runner |
no | The sandbox_runner module: SandboxRunner provisions an adk-sandbox workspace, binds its tools for the run, and stops it afterwards |
Quick Start
The runner reads an existing session, so create it first:
use Arc;
use LlmAgentBuilder;
use Content;
use GeminiModel;
use Runner;
use ;
use StreamExt;
async
run_str validates the ids and calls run(UserId, SessionId, Content). run_with_config overrides the runner's RunConfig for one run, and start_with_config also returns the invocation id before the first event. Runner::new(RunnerConfig { .. }) builds from a struct literal that names every field.
Builder Options
| Method | Purpose |
|---|---|
app_name, agent, session_service |
Required |
artifact_service, memory_service |
Services exposed to agents and tools |
plugin_manager |
Run, user-message, event, agent, model, and tool plugin callbacks (plugins) |
run_config |
The base RunConfig for every run |
budget |
A RunBudget applied to every run with fresh counters |
tool_policy |
The ToolPolicy for every run |
egress_policy |
The operator's network egress ceiling (adk_core::egress::EgressPolicy); a tool whose Tool::egress declaration it does not admit is refused before it runs, and a run's own policy only narrows it |
governance |
Share a GovernanceControl (kill switch) across runners |
action_ledger, approval_store, spend_ledger |
Durable stores installed on every run whose RunConfig leaves them unset |
durable_run_store |
interrupt also requests cancellation of the session's durable runs on every replica |
audit_log, audit_failure_mode |
Record governed actions; AuditFailureMode::Block (the default) refuses an action whose record cannot be written |
identity_source, agent_principal |
The principal the root agent acts as |
subject_delegation |
Which runs may act for a subject other than the session's user |
compaction_config |
Post-invocation EventsCompactionConfig |
intra_compaction_config, intra_compaction_summarizer, without_intra_compaction |
Auto-compaction before each model call; on by default at 80% of the model's context window; IntraCompactionConfig::in_background writes the summary off the critical path |
context_compaction |
A compaction strategy in place of the summary (context-compaction) |
context_cache_config, cache_capable |
Provider prompt-cache lifecycle |
request_context |
Auth middleware context |
cancellation_token |
Cooperative cancellation of every run |
action_ledger, approval_store, and spend_ledger accept any backend implementing the adk-core traits — in-memory, or SQLite, PostgreSQL, Redis, MongoDB, Neo4j, or Firestore from adk-session.
Runner vs Direct Agent Execution
| Concern | Direct agent.run() |
Runner |
|---|---|---|
| Session load and event persistence | Manual | Automatic |
| State deltas | Manual | Applied as events arrive |
| Artifact and memory services | Manual | Attached to the invocation context |
| Agent transfers | Manual | Automatic, with restrictions enforced |
| Input guardrail screening before save | Manual | Automatic |
| Budgets, spend, policy, audit | Manual | Automatic |
Agent Transfers
When an agent sets transfer_to_agent in EventActions, the runner finds the target in the agent tree, builds its invocation context, and continues streaming its events in the same run.
In an ordinary agent tree, the runner checks every handoff — from a model's transfer_to_agent call, a tool's actions, or a custom agent's event — against the source agent's sub-agents, its parent unless Agent::allows_transfer_to_parent says no, and its parent's other sub-agents unless Agent::allows_transfer_to_peers says no (Runner::allowed_transfer_targets); a refused handoff is logged and control stays with the source. Validated composite roots can provide an exact per-member transfer allowlist through the Agent policy hooks; the runner reports undeclared targets or depth overflow as errors. After allowlist and depth validation, the runner awaits Agent::govern_transfer before executing the target. The default allows the transfer; portable teams and other composite roots can deny it with a reason, which surfaces as agent.transfer.denied.
Run Lifecycle
| Stage | Guarantee |
|---|---|
| Identity | The run acts for its session's user; a run configured to act for another subject fails with identity.subject_mismatch unless subject_delegation allows it |
| Input screening | Every agent's input guardrails screen the user message before it is saved |
Plugin on_event |
Sees every event the run yields, including a before_run early exit, a cancelled run's answers to its calls in flight, and a budget stop event |
| Cancellation | Runner::interrupt(session_id) stops a run; each call still in flight is answered {"status": "outcome_unknown"}, persisted, and yielded |
| Steering | Runner::steer(identity, content) screens a message like the run's own and queues it on that run; an agent takes it after a tool step and the runner saves it as a user event, or its SteerReceipt returns it when the run ends first. adk-surface's send and steer commands, Kernel::steer and the kernel's chat gateway call it for a message that arrives while a turn runs |
Plugin after_run |
Runs once for every run whose before_run ran, however it ends — including a consumer that drops the stream, whose calls in flight are answered outcome-unknown first. A durable attempt its worker drops writes nothing; the recovering worker finishes the run |
Runner::close |
Closes every agent's toolsets through Agent::close, then the plugins |
Runner::prewarm |
Calls Agent::prewarm on the root agent — LlmAgent opens its model's pooled connection with Llm::prewarm, a harness also starts its MCP servers — and with Prewarm::session reads the session, refusing an archived one; refused while frozen, stopped by Prewarm::budget (10 s by default); sends no prompt |
Runner::recover_unanswered_calls answers function calls a stopped process left unanswered from the action ledger (already_succeeded, already_failed, or outcome_unknown) without executing them.
Run Budgets
RunnerConfigBuilder::budget(RunBudget) limits model calls, total tokens, cost, wall time, and tool calls. Each run gets a fresh BudgetTracker, shared with transfer targets, workflow sub-agents, and agent tools through the run config. Limits are checked before every model call and tool dispatch; a run that reaches one ends with a persisted event explaining why and an AdkError with category ResourceExhausted. Under a cost cap, a response with no known cost stops the run unless RunBudget::allow_unpriced_models() is set.
use Arc;
use ;
use Runner;
use SessionService;
Spend Ledger
When RunConfig::spend_ledger is set, every model call of the run — agent turns, compaction summaries (session compaction and auto-compaction), LLM routing, and MCP sampling — reserves its upper-bound cost (Llm::max_cost_micro_usd) before it is sent and commits its reported UsageMetadata::cost, keyed by app, agent, and vendor, through adk_core::ModelCallScope. A reservation the ledger refuses fails the call with spend.limit_exceeded, so a capped run never spends past its cap. Runner::with_llm_spend_estimate sets what an unpriced call commits when it reports no cost. See Spend Ledger.
Model History After Overlapping or Interrupted Turns
- Actual results: late tool responses are paired with their calls before a later user turn.
- Missing results: unresolved calls from earlier turns are omitted from model history; no result is fabricated.
- Current execution: unresolved calls at the history tail remain available for tool execution and confirmation.
- Persistence: source session events are unchanged by this projection.
temp: state keys stay visible for the rest of their invocation — to later tools, transferred agents, and {temp:key} instructions — and session services drop them when they persist the event.
Session History
runner.history_control() forks, rewinds, and edits sessions under the runtime's rules: it
refuses a session while a turn runs on it (session.history.run_active), across every runner
sharing a SessionActivity (RunnerBuilder::session_activity) and the durable run store, and
records a decision and an outcome per operation in the runner's audit trail.
RewindTarget::BeforeInvocation undoes a turn. See
Fork, Rewind, and Edit History.
Context Compaction
use Arc;
use LlmEventSummarizer;
use ;
use ;
use SessionService;
Compaction runs after each invocation completes. When the session's count of user events is a multiple of the interval, older events are summarized into a single compacted event, and MutableSession::conversation_history() uses the most recent summary instead of the original events. No compaction covers a tool call still held for confirmation: session compaction and auto-compaction both stop before it, so its approval can still resume it.
Auto-compaction is on by default. Before every model call, LlmAgent and CodeActAgent pass their history to the compactor the runner installs on RunConfig::history_compactor (IntraInvocationCompactor); once the request passes 80% of the model's context window (Llm::context_window), or 100,000 estimated tokens when the model reports none, all but the most recent history entries (at most 10, within half the threshold) are summarized by the agent's model — by its provider when the model compacts natively (Llm::native_compaction, such as Claude on the Claude API), whose signed result then opens later requests — and the compaction is recorded in the session so later runs start from the summary. A request the model rejects as too long is compacted and sent once more. See Context Compaction. BaseEventsSummarizer and EventsCompactionConfig are re-exported from adk-core.
See Context Compaction for the full guide.
Changes in 3.0
| Change | Migration |
|---|---|
RunnerConfig gains tool_policy, egress_policy, governance, action_ledger, approval_store, spend_ledger, durable_runs, audit, identity_source, and subject_delegation |
Set them to None in struct literals, or use Runner::builder() |
Agents compact their history before every model call, on by default; the runner no longer compacts once before the agent runs or retries agent.run() on a token-limit error |
without_intra_compaction() turns it off; intra_compaction_config(IntraCompactionConfig::at_tokens(n)) keeps a fixed threshold |
adk_runner::Callbacks and its callback aliases are removed; runner plugins' agent, model, and tool callbacks now run |
Register callbacks on the agent builder or as plugins |
| Every transfer obeys the source agent's restrictions | — |
A cancelled run persists outcome_unknown answers to its in-flight calls |
— |
| Nested agents' input guardrails screen every user message before it is saved | — |
A run acting for a subject other than its session's user fails with identity.subject_mismatch |
Configure subject_delegation |
Runner::close, Runner::cancel_durable_runs, Runner::recover_unanswered_calls, Runner::allowed_transfer_targets, and Runner::steer are new |
— |
See the 2.x to 3.0 migration guide and the changelog for the full list.
Related Crates
- adk-rust — umbrella crate
- adk-core — core traits
- adk-agent — agent implementations
- adk-session — session storage
- adk-artifact — artifact storage
- adk-cli — console and server launcher
License
Apache-2.0
Part of ADK-Rust
This crate is part of the ADK-Rust framework for building AI agents in Rust.