Skip to content

.NET: Cleanup unnecessary usages of AsIChatClient - #4561

Merged
westey (westey-m) merged 3 commits into
microsoft:mainfrom
westey-m:asichatclient-cleanup
Mar 10, 2026
Merged

.NET: Cleanup unnecessary usages of AsIChatClient#4561
westey (westey-m) merged 3 commits into
microsoft:mainfrom
westey-m:asichatclient-cleanup

Conversation

@westey-m

Copy link
Copy Markdown
Contributor

Motivation and Context

#4505

Description

  • Cleanup unnecessary usages of AsIChatClient

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

CopilotAI review requested due to automatic review settings March 9, 2026 14:43
@markwallace-microsoftMark Wallace (markwallace-microsoft) added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net labels Mar 9, 2026
@github-actionsgithub-actionsBot changed the title Cleanup unnecessary usages of AsIChatClient.NET: Cleanup unnecessary usages of AsIChatClientMar 9, 2026

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.OpenAI package references and using Microsoft.Extensions.AI; imports where they were only needed for the AsIChatClient() 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
FileDescription
dotnet/samples/05-end-to-end/AspNetAgentAuthorization/Service/Service.csprojRemoved Microsoft.Extensions.AI.OpenAI package reference
dotnet/samples/05-end-to-end/AspNetAgentAuthorization/Service/Program.csAdded using OpenAI.Chat;, removed .AsIChatClient() call
dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.csRemoved using Microsoft.Extensions.AI; and .AsIChatClient() call
dotnet/samples/05-end-to-end/AGUIWebChat/README.mdUpdated two code snippets to remove .AsIChatClient()
dotnet/samples/05-end-to-end/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.csChanged alias import to namespace import, removed 8 .AsIChatClient() calls
dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Server.csprojRemoved Microsoft.Extensions.AI.OpenAI package reference
dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Program.csRemoved using Microsoft.Extensions.AI; and .AsIChatClient() call
dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Server.csprojRemoved Microsoft.Extensions.AI.OpenAI package reference
dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.csRemoved .AsIChatClient() call
dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Server.csprojRemoved Microsoft.Extensions.AI.OpenAI package reference
dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Program.csRemoved using Microsoft.Extensions.AI; and .AsIChatClient() call
dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Server.csprojRemoved Microsoft.Extensions.AI.OpenAI package reference
dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.csRemoved .AsIChatClient() call
dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Server.csprojRemoved Microsoft.Extensions.AI.OpenAI package reference
dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.csRemoved using Microsoft.Extensions.AI; and .AsIChatClient() call

@westey-m
westey (westey-m) added this pull request to the merge queueMar 9, 2026
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks Mar 9, 2026
@westey-m
westey (westey-m) added this pull request to the merge queueMar 9, 2026
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks Mar 9, 2026
@westey-m
westey (westey-m) added this pull request to the merge queueMar 9, 2026
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks Mar 9, 2026
@westey-m
westey (westey-m) added this pull request to the merge queueMar 9, 2026
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks Mar 9, 2026
@westey-m
westey (westey-m) added this pull request to the merge queueMar 10, 2026
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks Mar 10, 2026
CopilotAI review requested due to automatic review settings March 10, 2026 15:27
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentationUsage: [Issues, PRs], Target: documentation in the code base and learn docs.NETUsage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@westey-m@rogerbarreto@SergeyMenshykh@markwallace-microsoft