.NET: CosmosDB Actor State Storage#262
Merged
adityamandaleeka merged 18 commits intomainfrom Aug 5, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a CosmosDB-based implementation for actor state storage in the AI Agents framework. It provides an alternative storage backend to the default in-memory storage for persistent actor state management.
Key changes include:
- A complete CosmosDB implementation of
IActorStateStoragewith optimistic concurrency control - Comprehensive integration tests using Aspire for both real CosmosDB and emulator scenarios
- Service collection extensions for easy dependency injection setup
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
CosmosActorStateStorage.cs |
Core implementation of actor state storage using CosmosDB with document structure and transactional batch operations |
ServiceCollectionExtensions.cs |
DI configuration helpers for registering CosmosDB storage with various setup options |
| Test files | Comprehensive integration tests covering CRUD operations, concurrency, list operations, and edge cases |
| Sample integration | Example usage in HelloHttpApi sample showing how to integrate CosmosDB storage |
| Project files | Package references and solution structure updates |
...Microsoft.Extensions.AI.Agents.Runtime.Storage.CosmosDB.Tests/SkipOnEmulatorFactAttribute.cs
Outdated
Show resolved
Hide resolved
....Extensions.AI.Agents.Runtime.Storage.CosmosDB.Tests/CosmosActorStateStorageListKeysTests.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Extensions.AI.Agents.Runtime.Storage.CosmosDB/CosmosActorStateStorage.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Extensions.AI.Agents.Runtime.Storage.CosmosDB/CosmosActorStateStorage.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Extensions.AI.Agents.Runtime.Storage.CosmosDB/CosmosActorStateStorage.cs
Outdated
Show resolved
Hide resolved
93e26b4 to
43f02c9
Compare
43f02c9 to
870a911
Compare
stephentoub
reviewed
Jul 30, 2025
dotnet/src/Microsoft.Extensions.AI.Agents.Runtime.Storage.CosmosDB/CosmosActorStateStorage.cs
Outdated
Show resolved
Hide resolved
ReubenBond
reviewed
Jul 30, 2025
dotnet/src/Microsoft.Extensions.AI.Agents.Runtime.Storage.CosmosDB/LazyCosmosContainer.cs
Show resolved
Hide resolved
ReubenBond
reviewed
Jul 30, 2025
dotnet/src/Microsoft.Extensions.AI.Agents.Runtime.Storage.CosmosDB/LazyCosmosContainer.cs
Show resolved
Hide resolved
ReubenBond
reviewed
Jul 30, 2025
dotnet/src/Microsoft.Extensions.AI.Agents.Runtime.Storage.CosmosDB/CosmosActorStateStorage.cs
Outdated
Show resolved
Hide resolved
dead4c9 to
fc7937f
Compare
ReubenBond
pushed a commit
to ReubenBond/agent-framework
that referenced
this pull request
Oct 28, 2025
* Implement CosmosDB actor state storage. * Fix. * Minor fixes. * Fixes. * Make CosmosDB initialization be lazy. * Remove unnecessary read from write path. * Throw on empty writes. * Add arg validation for read. * Add CosmosIdSanitizer. * Fix. * Fix. * Simplify doc IDs. * Update comment. * fb * Make LazyCosmosContainer internal and add tests. * Make test constants public and remove IVT. * Use source generated JSON context for future nativeAOT support. * Re-add dropped comments.
Arturo-Quiroga-MSFT
pushed a commit
to Arturo-Quiroga-MSFT/agent-framework-public
that referenced
this pull request
Nov 23, 2025
* Implement CosmosDB actor state storage. * Fix. * Minor fixes. * Fixes. * Make CosmosDB initialization be lazy. * Remove unnecessary read from write path. * Throw on empty writes. * Add arg validation for read. * Add CosmosIdSanitizer. * Fix. * Fix. * Simplify doc IDs. * Update comment. * fb * Make LazyCosmosContainer internal and add tests. * Make test constants public and remove IVT. * Use source generated JSON context for future nativeAOT support. * Re-add dropped comments.
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.
This change adds an IActorStateStorage implementation that uses CosmosDB, and a set of tests for it that use Aspire and can run either using the real service or in the emulator.
I've just rebased everything onto current main (was previously based on a personal feature branch) and had to disable a few warnings to get things building and running. I suspect we'll be able to resolve some of those soon but I didn't want to delay getting this PR out.