Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Storage is a critical component of the Microsoft Agents SDK, enabling agents to persist conversation state, user data, and other information across sessions. It supports various storage options, including in-memory storage, Azure Cosmos DB, Azure Blobs Storage, and allows for custom storage providers.
Key storage options
Memory Storage
- Suitable for testing and development purposes.
- Data is cleared when the agent restarts, making it unsuitable for production.
- Data is only availble on the webapp instance, making it unsuitable when running in a cluster.
Azure Cosmos DB
- A globally distributed, multi-model database ideal for production agents.
- Supports partitioned storage for scalability and performance.
Azure Blob Storage
- Optimized for storing unstructured data like text or binary files.
- Commonly used for agent state and transcript storage.
Custom storage options can be provided by implementing
IStorage
Using different storage providers
Memory storage
All samples use MemoryStorage
For .NET, In Program.cs, register MemoryStorage
builder.Services.AddSingleton<IStorage, MemoryStorage>();
Azure CosmosDb storage
For .NET:
Add a package dependency for
Microsoft.Agents.Storage.CosmosDbIn Program.cs, add (or replace existing)
IStorageregistration with:builder.Services.AddSingleton<IStorage>(sp => { var options = new CosmosDbPartitionedStorageOptions() { CosmosDbEndpoint = "your-cosmosdb-endpoint", DatabaseId = "your-database-id", ContainerId = "your-container-id", // Get a TokenCredential from your defined Connections TokenCredential = sp.GetService<IConnections>().GetConnection("ServiceConnection").GetTokenCredential() }; return new CosmosDbPartitionedStorage(options); });For more details, see
CosmosDbPartitionedStorageOptions.
Azure blob storage
For .NET:
Add a package dependency for
Microsoft.Agents.Storage.BlobsIn Program.cs, add (or replace existing)
IStorageregistration with:builder.Services.AddSingleton<IStorage>(sp => { // Get a TokenCredential from your defined Connections var tokenCredential = sp.GetService<IConnections>().GetConnection("ServiceConnection").GetTokenCredential(); return new BlobsStorage( new Uri("{{your-blobs-storage-endpoint}}/agent-state"), tokenCredential); });