Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix API Key Behavior and Entity Handling in Mem0 Integration #1857

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/concepts/memory.mdx
Original file line number Diff line number Diff line change
@@ -134,6 +134,23 @@ crew = Crew(
)
```

## Memory Configuration Options
If you want to access a specific organization and project, you can set the `org_id` and `project_id` parameters in the memory configuration.

```python Code
from crewai import Crew

crew = Crew(
agents=[...],
tasks=[...],
verbose=True,
memory=True,
memory_config={
"provider": "mem0",
"config": {"user_id": "john", "org_id": "my_org_id", "project_id": "my_project_id"},
},
)
```

## Additional Embedding Providers

18 changes: 13 additions & 5 deletions src/crewai/memory/storage/mem0_storage.py
Original file line number Diff line number Diff line change
@@ -27,10 +27,18 @@ def __init__(self, type, crew=None):
raise ValueError("User ID is required for user memory type")

# API key in memory config overrides the environment variable
mem0_api_key = self.memory_config.get("config", {}).get("api_key") or os.getenv(
"MEM0_API_KEY"
)
self.memory = MemoryClient(api_key=mem0_api_key)
config = self.memory_config.get("config", {})
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")

# 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
)
else:
self.memory = MemoryClient(api_key=mem0_api_key)

def _sanitize_role(self, role: str) -> str:
"""
@@ -57,7 +65,7 @@ def save(self, value: Any, metadata: Dict[str, Any]) -> None:
metadata={"type": "long_term", **metadata},
)
elif self.memory_type == "entities":
entity_name = None
entity_name = self._get_agent_name()
self.memory.add(
value, user_id=entity_name, metadata={"type": "entity", **metadata}
)