From 77fa1b18c72334dff65fa2ee39b60d1780bc08f4 Mon Sep 17 00:00:00 2001 From: Vidit-Ostwal Date: Fri, 28 Mar 2025 22:30:32 +0530 Subject: [PATCH] added early return --- src/crewai/memory/contextual/contextual_memory.py | 4 ++++ src/crewai/memory/storage/mem0_storage.py | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/crewai/memory/contextual/contextual_memory.py b/src/crewai/memory/contextual/contextual_memory.py index cdb9cf836..a9f657d8a 100644 --- a/src/crewai/memory/contextual/contextual_memory.py +++ b/src/crewai/memory/contextual/contextual_memory.py @@ -94,6 +94,10 @@ class ContextualMemory: Returns: str: Formatted user memories as bullet points, or an empty string if none found. """ + + if self.um is None: + return "" + user_memories = self.um.search(query) if not user_memories: return "" diff --git a/src/crewai/memory/storage/mem0_storage.py b/src/crewai/memory/storage/mem0_storage.py index 0319c6a8a..6c9ffc682 100644 --- a/src/crewai/memory/storage/mem0_storage.py +++ b/src/crewai/memory/storage/mem0_storage.py @@ -31,6 +31,7 @@ class Mem0Storage(Storage): mem0_api_key = config.get("api_key") or os.getenv("MEM0_API_KEY") mem0_org_id = config.get("org_id") mem0_project_id = config.get("project_id") + mem0_local_config = config.get("local_mem0_config") # Initialize MemoryClient or Memory based on the presence of the mem0_api_key if mem0_api_key: @@ -41,7 +42,10 @@ class Mem0Storage(Storage): else: self.memory = MemoryClient(api_key=mem0_api_key) else: - self.memory = Memory() # Fallback to Memory if no Mem0 API key is provided + if mem0_local_config and len(mem0_local_config): + self.memory = Memory.from_config(config) + else: + self.memory = Memory() def _sanitize_role(self, role: str) -> str: """ @@ -114,3 +118,7 @@ class Mem0Storage(Storage): agents = [self._sanitize_role(agent.role) for agent in agents] agents = "_".join(agents) return agents + + def reset(self): + if self.memory: + self.memory.reset()