This collection demonstrates how to use Microsoft Agent Framework (MAF) with Claude models deployed in Microsoft Foundry. These samples showcase the integration of Claude's advanced language capabilities with MAF's powerful agent orchestration features using the elbruno.Extensions.AI.Claude NuGet package.
All samples in this collection use the elbruno.Extensions.AI.Claude NuGet package, which provides a clean, native implementation of IChatClient for Claude models deployed in Microsoft Foundry. This package simplifies Claude integration by eliminating the need for custom HTTP handlers or API transformations, while maintaining full compatibility with Microsoft.Extensions.AI and the Agent Framework ecosystem.
Path: samples/MAF/MAF-FoundryClaude-01/
A console application demonstrating basic agent chat with Claude.
Key Features:
- Single prompt/response interaction
ChatClientAgentpattern- Direct
AzureClaudeClientinstantiation from NuGet package - Microsoft Foundry deployment integration
Use Cases: Quick prototyping, testing Claude integration, simple Q&A applications
Path: samples/MAF/MAF-FoundryClaude-Persisting-01/
A console application showing how to persist and resume agent conversations with Claude.
Key Features:
- Thread serialization and deserialization
- Conversation state persistence to JSON files
- Multi-turn conversations with preserved context
- Step-by-step demonstration of context retention
Use Cases: Multi-session chatbots, long-running workflows, debugging conversation flows
Path: samples/MAF/MAF-AIWebChatApp-FoundryClaude/
A Blazor Server web application with a modern chat interface powered by Claude.
Key Features:
- Interactive web-based chat UI
- Real-time messaging with Claude
- Dependency injection for agent configuration
- Modern gradient-themed interface
- Blazor Server with interactive rendering
Use Cases: Web-based chatbots, customer support interfaces, interactive AI applications
All samples require:
- Azure Subscription: Active Azure subscription
- Microsoft Foundry Project: Create a project in Microsoft Foundry
- Claude Model Deployment: Deploy a Claude model (options below)
- API Credentials: Obtain endpoint URLs and API key
- .NET 10 SDK or later: Download
- IDE: Visual Studio 2022, VS Code, or Rider (optional but recommended)
Available Claude models in Microsoft Foundry:
| Model | Description | Best For |
|---|---|---|
| claude-haiku-4-5 | Fast, cost-effective | High-volume applications, quick responses |
| claude-sonnet-4-5 | Balanced performance | General-purpose tasks, moderate complexity |
| claude-opus-4-5 | Highest capability | Complex reasoning, detailed analysis |
Each sample requires the following user secrets:
cd samples/MAF/<sample-name>
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"-
endpointClaude: Claude-specific endpoint
- Format:
https://<resource-name>.services.ai.azure.com/anthropic/v1/messages - Replace
<resource-name>with your Microsoft Foundry resource name
- Format:
-
apikey: API key for authentication
- Azure Portal → Your AI resource → Keys and Endpoint → Key 1 or Key 2
-
deploymentName: Your Claude model deployment name
- Microsoft Foundry → Deployments → Your Claude deployment name
All samples use the elbruno.Extensions.AI.Claude NuGet package:
dotnet add package elbruno.Extensions.AI.ClaudeAlong with the required MAF and AI packages:
dotnet add package Microsoft.Agents.AI --version 1.0.0
dotnet add package Microsoft.Agents.AI.Foundry --version 1.0.0
dotnet add package Microsoft.Extensions.AI --version 10.4.0
dotnet add package Microsoft.Extensions.AI.OpenAI --version 10.4.0# Basic chat example
cd samples/MAF/MAF-FoundryClaude-01
dotnet run
# Persisting conversations example
cd samples/MAF/MAF-FoundryClaude-Persisting-01
dotnet runcd samples/MAF/MAF-AIWebChatApp-FoundryClaude
dotnet run
# Open browser to: https://localhost:5001All samples use AzureClaudeClient from the elbruno.Extensions.AI.Claude NuGet package:
Key Features:
- Native IChatClient implementation - Direct implementation of Microsoft.Extensions.AI abstractions
- Simple configuration - Just endpoint, model ID, and API key
- No custom handlers needed - All API transformation handled internally
- Full streaming support - Real-time responses with Server-Sent Events
- Automatic header management - Includes required
anthropic-versionheader
This approach provides:
- ✅ Clean, maintainable code without custom HTTP handlers
- ✅ Native Claude integration with Microsoft.Extensions.AI
- ✅ Full compatibility with Agent Framework APIs
- ✅ Easy switching between AI providers
- ✅ Support for both streaming and non-streaming responses
MAF Application
↓
IChatClient (Microsoft.Extensions.AI)
↓
AzureClaudeClient (elbruno.Extensions.AI.Claude)
↓
Claude API (Microsoft Foundry)
using elbruno.Extensions.AI.Claude;
using Microsoft.Extensions.AI;
// Create IChatClient using AzureClaudeClient
IChatClient chatClient = new AzureClaudeClient(
endpoint: new Uri(endpointClaude),
modelId: deploymentName,
apiKey: apiKey);var agent = chatClient.CreateAIAgent(
name: "MyAgent",
instructions: "You are a helpful assistant"
);
// Run the agent
var response = await agent.RunAsync("Your question here");
Console.WriteLine(response.Text);// Create thread
var thread = agent.GetNewThread();
var response = await agent.RunAsync(question, thread);
// Save thread
var threadJson = thread.Serialize(JsonSerializerOptions.Web).GetRawText();
await File.WriteAllTextAsync("thread.json", threadJson);
// Load thread
var loadedJson = await File.ReadAllTextAsync("thread.json");
var reloaded = JsonSerializer.Deserialize<JsonElement>(loadedJson, JsonSerializerOptions.Web);
thread = agent.DeserializeThread(reloaded, JsonSerializerOptions.Web);
// Continue conversation
response = await agent.RunAsync(nextQuestion, thread);| Feature | Claude (via Microsoft Foundry) | OpenAI (via Azure OpenAI) |
|---|---|---|
| Authentication | x-api-key header | api-key header or Bearer token |
| Message Format | Anthropic Messages API | OpenAI Chat Completions API |
| System Messages | Separate system parameter |
Part of messages array |
| Streaming | Server-Sent Events (SSE) | Server-Sent Events (SSE) |
| Context Length | Up to 200K tokens (Claude 3+) | Varies by model (4K-128K) |
| Tool Calling | Native function calling | Native function calling |
The ClaudeToOpenAIMessageHandler abstracts these differences, allowing you to use the same MAF APIs regardless of the underlying model.
- Use claude-haiku-4-5 for high-volume, cost-sensitive applications
- Use claude-sonnet-4-5 for balanced performance and capability
- Use claude-opus-4-5 for complex reasoning tasks
- Always wrap agent calls in try-catch blocks
- Log errors for debugging
- Provide user-friendly error messages
- Never hardcode API keys
- Use user secrets for local development
- Use managed identities or Key Vault in production
- Enable streaming for better UX
- Cache frequent responses when appropriate
- Monitor token usage and costs
- Test with different prompt lengths
- Validate conversation persistence
- Check error scenarios (network issues, rate limits)
- Cause: Invalid API key or incorrect endpoint
- Solution: Verify
apikeyandendpointClaudein user secrets - Check: Ensure API key is from the correct Azure resource
- Cause: Deployment name doesn't match actual deployment
- Solution: Verify
deploymentNamematches Microsoft Foundry deployment - Check: Go to Microsoft Foundry → Deployments → Verify name
- Cause: Handler not properly transforming SSE events
- Solution: Ensure
ClaudeToOpenAIMessageHandleris correctly configured - Check: Review console logs for handler errors
- Cause: Thread not properly serialized or deserialized
- Solution: Use
JsonSerializerOptions.Webfor both operations - Check: Validate saved JSON file is not corrupted
- Check Logs: Review application logs for detailed error messages
- Azure Portal: Verify Claude deployment status and quota
- Documentation: Refer to sample-specific README files
- GitHub Issues: Report bugs or request features in the repo
- Microsoft Agent Framework
- Microsoft Foundry Documentation
- Claude in Microsoft Foundry
- Claude API Documentation
- Microsoft.Extensions.AI
- MAF-AIFoundry-01: Microsoft Foundry with OpenAI models
- MAF-Ollama-01: Local AI models with Ollama
- MAF-MultiAgents: Multi-agent orchestration patterns
Contributions are welcome! Please follow the repository's contribution guidelines:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This sample collection is part of the Generative AI for Beginners .NET course and follows the repository's MIT license.
| Sample | Type | Complexity | Key Learning |
|---|---|---|---|
| MAF-FoundryClaude-01 | Console | Beginner | Basic Claude integration |
| MAF-FoundryClaude-Persisting-01 | Console | Intermediate | Conversation persistence |
| MAF-AIWebChatApp-FoundryClaude | Web | Intermediate | Web UI with DI |
Choose the sample that best fits your learning goals or project requirements!