Python: Remove unsupported memory scoping params from mem0/redis samples and docs#4367
Conversation
Fixes microsoft#4353 The `Mem0ContextProvider` and `RedisContextProvider` no longer support `thread_id` or `scope_to_per_operation_thread_id` parameters. This commit updates the affected samples and READMEs to use only the currently supported API (`user_id`, `agent_id`, `application_id`). Changes: - mem0_sessions.py: Remove `thread_id` and `scope_to_per_operation_thread_id` from examples 1 and 2, rewrite to demonstrate user-scoped and agent-scoped memory patterns - redis_sessions.py: Update module docstring to remove references to removed thread scoping params - mem0/README.md: Update Memory Scoping docs to reflect current API - redis/README.md: Remove `thread_id` and `scope_to_per_operation_thread_id` references from docs
There was a problem hiding this comment.
Pull request overview
Updates Python mem0/redis context-provider samples and READMEs to remove the no-longer-supported thread_id / scope_to_per_operation_thread_id scoping parameters, aligning examples with the current provider APIs (user_id, agent_id, application_id) and fixing a runtime TypeError in the mem0 sessions sample.
Changes:
- Removed unsupported thread-scoping parameters from
mem0_sessions.pyand rewrote examples to demonstrate user/agent scoping. - Updated
redis_sessions.pydocstrings and both provider READMEs to remove references to thread scoping and document only supported scoping identifiers. - Cleaned up minor sample/docs inconsistencies (e.g., corrected run command, removed unused import).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/samples/02-agents/context_providers/redis/redis_sessions.py | Updates sample narrative/docstrings from thread scoping to memory scoping and refreshes example descriptions. |
| python/samples/02-agents/context_providers/redis/README.md | Removes thread-scoping docs and documents supported scope identifiers for Redis provider usage. |
| python/samples/02-agents/context_providers/mem0/mem0_sessions.py | Removes unsupported args causing runtime errors and updates examples to demonstrate supported scoping. |
| python/samples/02-agents/context_providers/mem0/README.md | Replaces outdated scoping documentation with the supported identifier-based scoping model. |
| async def example_global_thread_scope() -> None: | ||
| """Example 1: Global thread_id scope (memories shared across all operations).""" | ||
| print("1. Global Thread Scope Example:") | ||
| """Example 1: Global memory scope (memories shared across all operations).""" | ||
| print("1. Global Memory Scope Example:") | ||
| print("-" * 40) |
There was a problem hiding this comment.
The sample has been renamed to “memory scoping”, but the function names and calls still use the older “*_thread_scope” terminology (e.g., example_global_thread_scope). Renaming these functions to match the updated concepts would reduce confusion for readers and keep the sample consistent.
| """Example 2: Agent-scoped memory with custom vectorizer. | ||
|
|
||
| Note: When scope_to_per_operation_thread_id=True, the provider is bound to a single session | ||
| throughout its lifetime. Use the same session object for all operations with that provider. | ||
| Demonstrates using a custom OpenAI vectorizer for hybrid vector search. | ||
| Memories are scoped by user_id and agent_id. | ||
| """ |
There was a problem hiding this comment.
The updated docstring says memories are scoped by user_id and agent_id, but this example also sets application_id on RedisContextProvider, so the effective scope includes that as well. Please update the docstring to reflect all scope identifiers used here (or remove application_id from the provider config if it's not meant to be part of the example).
- Rename `example_global_thread_scope` -> `example_global_memory_scope` - Rename `example_per_operation_thread_scope` -> `example_agent_scoped_memory` - Update example 2 docstring to mention `application_id` alongside `user_id` and `agent_id` since it's set in the provider config - Update module docstring scenario 2 to include `application_id`
Motivation and Context
Fixes #4353
The
Mem0ContextProviderandRedisContextProviderno longer supportthread_idorscope_to_per_operation_thread_idparameters. However, themem0_sessions.pysample still passes these arguments toMem0ContextProvider.__init__(), causing aTypeErrorat runtime:The
redis_sessions.pysample code is functionally correct but its module docstring and the Redis README still document the removed thread scoping features.Description
Updates 2 sample files and 2 READMEs to use only the currently supported memory scoping API (
user_id,agent_id,application_id):mem0_sessions.py:thread_idandscope_to_per_operation_thread_id=False; rewritten to demonstrate user-scoped memory persistence across sessionsscope_to_per_operation_thread_id=True; rewritten to demonstrate agent-scoped memory isolation usingagent_idimport uuidredis_sessions.py:scope_to_per_operation_thread_idandthread_idmem0/README.md:mem0_sessions.pydescription to reflect new examplesscope_to_per_operation_thread_idandthread_idreferences, now documents the three supported scoping identifiers (user_id,agent_id,application_id)redis/README.md:redis_sessions.pydescription to removethread_idandscope_to_per_operation_thread_idreferencesthread_idfrom "Provider configuration highlights" partition fieldsscope_to_per_operation_thread_idthread_idfrom the required scope listContribution Checklist