.NET: Add Cosmos chat history retrieval API - #7412
Open
ilia-sokolov wants to merge 4 commits into
Open
Conversation
ilia-sokolov
temporarily deployed
to
github-app-auth
July 29, 2026 20:33 — with
GitHub Actions
Inactive
ilia-sokolov
temporarily deployed
to
github-app-auth
July 29, 2026 20:33 — with
GitHub Actions
Inactive
ilia-sokolov
temporarily deployed
to
github-app-auth
July 29, 2026 20:33 — with
GitHub Actions
Inactive
ilia-sokolov
temporarily deployed
to
github-app-auth
July 29, 2026 20:34 — with
GitHub Actions
Inactive
ilia-sokolov
marked this pull request as ready for review
July 29, 2026 20:35
ilia-sokolov
temporarily deployed
to
github-app-auth
July 29, 2026 20:35 — with
GitHub Actions
Inactive
ilia-sokolov
temporarily deployed
to
github-app-auth
July 29, 2026 20:37 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a public retrieval API to the .NET Cosmos-backed chat history provider so callers can read stored conversation messages out-of-band (without running the agent invocation pipeline), while reusing the same Cosmos query/pagination logic that invocation retrieval uses.
Changes:
- Added
GetMessagesAsync(AgentSession?, CancellationToken)toCosmosChatHistoryProviderfor direct message retrieval. - Refactored invocation history retrieval (
ProvideChatHistoryAsync) to reuseGetMessagesAsyncso both paths share the same query/paging/limits behavior. - Added Cosmos emulator-dependent unit tests covering pagination, empty histories, filter/source-attribution differences, disposal, and cancellation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.CosmosNoSql/CosmosChatHistoryProvider.cs | Introduces the new retrieval API and routes invocation history retrieval through it; disposes the Cosmos query iterator. |
| dotnet/tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/CosmosChatHistoryProviderTests.cs | Adds emulator-based tests validating the new public retrieval behavior and its differences from invocation-processed history. |
ilia-sokolov
temporarily deployed
to
github-app-auth
July 30, 2026 08:41 — with
GitHub Actions
Inactive
ilia-sokolov
temporarily deployed
to
github-app-auth
July 30, 2026 08:57 — with
GitHub Actions
Inactive
ilia-sokolov
temporarily deployed
to
github-app-auth
July 30, 2026 09:34 — with
GitHub Actions
Inactive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
CosmosChatHistoryProviderexposes utilities for counting and clearing stored messages, but applications cannot retrieve those messages without running the agent invocation pipeline. This makes migration, inspection, and other out-of-band conversation-history scenarios unnecessarily difficult.Description & Review Guide
GetMessagesAsync(AgentSession?, CancellationToken)to retrieve the messages stored for a session.ProvideChatHistoryAsyncso public and invocation retrieval share the same Cosmos query, pagination,MaxItemCount, andMaxMessagesToRetrievebehavior.Related Issue
Fixes #3809
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.