Python: support mem0ai 2.x#7004
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
44fd614 to
987f2b5
Compare
There was a problem hiding this comment.
Pull request overview
Updates the Python Mem0 integration to be compatible with mem0ai 2.x by aligning the OSS AsyncMemory search call shape with the new API expectations, and clarifying/strengthening scoping behavior differences between OSS vs Platform clients.
Changes:
- Bump
agent-framework-mem0dependency tomem0ai>=2.0.0,<3and refreshuv.lock. - Update
Mem0ContextProviderto pass entity scoping viafiltersforsearch()(mem0ai 2.x), and treatapplication_idas Platform-only for OSS (AsyncMemory). - Add/adjust unit tests for OSS vs Platform search and storage scoping; add workspace NumPy constraint (
numpy<2.5) to keep mypy (py3.10 profile) passing.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| python/uv.lock | Updates resolved deps for mem0ai 2.x and applies the workspace numpy<2.5 constraint. |
| python/pyproject.toml | Adds workspace resolver constraint for numpy<2.5 to keep type checking compatible with the repo’s mypy Python version. |
| python/packages/mem0/pyproject.toml | Bumps agent-framework-mem0 dependency to mem0ai>=2.0.0,<3. |
| python/packages/mem0/agent_framework_mem0/_context_provider.py | Adapts Mem0 search scoping to filters (2.x) and enforces Platform-only application_id behavior for OSS clients. |
| python/packages/mem0/tests/test_mem0_context_provider.py | Adds/updates tests validating OSS vs Platform filter shapes and application_id handling for search/storage. |
|
Flagged issue OSS configurations that include both Source: automated DevFlow PR review |
There was a problem hiding this comment.
Automated Code Review
Reviewers: 5 | Confidence: 92%
✓ Correctness
The PR correctly adapts the Mem0ContextProvider to mem0ai 2.x by unifying search calls to use a
filtersdict (required by the new SDK), properly excluding Platform-onlyapp_idfrom OSS client paths, and adding validation to reject OSS-only configurations withapplication_id. The logic is internally consistent, well-tested, and I found no correctness issues.
✓ Security Reliability
The PR cleanly migrates from mem0ai 1.x to 2.x by routing OS search entity IDs through a
filtersdict and treatingapplication_idas Platform-only. Validation correctly rejects unsupported OS-only configurations early. Error handling withasyncio.gather(return_exceptions=True)and re-raising ofCancelledErroris appropriate. No injection risks, resource leaks, secrets exposure, or unhandled failure modes were identified.
✓ Test Coverage
The PR has strong test coverage for all behavioral changes. New tests cover OSS filter format changes (filters dict vs direct kwargs), OSS rejection of application_id-only configuration, Platform client app_id propagation, and OSS storage omission of app_id. Unit tests for _build_search_kwargs and _validate_filters complement the integration-level before_run/after_run tests. Assertions are meaningful (checking exact dict shapes, not just no-exception), and mocks appropriately distinguish OS (AsyncMemory) from Platform (AsyncMemoryClient) clients.
✓ Failure Modes
The PR cleanly handles the mem0ai 2.x migration with proper guard rails. The _validate_filters() method correctly prevents OSS clients from reaching Platform-only code paths (app-only fallback), and the unified filters dict approach is well-tested. No silent failures, swallowed exceptions, or operational failure modes are introduced by this change.
✗ Design Approach
The PR mostly aligns the mem0 2.x search call shape, but it also codifies a design that silently drops
application_idwhenever an OSSAsyncMemoryclient is used alongsideuser_idoragent_id. That means OSS callers who supply both scopes will have reads and writes collapsed onto only the user/agent partition, so memories can leak across applications that share the same user or agent identifiers.
Flagged Issues
- OSS configurations that include both
application_idanduser_id/agent_idare silently merged across applications:_build_search_kwargs()dropsapp_idfor OSS (_context_provider.py:246-248) andafter_run()also omits it on writes (_context_provider.py:225-226). For inputs like(user_id='u1', application_id='appA')vs(user_id='u1', application_id='appB'), both providers hit the same OSS partition. If OS cannot support app scope, this combination should be rejected rather than silently ignored.
Automated review by eavanvalkenburg's agents
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Addressed the automated review concern in 2faa2fc: OSS AsyncMemory now rejects any configuration that includes application_id, including user_id/application_id or agent_id/application_id combinations, instead of silently dropping app scope. I also restored uv.lock to the upstream main baseline and kept only the mem0ai entry/specifier changes so the broad lock rewrite that caused CI sample typing failures is no longer in the PR diff. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Motivation & Context
Mem0ContextProvider needs to support mem0ai 2.x, where OSS search no longer accepts entity IDs as top-level keyword arguments. Without this update, OSS retrieval uses the old 1.x call shape and fails against the newer SDK.
This also replaces the earlier implementation in #6129 with the same compatibility goal plus passing package checks on the current branch.
Description & Review Guide
agent-framework-mem0tomem0ai>=2.0.0,<3and refreshes the lockfile.filtersfor mem0ai 2.x.application_idas Platform-only for OSSAsyncMemory, including rejecting OSS application-only configuration and omitting app scope from OSS storage.typestatements while the repo mypy test profile targets Python 3.10.application_idis the right compatibility behavior for mem0ai 2.x.Related Issue
Supersedes #6129. No linked issue.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.