Share via


AIContextProvider Class

Definition

Provides an abstract base class for components that enhance AI context during agent invocations.

public abstract class AIContextProvider
type AIContextProvider = class
Public MustInherit Class AIContextProvider
Inheritance
AIContextProvider
Derived

Remarks

An AI context provider is a component that participates in the agent invocation lifecycle by:

  • Listening to changes in conversations
  • Providing additional context to agents during invocation
  • Supplying additional function tools for enhanced capabilities
  • Processing invocation results for state management or learning

Context providers operate through a two-phase lifecycle: they are called at the start of invocation via InvokingAsync(AIContextProvider+InvokingContext, CancellationToken) to provide context, and optionally called at the end of invocation via InvokedAsync(AIContextProvider+InvokedContext, CancellationToken) to process results.

Constructors

Name Description
AIContextProvider(Func<IEnumerable<ChatMessage>,IEnumerable<ChatMessage>>, Func<IEnumerable<ChatMessage>,IEnumerable<ChatMessage>>)

Initializes a new instance of the AIContextProvider class.

Properties

Name Description
ProvideInputMessageFilter

Gets the filter function to apply to input messages before providing context via ProvideAIContextAsync(AIContextProvider+InvokingContext, CancellationToken).

StateKey

Gets the key used to store the provider state in the StateBag.

StoreInputMessageFilter

Gets the filter function to apply to request messages before storing context via StoreAIContextAsync(AIContextProvider+InvokedContext, CancellationToken).

Methods

Name Description
GetService(Type, Object)

Asks the AIContextProvider for an object of the specified type serviceType.

GetService<TService>(Object)

Asks the AIContextProvider for an object of type TService.

InvokedAsync(AIContextProvider+InvokedContext, CancellationToken)

Called at the end of the agent invocation to process the invocation results.

InvokedCoreAsync(AIContextProvider+InvokedContext, CancellationToken)

Called at the end of the agent invocation to process the invocation results.

InvokingAsync(AIContextProvider+InvokingContext, CancellationToken)

Called at the start of agent invocation to provide additional context.

InvokingCoreAsync(AIContextProvider+InvokingContext, CancellationToken)

Called at the start of agent invocation to provide additional context.

ProvideAIContextAsync(AIContextProvider+InvokingContext, CancellationToken)

When overridden in a derived class, provides additional AI context to be merged with the input context for the current invocation.

StoreAIContextAsync(AIContextProvider+InvokedContext, CancellationToken)

When overridden in a derived class, processes invocation results at the end of the agent invocation.

Applies to