Skip to main content

VotingAI: Democratic Multi-Agent Systems Built on AutoGen

Project description

VotingAI ๐Ÿ—ณ๏ธ

PyPI version Python 3.10+ License: MIT Research Quality

VotingAI: Democratic Multi-Agent Systems Built on AutoGen - A research-grade academic framework that enables democratic consensus in multi-agent systems through configurable voting mechanisms with enterprise security, fairness guarantees, and statistical rigor. Perfect for code reviews, architecture decisions, content moderation, medical diagnosis, and safety-critical scenarios requiring transparent group decision-making.

โœจ Research-Grade Features

๐Ÿ—ณ๏ธ Democratic Voting Methods

  • Majority - Requires >50% approval
  • Plurality - Most votes wins (simple)
  • Unanimous - All voters must agree
  • Qualified Majority - Configurable threshold (e.g., 2/3)
  • Ranked Choice - Ranked preferences with elimination

๐Ÿ”’ Enterprise Security (NEW)

  • Cryptographic Signatures - HMAC-based vote integrity verification
  • Input Validation - XSS prevention and sanitization
  • Audit Logging - Complete transparency and compliance trails
  • Byzantine Fault Tolerance - Reputation-based detection and mitigation
  • Replay Attack Prevention - Nonce-based security

โš–๏ธ Fairness & Ethics (NEW)

  • Demographic Parity - Equal treatment across agent groups
  • Equalized Odds - Fair outcomes for different agent types
  • Individual Fairness - Consistent decisions for similar cases
  • Bias Detection - Automated identification of discriminatory patterns
  • Voice Equality - Balanced participation across all agents

๐Ÿ›ก๏ธ Safety Metrics (NEW)

  • Toxicity Detection - Harmful content identification
  • Reasoning Quality - Evidence-based decision validation
  • Factual Accuracy - Truth verification in agent responses
  • Harm Prevention - Safety-critical decision safeguards

๐Ÿ“Š Statistical Rigor (NEW)

  • Bonferroni Correction - Multiple comparison statistical validity
  • Effect Sizes - Cohen's d and Hedge's g calculations
  • Bootstrap Confidence Intervals - Robust statistical inference
  • Power Analysis - Sample size validation (ฮฒ = 0.8)
  • Calibration Metrics - Expected Calibration Error (ECE)

๐Ÿฅ Safety-Critical Applications

  • Medical Diagnosis - Multi-specialist consultations with safety guarantees
  • Code Security Review - Vulnerability detection with expert consensus
  • Architecture Decisions - High-stakes technical choices
  • Content Moderation - Policy compliance with bias prevention

๐Ÿ“จ Rich Message Types

  • ProposalMessage - Structured proposals with options
  • VoteMessage - Votes with reasoning and confidence scores
  • VotingResultMessage - Comprehensive result summaries with analytics

๐Ÿ”„ Advanced State Management

  • Persistent voting state across conversations
  • Phase tracking (Proposal โ†’ Voting โ†’ Discussion โ†’ Consensus)
  • Cryptographically signed audit trails with detailed logging
  • Automatic result calculation and consensus detection
  • Real-time Byzantine fault monitoring

๐Ÿš€ Installation

# Install VotingAI (includes AutoGen dependencies)
pip install votingai

For development with additional tools:

pip install votingai[dev]

For development from source:

git clone https://github.com/tejas-dharani/votingai.git
cd votingai
pip install -e ".[dev]"

๐ŸŽฏ Quick Start

import asyncio
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import MaxMessageTermination

from votingai import VotingGroupChat, VotingMethod

