Share via


InMemoryChatHistoryProvider Class

Definition

Provides an in-memory implementation of ChatHistoryProvider with support for message reduction.

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

Remarks

InMemoryChatHistoryProvider stores chat messages in the StateBag, providing fast access and manipulation capabilities integrated with session state management.

This ChatHistoryProvider maintains all messages in memory. For long-running conversations or high-volume scenarios, consider using message reduction strategies or alternative storage implementations.

Constructors

Name Description
InMemoryChatHistoryProvider(InMemoryChatHistoryProviderOptions)

Initializes a new instance of the InMemoryChatHistoryProvider class.

Properties

Name Description
ChatReducer

Gets the chat reducer used to process or reduce chat messages. If null, no reduction logic will be applied.

ReducerTriggerEvent

Gets the event that triggers the reducer invocation in this provider.

StateKey

Gets the key used to store the provider state in the StateBag.

Methods

Name Description
GetMessages(AgentSession)

Gets the chat messages stored for the specified session.

GetService(Type, Object)

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

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

Asks the ChatHistoryProvider for an object of type TService.

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

Called at the end of the agent invocation to add new messages to the chat history.

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

Called at the end of the agent invocation to add new messages to the chat history.

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

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

(Inherited from ChatHistoryProvider)
InvokingCoreAsync(ChatHistoryProvider+InvokingContext, CancellationToken)

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

(Inherited from ChatHistoryProvider)
ProvideChatHistoryAsync(ChatHistoryProvider+InvokingContext, CancellationToken)

When overridden in a derived class, provides the chat history messages to be used for the current invocation.

(Inherited from ChatHistoryProvider)
SetMessages(AgentSession, List<ChatMessage>)

Sets the chat messages for the specified session.

StoreChatHistoryAsync(ChatHistoryProvider+InvokedContext, CancellationToken)

When overridden in a derived class, adds new messages to the chat history at the end of the agent invocation.

(Inherited from ChatHistoryProvider)

Applies to