Overview
TheAutoAgentBuilder class turns a plain-English task into a roster of agents. A single builder agent is forced to call one function, build_agents, and must answer with a list of agent configurations rather than prose.
Each generated agent carries exactly four fields — the minimum needed to construct an Agent:
Because the provider enforces the tool schema, there is no markdown fence to strip and no JSON to extract from a paragraph. This is the main behavioral difference from
AutoSwarmBuilder, which uses structured output and also selects a swarm_type for you.Class Definition
Parameters
str
default:"auto-agent-builder"
Name of this builder instance
str
default:"Generates agent configurations from a task"
What this builder is for
str
default:"gpt-5.4"
Model backing the builder agent itself. This is not the model given to the generated agents — the builder chooses those per agent. Must support function calling
int
default:"5"
Upper bound on roster size. This is a ceiling, not a target — the builder is instructed to prefer the smallest roster that covers the task, so it will routinely return fewer. Must be >= 1
Optional[int]
default:"None"
Exact number of agents to generate. When set, overrides
max_agents and the builder’s prefer-fewer guidance, and the count is verified on the result. Must be >= 1str
default:"AUTO_AGENT_BUILDER_SYSTEM_PROMPT"
Instructions for the builder agent. Override to constrain the roster — force a model tier, require a specific role, or restrict the decomposition strategy
Optional[Dict[str, Any]]
default:"None"
Extra keyword arguments forwarded to every generated
Agent, e.g. max_loops or streaming_on. Keys that collide with the four generated fields are ignored. Unused when return_dict is True, since no agent is constructedbool
default:"False"
When True,
run() returns the raw configuration dicts instead of constructed Agent objects. Use this to inspect, serialize, or edit the roster before building anything from itbool
default:"False"
Whether to log the generated roster
ValueError: Ifmax_agentsornum_agentsis less than 1
Roster size: ceiling vs exact count
This is the setting most likely to surprise you.
The default system prompt actively pushes the count down — it states that “fewer is almost always better” and that “2–3 agents is the common, correct case for most tasks.” So
max_agents=5 returning three agents is the builder working correctly, not a failure.
Methods
run()
str
required
The task the generated team should be able to handle
Union[List[Agent], List[Dict[str, str]]]
Configuration dicts when
return_dict=True, otherwise constructed Agent objectsValueError: Iftaskis empty, or the builder returns no usable agent configurations
build_agents()
Agent objects. Ignores return_dict — this is the shape-specific entry point for callers that want agents regardless of how the builder was configured.
Returns:
List[Agent]
Constructed agents, ready to run or hand to a multi-agent structure.
agent_kwargs is applied to eachbuild_configs()
return_dict.
Returns:
List[Dict[str, str]]
One dict per agent with
name, description, system_prompt and model_name. Truncated to num_agents or max_agents__call__()
run(). Follows return_dict.
Output shapes
One LLM call per method
Every public method triggers a fresh call, and the builder is not deterministic. Callingbuild_configs() and then build_agents() designs two different rosters — so what you printed may not be what you ran.
Generate once and reuse the result:
Validation behavior
The builder filters the model’s output before returning it:
Tool calls are parsed from all shapes providers return: a plain dict, a list-wrapped dict, or an attribute-style object such as litellm’s
ChatCompletionMessageToolCall.
Usage Examples
Inspect the roster before building
Build and run in sequence
Compose with SwarmRouter
The builder answers who is on the team;SwarmRouter answers how they run.
MixtureOfAgents, HierarchicalSwarm, GroupChat, or anything else that accepts one.
Constrain the roster with a custom prompt
The builder system prompt
The default prompt is exported and can be imported, extended, or replaced:Comparison with AutoSwarmBuilder
Use
AutoAgentBuilder when you want the roster and full control over what runs it. Use AutoSwarmBuilder when you want the whole pipeline decided for you.
Requirements
The builder needs a model that supports function calling, plus a provider key:model_name on the configs before constructing.