Share via


ChatHistoryProvider.InvokingAsync Method

Definition

Called at the start of agent invocation to provide messages for the next agent invocation.

public System.Threading.Tasks.ValueTask<System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.ChatMessage>> InvokingAsync(Microsoft.Agents.AI.ChatHistoryProvider.InvokingContext context, System.Threading.CancellationToken cancellationToken = default);
member this.InvokingAsync : Microsoft.Agents.AI.ChatHistoryProvider.InvokingContext * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<seq<Microsoft.Extensions.AI.ChatMessage>>
Public Function InvokingAsync (context As ChatHistoryProvider.InvokingContext, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of IEnumerable(Of ChatMessage))

Parameters

context
ChatHistoryProvider.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 a collection of ChatMessage instances that will be used for the agent invocation.

Remarks

If the total message history becomes very large, implementations should apply appropriate strategies to manage storage constraints, such as:

  • Truncating older messages while preserving recent context
  • Summarizing message groups to maintain essential context
  • Implementing sliding window approaches for message retention
  • Archiving old messages while keeping active conversation context

Applies to