Skip to content

.NET: Adds Valkey to chat message history - issue 5445#5542

Open
MatthiasHowellYopp wants to merge 2 commits into
microsoft:mainfrom
MatthiasHowellYopp:issue-5445
Open

.NET: Adds Valkey to chat message history - issue 5445#5542
MatthiasHowellYopp wants to merge 2 commits into
microsoft:mainfrom
MatthiasHowellYopp:issue-5445

Conversation

@MatthiasHowellYopp
Copy link
Copy Markdown

Motivation and Context
The .NET Agent Framework currently has no dedicated Valkey integration package. Teams running Valkey in production — whether self-hosted or through managed cloud services like AWS ElastiCache for Valkey or GCP Memorystore for Valkey — have no first-party way to use Valkey for persistent chat history or long-term memory context. This has become increasingly common since the Redis license change.

The Microsoft.Agents.AI.Valkey package was scaffolded with working ValkeyChatHistoryProvider and ValkeyContextProvider implementations. This PR completes the package by adding missing pieces identified during review, fixing bugs in the existing sample, and adding a Bedrock-powered sample for AWS users.

Fixes issue #5445

Description
###Valkey package improvements:

  • Added ValkeyProviderScope copy constructor matching the Mem0ProviderScope pattern, with null-guard via Throw.IfNull
  • Added XML doc tags to all ValkeyProviderScope properties for consistency with Mem0ProviderScope
  • Kept the package dependency lean — only references Microsoft.Agents.AI.Abstractions (no dependency on Microsoft.Agents.AI)

###Bug fix in existing sample:

  • Fixed Program.cs — the stateInitializer referenced session?.Id which doesn't exist on AgentSession. Replaced with Guid.NewGuid():N using a discard parameter to make intent clear

###New Bedrock sample (AgentWithMemory_Step03_MemoryUsingValkey_Bedrock):

  • Demonstrates both ValkeyChatHistoryProvider and ValkeyContextProvider powered by Amazon Bedrock via AWSSDK.Extensions.Bedrock.MEAI
  • Uses IAmazonBedrockRuntime.AsIChatClient() which provides an IChatClient that plugs directly into the Agent Framework's ChatClientAgent
  • Uses the standard AWS credential chain (env vars, profile, IAM role)
  • Includes README with prerequisites, environment variables, and run instructions

###Infrastructure:

  • Added AWSSDK.Extensions.Bedrock.MEAI v4.0.6.10 to Directory.Packages.props
  • Registered the Bedrock sample in agent-framework-dotnet.slnx

Unit tests:

Added tests for ValkeyProviderScope copy constructor (clone all properties, null source throws)
23 tests total, all passing

Contribution Checklist
[x] The code builds clean without any errors or warnings
[x] The PR follows the Contribution Guidelines
[x] 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.

@moonbox3 moonbox3 added documentation Improvements or additions to documentation .NET labels Apr 28, 2026
@github-actions github-actions Bot changed the title Adds Valkey to chat message history - issue 5445 .NET: Adds Valkey to chat message history - issue 5445 Apr 28, 2026
Copilot AI review requested due to automatic review settings April 29, 2026 18:05
Copy link
Copy Markdown
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

Note

Copilot was unable to run its full agentic suite in this review.

Completes the new .NET Valkey integration by adding Valkey-backed chat history/context providers, unit tests, and two samples (Azure OpenAI + Amazon Bedrock), plus wiring the new projects into the solution and central package versions.

Changes:

  • Added Microsoft.Agents.AI.Valkey package implementation: ValkeyChatHistoryProvider, ValkeyContextProvider, and ValkeyProviderScope.
  • Added a new Valkey unit test project with coverage for provider behavior and scope cloning.
  • Added new AgentWithMemory step 03 samples (Azure OpenAI + Bedrock), plus solution and package version updates.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
