.NET: Cleanup unnecessary usages of AsIChatClient#4561
Merged
westey-m merged 3 commits intomicrosoft:mainfrom Mar 10, 2026
Merged
.NET: Cleanup unnecessary usages of AsIChatClient#4561westey-m merged 3 commits intomicrosoft:mainfrom
westey-m merged 3 commits intomicrosoft:mainfrom
Conversation
Contributor
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 |
rogerbarreto
approved these changes
Mar 9, 2026
SergeyMenshykh
approved these changes
Mar 9, 2026
davidahmann
pushed a commit
to davidahmann/agent-framework
that referenced
this pull request
Mar 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
#4505
Description
Contribution Checklist