diff --git a/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs b/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs index 5edfcf53d9..285e78b5f3 100644 --- a/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs +++ b/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs @@ -1,15 +1,16 @@ // Copyright (c) Microsoft. All rights reserved. +using System.ClientModel.Primitives; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.Metrics; -using Azure.AI.OpenAI; 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 +111,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://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 .AsBuilder() diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIChatCompletion/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIChatCompletion/Program.cs index bd31350258..d09efb60f0 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://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 6d162ebfd6..e34a9de731 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://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 c67756299c..75754f51f9 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://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 626a3e98c4..e35f2f6218 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://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 48a6378e1f..f62be9f9d1 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://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 41ea8a5c92..a4a523c2f1 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://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 b18d8e2d84..a9247950d9 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://ai.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 1ffe3c9993..3bf2d69496 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://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 8986734972..780ab7b385 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://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 c48242f5ca..53a5cdd035 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://ai.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 894c034eb0..ff1f4fe4e5 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs @@ -4,12 +4,14 @@ // 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; 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"; @@ -22,9 +24,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://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 8e8c5701ad..3bb1b846dc 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://ai.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 cce53ef3c0..22d7f3ba0c 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://ai.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://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 ad59deb97f..b299a1bbd1 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://ai.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 ea59c84ba4..5773736fb3 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs @@ -5,20 +5,24 @@ // 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; 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."); 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://ai.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 7284efcc42..1000a7b99a 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://ai.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 590b5308d5..d89d25ac7d 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://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 1a0d236961..05e1f153e5 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://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 aae520eec9..32864f3fef 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://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 437453a865..95a18063aa 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://ai.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 49305d9908..dd1619e888 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://ai.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 44d0f0fe77..782d7db01c 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://ai.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 6298337d79..87722de5a9 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://ai.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 17de5311c5..b6eefab9c1 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://ai.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 cb3914fa64..e0f4b54a67 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://ai.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 2b30f3f5a1..f0b2e63148 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://ai.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 aeb06cfb64..c66003d2a1 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://ai.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }).GetChatClient(deploymentName).AsIChatClient(); Console.Write("Choose workflow type ('sequential', 'concurrent', 'handoffs', 'groupchat'): "); switch (Console.ReadLine()) diff --git a/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step01_Concurrent/Program.cs b/dotnet/samples/SemanticKernelMigration/AgentOrchestrations/Step01_Concurrent/Program.cs index ac6c276434..f7d4a06153 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://ai.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 e317ac0ff8..af223c2cb0 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://ai.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 f66fefe535..d2e064bc25 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://ai.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 527f813be6..5a41bffd2e 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://ai.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 56ca87973a..adbe3a95be 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://ai.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 caf166674d..289ef79331 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://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 22a17887e1..c3c5684c01 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://ai.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://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 8ee5ae89b6..d7a98be422 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://ai.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://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 12bb3b46b7..13aa624661 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://ai.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://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 e2bef86a7f..8403f7c51b 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://ai.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://ai.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri(endpoint) }) .GetOpenAIResponseClient(deploymentName) .CreateAIAgent(name: "Joker", instructions: "You are good at telling jokes."));