From ba09edb8dfd8b3a3832346d98da812d368d64cd5 Mon Sep 17 00:00:00 2001 From: Kye Date: Sat, 23 Sep 2023 23:11:17 -0400 Subject: [PATCH] dialogue simulator --- swarms/swarms/dialogue_simulator.py | 48 +++++++++++++++++++++++++++++ swarms/workers/worker.py | 11 +++++-- 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 swarms/swarms/dialogue_simulator.py diff --git a/swarms/swarms/dialogue_simulator.py b/swarms/swarms/dialogue_simulator.py new file mode 100644 index 00000000..18cc989d --- /dev/null +++ b/swarms/swarms/dialogue_simulator.py @@ -0,0 +1,48 @@ +from typing import List, Callable + + +class DialogueSimulator: + def __init__( + self, + agents, + selection_func + ): + self.agents = agents + self._step = 0 + self.select_next_speaker = selection_func + + def reset(self): + for agent in self.agents: + agent.reset() + + def start(self, name: str, message: str): + #init conv with a message from name + for agent in self.agents: + agent.receive(name, message) + + #increment time + self._step += 1 + + def step(self) -> tuple[str, str]: + #choose next speaker + speaker_idx = self.select_next_speaker( + self._step, + self.agent + ) + speaker = self.agents[speaker_idx] + + #2. next speaker ends message + message = speaker.send() + + #everyone receives messages + for receiver in self.agents: + receiver.receive(speaker.name, message) + + #increment time + self._step += 1 + + return speaker.name, message + + def select_next_speaker(step: int, agents) -> int: + idx = (step) % len(agents) + return idx diff --git a/swarms/workers/worker.py b/swarms/workers/worker.py index 0b94da26..7a098e50 100644 --- a/swarms/workers/worker.py +++ b/swarms/workers/worker.py @@ -8,11 +8,11 @@ from langchain_experimental.autonomous_agents import AutoGPT from swarms.tools.autogpt import ( ReadFileTool, + VQAinference, WriteFileTool, + compile, process_csv, query_website_tool, - compile, - VQAinference ) from swarms.utils.decorators import error_decorator, log_decorator, timing_decorator @@ -58,6 +58,13 @@ class Worker: self.setup_memory() self.setup_agent() + def reset(self): + self.message_history = ["Here is the conversation so far"] + + def receieve(self, name: str, message: str) -> None: + self.message_history.append(f"{name}: {message}") + + @log_decorator @error_decorator @timing_decorator