dotnet/tests/Microsoft.Agents.AI.Valkey.UnitTests/ValkeyContextProviderTests.cs Adds unit tests for ValkeyContextProvider behaviors (escaping, parsing, disposal, scope/state).
dotnet/tests/Microsoft.Agents.AI.Valkey.UnitTests/ValkeyChatHistoryProviderTests.cs Adds unit tests for ValkeyChatHistoryProvider behaviors (store/retrieve/trim/dispose).
dotnet/tests/Microsoft.Agents.AI.Valkey.UnitTests/TestHelpers.cs Adds shared test helpers for constructing provider invoke contexts and a test AgentSession.
dotnet/tests/Microsoft.Agents.AI.Valkey.UnitTests/Microsoft.Agents.AI.Valkey.UnitTests.csproj Introduces the Valkey unit test project.
dotnet/src/Microsoft.Agents.AI.Valkey/ValkeyProviderScope.cs Adds ValkeyProviderScope including copy constructor and XML docs.
dotnet/src/Microsoft.Agents.AI.Valkey/ValkeyContextProvider.cs Introduces Valkey full-text-search-backed long-term memory/context provider.
dotnet/src/Microsoft.Agents.AI.Valkey/ValkeyChatHistoryProvider.cs Introduces Valkey-backed persistent chat history provider using list operations.
dotnet/src/Microsoft.Agents.AI.Valkey/Microsoft.Agents.AI.Valkey.csproj Adds new Valkey project with dependencies and InternalsVisibleTo for tests.
dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step03_MemoryUsingValkey_Bedrock/README.md Adds Bedrock+Valkey sample documentation.
dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step03_MemoryUsingValkey_Bedrock/Program.cs Adds Bedrock-powered sample using both Valkey providers.
dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step03_MemoryUsingValkey_Bedrock/AgentWithMemory_Step03_MemoryUsingValkey_Bedrock.csproj Adds Bedrock sample project and dependency on AWSSDK.Extensions.Bedrock.MEAI.
dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step03_MemoryUsingValkey/README.md Adds Azure OpenAI+Valkey sample documentation.
dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step03_MemoryUsingValkey/Program.cs Adds Azure OpenAI powered sample using both Valkey providers.
dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step03_MemoryUsingValkey/AgentWithMemory_Step03_MemoryUsingValkey.csproj Adds Azure OpenAI sample project references.
dotnet/agent-framework-dotnet.slnx Registers the new Valkey project, new Valkey unit tests, and new samples in the solution.
dotnet/Directory.Packages.props Adds centrally managed version for AWSSDK.Extensions.Bedrock.MEAI.
.gitignore Ignores .kiro/ folder.

Comment thread dotnet/src/Microsoft.Agents.AI.Valkey/ValkeyContextProvider.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Valkey/ValkeyContextProvider.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Valkey/ValkeyContextProvider.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Valkey/ValkeyChatHistoryProvider.cs Outdated
Comment thread dotnet/tests/Microsoft.Agents.AI.Valkey.UnitTests/TestHelpers.cs
@MatthiasHowellYopp MatthiasHowellYopp force-pushed the issue-5445 branch 7 times, most recently from ab4e77d to 4f45ce9 Compare May 5, 2026 20:42
@MatthiasHowellYopp MatthiasHowellYopp force-pushed the issue-5445 branch 3 times, most recently from 16dc043 to 09145fa Compare May 14, 2026 14:29
@MatthiasHowellYopp MatthiasHowellYopp force-pushed the issue-5445 branch 3 times, most recently from 8036db8 to a3186e1 Compare May 20, 2026 15:17
@MatthiasHowellYopp
Copy link
Copy Markdown
Author

@westey-m Hoping I can get a review on this this week, tks

@MatthiasHowellYopp MatthiasHowellYopp force-pushed the issue-5445 branch 2 times, most recently from 786c06a to ecbe5e6 Compare May 21, 2026 17:06
Comment thread dotnet/src/Microsoft.Agents.AI.Valkey/Microsoft.Agents.AI.Valkey.csproj Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Valkey/ValkeyChatHistoryProvider.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Valkey/ValkeyChatHistoryProvider.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Valkey/ValkeyChatHistoryProvider.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Valkey/ValkeyContextProvider.cs Outdated
@westey-m
Copy link
Copy Markdown
Contributor

@westey-m Hoping I can get a review on this this week, tks

Thanks for the contribution @MatthiasHowellYopp. I've added a few comments.

@MatthiasHowellYopp
Copy link
Copy Markdown
Author

MatthiasHowellYopp commented May 22, 2026

Thanks for the thorough review @westey-m — pushed updates addressing all feedback:

Changes made:

Switched from StackExchange.Redis to Valkey.Glide 1.1.0 (official Valkey .NET client, GA'd April 2026). This resolves the naming question — we're now using the Valkey-native client library.

Extracted optional params into ValkeyChatHistoryProviderOptions following the InMemoryChatHistoryProviderOptions pattern. Constructor is now (IConnectionMultiplexer, Func, Options?, ILoggerFactory?).

Added JsonSerializerOptions to options, passed through to ProviderSessionState. Removed class-level [RequiresUnreferencedCode]/[RequiresDynamicCode].

MaxMessages/MaxMessagesToRetrieve are now private readonly fields set from options.

Removed ValkeyContextProvider and ValkeyProviderScope — agree it overlaps with ChatHistoryMemoryProvider + MEVD. Can revisit as a separate enhancement if there's a distinct use case for full-text search without embeddings.
Removed connection string constructors — caller manages their own IConnectionMultiplexer lifetime.

Updated model name in sample.

MatthiasHowellYopp and others added 2 commits May 22, 2026 09:23
…text provider

- Switch from StackExchange.Redis to Valkey.Glide 1.1.0 (official Valkey .NET client)
- Extract optional params into ValkeyChatHistoryProviderOptions
- Add JsonSerializerOptions support, remove [RequiresUnreferencedCode]
- Make MaxMessages/MaxMessagesToRetrieve readonly via options
- Remove ValkeyContextProvider (overlaps with ChatHistoryMemoryProvider + MEVD)
- Remove ValkeyProviderScope (only used by context provider)
- Remove connection string constructors (caller manages IConnectionMultiplexer)
- Update samples to use new API and gpt-5.4-mini
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 .NET

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants