This sample demonstrates how to orchestrate multiple AI agents using different AI providers in a sequential workflow with the Microsoft Agent Framework.
This demo showcases a real-world scenario where three specialized agents collaborate to research, write, and review an article:
- Researcher Agent (Microsoft Foundry Persistent Agent) - Researches topics and gathers key information
- Writer Agent (Azure OpenAI) - Creates engaging content based on research
- Reviewer Agent (Ollama local model) - Reviews the article and provides constructive feedback
The workflow demonstrates:
- Multi-provider orchestration: Using different AI services (Microsoft Foundry, Azure OpenAI, and Ollama) in a single workflow
- Sequential agent workflows: Agents execute in order, with each building on the previous agent's output
- Persistent agents: Creating and managing agents in Microsoft Foundry
- OpenTelemetry tracing: Monitoring agent execution with distributed tracing
- Flexible configuration: Supporting multiple authentication methods and providers
User Input
↓
Researcher (Microsoft Foundry Agent)
↓ (research findings)
Writer (Azure OpenAI)
↓ (article draft)
Reviewer (Ollama - llama3.2)
↓
Final Output (reviewed article with feedback)
Before running this sample, ensure you have:
- .NET 10 SDK or later installed
- Azure CLI installed and authenticated (
az login) - Ollama installed and running locally with the
llama3.2model - Microsoft Foundry Project with access to deploy models
- One of the following for Agent 2 (Writer):
- Azure OpenAI endpoint and API key
- Azure OpenAI endpoint with managed identity/Azure CLI credentials
Ollama is required for the Reviewer agent (Agent 3).
# Install Ollama from https://ollama.com
# Pull the llama3.2 model
ollama pull llama3.2
# Verify Ollama is running (should respond on http://localhost:11434/)
ollama run llama3.2This application uses .NET user secrets to store sensitive configuration. Navigate to the project directory and set the required secrets:
cd 06-MAF/src/MAF-MultiAgents# Set your Microsoft Foundry project endpoint
dotnet user-secrets set "AZURE_FOUNDRY_PROJECT_ENDPOINT" "https://<your-project>.services.ai.azure.com/"
# Set your model deployment name (default: gpt-5-mini)
dotnet user-secrets set "deploymentName" "gpt-5-mini"Choose ONE of the following options:
dotnet user-secrets set "deploymentName" "gpt-5-mini"To create a GitHub token:
- Go to https://github.com/settings/tokens
- Click "Generate new token (classic)"
- Select scopes as needed
- Copy the token and use it above
Option B: Azure OpenAI with API Key
dotnet user-secrets set "AzureOpenAI:Endpoint" "https://<your-resource>.openai.azure.com/"
dotnet user-secrets set "AzureOpenAI:ApiKey" "your-azure-openai-api-key"
dotnet user-secrets set "AzureOpenAI:Deployment" "gpt-5-mini"Option C: Azure OpenAI with DefaultAzureCredential (Recommended)
dotnet user-secrets set "AzureOpenAI:Endpoint" "https://<your-resource>.openai.azure.com/"
dotnet user-secrets set "AzureOpenAI:Deployment" "gpt-5-mini"
az login # Required for DefaultAzureCredentialThe Researcher agent uses Azure CLI credentials to authenticate with Microsoft Foundry:
# Login to Azure CLI
az login
# Verify your authentication
az account showThe application automatically selects the chat client provider in the following order:
- Azure OpenAI with API Key - If
apikeyis set - Azure OpenAI with Default Credentials - Fallback using Azure CLI or managed identity
Once all secrets are configured, run the application:
dotnet build
dotnet runThe console will display:
- Agent setup messages for each of the three agents
- Workflow creation confirmation
- OpenTelemetry tracing output showing agent execution
- The final article with research, writing, and review feedback
- A prompt asking if you want to delete the persistent agent from Microsoft Foundry
=== Microsoft Agent Framework - Multi-Model Orchestration Demo ===
This demo showcases 3 agents working together:
1. Researcher (Microsoft Foundry Agent) - Researches topics
2. Writer (Azure OpenAI) - Writes content based on research
3. Reviewer (Ollama - llama3.2) - Reviews and provides feedback
Setting up Agent 1: Researcher (Microsoft Foundry Agent)...
Setting up Agent 2: Writer (Azure OpenAI)...
Setting up Agent 3: Reviewer (Ollama)...
Creating workflow: Researcher -> Writer -> Reviewer
Starting workflow with topic: 'artificial intelligence in healthcare'
================================================================================
[OpenTelemetry traces shown here...]
=== Final Output ===
[Reviewed article with feedback...]
================================================================================
Workflow completed successfully!
=== Clean Up ===
Do you want to delete the Researcher agent in Microsoft Foundry? (yes/no)
MAF-MultiAgents/
├── Program.cs # Main workflow orchestration
├── AIFoundryAgentsProvider.cs # Microsoft Foundry agent factory
├── ChatClientProvider.cs # Multi-provider chat client factory
├── AppConfigurationService.cs # Configuration management
├── MAF-MultiAgents.csproj # Project dependencies
└── README.md # This file
Creates and manages persistent agents in Microsoft Foundry:
CreateAIAgent()- Creates a new persistent agentDeleteAIAgentInAIFoundry()- Removes agents from Microsoft Foundry
Factory class for creating chat clients with different providers:
GetChatClient()- Returns a chat client based on available configuration (Azure OpenAI)GetChatClientOllama()- Returns an Ollama chat client for local inference
Centralized configuration service that reads from:
- User secrets
- Environment variables
Edit the topic variable in Program.cs:
var topic = "artificial intelligence in healthcare";Update the Instructions property for any agent:
AIAgent researcher = new ChatClientAgent(
azureChatClient,
new ChatClientAgentOptions
{
Name = "Researcher",
Instructions = "Your custom instructions here..."
});Change the model for any provider:
- Azure OpenAI: Update
deploymentNamesecret with your deployment name - Ollama: Modify the model parameter in
GetChatClientOllama()call
Extend the workflow by adding additional agents:
AIAgent seoOptimizer = new ChatClientAgent(
chatClient,
new ChatClientAgentOptions
{
Name = "SEO Optimizer",
Instructions = "Optimize the article for search engines."
});
Workflow workflow = AgentWorkflowBuilder
.BuildSequential(researcher, writer, reviewer, seoOptimizer);Issue: "Azure CLI credentials not found"
- Solution: Run
az loginto authenticate with Azure CLI
Issue: "Ollama connection refused"
- Solution: Ensure Ollama is running (
ollama run llama3.2) and accessible at http://localhost:11434/
Issue: "Model deployment not found"
- Solution: Verify your
deploymentNamesecret matches an actual deployment in your Azure OpenAI or AI Foundry resource
Issue: "GitHub token authentication failed"
- Solution: Verify your GitHub token is valid and has the required permissions
Issue: "Microsoft Foundry endpoint not found"
- Solution: Check that your
AZURE_FOUNDRY_PROJECT_ENDPOINTis correct and accessible
- Microsoft Agent Framework Documentation
- Microsoft.Extensions.AI Documentation
- Microsoft Foundry
- Ollama Documentation
- OpenTelemetry for .NET
After exploring this sample:
- Try modifying the agent instructions to see how it affects the output
- Experiment with different AI models for each agent
- Add additional agents to create more complex workflows
- Explore the OpenTelemetry traces to understand agent execution patterns
- Integrate with other MCP servers for additional capabilities
Note: This sample uses preview versions of Microsoft Agent Framework packages. Check for updates regularly as the framework evolves.