AgentResult.
Quick example
Three API modes
- Sync
- Async
- Stream
Blocks until complete. Best for scripts, tests, and simple integrations.
Run lifecycle
Every agent run follows this state machine:Terminal states
| State | Meaning | final_text |
|---|---|---|
completed | Run finished successfully | Model’s response |
failed | Unrecoverable error occurred | Error message |
degraded | Partial result (some failures tolerated) | Best-effort response |
cancelled | Caller cancelled the run | Empty or partial |
interrupted | Timeout or external interrupt | Empty or partial |
The step loop
Each “step” is one iteration of the agent’s decision cycle:Build LLM request
The runner constructs an
LLMRequest with the conversation history, tool
schemas, and model configuration.Call the LLM
The request is sent through the LLM runtime (with retry, circuit breaker,
rate limiting, and caching policies).
Process response
If the LLM returns text only → the run is complete. If it returns tool
calls → proceed to tool execution.
Execute tools
Each tool call is validated, policy-checked, executed, and its output is
sanitized and fed back to the LLM.
Runner configuration
Run handles and lifecycle control
For advanced control, userun_handle():
Thread-based memory
Pass athread_id to maintain conversation context across runs:
Resume from checkpoint
Compact long threads
AgentResult reference
| Field | Type | Description |
|---|---|---|
final_text | str | The agent’s final response |
state | str | Terminal state: completed, failed, degraded, cancelled, interrupted |
run_id | str | Unique run identifier |
thread_id | str | Thread identifier for memory continuity |
tool_executions | list[ToolExecutionRecord] | All tool calls with name, success, output, latency |
subagent_executions | list[SubagentExecutionRecord] | All subagent invocations |
usage_aggregate | UsageAggregate | Token counts aggregate across LLM calls |
state_snapshot | dict[str, JSONValue] | Final runtime counters/snapshot metadata |
ToolExecutionRecord fields
AgentResult.tool_executions entries include:
| Field | Type | Description |
|---|---|---|
tool_name | str | Tool name |
tool_call_id | str | None | Tool call id from the model/provider |
success | bool | Execution success |
output | JSONValue | None | Tool output payload |
error | str | None | Error text (when failed) |
latency_ms | float | None | Tool latency |
agent_name | str | None | Agent that executed the tool (parent or subagent) |
agent_depth | int | None | Nesting depth where tool ran |
agent_path | str | None | Agent lineage path for nested calls |