Share via


TextSearchProvider Class

Definition

A text search context provider that performs a search over external knowledge and injects the formatted results into the AI invocation context, or exposes a search tool for on-demand use. This provider can be used to enable Retrieval Augmented Generation (RAG) on an agent.

public sealed class TextSearchProvider : Microsoft.Agents.AI.MessageAIContextProvider
type TextSearchProvider = class
    inherit MessageAIContextProvider
Public NotInheritable Class TextSearchProvider
Inherits MessageAIContextProvider
Inheritance

Remarks

The provider supports two behaviors controlled via SearchTime:

  • BeforeAIInvoke – Automatically performs a search prior to every AI invocation and injects results as additional messages.
  • OnDemandFunctionCalling – Exposes a function tool that the model may invoke to retrieve contextual information when needed.

When RecentMessageMemoryLimit is greater than zero the provider will retain the most recent user and assistant messages (up to the configured limit) across invocations and prepend them (in chronological order) to the current request messages when forming the search input. This can improve search relevance by providing multi-turn context to the retrieval layer without permanently altering the conversation history.

Constructors

Name Description
TextSearchProvider(Func<String,CancellationToken,Task<IEnumerable<TextSearchProvider.TextSearchResult>>>, TextSearchProviderOptions, ILoggerFactory)

Initializes a new instance of the TextSearchProvider class.

Properties

Name Description
ProvideInputMessageFilter

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

(Inherited from AIContextProvider)
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).

(Inherited from AIContextProvider)

Methods

Name Description
GetService(Type, Object)

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

(Inherited from AIContextProvider)
GetService<TService>(Object)

Asks the AIContextProvider for an object of type TService.

(Inherited from AIContextProvider)
InvokedAsync(AIContextProvider+InvokedContext, CancellationToken)

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

(Inherited from AIContextProvider)
InvokedCoreAsync(AIContextProvider+InvokedContext, CancellationToken)

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

(Inherited from AIContextProvider)
InvokingAsync(AIContextProvider+InvokingContext, CancellationToken)

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

(Inherited from AIContextProvider)
InvokingAsync(MessageAIContextProvider+InvokingContext, CancellationToken)

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

(Inherited from MessageAIContextProvider)
InvokingCoreAsync(AIContextProvider+InvokingContext, CancellationToken)

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

(Inherited from AIContextProvider)
InvokingCoreAsync(MessageAIContextProvider+InvokingContext, CancellationToken)

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

(Inherited from MessageAIContextProvider)
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.

(Inherited from MessageAIContextProvider)
ProvideMessagesAsync(MessageAIContextProvider+InvokingContext, CancellationToken)

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

(Inherited from MessageAIContextProvider)
StoreAIContextAsync(AIContextProvider+InvokedContext, CancellationToken)

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

(Inherited from AIContextProvider)

Applies to