Skip to content

Python: Remove unsupported memory scoping params from mem0/redis samples and docs#4367

Open
LEDazzio01 wants to merge 2 commits intomicrosoft:mainfrom
LEDazzio01:fix/4353-remove-unsupported-memory-scoping-params
Open

Python: Remove unsupported memory scoping params from mem0/redis samples and docs#4367
LEDazzio01 wants to merge 2 commits intomicrosoft:mainfrom
LEDazzio01:fix/4353-remove-unsupported-memory-scoping-params

Conversation

@LEDazzio01
Copy link
Contributor

Motivation and Context

Fixes #4353

The Mem0ContextProvider and RedisContextProvider no longer support thread_id or scope_to_per_operation_thread_id parameters. However, the mem0_sessions.py sample still passes these arguments to Mem0ContextProvider.__init__(), causing a TypeError at runtime:

TypeError: Mem0ContextProvider.__init__() got an unexpected keyword argument 'thread_id'

The redis_sessions.py sample 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:

  • Example 1: Removed thread_id and scope_to_per_operation_thread_id=False; rewritten to demonstrate user-scoped memory persistence across sessions
  • Example 2: Removed scope_to_per_operation_thread_id=True; rewritten to demonstrate agent-scoped memory isolation using agent_id
  • Example 3: Unchanged (already uses the correct API)
  • Removed unused import uuid

redis_sessions.py:

  • Updated module docstring to remove references to scope_to_per_operation_thread_id and thread_id
  • Updated example 2 docstring to describe agent-scoped memory with custom vectorizer

mem0/README.md:

  • Updated mem0_sessions.py description to reflect new examples
  • Replaced "Memory Scoping" section — removed scope_to_per_operation_thread_id and thread_id references, now documents the three supported scoping identifiers (user_id, agent_id, application_id)

redis/README.md:

  • Updated redis_sessions.py description to remove thread_id and scope_to_per_operation_thread_id references
  • Removed thread_id from "Provider configuration highlights" partition fields
  • Removed "Thread scoping" bullet
  • Updated "Memory scoping" key concepts to remove scope_to_per_operation_thread_id
  • Updated troubleshooting to remove thread_id from the required scope list

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

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
Copilot AI review requested due to automatic review settings March 1, 2026 01:25
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python labels Mar 1, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py and rewrote examples to demonstrate user/agent scoping.
  • Updated redis_sessions.py docstrings 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.

Comment on lines 58 to 61
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)
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +102 to 106
"""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.
"""
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
- 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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Memory scoping not longer supported

3 participants