Skip to content

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

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

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

Conversation

@westey-m

Copy link
Copy Markdown
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 Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants