Skip to content

.NET: [BREAKING] Add ChatClient decorator for calling AIContextProviders#4097

Merged
westey-m merged 7 commits intomicrosoft:mainfrom
westey-m:chatclient-aicontextprovider
Feb 23, 2026
Merged

.NET: [BREAKING] Add ChatClient decorator for calling AIContextProviders#4097
westey-m merged 7 commits intomicrosoft:mainfrom
westey-m:chatclient-aicontextprovider

Conversation

@westey-m
Copy link
Contributor

Motivation and Context

#3957

Description

  • Add ChatClient decorator and ChatClientBuilder extension to allow calling AIContextProviders

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 19, 2026 19:47
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation .NET labels Feb 19, 2026
@github-actions github-actions bot changed the title Add ChatClient decorator for calling AIContextProviders .NET: Add ChatClient decorator for calling AIContextProviders Feb 19, 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

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 AIContextProviderChatClient and a ChatClientBuilder.Use(...) extension to invoke AIContextProviders around IChatClient calls.
  • Introduces MessageAIContextProviderAgent to invoke MessageAIContextProviders around AIAgent runs (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.

@westey-m westey-m changed the title .NET: Add ChatClient decorator for calling AIContextProviders .NET: [BREAKING] Add ChatClient decorator for calling AIContextProviders Feb 23, 2026
@westey-m westey-m enabled auto-merge February 23, 2026 14:54
@westey-m westey-m added this pull request to the merge queue Feb 23, 2026
Merged via the queue into microsoft:main with commit e45e581 Feb 23, 2026
15 checks passed
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.

5 participants