Skip to main content

Overview

The MixtureOfAgents 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.

Class Definition

Parameters

str
default:"uuid.uuid4()"
Unique identifier for the mixture of agents instance
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
Agent
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"
Maximum number of execution loops for the aggregator agent
OutputType
default:"final"
Output format type. Options: “final”, “all”, “list”, etc.
str
default:"claude-sonnet-4-20250514"
The model name for the aggregator agent

Methods

reliability_check()

Performs a reliability check on the Mixture of Agents class configuration. Raises:
  • ValueError: If no agents are provided
  • ValueError: If no aggregator system prompt is provided
  • ValueError: If no layers are specified

step()

Executes a single step by running all agents concurrently with the given task. Parameters:
str
required
The task to be executed by all agents
str
Optional image input for the task
Returns:
Dict[str, str]
Dictionary mapping agent names to their output responses

run()

Executes the complete mixture of agents workflow with multiple layers and aggregation. Parameters:
str
required
The task to be executed by the mixture of agents
str
Optional image input for the task
Returns:
str
The aggregated response from all agents after processing through all layers
Workflow:
  1. Adds initial task to conversation history
  2. For each layer:
    • Runs all agents concurrently with full context
    • Adds each agent’s output to conversation
    • Updates context with latest conversation history
  3. Runs aggregator agent on complete conversation
  4. Returns formatted output based on output_type

run_batched()

Runs the mixture of agents for a batch of tasks sequentially. Parameters:
List[str]
required
A list of tasks to be executed by the mixture of agents
Returns:
List[str]
A list of aggregated responses from the mixture of agents, one for each task

run_concurrently()

Runs the mixture of agents for a batch of tasks concurrently using ThreadPoolExecutor. Parameters:
List[str]
required
A list of tasks to be executed concurrently
Returns:
List[str]
A list of aggregated responses from the mixture of agents

Usage Example

Architecture

The MixtureOfAgents architecture works as follows:
  1. Layer Processing: Each layer runs all agents concurrently with the full conversation context
  2. Context Accumulation: Agent outputs are added to the conversation history after each layer
  3. Iterative Refinement: Subsequent layers build upon previous outputs, enabling deeper analysis
  4. Final Aggregation: An aggregator agent synthesizes all responses into a coherent final output

Source Code

View the source code on GitHub