Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

parshvadaftari
Copy link

This integration introduces memory layer for the AI agents, leveraging mem0 as primary memory provider.

@DouweM
Copy link
Collaborator

DouweM commented Oct 10, 2025

@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 Mem0Toolset?

@nurikk
Copy link
Contributor

nurikk commented Oct 10, 2025

Here's mine implementation for reference.

https://gist.github.com/nurikk/71f80d8fa375c2a038c6e8e81ab8b6a9

@parshvadaftari
Copy link
Author

Hey @DouweM Thanks for pointing it out and thank you @nurikk for the response. Will definitely revamp this version and make requested changes.

@parshvadaftari
Copy link
Author

Hey @DouweM Have implemented the changes and made sure the tests passed. pydantic-ai-slim is failing due to network timeout error. Would love to have feedback for this integration. Thanks!

allowing agents to save and search through conversation memories.
"""

# pyright: reportUnknownMemberType=false, reportUnknownArgumentType=false, reportUnknownVariableType=false
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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__')
Copy link
Collaborator

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]
Copy link
Collaborator

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:
Copy link
Collaborator

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
Copy link
Collaborator

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', '')
Copy link
Collaborator

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:']
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.