All .NET code samples in the repository fail to compile with .NET 10 SDK due to a missing AsIChatClient() conversion. The CreateAIAgent extension method requires an IChatClient interface, but the code passes a ChatClient object directly.
Error Message
error CS1929: 'ChatClient' does not contain a definition for 'CreateAIAgent' and the best
extension method overload 'ChatClientExtensions.CreateAIAgent(IChatClient, string?, string?,
string?, IList<AITool>?, ILoggerFactory?, IServiceProvider?)' requires a receiver of type
'Microsoft.Extensions.AI.IChatClient'
Steps to Reproduce
- Clone the repository
- Ensure .NET 10 SDK is installed (dotnet --version shows 10.0.x)
- Navigate to any .NET sample, e.g., 02-explore-agentic-frameworks/code_samples/
- Run: dotnet run 02-dotnet-agent-framework.cs
- Build fails with the error above
Affected Files
All .NET sample files are affected, including:
- 01-intro-to-ai-agents/code_samples/01-dotnet-agent-framework.cs
- 02-explore-agentic-frameworks/code_samples/02-dotnet-agent-framework.cs
- 03-agentic-design-patterns/code_samples/03-dotnet-agent-framework.cs
- 04-tool-use/code_samples/04-dotnet-agent-framework.cs
- And others...
Root Cause
The OpenAIClient.GetChatClient() method returns an OpenAI ChatClient object, but the CreateAIAgent() extension method (from Microsoft.Agents.AI) expects the IChatClient interface from Microsoft.Extensions.AI.
Proposed Fix
-
Add the Microsoft.Extensions.AI.OpenAI package reference:
#:package Microsoft.Extensions.AI.OpenAI@10.*-*
-
Add .AsIChatClient() conversion after GetChatClient():
AIAgent agent = openAIClient
.GetChatClient(github_model_id)
.AsIChatClient()
.CreateAIAgent(
name: AGENT_NAME,
instructions: AGENT_INSTRUCTIONS,
tools: [AIFunctionFactory.Create(GetRandomDestination)]
);
Environment
- .NET SDK: 10.0.101
- OS: Windows 11
- Packages:
- Microsoft.Extensions.AI@10.*
- Microsoft.Agents.AI.OpenAI@1.
Labels
bug, dotnet, good first issue
All .NET code samples in the repository fail to compile with .NET 10 SDK due to a missing AsIChatClient() conversion. The CreateAIAgent extension method requires an IChatClient interface, but the code passes a ChatClient object directly.
Error Message
Steps to Reproduce
Affected Files
All .NET sample files are affected, including:
Root Cause
The OpenAIClient.GetChatClient() method returns an OpenAI ChatClient object, but the CreateAIAgent() extension method (from Microsoft.Agents.AI) expects the IChatClient interface from Microsoft.Extensions.AI.
Proposed Fix
Add the Microsoft.Extensions.AI.OpenAI package reference:
#:package Microsoft.Extensions.AI.OpenAI@10.*-*Add .AsIChatClient() conversion after GetChatClient():
Environment
Labels
bug, dotnet, good first issue