Skip to main content
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

Output from one run, shortened:
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:
Output:
  • swarm_type is any SwarmType except "AutoSwarmBuilder" and "auto". A spec naming either is rejected.
  • rearrange_flow is set only when the boss picks AgentRearrange.
  • task is 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

With auto_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.
Output from one run, with each haiku cut to its first line:
  • agents lists the names of the agents that actually ran, built from the same spec that is reported back.
  • The router runs with output_type="dict", so output is the conversation as a list of messages, each with role, content, timestamp and message_id.
  • The router gets the builder’s max_loops.
  • The spec’s rules and multi_agent_collab_prompt are not applied. SwarmRouter logs that it ignored rules.
  • builder.usage adds 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:
This prints [('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:
The boss followed the model named in the task, and the run printed 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.
The boss chose 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.
Output:
The boss is not told about 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 with additional_llm_args.
  • batch_run(tasks) calls run() on each task in turn and returns a list of results.

Next steps