Share via


MessageAIContextProvider.ProvideMessagesAsync Method

Definition

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

protected virtual System.Threading.Tasks.ValueTask<System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.ChatMessage>> ProvideMessagesAsync(Microsoft.Agents.AI.MessageAIContextProvider.InvokingContext context, System.Threading.CancellationToken cancellationToken = default);
abstract member ProvideMessagesAsync : Microsoft.Agents.AI.MessageAIContextProvider.InvokingContext * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<seq<Microsoft.Extensions.AI.ChatMessage>>
override this.ProvideMessagesAsync : Microsoft.Agents.AI.MessageAIContextProvider.InvokingContext * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<seq<Microsoft.Extensions.AI.ChatMessage>>
Protected Overridable Function ProvideMessagesAsync (context As MessageAIContextProvider.InvokingContext, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of IEnumerable(Of ChatMessage))

Parameters

context
MessageAIContextProvider.InvokingContext

Contains the request context including the caller provided messages that will be used by the agent for this invocation.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

A task that represents the asynchronous operation. The task result contains an IEnumerable<T> with additional messages to be merged with the input messages.

Remarks

This method is called from InvokingCoreAsync(MessageAIContextProvider+InvokingContext, CancellationToken). Note that InvokingCoreAsync(MessageAIContextProvider+InvokingContext, CancellationToken) can be overridden to directly control messages merging and source stamping, in which case it is up to the implementer to call this method as needed to retrieve the additional messages.

In contrast with InvokingCoreAsync(MessageAIContextProvider+InvokingContext, CancellationToken), this method only returns additional messages to be merged with the input, while InvokingCoreAsync(MessageAIContextProvider+InvokingContext, CancellationToken) is responsible for returning the full merged IEnumerable<T> for the invocation.

Applies to