Skip to content

.NET: [BREAKING] Refactor providers to move common functionality to base - #3900

Merged
westey (westey-m) merged 4 commits into
microsoft:mainfrom
westey-m:provider-common-base-functionality
Feb 16, 2026
Merged

.NET: [BREAKING] Refactor providers to move common functionality to base#3900
westey (westey-m) merged 4 commits into
microsoft:mainfrom
westey-m:provider-common-base-functionality

Conversation

@westey-m

Copy link
Copy Markdown
Contributor

Motivation and Context

All providers have common filtering, state bag access and source stamping, so moving common functionality to base classes.

Description

  • Move common functionality to base classes

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.

CopilotAI review requested due to automatic review settings February 12, 2026 22:02
@markwallace-microsoftMark Wallace (markwallace-microsoft) added .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows labels Feb 12, 2026
@github-actionsgithub-actionsBot changed the title Refactor providers to move common functionality to base.NET: Refactor providers to move common functionality to baseFeb 12, 2026

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors provider classes to consolidate common functionality into base classes, introducing a template method pattern and generic state management. The refactoring moves filtering, state management, and source stamping logic from individual provider implementations into ChatHistoryProvider, AIContextProvider, and their new generic variants ChatHistoryProvider<TState> and AIContextProvider<TState>.

Changes:

  • Introduced generic base classes ChatHistoryProvider<TState> and AIContextProvider<TState> that consolidate state management (GetOrInitializeState, SaveState) with StateKey and JsonSerializerOptions handling
  • Refactored base provider classes to use template method pattern: sealed InvokingCoreAsync/InvokedCoreAsync methods now call overridable ProvideChatHistoryAsync/StoreChatHistoryAsync (for ChatHistoryProvider) and ProvideAIContextAsync/StoreAIContextAsync (for AIContextProvider)
  • Moved message filtering logic to base class constructors with default implementations (ChatHistory excludes ChatHistory-sourced messages from storage; AIContext includes only External messages)
  • Updated all concrete provider implementations and tests to work with the new base class structure
  • Renamed RetrievalOutputMessageFilter to ProvideOutputMessageFilter for consistency

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 8 comments.

Show a summary per file
FileDescription
dotnet/src/Microsoft.Agents.AI.Abstractions/ChatHistoryProvider{TState}.csNew generic base class providing typed state management for ChatHistoryProvider implementations
dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider{TState}.csNew generic base class providing typed state management for AIContextProvider implementations
dotnet/src/Microsoft.Agents.AI.Abstractions/ChatHistoryProvider.csRefactored to template method pattern with ProvideChatHistoryAsync/StoreChatHistoryAsync, added constructor for filters
dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.csRefactored to template method pattern with ProvideAIContextAsync/StoreAIContextAsync, added constructor for filters
dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryChatHistoryProvider.csUpdated to extend ChatHistoryProvider and pass filters to base constructor
dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryChatHistoryProviderOptions.csRenamed RetrievalOutputMessageFilter to ProvideOutputMessageFilter
dotnet/src/Microsoft.Agents.AI.CosmosNoSql/CosmosChatHistoryProvider.csUpdated to extend ChatHistoryProvider, removed properties in favor of constructor parameters (breaking change)
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowChatHistoryProvider.csUpdated to extend ChatHistoryProvider, removed duplicate state management code
dotnet/src/Microsoft.Agents.AI/Memory/ChatHistoryMemoryProvider.csUpdated to extend AIContextProvider, removed duplicate state management and filter code
dotnet/src/Microsoft.Agents.AI/TextSearchProvider.csUpdated to extend AIContextProvider, removed duplicate state and filter code, made State class public
dotnet/src/Microsoft.Agents.AI.Mem0/Mem0Provider.csUpdated to extend AIContextProvider, moved state validation to wrapper function
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatHistoryProviderTests.csAdded comprehensive tests for new base class functionality
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatHistoryProviderTStateTests.csNew test file for ChatHistoryProvider functionality
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIContextProviderTests.csAdded comprehensive tests for new base class functionality
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIContextProviderTStateTests.csNew test file for AIContextProvider functionality
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/*.csUpdated Mock instantiations to pass null parameters to new base class constructors
dotnet/tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/CosmosChatHistoryProviderTests.csUpdated to use constructor parameters instead of property setters, updated comment
dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyChatHistoryStorage/Program.csUpdated VectorChatHistoryProvider to extend ChatHistoryProvider
dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step03_CustomMemory/Program.csUpdated UserInfoMemory to extend AIContextProvider

Comment threaddotnet/src/Microsoft.Agents.AI.Abstractions/ChatHistoryProvider.cs Outdated
Comment threaddotnet/src/Microsoft.Agents.AI.Abstractions/ChatHistoryProvider.cs Outdated
Comment threaddotnet/src/Microsoft.Agents.AI.Mem0/Mem0Provider.cs Outdated
@westey-mwestey (westey-m) changed the title .NET: Refactor providers to move common functionality to base.NET: [BREAKING]Refactor providers to move common functionality to baseFeb 13, 2026
CopilotAI review requested due to automatic review settings February 13, 2026 09:27

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated no new comments.

Co-Authored-By: Copilot <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings February 13, 2026 14:44
@westey-m
westey (westey-m)force-pushed the provider-common-base-functionality branch from e252d58 to 46bb61aCompareFebruary 13, 2026 14:44
@westey-m
westey (westey-m) requested a review from a team as a code ownerFebruary 13, 2026 14:44
@westey-m
westey (westey-m) changed the base branch from feature-session-statebag to mainFebruary 13, 2026 14:44
@markwallace-microsoftMark Wallace (markwallace-microsoft) added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python lab labels Feb 13, 2026
@github-actionsgithub-actionsBot changed the title .NET: [BREAKING]Refactor providers to move common functionality to basePython: .NET: [BREAKING]Refactor providers to move common functionality to baseFeb 13, 2026

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.

@westey-mwestey (westey-m) changed the title Python: .NET: [BREAKING]Refactor providers to move common functionality to basePython: .NET: [BREAKING] Refactor providers to move common functionality to baseFeb 13, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentationUsage: [Issues, PRs], Target: documentation in the code base and learn docs.NETUsage: [Issues, PRs], Target: .NetpythonUsage: [Issues, PRs], Target: PythonworkflowsUsage: [Issues, PRs], Target: Workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@westey-m@rogerbarreto@SergeyMenshykh@moonbox3@markwallace-microsoft