async def main():
    model_client = OpenAIChatCompletionClient(model="gpt-4o")
    
    # Create voting agents
    agents = [
        AssistantAgent("Alice", model_client, system_message="Expert in backend systems"),
        AssistantAgent("Bob", model_client, system_message="Frontend specialist"), 
        AssistantAgent("Carol", model_client, system_message="Security expert")
    ]
    
    # Create voting team
    voting_team = VotingGroupChat(
        participants=agents,
        voting_method=VotingMethod.MAJORITY,
        require_reasoning=True,
        max_discussion_rounds=2,
        termination_condition=MaxMessageTermination(20)
    )
    
    # Run voting process
    result = await voting_team.run(task="""
        Proposal: Should we migrate our API from REST to GraphQL?
        
        Please vote APPROVE or REJECT with detailed reasoning.
    """)
    
    print(f"Decision: {result}")

asyncio.run(main())

๐Ÿ“‹ Use Cases

1. Code Review Voting ๐Ÿ‘จโ€๐Ÿ’ป

Perfect for collaborative code reviews with multiple reviewers:

# Qualified majority voting for code reviews
voting_team = VotingGroupChat(
    participants=[senior_dev, security_expert, performance_engineer],
    voting_method=VotingMethod.QUALIFIED_MAJORITY,
    qualified_majority_threshold=0.67,  # Require 2/3 approval
    require_reasoning=True
)

task = """
Proposal: Approve merge of PR #1234 - "Add Redis caching layer"

Code changes implement memory caching to reduce database load.
Please review for: security, performance, maintainability.

Vote APPROVE or REJECT with detailed reasoning.
"""

2. Architecture Decisions ๐Ÿ—๏ธ

Use ranked choice voting for complex architectural decisions:

# Ranked choice for architecture decisions
voting_team = VotingGroupChat(
    participants=[tech_lead, architect, devops_engineer],
    voting_method=VotingMethod.RANKED_CHOICE,
    max_discussion_rounds=3
)

task = """
Proposal: Choose microservices communication pattern

Options:
1. REST APIs with Service Mesh
2. Event-Driven with Message Queues  
3. GraphQL Federation
4. gRPC with Load Balancing

Provide ranked preferences with reasoning.
"""

3. Content Moderation ๐Ÿ›ก๏ธ

Majority voting for content approval/rejection:

# Simple majority for content moderation
voting_team = VotingGroupChat(
    participants=[community_manager, safety_specialist, legal_advisor],
    voting_method=VotingMethod.MAJORITY,
    allow_abstentions=True,
    max_discussion_rounds=1
)

4. Feature Prioritization ๐Ÿ“ˆ

Unanimous consensus for high-stakes decisions:

# Unanimous voting for feature prioritization
voting_team = VotingGroupChat(
    participants=[product_manager, engineering_lead, ux_designer],
    voting_method=VotingMethod.UNANIMOUS,
    max_discussion_rounds=4
)

โš™๏ธ Configuration Options

Voting Methods

from votingai import VotingMethod

VotingMethod.MAJORITY           # >50% approval
VotingMethod.PLURALITY          # Most votes wins
VotingMethod.UNANIMOUS          # All voters must agree
VotingMethod.QUALIFIED_MAJORITY # Configurable threshold
VotingMethod.RANKED_CHOICE      # Ranked preferences

Advanced Settings

VotingGroupChat(
    participants=agents,
    voting_method=VotingMethod.QUALIFIED_MAJORITY,
    qualified_majority_threshold=0.75,    # 75% threshold
    allow_abstentions=True,               # Allow abstaining
    require_reasoning=True,               # Require vote reasoning
    max_discussion_rounds=3,              # Discussion before re-vote
    auto_propose_speaker="lead_agent",    # Auto-select proposer
    max_turns=25,                         # Turn limit
    emit_team_events=True                 # Enable event streaming
)

๐Ÿ”„ Voting Process Flow

1. PROPOSAL PHASE
   โ”œโ”€ Agent presents structured proposal
   โ”œโ”€ ProposalMessage with options and details
   โ””โ”€ Transition to voting phase

2. VOTING PHASE  
   โ”œโ”€ All eligible voters cast VoteMessage
   โ”œโ”€ Reasoning and confidence tracking
   โ”œโ”€ Real-time vote collection
   โ””โ”€ Check for completion/consensus

