Repository: crewAIInc/crewAI (python)

Issue:
[BUG]Mem0 local config not being applied
### Description

The mem0 local config is not being applied when agent memory is being instantiated.

I belive the issue is in storage/mem0_storage on line 50
if mem0_local_config and len(mem0_local_config):
                self.memory = Memory.from_config(config)

Should be

if mem0_local_config and len(mem0_local_config):
                self.memory = Memory.from_config(mem0_local_config)

### Steps to Reproduce

Just try using mem0 with a local config. I am attempting to use Gemini as an embedder but the exceptions I get state the OpenAI API key is not set.

### Expected behavior

The local config should be applied

### Screenshots/Code snippets

embedder_config = {
    "provider": "google",
    "config": {
        "model": "models/text-embedding-004",
        "api_key": GEMINI_API_KEY,
    }
}
----
@crew
    def crew(self) -> Crew:
        """Creates the TedCrew crew"""

        return Crew(
            agents=self.agents,
            tasks=self.tasks,
            process=Process.sequential,
            verbose=True,
            memory=True,
            memory_config={
                "provider": "mem0",
                "config": {"user_id": "tedcrew", 'local_mem0_config': mem0_config},
                "user_memory" : {} #Set user_memory explicitly to a dictionary, we are working on this issue.
            },
            # Long-term memory for persistent storage across sessions
            long_term_memory = LongTermMemory(
                storage=LTMSQLiteStorage(
                    db_path=f"{DATA_DIR}/long_term_memory_storage.db"
                )
            ),
            # Short-term memory for current context using RAG
            short_term_memory = ShortTermMemory(
                storage = RAGStorage(
                        embedder_config=embedder_config,
                        type="short_term",
                        path=f"{DATA_DIR}/"
                    )
            ),
            # Entity memory for tracking key information about entities
            entity_memory = EntityMemory(
                storage=RAGStorage(
                    embedder_config=embedder_config,
                    type="short_term",
                    path=f"{DATA_DIR}/"
                )
            ),
            embedder=embedder_config
        )

### Operating System

macOS Sonoma

### Python Version

3.12

### crewAI Version

0.114.0

### crewAI Tools Version

0.40.1

### Virtual Environment

Venv

### Evidence

<img width="1059" alt="Image" src="https://github.com/user-attachments/assets/bf0f8d50-708d-4cc8-9a2a-e10950a173fa" />

### Possible Solution

I belive the issue is in storage/mem0_storage on line 50
if mem0_local_config and len(mem0_local_config):
                self.memory = Memory.from_config(config)

Should be

if mem0_local_config and len(mem0_local_config):
                self.memory = Memory.from_config(mem0_local_config)

### Additional context

None

Pull request description:
Fix: Use mem0_local_config instead of config in Memory.from_config
# Fix: Use mem0_local_config instead of config in Memory.from_config

Fixes #2587

## Description
The mem0 local configuration was not being properly applied when agent memory was being instantiated. This PR fixes the issue by changing the parameter passed to Memory.from_config from 'config' to 'mem0_local_config'.

## Changes
- Changed the parameter passed to Memory.from_config from 'config' to 'mem0_local_config' in mem0_storage.py
- Added a test to verify that the local mem0 configuration is properly passed to Memory.from_config

## Testing
- Added a new test case that verifies the fix works correctly
- All tests are passing

Link to Devin run: https://app.devin.ai/sessions/0c70180337924c108156b7eed0de46b6
Author: Joe Moura (joao@crewai.com)


Patch:
diff --git a/src/crewai/memory/storage/mem0_storage.py b/src/crewai/memory/storage/mem0_storage.py
index ccf8cc81..83578872 100644
--- a/src/crewai/memory/storage/mem0_storage.py
+++ b/src/crewai/memory/storage/mem0_storage.py
@@ -48,7 +48,7 @@ class Mem0Storage(Storage):
                 self.memory = MemoryClient(api_key=mem0_api_key)
         else:
             if mem0_local_config and len(mem0_local_config):
-                self.memory = Memory.from_config(config)
+                self.memory = Memory.from_config(mem0_local_config)
             else:
                 self.memory = Memory()
 


Test patch:
diff --git a/tests/storage/test_mem0_storage.py b/tests/storage/test_mem0_storage.py
index f9e56739..f0c62d48 100644
--- a/tests/storage/test_mem0_storage.py
+++ b/tests/storage/test_mem0_storage.py
@@ -29,7 +29,7 @@ def mem0_storage_with_mocked_config(mock_mem0_memory):
     """Fixture to create a Mem0Storage instance with mocked dependencies"""
 
     # Patch the Memory class to return our mock
-    with patch("mem0.memory.main.Memory.from_config", return_value=mock_mem0_memory):
+    with patch("mem0.memory.main.Memory.from_config", return_value=mock_mem0_memory) as mock_from_config:
         config = {
             "vector_store": {
                 "provider": "mock_vector_store",
@@ -66,13 +66,15 @@ def mem0_storage_with_mocked_config(mock_mem0_memory):
         )
 
         mem0_storage = Mem0Storage(type="short_term", crew=crew)
-        return mem0_storage
+        return mem0_storage, mock_from_config, config
 
 
 def test_mem0_storage_initialization(mem0_storage_with_mocked_config, mock_mem0_memory):
     """Test that Mem0Storage initializes correctly with the mocked config"""
-    assert mem0_storage_with_mocked_config.memory_type == "short_term"
-    assert mem0_storage_with_mocked_config.memory is mock_mem0_memory
+    mem0_storage, mock_from_config, config = mem0_storage_with_mocked_config
+    assert mem0_storage.memory_type == "short_term"
+    assert mem0_storage.memory is mock_mem0_memory
+    mock_from_config.assert_called_once_with(config)
 
 
 @pytest.fixture