Skip to main content
The Agent API owns conversation state. It is one resource with two ways to call it: the TypeScript SDK’s aomi.agent surface, or the versioned REST resource at /v1/agent for any other language. Both are documented on this page. The SDK runs this loop for you — agent.run() starts the turn, hydrates ordered event pages, and follows the event stream until a terminal state. Provisional streamed text does not advance the durable cursor. A raw HTTP caller drives the same loop directly with the endpoints in the Agent REST API reference. The TypeScript snippets assume an aomi instance created with the Client SDK quickstart or OAuth device flow.

Run a turn

AgentRun is Promise-like. You can await it directly or call result().

Observe a run

Attach listeners immediately after creating the run:

Continue a conversation

Pass the same sessionId to each turn:
An Agent session is the persisted conversation. It is not the guest or OAuth credential used to authorize the caller.

Communicate wallet context with UserState

Each turn can carry a UserState — the contractual snapshot of the caller’s wallet context that the harness builds and signs against:
When you configure wallet: on the Aomi constructor, the SDK derives this from the adapter automatically, so most integrations never build it by hand. Pass it explicitly when your application tracks the connection itself. The contract is strict and schema-validated on the backend — a userState with unknown fields is rejected: Use UserState for wallet context only. Read wallet requests from typed Actions and, on environments supporting durable execution, Commit views. A current transaction review can arrive in EventPage.commits and the session snapshot rather than as an action event. See durable transaction reviews before integrating transaction execution.
Account abstraction and sponsorship are deliberately not part of UserState. They are backend authority, resolved per execution — the client never sends or stores them.

Choose Auto or Direct routing

Omit target to use Auto routing. Select one deployed App explicitly for Direct routing:
The SDK converts target to the wire mode and App selector fields. An App’s canonical Application ID is distinct from a Pipeline catalog slug, session ID, or OAuth identity. Use an ID returned by your environment’s App catalog.

Interrupt work

Manage sessions

Session management is available through the wire-close client on the same Aomi instance:
Use cursor pagination for user-facing session lists. Use sessions.all() only when the complete list is small enough to load into memory. Renaming, archiving, and deleting sessions require the scopes configured for the signed-in account; staging guest access can be read-only.

Handle actions

For typed Agent Actions, review the request, then resolve or reject it. Durable transaction Commits use the separate controller described in Wallet and signing:
See Wallet and signing for wallet adapters and review boundaries.

Handle errors

Failed Agent calls throw a typed AgentApiError:
AgentApiError exposes: Retry only when retryable is true, reuse the same idempotency key when retrying one logical mutation, and never retry a wallet signature prompt without showing the user the exact current request again. For 401/403 failures, see Authentication failures.

Call the REST resource directly

Not using TypeScript, or already own OAuth token acquisition? The same resource is documented endpoint by endpoint in the Agent REST API reference.
Last modified on September 2, 2026