Fix: Build failures in #4516 - Revert agent construction pattern changes#4539
Open
hobostay wants to merge 3 commits intomicrosoft:mainfrom
Open
Fix: Build failures in #4516 - Revert agent construction pattern changes#4539hobostay wants to merge 3 commits intomicrosoft:mainfrom
hobostay wants to merge 3 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
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 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 <noreply@anthropic.com>
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.
Summary
This PR fixes the build failures caused by PR #4516.
Root Cause
Adding
using Microsoft.Agents.AI.OpenAI;caused the compiler to select the wrong extension method:ChatClientExtensions.AsAIAgent(IChatClient, ...)requiresIChatClienttypeChatClient.AsIChatClient().AsAIAgent(...)which is correctChanges
ChatClientAgentFactory.cs - Removed
using Microsoft.Agents.AI.OpenAI;and restored.AsIChatClient().AsAIAgent()pattern (7 occurrences)AGUI Samples (Step01-Step05) - Removed unnecessary using statement and restored correct pattern
AGUIWebChat - Fixed Server/Program.cs and updated README.md
Root README.md - Replaced timeout-prone Discord badge (
dcbadge.limes.pink) with stableimg.shields.ioversionIssues Fixed
Test plan
All CI checks should now pass:
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com