Overview
The Microsoft Agent Framework .NET SDK supports multiple AI providers through theIChatClient interface from Microsoft.Extensions.AI. This unified interface allows you to switch between providers with minimal code changes.
Supported Providers
The framework supports:- Azure OpenAI: Microsoft’s enterprise-grade OpenAI service
- OpenAI: Direct OpenAI API access
- Anthropic: Claude models (via Anthropic API or Azure AI Foundry)
- Google Gemini: Google’s Gemini models
- Ollama: Local open-source models
- ONNX Runtime: Local inference with ONNX models
- GitHub Copilot: GitHub’s Copilot models
- Azure AI Foundry: Multi-model access through Azure AI
- Custom: Build your own provider
Azure OpenAI
The recommended provider for enterprise applications.Using DefaultAzureCredential
Using API Key
Configuration
Set these environment variables:OpenAI
Direct access to OpenAI’s API.Configuration
Anthropic
Via Anthropic API
Via Azure AI Foundry
Configuration
Google Gemini
Using Google GenAI Client
Using Community Package
Configuration
Ollama
Run open-source models locally.Setup Ollama
- Install Ollama: https://ollama.ai/
- Pull a model:
ollama pull llama3.2 - Start server:
ollama serve
Configuration
ONNX Runtime
Local inference with ONNX models.Configuration
GitHub Copilot
Configuration
Azure AI Foundry
Access multiple models through Azure AI.Using Azure AI Project
Using Foundry Model
Configuration
Custom Provider
ImplementIChatClient for custom providers:
Provider Comparison
Switching Providers
The unified interface makes switching providers easy:Best Practices
Use Environment Variables for Configuration
Use Environment Variables for Configuration
Never hardcode credentials. Use environment variables:
Handle Provider-Specific Features Gracefully
Handle Provider-Specific Features Gracefully
Not all providers support all features (e.g., function calling, structured output). Implement fallbacks:
Monitor Token Usage
Monitor Token Usage
Track token consumption across providers:
Use Appropriate Models
Use Appropriate Models
Choose models based on task requirements:
- Fast/cheap:
gpt-4o-mini,claude-haiku - Balanced:
gpt-4o,claude-sonnet - Advanced:
o1,claude-opus
Consider Latency and Availability
Consider Latency and Availability
- Cloud providers: Higher latency, always available
- Local models: Lower latency, offline capable, limited power
Secure Credentials
Secure Credentials
For Azure providers, prefer managed identities in production:
Provider-Specific Packages
Install the appropriate NuGet package for your provider:Next Steps
Agents
Build agents with any provider
Tools
Add function calling (provider support varies)
Observability
Monitor provider performance
RAG
Combine providers with retrieval