From d09ac3b2866f7e78c1d9c5e5e391f73908d1a6cb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 10 Oct 2025 21:46:44 +0000 Subject: [PATCH 1/8] Initial plan From c36be12715d741826adba5cc3063a58264f91db5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 10 Oct 2025 22:01:45 +0000 Subject: [PATCH 2/8] Update Agent Step files to use OpenAIClient instead of AzureOpenAIClient Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --- .../Program.cs | 9 +++++---- .../Agents/Agent_Step01_Running/Program.cs | 9 +++++---- .../Agent_Step02_MultiturnConversation/Program.cs | 9 +++++---- .../Agent_Step03_UsingFunctionTools/Program.cs | 9 +++++---- .../Program.cs | 9 +++++---- .../Agent_Step05_StructuredOutput/Program.cs | 9 +++++---- .../Program.cs | 9 +++++---- .../Agent_Step07_3rdPartyThreadStorage/Program.cs | 9 +++++---- .../Agents/Agent_Step08_Observability/Program.cs | 7 +++++-- .../Agent_Step09_DependencyInjection/Program.cs | 9 +++++---- .../Agents/Agent_Step11_UsingImages/Program.cs | 7 +++++-- .../Agents/Agent_Step12_AsFunctionTool/Program.cs | 15 ++++++++------- .../Agents/Agent_Step13_Memory/Program.cs | 9 +++++---- .../Agents/Agent_Step14_Middleware/Program.cs | 7 +++++-- .../Agents/Agent_Step15_Plugins/Program.cs | 9 +++++---- .../Agents/Agent_Step16_ChatReduction/Program.cs | 9 +++++---- 16 files changed, 83 insertions(+), 61 deletions(-) diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIChatCompletion/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIChatCompletion/Program.cs index bd3135025..501b90a44 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIChatCompletion/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIChatCompletion/Program.cs @@ -2,7 +2,8 @@ // This sample shows how to create and use a simple AI agent with Azure OpenAI Chat Completion as the backend. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using OpenAI; @@ -10,9 +11,9 @@ var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; -AIAgent agent = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +AIAgent agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step01_Running/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step01_Running/Program.cs index c67756299..6fac777ec 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step01_Running/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step01_Running/Program.cs @@ -2,7 +2,8 @@ // This sample shows how to create and use a simple AI agent with Azure OpenAI as the backend. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using OpenAI; @@ -10,9 +11,9 @@ var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; -AIAgent agent = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +AIAgent agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs index 626a3e98c..b0856663a 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs @@ -2,7 +2,8 @@ // This sample shows how to create and use a simple AI agent with a multi-turn conversation. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using OpenAI; @@ -10,9 +11,9 @@ var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; -AIAgent agent = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +AIAgent agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step03_UsingFunctionTools/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step03_UsingFunctionTools/Program.cs index 48a6378e1..c8d841546 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step03_UsingFunctionTools/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step03_UsingFunctionTools/Program.cs @@ -3,8 +3,9 @@ // This sample demonstrates how to use a ChatClientAgent with function tools. // It shows both non-streaming and streaming agent interactions using menu-related tools. +using System.ClientModel; +using System.ClientModel.Primitives; using System.ComponentModel; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; @@ -18,9 +19,9 @@ static string GetWeather([Description("The location to get the weather for.")] s => $"The weather in {location} is cloudy with a high of 15°C."; // Create the chat client and agent, and provide the function tool to the agent. -AIAgent agent = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +AIAgent agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are a helpful assistant", tools: [AIFunctionFactory.Create(GetWeather)]); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs index 41ea8a5c9..fb28eabab 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs @@ -5,8 +5,9 @@ // If the agent is hosted in a service, with a remote user, combine this sample with the Persisted Conversations sample to persist the chat history // while the agent is waiting for user input. +using System.ClientModel; +using System.ClientModel.Primitives; using System.ComponentModel; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; @@ -22,9 +23,9 @@ static string GetWeather([Description("The location to get the weather for.")] s // Create the chat client and agent. // Note that we are wrapping the function tool with ApprovalRequiredAIFunction to require user approval before invoking it. -AIAgent agent = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +AIAgent agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are a helpful assistant", tools: [new ApprovalRequiredAIFunction(AIFunctionFactory.Create(GetWeather))]); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs index b18d8e2d8..e7d5faa24 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs @@ -2,10 +2,11 @@ // This sample shows how to configure ChatClientAgent to produce structured output. +using System.ClientModel; +using System.ClientModel.Primitives; using System.ComponentModel; using System.Text.Json; using System.Text.Json.Serialization; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; using OpenAI; @@ -16,9 +17,9 @@ var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; // Create chat client to be used by chat client agents. -ChatClient chatClient = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +ChatClient chatClient = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName); // Create the ChatClientAgent with the specified name and instructions. diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs index 1ffe3c999..94aa48592 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs @@ -2,8 +2,9 @@ // This sample shows how to create and use a simple AI agent with a conversation that can be persisted to disk. +using System.ClientModel; +using System.ClientModel.Primitives; using System.Text.Json; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; using OpenAI; @@ -12,9 +13,9 @@ var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; // Create the agent -AIAgent agent = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +AIAgent agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs index 898673497..e160e6507 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs @@ -4,8 +4,9 @@ // This sample shows how to create and use a simple AI agent with a conversation that can be persisted to disk. +using System.ClientModel; +using System.ClientModel.Primitives; using System.Text.Json; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; @@ -22,9 +23,9 @@ VectorStore vectorStore = new InMemoryVectorStore(); // Create the agent -AIAgent agent = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +AIAgent agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(new ChatClientAgentOptions { diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs index c48242f5c..8fc2724e2 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs @@ -2,7 +2,8 @@ // This sample shows how to create and use a simple AI agent with Azure OpenAI as the backend that logs telemetry using OpenTelemetry. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Azure.Monitor.OpenTelemetry.Exporter; using Microsoft.Agents.AI; @@ -27,7 +28,9 @@ using var tracerProvider = tracerProviderBuilder.Build(); // Create the agent, and enable OpenTelemetry instrumentation. -AIAgent agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) +AIAgent agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker") .AsBuilder() diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs index 894c034eb..25966d2c7 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs @@ -4,7 +4,8 @@ // This sample shows how to use dependency injection to register an AIAgent and use it from a hosted service with a user input chat loop. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; @@ -22,9 +23,9 @@ new ChatClientAgentOptions(instructions: "You are good at telling jokes.", name: "Joker")); // Add a chat client to the service collection. -builder.Services.AddKeyedChatClient("AzureOpenAI", (sp) => new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +builder.Services.AddKeyedChatClient("AzureOpenAI", (sp) => new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .AsIChatClient()); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs index 8e8c5701a..8b74ab679 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs @@ -2,7 +2,8 @@ // This sample shows how to use Image Multi-Modality with an AI agent. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Extensions.AI; using OpenAI; @@ -10,7 +11,9 @@ var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = System.Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o"; -var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) +var agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent( name: "VisionAgent", diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step12_AsFunctionTool/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step12_AsFunctionTool/Program.cs index cce53ef3c..ebd17d9fc 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step12_AsFunctionTool/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step12_AsFunctionTool/Program.cs @@ -2,8 +2,9 @@ // This sample shows how to create and use a Azure OpenAI AI agent as a function tool. +using System.ClientModel; +using System.ClientModel.Primitives; using System.ComponentModel; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; @@ -17,9 +18,9 @@ static string GetWeather([Description("The location to get the weather for.")] s => $"The weather in {location} is cloudy with a high of 15°C."; // Create the chat client and agent, and provide the function tool to the agent. -AIAgent weatherAgent = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +AIAgent weatherAgent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent( instructions: "You answer questions about the weather.", @@ -28,9 +29,9 @@ static string GetWeather([Description("The location to get the weather for.")] s tools: [AIFunctionFactory.Create(GetWeather)]); // Create the main agent, and provide the weather agent as a function tool. -AIAgent agent = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +AIAgent agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are a helpful assistant who responds in French.", tools: [weatherAgent.AsAIFunction()]); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step13_Memory/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step13_Memory/Program.cs index ad59deb97..bf2d2bf61 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step13_Memory/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step13_Memory/Program.cs @@ -6,9 +6,10 @@ // The component adds a prompt to ask for this information if it is not already known // and provides it to the model before each invocation if known. +using System.ClientModel; +using System.ClientModel.Primitives; using System.Text; using System.Text.Json; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; @@ -19,9 +20,9 @@ var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; -ChatClient chatClient = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +ChatClient chatClient = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName); // Create the agent and provide a factory to add our custom memory component to diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs index ea59c84ba..ea106cb1b 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs @@ -5,9 +5,10 @@ // function invocation (logging and result overrides), and human-in-the-loop // approval workflows for sensitive function calls. +using System.ClientModel; +using System.ClientModel.Primitives; using System.ComponentModel; using System.Text.RegularExpressions; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.ChatClient; @@ -18,7 +19,9 @@ var deploymentName = System.Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o"; // Get a client to create/retrieve server side agents with -var azureOpenAIClient = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) +var azureOpenAIClient = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName); [Description("Get the weather for a given location.")] diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step15_Plugins/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step15_Plugins/Program.cs index 7284efcc4..6d6402979 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step15_Plugins/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step15_Plugins/Program.cs @@ -9,7 +9,8 @@ // as AI functions. The AsAITools method of the plugin class shows how to specify // which methods should be exposed to the AI agent. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; @@ -27,9 +28,9 @@ IServiceProvider serviceProvider = services.BuildServiceProvider(); -AIAgent agent = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +AIAgent agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent( instructions: "You are a helpful assistant that helps people find information.", diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs index 590b5308d..ed439793b 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs @@ -5,7 +5,8 @@ // NOTE: this feature is only supported where the chat history is stored locally, such as with OpenAI Chat Completion. // Where the chat history is stored server side, such as with Azure Foundry Agents, the service must manage the chat history size. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; @@ -15,9 +16,9 @@ var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; // Construct the agent, and provide a factory to create an in-memory chat message store with a reducer that keeps only the last 2 non-system messages. -AIAgent agent = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +AIAgent agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(new ChatClientAgentOptions { From c49e13b414833c8ff721a854faae2a062c5b1ca0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 10 Oct 2025 22:08:02 +0000 Subject: [PATCH 3/8] Update remaining workflow and agent provider files to use OpenAIClient Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --- .../GettingStarted/AgentOpenTelemetry/Program.cs | 10 +++++++--- .../Agent_With_AzureOpenAIResponses/Program.cs | 9 +++++---- .../Workflows/Agents/CustomAgentExecutors/Program.cs | 8 ++++++-- .../Workflows/Agents/WorkflowAsAnAgent/Program.cs | 8 ++++++-- .../Workflows/Concurrent/Concurrent/Program.cs | 8 ++++++-- .../ConditionalEdges/01_EdgeCondition/Program.cs | 8 ++++++-- .../ConditionalEdges/02_SwitchCase/Program.cs | 8 ++++++-- .../ConditionalEdges/03_MultiSelection/Program.cs | 8 ++++++-- .../_Foundational/03_AgentsInWorkflows/Program.cs | 8 ++++++-- .../_Foundational/04_AgentWorkflowPatterns/Program.cs | 8 ++++++-- 10 files changed, 60 insertions(+), 23 deletions(-) diff --git a/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs b/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs index 5edfcf53d..8537388f1 100644 --- a/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs +++ b/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs @@ -1,15 +1,17 @@ // Copyright (c) Microsoft. All rights reserved. +using System.ClientModel; +using System.ClientModel.Primitives; using System.ComponentModel; using System.Diagnostics; -using System.Diagnostics.Metrics; -using Azure.AI.OpenAI; +using System.Diagnostics.Meters; using Azure.Identity; using Azure.Monitor.OpenTelemetry.Exporter; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using OpenAI; using OpenTelemetry; using OpenTelemetry.Logs; using OpenTelemetry.Metrics; @@ -110,7 +112,9 @@ static async Task GetWeatherAsync([Description("The location to get the return $"The weather in {location} is cloudy with a high of 15°C."; } -using var instrumentedChatClient = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) +using var instrumentedChatClient = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .AsIChatClient() // Converts a native OpenAI SDK ChatClient into a Microsoft.Extensions.AI.IChatClient .AsBuilder() diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIResponses/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIResponses/Program.cs index 6d162ebfd..8239298bb 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIResponses/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIResponses/Program.cs @@ -2,7 +2,8 @@ // This sample shows how to create and use a simple AI agent with Azure OpenAI Responses as the backend. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using OpenAI; @@ -10,9 +11,9 @@ var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; -AIAgent agent = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +AIAgent agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName) .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); diff --git a/dotnet/samples/GettingStarted/Workflows/Agents/CustomAgentExecutors/Program.cs b/dotnet/samples/GettingStarted/Workflows/Agents/CustomAgentExecutors/Program.cs index 437453a86..0004bfa83 100644 --- a/dotnet/samples/GettingStarted/Workflows/Agents/CustomAgentExecutors/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/Agents/CustomAgentExecutors/Program.cs @@ -1,13 +1,15 @@ // Copyright (c) Microsoft. All rights reserved. +using System.ClientModel; +using System.ClientModel.Primitives; using System.Text.Json; using System.Text.Json.Serialization; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Workflows; using Microsoft.Agents.AI.Workflows.Reflection; using Microsoft.Extensions.AI; +using OpenAI; namespace WorkflowCustomAgentExecutorsSample; @@ -35,7 +37,9 @@ private static async Task Main() // Set up the Azure OpenAI client var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; - var chatClient = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()).GetChatClient(deploymentName).AsIChatClient(); + var chatClient = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); // Create the executors var sloganWriter = new SloganWriterExecutor("SloganWriter", chatClient); diff --git a/dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/Program.cs b/dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/Program.cs index 49305d990..b400589d3 100644 --- a/dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/Program.cs @@ -1,10 +1,12 @@ // Copyright (c) Microsoft. All rights reserved. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Workflows; using Microsoft.Extensions.AI; +using OpenAI; namespace WorkflowAsAnAgentsSample; @@ -32,7 +34,9 @@ private static async Task Main() // Set up the Azure OpenAI client var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; - var chatClient = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()).GetChatClient(deploymentName).AsIChatClient(); + var chatClient = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); // Create the workflow and turn it into an agent var workflow = await WorkflowHelper.GetWorkflowAsync(chatClient).ConfigureAwait(false); diff --git a/dotnet/samples/GettingStarted/Workflows/Concurrent/Concurrent/Program.cs b/dotnet/samples/GettingStarted/Workflows/Concurrent/Concurrent/Program.cs index 44d0f0fe7..577fc905d 100644 --- a/dotnet/samples/GettingStarted/Workflows/Concurrent/Concurrent/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/Concurrent/Concurrent/Program.cs @@ -1,11 +1,13 @@ // Copyright (c) Microsoft. All rights reserved. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Workflows; using Microsoft.Agents.AI.Workflows.Reflection; using Microsoft.Extensions.AI; +using OpenAI; namespace WorkflowConcurrentSample; @@ -35,7 +37,9 @@ private static async Task Main() // Set up the Azure OpenAI client var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; - var chatClient = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()).GetChatClient(deploymentName).AsIChatClient(); + var chatClient = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); // Create the executors ChatClientAgent physicist = new( diff --git a/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/01_EdgeCondition/Program.cs b/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/01_EdgeCondition/Program.cs index 6298337d7..e36e49040 100644 --- a/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/01_EdgeCondition/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/01_EdgeCondition/Program.cs @@ -1,13 +1,15 @@ // Copyright (c) Microsoft. All rights reserved. +using System.ClientModel; +using System.ClientModel.Primitives; using System.Text.Json; using System.Text.Json.Serialization; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Workflows; using Microsoft.Agents.AI.Workflows.Reflection; using Microsoft.Extensions.AI; +using OpenAI; namespace WorkflowEdgeConditionSample; @@ -38,7 +40,9 @@ private static async Task Main() // Set up the Azure OpenAI client var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; - var chatClient = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()).GetChatClient(deploymentName).AsIChatClient(); + var chatClient = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); // Create agents AIAgent spamDetectionAgent = GetSpamDetectionAgent(chatClient); diff --git a/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/02_SwitchCase/Program.cs b/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/02_SwitchCase/Program.cs index 17de5311c..30cb327d3 100644 --- a/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/02_SwitchCase/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/02_SwitchCase/Program.cs @@ -1,13 +1,15 @@ // Copyright (c) Microsoft. All rights reserved. +using System.ClientModel; +using System.ClientModel.Primitives; using System.Text.Json; using System.Text.Json.Serialization; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Workflows; using Microsoft.Agents.AI.Workflows.Reflection; using Microsoft.Extensions.AI; +using OpenAI; namespace WorkflowSwitchCaseSample; @@ -39,7 +41,9 @@ private static async Task Main() // Set up the Azure OpenAI client var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; - var chatClient = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()).GetChatClient(deploymentName).AsIChatClient(); + var chatClient = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); // Create agents AIAgent spamDetectionAgent = GetSpamDetectionAgent(chatClient); diff --git a/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/03_MultiSelection/Program.cs b/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/03_MultiSelection/Program.cs index cb3914fa6..5ffaa9175 100644 --- a/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/03_MultiSelection/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/03_MultiSelection/Program.cs @@ -1,13 +1,15 @@ // Copyright (c) Microsoft. All rights reserved. +using System.ClientModel; +using System.ClientModel.Primitives; using System.Text.Json; using System.Text.Json.Serialization; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Workflows; using Microsoft.Agents.AI.Workflows.Reflection; using Microsoft.Extensions.AI; +using OpenAI; namespace WorkflowMultiSelectionSample; @@ -41,7 +43,9 @@ private static async Task Main() // Set up the Azure OpenAI client var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; - var chatClient = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()).GetChatClient(deploymentName).AsIChatClient(); + var chatClient = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); // Create agents AIAgent emailAnalysisAgent = GetEmailAnalysisAgent(chatClient); diff --git a/dotnet/samples/GettingStarted/Workflows/_Foundational/03_AgentsInWorkflows/Program.cs b/dotnet/samples/GettingStarted/Workflows/_Foundational/03_AgentsInWorkflows/Program.cs index 2b30f3f5a..2f31b6b2d 100644 --- a/dotnet/samples/GettingStarted/Workflows/_Foundational/03_AgentsInWorkflows/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/_Foundational/03_AgentsInWorkflows/Program.cs @@ -1,10 +1,12 @@ // Copyright (c) Microsoft. All rights reserved. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Workflows; using Microsoft.Extensions.AI; +using OpenAI; namespace WorkflowAgentsInWorkflowsSample; @@ -30,7 +32,9 @@ private static async Task Main() // Set up the Azure OpenAI client var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; - var chatClient = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()).GetChatClient(deploymentName).AsIChatClient(); + var chatClient = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); // Create agents AIAgent frenchAgent = GetTranslationAgent("French", chatClient); diff --git a/dotnet/samples/GettingStarted/Workflows/_Foundational/04_AgentWorkflowPatterns/Program.cs b/dotnet/samples/GettingStarted/Workflows/_Foundational/04_AgentWorkflowPatterns/Program.cs index aeb06cfb6..d83e1e31d 100644 --- a/dotnet/samples/GettingStarted/Workflows/_Foundational/04_AgentWorkflowPatterns/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/_Foundational/04_AgentWorkflowPatterns/Program.cs @@ -1,11 +1,13 @@ // Copyright (c) Microsoft. All rights reserved. +using System.ClientModel; +using System.ClientModel.Primitives; using System.Text.Json; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Workflows; using Microsoft.Extensions.AI; +using OpenAI; namespace WorkflowAgentsInWorkflowsSample; @@ -25,7 +27,9 @@ private static async Task Main() // Set up the Azure OpenAI client. var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; - var client = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()).GetChatClient(deploymentName).AsIChatClient(); + var client = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); Console.Write("Choose workflow type ('sequential', 'concurrent', 'handoffs', 'groupchat'): "); switch (Console.ReadLine()) From 164e5900ea0dd85120db72bf4c824dee0297beb7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 10 Oct 2025 22:17:01 +0000 Subject: [PATCH 4/8] Complete migration from AzureOpenAIClient to OpenAIClient for all non-Assistants files Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --- .../ModelContextProtocol/Agent_MCP_Server/Program.cs | 9 +++++---- .../Agent_MCP_Server_Auth/Program.cs | 9 +++++---- .../AgentOrchestrations/Step01_Concurrent/Program.cs | 8 ++++++-- .../AgentOrchestrations/Step02_Sequential/Program.cs | 8 ++++++-- .../AgentOrchestrations/Step03_Handoff/Program.cs | 8 ++++++-- .../AzureOpenAI/Step01_Basics/Program.cs | 7 +++++-- .../AzureOpenAI/Step02_ToolCall/Program.cs | 7 +++++-- .../AzureOpenAI/Step03_DependencyInjection/Program.cs | 7 +++++-- .../AzureOpenAIResponses/Step01_Basics/Program.cs | 11 ++++++++--- .../Step02_ReasoningModel/Program.cs | 11 ++++++++--- .../AzureOpenAIResponses/Step03_ToolCall/Program.cs | 11 ++++++++--- .../Step04_DependencyInjection/Program.cs | 11 ++++++++--- 12 files changed, 75 insertions(+), 32 deletions(-) diff --git a/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server/Program.cs b/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server/Program.cs index 1a0d23696..c40c51516 100644 --- a/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server/Program.cs +++ b/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server/Program.cs @@ -2,7 +2,8 @@ // This sample shows how to create and use a simple AI agent with tools from an MCP Server. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; @@ -23,9 +24,9 @@ // Retrieve the list of tools available on the GitHub server var mcpTools = await mcpClient.ListToolsAsync().ConfigureAwait(false); -AIAgent agent = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +AIAgent agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You answer questions related to GitHub repositories only.", tools: [.. mcpTools.Cast()]); diff --git a/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server_Auth/Program.cs b/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server_Auth/Program.cs index aae520eec..d27a4a83b 100644 --- a/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server_Auth/Program.cs +++ b/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server_Auth/Program.cs @@ -2,11 +2,12 @@ // This sample shows how to create and use a simple AI agent with tools from an MCP Server that requires authentication. +using System.ClientModel; +using System.ClientModel.Primitives; using System.Diagnostics; using System.Net; using System.Text; using System.Web; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Extensions.Logging; @@ -46,9 +47,9 @@ // Retrieve the list of tools available on the GitHub server var mcpTools = await mcpClient.ListToolsAsync().ConfigureAwait(false); -AIAgent agent = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) +AIAgent agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You answer questions related to the weather.", tools: [.. mcpTools]); diff --git a/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step01_Concurrent/Program.cs b/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step01_Concurrent/Program.cs index ac6c27643..af262cc50 100644 --- a/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step01_Concurrent/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step01_Concurrent/Program.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Workflows; @@ -10,6 +11,7 @@ using Microsoft.SemanticKernel.Agents.Orchestration; using Microsoft.SemanticKernel.Agents.Orchestration.Concurrent; using Microsoft.SemanticKernel.Agents.Runtime.InProcess; +using OpenAI; var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; @@ -74,7 +76,9 @@ ValueTask StreamingResultCallback(StreamingChatMessageContent streamedResponse, # region AFConcurrentAgentWorkflow async Task AFConcurrentAgentWorkflow() { - var client = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()).GetChatClient(deploymentName).AsIChatClient(); + var client = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); var frenchAgent = GetAFTranslationAgent("French", client); var spanishAgent = GetAFTranslationAgent("Spanish", client); var concurrentAgentWorkflow = AgentWorkflowBuilder.BuildConcurrent([frenchAgent, spanishAgent]); diff --git a/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step02_Sequential/Program.cs b/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step02_Sequential/Program.cs index e317ac0ff..4420995fc 100644 --- a/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step02_Sequential/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step02_Sequential/Program.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Workflows; @@ -10,6 +11,7 @@ using Microsoft.SemanticKernel.Agents.Orchestration; using Microsoft.SemanticKernel.Agents.Orchestration.Sequential; using Microsoft.SemanticKernel.Agents.Runtime.InProcess; +using OpenAI; var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; @@ -75,7 +77,9 @@ ValueTask StreamingResultCallback(StreamingChatMessageContent streamedResponse, # region AFSequentialAgentWorkflow async Task AFSequentialAgentWorkflow() { - var client = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()).GetChatClient(deploymentName).AsIChatClient(); + var client = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); var frenchAgent = GetAFTranslationAgent("French", client); var spanishAgent = GetAFTranslationAgent("Spanish", client); var englishAgent = GetAFTranslationAgent("English", client); diff --git a/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step03_Handoff/Program.cs b/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step03_Handoff/Program.cs index f66fefe53..1b0c27fc2 100644 --- a/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step03_Handoff/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step03_Handoff/Program.cs @@ -1,8 +1,9 @@ // Copyright (c) Microsoft. All rights reserved. +using System.ClientModel; +using System.ClientModel.Primitives; using System.ComponentModel; using System.Text.Json; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Workflows; @@ -13,6 +14,7 @@ using Microsoft.SemanticKernel.Agents.Orchestration.Handoff; using Microsoft.SemanticKernel.Agents.Runtime.InProcess; using Microsoft.SemanticKernel.ChatCompletion; +using OpenAI; var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; @@ -170,7 +172,9 @@ static string AFProcessRefund([Description("The order ID to process the refund f async Task AFHandoffAgentWorkflow() { // Create agents - var client = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()).GetChatClient(deploymentName).AsIChatClient(); + var client = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); ChatClientAgent triageAgent = new(client, instructions: "A customer support agent that triages issues.", diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step01_Basics/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step01_Basics/Program.cs index 527f813be..3c0f2ca4b 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step01_Basics/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step01_Basics/Program.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.SemanticKernel; @@ -50,7 +51,9 @@ async Task AFAgent() { Console.WriteLine("\n=== AF Agent ===\n"); - var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()).GetChatClient(deploymentName) + var agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName) .CreateAIAgent(name: "Joker", instructions: "You are good at telling jokes."); var thread = agent.GetNewThread(); diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step02_ToolCall/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step02_ToolCall/Program.cs index 56ca87973..fd995e02b 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step02_ToolCall/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step02_ToolCall/Program.cs @@ -1,7 +1,8 @@ // Copyright (c) Microsoft. All rights reserved. +using System.ClientModel; +using System.ClientModel.Primitives; using System.ComponentModel; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Extensions.AI; using Microsoft.SemanticKernel; @@ -44,7 +45,9 @@ async Task SKAgent() async Task AFAgent() { - var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()).GetChatClient(deploymentName) + var agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are a helpful assistant", tools: [AIFunctionFactory.Create(GetWeather)]); Console.WriteLine("\n=== AF Agent Response ===\n"); diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step03_DependencyInjection/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step03_DependencyInjection/Program.cs index caf166674..d02c98ced 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step03_DependencyInjection/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step03_DependencyInjection/Program.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; @@ -43,7 +44,9 @@ async Task AFAgent() Console.WriteLine("\n=== AF Agent ===\n"); var serviceCollection = new ServiceCollection(); - serviceCollection.AddTransient((sp) => new AzureOpenAIClient(new(endpoint), new AzureCliCredential()) + serviceCollection.AddTransient((sp) => new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(name: "Joker", instructions: "You are good at telling jokes.")); diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step01_Basics/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step01_Basics/Program.cs index 22a17887e..013189530 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step01_Basics/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step01_Basics/Program.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.SemanticKernel.Agents.OpenAI; @@ -19,7 +20,9 @@ async Task SKAgentAsync() { Console.WriteLine("\n=== SK Agent ===\n"); - var responseClient = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) + var responseClient = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName); OpenAIResponseAgent agent = new(responseClient) { @@ -49,7 +52,9 @@ async Task AFAgentAsync() { Console.WriteLine("\n=== AF Agent ===\n"); - var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) + var agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName) .CreateAIAgent(name: "Joker", instructions: "You are good at telling jokes."); diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step02_ReasoningModel/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step02_ReasoningModel/Program.cs index 8ee5ae89b..72322a7e9 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step02_ReasoningModel/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step02_ReasoningModel/Program.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; @@ -46,7 +47,9 @@ async Task SKAgentAsync() { Console.WriteLine("\n=== SK Agent ===\n"); - var responseClient = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) + var responseClient = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName); OpenAIResponseAgent agent = new(responseClient) { @@ -114,7 +117,9 @@ async Task AFAgentAsync() { Console.WriteLine("\n=== AF Agent ===\n"); - var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) + var agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName) .CreateAIAgent(name: "Thinker", instructions: "You are good at thinking hard before answering."); diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step03_ToolCall/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step03_ToolCall/Program.cs index 12bb3b46b..03cce8bb2 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step03_ToolCall/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step03_ToolCall/Program.cs @@ -1,7 +1,8 @@ // Copyright (c) Microsoft. All rights reserved. +using System.ClientModel; +using System.ClientModel.Primitives; using System.ComponentModel; -using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Extensions.AI; using Microsoft.SemanticKernel; @@ -24,7 +25,9 @@ static string GetWeather([Description("The location to get the weather for.")] s async Task SKAgentAsync() { - OpenAIResponseAgent agent = new(new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) + OpenAIResponseAgent agent = new(new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName)); // Initialize plugin and add to the agent's Kernel (same as direct Kernel usage). @@ -43,7 +46,9 @@ async Task SKAgentAsync() async Task AFAgentAsync() { - var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) + var agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName) .CreateAIAgent(instructions: "You are a helpful assistant", tools: [AIFunctionFactory.Create(GetWeather)]); diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step04_DependencyInjection/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step04_DependencyInjection/Program.cs index e2bef86a7..e2211ebe2 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step04_DependencyInjection/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step04_DependencyInjection/Program.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. -using Azure.AI.OpenAI; +using System.ClientModel; +using System.ClientModel.Primitives; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; @@ -23,7 +24,9 @@ async Task SKAgentAsync() var serviceCollection = new ServiceCollection(); serviceCollection.AddTransient((sp) - => new OpenAIResponseAgent(new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) + => new OpenAIResponseAgent(new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName)) { Name = "Joker", @@ -42,7 +45,9 @@ async Task AFAgentAsync() Console.WriteLine("\n=== AF Agent ===\n"); var serviceCollection = new ServiceCollection(); - serviceCollection.AddTransient((sp) => new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) + serviceCollection.AddTransient((sp) => new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName) .CreateAIAgent(name: "Joker", instructions: "You are good at telling jokes.")); From d05af26d5c41ceb55b0b5b5dd642b594bf945004 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 10 Oct 2025 22:18:29 +0000 Subject: [PATCH 5/8] Fix missing OpenAI using statement in Agent_Step14_Middleware Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --- .../GettingStarted/Agents/Agent_Step14_Middleware/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs index ea106cb1b..951f92acf 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs @@ -13,6 +13,7 @@ using Microsoft.Agents.AI; using Microsoft.Agents.AI.ChatClient; using Microsoft.Extensions.AI; +using OpenAI; // Get Azure AI Foundry configuration from environment variables var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); From e81b48f3db9a046385278ca061ece8fdc716235d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 10 Oct 2025 22:29:10 +0000 Subject: [PATCH 6/8] Fix build errors: correct using statements in AgentOpenTelemetry and Agent_Step09_DependencyInjection Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --- dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs | 2 +- .../Agents/Agent_Step09_DependencyInjection/Program.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs b/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs index 8537388f1..a782bc690 100644 --- a/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs +++ b/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs @@ -4,7 +4,7 @@ using System.ClientModel.Primitives; using System.ComponentModel; using System.Diagnostics; -using System.Diagnostics.Meters; +using System.Diagnostics.Metrics; using Azure.Identity; using Azure.Monitor.OpenTelemetry.Exporter; using Microsoft.Agents.AI; diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs index 25966d2c7..958dd51b9 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs @@ -11,6 +11,7 @@ using Microsoft.Extensions.AI; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using OpenAI; var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; From 67c21ece4a58fe9166e41c0c2912562897447097 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 11 Oct 2025 13:29:26 +0000 Subject: [PATCH 7/8] Remove unnecessary using directive from AgentOpenTelemetry Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --- dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs b/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs index a782bc690..e22a9cc11 100644 --- a/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs +++ b/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs @@ -1,6 +1,5 @@ // Copyright (c) Microsoft. All rights reserved. -using System.ClientModel; using System.ClientModel.Primitives; using System.ComponentModel; using System.Diagnostics; From 15a59aa1fbd923f364de71e017d38e0944e7fef1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 11 Oct 2025 13:33:55 +0000 Subject: [PATCH 8/8] Replace cognitiveservices scope with ai.azure.com scope across all samples Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --- dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs | 2 +- .../Agent_With_AzureOpenAIChatCompletion/Program.cs | 2 +- .../AgentProviders/Agent_With_AzureOpenAIResponses/Program.cs | 2 +- .../GettingStarted/Agents/Agent_Step01_Running/Program.cs | 2 +- .../Agents/Agent_Step02_MultiturnConversation/Program.cs | 2 +- .../Agents/Agent_Step03_UsingFunctionTools/Program.cs | 2 +- .../Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs | 2 +- .../Agents/Agent_Step05_StructuredOutput/Program.cs | 2 +- .../Agents/Agent_Step06_PersistedConversations/Program.cs | 2 +- .../Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs | 2 +- .../Agents/Agent_Step08_Observability/Program.cs | 2 +- .../Agents/Agent_Step09_DependencyInjection/Program.cs | 2 +- .../GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs | 2 +- .../Agents/Agent_Step12_AsFunctionTool/Program.cs | 4 ++-- .../GettingStarted/Agents/Agent_Step13_Memory/Program.cs | 2 +- .../GettingStarted/Agents/Agent_Step14_Middleware/Program.cs | 2 +- .../GettingStarted/Agents/Agent_Step15_Plugins/Program.cs | 2 +- .../Agents/Agent_Step16_ChatReduction/Program.cs | 2 +- .../ModelContextProtocol/Agent_MCP_Server/Program.cs | 2 +- .../ModelContextProtocol/Agent_MCP_Server_Auth/Program.cs | 2 +- .../Workflows/Agents/CustomAgentExecutors/Program.cs | 2 +- .../Workflows/Agents/WorkflowAsAnAgent/Program.cs | 2 +- .../GettingStarted/Workflows/Concurrent/Concurrent/Program.cs | 2 +- .../Workflows/ConditionalEdges/01_EdgeCondition/Program.cs | 2 +- .../Workflows/ConditionalEdges/02_SwitchCase/Program.cs | 2 +- .../Workflows/ConditionalEdges/03_MultiSelection/Program.cs | 2 +- .../Workflows/_Foundational/03_AgentsInWorkflows/Program.cs | 2 +- .../_Foundational/04_AgentWorkflowPatterns/Program.cs | 2 +- .../AgentOrchestrations/Step01_Concurrent/Program.cs | 2 +- .../AgentOrchestrations/Step02_Sequential/Program.cs | 2 +- .../AgentOrchestrations/Step03_Handoff/Program.cs | 2 +- .../AzureOpenAI/Step01_Basics/Program.cs | 2 +- .../AzureOpenAI/Step02_ToolCall/Program.cs | 2 +- .../AzureOpenAI/Step03_DependencyInjection/Program.cs | 2 +- .../AzureOpenAIResponses/Step01_Basics/Program.cs | 4 ++-- .../AzureOpenAIResponses/Step02_ReasoningModel/Program.cs | 4 ++-- .../AzureOpenAIResponses/Step03_ToolCall/Program.cs | 4 ++-- .../Step04_DependencyInjection/Program.cs | 4 ++-- 38 files changed, 43 insertions(+), 43 deletions(-) diff --git a/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs b/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs index e22a9cc11..285e78b5f 100644 --- a/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs +++ b/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs @@ -112,7 +112,7 @@ static async Task GetWeatherAsync([Description("The location to get the } using var instrumentedChatClient = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .AsIChatClient() // Converts a native OpenAI SDK ChatClient into a Microsoft.Extensions.AI.IChatClient diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIChatCompletion/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIChatCompletion/Program.cs index 501b90a44..d09efb60f 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIChatCompletion/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIChatCompletion/Program.cs @@ -12,7 +12,7 @@ var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; AIAgent agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIResponses/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIResponses/Program.cs index 8239298bb..e34a9de73 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIResponses/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIResponses/Program.cs @@ -12,7 +12,7 @@ var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; AIAgent agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName) .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step01_Running/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step01_Running/Program.cs index 6fac777ec..75754f51f 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step01_Running/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step01_Running/Program.cs @@ -12,7 +12,7 @@ var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; AIAgent agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs index b0856663a..e35f2f621 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs @@ -12,7 +12,7 @@ var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; AIAgent agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step03_UsingFunctionTools/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step03_UsingFunctionTools/Program.cs index c8d841546..f62be9f9d 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step03_UsingFunctionTools/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step03_UsingFunctionTools/Program.cs @@ -20,7 +20,7 @@ static string GetWeather([Description("The location to get the weather for.")] s // Create the chat client and agent, and provide the function tool to the agent. AIAgent agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are a helpful assistant", tools: [AIFunctionFactory.Create(GetWeather)]); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs index fb28eabab..a4a523c2f 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs @@ -24,7 +24,7 @@ static string GetWeather([Description("The location to get the weather for.")] s // Create the chat client and agent. // Note that we are wrapping the function tool with ApprovalRequiredAIFunction to require user approval before invoking it. AIAgent agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are a helpful assistant", tools: [new ApprovalRequiredAIFunction(AIFunctionFactory.Create(GetWeather))]); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs index e7d5faa24..a9247950d 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs @@ -18,7 +18,7 @@ // Create chat client to be used by chat client agents. ChatClient chatClient = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs index 94aa48592..3bf2d6949 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs @@ -14,7 +14,7 @@ // Create the agent AIAgent agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs index e160e6507..780ab7b38 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs @@ -24,7 +24,7 @@ // Create the agent AIAgent agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(new ChatClientAgentOptions diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs index 8fc2724e2..53a5cdd03 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs @@ -29,7 +29,7 @@ // Create the agent, and enable OpenTelemetry instrumentation. AIAgent agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker") diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs index 958dd51b9..ff1f4fe4e 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs @@ -25,7 +25,7 @@ // Add a chat client to the service collection. builder.Services.AddKeyedChatClient("AzureOpenAI", (sp) => new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .AsIChatClient()); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs index 8b74ab679..3bb1b846d 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs @@ -12,7 +12,7 @@ var deploymentName = System.Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o"; var agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent( diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step12_AsFunctionTool/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step12_AsFunctionTool/Program.cs index ebd17d9fc..22d7f3ba0 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step12_AsFunctionTool/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step12_AsFunctionTool/Program.cs @@ -19,7 +19,7 @@ static string GetWeather([Description("The location to get the weather for.")] s // Create the chat client and agent, and provide the function tool to the agent. AIAgent weatherAgent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent( @@ -30,7 +30,7 @@ static string GetWeather([Description("The location to get the weather for.")] s // Create the main agent, and provide the weather agent as a function tool. AIAgent agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are a helpful assistant who responds in French.", tools: [weatherAgent.AsAIFunction()]); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step13_Memory/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step13_Memory/Program.cs index bf2d2bf61..b299a1bbd 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step13_Memory/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step13_Memory/Program.cs @@ -21,7 +21,7 @@ var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; ChatClient chatClient = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs index 951f92acf..5773736fb 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs @@ -21,7 +21,7 @@ // Get a client to create/retrieve server side agents with var azureOpenAIClient = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step15_Plugins/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step15_Plugins/Program.cs index 6d6402979..1000a7b99 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step15_Plugins/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step15_Plugins/Program.cs @@ -29,7 +29,7 @@ IServiceProvider serviceProvider = services.BuildServiceProvider(); AIAgent agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent( diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs index ed439793b..d89d25ac7 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs @@ -17,7 +17,7 @@ // Construct the agent, and provide a factory to create an in-memory chat message store with a reducer that keeps only the last 2 non-system messages. AIAgent agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(new ChatClientAgentOptions diff --git a/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server/Program.cs b/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server/Program.cs index c40c51516..05e1f153e 100644 --- a/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server/Program.cs +++ b/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server/Program.cs @@ -25,7 +25,7 @@ var mcpTools = await mcpClient.ListToolsAsync().ConfigureAwait(false); AIAgent agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You answer questions related to GitHub repositories only.", tools: [.. mcpTools.Cast()]); diff --git a/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server_Auth/Program.cs b/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server_Auth/Program.cs index d27a4a83b..32864f3fe 100644 --- a/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server_Auth/Program.cs +++ b/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server_Auth/Program.cs @@ -48,7 +48,7 @@ var mcpTools = await mcpClient.ListToolsAsync().ConfigureAwait(false); AIAgent agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(instructions: "You answer questions related to the weather.", tools: [.. mcpTools]); diff --git a/dotnet/samples/GettingStarted/Workflows/Agents/CustomAgentExecutors/Program.cs b/dotnet/samples/GettingStarted/Workflows/Agents/CustomAgentExecutors/Program.cs index 0004bfa83..95a18063a 100644 --- a/dotnet/samples/GettingStarted/Workflows/Agents/CustomAgentExecutors/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/Agents/CustomAgentExecutors/Program.cs @@ -38,7 +38,7 @@ private static async Task Main() var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; var chatClient = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); // Create the executors diff --git a/dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/Program.cs b/dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/Program.cs index b400589d3..dd1619e88 100644 --- a/dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/Program.cs @@ -35,7 +35,7 @@ private static async Task Main() var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; var chatClient = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); // Create the workflow and turn it into an agent diff --git a/dotnet/samples/GettingStarted/Workflows/Concurrent/Concurrent/Program.cs b/dotnet/samples/GettingStarted/Workflows/Concurrent/Concurrent/Program.cs index 577fc905d..782d7db01 100644 --- a/dotnet/samples/GettingStarted/Workflows/Concurrent/Concurrent/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/Concurrent/Concurrent/Program.cs @@ -38,7 +38,7 @@ private static async Task Main() var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; var chatClient = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); // Create the executors diff --git a/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/01_EdgeCondition/Program.cs b/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/01_EdgeCondition/Program.cs index e36e49040..87722de5a 100644 --- a/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/01_EdgeCondition/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/01_EdgeCondition/Program.cs @@ -41,7 +41,7 @@ private static async Task Main() var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; var chatClient = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); // Create agents diff --git a/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/02_SwitchCase/Program.cs b/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/02_SwitchCase/Program.cs index 30cb327d3..b6eefab9c 100644 --- a/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/02_SwitchCase/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/02_SwitchCase/Program.cs @@ -42,7 +42,7 @@ private static async Task Main() var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; var chatClient = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); // Create agents diff --git a/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/03_MultiSelection/Program.cs b/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/03_MultiSelection/Program.cs index 5ffaa9175..e0f4b54a6 100644 --- a/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/03_MultiSelection/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/ConditionalEdges/03_MultiSelection/Program.cs @@ -44,7 +44,7 @@ private static async Task Main() var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; var chatClient = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); // Create agents diff --git a/dotnet/samples/GettingStarted/Workflows/_Foundational/03_AgentsInWorkflows/Program.cs b/dotnet/samples/GettingStarted/Workflows/_Foundational/03_AgentsInWorkflows/Program.cs index 2f31b6b2d..f0b2e6314 100644 --- a/dotnet/samples/GettingStarted/Workflows/_Foundational/03_AgentsInWorkflows/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/_Foundational/03_AgentsInWorkflows/Program.cs @@ -33,7 +33,7 @@ private static async Task Main() var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; var chatClient = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); // Create agents diff --git a/dotnet/samples/GettingStarted/Workflows/_Foundational/04_AgentWorkflowPatterns/Program.cs b/dotnet/samples/GettingStarted/Workflows/_Foundational/04_AgentWorkflowPatterns/Program.cs index d83e1e31d..c66003d2a 100644 --- a/dotnet/samples/GettingStarted/Workflows/_Foundational/04_AgentWorkflowPatterns/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/_Foundational/04_AgentWorkflowPatterns/Program.cs @@ -28,7 +28,7 @@ private static async Task Main() var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; var client = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); Console.Write("Choose workflow type ('sequential', 'concurrent', 'handoffs', 'groupchat'): "); diff --git a/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step01_Concurrent/Program.cs b/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step01_Concurrent/Program.cs index af262cc50..f7d4a0615 100644 --- a/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step01_Concurrent/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step01_Concurrent/Program.cs @@ -77,7 +77,7 @@ ValueTask StreamingResultCallback(StreamingChatMessageContent streamedResponse, async Task AFConcurrentAgentWorkflow() { var client = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); var frenchAgent = GetAFTranslationAgent("French", client); var spanishAgent = GetAFTranslationAgent("Spanish", client); diff --git a/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step02_Sequential/Program.cs b/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step02_Sequential/Program.cs index 4420995fc..af223c2cb 100644 --- a/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step02_Sequential/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step02_Sequential/Program.cs @@ -78,7 +78,7 @@ ValueTask StreamingResultCallback(StreamingChatMessageContent streamedResponse, async Task AFSequentialAgentWorkflow() { var client = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); var frenchAgent = GetAFTranslationAgent("French", client); var spanishAgent = GetAFTranslationAgent("Spanish", client); diff --git a/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step03_Handoff/Program.cs b/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step03_Handoff/Program.cs index 1b0c27fc2..d2e064bc2 100644 --- a/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step03_Handoff/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step03_Handoff/Program.cs @@ -173,7 +173,7 @@ async Task AFHandoffAgentWorkflow() { // Create agents var client = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); ChatClientAgent triageAgent = new(client, diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step01_Basics/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step01_Basics/Program.cs index 3c0f2ca4b..5a41bffd2 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step01_Basics/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step01_Basics/Program.cs @@ -52,7 +52,7 @@ async Task AFAgent() Console.WriteLine("\n=== AF Agent ===\n"); var agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName) .CreateAIAgent(name: "Joker", instructions: "You are good at telling jokes."); diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step02_ToolCall/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step02_ToolCall/Program.cs index fd995e02b..adbe3a95b 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step02_ToolCall/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step02_ToolCall/Program.cs @@ -46,7 +46,7 @@ async Task SKAgent() async Task AFAgent() { var agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName) .CreateAIAgent(instructions: "You are a helpful assistant", tools: [AIFunctionFactory.Create(GetWeather)]); diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step03_DependencyInjection/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step03_DependencyInjection/Program.cs index d02c98ced..289ef7933 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step03_DependencyInjection/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAI/Step03_DependencyInjection/Program.cs @@ -45,7 +45,7 @@ async Task AFAgent() var serviceCollection = new ServiceCollection(); serviceCollection.AddTransient((sp) => new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetChatClient(deploymentName) .CreateAIAgent(name: "Joker", instructions: "You are good at telling jokes.")); diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step01_Basics/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step01_Basics/Program.cs index 013189530..c3c5684c0 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step01_Basics/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step01_Basics/Program.cs @@ -21,7 +21,7 @@ async Task SKAgentAsync() Console.WriteLine("\n=== SK Agent ===\n"); var responseClient = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName); OpenAIResponseAgent agent = new(responseClient) @@ -53,7 +53,7 @@ async Task AFAgentAsync() Console.WriteLine("\n=== AF Agent ===\n"); var agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName) .CreateAIAgent(name: "Joker", instructions: "You are good at telling jokes."); diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step02_ReasoningModel/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step02_ReasoningModel/Program.cs index 72322a7e9..d7a98be42 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step02_ReasoningModel/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step02_ReasoningModel/Program.cs @@ -48,7 +48,7 @@ async Task SKAgentAsync() Console.WriteLine("\n=== SK Agent ===\n"); var responseClient = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName); OpenAIResponseAgent agent = new(responseClient) @@ -118,7 +118,7 @@ async Task AFAgentAsync() Console.WriteLine("\n=== AF Agent ===\n"); var agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName) .CreateAIAgent(name: "Thinker", instructions: "You are good at thinking hard before answering."); diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step03_ToolCall/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step03_ToolCall/Program.cs index 03cce8bb2..13aa62466 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step03_ToolCall/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step03_ToolCall/Program.cs @@ -26,7 +26,7 @@ static string GetWeather([Description("The location to get the weather for.")] s async Task SKAgentAsync() { OpenAIResponseAgent agent = new(new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName)); @@ -47,7 +47,7 @@ async Task SKAgentAsync() async Task AFAgentAsync() { var agent = new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName) .CreateAIAgent(instructions: "You are a helpful assistant", tools: [AIFunctionFactory.Create(GetWeather)]); diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step04_DependencyInjection/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step04_DependencyInjection/Program.cs index e2211ebe2..8403f7c51 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step04_DependencyInjection/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step04_DependencyInjection/Program.cs @@ -25,7 +25,7 @@ async Task SKAgentAsync() var serviceCollection = new ServiceCollection(); serviceCollection.AddTransient((sp) => new OpenAIResponseAgent(new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName)) { @@ -46,7 +46,7 @@ async Task AFAgentAsync() var serviceCollection = new ServiceCollection(); serviceCollection.AddTransient((sp) => new OpenAIClient( - new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"), + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName) .CreateAIAgent(name: "Joker", instructions: "You are good at telling jokes."));