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.
Class Definition
Parameters
Unique identifier for the mixture of agents instance
The name of the mixture of agents
A description of the mixture of agents purpose and functionality
A list of reference agents to be used in the mixture. These agents will be executed in parallel layers
The aggregator agent to be used for synthesizing responses from all agents. If None, a default aggregator agent will be created
The system prompt for the aggregator agent that guides how responses are synthesized
The number of processing layers to execute. Each layer runs all agents and passes context forward
Maximum number of execution loops for the aggregator agent
Output format type. Options: “final”, “all”, “list”, etc.
The model name for the aggregator agent
Methods
reliability_check()
ValueError: If no agents are providedValueError: If no aggregator system prompt is providedValueError: If no layers are specified
step()
The task to be executed by all agents
Optional image input for the task
Dictionary mapping agent names to their output responses
run()
The task to be executed by the mixture of agents
Optional image input for the task
The aggregated response from all agents after processing through all layers
- Adds initial task to conversation history
- For each layer:
- Runs all agents concurrently with full context
- Adds each agent’s output to conversation
- Updates context with latest conversation history
- Runs aggregator agent on complete conversation
- Returns formatted output based on output_type
run_batched()
A list of tasks to be executed by the mixture of agents
A list of aggregated responses from the mixture of agents, one for each task
run_concurrently()
A list of tasks to be executed concurrently
A list of aggregated responses from the mixture of agents
Usage Example
Architecture
The MixtureOfAgents architecture works as follows:- Layer Processing: Each layer runs all agents concurrently with the full conversation context
- Context Accumulation: Agent outputs are added to the conversation history after each layer
- Iterative Refinement: Subsequent layers build upon previous outputs, enabling deeper analysis
- Final Aggregation: An aggregator agent synthesizes all responses into a coherent final output