From 53067f8b9290986f22e2ef94eb92e5df1c24fb66 Mon Sep 17 00:00:00 2001 From: Parth Patel <64201651+parthbs@users.noreply.github.com> Date: Fri, 21 Mar 2025 23:27:24 +0530 Subject: [PATCH] add Mem0 OSS support (#2429) Co-authored-by: Brandon Hancock (bhancock_ai) <109994880+bhancockio@users.noreply.github.com> --- src/crewai/memory/storage/mem0_storage.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/crewai/memory/storage/mem0_storage.py b/src/crewai/memory/storage/mem0_storage.py index be889afff..0319c6a8a 100644 --- a/src/crewai/memory/storage/mem0_storage.py +++ b/src/crewai/memory/storage/mem0_storage.py @@ -1,7 +1,7 @@ import os from typing import Any, Dict, List -from mem0 import MemoryClient +from mem0 import Memory, MemoryClient from crewai.memory.storage.interface import Storage @@ -32,13 +32,16 @@ class Mem0Storage(Storage): mem0_org_id = config.get("org_id") mem0_project_id = config.get("project_id") - # Initialize MemoryClient with available parameters - if mem0_org_id and mem0_project_id: - self.memory = MemoryClient( - api_key=mem0_api_key, org_id=mem0_org_id, project_id=mem0_project_id - ) + # Initialize MemoryClient or Memory based on the presence of the mem0_api_key + if mem0_api_key: + if mem0_org_id and mem0_project_id: + self.memory = MemoryClient( + api_key=mem0_api_key, org_id=mem0_org_id, project_id=mem0_project_id + ) + else: + self.memory = MemoryClient(api_key=mem0_api_key) else: - self.memory = MemoryClient(api_key=mem0_api_key) + self.memory = Memory() # Fallback to Memory if no Mem0 API key is provided def _sanitize_role(self, role: str) -> str: """