Your first agent
model is the only required constructor argument, but name and instructions make traces and behavior easier to understand.
Agent fields reference
Single agent vs multi-agent
- Single agent
- Multi-agent
A single agent handles everything. Best for focused tasks.Use when: The task is well-defined and doesn’t need specialized sub-expertise.
How subagent delegation works
When an agent has subagents, AFK automatically generates transfer tools (transfer_to_researcher, transfer_to_writer). The coordinator calls these like any other tool.
Each subagent runs a full agent loop with its own model, instructions, and tools. The coordinator sees only the subagent’s final_text.
Adding safety limits
Every agent should have aFailSafeConfig in production:
Policy-aware agents
Attach a PolicyEngine to control what the agent can do:allow (default), deny, request_approval (human-in-the-loop), or request_user_input.
Design guidelines
- Start with one agent. Only add subagents when you have clear evidence that the task needs specialized expertise.
- Keep instructions focused. Vague instructions produce vague results. Tell the agent exactly what to do and what not to do.
- Use typed tools. Every tool argument should be a Pydantic model. Untyped arguments bypass validation.
- Set cost limits early. Add
FailSafeConfigbefore your first deployment, not after your first runaway bill.
Next steps
Core Runner
How agents are executed — lifecycle, API modes, and state management.
Tools
Define typed tool functions with validation and policy gates.