Skip to content

Python: Mem0Provider.invoking() incompatible with Mem0 OSS AsyncMemory.search() #3833

@pamelafox

Description

@pamelafox

Bug Report

Description

Mem0Provider.invoking() passes user_id, agent_id, and run_id inside a filters dict to mem0_client.search():

filters = self._build_filters()
search_response = await self.mem0_client.search(
    query=input_text,
    filters=filters,
)

This works with the Mem0 Platform client (AsyncMemoryClient), but fails with the Mem0 OSS client (AsyncMemory), which expects user_id, agent_id, and run_id as direct keyword arguments:

# Mem0 OSS AsyncMemory.search() signature (mem0ai v1.0.3):
async def search(self, query, *, user_id=None, agent_id=None, run_id=None, ...)

Error

mem0.exceptions.ValidationError: At least one of 'user_id', 'agent_id', or 'run_id' must be provided.

Steps to Reproduce

  1. Create a Mem0Provider with mem0_client=AsyncMemory() (OSS) and user_id="some_user"
  2. Attach it to a ChatAgent via context_provider=
  3. Call agent.run("any message")
  4. The invoking() hook calls search(query=..., filters={"user_id": "some_user"}) which fails

Expected Behavior

Mem0Provider should work with both AsyncMemoryClient (Platform) and AsyncMemory (OSS). The search call should detect the client type and pass scoping parameters appropriately.

Suggested Fix

In _provider.py, invoking() should unpack the filters as keyword args when using AsyncMemory (OSS):

search_kwargs = {"query": input_text}
if isinstance(self.mem0_client, AsyncMemory):
    # OSS client expects user_id/agent_id/run_id as direct kwargs
    search_kwargs.update(filters)
else:
    # Platform client uses filters dict
    search_kwargs["filters"] = filters

search_response = await self.mem0_client.search(**search_kwargs)

Additional Context

Note that invoked() (the add call) already passes user_id as a direct keyword argument and works correctly with both clients. Only the search call in invoking() has this inconsistency.

Environment

  • agent-framework-mem0 at commit 98cd72839e
  • mem0ai==1.0.3
  • Python 3.12

Metadata

Metadata

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions