-
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?
Changes from 36 commits
2607ac3
67991a3
602497a
c7d326a
1f66c6d
7371a45
66a1ecc
3517d53
6e13c0b
bb90718
5d6eb6e
9a756bb
1dd20f9
3ab6084
50758c9
3fff7c4
45e307e
6316936
b810697
57fcae8
bb17567
c55ccac
9a4952d
9d0459d
cda4c07
9044c5a
6be3061
7f4917e
5929d35
47b34ec
e9c2bc8
8d3145b
ee7d530
d2746e1
c63f56e
34cc0d9
ea54fb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from .entity.entity_memory import EntityMemory | ||
from .long_term.long_term_memory import LongTermMemory | ||
from .short_term.short_term_memory import ShortTermMemory | ||
from .user.user_memory import UserMemory | ||
|
||
__all__ = ["EntityMemory", "LongTermMemory", "ShortTermMemory"] | ||
__all__ = ["UserMemory", "EntityMemory", "LongTermMemory", "ShortTermMemory"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,27 @@ class ShortTermMemory(Memory): | |
""" | ||
|
||
def __init__(self, crew=None, embedder_config=None, storage=None): | ||
storage = ( | ||
storage | ||
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 commentThe 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 commentThe 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. |
||
self.memory_provider = crew.memory_config.get("provider") | ||
else: | ||
self.memory_provider = None | ||
|
||
if self.memory_provider == "mem0": | ||
try: | ||
from crewai.memory.storage.mem0_storage import Mem0Storage | ||
except ImportError: | ||
raise ImportError( | ||
"Mem0 is not installed. Please install it with `pip install mem0ai`." | ||
) | ||
storage = Mem0Storage(type="short_term", crew=crew) | ||
else: | ||
storage = ( | ||
storage | ||
if storage | ||
else RAGStorage( | ||
type="short_term", embedder_config=embedder_config, crew=crew | ||
) | ||
) | ||
) | ||
super().__init__(storage) | ||
|
||
def save( | ||
|
@@ -30,11 +44,20 @@ def save( | |
agent: Optional[str] = None, | ||
) -> None: | ||
item = ShortTermMemoryItem(data=value, metadata=metadata, agent=agent) | ||
if self.memory_provider == "mem0": | ||
item.data = f"Remember the following insights from Agent run: {item.data}" | ||
|
||
super().save(value=item.data, metadata=item.metadata, agent=item.agent) | ||
|
||
def search(self, query: str, score_threshold: float = 0.35): | ||
return self.storage.search(query=query, score_threshold=score_threshold) # type: ignore # BUG? The reference is to the parent class, but the parent class does not have this parameters | ||
def search( | ||
self, | ||
query: str, | ||
limit: int = 3, | ||
score_threshold: float = 0.35, | ||
): | ||
return self.storage.search( | ||
query=query, limit=limit, score_threshold=score_threshold | ||
) # type: ignore # BUG? The reference is to the parent class, but the parent class does not have this parameters | ||
|
||
def reset(self) -> None: | ||
try: | ||
|
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.