Overview
TheMajorityVoting module provides a sophisticated multi-loop consensus building system for agents. Unlike simple majority voting, this system enables iterative consensus building where agents can refine their responses across multiple loops, with each subsequent loop considering the previous consensus. This approach leads to more robust and well-reasoned final decisions by leveraging the collective intelligence of multiple specialized agents.
Installation
Architecture
Key Concepts
- Multi-Loop Consensus Building: An iterative process where agents can refine their responses across multiple loops, with each loop building upon the previous consensus.
- Agents: Specialized entities (e.g., models, algorithms) that provide expert responses to tasks or queries.
- Consensus Agent: An automatically created agent that analyzes and synthesizes responses from all agents to determine the final consensus.
- Conversation History: A comprehensive record of all agent interactions, responses, and consensus building across all loops.
- Concurrent Execution: Agents run simultaneously for improved performance and efficiency.
Attributes
str
default:"swarm_id()"
Unique identifier for the majority voting system.
str
default:"MajorityVoting"
Name of the majority voting system.
str
default:"A multi-loop majority voting system for agents"
Description of the system.
List[Agent]
required
A list of agents to be used in the majority voting system.
bool
default:"False"
Whether to autosave conversations.
bool
default:"False"
Whether to enable verbose logging.
int
default:"1"
Maximum number of consensus building loops.
OutputType
default:"dict"
Output format: “str”, “dict”, “list”, or other.
str
default:"CONSENSUS_AGENT_PROMPT"
System prompt for the consensus agent.
str
default:"Consensus-Agent"
Name for the automatically created consensus agent.
str
Description for the consensus agent.
str
default:"gpt-5.4"
Model name for the consensus agent.
dict
default:"{}"
Additional keyword arguments passed to the consensus agent.
Methods
run()
Executes the multi-loop majority voting system for a single task and returns the consensus result.task(str): The task or question to be analyzed by the agent panelstreaming_callback(Optional[Callable[[str, str, bool], None]]): Optional callback invoked as(agent_name, chunk, is_final)while the consensus agent streams its response*args(Any): Variable length argument list passed to individual agents**kwargs(Any): Arbitrary keyword arguments passed to individual agents
output_type
Raises:
ValueError: If the agents list is empty or None
- Adds the input task to the conversation history
- For each loop (up to
max_loops):- Runs all agents concurrently on the current conversation state
- Collects agent responses and adds them to conversation history
- Runs the consensus agent to analyze and synthesize responses
- Adds consensus output to conversation history
- Returns the final result in the specified output format
batch_run()
Executes the majority voting system for multiple tasks sequentially.tasks(List[str]): List of tasks or questions to be processed*args(Any): Variable length argument list passed to each task execution**kwargs(Any): Arbitrary keyword arguments passed to each task execution
run_concurrently()
Executes the majority voting system for multiple tasks concurrently using thread pooling.tasks(List[str]): List of tasks or questions to be processed*args(Any): Variable length argument list passed to each task execution**kwargs(Any): Arbitrary keyword arguments passed to each task execution
Uses
os.cpu_count() workers for optimal performance. Results are returned in completion order, not input order.reliability_check()
Performs validation checks on the majority voting system configuration.ValueError: If agents list is empty or None
Consensus Agent
The MajorityVoting system automatically creates a specialized consensus agent that analyzes and synthesizes responses from all participating agents. This consensus agent:- Comprehensively evaluates each agent’s response across accuracy, depth of analysis, relevance, clarity, and unique perspectives
- Performs comparative analysis by identifying overlapping themes, divergent viewpoints, and strengths/weaknesses
- Builds consensus by identifying the most effective responses and synthesizing best elements
- Delivers actionable results that are fair, balanced, evidence-based, and well-supported
consensus_agent_prompt: Custom system promptconsensus_agent_name: Name for the agentconsensus_agent_description: Descriptionconsensus_agent_model_name: Model to useadditional_consensus_agent_kwargs: Additional configuration