Skip to content

.NET: [BREAKING] Refactor ChatMessageStore methods to be similar to AIContextProvider and add filtering support - #2604

Merged
westey (westey-m) merged 19 commits into
microsoft:mainfrom
westey-m:chatmessagestore-method-refactor
Jan 5, 2026
Merged

.NET: [BREAKING] Refactor ChatMessageStore methods to be similar to AIContextProvider and add filtering support#2604
westey (westey-m) merged 19 commits into
microsoft:mainfrom
westey-m:chatmessagestore-method-refactor

Conversation

@westey-m

@westey-mwestey (westey-m) commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

Motivation and Context

#2518
#2054

Description

  • Refactor ChatMessageStore interface to be more similar to AIContextProvider, to give more certainty as to the data being passed to it, and the circumstances under which that data is passed.
  • Add a ChatMessageStore decorator that makes it easy to filter the messages being passed to the ChatMessageStore. This allows us to easily avoid persisting messages from AIContextProviders in the chat history.
AIAgentagent=azureOpenAIClient.GetChatClient(deploymentName).CreateAIAgent(newChatClientAgentOptions{ChatOptions=new(){Instructions="You are a helpful support specialist for Contoso Outdoors. Answer questions using the provided context and cite the source document when available."},AIContextProviderFactory= ctx =>newTextSearchProvider(SearchAdapter,ctx.SerializedState,ctx.JsonSerializerOptions,textSearchOptions),// Since we are using ChatCompletion which stores chat history locally, we can also add a message removal policy// that removes messages produced by the TextSearchProvider before they are added to the chat history, so that// we don't bloat chat history with all the search result messages.ChatMessageStoreFactory= ctx =>newInMemoryChatMessageStore(ctx.SerializedState,ctx.JsonSerializerOptions).WithAIContextProviderMessageRemoval(),});

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.

@markwallace-microsoftMark Wallace (markwallace-microsoft) added .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows labels Dec 3, 2025
@github-actionsgithub-actionsBot changed the title Refactor ChatMessageStore methods to be similar to AIContextProvider.NET: Refactor ChatMessageStore methods to be similar to AIContextProviderDec 3, 2025
@westey-mwestey (westey-m) changed the title .NET: Refactor ChatMessageStore methods to be similar to AIContextProvider.NET: [BREAKING] Refactor ChatMessageStore methods to be similar to AIContextProviderDec 5, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NETUsage: [Issues, PRs], Target: .NetworkflowsUsage: [Issues, PRs], Target: Workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@westey-m@SergeyMenshykh@markwallace-microsoft