Skip to main content

Overview

The Microsoft Agent Framework .NET SDK supports multiple AI providers through the IChatClient 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

DefaultAzureCredential is convenient for development but requires careful consideration in production. Use ManagedIdentityCredential or another specific credential to avoid latency and security risks.

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

  1. Install Ollama: https://ollama.ai/
  2. Pull a model: ollama pull llama3.2
  3. 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

Implement IChatClient for custom providers:

Provider Comparison

Switching Providers

The unified interface makes switching providers easy:

Best Practices

Never hardcode credentials. Use environment variables:
Not all providers support all features (e.g., function calling, structured output). Implement fallbacks:
Track token consumption across providers:
Choose models based on task requirements:
  • Fast/cheap: gpt-4o-mini, claude-haiku
  • Balanced: gpt-4o, claude-sonnet
  • Advanced: o1, claude-opus
  • Cloud providers: Higher latency, always available
  • Local models: Lower latency, offline capable, limited power
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