This sample demonstrates how to use Microsoft Agent Framework (MAF) with Claude models deployed in Microsoft Foundry. It shows the integration of ChatClientAgent with Claude using the elbruno.Extensions.AI.Claude NuGet package.
- Framework: Microsoft Agent Framework (MAF)
- AI Model: Claude (Haiku, Sonnet, or Opus) via Microsoft Foundry
- Pattern: Basic agent chat with single prompt/response
- Key Package: elbruno.Extensions.AI.Claude - provides seamless Claude integration
- Create a Microsoft Foundry project
- Deploy a Claude model (e.g.,
claude-haiku-4-5,claude-sonnet-4-5) - Note your:
- Claude Endpoint:
https://<resource-name>.services.ai.azure.com/anthropic/v1/messages - API Key: From Azure portal
- Deployment Name: Your Claude model deployment name
- Claude Endpoint:
- .NET 10 SDK or later
Set user secrets for the project:
cd samples/MAF/MAF-FoundryClaude-01
dotnet user-secrets set "endpointClaude" "https://<resource-name>.services.ai.azure.com/anthropic/v1/messages"
dotnet user-secrets set "apikey" "<your-api-key>"
dotnet user-secrets set "deploymentName" "claude-haiku-4-5"# Navigate to the project directory
cd samples/MAF/MAF-FoundryClaude-01
# Restore dependencies
dotnet restore
# Run the application
dotnet run- Uses elbruno.Extensions.AI.Claude NuGet package for seamless Claude integration
- Implements
IChatClientinterface from Microsoft.Extensions.AI - Enables native Claude model usage with Microsoft Agent Framework
- Creates an
AIAgentusingChatClientAgent - Configures agent with name and instructions
- Executes single prompt with
RunAsync()
- Direct instantiation of
AzureClaudeClientwith endpoint, model ID, and API key - No custom HTTP handlers or transformations needed
- Clean, maintainable code following Microsoft.Extensions.AI patterns
MAF-FoundryClaude-01/
├── Program.cs # Main application with agent setup
├── MAF-FoundryClaude-01.csproj # Project file with dependencies
└── README.md # This file
dotnet add package elbruno.Extensions.AI.Claude --version 0.1.0-preview.2using elbruno.Extensions.AI.Claude;
using Microsoft.Extensions.AI;
// Create IChatClient using AzureClaudeClient from the NuGet package
IChatClient chatClient = new AzureClaudeClient(
endpoint: new Uri(endpointClaude),
modelId: deploymentName,
apiKey: apiKey);AIAgent writer = new ChatClientAgent(
chatClient,
new ChatClientAgentOptions
{
Name = "Writer",
Instructions = "You are a creative writer..."
});
AgentRunResponse response = await writer.RunAsync("Write a short story...");
Console.WriteLine(response.Text);============================================================
MAF with Claude via Microsoft Foundry
============================================================
Model: claude-haiku-4-5
Endpoint: https://<resource-name>.services.ai.azure.com/anthropic/v1/messages
============================================================
Prompt: Write a short story about a haunted house with a character named Lucia.
Response:
------------------------------------------------------------
[Claude's creative story about Lucia and the haunted house]
------------------------------------------------------------
- MAF-FoundryClaude-Persisting-01: Demonstrates conversation persistence with Claude agents
- MAF-AIWebChatApp-FoundryClaude: Blazor web chat application with Claude agent
- elbruno.Extensions.AI.Claude NuGet Package
- Microsoft Agent Framework Documentation
- Microsoft Foundry - Claude Models
- Claude API Documentation
- Microsoft.Extensions.AI
- Verify API key is correct in user secrets
- Ensure Claude endpoint URL matches your Azure resource
- Check that deployment name matches your Claude model deployment
- Confirm Claude model is deployed in your Microsoft Foundry project
- Verify deployment name in configuration matches actual deployment
- Ensure .NET 10 SDK is installed
- Run
dotnet restoreto restore NuGet packages - Check that all package versions are compatible
This sample is part of the Generative AI for Beginners .NET course and follows the repository's MIT license.