Welcome to the comprehensive guide for Microsoft Agent Framework (MAF) samples! These samples demonstrate how to build intelligent agents using .NET 10, Microsoft.Extensions.AI, and various AI providers (Azure OpenAI, Ollama, Claude, and Microsoft Foundry).
Microsoft Agent Framework v1.0 GA provides a modern, extensible foundation for building AI agents in .NET. These samples showcase:
- Simple agents — Single-shot and conversational AI agents
- Multi-agent workflows — Sequential and parallel agent orchestration
- Tool integration — Function calling and tool use
- Persistence — Saving and resuming conversation state
- Web applications — Blazor Server chat interfaces
- Hosted deployment — Docker containerization for Azure Foundry Agent Service
- Multiple AI providers — Azure OpenAI, Ollama, Claude, Microsoft Foundry, and more
- .NET 10 SDK or later (Download)
- Azure OpenAI — Cloud-based GPT models (requires Azure subscription)
- Ollama — Local LLM inference (ollama.com)
- Claude via Microsoft Foundry — Anthropic models deployed in Azure
- Microsoft Foundry — Azure AI Foundry projects with multiple models
- Docker — For building and deploying hosted agents
- Visual Studio 2025 or VS Code — Recommended for development
Before running samples, configure your AI provider:
- Azure OpenAI Setup — Configure Azure OpenAI credentials
- Ollama Setup — Install and run Ollama locally
cd samples/MAF/<sample-name>
dotnet user-secrets set "AzureOpenAI:Endpoint" "https://<your-endpoint>.openai.azure.com/"
dotnet user-secrets set "AzureOpenAI:Deployment" "gpt-5-mini"
# az login is required (samples use AzureCliCredential)Start here to learn the basics of MAF with simple agents.
| Sample | Description | Difficulty | Key Concepts |
|---|---|---|---|
| MAF01 | Basic single-agent chat with Azure OpenAI | 🟢 Beginner | Agent creation, RunAsync(), Azure OpenAI |
| MAF02 | Sequential workflow with two agents (Writer & Editor) | 🟢 Beginner | AgentWorkflowBuilder, sequential workflows, agent composition |
| MAF-Ollama-01 | Single agent using local Ollama model | 🟢 Beginner | Ollama integration, local inference, provider flexibility |
Quick Start:
cd samples/MAF/MAF01
dotnet user-secrets set "AzureOpenAI:Endpoint" "https://<your-endpoint>.openai.azure.com/"
dotnet user-secrets set "AzureOpenAI:Deployment" "gpt-5-mini"
# az login is required (samples use AzureCliCredential)
dotnet runWork with Azure AI Foundry projects and managed deployments.
| Sample | Description | Difficulty | Key Concepts |
|---|---|---|---|
| MAF-AIFoundry-01 | Basic agent using Azure Foundry with managed identity | 🟡 Intermediate | Azure Foundry, managed identity, AzureCliCredential |
| MAF-AIFoundry-02 | Advanced Foundry integration with AI Projects API | 🟡 Intermediate | AIProjectClient, Foundry-specific APIs, advanced setup |
| MAF-AIFoundryAgents-01 | Creating and managing agents in Microsoft Foundry | 🔴 Advanced | Persistent agents, Foundry resource management, agent lifecycle |
Setup:
az login # Authenticate with Azure CLI
dotnet user-secrets set "azureFoundryProjectEndpoint" "https://<resource>.services.ai.azure.com/"
dotnet user-secrets set "AzureOpenAI:Deployment" "gpt-5-mini"Deploy persistent agents in Microsoft Foundry with full lifecycle management.
| Sample | Description | Difficulty | Key Concepts |
|---|---|---|---|
| MAF-MicrosoftFoundryAgents-01 | Create agents in Microsoft Foundry with conversation loop | 🟡 Intermediate | AIProjectClient, agent persistence, interactive chat |
| MAF-MicrosoftFoundryAgents-02 | Advanced agent management and orchestration | 🔴 Advanced | Agent scaling, resource management, advanced workflows |
Run:
cd samples/MAF/MAF-MicrosoftFoundryAgents-01
dotnet user-secrets set "azureFoundryProjectEndpoint" "https://<resource>.services.ai.azure.com/"
dotnet user-secrets set "agentName" "my-agent"
dotnet runOrchestrate multiple specialized agents working together.
| Sample | Description | Difficulty | Key Concepts |
|---|---|---|---|
| MAF-MultiAgents | Three agents (Researcher, Writer, Reviewer) using multiple providers | 🔴 Advanced | Multi-provider orchestration, sequential workflows, OpenTelemetry, Foundry agents |
| MAF-MultiAgents-Factory-01 | Agent factory pattern for dynamic agent creation | 🔴 Advanced | Factory design pattern, agent composition, configuration-driven setup |
| MAF-MultiModel | Researcher, Writer, and Reviewer agents with mixed providers | 🔴 Advanced | Azure OpenAI + Ollama, workflow composition, multi-model inference |
Run:
cd samples/MAF/MAF-MultiAgents
dotnet user-secrets set "AZURE_FOUNDRY_PROJECT_ENDPOINT" "https://<resource>.services.ai.azure.com/"
dotnet user-secrets set "AzureOpenAI:Endpoint" "https://<openai-resource>.openai.azure.com/"
dotnet user-secrets set "AzureOpenAI:Deployment" "gpt-5-mini"
# az login is required (samples use AzureCliCredential)
ollama pull llama3.2
dotnet runDemonstrate streaming responses and background processing.
| Sample | Description | Difficulty | Key Concepts |
|---|---|---|---|
| MAF-BackgroundResponses-01-Simple | Stream responses with continuation tokens | 🟡 Intermediate | RunStreamingAsync(), continuation tokens, response management |
| MAF-BackgroundResponses-02-Tools | Streaming with tool integration | 🔴 Advanced | Streaming + tool calling, token continuation with functions |
| MAF-BackgroundResponses-03-Complex | Advanced streaming with complex workflows | 🔴 Advanced | Complex streaming scenarios, error handling, performance optimization |
Run:
cd samples/MAF/MAF-BackgroundResponses-01-Simple
dotnet user-secrets set "AzureOpenAI:Endpoint" "https://<your-endpoint>.openai.azure.com/"
dotnet user-secrets set "AzureOpenAI:Deployment" "gpt-5-mini"
# az login is required (samples use AzureCliCredential)
dotnet runSave and resume agent conversations across sessions.
| Sample | Description | Difficulty | Key Concepts |
|---|---|---|---|
| MAF-Persisting-01-Simple | Serialize and deserialize agent threads | 🟢 Beginner | AgentThread, serialization, DeserializeThread() |
| MAF-Persisting-02-Menu | Interactive menu-driven persistence demo | 🟡 Intermediate | File-based persistence, session management, user interaction |
| MAF-FoundryClaude-Persisting-01 | Persist Claude agent conversations | 🟡 Intermediate | Thread serialization with Claude, conversation resumption |
Run:
cd samples/MAF/MAF-Persisting-01-Simple
dotnet user-secrets set "AzureOpenAI:Endpoint" "https://<your-endpoint>.openai.azure.com/"
dotnet user-secrets set "AzureOpenAI:Deployment" "gpt-5-mini"
# az login is required (samples use AzureCliCredential)
dotnet runFull-featured Blazor Server web applications with chat interfaces.
| Sample | Description | Difficulty | Key Concepts |
|---|---|---|---|
| MAF-AIWebChatApp-Simple | Basic Blazor chat with OpenAI models | 🟡 Intermediate | Blazor Server, ASP.NET Aspire, OpenAI integration, web UI |
| MAF-AIWebChatApp-Middleware | Web chat with custom middleware | 🟡 Intermediate | Middleware patterns, request/response processing, custom HTTP handlers |
| MAF-AIWebChatApp-MutliAgent | Web interface for multi-agent workflows | 🔴 Advanced | Multi-agent web UI, workflow orchestration in web context |
| MAF-AIWebChatApp-AG-UI | Advanced UI with rich components | 🔴 Advanced | Complex Blazor components, rich UI interactions, performance optimization |
| MAF-AIWebChatApp-Persisting | Web chat with conversation persistence | 🔴 Advanced | Web-based persistence, session management, state tracking |
Run:
cd samples/MAF/MAF-AIWebChatApp-Simple/ChatApp20
dotnet run # Opens Aspire dashboard and web appAI-powered image generation samples.
| Sample | Description | Difficulty | Key Concepts |
|---|---|---|---|
| MAF-ImageGen-01 | Basic image generation with Azure OpenAI | 🟡 Intermediate | DALL-E API, image generation, Azure OpenAI vision |
| MAF-ImageGen-02 | Advanced image generation with refinement | 🔴 Advanced | Image generation workflows, prompt engineering, advanced DALL-E features |
Run:
cd samples/MAF/MAF-ImageGen-01
dotnet user-secrets set "AzureOpenAI:Endpoint" "https://<your-endpoint>.openai.azure.com/"
dotnet user-secrets set "AzureOpenAI:Deployment" "gpt-5-mini"
# az login is required (samples use AzureCliCredential)
dotnet runWork with Anthropic Claude models via Microsoft Foundry.
| Sample | Description | Difficulty | Key Concepts |
|---|---|---|---|
| MAF-FoundryClaude-01 | Basic chat with Claude via Microsoft Foundry | 🟡 Intermediate | Claude integration, AzureClaudeClient, elbruno.Extensions.AI.Claude |
| MAF-AIWebChatApp-FoundryClaude | Blazor web chat with Claude models | 🟡 Intermediate | Web chat UI, Claude in Blazor, dependency injection, real-time chat |
Setup:
cd samples/MAF/MAF-FoundryClaude-01
dotnet user-secrets set "endpointClaude" "https://<resource>.services.ai.azure.com/anthropic/v1/messages"
dotnet user-secrets set "apikey" "<your-api-key>"
dotnet user-secrets set "deploymentName" "claude-haiku-4-5"
dotnet runDeploy agents as containers to Azure Foundry Agent Service.
| Sample | Description | Difficulty | Key Concepts |
|---|---|---|---|
| MAF-HostedAgent-01-TimeZone | Single agent with tool calling, containerized for Foundry | 🟡 Intermediate | Tool functions, Docker containerization, agent manifests, agent.yaml |
| MAF-HostedAgent-02-MultiAgent | Multi-agent workflow for containerized deployment | 🔴 Advanced | Sequential workflows in containers, agent orchestration, Foundry deployment |
Build and Run Locally:
cd samples/MAF/MAF-HostedAgent-01-TimeZone
dotnet build
dotnet run
# Build Docker image
docker build -t timezone-agent:latest .
# Run in Docker
docker run -it --rm \
-e AZURE_OPENAI_ENDPOINT="https://<your-resource>.openai.azure.com/" \
-e AZURE_OPENAI_MODEL="gpt-5-mini" \
-e AZURE_OPENAI_APIKEY="<your-api-key>" \
timezone-agent:latest- MAF01 — Create your first agent
- MAF02 — Chain agents with workflows
- MAF-Ollama-01 — Work with local models
- MAF-Persisting-01-Simple — Save conversations
- MAF-AIWebChatApp-Simple — Build a web chat app
- MAF-MultiAgents — Orchestrate multiple agents
- MAF-HostedAgent-01-TimeZone — Deploy as a container
- MAF-AIFoundry-01 — Use Microsoft Foundry
- MAF-MultiModel — Mix Azure OpenAI + Ollama
- MAF-FoundryClaude-01 — Integrate Claude
- MAF-BackgroundResponses-01-Simple — Implement streaming
- MAF-HostedAgent-02-MultiAgent — Complex hosted agents
using Microsoft.Extensions.AI;
using Microsoft.Agents.AI;
using Azure.AI.OpenAI;
var client = new AzureOpenAIClient(...).GetChatClient("gpt-5-mini").AsIChatClient();
AIAgent agent = client.AsAIAgent(
name: "MyAgent",
instructions: "You are a helpful assistant...");
AgentResponse response = await agent.RunAsync("What is AI?");
Console.WriteLine(response.Text);using Microsoft.Agents.AI.Workflows;
AIAgent agent1 = ...;
AIAgent agent2 = ...;
Workflow workflow = AgentWorkflowBuilder.BuildSequential(agent1, agent2);
AIAgent workflowAgent = workflow.AsAIAgent();
AgentResponse result = await workflowAgent.RunAsync("Start processing...");var thread = agent.GetNewThread();
var response = await agent.RunAsync("Hello!", thread);
// Save thread
var json = thread.Serialize(JsonSerializerOptions.Web).GetRawText();
await File.WriteAllTextAsync("thread.json", json);
// Load thread later
var loaded = JsonSerializer.Deserialize<JsonElement>(await File.ReadAllTextAsync("thread.json"));
thread = agent.DeserializeThread(loaded, JsonSerializerOptions.Web);
response = await agent.RunAsync("Continue...", thread);AIAgent agent = client.AsAIAgent(
name: "ToolAgent",
instructions: "You are helpful...",
tools: [
AIFunctionFactory.Create(GetWeather),
AIFunctionFactory.Create(GetTime)
]);
static string GetWeather(string location) => $"Sunny in {location}";
static string GetTime() => DateTime.Now.ToString();- Microsoft Agent Framework — Complete MAF documentation
- Microsoft.Extensions.AI — AI extensions guide
- Azure Foundry Agents — Foundry agent documentation
- Lesson 01: Introduction to Generative AI — Foundational concepts
- Lesson 02: Generative AI Techniques — Advanced patterns
- Lesson 04: Agents with MAF — Agent-specific content
- Setup Azure OpenAI
- Setup Ollama
- Project README — Course overview
- CONTRIBUTING.MD — Contribution guidelines
Problem: InvalidOperationException: Missing configuration
- Solution: Check user secrets are set correctly:
dotnet user-secrets list - For Azure:
az loginto authenticate
Problem: 403 Forbidden from Azure OpenAI
- Solution: Verify API key, endpoint, and deployment name match your Azure resource
Problem: Ollama connection refused
- Solution: Ensure Ollama is running:
ollama run llama3.2
Problem: Claude model not found
- Solution: Verify Claude is deployed in Microsoft Foundry and deployment name is correct
Problem: .csproj build fails
- Solution: Run
dotnet restorefirst, thendotnet build
Problem: Docker build fails
- Solution: Ensure Docker is installed and running:
docker --version
Found an issue or have an improvement? Please see CONTRIBUTING.MD for guidelines.
These samples are part of the Generative AI for Beginners .NET course and follow the repository's MIT License.
Happy building! 🚀