pull/55/head
Kye 1 year ago
parent 520a57236e
commit f0565da13c

@ -0,0 +1,34 @@
from typing import List
from swarms import Worker
class MultiAgentDebate:
def __init__(self, agents: List[Worker]):
self.agents = agents
def run(self, task: str):
results = []
for agent in self.agents:
response = agent.run(task)
results.append({
'agent': agent.ai_name,
'response': response
})
return results
# Initialize agents
agents = [
Worker(openai_api_key="", ai_name="Optimus Prime"),
Worker(openai_api_key="", ai_name="Bumblebee"),
Worker(openai_api_key="", ai_name="Megatron")
]
# Initialize multi-agent debate
debate = MultiAgentDebate(agents)
# Run task
task = "What were the winning boston marathon times for the past 5 years (ending in 2022)? Generate a table of the year, name, country of origin, and times."
results = debate.run(task)
# Print results
for result in results:
print(f"Agent {result['agent']} responded: {result['response']}")

@ -21,9 +21,12 @@ class DialogueSimulator:
while step < max_iters: while step < max_iters:
speaker_idx = step % len(self.agents) speaker_idx = step % len(self.agents)
speaker = self.agents[speaker_idx] speaker = self.agents[speaker_idx]
speaker_message = speaker.run() speaker_message = speaker.run(prompt)
for receiver in self.agents: for receiver in self.agents:
receiver.receive(speaker.name, speaker_message) message_history = f"Speaker Name: {speaker.name} and message: {speake_message}"
receiver.run(message_history)
print(f"({speaker.name}): {speaker_message}") print(f"({speaker.name}): {speaker_message}")
print("\n") print("\n")
step += 1 step += 1

@ -0,0 +1,34 @@
from typing import List
from swarms import Worker
class MultiAgentDebate:
def __init__(self, agents: List[Worker]):
self.agents = agents
def run(self, task: str):
results = []
for agent in self.agents:
response = agent.run(task)
results.append({
'agent': agent.ai_name,
'response': response
})
return results
# Initialize agents
agents = [
Worker(openai_api_key="", ai_name="Optimus Prime"),
Worker(openai_api_key="", ai_name="Bumblebee"),
Worker(openai_api_key="", ai_name="Megatron")
]
# Initialize multi-agent debate
debate = MultiAgentDebate(agents)
# Run task
task = "What were the winning boston marathon times for the past 5 years (ending in 2022)? Generate a table of the year, name, country of origin, and times."
results = debate.run(task)
# Print results
for result in results:
print(f"Agent {result['agent']} responded: {result['response']}")
Loading…
Cancel
Save