diff --git a/dotnet/src/Microsoft.Agents.AI.CosmosNoSql/CosmosDBChatExtensions.cs b/dotnet/src/Microsoft.Agents.AI.CosmosNoSql/CosmosDBChatExtensions.cs index 45c0d09536..061b64593c 100644 --- a/dotnet/src/Microsoft.Agents.AI.CosmosNoSql/CosmosDBChatExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.CosmosNoSql/CosmosDBChatExtensions.cs @@ -3,7 +3,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; -using Azure.Identity; +using Azure.Core; using Microsoft.Azure.Cosmos; namespace Microsoft.Agents.AI; @@ -47,8 +47,9 @@ public static ChatClientAgentOptions WithCosmosDBMessageStore( /// The Cosmos DB account endpoint URI. /// The identifier of the Cosmos DB database. /// The identifier of the Cosmos DB container. + /// The TokenCredential to use for authentication (e.g., DefaultAzureCredential, ManagedIdentityCredential). /// The configured . - /// Thrown when is null. + /// Thrown when or is null. /// Thrown when any string parameter is null or whitespace. [RequiresUnreferencedCode("The CosmosChatMessageStore uses JSON serialization which is incompatible with trimming.")] [RequiresDynamicCode("The CosmosChatMessageStore uses JSON serialization which is incompatible with NativeAOT.")] @@ -56,14 +57,20 @@ public static ChatClientAgentOptions WithCosmosDBMessageStoreUsingManagedIdentit this ChatClientAgentOptions options, string accountEndpoint, string databaseId, - string containerId) + string containerId, + TokenCredential tokenCredential) { if (options is null) { throw new ArgumentNullException(nameof(options)); } - options.ChatMessageStoreFactory = (context, ct) => new ValueTask(new CosmosChatMessageStore(accountEndpoint, new DefaultAzureCredential(), databaseId, containerId)); + if (tokenCredential is null) + { + throw new ArgumentNullException(nameof(tokenCredential)); + } + + options.ChatMessageStoreFactory = (context, ct) => new ValueTask(new CosmosChatMessageStore(accountEndpoint, tokenCredential, databaseId, containerId)); return options; } diff --git a/dotnet/src/Microsoft.Agents.AI.CosmosNoSql/CosmosDBWorkflowExtensions.cs b/dotnet/src/Microsoft.Agents.AI.CosmosNoSql/CosmosDBWorkflowExtensions.cs index 9d8bc52e68..4005808dbe 100644 --- a/dotnet/src/Microsoft.Agents.AI.CosmosNoSql/CosmosDBWorkflowExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.CosmosNoSql/CosmosDBWorkflowExtensions.cs @@ -2,7 +2,7 @@ using System; using System.Diagnostics.CodeAnalysis; -using Azure.Identity; +using Azure.Core; using Microsoft.Agents.AI.Workflows.Checkpointing; using Microsoft.Azure.Cosmos; @@ -52,14 +52,17 @@ public static CosmosCheckpointStore CreateCheckpointStore( /// The Cosmos DB account endpoint URI. /// The identifier of the Cosmos DB database. /// The identifier of the Cosmos DB container. + /// The TokenCredential to use for authentication (e.g., DefaultAzureCredential, ManagedIdentityCredential). /// A new instance of . /// Thrown when any string parameter is null or whitespace. + /// Thrown when is null. [RequiresUnreferencedCode("The CosmosCheckpointStore uses JSON serialization which is incompatible with trimming.")] [RequiresDynamicCode("The CosmosCheckpointStore uses JSON serialization which is incompatible with NativeAOT.")] public static CosmosCheckpointStore CreateCheckpointStoreUsingManagedIdentity( string accountEndpoint, string databaseId, - string containerId) + string containerId, + TokenCredential tokenCredential) { if (string.IsNullOrWhiteSpace(accountEndpoint)) { @@ -76,7 +79,12 @@ public static CosmosCheckpointStore CreateCheckpointStoreUsingManagedIdentity( throw new ArgumentException("Cannot be null or whitespace", nameof(containerId)); } - return new CosmosCheckpointStore(accountEndpoint, new DefaultAzureCredential(), databaseId, containerId); + if (tokenCredential is null) + { + throw new ArgumentNullException(nameof(tokenCredential)); + } + + return new CosmosCheckpointStore(accountEndpoint, tokenCredential, databaseId, containerId); } /// @@ -154,14 +162,17 @@ public static CosmosCheckpointStore CreateCheckpointStore( /// The Cosmos DB account endpoint URI. /// The identifier of the Cosmos DB database. /// The identifier of the Cosmos DB container. + /// The TokenCredential to use for authentication (e.g., DefaultAzureCredential, ManagedIdentityCredential). /// A new instance of . /// Thrown when any string parameter is null or whitespace. + /// Thrown when is null. [RequiresUnreferencedCode("The CosmosCheckpointStore uses JSON serialization which is incompatible with trimming.")] [RequiresDynamicCode("The CosmosCheckpointStore uses JSON serialization which is incompatible with NativeAOT.")] public static CosmosCheckpointStore CreateCheckpointStoreUsingManagedIdentity( string accountEndpoint, string databaseId, - string containerId) + string containerId, + TokenCredential tokenCredential) { if (string.IsNullOrWhiteSpace(accountEndpoint)) { @@ -178,7 +189,12 @@ public static CosmosCheckpointStore CreateCheckpointStoreUsingManagedIdentity throw new ArgumentException("Cannot be null or whitespace", nameof(containerId)); } - return new CosmosCheckpointStore(accountEndpoint, new DefaultAzureCredential(), databaseId, containerId); + if (tokenCredential is null) + { + throw new ArgumentNullException(nameof(tokenCredential)); + } + + return new CosmosCheckpointStore(accountEndpoint, tokenCredential, databaseId, containerId); } ///