Skip to content

Fix: Build failures in #4516 - Revert agent construction pattern changes#4539

Open
hobostay wants to merge 3 commits intomicrosoft:mainfrom
hobostay:fix/agent-construction-build-errors
Open

Fix: Build failures in #4516 - Revert agent construction pattern changes#4539
hobostay wants to merge 3 commits intomicrosoft:mainfrom
hobostay:fix/agent-construction-build-errors

Conversation

@hobostay
Copy link

@hobostay hobostay commented Mar 7, 2026

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, ...) requires IChatClient type
  • The original code used ChatClient.AsIChatClient().AsAIAgent(...) which is correct

Changes

  1. ChatClientAgentFactory.cs - Removed using Microsoft.Agents.AI.OpenAI; and restored .AsIChatClient().AsAIAgent() pattern (7 occurrences)

  2. AGUI Samples (Step01-Step05) - Removed unnecessary using statement and restored correct pattern

  3. AGUIWebChat - Fixed Server/Program.cs and updated README.md

  4. Root README.md - Replaced timeout-prone Discord badge (dcbadge.limes.pink) with stable img.shields.io version

Issues Fixed

Check Status
7× CS1929 build errors ✅ Fixed
IDE0005 format error ✅ Fixed
Markdown link check timeout ✅ Fixed

Test plan

All CI checks should now pass:

  • dotnet-build (net10.0, net9.0, net8.0, net472)
  • check-format
  • markdown-link-check
  • merge-gatekeeper

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

hobostay and others added 3 commits March 6, 2026 10:26
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>
@markwallace-microsoft markwallace-microsoft added the documentation Improvements or additions to documentation label Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants