anthropic-agent
Learn how to use the Microsoft Agent Framework with Anthropic's Claude models.
$ npx -y skills add managedcode/dotnet-skills --agent claude-codeHow it fires
How this agent gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
Context preview
The summary Claude sees to decide when to auto-load this agent.
Learn how to use the Microsoft Agent Framework with Anthropic's Claude models.
Agent definition
anthropic-agent.mdtitle: Anthropic Agents
description: Learn how to use the Microsoft Agent Framework with Anthropic's Claude models.
zone_pivot_groups: programming-languages
author: rogerbarreto
ms.topic: tutorial
ms.author: rbarreto
ms.date: 03/11/2026
ms.service: agent-framework
Anthropic Agents
The Microsoft Agent Framework supports creating agents that use [Anthropic's Claude models](https://www.anthropic.com/claude).
::: zone pivot="programming-language-csharp"
Getting Started
Add the required NuGet packages to your project.
dotnet add package Microsoft.Agents.AI.Anthropic --prerelease
The `Microsoft.Agents.AI.Anthropic` package uses `Anthropic` 12.8.0 or later and supports Claude Haiku, Sonnet, and Opus model families.
If you're using Azure Foundry, also add:
dotnet add package Anthropic.Foundry --prerelease
dotnet add package Azure.Identity
Configuration
Environment Variables
Set up the required environment variables for Anthropic authentication:
# Required for Anthropic API access
$env:ANTHROPIC_API_KEY="your-anthropic-api-key"
$env:ANTHROPIC_DEPLOYMENT_NAME="claude-sonnet-4-5" # or your preferred model (e.g. claude-opus-4-5, claude-haiku-4-5)
> [!NOTE] > `claude-haiku-3` is deprecated. Prefer `claude-haiku-4-5`, `claude-sonnet-4-5`, `claude-sonnet-4-6`, or `claude-opus-4-5` for new workloads.
You can get an API key from the [Anthropic Console](https://console.anthropic.com/).
For Azure Foundry with API Key
$env:ANTHROPIC_RESOURCE="your-foundry-resource-name" # Subdomain before .services.ai.azure.com
$env:ANTHROPIC_API_KEY="your-anthropic-api-key"
$env:ANTHROPIC_DEPLOYMENT_NAME="claude-sonnet-4-5"
For Azure Foundry with Azure CLI
$env:ANTHROPIC_RESOURCE="your-foundry-resource-name" # Subdomain before .services.ai.azure.com
$env:ANTHROPIC_DEPLOYMENT_NAME="claude-sonnet-4-5"
> [!NOTE] > When using Azure Foundry with Azure CLI, make sure you're logged in with `az login` and have access to the Azure Foundry resource. For more information, see the [Azure CLI documentation](/cli/azure/authenticate-azure-cli-interactively).
Creating an Anthropic Agent
Basic Agent Creation (Anthropic Public API)
The simplest way to create an Anthropic agent using the public API:
var apiKey = Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY");
var deploymentName = Environment.GetEnvironmentVariable("ANTHROPIC_DEPLOYMENT_NAME") ?? "claude-sonnet-4-5";
AnthropicClient client = new() { APIKey = apiKey };
AIAgent agent = client.AsAIAgent(
model: deploymentName,
name: "HelpfulAssistant",
instructions: "You are a helpful assistant.");
// Invoke the agent and output the text result.
Console.WriteLine(await agent.RunAsync("Hello, how can you help me?"));Using Anthropic on Azure Foundry with API Key
After you've set up Anthropic on Azure Foundry, you can use it with API key authentication:
var resource = Environment.GetEnvironmentVariable("ANTHROPIC_RESOURCE");
var apiKey = Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY");
var deploymentName = Environment.GetEnvironmentVariable("ANTHROPIC_DEPLOYMENT_NAME") ?? "claude-sonnet-4-5";
AnthropicClient client = new AnthropicFoundryClient(
new AnthropicFoundryApiKeyCredentials(apiKey, resource));
AIAgent agent = client.AsAIAgent(
model: deploymentName,
name: "FoundryAgent",
instructions: "You are a helpful assistant using Anthropic on Azure Foundry.");
Console.WriteLine(await agent.RunAsync("How do I use Anthropic on Foundry?"));Using Anthropic on Azure Foundry with Azure Credentials (Azure Cli Credential example)
For environments where Azure Credentials are preferred:
var resource = Environment.GetEnvironmentVariable("ANTHROPIC_RESOURCE");
var deploymentName = Environment.GetEnvironmentVariable("ANTHROPIC_DEPLOYMENT_NAME") ?? "claude-sonnet-4-5";
AnthropicClient client = new AnthropicFoundryClient(
new AnthropicAzureTokenCredential(new AzureCliCredential(), resource));
AIAgent agent = client.AsAIAgent(
model: deploymentName,
name: "FoundryAgent",
instructions: "You are a helpful assistant using Anthropic on Azure Foundry.");
Console.WriteLine(await agent.RunAsync("How do I use Anthropic on Foundry?"));
/// <summary>
/// Provides methods for invoking the Azure hosted Anthropic models using <see cref="TokenCredential"/> types.
/// </summary>
public sealed class AnthropicAzureTokenCredential(TokenCredential tokenCredential, string resourceName) : IAnthropicFoundryCredentials
{
/// <inheritdoc/>
public string ResourceName { get; } = resourceName;
/// <inheritdoc/>
public void Apply(HttpRequestMessage requestMessage)
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue(
scheme: "bearer",
parameter: tokenCredential.GetToken(new TokenRequestContext(scopes: ["https://ai.azure.com/.default"]), CancellationToken.None)
.Token);
}
}Using the Agent
The agent is a standard `AIAgent` and supports all standard agent operations.
See the [Agent getting started tutorials](../../../tutorials/overview.md) for more information on how to run and interact with agents.
::: zone-end ::: zone pivot="programming-language-python"
Prerequisites
Install the Microsoft Agent Framework Anthropic package.
pip install agent-framework-anthropic --pre
Configuration
Environment Variables
Set up the required environment variables for Anthropic authentication:
# Required for Anthropic API access
ANTHROPIC_API_KEY="your-anthropic-api-key"
ANTHROPIC_CHAT_MODEL_ID="claude-sonnet-4-6-20260301" # or your preferred model
Alternatively, you can use a `.env` file in your project root:
ANTHROPIC_API_KEY=your-anthropic-api-key
ANTHROPIC_CHAT_MODEL_ID=claude-sonnet-4-6-20260301
You can get an API key fr
Read more
title: Anthropic Agents description: Learn how to use the Microsoft Agent Framework with Anthropic's Claude models. zone_pivot_groups: programming-languages author: rogerbarreto ms.topic: tutorial ms.author: rbarreto ms.date: 03/11/2026 ms.service: agent-framework
Anthropic Agents
The Microsoft Agent Framework supports creating agents that use [Anthropic's Claude models](https://www.anthropic.com/claude).
::: zone pivot="programming-language-csharp"
Getting Started
Add the required NuGet packages to your project.
dotnet add package Microsoft.Agents.AI.Anthropic --prerelease
The `Microsoft.Agents.AI.Anthropic` package uses `Anthropic` 12.8.0 or later and supports Claude Haiku, Sonnet, and Opus model families.
If you're using Azure Foundry, also add:
dotnet add package Anthropic.Foundry --prerelease dotnet add package Azure.Identity
Configuration
Environment Variables
Set up the required environment variables for Anthropic authentication:
# Required for Anthropic API access $env:ANTHROPIC_API_KEY="your-anthropic-api-key" $env:ANTHROPIC_DEPLOYMENT_NAME="claude-sonnet-4-5" # or your preferred model (e.g. claude-opus-4-5, claude-haiku-4-5)
> [!NOTE] > `claude-haiku-3` is deprecated. Prefer `claude-haiku-4-5`, `claude-sonnet-4-5`, `claude-sonnet-4-6`, or `claude-opus-4-5` for new workloads.
You can get an API key from the [Anthropic Console](https://console.anthropic.com/).
For Azure Foundry with API Key
$env:ANTHROPIC_RESOURCE="your-foundry-resource-name" # Subdomain before .services.ai.azure.com $env:ANTHROPIC_API_KEY="your-anthropic-api-key" $env:ANTHROPIC_DEPLOYMENT_NAME="claude-sonnet-4-5"
For Azure Foundry with Azure CLI
$env:ANTHROPIC_RESOURCE="your-foundry-resource-name" # Subdomain before .services.ai.azure.com $env:ANTHROPIC_DEPLOYMENT_NAME="claude-sonnet-4-5"
> [!NOTE] > When using Azure Foundry with Azure CLI, make sure you're logged in with `az login` and have access to the Azure Foundry resource. For more information, see the [Azure CLI documentation](/cli/azure/authenticate-azure-cli-interactively).
Creating an Anthropic Agent
Basic Agent Creation (Anthropic Public API)
The simplest way to create an Anthropic agent using the public API:
var apiKey = Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY");
var deploymentName = Environment.GetEnvironmentVariable("ANTHROPIC_DEPLOYMENT_NAME") ?? "claude-sonnet-4-5";
AnthropicClient client = new() { APIKey = apiKey };
AIAgent agent = client.AsAIAgent(
model: deploymentName,
name: "HelpfulAssistant",
instructions: "You are a helpful assistant.");
// Invoke the agent and output the text result.
Console.WriteLine(await agent.RunAsync("Hello, how can you help me?"));Using Anthropic on Azure Foundry with API Key
After you've set up Anthropic on Azure Foundry, you can use it with API key authentication:
var resource = Environment.GetEnvironmentVariable("ANTHROPIC_RESOURCE");
var apiKey = Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY");
var deploymentName = Environment.GetEnvironmentVariable("ANTHROPIC_DEPLOYMENT_NAME") ?? "claude-sonnet-4-5";
AnthropicClient client = new AnthropicFoundryClient(
new AnthropicFoundryApiKeyCredentials(apiKey, resource));
AIAgent agent = client.AsAIAgent(
model: deploymentName,
name: "FoundryAgent",
instructions: "You are a helpful assistant using Anthropic on Azure Foundry.");
Console.WriteLine(await agent.RunAsync("How do I use Anthropic on Foundry?"));Using Anthropic on Azure Foundry with Azure Credentials (Azure Cli Credential example)
For environments where Azure Credentials are preferred:
var resource = Environment.GetEnvironmentVariable("ANTHROPIC_RESOURCE");
var deploymentName = Environment.GetEnvironmentVariable("ANTHROPIC_DEPLOYMENT_NAME") ?? "claude-sonnet-4-5";
AnthropicClient client = new AnthropicFoundryClient(
new AnthropicAzureTokenCredential(new AzureCliCredential(), resource));
AIAgent agent = client.AsAIAgent(
model: deploymentName,
name: "FoundryAgent",
instructions: "You are a helpful assistant using Anthropic on Azure Foundry.");
Console.WriteLine(await agent.RunAsync("How do I use Anthropic on Foundry?"));
/// <summary>
/// Provides methods for invoking the Azure hosted Anthropic models using <see cref="TokenCredential"/> types.
/// </summary>
public sealed class AnthropicAzureTokenCredential(TokenCredential tokenCredential, string resourceName) : IAnthropicFoundryCredentials
{
/// <inheritdoc/>
public string ResourceName { get; } = resourceName;
/// <inheritdoc/>
public void Apply(HttpRequestMessage requestMessage)
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue(
scheme: "bearer",
parameter: tokenCredential.GetToken(new TokenRequestContext(scopes: ["https://ai.azure.com/.default"]), CancellationToken.None)
.Token);
}
}Using the Agent
The agent is a standard `AIAgent` and supports all standard agent operations.
See the [Agent getting started tutorials](../../../tutorials/overview.md) for more information on how to run and interact with agents.
::: zone-end ::: zone pivot="programming-language-python"
Prerequisites
Install the Microsoft Agent Framework Anthropic package.
pip install agent-framework-anthropic --pre
Configuration
Environment Variables
Set up the required environment variables for Anthropic authentication:
# Required for Anthropic API access ANTHROPIC_API_KEY="your-anthropic-api-key" ANTHROPIC_CHAT_MODEL_ID="claude-sonnet-4-6-20260301" # or your preferred model
Alternatively, you can use a `.env` file in your project root:
ANTHROPIC_API_KEY=your-anthropic-api-key ANTHROPIC_CHAT_MODEL_ID=claude-sonnet-4-6-20260301
You can get an API key fr
Stop explaining .NET to your AI. Start building. We've all been there: asking Claude to use Entity Framework, only to get EF6 patterns in a .NET 8 project. Explaining to Copilot that Blazor Server and Blazor WebAssembly aren't the same thing.
Repo: managedcode/dotnet-skills
Other agents on dotnet-skills.
- AGENT
Specialist orchestration agent for .NET Aspire work. Use when the problem is clearly about AppHost design, ServiceDefaults, first-party versus CommunityToolkit/Aspire integrations, dashboard and testing, `DistributedApplicationTestingBuilder`, `WebApplicationFactory`
Open agent - agent-as-function-tool
Legacy tutorial alias retained locally; the live Learn URL now resolves into the broader Function Tools surface
Open agent - agent-as-mcp-tool
Learn how to expose an agent as a tool over the MCP protocol
Open agent - create-and-run-durable-agent
Learn how to create and run a durable AI agent with Azure Functions and the durable task extension for Microsoft Agent Framework
Open agent - enable-observability
Enable OpenTelemetry for an agent so agent interactions are automatically logged
Open agent - function-tools-approvals
Learn how to use function tools with human in the loop approvals
Open agent

