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.
fromswarms.structs.agentimportAgentfromswarms.structs.majority_votingimportMajorityVoting# Initialize agentsagents=[Agent(agent_name="Devin",system_prompt=("Autonomous agent that can interact with humans and other"" agents. Be Helpful and Kind. Use the tools provided to"" assist the user. Return all code in markdown format."),llm=llm,max_loops="auto",autosave=True,dashboard=False,streaming_on=True,verbose=True,stopping_token="<DONE>",interactive=True,tools=[terminal,browser,file_editor,create_file],code_interpreter=True,),Agent(agent_name="Codex",system_prompt=("An AI coding assistant capable of writing and understanding"" code snippets in various programming languages."),llm=llm,max_loops="auto",autosave=True,dashboard=False,streaming_on=True,verbose=True,stopping_token="<DONE>",interactive=True,tools=[terminal,browser,file_editor,create_file],code_interpreter=True,),Agent(agent_name="Tabnine",system_prompt=("A code completion AI that provides suggestions for code"" completion and code improvements."),llm=llm,max_loops="auto",autosave=True,dashboard=False,streaming_on=True,verbose=True,stopping_token="<DONE>",interactive=True,tools=[terminal,browser,file_editor,create_file],code_interpreter=True,),]# Create MajorityVoting instancemajority_voting=MajorityVoting(agents)# Run the majority voting systemresult=majority_voting.run("What is the capital of France?")print(result)# Output: 'Paris'
fromswarms.structs.agentimportAgentfromswarms.structs.majority_votingimportMajorityVoting# Initialize agentsagents=[Agent(agent_name="Devin",system_prompt=("Autonomous agent that can interact with humans and other"" agents. Be Helpful and Kind. Use the tools provided to"" assist the user. Return all code in markdown format."),llm=llm,max_loops="auto",autosave=True,dashboard=False,streaming_on=True,verbose=True,stopping_token="<DONE>",interactive=True,tools=[terminal,browser,file_editor,create_file],code_interpreter=True,),Agent(agent_name="Codex",system_prompt=("An AI coding assistant capable of writing and understanding"" code snippets in various programming languages."),llm=llm,max_loops="auto",autosave=True,dashboard=False,streaming_on=True,verbose=True,stopping_token="<DONE>",interactive=True,tools=[terminal,browser,file_editor,create_file],code_interpreter=True,),Agent(agent_name="Tabnine",system_prompt=("A code completion AI that provides suggestions for code"" completion and code improvements."),llm=llm,max_loops="auto",autosave=True,dashboard=False,streaming_on=True,verbose=True,stopping_token="<DONE>",interactive=True,tools=[terminal,browser,file_editor,create_file],code_interpreter=True,),]# Create MajorityVoting instancemajority_voting=MajorityVoting(agents)# Run the majority voting system with a different taskresult=majority_voting.run("Create a new file for a plan to take over the world.")print(result)