Files
agent-framework/python/packages/redis
T
Eduard van Valkenburg ac0e6b0ee1 Python: PR1 — New session and context provider types (side-by-side) (#3763)
* PR1: Add core context provider types and tests

New types in _sessions.py (no changes to existing code):
- SessionContext: per-invocation state with extend_messages/get_messages/
  extend_instructions/extend_tools and read-only response property
- _ContextProviderBase: base class with before_run/after_run hooks
- _HistoryProviderBase: storage base with load/store flags, abstract
  get_messages/save_messages, default before_run/after_run
- AgentSession: lightweight session with state dict, to_dict/from_dict
- InMemoryHistoryProvider: built-in provider storing in session.state

35 unit tests covering all classes and configuration flags.

* feat: keyword-only params, stateless InMemoryHistoryProvider, deep serialization

- Make before_run/after_run parameters keyword-only
- InMemoryHistoryProvider stores ChatMessage objects directly (no per-cycle serialization)
- Deep serialization via to_dict/from_dict only at session boundary
- State type registry for automatic deserialization of registered types
- Updated tests for new serialization approach

* feat: add new-pattern provider implementations for external packages

- _RedisContextProvider(BaseContextProvider) - Redis search/vector context
- _RedisHistoryProvider(BaseHistoryProvider) - Redis-backed message storage
- _Mem0ContextProvider(BaseContextProvider) - Mem0 semantic memory
- _AzureAISearchContextProvider(BaseContextProvider) - Azure AI Search (semantic + agentic)

All use temporary _ prefix names for side-by-side coexistence with existing providers.
Will be renamed in PR2 when old ContextProvider/ChatMessageStore are removed.

* test: add tests for new-pattern provider implementations

- 32 tests for _RedisContextProvider and _RedisHistoryProvider
- 29 tests for _Mem0ContextProvider
- 17 tests for _AzureAISearchContextProvider

* fix: address PR review comments and CI failures

- Move module docstring before imports in _sessions.py (review comment)
- Import TYPE_CHECKING unconditionally in Redis _context_provider.py (NameError on Python <3.12)
- Fix Mem0 test_init_auto_creates_client_when_none to patch at class level

* feat: add source attribution to extend_messages

Set attribution marker in additional_properties for each message
added via extend_messages(), matching the tool attribution pattern.
Uses setdefault to preserve any existing attribution.

* refactor: make attribution value a dict with source_id key

* add attribution and use sets for filters

* Add source_type to message attribution and copy messages in extend_messages

- SessionContext.extend_messages now accepts source as str or object with
  source_id attribute; when an object is passed, its class name is recorded
  as source_type in the attribution dict
- Messages are shallow-copied before attribution is added so callers'
  original objects are never mutated
- Filter framework-internal keys (attribution) from A2A wire metadata
  to prevent leaking internal state over the wire

* fix: correct mypy type: ignore comment from union-attr to attr-defined

* set attribution to _attribution

* adjusted naming of bools
ac0e6b0ee1 · 2026-02-10 21:19:15 +00:00
History
..

Get Started with Microsoft Agent Framework Redis

Please install this package via pip:

pip install agent-framework-redis --pre

Components

Memory Context Provider

The RedisProvider enables persistent context & memory capabilities for your agents, allowing them to remember user preferences and conversation context across sessions and threads.

Basic Usage Examples

Review the set of getting started examples for using the Redis context provider.

Redis Chat Message Store

The RedisChatMessageStore provides persistent conversation storage using Redis Lists, enabling chat history to survive application restarts and support distributed applications.

Key Features

  • Persistent Storage: Messages survive application restarts
  • Thread Isolation: Each conversation thread has its own Redis key
  • Message Limits: Configurable automatic trimming of old messages
  • Serialization Support: Full compatibility with Agent Framework thread serialization
  • Production Ready: Connection pooling, error handling, and performance optimized

Basic Usage Examples

See the complete Redis chat message store examples including:

  • User session management
  • Conversation persistence across restarts
  • Thread serialization and deserialization
  • Automatic message trimming
  • Error handling patterns

Installing and running Redis

You have 3 options to set-up Redis:

Option A: Local Redis with Docker

docker run --name redis -p 6379:6379 -d redis:8.0.3

Option B: Redis Cloud

Get a free db at https://redis.io/cloud/

Option C: Azure Managed Redis

Here's a quickstart guide to create Azure Managed Redis for as low as $12 monthly: https://learn.microsoft.com/en-us/azure/redis/quickstart-create-managed-redis