Skip to main content
The MixtureOfAgents architecture runs multiple expert agents in parallel and synthesizes their diverse outputs through an aggregator agent. This collaborative approach achieves superior results through multi-perspective analysis.

When to Use

  • Complex problem-solving: Tasks requiring multiple expert perspectives
  • Quality through collaboration: Combine diverse viewpoints for better outcomes
  • State-of-the-art performance: Achieve highest quality through synthesis
  • Expert systems: Leverage specialized knowledge from multiple domains
  • Comprehensive analysis: Get well-rounded insights

Key Features

  • Parallel execution of expert agents
  • Automatic aggregation and synthesis
  • Multi-layer processing (optional)
  • Layer-labelled worker answers, so the aggregator knows who said what and in which round
  • Flexible output formatting
  • Conversation history tracking

Basic Example

Multi-Layer Processing

Use multiple layers for iterative refinement:
Each layer:
  1. Experts analyze their input, concurrently
  2. Each answer is added to the conversation, labelled with the expert and the layer, for example Market-Analyst (layer 2/3)
  3. The next layer receives the original task plus the previous layer’s answers, not the whole transcript
After the last layer, the aggregator reads every labelled answer from every layer and synthesizes the final result.

Key Parameters

str
default:"MixtureOfAgents"
Name for the MoA instance
List[Agent]
required
List of expert agents to run in parallel
Agent
default:"None"
Agent that synthesizes expert outputs. If omitted, a default aggregator is created automatically from aggregator_system_prompt and aggregator_model_name.
int
default:"3"
Number of processing layers (iterations)
int
default:"1"
Stored for compatibility with other swarm classes. It does not change execution; use layers for more rounds
OutputType
default:"final"
Output format (final, all, list, dict)
str
default:"AGGREGATOR_SYSTEM_PROMPT_MAIN"
System prompt for the automatically created aggregator. Ignored when you pass your own aggregator_agent
str
default:"claude-sonnet-4-20250514"
Model for the aggregator agent
int
default:"None"
Cap on how many worker agents run concurrently within a single layer. Forwarded to run_agents_concurrently(). When omitted, the pool uses 95% of the available CPU cores.
Dict[str, Any]
default:"None"
Extra Agent keyword arguments forwarded to the automatically created aggregator. Ignored entirely when you pass your own aggregator_agent.
The parameter is spelled aggegrator_args in the code — note the transposed letters. That misspelling is the name you must type; aggregator_args is not accepted and raises TypeError.

Methods

run()

Execute the mixture of agents with a task.

run_batched()

Process multiple tasks sequentially.

run_concurrently()

Process multiple tasks in parallel. Results come back in task order.
Every task runs on the same instance, conversation and worker agents, so concurrent tasks can overwrite each other’s state. Prefer run_batched(), or one MixtureOfAgents per task, when results must stay isolated.

Use Cases

Investment Analysis

Medical Diagnosis

Research Synthesis

Custom Aggregator Prompt

aggregator_system_prompt configures the aggregator that MixtureOfAgents builds for you. If you pass your own aggregator_agent, set the prompt on that agent’s system_prompt instead.

Automatic Aggregator Setup

If no aggregator agent is provided, one is created automatically:
Use aggegrator_args to pass any other Agent keyword argument through to that auto-created aggregator:
aggegrator_args only applies when the aggregator is auto-created. If you pass your own aggregator_agent, configure it on that Agent directly — aggegrator_args is ignored.

Architecture Flow

Multi-Layer Flow

With layers=3:
With layers=1 the labels are the plain agent names.

Output Types

Best Practices

Expert Selection: Choose agents with complementary expertise for maximum benefit
  1. Diverse Experts: Select agents with different perspectives/specializations
  2. Clear Prompts: Give each expert a specific focus area
  3. Quality Aggregator: Use a strong model for synthesis (Claude Sonnet, GPT-5.4)
  4. Layer Count: Start with 1 layer, add more only if needed
  5. Aggregator Instructions: Provide clear synthesis guidelines
More experts and layers increase cost and latency - balance quality with efficiency

Reliability Checks

The system validates configuration on initialization:
Validations:
  • At least one expert agent required
  • Aggregator system prompt must be provided
  • Layers must be specified

Performance Considerations

Concurrent Execution

Experts run concurrently on a thread pool:
Only each expert’s final answer is recorded, not its whole transcript.

Conversation Context

Layers do not receive the full transcript. The first layer gets the task alone; each later layer gets the original task plus the previous layer’s synthesis. This deliberately avoids re-sending a growing transcript to every worker on every layer.
The aggregator is the one agent that sees everything. It receives the conversation as chat turns: the task, then every expert answer from every layer, each labelled with its speaker and layer.