From ffea0d9810605997cdf50f88b58299efb924afa0 Mon Sep 17 00:00:00 2001 From: Kye Date: Tue, 22 Aug 2023 00:00:34 -0400 Subject: [PATCH] __call__ --- swarms/orchestrator/autoscaler.py | 22 ++++++++++++++++------ swarms/workers/autobot.py | 10 ++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/swarms/orchestrator/autoscaler.py b/swarms/orchestrator/autoscaler.py index 0fad0382..e78b5d4f 100644 --- a/swarms/orchestrator/autoscaler.py +++ b/swarms/orchestrator/autoscaler.py @@ -3,11 +3,17 @@ import queue from time import sleep from swarms.workers.autobot import AutoBot +from swarms.utils.decorators import error_decorator, log_decorator, timing_decorator + # TODO Handle task assignment and task delegation # TODO: User task => decomposed into very small sub tasks => sub tasks assigned to workers => workers complete and update the swarm, can ask for help from other agents. # TODO: Missing, Task Assignment, Task delegation, Task completion, Swarm level communication with vector db +# class AutoScaler: + @log_decorator + @error_decorator + @timing_decorator def __init__(self, initial_agents=10, scale_up_factor=1, @@ -23,6 +29,9 @@ class AutoScaler: def add_task(self, task): self.tasks_queue.put(task) + @log_decorator + @error_decorator + @timing_decorator def scale_up(self): with self.lock: new_agents_counts = len(self.agents_pool) * self.scale_up_factor @@ -34,6 +43,9 @@ class AutoScaler: if len(self.agents_pool) > 10: #ensure minmum of 10 agents del self.agents_pool[-1] #remove last agent + @log_decorator + @error_decorator + @timing_decorator def monitor_and_scale(self): while True: sleep(60)#check minute @@ -44,7 +56,10 @@ class AutoScaler: self.scale_up() elif active_agents / len(self.agents_pool) < self.idle_threshold: self.scale_down() - + + @log_decorator + @error_decorator + @timing_decorator def start(self): monitor_thread = threading.Thread(target=self.monitor_and_scale) monitor_thread.start() @@ -56,8 +71,3 @@ class AutoScaler: if available_agent: available_agent.run(task) - - - - - \ No newline at end of file diff --git a/swarms/workers/autobot.py b/swarms/workers/autobot.py index 8abe4c93..aaa0d082 100644 --- a/swarms/workers/autobot.py +++ b/swarms/workers/autobot.py @@ -93,5 +93,15 @@ class AutoBot: try: result = self.agent.run([task]) return result + except Exception as error: + raise RuntimeError(f"Error while running agent: {error}") + + @log_decorator + @error_decorator + @timing_decorator + def __call__(self, task): + try: + results = self.agent.run([task]) + return results except Exception as error: raise RuntimeError(f"Error while running agent: {error}") \ No newline at end of file