|
|
@ -27,6 +27,7 @@ from swarms.utils.decorators import error_decorator, log_decorator, timing_decor
|
|
|
|
ROOT_DIR = "./data/"
|
|
|
|
ROOT_DIR = "./data/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#main
|
|
|
|
class Worker:
|
|
|
|
class Worker:
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Useful for when you need to spawn an autonomous agent instance as a worker to accomplish complex tasks,
|
|
|
|
Useful for when you need to spawn an autonomous agent instance as a worker to accomplish complex tasks,
|
|
|
@ -60,12 +61,12 @@ class Worker:
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
def __init__(
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
self,
|
|
|
|
openai_api_key = None,
|
|
|
|
openai_api_key: str = None,
|
|
|
|
ai_name = "Autobot Swarm Worker",
|
|
|
|
ai_name: str = "Autobot Swarm Worker",
|
|
|
|
ai_role = "Worker in a swarm",
|
|
|
|
ai_role: str = "Worker in a swarm",
|
|
|
|
external_tools = None,
|
|
|
|
external_tools = None,
|
|
|
|
human_in_the_loop = False,
|
|
|
|
human_in_the_loop = False,
|
|
|
|
temperature = 0.5,
|
|
|
|
temperature: float = 0.5,
|
|
|
|
llm = None,
|
|
|
|
llm = None,
|
|
|
|
):
|
|
|
|
):
|
|
|
|
self.openai_api_key = openai_api_key
|
|
|
|
self.openai_api_key = openai_api_key
|
|
|
@ -91,7 +92,11 @@ class Worker:
|
|
|
|
def name(self):
|
|
|
|
def name(self):
|
|
|
|
return self.ai_name
|
|
|
|
return self.ai_name
|
|
|
|
|
|
|
|
|
|
|
|
def receieve(self, name: str, message: str) -> None:
|
|
|
|
def receieve(
|
|
|
|
|
|
|
|
self,
|
|
|
|
|
|
|
|
name: str,
|
|
|
|
|
|
|
|
message: str
|
|
|
|
|
|
|
|
) -> None:
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Receive a message and update the message history.
|
|
|
|
Receive a message and update the message history.
|
|
|
|
|
|
|
|
|
|
|
@ -107,8 +112,6 @@ class Worker:
|
|
|
|
def add(self, task, priority=0):
|
|
|
|
def add(self, task, priority=0):
|
|
|
|
self.task_queue.append((priority, task))
|
|
|
|
self.task_queue.append((priority, task))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setup_tools(self, external_tools):
|
|
|
|
def setup_tools(self, external_tools):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Set up tools for the worker.
|
|
|
|
Set up tools for the worker.
|
|
|
@ -177,7 +180,10 @@ class Worker:
|
|
|
|
@log_decorator
|
|
|
|
@log_decorator
|
|
|
|
@error_decorator
|
|
|
|
@error_decorator
|
|
|
|
@timing_decorator
|
|
|
|
@timing_decorator
|
|
|
|
def run(self, task):
|
|
|
|
def run(
|
|
|
|
|
|
|
|
self,
|
|
|
|
|
|
|
|
task: str = None
|
|
|
|
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Run the autonomous agent on a given task.
|
|
|
|
Run the autonomous agent on a given task.
|
|
|
|
|
|
|
|
|
|
|
@ -196,7 +202,10 @@ class Worker:
|
|
|
|
@log_decorator
|
|
|
|
@log_decorator
|
|
|
|
@error_decorator
|
|
|
|
@error_decorator
|
|
|
|
@timing_decorator
|
|
|
|
@timing_decorator
|
|
|
|
def __call__(self, task):
|
|
|
|
def __call__(
|
|
|
|
|
|
|
|
self,
|
|
|
|
|
|
|
|
task: str = None
|
|
|
|
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Make the worker callable to run the agent on a given task.
|
|
|
|
Make the worker callable to run the agent on a given task.
|
|
|
|
|
|
|
|
|
|
|
|