MajorityVoting
The MajorityVoting
module provides a mechanism for performing majority voting among a group of agents. Majority voting is a decision rule that selects the option which has the majority of votes. This is particularly useful in systems where multiple agents provide responses to a query, and the most common response needs to be identified as the final output.
Key Concepts
Majority Voting: A method to determine the most common response from a set of answers.
Agents: Entities (e.g., models, algorithms) that provide responses to tasks or queries.
Output Parser: A function that processes the responses from the agents before performing the majority voting.
Function Definitions
Function: majority_voting
majority_voting
Performs majority voting on a list of answers and returns the most common answer.
Parameters
answers
List[str]
A list of answers from different agents.
Returns
answer
str
The most common answer in the list. If the list is empty, returns "I don't know".
Class Definitions
Class: MajorityVoting
MajorityVoting
Class representing a majority voting system for agents.
Parameters
agents
List[Agent]
A list of agents to be used in the majority voting system.
output_parser
Callable
A function used to parse the output of the agents. If not provided, the default majority_voting
function is used.
autosave
bool
A boolean indicating whether to autosave the conversation to a file. Default is False
.
verbose
bool
A boolean indicating whether to enable verbose logging. Default is False
.
Method: __init__
__init__
Initializes the MajorityVoting
system.
Parameters
agents
List[Agent]
A list of agents to be used in the majority voting system.
output_parser
Callable
A function used to parse the output of the agents. Default is the majority_voting
function.
autosave
bool
A boolean indicating whether to autosave the conversation to a file. Default is False
.
verbose
bool
A boolean indicating whether to enable verbose logging. Default is False
.
args
tuple
Additional positional arguments.
kwargs
dict
Additional keyword arguments.
Method: run
run
Runs the majority voting system and returns the majority vote.
Parameters
task
str
The task to be performed by the agents.
args
tuple
Variable length argument list.
kwargs
dict
Arbitrary keyword arguments.
Returns
results
List[Any]
The majority vote.
Usage Examples
Example 1: Basic Majority Voting
Example 2: Running a Task with Detailed Outputs
Last updated