-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add support for retrieving user preferences and memories using Mem0 #1209
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Deshraj Yadav <[email protected]>
) | ||
return f"Entities:\n{formatted_results}" if em_results else "" | ||
|
||
def _fetch_user_memories(self, query) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is never being called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, there was a pending local commit for this. Pushed now.
Hey @joaomdmoura @theCyberTech could you please add the Mem0 API key to the CI variables to enable the Mem0 tests to run? |
Sure! I'm testing this again tomorrow so we cna merge :) |
Co-authored-by: Deshraj Yadav <[email protected]>
Hey @joaomdmoura @bhancockio Can you please review the PR, I have made the necessary changes. |
If I create a crew like this: crew = Crew(
agents=[qa_agent],
tasks=[qa_task],
verbose=True,
memory=True,
memory_config={
"provider": "mem0",
"config": {"user_id": "Personal Travel Planner Agent"},
},
process=Process.sequential,
) And I do not include a mem0 API key, I get the following error:
It's not clear that the Mem0 API key is missing which will make it hard for our users to know how to fix this bug |
Hey @bhancockio I have fixed |
src/crewai/crew.py
Outdated
self.entity_memory | ||
if self.entity_memory | ||
else EntityMemory(crew=self, embedder_config=self.embedder) | ||
self._entity_memory = EntityMemory( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add back in the check for if entity memory exists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
em: EntityMemory, | ||
um: UserMemory, | ||
): | ||
self.memory_provider = stm.memory_provider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to tie together memory provider with the short term memory?
Shouldn't we update the parameters of ContextualMemory to include memory_config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes makes sense. I have updated the params for ContextualMemory.
storage | ||
if storage | ||
else RAGStorage( | ||
if hasattr(crew, "memory_config") and crew.memory_config is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we tying together entity memory with user memory? Shouldn't they be separate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The root issue is that we are an agnostic platform and this PR directly couples CrewAI memory with mem0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for reviewing the PR!
In this case, we're using Mem0 within entity_memory
when the user opts for Mem0. So, it's not only the user memory being utilized but also the entity memory.
Let me know if we only want to use user_memory
when user opts for Mem0 and keep other memories as is.
if storage | ||
else RAGStorage( | ||
type="short_term", embedder_config=embedder_config, crew=crew | ||
if hasattr(crew, "memory_config") and crew.memory_config is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once again, why are we connecting short term with mem0? Shouldn't we only be checking user memory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here when user opts for Mem0 we use mem0 inside short_term memory as well.
So let me know if we only want to use user_memory when user opts for Mem0 and keep other memories as is.
@@ -7,8 +7,10 @@ class Storage: | |||
def save(self, value: Any, metadata: Dict[str, Any]) -> None: | |||
pass | |||
|
|||
def search(self, key: str) -> List[Dict[str, Any]]: # type: ignore | |||
pass | |||
def search( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Search is supposed to return a list of dictionaries not just a single dictionary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey here I included to have either Dict[str, Any]
or List[Any]
@@ -160,7 +162,7 @@ def search( | |||
self, | |||
query: str, | |||
limit: int = 3, | |||
filter: Optional[dict] = None, | |||
filters: Optional[dict] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like filters is being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I have removed it.
pyproject.toml
Outdated
@@ -21,6 +21,7 @@ dependencies = [ | |||
"python-dotenv>=1.0.0", | |||
"appdirs>=1.4.4", | |||
"jsonref>=1.1.0", | |||
"mem0ai>=0.1.24", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an optional dependency that users who want to use mem0 can add.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, moved to optional dependency.
storage | ||
if storage | ||
else RAGStorage( | ||
if hasattr(crew, "memory_config") and crew.memory_config is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The root issue is that we are an agnostic platform and this PR directly couples CrewAI memory with mem0.
Hey @bhancockio, latest commit resolves the issue mentioned here. |
pyproject.toml
Outdated
@@ -39,6 +39,7 @@ Repository = "https://github.com/crewAIInc/crewAI" | |||
[project.optional-dependencies] | |||
tools = ["crewai-tools>=0.13.4"] | |||
agentops = ["agentops>=0.3.0"] | |||
mem0 = ["mem0ai>=0.1.24"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dev-Khant Should this be 0.1.29 now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes bumped up the version
@Dev-Khant here are my final remarks. We are super close to getting this merged in! https://www.loom.com/share/4610bf10afc147379aec202f0aca005b?sid=f1a0773a-c66b-447c-a199-905485e8b8f3 |
Hey @bhancockio I have resolved the issue mentioned here: https://www.loom.com/share/4610bf10afc147379aec202f0aca005b?sid=f1a0773a-c66b-447c-a199-905485e8b8f3. Thanks! |
Changes
Comparison
User preferences provided through Mem0:
Full notebook: https://colab.research.google.com/drive/1nJi71bZOsFf6MPS385X-eqJVrAUXGRGJ?usp=sharing
TL;DR
Agent with UserMemory shows significant improvements in personalization:
This TL;DR highlights the key differences between the agent outputs, specifically showing how the agent with memory provides more personalized and relevant recommendations based on the user preferences you provided in the example.
Travel Planner Agent Output without Memory
Travel Planner Agent Output with Memory