Skip to content

Conversation

@Wxysnx
Copy link
Contributor

@Wxysnx Wxysnx commented Jul 18, 2025

example video:https://www.loom.com/share/f87f67d881bd4e1da24050ce96ac6c95?sid=d4e8a531-f2d9-4035-80f5-efd856afdaf1

This PR implements the ElectionSwarm class, a collective decision-making system based on multi-agent voting mechanisms. It runs multiple agents in parallel and integrates their responses through various voting strategies, thereby enhancing the performance quality and consistency of large language models in complex tasks.

Research Background
This implementation builds on research in "collective intelligence" and "multi-agent collaboration," particularly focusing on:

Integration of Diverse Perspectives: By aggregating responses from multiple different agents, the system synthesizes varied viewpoints and expertise
Mitigation of Agent Bias: Reduces bias or errors from individual agents through mechanisms like majority voting
Enhanced Result Robustness: Ensures final outputs reflect consensus among multiple agents, increasing result reliability
Core Features
ElectionSwarm implements multiple voting mechanisms, including:

Majority Voting: Selects the response that receives the most votes
Unanimous Voting: Requires consensus from all agents
Quorum Voting: Requires reaching a preset threshold percentage of responses
Ranked Choice Voting: Implements a simplified ranked choice voting system that eliminates candidates with the lowest votes through multiple rounds
Additionally, the system supports:

Parallel processing for improved efficiency
Flexible tiebreaking methods for handling tied scenarios
Comprehensive logging to track decision processes
Technical Implementation
Key technical highlights of this implementation include:

Parallel Execution: Utilizes ThreadPoolExecutor to achieve parallel agent processing
Response Normalization: Ensures consistent comparison of responses via the _normalize_response method
Multi-round Voting Mechanisms: Implements complex multi-round decision processes, particularly in ranked choice voting
Robust Design: Handles various edge cases to ensure the system produces valid results under all circumstances
Research Significance
This implementation aligns with current research trends demonstrating that integrating outputs from multiple language models can significantly reduce hallucinations, improve factual accuracy, and enhance performance on complex reasoning tasks.


📚 Documentation preview 📚: https://swarms--962.org.readthedocs.build/en/962/

# 如果所有候选者得票相同,只淘汰一半(避免全部淘汰)
if len(to_eliminate) == len(vote_counts):
import random
to_eliminate = random.sample(to_eliminate, len(to_eliminate) // 2 + 1)

Check failure

Code scanning / Bearer

Usage of weak Pseudo-Random Number Generator (PRNG) Error

Usage of weak Pseudo-Random Number Generator (PRNG)
# 没有候选者被淘汰(可能逻辑错误),为避免死循环,强制淘汰一个
if remaining_candidates:
import random
new_remaining.remove(random.choice(remaining_candidates))

Check failure

Code scanning / Bearer

Usage of weak Pseudo-Random Number Generator (PRNG) Error

Usage of weak Pseudo-Random Number Generator (PRNG)
"""
if self.tie_breaking_method == "random":
import random
return random.choice(tied_responses)

Check failure

Code scanning / Bearer

Usage of weak Pseudo-Random Number Generator (PRNG) Error

Usage of weak Pseudo-Random Number Generator (PRNG)
except:
# If judge response couldn't be interpreted, fall back to random
import random
return random.choice(tied_responses)

Check failure

Code scanning / Bearer

Usage of weak Pseudo-Random Number Generator (PRNG) Error

Usage of weak Pseudo-Random Number Generator (PRNG)

# Default fallback
import random
return random.choice(tied_responses)

Check failure

Code scanning / Bearer

Usage of weak Pseudo-Random Number Generator (PRNG) Error

Usage of weak Pseudo-Random Number Generator (PRNG)
from swarms import Agent
from swarms.utils.formatter import formatter
from swarms.structs.election_swarm_agent import ElectionSwarm
from dotenv import load_dotenv

Check failure

Code scanning / Pyre

Undefined import Error

Undefined import [21]: Could not find a module corresponding to import dotenv.
import uuid
from typing import Dict, List, Optional, Union, Any, Callable
from concurrent.futures import ThreadPoolExecutor
from loguru import logger

Check failure

Code scanning / Pyre

Undefined import Error

Undefined import [21]: Could not find a module corresponding to import loguru.
Which response best addresses the original task? Respond only with the number of your choice.
"""

judge_decision = self.judge_agent.run(judge_task)

Check failure

Code scanning / Pyre

Undefined attribute Error

Undefined attribute [16]: Optional has no attribute run.

# Extract numeric decision from judge response
try:
decision_num = int(''.join(filter(str.isdigit, judge_decision)))

Check failure

Code scanning / Pyre

Incompatible parameter type Error

Incompatible parameter type [6]: In call filter.__new__, for 1st positional argument, expected None but got typing.Callable(str.isdigit)[[Named(self, pyre_extensions.PyreReadOnly[Variable[_Self_str__ (bound to str)]])], bool].
@Wxysnx
Copy link
Contributor Author

Wxysnx commented Jul 18, 2025

#957

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant