Prerequisites
Before installing the Microsoft Agent Framework .NET SDK, ensure you have:- .NET 8.0 or later installed on your machine
- An Azure OpenAI resource or other supported AI provider
- Azure CLI (for authentication)
Install the SDK
The Microsoft Agent Framework is distributed as NuGet packages. Install the core package using the .NET CLI:Additional Packages
Depending on your provider and features, you may need additional packages:Set Up Authentication
Azure Authentication
The SDK usesDefaultAzureCredential from Azure.Identity for authentication. This supports multiple authentication methods:
Install Azure CLI
Download and install the Azure CLI.
DefaultAzureCredential is convenient for development but requires careful consideration in production. Consider using ManagedIdentityCredential or other specific credentials in production environments.Configure Environment Variables
Set up the required environment variables for your Azure OpenAI resource:Environment Variable Reference
| Variable | Description | Required |
|---|---|---|
AZURE_OPENAI_ENDPOINT | Your Azure OpenAI endpoint URL | Yes |
AZURE_OPENAI_DEPLOYMENT_NAME | Model deployment name (e.g., gpt-4o-mini, gpt-4) | No (defaults to gpt-4o-mini) |
Create a New Project
Create a new .NET console application to start building agents:Verify Your Setup
Create a simple test to verify your installation:Program.cs
Troubleshooting
Authentication errors
Authentication errors
Error:
Azure.Identity.AuthenticationFailedExceptionSolution: Ensure you’re logged in with az login and have the correct permissions for your Azure OpenAI resource.Missing environment variables
Missing environment variables
Error:
AZURE_OPENAI_ENDPOINT is not setSolution: Set the required environment variables as shown in the Configure Environment Variables section.Package version conflicts
Package version conflicts
Error: Package dependency conflictsSolution: Ensure you’re using compatible versions. The SDK requires .NET 8.0 or later and Microsoft.Extensions.AI 10.3.0 or later.
Deployment not found
Deployment not found
Error:
The API deployment for this resource does not existSolution: Verify your AZURE_OPENAI_DEPLOYMENT_NAME matches a deployment in your Azure OpenAI resource.Next Steps
Now that you have the SDK installed and configured:Quickstart
Learn the core concepts and build your first agent
Create Your First Agent
Build a complete agent with tools and streaming