From a2f3566cd98d7b9c0fc77d50c5d8d7801e9dc915 Mon Sep 17 00:00:00 2001 From: Vidit Ostwal <110953813+Vidit-Ostwal@users.noreply.github.com> Date: Thu, 17 Apr 2025 18:29:15 +0530 Subject: [PATCH] Pr branch (#2312) * Adjust checking for callable crew object. Changes back to how it was being done before. Fixes #2307 * Fix specific memory reset errors. When not initiated, the function should raise the "memory system is not initialized" RuntimeError. * Remove print statement * Fixes test case --------- Co-authored-by: Carlos Souza --- src/crewai/cli/utils.py | 8 +++----- src/crewai/crew.py | 12 ++++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/crewai/cli/utils.py b/src/crewai/cli/utils.py index 8912036db..078afec60 100644 --- a/src/crewai/cli/utils.py +++ b/src/crewai/cli/utils.py @@ -273,11 +273,9 @@ def get_crew(crew_path: str = "crew.py", require: bool = False) -> Crew | None: for attr_name in dir(module): attr = getattr(module, attr_name) try: - if isinstance(attr, Crew) and hasattr(attr, "kickoff"): - print( - f"Found valid crew object in attribute '{attr_name}' at {crew_os_path}." - ) - return attr + if callable(attr) and hasattr(attr, "crew"): + crew_instance = attr().crew() + return crew_instance except Exception as e: print(f"Error processing attribute {attr_name}: {e}") diff --git a/src/crewai/crew.py b/src/crewai/crew.py index 76cae613e..f1c33f637 100644 --- a/src/crewai/crew.py +++ b/src/crewai/crew.py @@ -1399,12 +1399,12 @@ class Crew(BaseModel): RuntimeError: If the specified memory system fails to reset """ reset_functions = { - "long": (self._long_term_memory, "long term"), - "short": (self._short_term_memory, "short term"), - "entity": (self._entity_memory, "entity"), - "knowledge": (self.knowledge, "knowledge"), - "kickoff_outputs": (self._task_output_handler, "task output"), - "external": (self._external_memory, "external"), + "long": (getattr(self, "_long_term_memory", None), "long term"), + "short": (getattr(self, "_short_term_memory", None), "short term"), + "entity": (getattr(self, "_entity_memory", None), "entity"), + "knowledge": (getattr(self, "knowledge", None), "knowledge"), + "kickoff_outputs": (getattr(self, "_task_output_handler", None), "task output"), + "external": (getattr(self, "_external_memory", None), "external"), } memory_system, name = reset_functions[memory_type]