Description
What problem does it solve?
The CosmosChatHistoryProvider currently provides utility methods like GetMessageCountAsync() and ClearMessagesAsync(), but there's no public method to retrieve the chat history messages outside of the normal chat invocation flow.
In scenarios where legacy code or other parts of an application need to read the conversation history without performing a chat operation, there's no convenient way to do so. The only method that retrieves messages (InvokingCoreAsync) is protected and only accessible during the chat invocation pipeline.
What would the expected behavior be?
Add a public GetMessagesAsync() method that returns the chat history for the current conversation, respecting the same configuration properties (MaxMessagesToRetrieve, MaxItemCount, etc.) as the internal retrieval logic.
Are there any alternatives you've considered?
Direct Cosmos DB access: Creating a separate helper class that queries Cosmos DB directly, but this duplicates query logic and risks deserialization inconsistencies if the internal implementation changes.
(Other approaches like reflection are obviously not viable alternatives)
Additional Context
I understand this adds a third public utility method to the class, which could potentially lead to future feature requests for similar convenience methods. However, this particular request fills a genuine gap in the API—reading conversation history is a fundamental operation that complements the existing count and delete utilities. The implementation can be based directly on the existing internal retrieval logic, ensuring consistency and maintainability.
Code Sample
var provider = new CosmosChatHistoryProvider(
cosmosClient,
"myDatabase",
"myContainer",
"conversation-123");
// Configure optional limits
provider.MaxMessagesToRetrieve = 50;
// Retrieve the conversation history
IEnumerable<ChatMessage> messages = await provider.GetMessagesAsync();
// Process messages
foreach (var message in messages)
{
Console.WriteLine($"{message.Role}: {message.Text}");
}
Language/SDK
.NET
Description
What problem does it solve?
The
CosmosChatHistoryProvidercurrently provides utility methods likeGetMessageCountAsync()andClearMessagesAsync(), but there's no public method to retrieve the chat history messages outside of the normal chat invocation flow.In scenarios where legacy code or other parts of an application need to read the conversation history without performing a chat operation, there's no convenient way to do so. The only method that retrieves messages (
InvokingCoreAsync) isprotectedand only accessible during the chat invocation pipeline.What would the expected behavior be?
Add a public
GetMessagesAsync()method that returns the chat history for the current conversation, respecting the same configuration properties (MaxMessagesToRetrieve,MaxItemCount, etc.) as the internal retrieval logic.Are there any alternatives you've considered?
Direct Cosmos DB access: Creating a separate helper class that queries Cosmos DB directly, but this duplicates query logic and risks deserialization inconsistencies if the internal implementation changes.
(Other approaches like reflection are obviously not viable alternatives)
Additional Context
I understand this adds a third public utility method to the class, which could potentially lead to future feature requests for similar convenience methods. However, this particular request fills a genuine gap in the API—reading conversation history is a fundamental operation that complements the existing count and delete utilities. The implementation can be based directly on the existing internal retrieval logic, ensuring consistency and maintainability.
Code Sample
var provider = new CosmosChatHistoryProvider( cosmosClient, "myDatabase", "myContainer", "conversation-123"); // Configure optional limits provider.MaxMessagesToRetrieve = 50; // Retrieve the conversation history IEnumerable<ChatMessage> messages = await provider.GetMessagesAsync(); // Process messages foreach (var message in messages) { Console.WriteLine($"{message.Role}: {message.Text}"); }Language/SDK
.NET