Skip to main content
This catalog provides runnable code examples for every major AFK capability. Each example is self-contained and demonstrates a specific pattern — from the simplest possible agent run to advanced tool security configurations. The examples are ordered by complexity. If you are new to AFK, start at the top and work your way down. Each example builds on concepts introduced in the previous ones.

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 LLMBuilder directly with Pydantic models.
  • Locking down tool capabilities? Go to Tool Security. It demonstrates scoped tool registration and policy gates.

Complexity progression

LevelExampleWhat You Learn
BeginnerMinimal Chat AgentAgent + Runner basics, final_text access
BeginnerStructured OutputDirect LLM usage, Pydantic schema validation
IntermediatePolicy + HITLPolicy engine, approval flows, interaction modes
IntermediateTool SecurityTool scoping, sandbox profiles, policy gates
IntermediateHooks + MiddlewarePre/post tool execution hooks, middleware chains
IntermediateRuntime ToolsBuilt-in file, search, and command tools
IntermediatePrompt LoaderExternal prompt files, template variables
AdvancedSubagent RouterMulti-agent coordination, delegation patterns
AdvancedResume + CompactCheckpointing, memory management, long-running workflows
IntermediateStreaming + MemoryReal-time streaming with multi-turn thread persistence
IntermediateCost MonitoringBudget limits, real-time cost tracking, batch budgets
AdvancedMCP ClientConnect to external MCP servers, hybrid local+remote tools
AdvancedMulti-Model FallbackFallback chains, circuit breakers, model tier strategies

Scenario catalog