Skip to content

fix(memory): add mem0ai 2.0 API compatibility for Mem0LongTermMemory#1520

Open
octo-patch wants to merge 1 commit intoagentscope-ai:mainfrom
octo-patch:fix/issue-1511-mem0-v2-api-compatibility
Open

fix(memory): add mem0ai 2.0 API compatibility for Mem0LongTermMemory#1520
octo-patch wants to merge 1 commit intoagentscope-ai:mainfrom
octo-patch:fix/issue-1511-mem0-v2-api-compatibility

Conversation

@octo-patch
Copy link
Copy Markdown
Contributor

Fixes #1511

Problem

mem0ai 2.0 introduced a breaking change to both search() and add(): entity identifiers (user_id, agent_id, run_id) are no longer accepted as top-level parameters. They must now be passed inside a filters dict:

Version Call Style
v1.x client.search(query, user_id="alice")
v2.0 client.search(query, filters={"user_id": "alice"})

This caused Mem0LongTermMemory to raise:

Error retrieving memory: Top-level entity parameters frozenset({'user_id', 'run_id', 'agent_id'}) are not supported in search(). Use filters={'user_id': '...'} instead.

Solution

  • Add _detect_mem0_v2() static method to detect the installed mem0ai version.
  • Add _build_entity_filters() instance method that returns the correct kwargs format:
    • mem0ai >= 2.0.0: {"filters": {"user_id": ..., ...}} (with AND for multiple identifiers)
    • mem0ai < 2.0.0: {"user_id": ..., "agent_id": ..., "run_id": ...}
  • Update all three call sites (retrieve(), retrieve_from_memory(), _mem0_record()) to use _build_entity_filters().

This preserves full backward compatibility with older mem0ai versions.

Testing

Verified the logic manually against the mem0ai 2.0 documentation. The version check uses the existing packaging dependency already imported in this module.

agentscope-ai#1511)

mem0ai 2.0 removed support for top-level entity parameters (user_id, agent_id, run_id) in search() and add(). They must now be passed inside a filters dict.

Add _detect_mem0_v2() to check the installed version and _build_entity_filters() to return the correct kwargs format for the installed version, preserving backward compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Mem0 2.0 API breaking change causes Mem0LongTermMemory to fail in AgentScope

1 participant