.NET: Fix: Standardize agent construction pattern in samples#4516
Open
hobostay wants to merge 2 commits intomicrosoft:mainfrom
Open
.NET: Fix: Standardize agent construction pattern in samples#4516hobostay wants to merge 2 commits intomicrosoft:mainfrom
hobostay wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Remove redundant .AsIChatClient() call before .AsAIAgent() since ChatClient already implements IChatClient. This simplifies the code and reduces dependencies as suggested in issue microsoft#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
Author
|
@microsoft-github-policy-service agree |
westey-m
reviewed
Mar 6, 2026
| ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); | ||
|
|
||
| return chatClient.AsIChatClient().AsAIAgent( | ||
| return chatClient.AsAIAgent( |
Contributor
There was a problem hiding this comment.
This will require a reference to the Microsoft.Agents.AI.OpenAI project to compile.
Author
There was a problem hiding this comment.
Thank you for the review! I've added the missing using Microsoft.Agents.AI.OpenAI; statements to all files that use chatClient.AsAIAgent().
The AsAIAgent() extension method is defined in the Microsoft.Agents.AI.OpenAI namespace, so this using statement is required for the code to compile when calling chatClient.AsAIAgent() directly.
Updated files:
- dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.cs
- dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs
- dotnet/samples/02-agents/AGUI/Step03_FrontendTools/Server/Program.cs
- dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs
- dotnet/samples/02-agents/AGUI/Step05_StateManagement/Server/Program.cs
- dotnet/samples/05-end-to-end/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs
- dotnet/samples/05-end-to-end/AGUIWebChat/Server/Program.cs
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
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.
This PR addresses issue #4505 by standardizing the agent construction pattern across all sample files.
Changes
Benefits