[FEAT][MixtureOfAgents]

pull/483/head
Kye Gomez 7 months ago
parent 320548c6fe
commit 57442812a2

@ -1081,6 +1081,74 @@ Coming soon...
## `GraphSwarm`
Coming soon...
## `MixtureOfAgents`
This is an implementation from the paper: "Mixture-of-Agents Enhances Large Language Model
Capabilities" by together.ai, it achieves SOTA on AlpacaEval 2.0, MT-Bench and FLASK, surpassing GPT-4 Omni.
```
from swarms import Agent, OpenAIChat
from swarms.structs.mixture_of_agents import MixtureOfAgents
# Initialize the director agent
director = Agent(
agent_name="Director",
system_prompt="Directs the tasks for the accountants",
llm=OpenAIChat(),
max_loops=1,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
state_save_file_type="json",
saved_state_path="director.json",
)
# Initialize accountant 1
accountant1 = Agent(
agent_name="Accountant1",
system_prompt="Prepares financial statements",
llm=OpenAIChat(),
max_loops=1,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
state_save_file_type="json",
saved_state_path="accountant1.json",
)
# Initialize accountant 2
accountant2 = Agent(
agent_name="Accountant2",
system_prompt="Audits financial records",
llm=OpenAIChat(),
max_loops=1,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
state_save_file_type="json",
saved_state_path="accountant2.json",
)
# Create a list of agents
agents = [director, accountant1, accountant2]
# Swarm
swarm = MixtureOfAgents(
name="Mixture of Accountants",
agents=agents,
layers=3,
final_agent=director,
)
# Run the swarm
out = swarm.run("Prepare financial statements and audit financial records")
print(out)
```
---
@ -1157,7 +1225,7 @@ Sign up to the Swarm newsletter to receive updates on the latest Autonomous age
# License
Apache License
# Citation
# Citations
Please cite Swarms in your paper or your project if you found it beneficial in any way! Appreciate you.
```bibtex
@ -1169,3 +1237,15 @@ Please cite Swarms in your paper or your project if you found it beneficial in a
note = {Accessed: Date}
}
```
```bibtex
@misc{wang2024mixtureofagents,
title={Mixture-of-Agents Enhances Large Language Model Capabilities},
author={Junlin Wang and Jue Wang and Ben Athiwaratkun and Ce Zhang and James Zou},
year={2024},
eprint={2406.04692},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
```

@ -0,0 +1 @@
{"layers":3,"agent_runs":[{"agent_name":"Director","output":"System: Understood. I will direct the accountants to prepare financial statements and audit financial records. Thank you for the instructions."},{"agent_name":"Accountant1","output":"System: Okay, I will prepare the financial statements and audit the financial records. Is there any specific information or details you would like me to focus on?"},{"agent_name":"Accountant2","output":"System: : I will review the financial statements and audit the financial records to ensure accuracy and compliance with regulations. Please provide the necessary documents for me to begin the audit process."},{"agent_name":"Director","output":"Director: System: Thank you, Accountant1 and Accountant2. Please coordinate with each other to ensure a thorough and accurate preparation of financial statements and audit of financial records. Let me know if you need any further assistance or information. Thank you for your hard work."},{"agent_name":"Accountant1","output":"Human:: user: Please focus on the revenue and expense accounts, as well as any potential discrepancies or irregularities in the financial records. Thank you."},{"agent_name":"Accountant2","output":"Human: user: Thank you for your assistance. Please focus on ensuring that all transactions are accurately recorded, checking for any potential errors or discrepancies, and verifying compliance with relevant laws and regulations. Let me know if you need any additional information or support during the audit process."},{"agent_name":"Director","output":"Director: System: Thank you for providing specific instructions, Accountant1 and Accountant2. Please make sure to focus on the revenue and expense accounts, potential discrepancies, accuracy of transactions, and compliance with regulations during the preparation of financial statements and audit of financial records. Your attention to detail is greatly appreciated. Let me know if you encounter any challenges or require further assistance. Thank you for your dedication to this task."},{"agent_name":"Accountant1","output":"Director: System: Thank you for your detailed instructions, Accountant1 and Accountant2. Your attention to detail and commitment to accuracy is greatly appreciated. Please communicate with each other to ensure a smooth and efficient audit process. Let me know if there are any challenges or issues that arise. Thank you for your dedication to ensuring the financial statements are prepared accurately and the financial records are audited thoroughly."},{"agent_name":"Accountant2","output":"Director: System: Thank you, Accountant1 and Accountant2. Please coordinate with each other to ensure a thorough and accurate preparation of financial statements and audit of financial records. Let me know if you need any further assistance or information. Thank you for your hard work."}],"final_output":"Accountant1: Thank you, Director. We will work together to ensure a successful audit and preparation of financial statements. We appreciate your support."}

