-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add mem0 as a memory provider #3129
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
base: main
Are you sure you want to change the base?
Add mem0 as a memory provider #3129
Conversation
@parshvadaftari Thanks for working on this. Did you see #2932 though? I was expecting a much more lightweight architecture built on top of toolsets, rather than requiring a completely new module and abstract classes. Can you see if you could reimagine this as |
Here's mine implementation for reference. https://gist.github.com/nurikk/71f80d8fa375c2a038c6e8e81ab8b6a9 |
Hey @DouweM Have implemented the changes and made sure the tests passed. |
allowing agents to save and search through conversation memories. | ||
""" | ||
|
||
# pyright: reportUnknownMemberType=false, reportUnknownArgumentType=false, reportUnknownVariableType=false |
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.
Please remove this, we have these rules for a reason!
from .function import FunctionToolset | ||
|
||
if TYPE_CHECKING: | ||
from mem0 import AsyncMemoryClient, MemoryClient |
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 don't think we need it if we already have it below
AsyncMemoryClient = None # pragma: no cover | ||
MemoryClient = None # pragma: no cover | ||
else: | ||
_import_error = 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.
We can show the user new "please install..." error right away
|
||
This toolset adds two tools to your agent: | ||
- `save_memory`: Save information to memory for later retrieval | ||
- `search_memory`: Search through stored memories |
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.
Those docs have weird names like _search_memory_impl
if client is not None: | ||
self.client = client | ||
# Check if client is async by looking for async methods | ||
self._is_async = hasattr(client, 'search') and hasattr(getattr(client, 'search'), '__call__') |
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.
Is this the best way to do this? Could we not check isinstance
?
self._is_async = inspect.iscoroutinefunction(client.search) | ||
else: | ||
# Create async client by default for better performance | ||
self.client = AsyncMemoryClient( # type: ignore[misc] |
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.
What error are we ignoring here?
|
||
return '\n'.join(memory_lines) | ||
|
||
except Exception as e: |
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.
Can we be more specific in the errors we mask?
else: | ||
response = self.client.search(query=query, user_id=user_id, limit=self._limit) | ||
|
||
# Parse response - handle both dict format and raw list |
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? Examples like https://docs.mem0.ai/integrations/google-ai-adk treat it as a list
memory_lines = ['Found relevant memories:'] | ||
for mem in results: | ||
if isinstance(mem, dict): | ||
memory_text = mem.get('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.
If the memory object is invalid, we should just skip it right
return 'No relevant memories found.' | ||
|
||
# Format memories for the agent | ||
memory_lines = ['Found relevant memories:'] |
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 need this prefix? The examples in their docs don't use it
This integration introduces memory layer for the AI agents, leveraging mem0 as primary memory provider.