From 474e93f7c4db2e482b0f563f0bf9bef6684c2ec7 Mon Sep 17 00:00:00 2001 From: Kye Date: Thu, 6 Jul 2023 14:12:59 -0400 Subject: [PATCH] error handling for bossnode --- swarms/agents/boss/boss_agent.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/swarms/agents/boss/boss_agent.py b/swarms/agents/boss/boss_agent.py index d9e9361d..de985d63 100644 --- a/swarms/agents/boss/boss_agent.py +++ b/swarms/agents/boss/boss_agent.py @@ -1,4 +1,5 @@ from swarms.tools.agent_tools import * +from pydantic import ValidationError # ---------- Boss Node ---------- class BossNode: @@ -9,14 +10,31 @@ class BossNode: self.verbose = verbose self.max_iterations = max_iterations - self.baby_agi = BabyAGI.from_llm( - llm=self.llm, - vectorstore=self.vectorstore, - task_execution_chain=self.task_execution_chain - ) + try: + # Ensure llm is a dictionary before passing it to BabyAGI + assert isinstance(llm, dict), "llm should be a dictionary." + + self.baby_agi = BabyAGI.from_llm( + llm=self.llm, + vectorstore=self.vectorstore, + task_execution_chain=self.task_execution_chain, + verbose=self.verbose, + max_iterations=self.max_iterations, + ) + except ValidationError as e: + print(f"Validation Error while initializing BabyAGI: {e}") + except Exception as e: + print(f"Unexpected Error while initializing BabyAGI: {e}") def create_task(self, objective): - return {"objective": objective} + try: + task = {"objective": objective} + return task + except Exception as e: + print(f"Unexpected Error while creating a task: {e}") def execute_task(self, task): - self.baby_agi(task) \ No newline at end of file + try: + self.baby_agi(task) + except Exception as e: + print(f"Unexpected Error while executing a task: {e}") \ No newline at end of file