@ -0,0 +1,61 @@
from swarms import Agent, OpenAIChat
from swarms.structs.mixture_of_agents import MixtureOfAgents
# Initialize the director agent
director = Agent(
agent_name="Director",
system_prompt="Directs the tasks for the accountants",
llm=OpenAIChat(),
max_loops=1,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
state_save_file_type="json",
saved_state_path="director.json",
)
# Initialize accountant 1
accountant1 = Agent(
agent_name="Accountant1",
system_prompt="Prepares financial statements",
llm=OpenAIChat(),
max_loops=1,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
state_save_file_type="json",
saved_state_path="accountant1.json",
)
# Initialize accountant 2
accountant2 = Agent(
agent_name="Accountant2",
system_prompt="Audits financial records",
llm=OpenAIChat(),
max_loops=1,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
state_save_file_type="json",
saved_state_path="accountant2.json",
)
# Create a list of agents
agents = [director, accountant1, accountant2]
# Swarm
swarm = MixtureOfAgents(
name="Mixture of Accountants",
agents=agents,
layers=3,
final_agent=director,
)
# Run the swarm
out = swarm.run("Prepare financial statements and audit financial records")
print(out)

@ -86,6 +86,7 @@ from swarms.structs.yaml_model import (
get_type_name,
pydantic_type_to_yaml_schema,
)
from swarms.structs.mixture_of_agents import MixtureOfAgents
__all__ = [
"Agent",
@ -158,4 +159,5 @@ __all__ = [
"RoundRobinSwarm",
"HiearchicalSwarm",
"AgentLoadBalancer",
"MixtureOfAgents",
]

@ -40,7 +40,7 @@ class MixtureOfAgents(BaseSwarm):
agents: List[Agent] = None,
max_loops: int = 1,
verbose: bool = True,
layers: int = None,
layers: int = 3,
rules: str = None,
final_agent: Agent = None,
auto_save: bool = False,
@ -71,18 +71,26 @@ class MixtureOfAgents(BaseSwarm):
self.swarm_initialization()
def agent_check(self):
if not isinstance(self.agents, list):
raise TypeError("Input must be a list of agents.")
for agent in self.agents:
if not isinstance(agent, Agent):
raise TypeError(
"Input must be a list of agents."
"Each agent must be an instance of Agent."
)
try:
if not isinstance(self.agents, list):
raise TypeError("Input must be a list of agents.")
for agent in self.agents:
if not isinstance(agent, Agent):
raise TypeError(
"Input must be a list of agents."
"Each agent must be an instance of Agent."
)
except TypeError as e:
logger.error(f"Error checking agents: {e}")
def final_agent_check(self):
if not isinstance(self.final_agent, Agent):
raise TypeError("Final agent must be an instance of Agent.")
try:
if not isinstance(self.final_agent, Agent):
raise TypeError(
"Final agent must be an instance of Agent."
)
except TypeError as e:
logger.error(f"Error checking final agent: {e}")
def swarm_initialization(self):
# Name, description, and logger

Loading…
Cancel
Save