Share via


AIContextProvider.InvokedCoreAsync Method

Definition

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

protected virtual System.Threading.Tasks.ValueTask InvokedCoreAsync(Microsoft.Agents.AI.AIContextProvider.InvokedContext context, System.Threading.CancellationToken cancellationToken = default);
abstract member InvokedCoreAsync : Microsoft.Agents.AI.AIContextProvider.InvokedContext * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask
override this.InvokedCoreAsync : Microsoft.Agents.AI.AIContextProvider.InvokedContext * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask
Protected Overridable Function InvokedCoreAsync (context As AIContextProvider.InvokedContext, Optional cancellationToken As CancellationToken = Nothing) As ValueTask

Parameters

context
AIContextProvider.InvokedContext

Contains the invocation context including request messages, response messages, and any exception that occurred.

cancellationToken
CancellationToken

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

Returns

A task that represents the asynchronous operation.

Remarks

Implementers can use the request and response messages in the provided context to:

  • Update internal state based on conversation outcomes
  • Extract and store memories or preferences from user messages
  • Log or audit conversation details
  • Perform cleanup or finalization tasks

This method is called regardless of whether the invocation succeeded or failed. To check if the invocation was successful, inspect the InvokeException property.

The default implementation of this method skips execution for any invocation failures, filters the request messages using the configured store-input message filter (which defaults to including only External messages), and calls StoreAIContextAsync(AIContextProvider+InvokedContext, CancellationToken) to process the invocation results. For most scenarios, overriding StoreAIContextAsync(AIContextProvider+InvokedContext, CancellationToken) is sufficient to process invocation results, while still benefiting from the default error handling and filtering behavior. However, for scenarios that require more control over error handling or message filtering, overriding this method allows you to directly control the processing of invocation results.

Applies to