Skip to content

Commit 3a6bc38

Browse files
committed
Add missing anthropic c# doc
1 parent 5e8a7ae commit 3a6bc38

1 file changed

Lines changed: 133 additions & 4 deletions

File tree

agent-framework/user-guide/agents/agent-types/anthropic-agent.md

Lines changed: 133 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
title: Anthropic Agents
33
description: Learn how to use the Microsoft Agent Framework with Anthropic's Claude models.
44
zone_pivot_groups: programming-languages
5-
author: eavanvalkenburg
5+
author: eavanvalkenburg, rogerbarreto
66
ms.topic: tutorial
7-
ms.author: edvan
8-
ms.date: 11/05/2025
7+
ms.author: edvan, rbarreto
8+
ms.date: 12/12/2025
99
ms.service: agent-framework
1010
---
1111

@@ -15,7 +15,136 @@ The Microsoft Agent Framework supports creating agents that use [Anthropic's Cla
1515

1616
::: zone pivot="programming-language-csharp"
1717

18-
Coming soon...
18+
## Getting Started
19+
20+
Add the required NuGet packages to your project.
21+
22+
```powershell
23+
dotnet add package Microsoft.Agents.AI.Anthropic --prerelease
24+
```
25+
26+
If you're using Azure Foundry, also add:
27+
28+
```powershell
29+
dotnet add package Anthropic.Foundry --prerelease
30+
dotnet add package Azure.Identity
31+
```
32+
33+
## Configuration
34+
35+
### Environment Variables
36+
37+
Set up the required environment variables for Anthropic authentication:
38+
39+
```powershell
40+
# Required for Anthropic API access
41+
$env:ANTHROPIC_API_KEY="your-anthropic-api-key"
42+
$env:ANTHROPIC_DEPLOYMENT_NAME="claude-haiku-4-5" # or your preferred model
43+
```
44+
45+
You can get an API key from the [Anthropic Console](https://console.anthropic.com/).
46+
47+
### For Azure Foundry with API Key
48+
49+
```powershell
50+
$env:ANTHROPIC_RESOURCE="your-foundry-resource-name" # Subdomain before .services.ai.azure.com
51+
$env:ANTHROPIC_API_KEY="your-anthropic-api-key"
52+
$env:ANTHROPIC_DEPLOYMENT_NAME="claude-haiku-4-5"
53+
```
54+
55+
### For Azure Foundry with Azure CLI
56+
57+
```powershell
58+
$env:ANTHROPIC_RESOURCE="your-foundry-resource-name" # Subdomain before .services.ai.azure.com
59+
$env:ANTHROPIC_DEPLOYMENT_NAME="claude-haiku-4-5"
60+
```
61+
62+
> [!NOTE]
63+
> 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).
64+
65+
## Creating an Anthropic Agent
66+
67+
### Basic Agent Creation (Anthropic Public API)
68+
69+
The simplest way to create an Anthropic agent using the public API:
70+
71+
```csharp
72+
var apiKey = Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY");
73+
var deploymentName = Environment.GetEnvironmentVariable("ANTHROPIC_DEPLOYMENT_NAME") ?? "claude-haiku-4-5";
74+
75+
AnthropicClient client = new() { APIKey = apiKey };
76+
77+
AIAgent agent = client.CreateAIAgent(
78+
model: deploymentName,
79+
name: "HelpfulAssistant",
80+
instructions: "You are a helpful assistant.");
81+
82+
// Invoke the agent and output the text result.
83+
Console.WriteLine(await agent.RunAsync("Hello, how can you help me?"));
84+
```
85+
86+
### Using Anthropic on Azure Foundry with API Key
87+
88+
After you've set up Anthropic on Azure Foundry, you can use it with API key authentication:
89+
90+
```csharp
91+
var resource = Environment.GetEnvironmentVariable("ANTHROPIC_RESOURCE");
92+
var apiKey = Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY");
93+
var deploymentName = Environment.GetEnvironmentVariable("ANTHROPIC_DEPLOYMENT_NAME") ?? "claude-haiku-4-5";
94+
95+
AnthropicClient client = new AnthropicFoundryClient(
96+
new AnthropicFoundryApiKeyCredentials(apiKey, resource));
97+
98+
AIAgent agent = client.CreateAIAgent(
99+
model: deploymentName,
100+
name: "FoundryAgent",
101+
instructions: "You are a helpful assistant using Anthropic on Azure Foundry.");
102+
103+
Console.WriteLine(await agent.RunAsync("How do I use Anthropic on Foundry?"));
104+
```
105+
106+
### Using Anthropic on Azure Foundry with Azure Credentials (Azure Cli Credential example)
107+
108+
For environments where Azure Credentials are preferred:
109+
110+
```csharp
111+
var resource = Environment.GetEnvironmentVariable("ANTHROPIC_RESOURCE");
112+
var deploymentName = Environment.GetEnvironmentVariable("ANTHROPIC_DEPLOYMENT_NAME") ?? "claude-haiku-4-5";
113+
114+
AnthropicClient client = new AnthropicFoundryClient(
115+
new AnthropicAzureTokenCredential(new AzureCliCredential(), resource));
116+
117+
AIAgent agent = client.CreateAIAgent(
118+
model: deploymentName,
119+
name: "FoundryAgent",
120+
instructions: "You are a helpful assistant using Anthropic on Azure Foundry.");
121+
122+
Console.WriteLine(await agent.RunAsync("How do I use Anthropic on Foundry?"));
123+
124+
/// <summary>
125+
/// Provides methods for invoking the Azure hosted Anthropic models using <see cref="TokenCredential"/> types.
126+
/// </summary>
127+
public sealed class AnthropicAzureTokenCredential(TokenCredential tokenCredential, string resourceName) : IAnthropicFoundryCredentials
128+
{
129+
/// <inheritdoc/>
130+
public string ResourceName { get; } = resourceName;
131+
132+
/// <inheritdoc/>
133+
public void Apply(HttpRequestMessage requestMessage)
134+
{
135+
requestMessage.Headers.Authorization = new AuthenticationHeaderValue(
136+
scheme: "bearer",
137+
parameter: tokenCredential.GetToken(new TokenRequestContext(scopes: ["https://ai.azure.com/.default"]), CancellationToken.None)
138+
.Token);
139+
}
140+
}
141+
```
142+
143+
## Using the Agent
144+
145+
The agent is a standard `AIAgent` and supports all standard agent operations.
146+
147+
See the [Agent getting started tutorials](../../../tutorials/overview.md) for more information on how to run and interact with agents.
19148

20149
::: zone-end
21150
::: zone pivot="programming-language-python"

0 commit comments

Comments
 (0)