From 536c793ea6c4fe79c79cab2f711d48d929ec9722 Mon Sep 17 00:00:00 2001
From: Kye <kye@apacmediasolutions.com>
Date: Tue, 26 Sep 2023 18:35:48 -0400
Subject: [PATCH] multi agent debate

---
 swarms/agents/base.py         | 51 ----------------------------------
 swarms/swarms/__init__.py     |  2 ++
 swarms/swarms/base.py         |  4 ++-
 swarms/swarms/groupchat.py    | 52 +++++++++++++++++------------------
 swarms/swarms/simple_swarm.py |  7 +++--
 5 files changed, 35 insertions(+), 81 deletions(-)

diff --git a/swarms/agents/base.py b/swarms/agents/base.py
index 9e0a641c..e69de29b 100644
--- a/swarms/agents/base.py
+++ b/swarms/agents/base.py
@@ -1,51 +0,0 @@
-from abc import ABC, abstractmethod
-from agent_protocol import Agent, Step, Task
-
-
-class AbstractAgent:
-    @staticmethod
-    async def plan(step: Step) -> Step:
-        task = await Agent.db.get_task(step.task_id)
-        steps = generate_steps(task.input)
-
-        last_step = steps[-1]
-        for step in steps[:-1]:
-            await Agent.db.create_step(
-                task_id=task.task_id, 
-                name=step, 
-                pass
-            )
-
-        await Agent.db.create_step(
-            task_id=task.task_id, 
-            name=last_step, 
-            is_last=True
-        )
-        step.output = steps
-        return step
-
-    @staticmethod
-    async def execute(step: Step) -> Step:
-        # Use tools, websearch, etc.
-        ...
-
-    @staticmethod
-    async def task_handler(task: Task) -> None:
-        await Agent.db.create_step(
-            task_id=task.task_id, 
-            name="plan", 
-            pass
-        )
-
-    @staticmethod
-    async def step_handler(step: Step) -> Step:
-        if step.name == "plan":
-            await AbstractAgent.plan(step)
-        else:
-            await AbstractAgent.execute(step)
-
-        return step
-
-    @staticmethod
-    def start_agent():
-        Agent.setup_agent(AbstractAgent.task_handler, AbstractAgent.step_handler).start()
\ No newline at end of file
diff --git a/swarms/swarms/__init__.py b/swarms/swarms/__init__.py
index 8ec78e9f..6aa0714e 100644
--- a/swarms/swarms/__init__.py
+++ b/swarms/swarms/__init__.py
@@ -6,3 +6,5 @@ from swarms.swarms.orchestrate import Orchestrator
 from swarms.swarms.god_mode import GodMode
 from swarms.swarms.simple_swarm import SimpleSwarm
 from swarms.swarms.multi_agent_debate import MultiAgentDebate
+from swarms.swarms.groupchat import GroupChat
+
diff --git a/swarms/swarms/base.py b/swarms/swarms/base.py
index b1d1a17f..ae9326f3 100644
--- a/swarms/swarms/base.py
+++ b/swarms/swarms/base.py
@@ -18,4 +18,6 @@ class AbstractSwarm(ABC):
 
     @abstractmethod
     def run(self):
-        pass
\ No newline at end of file
+        pass
+
+    
\ No newline at end of file
diff --git a/swarms/swarms/groupchat.py b/swarms/swarms/groupchat.py
index 2e8dca03..9b5e9552 100644
--- a/swarms/swarms/groupchat.py
+++ b/swarms/swarms/groupchat.py
@@ -7,29 +7,29 @@ from swarms.workers.worker import Worker
 
 @dataclass
 class GroupChat:
-    """A group chat with multiple participants with a list of agents and a max number of rounds"""
+    """A group chat with multiple participants with a list of workers and a max number of rounds"""
 
-    agents: List[Worker]
+    workers: List[Worker]
     messages: List[Dict]
     max_rounds: int = 10
-    admin_name: str = "Admin" #admin agent
+    admin_name: str = "Admin" #admin worker
 
     @property
