Uh oh!
There was an error while loading. Please reload this page.
.NET: Cleanup unnecessary usages of AsIChatClient - #4561
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses Issue #4505 by removing unnecessary .AsIChatClient() calls from sample code throughout the dotnet samples. The AsAIAgent() extension method on OpenAI.Chat.ChatClient already internally calls AsIChatClient(), so the explicit intermediate call was redundant and required an extra dependency (Microsoft.Extensions.AI.OpenAI).
Changes:
- Replaced
.GetChatClient(deploymentName).AsIChatClient().AsAIAgent(...)with.GetChatClient(deploymentName).AsAIAgent(...)across all AGUI and end-to-end sample projects. - Removed unnecessary
Microsoft.Extensions.AI.OpenAIpackage references andusing Microsoft.Extensions.AI;imports where they were only needed for theAsIChatClient()extension method. - Updated README documentation in the AGUIWebChat sample to match the simplified code pattern.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
dotnet/samples/05-end-to-end/AspNetAgentAuthorization/Service/Service.csproj | Removed Microsoft.Extensions.AI.OpenAI package reference |
dotnet/samples/05-end-to-end/AspNetAgentAuthorization/Service/Program.cs | Added using OpenAI.Chat;, removed .AsIChatClient() call |
dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.cs | Removed using Microsoft.Extensions.AI; and .AsIChatClient() call |
dotnet/samples/05-end-to-end/AGUIWebChat/README.md | Updated two code snippets to remove .AsIChatClient() |
dotnet/samples/05-end-to-end/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs | Changed alias import to namespace import, removed 8 .AsIChatClient() calls |
dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Server.csproj | Removed Microsoft.Extensions.AI.OpenAI package reference |
dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Program.cs | Removed using Microsoft.Extensions.AI; and .AsIChatClient() call |
dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Server.csproj | Removed Microsoft.Extensions.AI.OpenAI package reference |
dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs | Removed .AsIChatClient() call |
dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Server.csproj | Removed Microsoft.Extensions.AI.OpenAI package reference |
dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Program.cs | Removed using Microsoft.Extensions.AI; and .AsIChatClient() call |
dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Server.csproj | Removed Microsoft.Extensions.AI.OpenAI package reference |
dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs | Removed .AsIChatClient() call |
dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Server.csproj | Removed Microsoft.Extensions.AI.OpenAI package reference |
dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.cs | Removed using Microsoft.Extensions.AI; and .AsIChatClient() call |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Motivation and Context
#4505
Description
Contribution Checklist