Table of Contents

Method InvokingCoreAsync

Namespace
Oscova.Agents.Providers
Assembly
Oscova.Agents.dll

InvokingCoreAsync(InvokingContext, CancellationToken)

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

protected override ValueTask<AIContext> InvokingCoreAsync(AIContextProvider.InvokingContext context, CancellationToken cancellationToken = default)

Parameters

context AIContextProvider.InvokingContext

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

cancellationToken CancellationToken

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

Returns

ValueTask<AIContext>

A task that represents the asynchronous operation. The task result contains the Microsoft.Agents.AI.AIContext with additional context to be used by the agent during this invocation.

Remarks

Implementers can load any additional context required at this time, such as:

  • Retrieving relevant information from knowledge bases
  • Adding system instructions or prompts
  • Providing function tools for the current invocation
  • Injecting contextual messages from conversation history

The default implementation of this method filters the input messages using the configured provide-input message filter (which defaults to including only Microsoft.Agents.AI.AgentRequestMessageSourceType.External messages), then calls Microsoft.Agents.AI.AIContextProvider.ProvideAIContextAsync(Microsoft.Agents.AI.AIContextProvider.InvokingContext,System.Threading.CancellationToken) to get additional context, stamps any messages from the returned context with Microsoft.Agents.AI.AgentRequestMessageSourceType.AIContextProvider source attribution, and merges the returned context with the original (unfiltered) input context (concatenating instructions, messages, and tools). For most scenarios, overriding Microsoft.Agents.AI.AIContextProvider.ProvideAIContextAsync(Microsoft.Agents.AI.AIContextProvider.InvokingContext,System.Threading.CancellationToken) is sufficient to provide additional context, while still benefiting from the default filtering, merging and source stamping behavior. However, for scenarios that require more control over context filtering, merging or source stamping, overriding this method allows you to directly control the full Microsoft.Agents.AI.AIContext returned for the invocation.