-    def agent_names(self) -> List[str]:
-        """returns the names of the agents in the group chat"""
-        return [agent.ai_name for agent in self.agents]
+    def worker_names(self) -> List[str]:
+        """returns the names of the workers in the group chat"""
+        return [worker.ai_name for worker in self.workers]
     
     def reset(self):
         self.messages.clear()
     
-    def agent_by_name(self, name: str) -> Worker:
+    def worker_by_name(self, name: str) -> Worker:
         """Find the next speaker baed on the message"""
-        return self.agents[self.agent_names.index(name)]
+        return self.workers[self.worker_names.index(name)]
     
-    def next_agent(self, agent: Worker) -> Worker:
-        """Returns the next agent in the list"""
-        return self.agents[
-            (self.agents_names.index(agent.ai_name) + 1) % len(self.agents)
+    def next_worker(self, worker: Worker) -> Worker:
+        """Returns the next worker in the list"""
+        return self.workers[
+            (self.workers_names.index(worker.ai_name) + 1) % len(self.workers)
         ]
     
     def select_speaker_msg(self):
@@ -39,7 +39,7 @@ class GroupChat:
         You are in a role play game the following rules are available:
         {self.__participant_roles()}.
 
-        Read the following conversation then select the next role from {self.agent_names}
+        Read the following conversation then select the next role from {self.worker_names}
         to play and only return the role
         """
     
@@ -55,20 +55,20 @@ class GroupChat:
             self.messages + [
                 {
                     "role": "system",
-                    "context": f"Read the above conversation. Then select the next role from {self.agent_names} to play. Only return the role.",
+                    "context": f"Read the above conversation. Then select the next role from {self.worker_names} to play. Only return the role.",
                 }
             ]
         )
         if not final:
-            return self.next_agent(last_speaker)
+            return self.next_worker(last_speaker)
         try:
-            return self.agent_by_name(name)
+            return self.worker_by_name(name)
         except ValueError:
-            return self.next_agent(last_speaker)
+            return self.next_worker(last_speaker)
         
     def _participant_roles(self):
         return "\n".join(
-            [f"{agent.ai_name}: {agent.system_message}" for agent in self.agents] 
+            [f"{worker.ai_name}: {worker.system_message}" for worker in self.workers] 
         )
     
 
@@ -117,12 +117,12 @@ class GroupChatManager(Worker):
             
             groupchat.messages.append(message)
 
-            #broadcast the message to all agents except the speaker
-            for agent in groupchat.agents:
-                if agent != speaker:
+            #broadcast the message to all workers except the speaker
+            for worker in groupchat.workers:
+                if worker != speaker:
                     self.send(
                         message,
-                        agent,
+                        worker,
                         request_reply=False,
                         silent=True,
                     )
@@ -137,12 +137,12 @@ class GroupChatManager(Worker):
             
             except KeyboardInterrupt:
                 #let the admin speak if interrupted
-                if groupchat.admin_name in groupchat.agent_names:
-                    #admin agent is a particpant
-                    speaker = groupchat.agent_by_name(groupchat.admin_name)
+                if groupchat.admin_name in groupchat.worker_names:
+                    #admin worker is a particpant
+                    speaker = groupchat.worker_by_name(groupchat.admin_name)
                     reply = speaker.generate_reply(sender=self)
                 else:
-                    #admin agent is not found in particpants
+                    #admin worker is not found in particpants
                     raise
             if reply is None:
                 break
diff --git a/swarms/swarms/simple_swarm.py b/swarms/swarms/simple_swarm.py
index 579c367c..1ffe260f 100644
--- a/swarms/swarms/simple_swarm.py
+++ b/swarms/swarms/simple_swarm.py
@@ -4,8 +4,8 @@ class SimpleSwarm:
     def __init__(
        self,
        num_workers,
-        openai_api_key,
-        ai_name
+       openai_api_key,
+       ai_name
     ):
         """
         
@@ -24,11 +24,12 @@ class SimpleSwarm:
 
     def run(self, task):
         responses = []
+
         for worker in self.workers:
             response = worker.run(task)
             responses.append(response)
+            
         return responses
     
     def __call__(self, task):
         return self.run(task) 
-    
\ No newline at end of file