Skip to content

Comments

.NET: Support a message only AIContextProvider as an AIAgent Decorator#4009

Merged
westey-m merged 6 commits intomicrosoft:mainfrom
westey-m:context-provider-agent-decorator
Feb 19, 2026
Merged

.NET: Support a message only AIContextProvider as an AIAgent Decorator#4009
westey-m merged 6 commits intomicrosoft:mainfrom
westey-m:context-provider-agent-decorator

Conversation

@westey-m
Copy link
Contributor

Motivation and Context

#3958

Description

  • Introduce a new MessageAIContextProvider that only supports message context enrichment
  • Allow the MessageAIContextProvider to be used to decorate any AIAgent instance

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 17, 2026 18:31
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation .NET labels Feb 17, 2026
@github-actions github-actions bot changed the title Support a message only AIContextProvider as an AIAgent Decorator .NET: Support a message only AIContextProvider as an AIAgent Decorator Feb 17, 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 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 MessageAIContextProvider abstract base class that inherits from AIContextProvider and focuses solely on message enrichment
  • Added MessageAIContextProviderAgent decorator that wraps any AIAgent and invokes a pipeline of MessageAIContextProvider instances
  • Converted TextSearchProvider, ChatHistoryMemoryProvider, and Mem0Provider to inherit from MessageAIContextProvider
  • Added AIAgentBuilder.Use(MessageAIContextProvider[]) extension method for easy integration
  • Enhanced ProviderSessionState constructor validation with proper null and whitespace checks
  • Exposed ProvideInputMessageFilter and StoreInputMessageFilter as protected properties in AIContextProvider to 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

@westey-m westey-m enabled auto-merge February 19, 2026 15:52
@westey-m westey-m added this pull request to the merge queue Feb 19, 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 .NET

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants