You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -170,9 +171,10 @@ var agent = new ChatClientAgent(chatClient, instructions: "You are helpful.");
170
171
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`:
Copy file name to clipboardExpand all lines: agent-framework/agents/background-responses.md
+6-8Lines changed: 6 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,11 +55,10 @@ Some agents may not allow explicit control over background responses. These agen
55
55
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:
56
56
57
57
```csharp
58
-
AIAgentagent=newAzureOpenAIClient(
59
-
newUri("https://<myresource>.openai.azure.com"),
58
+
AIAgentagent=newAIProjectClient(
59
+
newUri("<your-foundry-project-endpoint>"),
60
60
newDefaultAzureCredential())
61
-
.GetResponsesClient("<deployment-name>")
62
-
.AsAIAgent();
61
+
.AsAIAgent(model: "<deployment-name>", instructions: "You are a helpful assistant.");
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:
101
100
102
101
```csharp
103
-
AIAgentagent=newAzureOpenAIClient(
104
-
newUri("https://<myresource>.openai.azure.com"),
102
+
AIAgentagent=newAIProjectClient(
103
+
newUri("<your-foundry-project-endpoint>"),
105
104
newDefaultAzureCredential())
106
-
.GetResponsesClient("<deployment-name>")
107
-
.AsAIAgent();
105
+
.AsAIAgent(model: "<deployment-name>", instructions: "You are a helpful assistant.");
Copy file name to clipboardExpand all lines: agent-framework/agents/declarative.md
+9-6Lines changed: 9 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,17 +18,17 @@ Declarative agents allow you to define agent configuration using YAML or JSON fi
18
18
The following example shows how to create a declarative agent from a YAML configuration:
19
19
20
20
```csharp
21
-
usingAzure.AI.OpenAI;
21
+
usingAzure.AI.Projects;
22
22
usingAzure.Identity;
23
23
usingMicrosoft.Agents.AI;
24
-
usingMicrosoft.Extensions.AI;
25
24
26
25
// Create the chat client
27
-
IChatClientchatClient=newAzureOpenAIClient(
28
-
newUri("https://<myresource>.openai.azure.com"),
26
+
IChatClientchatClient=newAIProjectClient(
27
+
newUri("<your-foundry-project-endpoint>"),
29
28
newDefaultAzureCredential())
30
-
.GetChatClient("gpt-4o-mini")
31
-
.AsIChatClient();
29
+
.GetProjectOpenAIClient()
30
+
.GetProjectResponsesClient()
31
+
.AsIChatClient("gpt-4o-mini");
32
32
33
33
// Define the agent using a YAML definition.
34
34
varyamlDefinition=
@@ -67,6 +67,9 @@ await foreach (var update in agent!.RunStreamingAsync("Tell me a joke about a pi
67
67
}
68
68
```
69
69
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.
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.
Console.WriteLine(awaitagent.RunAsync("Tell me a joke about a pirate."));
40
54
```
41
55
42
56
> [!WARNING]
43
57
> `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.
44
58
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.
47
60
48
-
### Using the Persistent SDK
61
+
##Foundry Agent (versioned)
49
62
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`.
Console.WriteLine(awaitagent.RunAsync("Tell me a joke about a pirate."));
75
81
```
76
82
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
78
87
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.
> `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
+
112
115
### Invoking the agent
113
116
114
117
Once configured, the agent automatically discovers available skills and uses them when a task matches:
0 commit comments