MajorityVoting
Overview
The MajorityVoting swarm type implements a democratic decision-making process where multiple agents independently analyze a problem and propose solutions. The final outcome is determined by majority consensus, making this architecture ideal for scenarios where you want to leverage collective intelligence while maintaining a clear decision-making process. Key features:- Democratic Decision Making: Multiple agents vote on solutions
- Consensus Building: Majority rule determines final outcome
- Independent Analysis: Each agent works independently before voting
- Transparent Process: Clear voting mechanism and results
Use Cases
- Content quality assessment and approval
- Problem diagnosis with multiple expert opinions
- Decision-making in uncertain scenarios
- Quality control and validation processes
API Usage
Basic MajorityVoting Example
- Shell (curl)
- Python (requests)
- JavaScript (fetch)
- Go
- Rust
curl -X POST "https://api.swarms.world/v1/swarm/completions" \
-H "x-api-key: $SWARMS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Content Quality Assessment",
"description": "Multi-agent content review with majority voting for approval",
"swarm_type": "MajorityVoting",
"task": "Review and vote on whether to approve this marketing content for publication: [Content: Our revolutionary AI solution transforms business operations by leveraging cutting-edge machine learning algorithms to optimize workflows and increase productivity by up to 300%]",
"agents": [
{
"agent_name": "Marketing Expert",
"description": "Evaluates marketing effectiveness and messaging",
"system_prompt": "You are a marketing expert. Assess marketing content for effectiveness, clarity, and appeal to target audiences. Vote YES if the content is ready for publication, NO if it needs revision.",
"model_name": "gpt-4.1",
"max_loops": 1,
"temperature": 0.3
},
{
"agent_name": "Technical Reviewer",
"description": "Reviews technical accuracy and claims",
"system_prompt": "You are a technical reviewer. Assess the technical accuracy of claims and ensure they are substantiated. Vote YES if claims are accurate, NO if they are exaggerated or unsubstantiated.",
"model_name": "gpt-4.1",
"max_loops": 1,
"temperature": 0.2
},
{
"agent_name": "Legal Compliance",
"description": "Checks for legal and compliance issues",
"system_prompt": "You are a legal compliance expert. Review content for potential legal issues, compliance concerns, and regulatory requirements. Vote YES if content is compliant, NO if there are legal concerns.",
"model_name": "gpt-4.1",
"max_loops": 1,
"temperature": 0.1
},
{
"agent_name": "Brand Guardian",
"description": "Ensures brand consistency and voice",
"system_prompt": "You are a brand guardian. Ensure content aligns with brand voice, values, and positioning. Vote YES if content fits the brand, NO if it needs brand alignment adjustments.",
"model_name": "gpt-4.1",
"max_loops": 1,
"temperature": 0.4
},
{
"agent_name": "Audience Advocate",
"description": "Represents the target audience perspective",
"system_prompt": "You are an audience advocate. Evaluate whether the content is clear, credible, and persuasive from the perspective of the target audience. Vote YES if the content would resonate with readers, NO if it would not.",
"model_name": "gpt-4.1",
"max_loops": 1,
"temperature": 0.3
}
],
"max_loops": 1
}'
import requests
import json
API_BASE_URL = "https://api.swarms.world"
API_KEY = "your_api_key_here"
headers = {
"x-api-key": API_KEY,
"Content-Type": "application/json"
}
swarm_config = {
"name": "Content Quality Assessment",
"description": "Multi-agent content review with majority voting for approval",
"swarm_type": "MajorityVoting",
"task": "Review and vote on whether to approve this marketing content for publication: [Content: Our revolutionary AI solution transforms business operations by leveraging cutting-edge machine learning algorithms to optimize workflows and increase productivity by up to 300%]",
"agents": [
{
"agent_name": "Marketing Expert",
"description": "Evaluates marketing effectiveness and messaging",
"system_prompt": "You are a marketing expert. Assess marketing content for effectiveness, clarity, and appeal to target audiences. Vote YES if the content is ready for publication, NO if it needs revision.",
"model_name": "gpt-4.1",
"max_loops": 1,
"temperature": 0.3
},
{
"agent_name": "Technical Reviewer",
"description": "Reviews technical accuracy and claims",
"system_prompt": "You are a technical reviewer. Assess the technical accuracy of claims and ensure they are substantiated. Vote YES if claims are accurate, NO if they are exaggerated or unsubstantiated.",
"model_name": "gpt-4.1",
"max_loops": 1,
"temperature": 0.2
},
{
"agent_name": "Legal Compliance",
"description": "Checks for legal and compliance issues",
"system_prompt": "You are a legal compliance expert. Review content for potential legal issues, compliance concerns, and regulatory requirements. Vote YES if content is compliant, NO if there are legal concerns.",
"model_name": "gpt-4.1",
"max_loops": 1,
"temperature": 0.1
},
{
"agent_name": "Brand Guardian",
"description": "Ensures brand consistency and voice",
"system_prompt": "You are a brand guardian. Ensure content aligns with brand voice, values, and positioning. Vote YES if content fits the brand, NO if it needs brand alignment adjustments.",
"model_name": "gpt-4.1",
"max_loops": 1,
"temperature": 0.4
},
{
"agent_name": "Audience Advocate",
"description": "Represents the target audience perspective",
"system_prompt": "You are an audience advocate. Evaluate whether the content is clear, credible, and persuasive from the perspective of the target audience. Vote YES if the content would resonate with readers, NO if it would not.",
"model_name": "gpt-4.1",
"max_loops": 1,
"temperature": 0.3
}
],
"max_loops": 1
}
response = requests.post(
f"{API_BASE_URL}/v1/swarm/completions",
headers=headers,
json=swarm_config
)
if response.status_code == 200:
result = response.json()
print("MajorityVoting swarm completed successfully!")
print(f"Cost: ${result['usage']['billing_info']['total_cost']}")
print(f"Execution time: {result['execution_time']} seconds")
print(f"Voting results: {result['output']}")
else:
print(f"Error: {response.status_code} - {response.text}")
const API_BASE_URL = "https://api.swarms.world";
const API_KEY = "your_api_key_here";
const headers = {
"x-api-key": API_KEY,
"Content-Type": "application/json"
};
const swarmConfig = {
name: "Content Quality Assessment",
description: "Multi-agent content review with majority voting for approval",
swarm_type: "MajorityVoting",
task: "Review and vote on whether to approve this marketing content for publication: [Content: Our revolutionary AI solution transforms business operations by leveraging cutting-edge machine learning algorithms to optimize workflows and increase productivity by up to 300%]",
agents: [
{
agent_name: "Marketing Expert",
description: "Evaluates marketing effectiveness and messaging",
system_prompt: "You are a marketing expert. Assess marketing content for effectiveness, clarity, and appeal to target audiences. Vote YES if the content is ready for publication, NO if it needs revision.",
model_name: "gpt-4.1",
max_loops: 1,
temperature: 0.3
},
{
agent_name: "Technical Reviewer",
description: "Reviews technical accuracy and claims",
system_prompt: "You are a technical reviewer. Assess the technical accuracy of claims and ensure they are substantiated. Vote YES if claims are accurate, NO if they are exaggerated or unsubstantiated.",
model_name: "gpt-4.1",
max_loops: 1,
temperature: 0.2
},
{
agent_name: "Legal Compliance",
description: "Checks for legal and compliance issues",
system_prompt: "You are a legal compliance expert. Review content for potential legal issues, compliance concerns, and regulatory requirements. Vote YES if content is compliant, NO if there are legal concerns.",
model_name: "gpt-4.1",
max_loops: 1,
temperature: 0.1
},
{
agent_name: "Brand Guardian",
description: "Ensures brand consistency and voice",
system_prompt: "You are a brand guardian. Ensure content aligns with brand voice, values, and positioning. Vote YES if content fits the brand, NO if it needs brand alignment adjustments.",
model_name: "gpt-4.1",
max_loops: 1,
temperature: 0.4
},
{
agent_name: "Audience Advocate",
description: "Represents the target audience perspective",
system_prompt: "You are an audience advocate. Evaluate whether the content is clear, credible, and persuasive from the perspective of the target audience. Vote YES if the content would resonate with readers, NO if it would not.",
model_name: "gpt-4.1",
max_loops: 1,
temperature: 0.3
}
],
max_loops: 1
};
fetch(`${API_BASE_URL}/v1/swarm/completions`, {
method: "POST",
headers: headers,
body: JSON.stringify(swarmConfig)
})
.then(response => response.json())
.then(result => {
if (result.status === "success") {
console.log("MajorityVoting swarm completed successfully!");
console.log(`Cost: $${result.usage.billing_info.total_cost}`);
console.log(`Execution time: ${result.execution_time} seconds`);
console.log("Voting results:", result.output);
}
})
.catch(error => console.error("Error:", error));
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Agent struct {
AgentName string `json:"agent_name"`
Description string `json:"description"`
SystemPrompt string `json:"system_prompt"`
ModelName string `json:"model_name"`
MaxLoops int `json:"max_loops"`
Temperature float64 `json:"temperature"`
}
type SwarmConfig struct {
Name string `json:"name"`
Description string `json:"description"`
SwarmType string `json:"swarm_type"`
Task string `json:"task"`
Agents []Agent `json:"agents"`
MaxLoops int `json:"max_loops"`
}
func main() {
API_BASE_URL := "https://api.swarms.world"
API_KEY := "your_api_key_here"
swarmConfig := SwarmConfig{
Name: "Content Quality Assessment",
Description: "Multi-agent content review with majority voting for approval",
SwarmType: "MajorityVoting",
Task: "Review and vote on whether to approve this marketing content for publication: [Content: Our revolutionary AI solution transforms business operations by leveraging cutting-edge machine learning algorithms to optimize workflows and increase productivity by up to 300%]",
Agents: []Agent{
{
AgentName: "Marketing Expert",
Description: "Evaluates marketing effectiveness and messaging",
SystemPrompt: "You are a marketing expert. Assess marketing content for effectiveness, clarity, and appeal to target audiences. Vote YES if the content is ready for publication, NO if it needs revision.",
ModelName: "gpt-4.1",
MaxLoops: 1,
Temperature: 0.3,
},
{
AgentName: "Technical Reviewer",
Description: "Reviews technical accuracy and claims",
SystemPrompt: "You are a technical reviewer. Assess the technical accuracy of claims and ensure they are substantiated. Vote YES if claims are accurate, NO if they are exaggerated or unsubstantiated.",
ModelName: "gpt-4.1",
MaxLoops: 1,
Temperature: 0.2,
},
{
AgentName: "Legal Compliance",
Description: "Checks for legal and compliance issues",
SystemPrompt: "You are a legal compliance expert. Review content for potential legal issues, compliance concerns, and regulatory requirements. Vote YES if content is compliant, NO if there are legal concerns.",
ModelName: "gpt-4.1",
MaxLoops: 1,
Temperature: 0.1,
},
{
AgentName: "Brand Guardian",
Description: "Ensures brand consistency and voice",
SystemPrompt: "You are a brand guardian. Ensure content aligns with brand voice, values, and positioning. Vote YES if content fits the brand, NO if it needs brand alignment adjustments.",
ModelName: "gpt-4.1",
MaxLoops: 1,
Temperature: 0.4,
},
{
AgentName: "Audience Advocate",
Description: "Represents the target audience perspective",
SystemPrompt: "You are an audience advocate. Evaluate whether the content is clear, credible, and persuasive from the perspective of the target audience. Vote YES if the content would resonate with readers, NO if it would not.",
ModelName: "gpt-4.1",
MaxLoops: 1,
Temperature: 0.3,
},
},
MaxLoops: 1,
}
jsonData, _ := json.Marshal(swarmConfig)
req, _ := http.NewRequest("POST", API_BASE_URL+"/v1/swarm/completions", bytes.NewBuffer(jsonData))
req.Header.Set("x-api-key", API_KEY)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Printf("Response: %s\n", string(body))
}
use reqwest::Client;
use serde_json::{json, Value};
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let api_base_url = "https://api.swarms.world";
let api_key = "your_api_key_here";
let swarm_config = json!({
"name": "Content Quality Assessment",
"description": "Multi-agent content review with majority voting for approval",
"swarm_type": "MajorityVoting",
"task": "Review and vote on whether to approve this marketing content for publication: [Content: Our revolutionary AI solution transforms business operations by leveraging cutting-edge machine learning algorithms to optimize workflows and increase productivity by up to 300%]",
"agents": [
{
"agent_name": "Marketing Expert",
"description": "Evaluates marketing effectiveness and messaging",
"system_prompt": "You are a marketing expert. Assess marketing content for effectiveness, clarity, and appeal to target audiences. Vote YES if the content is ready for publication, NO if it needs revision.",
"model_name": "gpt-4.1",
"max_loops": 1,
"temperature": 0.3
},
{
"agent_name": "Technical Reviewer",
"description": "Reviews technical accuracy and claims",
"system_prompt": "You are a technical reviewer. Assess the technical accuracy of claims and ensure they are substantiated. Vote YES if claims are accurate, NO if they are exaggerated or unsubstantiated.",
"model_name": "gpt-4.1",
"max_loops": 1,
"temperature": 0.2
},
{
"agent_name": "Legal Compliance",
"description": "Checks for legal and compliance issues",
"system_prompt": "You are a legal compliance expert. Review content for potential legal issues, compliance concerns, and regulatory requirements. Vote YES if content is compliant, NO if there are legal concerns.",
"model_name": "gpt-4.1",
"max_loops": 1,
"temperature": 0.1
},
{
"agent_name": "Brand Guardian",
"description": "Ensures brand consistency and voice",
"system_prompt": "You are a brand guardian. Ensure content aligns with brand voice, values, and positioning. Vote YES if content fits the brand, NO if it needs brand alignment adjustments.",
"model_name": "gpt-4.1",
"max_loops": 1,
"temperature": 0.4
},
{
"agent_name": "Audience Advocate",
"description": "Represents the target audience perspective",
"system_prompt": "You are an audience advocate. Evaluate whether the content is clear, credible, and persuasive from the perspective of the target audience. Vote YES if the content would resonate with readers, NO if it would not.",
"model_name": "gpt-4.1",
"max_loops": 1,
"temperature": 0.3
}
],
"max_loops": 1
});
let client = Client::new();
let response = client
.post(&format!("{}/v1/swarm/completions", api_base_url))
.header("x-api-key", api_key)
.header("Content-Type", "application/json")
.json(&swarm_config)
.send()
.await?;
if response.status().is_success() {
let result: Value = response.json().await?;
println!("MajorityVoting swarm completed successfully!");
println!("Response: {:?}", result);
} else {
println!("Error: {}", response.status());
}
Ok(())
}
{
"job_id": "swarms-V17nZFDesmLHxCRoeyF3NVYvPaXk",
"status": "success",
"swarm_name": "Content Quality Assessment",
"description": "Multi-agent content review with majority voting for approval",
"swarm_type": "MajorityVoting",
"output": [
{
"role": "Marketing Expert",
"content": "VOTE: YES. The content effectively communicates the value proposition and uses compelling language that would resonate with business audiences."
},
{
"role": "Technical Reviewer",
"content": "VOTE: NO. The claim of '300% productivity increase' is not substantiated and could be considered misleading without specific data."
},
{
"role": "Legal Compliance",
"content": "VOTE: NO. The unsubstantiated productivity claim could potentially violate advertising standards and truth-in-advertising regulations."
},
{
"role": "Brand Guardian",
"content": "VOTE: YES. The content aligns well with our brand voice of innovation and transformation."
},
{
"role": "Audience Advocate",
"content": "VOTE: NO. The '300% productivity increase' claim reads as implausible and undermines the credibility of the message for a business audience."
}
],
"number_of_agents": 5,
"execution_time": 28.7,
"usage": {
"input_tokens": 50,
"output_tokens": 1800,
"total_tokens": 1850,
"billing_info": {
"cost_breakdown": {
"agent_cost": 0.05,
"input_token_cost": 0.00015,
"output_token_cost": 0.027,
"token_counts": {
"total_input_tokens": 50,
"total_output_tokens": 1800,
"total_tokens": 1850
},
"num_agents": 5,
"night_time_discount_applied": true
},
"total_cost": 0.07715,
"discount_active": true,
"discount_type": "night_time",
"discount_percentage": 50
}
}
}
Best Practices
- Use an odd number of agents to avoid tie votes
- Design agents with distinct evaluation criteria
- Ensure clear voting instructions in system prompts
- Ideal for quality control and approval workflows