Skip to main content
This tutorial expands the quickstart into the core workflow used by most AFK applications. Each section introduces one concept and keeps the code small enough to copy into a single file.

1. Agent + runner

Key point: an agent is declarative. The runner owns execution.

2. Typed tools

Key point: tool arguments are validated before your function runs.

3. Streaming

Use streaming when a UI or CLI should show progress before the final result is ready.
Key point: run_stream() returns an AgentStreamHandle. Consume it to receive text, tool lifecycle events, errors, and the terminal result.

4. Memory continuity

Pass the same thread_id to keep conversation context attached to a thread.
Key point: thread continuity is explicit. Use the same thread_id for related turns.

5. Safety limits

Production agents need hard limits even when prompts and tools are well designed.
Key point: limits are part of the agent contract. Set them before shipping.

Agents

Agent fields, prompt resolution, subagents, skills, and MCP tools.

Tools

Tool schemas, context, hooks, middleware, sandboxing, and output limits.

Streaming

Event types, stream handles, cancellation, and UI patterns.

Production Readiness

Evals, telemetry, security controls, queues, and deployment.