Skip to main content
An Agent is a configuration object that describes what your AI agent is — its identity, capabilities, and boundaries. Agents don’t execute themselves; they’re run by a Runner.

Your first agent

Those are the fields most examples should set. 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

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 a FailSafeConfig in production:
Always set max_total_cost_usd in production. A runaway agent loop can spend significant API credits in minutes.

Policy-aware agents

Attach a PolicyEngine to control what the agent can do:
Policy decisions: 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 FailSafeConfig before 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.