Which example should I start with?
- First time using AFK? Start with Minimal Chat Agent. It shows the absolute simplest agent run in under 10 lines of code.
- Need to gate dangerous actions? Go to Policy + HITL. It demonstrates how policy engines and human approval work together.
- Building a multi-agent system? See Subagent Router. It shows how to delegate work to specialist subagents and merge results.
- Need to persist and resume runs? Check Resume + Compact. It covers checkpoint-based resumption and memory compaction.
- Using LLMs without the agent loop? See Structured Output. It shows how to use
LLMBuilderdirectly with Pydantic models. - Locking down tool capabilities? Go to Tool Security. It demonstrates scoped tool registration and policy gates.
Complexity progression
| Level | Example | What You Learn |
|---|---|---|
| Beginner | Minimal Chat Agent | Agent + Runner basics, final_text access |
| Beginner | Structured Output | Direct LLM usage, Pydantic schema validation |
| Intermediate | Policy + HITL | Policy engine, approval flows, interaction modes |
| Intermediate | Tool Security | Tool scoping, sandbox profiles, policy gates |
| Intermediate | Hooks + Middleware | Pre/post tool execution hooks, middleware chains |
| Intermediate | Runtime Tools | Built-in file, search, and command tools |
| Intermediate | Prompt Loader | External prompt files, template variables |
| Advanced | Subagent Router | Multi-agent coordination, delegation patterns |
| Advanced | Resume + Compact | Checkpointing, memory management, long-running workflows |
| Intermediate | Streaming + Memory | Real-time streaming with multi-turn thread persistence |
| Intermediate | Cost Monitoring | Budget limits, real-time cost tracking, batch budgets |
| Advanced | MCP Client | Connect to external MCP servers, hybrid local+remote tools |
| Advanced | Multi-Model Fallback | Fallback chains, circuit breakers, model tier strategies |
Scenario catalog
Minimal Chat Agent
The simplest possible AFK agent. Define an agent, run it synchronously, and
read the output. Start here.
Policy + HITL
Gate sensitive actions through a policy engine and route approval requests
to a human operator.
Subagent Router
Delegate workload to specialist subagents using a coordinator pattern. Merge
outputs into a unified response.
Resume + Compact
Checkpoint a run, resume it later from the last known state, and compact
memory to control storage growth.
Structured Output
Use the LLM builder directly (without the agent loop) to get
schema-validated structured responses via Pydantic.
Tool Security
Register destructive tools with tight scoping, enforce sandbox profiles, and
gate actions through policy.
Hooks + Middleware
Attach pre-execution and post-execution hooks to tools. Chain middleware for
logging, validation, and transformation.
Runtime Tools
Use AFK’s built-in file reading, directory listing, and command execution
tools with agents.
Prompt Loader
Load system prompts from external files with template variable substitution
and automatic caching.
Streaming + Memory
Combine real-time streaming with thread-based memory for multi-turn chat
UIs.
Cost Monitoring
Track and control agent costs using FailSafeConfig budgets and telemetry
events.
MCP Client
Connect to external MCP servers, discover tools, and combine with local
tools.
Multi-Model Fallback
Configure fallback model chains for LLM resilience, circuit breakers, and
cost optimization.