Configure the agent
Withmodel obtained from client.Model(...):
LLM is the configured provider and Instruction is a prompt provider; use NewPrompt for a string. Description tells other agents what this agent does when it appears in a sub-agent catalog.
Add Tools for Go functions, MCPClient for external tools, SkillClient for instruction libraries, and SubAgents for delegation. Middlewares wraps model/tool calls, prompts, and persistence. Multi-agent patterns explains how these agents compose.
Choose an execution method
Use
Run when you only need the final answer. Use Execute when the application consumes streaming events. There are no separate Start or Stream methods.
Wait for the result
Inside a function withctx and agent:
result.Status and result.Interrupts as well as Text(): a successful call can return a paused run rather than a final answer. Output contains the full typed message list, including non-text output.
Consume events
Wait, even after the event channel closes. One consumer should read Chunks. The handle has a bounded backlog of 256 events; if the consumer falls behind, Wait reports ErrStreamOverflow alongside any final result. The missing events cannot be reconstructed from that handle.
For a synchronous caller, avoid creating a streaming handle just to call Wait; Run does not subscribe to events.
Stop a run
Callhandle.Stop(ctx) or agent.Stop(ctx, streamID) with a live request context. Then wait for completion. handle.Cancel is an alias for Stop.
Stopping is cooperative. Built-in memory and Redis brokers support cancellation of active model and tool calls. Custom tools must honor their context. A tool that ignores cancellation may continue running after the agent stops waiting for it; stop is not a rollback of external side effects.
Identify a run
ThreadID, StreamID, and the incoming message ID are generated when omitted. The final result exposes RunID; choose a stable thread ID before calling if you need it afterwards. Persistence saves increments under the same run ID. Choosing a run ID does not by itself make repeated application submissions or tool side effects idempotent.
Bound work
AgentConfig.MaxLoops defaults to 50. It limits the agent’s model loop, not tokens, elapsed time, or cost. Use model output limits and request deadlines separately.
The lower-level agents.AgentOptions.SingleTurn is intended for evaluating a single model decision: it returns the model output without executing its tools. It is not exposed as a field on the root AgentConfig, and differs from MaxLoops: 1, which still executes the first round of tools.