Agent runtime#

Understand request ownership, phases, and runtime limits.

Read the walkthrough before consulting individual signatures.

Public interfaces#

Interface

Purpose

Agent

Run a model, execute requested tools, and repeat until an answer is ready.

AgentRunConfig

Identify a conversation and optionally one request within it.

AgentRunContext

Per-run references shared by all lifecycle hooks.

AgentState

Mutable conversation state created independently for one request.

AgentEventQueue

Carry one run’s ordered events from the runtime task to Agent.stream.

AgentError

Base exception for runtime and provider errors.

AgentIterationLimitError

The model/tool loop exceeded its configured limit.

AgentProtocolError

A model stream did not produce exactly one final response.

AgentResumeError

A session has nothing that can be resumed, or what it has cannot be picked up again.

AgentStopError

A model step ended for a reason other than finishing, and the caller asked to be told.

new_uuid7

Return a time-ordered UUIDv7 string for persisted runtime records.

ResumeKind

What resuming does, which depends on how the request was interrupted.

ResumePoint

Where a session was interrupted and what resuming it will do.

classify_resume

Read where a history was interrupted from its last message.

StopInfo

Why one model step stopped, normalized, with what the provider said kept.

StopReason

Provider-neutral reason a model step ended.

classify_stop

Turn a provider’s raw stop value into a StopInfo.

SyncAgent

An initialized Agent callable from ordinary synchronous Python code.

SyncModelAdapter

Use a model whose stream(request) returns an ordinary synchronous iterator.

create_agent_sync

Create a synchronous Agent with the same options as create_agent.

SyncContext

Adapt async with to ordinary with without changing the yielded value.

SyncObject

A blocking view of an existing Agent, provider, tool, or storage object.

SyncRuntime

Own one background event loop for all blocking calls in a scope.

SyncStream

Pull async events synchronously, preserving one task and bounded memory.