AIAgentBuilder.UseAIContextProviders(MessageAIContextProvider[]) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds one or more MessageAIContextProvider instances to the agent pipeline, enabling message enrichment for any AIAgent.
public Microsoft.Agents.AI.AIAgentBuilder UseAIContextProviders(params Microsoft.Agents.AI.MessageAIContextProvider[] providers);
member this.UseAIContextProviders : Microsoft.Agents.AI.MessageAIContextProvider[] -> Microsoft.Agents.AI.AIAgentBuilder
Public Function UseAIContextProviders (ParamArray providers As MessageAIContextProvider()) As AIAgentBuilder
Parameters
- providers
- MessageAIContextProvider[]
The MessageAIContextProvider instances to invoke before and after each agent invocation. Providers are called in sequence, with each receiving the output of the previous provider.
Returns
The AIAgentBuilder with the providers added, enabling method chaining.
Exceptions
providers is empty.
Remarks
This method wraps the inner agent with a DelegatingAIAgent that calls each provider's InvokingAsync(MessageAIContextProvider+InvokingContext, CancellationToken) in sequence before the inner agent runs, and calls InvokedAsync(AIContextProvider+InvokedContext, CancellationToken) on each provider after the inner agent completes.
This allows any AIAgent to benefit from MessageAIContextProvider-based context enrichment, not just agents that natively support AIContextProvider instances.