Skip to main content

Overview

The AdvisorSwarm implements the advisor strategy described in Anthropic’s research (April 2026). It pairs a cheaper executor model that drives the task end-to-end with a powerful advisor model consulted on-demand between executor turns. The executor runs every turn. The advisor is on-demand — consulted between executor turns when budget allows. Both agents read from and write to the same shared conversation context. The advisor never calls tools or produces user-facing output. This is provider-agnostic: any model supported by LiteLLM works for either role. The swarm follows this workflow:
  1. The shared conversation is cleared, then the user task is added to it
  2. Before each executor turn, the advisor reads the full shared context and provides guidance (if budget allows)
  3. The executor reads the full shared context (including any advisor guidance) and produces output
  4. Both advisor guidance and executor output are added to the shared conversation
  5. Repeat for max_loops executor turns

Installation

Key Features

Attributes

str
default:"None"
Unique identifier for this swarm instance. Auto-generated via generate_id("advisor-swarm") if not provided, producing advisor-swarm-<32 hex chars>.
str
default:"AdvisorSwarm"
Human-readable name
str
default:"An executor-advisor swarm..."
Description of the swarm’s purpose
str
default:"claude-sonnet-4-6"
Model for the executor agent
str
default:"claude-opus-4-6"
Model for the advisor agent
str
default:"Built-in"
System prompt for the executor
str
default:"Built-in"
System prompt for the advisor
int
default:"3"
Max advisor consultations per run(). 0 = executor runs alone.
int
default:"1"
Number of executor turns
OutputType
default:"dict-all-except-first"
Format for the returned conversation history, such as "dict", "str", "list", "final", "json" or "yaml"
bool
default:"False"
Enable detailed logging
Agent
default:"None"
Pre-configured Agent for execution (e.g., with tools or MCP). When set, executor_model_name, executor_system_prompt and tools are not applied to it
Agent
default:"None"
Pre-configured Agent for advising. When set, advisor_model_name and advisor_system_prompt are not applied to it
List[Callable]
default:"None"
Tools for the built-in executor agent only. The built-in advisor never gets tools
Raises:

Methods

run()

Execute the advisor-executor orchestration flow.
Parameters:
  • task (str): The task to accomplish. Required; an empty or missing task raises ValueError("A task is required")
  • img (str, optional): Optional single image input, passed to the executor
  • imgs (List[str], optional): Optional list of image inputs, passed to the executor
Returns: Formatted conversation history according to output_type Each call clears the shared conversation first, so reusing one swarm for several tasks does not carry the previous task’s transcript forward.

batched_run()

Run the swarm on multiple tasks, one after another.
Parameters:
  • tasks (List[str]): List of task strings
Returns: List of results, one per task, in task order

__call__()

Calling the swarm instance runs run(task=task).

Usage Examples

Basic Usage

Multi-Turn with Advisor Guidance

Run the executor for multiple turns, with the advisor providing guidance before each:

Custom Executor with Tools

Pass a pre-configured executor agent with tools while keeping the advisor tool-free:

Executor Only (No Advisor)

Set max_advisor_uses=0 to run the executor alone:

Different Providers

The swarm is provider-agnostic. Use any models LiteLLM supports:

Architecture Details

Shared Context

Both agents read from and write to the same Conversation object. This mirrors the Anthropic diagram where the advisor reads the same context as the executor. The conversation reaches each agent as typed chat turns, not as one pasted string: the agent’s own earlier messages arrive as assistant turns, and everyone else’s arrive as user turns labelled with the speaker’s name (for example Executor: ...). On each turn:
  1. The advisor receives the shared conversation as turns — it sees everything so far
  2. The advisor’s final answer is added to the conversation under the Advisor role
  3. The executor receives the shared conversation as turns — the task, any prior output, and the advisor’s guidance
  4. The executor’s final answer is added to the conversation under the Executor role
Only each agent’s final message is recorded, not the full transcript that Agent.run returns for its output_type.

Advisor Budget

The max_advisor_uses parameter controls how many times the advisor is consulted:

Multi-Turn Execution

When max_loops > 1, the executor runs multiple turns. Each turn, it reads the full conversation — including its own previous output and any advisor guidance — so it can build on prior work. The advisor’s budget is distributed across turns: it is consulted before each executor turn until the budget is exhausted.

Source Code

View the source code on GitHub