From 5a470136c03f6b0ae0152872948fb34fb5908926 Mon Sep 17 00:00:00 2001 From: hobostay <110hqc@gmail.com> Date: Fri, 6 Mar 2026 10:26:21 +0800 Subject: [PATCH 1/3] Fix: Standardize agent construction pattern in samples Remove redundant .AsIChatClient() call before .AsAIAgent() since ChatClient already implements IChatClient. This simplifies the code and reduces dependencies as suggested in issue #4505. Changes: - Update all sample files to use consistent pattern: chatClient.AsAIAgent() - Update README documentation to reflect the change - Affects AGUI samples and AGUIWebChat samples --- .../AGUI/Step01_GettingStarted/Server/Program.cs | 2 +- .../AGUI/Step02_BackendTools/Server/Program.cs | 2 +- .../AGUI/Step03_FrontendTools/Server/Program.cs | 2 +- .../AGUI/Step04_HumanInLoop/Server/Program.cs | 2 +- .../AGUI/Step05_StateManagement/Server/Program.cs | 2 +- .../AGUIDojoServer/ChatClientAgentFactory.cs | 14 +++++++------- dotnet/samples/05-end-to-end/AGUIWebChat/README.md | 4 ++-- .../05-end-to-end/AGUIWebChat/Server/Program.cs | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.cs b/dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.cs index 936d9430fb..67390ea394 100644 --- a/dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.cs +++ b/dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.cs @@ -27,7 +27,7 @@ new DefaultAzureCredential()) .GetChatClient(deploymentName); -AIAgent agent = chatClient.AsIChatClient().AsAIAgent( +AIAgent agent = chatClient.AsAIAgent( name: "AGUIAssistant", instructions: "You are a helpful assistant."); diff --git a/dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs b/dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs index 5b55829b45..33a32410e2 100644 --- a/dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs +++ b/dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs @@ -82,7 +82,7 @@ static RestaurantSearchResponse SearchRestaurants( new DefaultAzureCredential()) .GetChatClient(deploymentName); -ChatClientAgent agent = chatClient.AsIChatClient().AsAIAgent( +ChatClientAgent agent = chatClient.AsAIAgent( name: "AGUIAssistant", instructions: "You are a helpful assistant with access to restaurant information.", tools: tools); diff --git a/dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Program.cs b/dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Program.cs index 936d9430fb..67390ea394 100644 --- a/dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Program.cs +++ b/dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Program.cs @@ -27,7 +27,7 @@ new DefaultAzureCredential()) .GetChatClient(deploymentName); -AIAgent agent = chatClient.AsIChatClient().AsAIAgent( +AIAgent agent = chatClient.AsAIAgent( name: "AGUIAssistant", instructions: "You are a helpful assistant."); diff --git a/dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs b/dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs index b90f59a1d0..edfcd03219 100644 --- a/dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs +++ b/dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs @@ -60,7 +60,7 @@ static string ApproveExpenseReport(string expenseReportId) new DefaultAzureCredential()) .GetChatClient(deploymentName); -ChatClientAgent baseAgent = openAIChatClient.AsIChatClient().AsAIAgent( +ChatClientAgent baseAgent = openAIChatClient.AsAIAgent( name: "AGUIAssistant", instructions: "You are a helpful assistant in charge of approving expenses", tools: tools); diff --git a/dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Program.cs b/dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Program.cs index 46637e376b..ba85523124 100644 --- a/dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Program.cs +++ b/dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Program.cs @@ -37,7 +37,7 @@ new DefaultAzureCredential()) .GetChatClient(deploymentName); -AIAgent baseAgent = chatClient.AsIChatClient().AsAIAgent( +AIAgent baseAgent = chatClient.AsAIAgent( name: "RecipeAgent", instructions: """ You are a helpful recipe assistant. When users ask you to create or suggest a recipe, diff --git a/dotnet/samples/05-end-to-end/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs b/dotnet/samples/05-end-to-end/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs index cfb07d2850..0b69e23e04 100644 --- a/dotnet/samples/05-end-to-end/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs +++ b/dotnet/samples/05-end-to-end/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs @@ -36,7 +36,7 @@ public static ChatClientAgent CreateAgenticChat() { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - return chatClient.AsIChatClient().AsAIAgent( + return chatClient.AsAIAgent( name: "AgenticChat", description: "A simple chat agent using Azure OpenAI"); } @@ -45,7 +45,7 @@ public static ChatClientAgent CreateBackendToolRendering() { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - return chatClient.AsIChatClient().AsAIAgent( + return chatClient.AsAIAgent( name: "BackendToolRenderer", description: "An agent that can render backend tools using Azure OpenAI", tools: [AIFunctionFactory.Create( @@ -59,7 +59,7 @@ public static ChatClientAgent CreateHumanInTheLoop() { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - return chatClient.AsIChatClient().AsAIAgent( + return chatClient.AsAIAgent( name: "HumanInTheLoopAgent", description: "An agent that involves human feedback in its decision-making process using Azure OpenAI"); } @@ -68,7 +68,7 @@ public static ChatClientAgent CreateToolBasedGenerativeUI() { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - return chatClient.AsIChatClient().AsAIAgent( + return chatClient.AsAIAgent( name: "ToolBasedGenerativeUIAgent", description: "An agent that uses tools to generate user interfaces using Azure OpenAI"); } @@ -76,7 +76,7 @@ public static ChatClientAgent CreateToolBasedGenerativeUI() public static AIAgent CreateAgenticUI(JsonSerializerOptions options) { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - var baseAgent = chatClient.AsIChatClient().AsAIAgent(new ChatClientAgentOptions + var baseAgent = chatClient.AsAIAgent(new ChatClientAgentOptions { Name = "AgenticUIAgent", Description = "An agent that generates agentic user interfaces using Azure OpenAI", @@ -119,7 +119,7 @@ public static AIAgent CreateSharedState(JsonSerializerOptions options) { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - var baseAgent = chatClient.AsIChatClient().AsAIAgent( + var baseAgent = chatClient.AsAIAgent( name: "SharedStateAgent", description: "An agent that demonstrates shared state patterns using Azure OpenAI"); @@ -130,7 +130,7 @@ public static AIAgent CreatePredictiveStateUpdates(JsonSerializerOptions options { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - var baseAgent = chatClient.AsIChatClient().AsAIAgent(new ChatClientAgentOptions + var baseAgent = chatClient.AsAIAgent(new ChatClientAgentOptions { Name = "PredictiveStateUpdatesAgent", Description = "An agent that demonstrates predictive state updates using Azure OpenAI", diff --git a/dotnet/samples/05-end-to-end/AGUIWebChat/README.md b/dotnet/samples/05-end-to-end/AGUIWebChat/README.md index 0e42757fa1..721d1bdf41 100644 --- a/dotnet/samples/05-end-to-end/AGUIWebChat/README.md +++ b/dotnet/samples/05-end-to-end/AGUIWebChat/README.md @@ -74,7 +74,7 @@ AzureOpenAIClient azureOpenAIClient = new AzureOpenAIClient( ChatClient chatClient = azureOpenAIClient.GetChatClient(deploymentName); // Create AI agent -ChatClientAgent agent = chatClient.AsIChatClient().AsAIAgent( +ChatClientAgent agent = chatClient.AsAIAgent( name: "ChatAssistant", instructions: "You are a helpful assistant."); @@ -162,7 +162,7 @@ dotnet run Edit the instructions in `Server/Program.cs`: ```csharp -ChatClientAgent agent = chatClient.AsIChatClient().AsAIAgent( +ChatClientAgent agent = chatClient.AsAIAgent( name: "ChatAssistant", instructions: "You are a helpful coding assistant specializing in C# and .NET."); ``` diff --git a/dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.cs b/dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.cs index 0b474bb7f4..ca237667a7 100644 --- a/dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.cs +++ b/dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.cs @@ -28,7 +28,7 @@ ChatClient chatClient = azureOpenAIClient.GetChatClient(deploymentName); -ChatClientAgent agent = chatClient.AsIChatClient().AsAIAgent( +ChatClientAgent agent = chatClient.AsAIAgent( name: "ChatAssistant", instructions: "You are a helpful assistant."); From 73bf783d0f08c7869f08a1c09b1161a4daac26ba Mon Sep 17 00:00:00 2001 From: hobostay <110hqc@gmail.com> Date: Fri, 6 Mar 2026 23:41:40 +0800 Subject: [PATCH 2/3] fix: add missing using Microsoft.Agents.AI.OpenAI statements Address review feedback from @westey-m: - Add using Microsoft.Agents.AI.OpenAI to files that use chatClient.AsAIAgent() - This is required as AsAIAgent() extension method is defined in this namespace --- .../02-agents/AGUI/Step01_GettingStarted/Server/Program.cs | 1 + .../samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs | 1 + .../02-agents/AGUI/Step03_FrontendTools/Server/Program.cs | 1 + .../samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs | 1 + .../02-agents/AGUI/Step05_StateManagement/Server/Program.cs | 1 + .../AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs | 1 + dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.cs | 1 + 7 files changed, 7 insertions(+) diff --git a/dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.cs b/dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.cs index 67390ea394..30d4e34ac5 100644 --- a/dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.cs +++ b/dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.cs @@ -4,6 +4,7 @@ using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Hosting.AGUI.AspNetCore; +using Microsoft.Agents.AI.OpenAI; using Microsoft.Extensions.AI; using OpenAI.Chat; diff --git a/dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs b/dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs index 33a32410e2..b6223d90ce 100644 --- a/dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs +++ b/dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs @@ -6,6 +6,7 @@ using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Hosting.AGUI.AspNetCore; +using Microsoft.Agents.AI.OpenAI; using Microsoft.Extensions.AI; using Microsoft.Extensions.Options; using OpenAI.Chat; diff --git a/dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Program.cs b/dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Program.cs index 67390ea394..30d4e34ac5 100644 --- a/dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Program.cs +++ b/dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Program.cs @@ -4,6 +4,7 @@ using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Hosting.AGUI.AspNetCore; +using Microsoft.Agents.AI.OpenAI; using Microsoft.Extensions.AI; using OpenAI.Chat; diff --git a/dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs b/dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs index edfcd03219..fabf5b361f 100644 --- a/dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs +++ b/dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs @@ -5,6 +5,7 @@ using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Hosting.AGUI.AspNetCore; +using Microsoft.Agents.AI.OpenAI; using Microsoft.AspNetCore.Http.Json; using Microsoft.AspNetCore.HttpLogging; using Microsoft.Extensions.AI; diff --git a/dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Program.cs b/dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Program.cs index ba85523124..e27a04ed1f 100644 --- a/dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Program.cs +++ b/dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Program.cs @@ -4,6 +4,7 @@ using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Hosting.AGUI.AspNetCore; +using Microsoft.Agents.AI.OpenAI; using Microsoft.Extensions.AI; using Microsoft.Extensions.Options; using OpenAI.Chat; diff --git a/dotnet/samples/05-end-to-end/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs b/dotnet/samples/05-end-to-end/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs index 0b69e23e04..920948a15d 100644 --- a/dotnet/samples/05-end-to-end/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs +++ b/dotnet/samples/05-end-to-end/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs @@ -9,6 +9,7 @@ using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; +using Microsoft.Agents.AI.OpenAI; using Microsoft.Extensions.AI; using ChatClient = OpenAI.Chat.ChatClient; diff --git a/dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.cs b/dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.cs index ca237667a7..5f4ddc7fad 100644 --- a/dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.cs +++ b/dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.cs @@ -6,6 +6,7 @@ using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Hosting.AGUI.AspNetCore; +using Microsoft.Agents.AI.OpenAI; using Microsoft.Extensions.AI; using OpenAI.Chat; From 91e9b766a7d8b8537698a5227f4e300dddf25e80 Mon Sep 17 00:00:00 2001 From: hobostay Date: Sat, 7 Mar 2026 22:06:54 +0800 Subject: [PATCH 3/3] Fix: Revert agent construction pattern changes causing build failures This commit fixes the build failures caused by the original PR changes: 1. ChatClientAgentFactory.cs - Restored .AsIChatClient().AsAIAgent() pattern - Removed using Microsoft.Agents.AI.OpenAI which caused wrong extension method selection - Restored chatClient.AsIChatClient().AsAIAgent() calls (7 occurrences) 2. AGUI Samples (Step01-Step05) - Fixed agent construction - Removed unnecessary using Microsoft.Agents.AI.OpenAI - Restored chatClient.AsIChatClient().AsAIAgent() pattern 3. AGUIWebChat - Fixed Server and documentation - Removed unnecessary using statement - Restored correct pattern in Server/Program.cs - Updated README.md to reflect correct pattern 4. Root README.md - Fixed Discord badge link - Replaced timeout-prone dcbadge.limes.pink with img.shields.io Discord badge The issue was that adding using Microsoft.Agents.AI.OpenAI caused the compiler to select ChatClientExtensions.AsAIAgent(IChatClient) instead of the correct extension method for ChatClient, requiring explicit .AsIChatClient() conversion. Co-Authored-By: Claude Opus 4.6 --- README.md | 2 +- .../AGUI/Step01_GettingStarted/Server/Program.cs | 3 +-- .../AGUI/Step02_BackendTools/Server/Program.cs | 3 +-- .../AGUI/Step03_FrontendTools/Server/Program.cs | 3 +-- .../AGUI/Step04_HumanInLoop/Server/Program.cs | 3 +-- .../AGUI/Step05_StateManagement/Server/Program.cs | 3 +-- .../AGUIDojoServer/ChatClientAgentFactory.cs | 15 +++++++-------- .../samples/05-end-to-end/AGUIWebChat/README.md | 4 ++-- .../05-end-to-end/AGUIWebChat/Server/Program.cs | 3 +-- 9 files changed, 16 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 1c41003080..45c2315430 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Welcome to Microsoft Agent Framework! -[![Microsoft Azure AI Foundry Discord](https://dcbadge.limes.pink/api/server/b5zjErwbQM?style=flat)](https://discord.gg/b5zjErwbQM) +[![Microsoft Azure AI Foundry Discord](https://img.shields.io/discord/1260466022557278220?label=Discord&logo=discord&logoColor=white)](https://discord.gg/b5zjErwbQM) [![MS Learn Documentation](https://img.shields.io/badge/MS%20Learn-Documentation-blue)](https://learn.microsoft.com/en-us/agent-framework/) [![PyPI](https://img.shields.io/pypi/v/agent-framework)](https://pypi.org/project/agent-framework/) [![NuGet](https://img.shields.io/nuget/v/Microsoft.Agents.AI)](https://www.nuget.org/profiles/MicrosoftAgentFramework/) diff --git a/dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.cs b/dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.cs index 30d4e34ac5..936d9430fb 100644 --- a/dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.cs +++ b/dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.cs @@ -4,7 +4,6 @@ using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Hosting.AGUI.AspNetCore; -using Microsoft.Agents.AI.OpenAI; using Microsoft.Extensions.AI; using OpenAI.Chat; @@ -28,7 +27,7 @@ new DefaultAzureCredential()) .GetChatClient(deploymentName); -AIAgent agent = chatClient.AsAIAgent( +AIAgent agent = chatClient.AsIChatClient().AsAIAgent( name: "AGUIAssistant", instructions: "You are a helpful assistant."); diff --git a/dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs b/dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs index b6223d90ce..5b55829b45 100644 --- a/dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs +++ b/dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs @@ -6,7 +6,6 @@ using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Hosting.AGUI.AspNetCore; -using Microsoft.Agents.AI.OpenAI; using Microsoft.Extensions.AI; using Microsoft.Extensions.Options; using OpenAI.Chat; @@ -83,7 +82,7 @@ static RestaurantSearchResponse SearchRestaurants( new DefaultAzureCredential()) .GetChatClient(deploymentName); -ChatClientAgent agent = chatClient.AsAIAgent( +ChatClientAgent agent = chatClient.AsIChatClient().AsAIAgent( name: "AGUIAssistant", instructions: "You are a helpful assistant with access to restaurant information.", tools: tools); diff --git a/dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Program.cs b/dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Program.cs index 30d4e34ac5..936d9430fb 100644 --- a/dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Program.cs +++ b/dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Program.cs @@ -4,7 +4,6 @@ using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Hosting.AGUI.AspNetCore; -using Microsoft.Agents.AI.OpenAI; using Microsoft.Extensions.AI; using OpenAI.Chat; @@ -28,7 +27,7 @@ new DefaultAzureCredential()) .GetChatClient(deploymentName); -AIAgent agent = chatClient.AsAIAgent( +AIAgent agent = chatClient.AsIChatClient().AsAIAgent( name: "AGUIAssistant", instructions: "You are a helpful assistant."); diff --git a/dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs b/dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs index fabf5b361f..b90f59a1d0 100644 --- a/dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs +++ b/dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs @@ -5,7 +5,6 @@ using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Hosting.AGUI.AspNetCore; -using Microsoft.Agents.AI.OpenAI; using Microsoft.AspNetCore.Http.Json; using Microsoft.AspNetCore.HttpLogging; using Microsoft.Extensions.AI; @@ -61,7 +60,7 @@ static string ApproveExpenseReport(string expenseReportId) new DefaultAzureCredential()) .GetChatClient(deploymentName); -ChatClientAgent baseAgent = openAIChatClient.AsAIAgent( +ChatClientAgent baseAgent = openAIChatClient.AsIChatClient().AsAIAgent( name: "AGUIAssistant", instructions: "You are a helpful assistant in charge of approving expenses", tools: tools); diff --git a/dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Program.cs b/dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Program.cs index e27a04ed1f..46637e376b 100644 --- a/dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Program.cs +++ b/dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Program.cs @@ -4,7 +4,6 @@ using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Hosting.AGUI.AspNetCore; -using Microsoft.Agents.AI.OpenAI; using Microsoft.Extensions.AI; using Microsoft.Extensions.Options; using OpenAI.Chat; @@ -38,7 +37,7 @@ new DefaultAzureCredential()) .GetChatClient(deploymentName); -AIAgent baseAgent = chatClient.AsAIAgent( +AIAgent baseAgent = chatClient.AsIChatClient().AsAIAgent( name: "RecipeAgent", instructions: """ You are a helpful recipe assistant. When users ask you to create or suggest a recipe, diff --git a/dotnet/samples/05-end-to-end/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs b/dotnet/samples/05-end-to-end/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs index 920948a15d..cfb07d2850 100644 --- a/dotnet/samples/05-end-to-end/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs +++ b/dotnet/samples/05-end-to-end/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs @@ -9,7 +9,6 @@ using Azure.AI.OpenAI; using Azure.Identity; using Microsoft.Agents.AI; -using Microsoft.Agents.AI.OpenAI; using Microsoft.Extensions.AI; using ChatClient = OpenAI.Chat.ChatClient; @@ -37,7 +36,7 @@ public static ChatClientAgent CreateAgenticChat() { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - return chatClient.AsAIAgent( + return chatClient.AsIChatClient().AsAIAgent( name: "AgenticChat", description: "A simple chat agent using Azure OpenAI"); } @@ -46,7 +45,7 @@ public static ChatClientAgent CreateBackendToolRendering() { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - return chatClient.AsAIAgent( + return chatClient.AsIChatClient().AsAIAgent( name: "BackendToolRenderer", description: "An agent that can render backend tools using Azure OpenAI", tools: [AIFunctionFactory.Create( @@ -60,7 +59,7 @@ public static ChatClientAgent CreateHumanInTheLoop() { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - return chatClient.AsAIAgent( + return chatClient.AsIChatClient().AsAIAgent( name: "HumanInTheLoopAgent", description: "An agent that involves human feedback in its decision-making process using Azure OpenAI"); } @@ -69,7 +68,7 @@ public static ChatClientAgent CreateToolBasedGenerativeUI() { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - return chatClient.AsAIAgent( + return chatClient.AsIChatClient().AsAIAgent( name: "ToolBasedGenerativeUIAgent", description: "An agent that uses tools to generate user interfaces using Azure OpenAI"); } @@ -77,7 +76,7 @@ public static ChatClientAgent CreateToolBasedGenerativeUI() public static AIAgent CreateAgenticUI(JsonSerializerOptions options) { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - var baseAgent = chatClient.AsAIAgent(new ChatClientAgentOptions + var baseAgent = chatClient.AsIChatClient().AsAIAgent(new ChatClientAgentOptions { Name = "AgenticUIAgent", Description = "An agent that generates agentic user interfaces using Azure OpenAI", @@ -120,7 +119,7 @@ public static AIAgent CreateSharedState(JsonSerializerOptions options) { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - var baseAgent = chatClient.AsAIAgent( + var baseAgent = chatClient.AsIChatClient().AsAIAgent( name: "SharedStateAgent", description: "An agent that demonstrates shared state patterns using Azure OpenAI"); @@ -131,7 +130,7 @@ public static AIAgent CreatePredictiveStateUpdates(JsonSerializerOptions options { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - var baseAgent = chatClient.AsAIAgent(new ChatClientAgentOptions + var baseAgent = chatClient.AsIChatClient().AsAIAgent(new ChatClientAgentOptions { Name = "PredictiveStateUpdatesAgent", Description = "An agent that demonstrates predictive state updates using Azure OpenAI", diff --git a/dotnet/samples/05-end-to-end/AGUIWebChat/README.md b/dotnet/samples/05-end-to-end/AGUIWebChat/README.md index 721d1bdf41..0e42757fa1 100644 --- a/dotnet/samples/05-end-to-end/AGUIWebChat/README.md +++ b/dotnet/samples/05-end-to-end/AGUIWebChat/README.md @@ -74,7 +74,7 @@ AzureOpenAIClient azureOpenAIClient = new AzureOpenAIClient( ChatClient chatClient = azureOpenAIClient.GetChatClient(deploymentName); // Create AI agent -ChatClientAgent agent = chatClient.AsAIAgent( +ChatClientAgent agent = chatClient.AsIChatClient().AsAIAgent( name: "ChatAssistant", instructions: "You are a helpful assistant."); @@ -162,7 +162,7 @@ dotnet run Edit the instructions in `Server/Program.cs`: ```csharp -ChatClientAgent agent = chatClient.AsAIAgent( +ChatClientAgent agent = chatClient.AsIChatClient().AsAIAgent( name: "ChatAssistant", instructions: "You are a helpful coding assistant specializing in C# and .NET."); ``` diff --git a/dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.cs b/dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.cs index 5f4ddc7fad..0b474bb7f4 100644 --- a/dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.cs +++ b/dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.cs @@ -6,7 +6,6 @@ using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Hosting.AGUI.AspNetCore; -using Microsoft.Agents.AI.OpenAI; using Microsoft.Extensions.AI; using OpenAI.Chat; @@ -29,7 +28,7 @@ ChatClient chatClient = azureOpenAIClient.GetChatClient(deploymentName); -ChatClientAgent agent = chatClient.AsAIAgent( +ChatClientAgent agent = chatClient.AsIChatClient().AsAIAgent( name: "ChatAssistant", instructions: "You are a helpful assistant.");