Examples#

Small, complete programs you can run, read, and copy. Each one uses the real runtime with a deterministic adapter, so it produces the same output without credentials — and teaches framework behavior rather than model quality.

Start with Your first agent, then build your own extension in Write your first extension. For a real provider, follow Connect a model provider.

Streaming tools

Watch a tool call, its result, and the final answer in one stream.

Stream a tool round trip
Sessions

Restore a conversation from SQLite in a new process.

Restore SQLite history
On-demand skills

Read one skill’s instructions through a real tool round trip.

Load tools and skills on demand
Compaction

Replace older turns with a checkpoint when context grows.

Compact without losing history
Approval

Pause a privileged tool until the UI answers.

Pause for external approval
Observability

Record model usage, cache counts, and message timing for diagnostics.

Observe usage and timing
Subagent

Delegate one task to a child profile with its own tools.

Run an isolated child agent
Background subagents

Start children without waiting, then read their reports.

Run subagents in the background
Cancellation

Stop mid-stream and keep the runtime reusable.

Cancel and reuse an agent
Goal mode

Keep working until an evaluator agrees the goal is met.

Iterate toward a goal
Storage adapter

Back sessions with your own storage implementation.

Connect a storage adapter

Run every offline example with make docs-examples. Tests disable network connections and use a temporary working directory for each program.