AutoSwarmBuilder designs a multi-agent team for you. You describe the task; a boss model replies with a spec: the agents, each with a name, description, system prompt and model, plus the architecture to run them in, such as SequentialWorkflow. You can stop at the spec and review it, turn it into Agent objects, or have the builder run it through a SwarmRouter straight away.
Reference: AutoSwarmBuilder.
What run() returns
run(task) returns one of four things:
Here
swarm_type picks what the builder returns, not the architecture. The boss model picks the architecture.
The boss’s reply is parsed as JSON and checked against a schema. A bad reply is sent back to the boss with the error, up to max_json_repair_attempts times (1 by default), before run() raises ValueError.
1. Design a team
model_name on the builder sets the boss model only. The boss chooses a model_name for each agent it designs, here gpt-4o-mini. A spec without one gets gpt-5.4. Each spec also has system_prompt, max_tokens, temperature, max_loops, role, goal and auto_generate_prompt.
2. Get the full swarm spec
"return-swarm-router-config" adds the architecture and the team’s name to the agents:
swarm_typeis any SwarmType except"AutoSwarmBuilder"and"auto". A spec naming either is rejected.rearrange_flowis set only when the boss picksAgentRearrange.taskis always your exact task string, not the boss’s copy of it.- Two agents with the same name raise
ValueError.
3. Design and run in one call
Withauto_execute=True, run() builds the agents from the spec and runs them through a SwarmRouter. Pass execute=True or execute=False to run() to override it for one call.
agentslists the names of the agents that actually ran, built from the same spec that is reported back.- The router runs with
output_type="dict", sooutputis the conversation as a list of messages, each withrole,content,timestampandmessage_id. - The router gets the builder’s
max_loops. - The spec’s
rulesandmulti_agent_collab_promptare not applied.SwarmRouterlogs that it ignoredrules. builder.usageadds up the boss calls and every agent in every router the builder ran.
4. Review and edit the spec before running
To change the design before anything runs, take the spec, edit it, then build the agents and the router yourself. Here every agent is pinned to one model:[('Writer', 'gpt-5.4-mini'), ('Proofreader', 'gpt-5.4-mini')], then the proofread email. create_agents_from_specs() turns each spec’s description into the agent’s agent_description and raises ValueError on a repeated name.
5. Get ready-made Agent objects
"return-agents-objects" designs the team and builds the agents, but leaves running them to you:
SecurityReviewer (gpt-5.4-mini): and ReadabilityReviewer (gpt-5.4-mini):, each with a short review.
6. Pick an architecture for agents you already have
initialize_swarm_router() takes your own agents and asks the boss only to choose the architecture. The boss is told your agents’ names and descriptions, and the router runs your agents, not new ones.
SequentialWorkflow here, so the output shows the task, then the Researcher’s facts, then the Writer’s paragraph. The router uses output_type="dict" and the builder’s max_loops.
7. Limit the team size and the repair retries
max_agents and max_json_repair_attempts are attributes, not constructor arguments. Set them after construction, then call reliability_check() to validate them.
max_agents; the limit is checked after it replies. Say how many agents you want in the task as well, as the earlier examples do.
Tips
- Start with the spec. Run
"return-agents"or"return-swarm-router-config"first, read what the boss designed, then execute. - Name the team size and models in the task. The boss follows them, and it keeps runs small.
- Use a different boss prompt with
system_prompt, and pass extra arguments to the boss model withadditional_llm_args. batch_run(tasks)callsrun()on each task in turn and returns a list of results.
Next steps
- AutoSwarmBuilder reference
- SwarmRouter, which runs the generated team