.NET: Fix filter combine logic for ChatHistoryMemoryProvider#4501
Merged
westey-m merged 4 commits intomicrosoft:mainfrom Mar 6, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a bug in ChatHistoryMemoryProvider where combining multiple scope filters (ApplicationId/AgentId/UserId/SessionId) could produce an invalid expression tree due to mismatched ParameterExpression instances, breaking compilation/translation in some vector store connectors.
Changes:
- Reworked filter construction to use a single shared
ParameterExpression, rebinding each filter body before combining withExpression.AndAlso. - Added a unit test that captures the generated filter and verifies it can be compiled and executed when multiple scope fields are set.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI/Memory/ChatHistoryMemoryProvider.cs | Builds combined scope filters using a shared parameter and introduces a small expression visitor to rebind parameters safely. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/Memory/ChatHistoryMemoryProviderTests.cs | Adds a regression test ensuring combined filters are compilable/executable when multiple scope filters are present. |
dotnet/tests/Microsoft.Agents.AI.UnitTests/Memory/ChatHistoryMemoryProviderTests.cs
Show resolved
Hide resolved
peibekwe
reviewed
Mar 5, 2026
dotnet/src/Microsoft.Agents.AI/Memory/ChatHistoryMemoryProvider.cs
Outdated
Show resolved
Hide resolved
peibekwe
approved these changes
Mar 5, 2026
Address PR review nit: use explicit types instead of var for better readability in the filter-building logic and the new combined filter compilation test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
SergeyMenshykh
approved these changes
Mar 6, 2026
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 and Context
Fixes #4459
Description
Contribution Checklist