Uh oh!
There was an error while loading. Please reload this page.
.NET: Support a message only AIContextProvider as an AIAgent Decorator - #4009
Conversation
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 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Motivation and Context
#3958
Description
Contribution Checklist