ChatHistoryProvider Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides an abstract base class for fetching chat messages from, and adding chat messages to, chat history for the purposes of agent execution.
public abstract class ChatHistoryProvider
type ChatHistoryProvider = class
Public MustInherit Class ChatHistoryProvider
- Inheritance
-
ChatHistoryProvider
- Derived
Remarks
ChatHistoryProvider defines the contract that an AIAgent can use to retrieve messsages from chat history and provide notification of newly produced messages. Implementations are responsible for managing message persistence, retrieval, and any necessary optimization strategies such as truncation, summarization, or archival.
Key responsibilities include:
- Storing chat messages with proper ordering and metadata preservation
- Retrieving messages in chronological order for agent context
- Managing storage limits through truncation, summarization, or other strategies
The ChatHistoryProvider is passed a reference to the AgentSession via ChatHistoryProvider.InvokingContext and ChatHistoryProvider.InvokedContext allowing it to store state in the StateBag. Since a ChatHistoryProvider is used with many different sessions, it should not store any session-specific information within its own instance fields. Instead, any session-specific state should be stored in the associated StateBag.
A ChatHistoryProvider is only relevant for scenarios where the underlying AI service that the agent is using does not use in-service chat history storage.
Constructors
| Name | Description |
|---|---|
| ChatHistoryProvider(Func<IEnumerable<ChatMessage>,IEnumerable<ChatMessage>>, Func<IEnumerable<ChatMessage>,IEnumerable<ChatMessage>>) |
Initializes a new instance of the ChatHistoryProvider class. |
Properties
| Name | Description |
|---|---|
| StateKey |
Gets the key used to store the provider state in the StateBag. |
Methods
| Name | Description |
|---|---|
| GetService(Type, Object) |
Asks the ChatHistoryProvider for an object of the specified type |
| GetService<TService>(Object) |
Asks the ChatHistoryProvider for an object of type |
| InvokedAsync(ChatHistoryProvider+InvokedContext, CancellationToken) |
Called at the end of the agent invocation to add new messages to the chat history. |
| InvokedCoreAsync(ChatHistoryProvider+InvokedContext, CancellationToken) |
Called at the end of the agent invocation to add new messages to the chat history. |
| InvokingAsync(ChatHistoryProvider+InvokingContext, CancellationToken) |
Called at the start of agent invocation to provide messages for the next agent invocation. |
| InvokingCoreAsync(ChatHistoryProvider+InvokingContext, CancellationToken) |
Called at the start of agent invocation to provide messages for the next agent invocation. |
| ProvideChatHistoryAsync(ChatHistoryProvider+InvokingContext, CancellationToken) |
When overridden in a derived class, provides the chat history messages to be used for the current invocation. |
| StoreChatHistoryAsync(ChatHistoryProvider+InvokedContext, CancellationToken) |
When overridden in a derived class, adds new messages to the chat history at the end of the agent invocation. |