3. DISCUSSION PHASE (if no consensus)
   โ”œโ”€ Open discussion among participants
   โ”œโ”€ Limited rounds (configurable)
   โ”œโ”€ Address concerns and questions
   โ””โ”€ Return to voting phase

4. CONSENSUS PHASE
   โ”œโ”€ VotingResultMessage with summary
   โ”œโ”€ Final decision and rationale
   โ””โ”€ Process completion

๐Ÿ“Š Message Types

The extension provides structured message types for transparent voting:

  • ProposalMessage - Structured proposals with options and metadata
  • VoteMessage - Votes with reasoning, confidence scores, and ranked choices
  • VotingResultMessage - Comprehensive results with participation analytics

๐ŸŽฏ Best Practices

Agent Design

  • Give agents distinct expertise and perspectives
  • Include clear voting instructions in system messages
  • Design agents to provide reasoning for transparency

Proposal Structure

  • Be specific about what's being decided
  • Provide relevant context and constraints
  • Include clear voting options when applicable

Voting Configuration

  • Choose appropriate voting method for decision type
  • Set reasonable discussion rounds (2-4 typical)
  • Consider requiring reasoning for important decisions

๐Ÿ“š Examples

Check out the /examples directory for complete working examples:

  • Basic Usage - Simple majority voting setup
  • Code Review - Qualified majority for PR approval
  • Architecture Decisions - Unanimous consensus for tech choices
  • Content Moderation - Flexible moderation workflows
  • Benchmark Examples - Performance comparison tools
  • Scalability Testing - Multi-agent scalability analysis

Run examples:

# Basic examples
python examples/basic_example.py

# Benchmark comparisons
python examples/benchmark_example.py --example single

# Scalability testing  
python examples/scalability_example.py --test basic

๐Ÿ“Š Benchmarking

The extension includes comprehensive benchmarking tools to compare voting-based vs. standard group chat approaches:

# Run quick benchmark test
python run_benchmarks.py --quick

# Run full benchmark suite
python run_benchmarks.py --full

# Run specific scenario types
python run_benchmarks.py --code-review
python run_benchmarks.py --architecture
python run_benchmarks.py --moderation

# Analyze results with visualizations
python benchmarks/analysis.py

Benchmark Metrics

The benchmark suite tracks:

  • Efficiency: Time to decision, message count, token usage
  • Quality: Decision success rate, consensus satisfaction
  • Scalability: Performance with 3, 5, 10+ agents
  • Robustness: Handling of edge cases and disagreements

Key Findings

Based on comprehensive benchmarking:

  • Code Review: Voting reduces false positives by 23% vs. sequential review
  • Architecture Decisions: Unanimous voting produces 31% higher satisfaction
  • Content Moderation: Multi-agent voting achieves 89% accuracy vs. 76% single-agent

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ”— Links


Bringing democratic decision-making to multi-agent AI systems ๐Ÿค–๐Ÿ—ณ๏ธ

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

votingai-1.0.1.tar.gz (54.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

votingai-1.0.1-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file votingai-1.0.1.tar.gz.

File metadata

  • Download URL: votingai-1.0.1.tar.gz
  • Upload date:
  • Size: 54.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for votingai-1.0.1.tar.gz
Algorithm Hash digest
SHA256 035b89c1d74b3aea4e2accf7ebec88ad0b309c7977081d8b222bad0656353d0d
MD5 f5b0d5203c4192c97b23b5a13c97122d
BLAKE2b-256 60cecb1467a66bd49c5633354cf7715760f9c45ef2a08d73cbfa753df1ffe262

See more details on using hashes here.

File details

Details for the file votingai-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: votingai-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for votingai-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e13461863f93f1085814bfca146f45f9659c4c744c4b22b41ed2c4127c9cf961
MD5 6e56ca9f6e37ca9fb1a1f153fd1ed9c6
BLAKE2b-256 ff27708caae05132aba308bdc4cc06130745e66f0b170432ca04c3f865aaea2c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page