.NET: [BREAKING] Add ChatClient decorator for calling AIContextProviders#4097
Merged
westey-m merged 7 commits intomicrosoft:mainfrom Feb 23, 2026
Merged
Conversation
lokitoth
approved these changes
Feb 19, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds decorator-based middleware to invoke AIContextProvider/MessageAIContextProvider pipelines, enabling context enrichment before chat/agent execution and provider notifications after completion, aligning with issue #3957’s request for an IChatClient-level decorator.
Changes:
- Introduces
AIContextProviderChatClientand aChatClientBuilder.Use(...)extension to invokeAIContextProviders aroundIChatClientcalls. - Introduces
MessageAIContextProviderAgentto invokeMessageAIContextProviders aroundAIAgentruns (including streaming). - Adds unit tests and updates the Step14 middleware sample/docs to demonstrate the new pipeline.
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI/AIContextProviderDecorators/AIContextProviderChatClient.cs | New delegating chat client that invokes AIContextProvider pipeline for non-streaming and streaming calls. |
| dotnet/src/Microsoft.Agents.AI/AIContextProviderDecorators/AIContextProviderChatClientBuilderExtensions.cs | Adds ChatClientBuilder.Use(params AIContextProvider[]) extension to register the decorator. |
| dotnet/src/Microsoft.Agents.AI/AIContextProviderDecorators/MessageAIContextProviderAgent.cs | New delegating agent that invokes MessageAIContextProvider pipeline around agent runs and streaming. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/AIContextProviderDecorators/AIContextProviderChatClientTests.cs | Unit tests covering enrichment, sequencing, success/failure notifications, and builder integration for chat client decorator. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/AIContextProviderDecorators/MessageAIContextProviderAgentTests.cs | Unit tests covering enrichment, sequencing, and success/failure notifications for agent decorator (incl. streaming). |
| dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs | Sample updates to demonstrate using AIContextProvider in the IChatClient pipeline. |
| dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/README.md | Documentation update listing the new chat-client-level AIContextProvider middleware example. |
dotnet/src/Microsoft.Agents.AI/AIContextProviderDecorators/AIContextProviderChatClient.cs
Show resolved
Hide resolved
...rosoft.Agents.AI/AIContextProviderDecorators/AIContextProviderChatClientBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
rogerbarreto
approved these changes
Feb 20, 2026
rogerbarreto
approved these changes
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
#3957
Description
Contribution Checklist