Skip to main content
Use Agent.Run when you want a final result without live token deltas. It returns an AgentRun handle immediately; the work continues in the background until you wait with Get or Done.

AgentRun methods

Wait for the result

Call Get right after Run — it waits until the agent finishes:
Full walkthrough: Quickstart. Runnable example: Simple Agent.

Non-blocking Run

Wait on Done() (or multiplex with other work), poll Status, optionally Cancel, then Get:
Cancelling the Get context only unblocks the waiter — use AgentRun.Cancel to cancel the agent run itself. Full example with approvals: Non-blocking Run.

Reconnect with GetAgentRun

On a durable runtime (Temporal or Restate), persist agentRun.ID() before waiting. After a process crash, reconnect and wait again — the run keeps executing server-side:
Cancelling the GetAgentRun or Get context does not cancel the durable run — use AgentRun.Cancel for that. After reconnect, WithTimeout (if set) starts fresh — it is not the remaining time from the original Run. Full cancel/timeout rules: Timeouts & Modes. LocalRuntime cannot reconnect after a crash (ErrRunNotFound). Full protocol: Durable Execution.

Approvals on Run

Use WithApprovalHandler for interactive tool approval during Run (same as a blocking Run + Get). Stream-based approval uses CUSTOM events on AgentStream — see Approvals.

Examples

Simple Agent

Blocking Run + Get

Non-blocking Run

Status, Cancel, Done, Get, and approvals

Streaming

AgentStream, Events, and live tokens