dialogue simulator

Former-commit-id: ba09edb8df
group-chat
Kye 1 year ago
parent 8a4bf43da3
commit 4d7d37b9f5

@ -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

@ -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

Loading…
Cancel
Save