Skip to content

Commit 3dde166

Browse files
authored
Merge pull request #957 from MicrosoftDocs/foundry-updates-0002
Migrate C# samples to AIProjectClient and update Microsoft Foundry provider docs
2 parents ac568d7 + cd10f2f commit 3dde166

37 files changed

Lines changed: 338 additions & 298 deletions

agent-framework/agents/agent-pipeline.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,10 @@ The chat client layer handles the actual communication with the LLM service.
157157
`ChatClientAgent` uses an `IChatClient` instance, which can be decorated with additional middleware:
158158

159159
```csharp
160-
var chatClient = new AzureOpenAIClient(endpoint, credential)
161-
.GetChatClient(deploymentName)
162-
.AsIChatClient()
160+
var chatClient = new AIProjectClient(endpoint, credential)
161+
.GetProjectOpenAIClient()
162+
.GetProjectResponsesClient()
163+
.AsIChatClient(deploymentName)
163164
.AsBuilder()
164165
.Use(CustomChatClientMiddleware)
165166
.Build();
@@ -170,9 +171,10 @@ var agent = new ChatClientAgent(chatClient, instructions: "You are helpful.");
170171
You can also use `AIContextProvider` as chat client middleware to enrich messages, tools, and instructions at the client level. This must be used within the context of a running `AIAgent`:
171172

172173
```csharp
173-
var chatClient = new AzureOpenAIClient(endpoint, credential)
174-
.GetChatClient(deploymentName)
175-
.AsIChatClient()
174+
var chatClient = new AIProjectClient(endpoint, credential)
175+
.GetProjectOpenAIClient()
176+
.GetProjectResponsesClient()
177+
.AsIChatClient(deploymentName)
176178
.AsBuilder()
177179
.UseAIContextProviders(new MyContextProvider())
178180
.Build();

agent-framework/agents/background-responses.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ Some agents may not allow explicit control over background responses. These agen
5555
For non-streaming scenarios, when you initially run an agent, it may or may not return a continuation token. If no continuation token is returned, it means the operation has completed. If a continuation token is returned, it indicates that the agent has initiated a background response that is still processing and will require polling to retrieve the final result:
5656

