CosmosChatHistoryProvider 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 a Cosmos DB implementation of the ChatHistoryProvider abstract class.
public sealed class CosmosChatHistoryProvider : Microsoft.Agents.AI.ChatHistoryProvider, IDisposable
type CosmosChatHistoryProvider = class
inherit ChatHistoryProvider
interface IDisposable
Public NotInheritable Class CosmosChatHistoryProvider
Inherits ChatHistoryProvider
Implements IDisposable
- Inheritance
- Implements
Constructors
| Name | Description |
|---|---|
| CosmosChatHistoryProvider(CosmosClient, String, String, Func<AgentSession, CosmosChatHistoryProvider.State>, Boolean, String, Func<IEnumerable<ChatMessage>, IEnumerable<ChatMessage>>, Func<IEnumerable<ChatMessage>,IEnumerable<ChatMessage>>) |
Initializes a new instance of the CosmosChatHistoryProvider class. |
| CosmosChatHistoryProvider(String, String, String, Func<AgentSession, CosmosChatHistoryProvider.State>, String, Func<IEnumerable<ChatMessage>, IEnumerable<ChatMessage>>, Func<IEnumerable<ChatMessage>,IEnumerable<ChatMessage>>) |
Initializes a new instance of the CosmosChatHistoryProvider class using a connection string. |
| CosmosChatHistoryProvider(String, TokenCredential, String, String, Func<AgentSession,CosmosChatHistoryProvider.State>, String, Func<IEnumerable<ChatMessage>, IEnumerable<ChatMessage>>, Func<IEnumerable<ChatMessage>,IEnumerable<ChatMessage>>) |
Initializes a new instance of the CosmosChatHistoryProvider class using TokenCredential for authentication. |
Properties
| Name | Description |
|---|---|
| ContainerId |
Gets the container ID associated with this provider. |
| DatabaseId |
Gets the database ID associated with this provider. |
| MaxBatchSize |
Gets or sets the maximum number of items per transactional batch operation. Default is 100, maximum allowed by Cosmos DB is 100. |
| MaxItemCount |
Gets or sets the maximum number of messages to return in a single query batch. Default is 100 for optimal performance. |
| MaxMessagesToRetrieve |
Gets or sets the maximum number of messages to retrieve from the provider. This helps prevent exceeding LLM context windows in long conversations. Default is null (no limit). When set, only the most recent messages are returned. |
| MessageTtlSeconds |
Gets or sets the Time-To-Live (TTL) in seconds for messages. Default is 86400 seconds (24 hours). Set to null to disable TTL. |
| StateKey |
Gets the key used to store the provider state in the StateBag. |
Methods
| Name | Description |
|---|---|
| ClearMessagesAsync(AgentSession, CancellationToken) |
Deletes all messages in this conversation. This is an additional utility method beyond the base contract. |
| Dispose() | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
| GetMessageCountAsync(AgentSession, CancellationToken) |
Gets the count of messages in this conversation. This is an additional utility method beyond the base contract. |
| 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. (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) |
| 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) |