From 6224a59fce702b6186bb6e2b567cc54300be1d44 Mon Sep 17 00:00:00 2001 From: Kye Date: Thu, 13 Jul 2023 17:22:00 -0400 Subject: [PATCH] clean up + documentation + modularization + error handloinh Former-commit-id: 47ad7791d8d7c2b6d1d3e1c084e3026cdcd6c488 --- swarms/agents/boss/BossNode.py | 35 +++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/swarms/agents/boss/BossNode.py b/swarms/agents/boss/BossNode.py index d8c000bb..a9a8a844 100644 --- a/swarms/agents/boss/BossNode.py +++ b/swarms/agents/boss/BossNode.py @@ -1,9 +1,19 @@ from swarms.tools.agent_tools import * from pydantic import ValidationError +import logging + +logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') # ---------- Boss Node ---------- class BossNode: + """ + The BossNode class is responsible for creating and executing tasks using the BabyAGI model. + It takes a language model (llm), a vectorstore for memory, an agent_executor for task execution, and a maximum number of iterations for the BabyAGI model. + """ def __init__(self, llm, vectorstore, agent_executor, max_iterations): + if not llm or not vectorstore or not agent_executor or not max_iterations: + logging.error("llm, vectorstore, agent_executor, and max_iterations cannot be None.") + raise ValueError("llm, vectorstore, agent_executor, and max_iterations cannot be None.") self.llm = llm self.vectorstore = vectorstore self.agent_executor = agent_executor @@ -17,11 +27,30 @@ class BossNode: max_iterations=self.max_iterations, ) except ValidationError as e: - print(f"Validation Error while initializing BabyAGI: {e}") + logging.error(f"Validation Error while initializing BabyAGI: {e}") + raise except Exception as e: - print(f"Unexpected Error while initializing BabyAGI: {e}") + logging.error(f"Unexpected Error while initializing BabyAGI: {e}") + raise + def create_task(self, objective): + """ + Creates a task with the given objective. + """ + if not objective: + logging.error("Objective cannot be empty.") + raise ValueError("Objective cannot be empty.") return {"objective": objective} def execute_task(self, task): - self.baby_agi(task) \ No newline at end of file + """ + Executes a task using the BabyAGI model. + """ + if not task: + logging.error("Task cannot be empty.") + raise ValueError("Task cannot be empty.") + try: + self.baby_agi(task) + except Exception as e: + logging.error(f"Error while executing task: {e}") + raise \ No newline at end of file