Python: Separate mem0 storage and search scopes - #7531
Open
westey-m wants to merge 3 commits into
Open
Conversation
westey-m
temporarily deployed
to
github-app-auth
August 5, 2026 17:47 — with
GitHub Actions
Inactive
westey-m
temporarily deployed
to
github-app-auth
August 5, 2026 17:47 — with
GitHub Actions
Inactive
westey-m
temporarily deployed
to
github-app-auth
August 5, 2026 17:47 — with
GitHub Actions
Inactive
Contributor
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Python Mem0 context provider to explicitly separate storage scoping (how memories are stamped when written) from retrieval scoping (which memories are searched and injected), preventing accidental cross-user memory retrieval when an agent_id is shared across users.
Changes:
- Add explicit retrieval-scope parameters (
search_user_id,search_agent_id,search_application_id) and make retrieval opt-in (warn + retrieve nothing if nosearch_*configured). - Update samples and package documentation to demonstrate explicit retrieval scoping.
- Expand unit tests to cover non-inheritance of retrieval scope and cross-user isolation behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| python/samples/02-agents/context_providers/mem0/README.md | Documents the storage vs retrieval scoping model for the Mem0 sample. |
| python/samples/02-agents/context_providers/mem0/mem0_sessions.py | Updates sample sessions to set explicit retrieval scope via search_*. |
| python/samples/02-agents/context_providers/mem0/mem0_oss.py | Updates OSS sample provider construction to use explicit retrieval scope. |
| python/samples/02-agents/context_providers/mem0/mem0_basic.py | Updates basic sample to set search_user_id explicitly. |
| python/packages/mem0/tests/test_mem0_context_provider.py | Adds/updates tests to ensure retrieval scope is explicit and prevent cross-user leakage. |
| python/packages/mem0/README.md | Adds user-facing docs describing separate storage vs retrieval scope. |
| python/packages/mem0/AGENTS.md | Updates package guidance to include explicit retrieval scoping and behavior. |
| python/packages/mem0/agent_framework_mem0/_context_provider.py | Implements separate retrieval scope, warning-on-missing-retrieval, and new search_* parameters. |
Suppressed comments (1)
python/packages/mem0/agent_framework_mem0/_context_provider.py:285
- The OSS-client validation error message is now triggered by either application_id or search_application_id, but the message still only mentions application_id. This makes the exception misleading when a caller sets search_application_id.
if isinstance(self.mem0_client, AsyncMemory) and (self.application_id or self.search_application_id):
raise ValueError(
"application_id is not supported by the OSS AsyncMemory client, which scopes "
"memories only by user_id/agent_id. Remove application_id or use AsyncMemoryClient."
)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
westey-m
temporarily deployed
to
github-app-auth
August 5, 2026 18:00 — with
GitHub Actions
Inactive
westey-m
temporarily deployed
to
github-app-auth
August 5, 2026 18:01 — with
GitHub Actions
Inactive
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.
Motivation & Context
E.g. Allow users to stamp memories with both the agent and user id, but only retrieve for a user
Description & Review Guide
Related Issue
Fixes #
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.