Overview
TheMixtureOfAgents class manages and executes multiple agents in parallel layers, aggregating their responses through a specialized aggregator agent. This architecture enables sophisticated multi-perspective analysis by running agents concurrently and synthesizing their outputs.
The aggregator reads every worker answer from every layer as a separate, labelled chat turn. With more than one layer, each label carries the layer, for example Analyst (layer 2/3), so the aggregator can tell a refinement from a first pass.
Class Definition
Parameters
str
default:"auto-generated"
Unique identifier for the mixture of agents instance. Auto-generated via
generate_id("mixture-of-agents") if not provided, producing mixture-of-agents-<32 hex chars>.str
default:"MixtureOfAgents"
The name of the mixture of agents
str
A description of the mixture of agents purpose and functionality
List[Agent]
default:"None"
A list of reference agents to be used in the mixture. These agents will be executed in parallel layers. An empty list raises
ValueErrorAgent
default:"None"
The aggregator agent to be used for synthesizing responses from all agents. If None, a default aggregator agent will be created
str
default:"AGGREGATOR_SYSTEM_PROMPT_MAIN"
The system prompt for the aggregator agent that guides how responses are synthesized
int
default:"3"
The number of processing layers to execute. Each layer runs all agents and passes context forward
int
default:"1"
Stored for compatibility with other swarm classes. It does not change how many times the workers or the aggregator run; use
layers for more worker roundsOutputType
default:"final"
Output format type.
"final" returns the aggregator’s answer; "all", "list", "dict" and the other OutputType values return the whole conversation in that formatstr
default:"claude-sonnet-4-20250514"
The model name for the aggregator agent
int
Cap on concurrent worker agents per layer. When omitted, the pool uses 95% of
the available CPU cores.
Dict[str, Any]
Extra keyword arguments forwarded to the aggregator
Agent when one is built
for you.Methods
reliability_check()
ValueError: If no agents are providedValueError: If no aggregator system prompt is providedValueError: If no layers are specified
step()
run() records the results.
Parameters:
str
required
The task to be executed by all agents
str
Optional image input for the task
Dict[str, str]
Dictionary mapping agent names to their final answers. Each value is the agent’s last message, not its whole transcript
run()
str
required
The task to be executed by the mixture of agents
str
Optional image input for the task
str
The aggregated response from all agents after processing through all layers
run() catches exceptions internally and returns the string "Error: {e}" instead of raising, so callers should check the returned value rather than wrapping the call in a try/except.- Starts a fresh conversation, so a reused instance does not carry the previous task into the next one, and adds the task
- For each layer:
- Runs all agents concurrently. The first layer receives the task; later layers receive the original task plus the previous layer’s answers, each prefixed with the agent’s name, not the full transcript
- Adds each agent’s answer to the conversation. When
layers > 1the speaker is labelled with the layer, for exampleResearch-Agent (layer 1/3)
- Runs the aggregator on the conversation, passed as chat turns: the task, then every labelled worker answer. The team roster is left out
- Adds the aggregator’s answer to the conversation and returns the conversation formatted by
output_type
run_batched()
List[str]
required
A list of tasks to be executed by the mixture of agents
List[str]
A list of aggregated responses from the mixture of agents, one for each task
run_concurrently()
List[str]
required
A list of tasks to be executed concurrently
List[str]
A list of aggregated responses from the mixture of agents, in task order
Usage Example
Architecture
The MixtureOfAgents architecture works as follows:- Layer Processing: Each layer runs all agents concurrently. The first layer sees only the task; each later layer sees the task plus the previous layer’s answers
- Context Accumulation: Agent answers are added to the conversation after each layer, labelled with the agent and, when
layers > 1, the layer - Iterative Refinement: Subsequent layers build upon previous outputs, enabling deeper analysis
- Final Aggregation: The aggregator reads every labelled answer from every layer as chat turns and synthesizes them into one final output