5757
```csharp
58-
AIAgent agent = new AzureOpenAIClient(
59-
new Uri("https://<myresource>.openai.azure.com"),
58+
AIAgent agent = new AIProjectClient(
59+
new Uri("<your-foundry-project-endpoint>"),
6060
new DefaultAzureCredential())
61-
.GetResponsesClient("<deployment-name>")
62-
.AsAIAgent();
61+
.AsAIAgent(model: "<deployment-name>", instructions: "You are a helpful assistant.");
6362

6463
AgentRunOptions options = new()
6564
{
@@ -100,11 +99,10 @@ Console.WriteLine(response.Text);
10099
In streaming scenarios, background responses work much like regular streaming responses - the agent streams all updates back to consumers in real-time. However, the key difference is that if the original stream gets interrupted, agents support stream resumption through continuation tokens. Each update includes a continuation token that captures the current state, allowing the stream to be resumed from exactly where it left off by passing this token to subsequent streaming API calls:
101100

102101
```csharp
103-
AIAgent agent = new AzureOpenAIClient(
104-
new Uri("https://<myresource>.openai.azure.com"),
102+
AIAgent agent = new AIProjectClient(
103+
new Uri("<your-foundry-project-endpoint>"),
105104
new DefaultAzureCredential())
106-
.GetResponsesClient("<deployment-name>")
107-
.AsAIAgent();
105+
.AsAIAgent(model: "<deployment-name>", instructions: "You are a helpful assistant.");
108106

109107
AgentRunOptions options = new()
110108
{

agent-framework/agents/declarative.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ Declarative agents allow you to define agent configuration using YAML or JSON fi
1818
The following example shows how to create a declarative agent from a YAML configuration:
1919

2020
```csharp
21-
using Azure.AI.OpenAI;
21+
using Azure.AI.Projects;
2222
using Azure.Identity;
2323
using Microsoft.Agents.AI;
24-
using Microsoft.Extensions.AI;
2524

2625
// Create the chat client
27-
IChatClient chatClient = new AzureOpenAIClient(
28-
new Uri("https://<myresource>.openai.azure.com"),
26+
IChatClient chatClient = new AIProjectClient(
27+
new Uri("<your-foundry-project-endpoint>"),
2928
new DefaultAzureCredential())
30-
.GetChatClient("gpt-4o-mini")
31-
.AsIChatClient();
29+
.GetProjectOpenAIClient()
30+
.GetProjectResponsesClient()
31+
.AsIChatClient("gpt-4o-mini");
3232

3333
// Define the agent using a YAML definition.
3434
var yamlDefinition =
@@ -67,6 +67,9 @@ await foreach (var update in agent!.RunStreamingAsync("Tell me a joke about a pi
6767
}
6868
```
6969

70+
> [!WARNING]
71+
> `DefaultAzureCredential` is convenient for development but requires careful consideration in production. In production, consider using a specific credential (e.g., `ManagedIdentityCredential`) to avoid latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
72+
7073
:::zone-end
7174

7275
:::zone pivot="programming-language-python"

agent-framework/agents/index.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,23 @@ Once you have created the OpenAIClient, you can get a sub client for the specifi
139139

140140
```csharp
141141
AIAgent agent = client
142-
.GetChatClient(model)
143-
.AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker");
142+
.AsAIAgent(model: model, instructions: "You are good at telling jokes.", name: "Joker");
144143
```
145144

146-
### Using the Azure OpenAI SDK
145+
### Using the Azure AI Projects SDK
147146

148-
This SDK can be used to connect to both Azure OpenAI and Foundry Models services.
149-
Either way, you will need to supply the correct service URL when creating the `AzureOpenAIClient`.
147+
This SDK can be used to connect to Foundry services.
148+
You will need to supply the correct project endpoint URL when creating the `AIProjectClient`.
150149
See the table above for the correct URL to use.
151150

152151
```csharp
153-
AIAgent agent = new AzureOpenAIClient(
152+
AIAgent agent = new AIProjectClient(
154153
new Uri(serviceUrl),
155154
new DefaultAzureCredential())
156-
.GetChatClient(deploymentName)
157-
.AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker");
155+
.AsAIAgent(
156+
model: deploymentName,
157+
instructions: "You are good at telling jokes.",
158+
name: "Joker");
158159
```
159160

160161
### Using the Azure AI Persistent Agents SDK

agent-framework/agents/middleware/defining-middleware.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ var chatClient = new AIProjectClient(
184184
new Uri("<your-foundry-project-endpoint>"),
185185
new DefaultAzureCredential())
186186
.GetProjectOpenAIClient()
187-
.GetResponsesClient()
187+
.GetProjectResponsesClient()
188188
.AsIChatClient("gpt-4o-mini");
189189

190190
var middlewareEnabledChatClient = chatClient

agent-framework/agents/middleware/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var chatClient = new AIProjectClient(
4747
new Uri("<your-foundry-project-endpoint>"),
4848
new DefaultAzureCredential())
4949
.GetProjectOpenAIClient()
50-
.GetResponsesClient()
50+
.GetProjectResponsesClient()
5151
.AsIChatClient(deploymentName);
5252

5353
var middlewareEnabledChatClient = chatClient

agent-framework/agents/multimodal.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ You can send images to an agent by creating a `ChatMessage` that includes both t
2222
First, create an `AIAgent` that is able to analyze images.
2323

2424
```csharp
25-
AIAgent agent = new AzureOpenAIClient(
26-
new Uri("https://<myresource>.openai.azure.com"),
25+
AIAgent agent = new AIProjectClient(
26+
new Uri("<your-foundry-project-endpoint>"),
2727
new DefaultAzureCredential())
28-
.GetChatClient("gpt-4o")
2928
.AsAIAgent(
29+
model: "gpt-4o",
3030
name: "VisionAgent",
3131
instructions: "You are a helpful agent that can analyze images");
3232
```

agent-framework/agents/observability.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ Agent Framework integrates with [OpenTelemetry](https://opentelemetry.io/), and
2626
To enable observability for your chat client, you need to build the chat client as follows:
2727

2828
```csharp
29-
// Using the Azure OpenAI client as an example
30-
var instrumentedChatClient = new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
31-
.GetChatClient(deploymentName)
32-
.AsIChatClient() // Converts a native OpenAI SDK ChatClient into a Microsoft.Extensions.AI.IChatClient
29+
// Using the AIProjectClient as an example
30+
var instrumentedChatClient = new AIProjectClient(new Uri(endpoint), new DefaultAzureCredential())
31+
.GetProjectOpenAIClient()
32+
.GetProjectResponsesClient()
33+
.AsIChatClient(deploymentName) // Converts into a Microsoft.Extensions.AI.IChatClient
3334
.AsBuilder()
3435
.UseOpenTelemetry(sourceName: SourceName, configure: (cfg) => cfg.EnableSensitiveData = true) // Enable OpenTelemetry instrumentation with sensitive data
3536
.Build();

agent-framework/agents/providers/microsoft-foundry.md

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,74 +21,78 @@ Add the required NuGet packages to your project.
2121

2222
```dotnetcli
2323
dotnet add package Azure.Identity
24-
dotnet add package Microsoft.Agents.AI.AzureAI.Persistent --prerelease
24+
dotnet add package Microsoft.Agents.AI.Foundry --prerelease
2525
```
2626

27-
## Create Foundry Agents
27+
## Two agent types
2828

29-
As a first step you need to create a client to connect to the Agent Service.
29+
The Microsoft Foundry integration exposes two distinct usage patterns:
30+
31+
| Type | Produced type | Description | Use when |
32+
|---|---|---|---|
33+
| **Responses Agent** | `ChatClientAgent` | Your app programmatically provides a model, instructions, and tools at runtime via `AIProjectClient.AsAIAgent(...)`. No server-side agent resource is created. | You own the agent definition and want a simple, flexible setup. This is the pattern used in most samples. |
34+
| **Foundry Agent** (versioned) | `FoundryAgent` | Server-managed — agent definitions are created and versioned either through the Foundry portal or programmatically via `AIProjectClient.Agents`. Pass an `AgentVersion` or `AgentRecord` or `AgentReference` to `AIProjectClient.AsAIAgent(...)`. | You need strict, versioned agent definitions managed in the Foundry portal, through service APIs |
35+
36+
## Responses Agent (direct inference)
37+
38+
Use `AsAIAgent` on `AIProjectClient` directly with a model and instructions. This is the recommended starting point for most scenarios.
3039

3140
```csharp
32-
using System;
33-
using Azure.AI.Agents.Persistent;
41+
using Azure.AI.Projects;
3442
using Azure.Identity;
3543
using Microsoft.Agents.AI;
3644

37-
var persistentAgentsClient = new PersistentAgentsClient(
38-
"https://<myresource>.services.ai.azure.com/api/projects/<myproject>",
39-
new DefaultAzureCredential());
45+
AIAgent agent = new AIProjectClient(
46+
new Uri("<your-foundry-project-endpoint>"),
47+
new DefaultAzureCredential())
48+
.AsAIAgent(
49+
model: "gpt-4o-mini",
50+
name: "Joker",
51+
instructions: "You are good at telling jokes.");
52+
53+
Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate."));
4054
```
4155

4256
> [!WARNING]
4357
> `DefaultAzureCredential` is convenient for development but requires careful consideration in production. In production, consider using a specific credential (e.g., `ManagedIdentityCredential`) to avoid latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
4458
45-
To use the Agent Service, you need create an agent resource in the service.
46-
This can be done using either the Azure.AI.Agents.Persistent SDK or using Microsoft Agent Framework helpers.
59+
This path is code-first and does not create a server-managed agent resource.
4760

48-
### Using the Persistent SDK
61+
## Foundry Agent (versioned)
4962

50-
Create a persistent agent and retrieve it as an `AIAgent` using the `PersistentAgentsClient`.
63+
Use the native `AIProjectClient.Agents` APIs from the AI Projects SDK to retrieve versioned agent resources, then wrap them with `AsAIAgent`. Agents can be created and configured directly in the Foundry portal or programmatically via `AIProjectClient.Agents`.
5164

5265
```csharp
53-
// Create a persistent agent
54-
var agentMetadata = await persistentAgentsClient.Administration.CreateAgentAsync(
55-
model: "gpt-4o-mini",
56-
name: "Joker",
57-
instructions: "You are good at telling jokes.");
58-
59-
// Retrieve the agent that was just created as an AIAgent using its ID
60-
AIAgent agent1 = await persistentAgentsClient.GetAIAgentAsync(agentMetadata.Value.Id);
61-
62-
// Invoke the agent and output the text result.
63-
Console.WriteLine(await agent1.RunAsync("Tell me a joke about a pirate."));
64-
```
66+
using Azure.AI.Projects;
67+
using Azure.AI.Projects.Agents;
68+
using Azure.Identity;
69+
using Microsoft.Agents.AI;
70+
using Microsoft.Agents.AI.Foundry;
6571

66-
### Using Agent Framework helpers
72+
var aiProjectClient = new AIProjectClient(
73+
new Uri("<your-foundry-project-endpoint>"),
74+
new DefaultAzureCredential());
6775

68-
You can also create and return an `AIAgent` in one step:
76+
// Retrieve an existing agent by name (uses the latest version automatically)
77+
AgentRecord jokerRecord = await aiProjectClient.Agents.GetAgentAsync("Joker");
78+
FoundryAgent agent = aiProjectClient.AsAIAgent(jokerRecord);
6979

70-
```csharp
71-
AIAgent agent2 = await persistentAgentsClient.CreateAIAgentAsync(
72-
model: "gpt-4o-mini",
73-
name: "Joker",
74-
instructions: "You are good at telling jokes.");
80+
Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate."));
7581
```
7682

77-
## Reusing Foundry Agents
83+
> [!IMPORTANT]
84+
> Foundry Agents tools and instructions are strict to the ones it was created with, attempting to modify tooling or instructions at runtime is not supported.
85+
86+
## Using the agent
7887

79-
You can reuse existing Foundry Agents by retrieving them using their IDs.
88+
Both `ChatClientAgent` (Responses) and `FoundryAgent` (versioned) are standard `AIAgent` instances and support all standard operations including sessions, tools, middleware, and streaming.
8089

8190
```csharp
82-
AIAgent agent3 = await persistentAgentsClient.GetAIAgentAsync("<agent-id>");
91+
AgentSession session = await agent.CreateSessionAsync();
92+
Console.WriteLine(await agent.RunAsync("Tell me a joke.", session));
93+
Console.WriteLine(await agent.RunAsync("Now make it funnier.", session));
8394
```
8495

85-
> [!TIP]
86-
> See the [.NET samples](https://github.com/microsoft/agent-framework/tree/main/dotnet/samples) for complete runnable examples.
87-
88-
## Using the agent
89-
90-
The agent is a standard `AIAgent` and supports all standard `AIAgent` operations.
91-
9296
For more information on how to run and interact with agents, see the [Agent getting started tutorials](../../get-started/your-first-agent.md).
9397

9498
::: zone-end

agent-framework/agents/skills.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ The Agent Framework includes a skills provider that discovers skills from filesy
8686
Create a `FileAgentSkillsProvider` pointing to a directory containing your skills, and add it to the agent's context providers:
8787

8888
```csharp
89-
using Azure.AI.OpenAI;
89+
using Azure.AI.Projects;
9090
using Azure.Identity;
9191
using Microsoft.Agents.AI;
9292

@@ -95,20 +95,23 @@ var skillsProvider = new FileAgentSkillsProvider(
9595
skillPath: Path.Combine(AppContext.BaseDirectory, "skills"));
9696

9797
// Create an agent with the skills provider
98-
AIAgent agent = new AzureOpenAIClient(
98+
AIAgent agent = new AIProjectClient(
9999
new Uri(endpoint), new DefaultAzureCredential())
100-
.GetResponsesClient(deploymentName)
101100
.AsAIAgent(new ChatClientAgentOptions
102101
{
103102
Name = "SkillsAgent",
104103
ChatOptions = new()
105104
{
105+
ModelId = deploymentName,
106106
Instructions = "You are a helpful assistant.",
107107
},
108108
AIContextProviders = [skillsProvider],
109109
});
110110
```
111111

112+
> [!WARNING]
113+
> `DefaultAzureCredential` is convenient for development but requires careful consideration in production. In production, consider using a specific credential (e.g., `ManagedIdentityCredential`) to avoid latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
114+
112115
### Invoking the agent
113116

114117
Once configured, the agent automatically discovers available skills and uses them when a task matches:

0 commit comments

Comments
 (0)