Skip to main content

Overview

The AutoSwarmBuilder class automatically builds and manages swarms of AI agents by intelligently decomposing tasks and creating specialized agents as needed. It uses a sophisticated boss agent system to delegate work, design agent architectures, and orchestrate multi-agent collaboration.

Class Definition

Parameters

str
default:"auto-swarm-builder"
The name of the swarm builder instance
str
default:"Auto Swarm Builder"
A description of the swarm builder’s purpose
bool
default:"True"
Whether to output detailed logs during execution
int
default:"1"
Maximum number of execution loops. Must be greater than 0
str
default:"gpt-4.1"
The LLM model to use for the boss agent that designs the swarm architecture
bool
default:"False"
Whether to generate SwarmRouter configuration (legacy parameter)
bool
default:"False"
Whether to enable interactive mode
int
default:"8000"
Maximum tokens for the LLM responses from the boss agent
str
default:"return-agents"
Type of execution to perform. Options: “return-agents”, “return-swarm-router-config”, “return-agents-objects”
str
default:"BOSS_SYSTEM_PROMPT"
System prompt for the boss agent that designs swarm architectures. Defaults to comprehensive agent design prompt
dict
default:"{}"
Additional arguments to pass to the LiteLLM wrapper

Execution Types

return-agents

Returns agent specifications as a dictionary:

return-swarm-router-config

Returns complete SwarmRouter configuration:

return-agents-objects

Returns instantiated Agent objects ready for use:

Methods

run()

Runs the swarm builder on a given task, creating agents based on execution type. Parameters:
str
required
The task to execute. The boss agent will analyze this task and design an appropriate swarm architecture
Returns:
Any
The result depends on execution_type:
  • “return-agents”: Dictionary with agent specifications
  • “return-swarm-router-config”: SwarmRouter configuration dictionary
  • “return-agents-objects”: List of instantiated Agent objects
Raises:
  • ValueError: If execution_type is invalid
  • Exception: If there’s an error during swarm execution

create_agents()

Creates agent specifications for a given task using the boss agent. Parameters:
str
required
The task to create agents for
Returns:
dict
Dictionary containing agent specifications with comprehensive system prompts and configurations
Raises:
  • Exception: If there’s an error during agent creation

create_agents_from_specs()

Creates Agent objects from agent specifications. Parameters:
Any
required
Dictionary or Pydantic model containing agent specifications
Returns:
List[Agent]
List of instantiated Agent objects ready for use
Note: Automatically handles parameter name mapping (e.g., ‘description’ → ‘agent_description’)

create_router_config()

Creates a SwarmRouter configuration for a given task. Parameters:
str
required
The task to create router configuration for
Returns:
dict
Complete SwarmRouter configuration including agents, swarm type, and execution parameters
Raises:
  • Exception: If there’s an error during router config creation

batch_run()

Runs the swarm builder on a list of tasks sequentially. Parameters:
List[str]
required
List of tasks to execute
Returns:
List[Any]
List of results from each task execution

reliability_check()

Performs reliability checks on the AutoSwarmBuilder configuration. Raises:
  • ValueError: If max_loops is set to 0

list_types()

Lists all available execution types. Returns:
List[str]
List of available execution types

Data Models

AgentSpec

SwarmRouterConfig

Boss Agent Design Principles

The AutoSwarmBuilder uses a sophisticated boss agent with expertise in:
  1. Comprehensive Task Analysis: Deconstructing tasks into components and sub-tasks
  2. Agent Design Excellence: Creating agents with clear purposes and complementary personalities
  3. System Prompt Engineering: Crafting detailed prompts with role, capabilities, and protocols
  4. Multi-Agent Coordination: Designing communication channels and task handoff procedures
  5. Quality Assurance: Establishing success criteria and validation procedures

Usage Examples

Basic Agent Creation

Create Agent Objects

Generate SwarmRouter Config

Batch Processing

Advanced Features

Custom System Prompt

Additional LLM Arguments

Multi-Agent Architecture Types

The boss agent can design swarms using various architectures:
  • AgentRearrange: Dynamic task reallocation
  • MixtureOfAgents: Parallel specialized processing
  • SequentialWorkflow: Linear task progression
  • ConcurrentWorkflow: Parallel execution
  • GroupChat: Collaborative discussion
  • HierarchicalSwarm: Layered decision-making
  • HeavySwarm: High-capacity specialized processing
  • MajorityVoting: Democratic decision-making
  • And more…

Source Code

View the source code on GitHub