fix(memory): add mem0ai 2.0 API compatibility for Mem0LongTermMemory#1520
Open
octo-patch wants to merge 1 commit intoagentscope-ai:mainfrom
Open
fix(memory): add mem0ai 2.0 API compatibility for Mem0LongTermMemory#1520octo-patch wants to merge 1 commit intoagentscope-ai:mainfrom
octo-patch wants to merge 1 commit intoagentscope-ai:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1511
Problem
mem0ai 2.0 introduced a breaking change to both
search()andadd(): entity identifiers (user_id,agent_id,run_id) are no longer accepted as top-level parameters. They must now be passed inside afiltersdict:client.search(query, user_id="alice")client.search(query, filters={"user_id": "alice"})This caused
Mem0LongTermMemoryto raise:Solution
_detect_mem0_v2()static method to detect the installed mem0ai version._build_entity_filters()instance method that returns the correct kwargs format:{"filters": {"user_id": ..., ...}}(withANDfor multiple identifiers){"user_id": ..., "agent_id": ..., "run_id": ...}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
packagingdependency already imported in this module.