Skip to content

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

Open
westey-m wants to merge 2 commits intomicrosoft:mainfrom
westey-m:provider-common-base-functionality
Open

.NET: [BREAKING] Refactor providers to move common functionality to base#3900
westey-m wants to merge 2 commits intomicrosoft:mainfrom
westey-m:provider-common-base-functionality

Conversation

@westey-m
Copy link
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.

Copilot AI review requested due to automatic review settings February 12, 2026 22:02
@markwallace-microsoft markwallace-microsoft added .NET workflows Related to Workflows in agent-framework labels Feb 12, 2026
@github-actions github-actions bot changed the title Refactor providers to move common functionality to base .NET: Refactor providers to move common functionality to base Feb 12, 2026
Copy link
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

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
File Description
dotnet/src/Microsoft.Agents.AI.Abstractions/ChatHistoryProvider{TState}.cs New generic base class providing typed state management for ChatHistoryProvider implementations
dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider{TState}.cs New generic base class providing typed state management for AIContextProvider implementations
dotnet/src/Microsoft.Agents.AI.Abstractions/ChatHistoryProvider.cs Refactored to template method pattern with ProvideChatHistoryAsync/StoreChatHistoryAsync, added constructor for filters
dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs Refactored to template method pattern with ProvideAIContextAsync/StoreAIContextAsync, added constructor for filters
dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryChatHistoryProvider.cs Updated to extend ChatHistoryProvider and pass filters to base constructor
dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryChatHistoryProviderOptions.cs Renamed RetrievalOutputMessageFilter to ProvideOutputMessageFilter
dotnet/src/Microsoft.Agents.AI.CosmosNoSql/CosmosChatHistoryProvider.cs Updated to extend ChatHistoryProvider, removed properties in favor of constructor parameters (breaking change)
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowChatHistoryProvider.cs Updated to extend ChatHistoryProvider, removed duplicate state management code
dotnet/src/Microsoft.Agents.AI/Memory/ChatHistoryMemoryProvider.cs Updated to extend AIContextProvider, removed duplicate state management and filter code
dotnet/src/Microsoft.Agents.AI/TextSearchProvider.cs Updated to extend AIContextProvider, removed duplicate state and filter code, made State class public
dotnet/src/Microsoft.Agents.AI.Mem0/Mem0Provider.cs Updated to extend AIContextProvider, moved state validation to wrapper function
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatHistoryProviderTests.cs Added comprehensive tests for new base class functionality
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatHistoryProviderTStateTests.cs New test file for ChatHistoryProvider functionality
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIContextProviderTests.cs Added comprehensive tests for new base class functionality
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIContextProviderTStateTests.cs New test file for AIContextProvider functionality
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/*.cs Updated Mock instantiations to pass null parameters to new base class constructors
dotnet/tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/CosmosChatHistoryProviderTests.cs Updated to use constructor parameters instead of property setters, updated comment
dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyChatHistoryStorage/Program.cs Updated VectorChatHistoryProvider to extend ChatHistoryProvider
dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step03_CustomMemory/Program.cs Updated UserInfoMemory to extend AIContextProvider

@westey-m westey-m changed the title .NET: Refactor providers to move common functionality to base .NET: [BREAKING]Refactor providers to move common functionality to base Feb 13, 2026
Copilot AI review requested due to automatic review settings February 13, 2026 09:27
Copy link
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

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>
Copilot AI review requested due to automatic review settings February 13, 2026 14:44
@westey-m westey-m force-pushed the provider-common-base-functionality branch from e252d58 to 46bb61a Compare February 13, 2026 14:44
@westey-m westey-m requested a review from a team as a code owner February 13, 2026 14:44
@westey-m westey-m changed the base branch from feature-session-statebag to main February 13, 2026 14:44
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python lab Agent Framework Lab labels Feb 13, 2026
@github-actions github-actions bot changed the title .NET: [BREAKING]Refactor providers to move common functionality to base Python: .NET: [BREAKING]Refactor providers to move common functionality to base Feb 13, 2026
Copy link
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

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

@westey-m westey-m changed the title Python: .NET: [BREAKING]Refactor providers to move common functionality to base Python: .NET: [BREAKING] Refactor providers to move common functionality to base Feb 13, 2026
@westey-m westey-m changed the title Python: .NET: [BREAKING] Refactor providers to move common functionality to base .NET: [BREAKING] Refactor providers to move common functionality to base Feb 13, 2026
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 lab Agent Framework Lab .NET python workflows Related to Workflows in agent-framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants