Skip to main content
When a task is too complex for a single agent, AFK supports delegating subtasks to specialist subagents. The coordinator (or “lead”) agent decides what to delegate, and the runner handles dispatching work to subagents, collecting their results, and feeding those results back to the coordinator for synthesis. This pattern is useful for incident response, research workflows, content pipelines, and any scenario where different aspects of a task require distinct expertise or instructions.

Delegation flow

Example

How the coordinator pattern works

  1. The lead agent receives the user message and decides how to delegate. It can invoke subagents through tool-like calls that the runner intercepts.
  2. The runner dispatches each subagent invocation as a separate run. Subagents execute independently with their own instructions and model configuration. The runner manages concurrency, timeout, and failure handling for each subagent.
  3. Subagent results are returned to the lead agent as execution records. Each record contains the subagent’s output_text and optional error information.
  4. The lead agent receives all subagent outputs and synthesizes them into a unified response. This final synthesis step is what produces the coordinator’s final_text.

What subagent_executions contains

The AgentResult returned by the lead agent includes a subagent_executions list. Each entry is a SubagentExecutionRecord with: You can inspect these records to understand what each subagent contributed:

Subagent failure handling

By default, subagent failure policy is continue. You can configure stricter or more resilient behavior using FailSafeConfig:
With subagent_failure_policy="retry_then_degrade", the lead agent receives error information for failed subagents alongside successful results and can produce a best-effort synthesis.