Skip to content

Mem0 provider read filter misses agent-attributed memories #38424

@GodsBoy

Description

@GodsBoy

Bug Description

The Mem0 memory provider writes memories with both user_id and agent_id, but reads them back with only user_id.

That leaves mem0_profile, mem0_search, and prefetch with partial recall on Mem0 Platform. Older un-attributed memories are visible, while memories saved with agent attribution are skipped.

Related but not a duplicate: #25084 covers gateway namespace fragmentation. This report is about the read filter missing agent-attributed rows inside the same user namespace.

Steps to Reproduce

  1. Configure the Mem0 provider.
  2. Use Hermes through a gateway session so initialize(..., user_id=...) receives the platform user id.
  3. Let Hermes save memories through sync_turn() or mem0_conclude().
  4. Call mem0_profile or mem0_search.
  5. Compare the current read filter with an OR filter that includes the same user plus the active agent id.

Current read filter:

{"user_id": self._user_id}

Write filter:

{"user_id": self._user_id, "agent_id": self._agent_id}

Expected Behavior

Reads should include both:

  • older user-only memories
  • memories saved by the same user with agent attribution

Actual Behavior

Reads only return user-only memories. Agent-attributed memories are not included.

In a live Mem0 Platform account, the difference is visible with paginated get_all() calls for the same user:

{"user_id": "503782402"}
count: 153
agent_ids: {None: 153}

{"OR": [{"user_id": "503782402"}, {"user_id": "503782402", "agent_id": "hermie"}]}
count: 3379
agent_ids: {"hermie": 2520, "gideon": 447, "hermes": 259, None: 153}

Environment

  • Hermes Agent: current main
  • Mem0 SDK package: mem0ai 2.0.4
  • Memory provider: mem0
  • Platform: Telegram gateway session

Proposed Fix

Change the Mem0 provider read filter to include the existing plain user scope and the active agent-attributed scope:

{
    "OR": [
        {"user_id": self._user_id},
        {"user_id": self._user_id, "agent_id": self._agent_id},
    ]
}

This keeps compatibility with un-attributed memories and restores recall for memories saved with agent attribution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havecomp/pluginsPlugin system and bundled pluginstool/memoryMemory tool and memory providerstype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions