Skip to content

Python: mem0 basic example not working #2621

@amit12cool

Description

@amit12cool

On running the python basic example with mem0 hosted instance I get a 400 http request error.

REQUEST: POST https://api.mem0.ai/v2/memories/search/
HEADERS: {'host': 'api.mem0.ai', 'accept': '*/*', 'accept-encoding': 'gzip, deflate', 'connection': 'keep-alive', 'user-agent': 'python-httpx/0.28.1', 'authorization': 'Token m0-[REDACTED]', 'mem0-user-id': 'af[REDACTED]', 'content-length': '211', 'content-type': 'application/json'}
BODY: {"query":"Please retrieve my company report","user_id":"0dc6[REDACTED]","org_id":"org_[REDACTED]","project_id":"proj_[REDACTED]"}
================================================================================


================================================================================
RESPONSE: 400 Bad Request
HEADERS: {'date': 'Thu, 04 Dec 2025 06:52:38 GMT', 'content-type': 'application/json', 'content-length': '127', 'connection': 'keep-alive', 'server': 'uvicorn', 'vary': 'Accept, origin, Authorization, Cookie', 'allow': 'OPTIONS, POST', 'x-frame-options': 'DENY', 'x-content-type-options': 'nosniff', 'referrer-policy': 'same-origin', 'cross-origin-opener-policy': 'same-origin'}
BODY: {"error":"Filters are required and cannot be empty. Please refer to https://docs.mem0.ai/api-reference/memory/search-memories"}
================================================================================

Traceback (most recent call last):
  File "/home/Barco/agent-framework/python/samples/getting_started/context_providers/mem0/mem0_basic.py", line 116, in <module>
    asyncio.run(main())
  File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/Barco/agent-framework/python/samples/getting_started/context_providers/mem0/mem0_basic.py", line 91, in main
    result = await agent.run(query)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/Barco/agent-framework/python/.venv/lib/python3.11/site-packages/agent_framework/_middleware.py", line 1249, in middleware_enabled_run
    return await original_run(self, normalized_messages, thread=thread, **kwargs)  # type: ignore[return-value]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/Barco/agent-framework/python/.venv/lib/python3.11/site-packages/agent_framework/observability.py", line 1106, in trace_run
    return await run_func(self, messages=messages, thread=thread, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/Barco/agent-framework/python/.venv/lib/python3.11/site-packages/agent_framework/_agents.py", line 832, in run
    thread, run_chat_options, thread_messages = await self._prepare_thread_and_messages(
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/Barco/agent-framework/python/.venv/lib/python3.11/site-packages/agent_framework/_agents.py", line 1258, in _prepare_thread_and_messages
    context = await self.context_provider.invoking(input_messages or [])
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/Barco/agent-framework/python/.venv/lib/python3.11/site-packages/agent_framework/_memory.py", line 247, in invoking
    contexts = await asyncio.gather(*[provider.invoking(messages, **kwargs) for provider in self.providers])
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/Barco/agent-framework/python/.venv/lib/python3.11/site-packages/agent_framework_mem0/_provider.py", line 149, in invoking
    search_response: MemorySearchResponse_v1_1 | MemorySearchResponse_v2 = await self.mem0_client.search(  # type: ignore[misc]
                                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/Barco/agent-framework/python/.venv/lib/python3.11/site-packages/mem0/client/main.py", line 1158, in search
    response.raise_for_status()
  File "/home/Barco/agent-framework/python/.venv/lib/python3.11/site-packages/httpx/_models.py", line 829, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '400 Bad Request' for url 'https://api.mem0.ai/v2/memories/search/'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400

it looks like the mem0 v2 api is expecting filters param in the search argument as listed here https://docs.mem0.ai/api-reference/memory/search-memories

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpython

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions