.NET: Support a message only AIContextProvider as an AIAgent Decorator#4009
Merged
westey-m merged 6 commits intomicrosoft:mainfrom Feb 19, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request introduces MessageAIContextProvider, a new base class that enables message-only context enrichment for any AIAgent instance, addressing issue #3958. The implementation allows providers to enrich agent messages without requiring support for tools and instructions, making context providers more flexible and widely applicable.
Changes:
- Introduced
MessageAIContextProviderabstract base class that inherits fromAIContextProviderand focuses solely on message enrichment - Added
MessageAIContextProviderAgentdecorator that wraps anyAIAgentand invokes a pipeline ofMessageAIContextProviderinstances - Converted
TextSearchProvider,ChatHistoryMemoryProvider, andMem0Providerto inherit fromMessageAIContextProvider - Added
AIAgentBuilder.Use(MessageAIContextProvider[])extension method for easy integration - Enhanced
ProviderSessionStateconstructor validation with proper null and whitespace checks - Exposed
ProvideInputMessageFilterandStoreInputMessageFilteras protected properties inAIContextProviderto support inheritance - Updated samples to demonstrate the new pattern
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Abstractions/MessageAIContextProvider.cs | New base class for message-only context providers with InvokingAsync and ProvideMessagesAsync methods |
| dotnet/src/Microsoft.Agents.AI/MessageAIContextProviderAgent.cs | Decorator implementation that enriches messages via provider pipeline before delegating to inner agent |
| dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs | Exposed filter functions as protected properties to support derived class access |
| dotnet/src/Microsoft.Agents.AI.Abstractions/ProviderSessionState{TState}.cs | Added null and whitespace validation to constructor parameters |
| dotnet/src/Microsoft.Agents.AI/TextSearchProvider.cs | Refactored to inherit from MessageAIContextProvider with proper OnDemand validation |
| dotnet/src/Microsoft.Agents.AI/Memory/ChatHistoryMemoryProvider.cs | Refactored to inherit from MessageAIContextProvider with proper OnDemand validation |
| dotnet/src/Microsoft.Agents.AI.Mem0/Mem0Provider.cs | Simplified to inherit from MessageAIContextProvider returning messages directly |
| dotnet/src/Microsoft.Agents.AI/AIAgentBuilder.cs | Added Use extension method accepting MessageAIContextProvider array |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/MessageAIContextProviderTests.cs | Comprehensive tests for MessageAIContextProvider base class functionality |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/MessageAIContextProviderAgentTests.cs | Tests for decorator pattern including pipeline behavior and error handling |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ProviderSessionStateTests.cs | Constructor validation tests |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/Memory/ChatHistoryMemoryProviderTests.cs | MessageAIContextProvider integration tests for ChatHistoryMemoryProvider |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/Data/TextSearchProviderTests.cs | MessageAIContextProvider integration tests for TextSearchProvider |
| dotnet/tests/Microsoft.Agents.AI.Mem0.UnitTests/Mem0ProviderTests.cs | MessageAIContextProvider integration tests for Mem0Provider |
| dotnet/samples/GettingStarted/Agents/Agent_Step20_AdditionalAIContext/Program.cs | Updated sample to use MessageAIContextProvider pattern |
| dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs | Added example demonstrating MessageAIContextProvider middleware |
| dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/README.md | Updated documentation to mention MessageAIContextProvider middleware |
dotnet/src/Microsoft.Agents.AI.Abstractions/MessageAIContextProvider.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI/MessageAIContextProviderAgent.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Abstractions/MessageAIContextProvider.cs
Outdated
Show resolved
Hide resolved
lokitoth
reviewed
Feb 18, 2026
SergeyMenshykh
approved these changes
Feb 18, 2026
lokitoth
approved these changes
Feb 19, 2026
SergeyMenshykh
approved these changes
Feb 19, 2026
This was referenced Feb 23, 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
#3958
Description
Contribution Checklist