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
.AsAIAgent(instructions: "You are a helpful assistant.");
68
+
AIAgentbaseAgent=newAIProjectClient(
69
+
newUri("<your-foundry-project-endpoint>"),
70
+
newDefaultAzureCredential())
71
+
.AsAIAgent(
72
+
model: "gpt-4o-mini",
73
+
instructions: "You are a helpful assistant.");
73
74
74
75
// Register middleware at the agent level
75
76
varagentWithMiddleware=baseAgent
@@ -80,6 +81,9 @@ var agentWithMiddleware = baseAgent
80
81
Console.WriteLine(awaitagentWithMiddleware.RunAsync("What's the weather in Paris?"));
81
82
```
82
83
84
+
> [!WARNING]
85
+
> `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.
86
+
83
87
### Run-level middleware
84
88
85
89
Run-level middleware uses the same builder pattern, applied inline for a specific invocation:
Console.WriteLine(awaitagent.RunAsync("Hello, how are you?"));
61
63
```
62
64
65
+
> [!WARNING]
66
+
> `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.
67
+
63
68
> [!NOTE]
64
69
> For more information about `IChatClient` middleware, see [Custom IChatClient middleware](/dotnet/ai/microsoft-extensions-ai#custom-ichatclient-middleware).
> `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.
49
+
48
50
## Step 2: Create Your Agent Run Middleware
49
51
50
52
Next, create a function that will get invoked for each agent run.
@@ -178,9 +180,12 @@ To add middleware to your <xref:Microsoft.Extensions.AI.IChatClient>, you can us
178
180
After adding the middleware, you can use the `IChatClient` with your agent as usual.
.AsAIAgent(instructions: "You are a helpful assistant.");
57
+
AIAgentagent=newAIProjectClient(
58
+
newUri("<your-foundry-project-endpoint>"),
59
+
newDefaultAzureCredential())
60
+
.AsAIAgent(
61
+
model: "gpt-4o-mini",
62
+
instructions: "You are a helpful assistant.");
62
63
63
64
varsafeAgent=agent
64
65
.AsBuilder()
@@ -68,6 +69,9 @@ var safeAgent = agent
68
69
Console.WriteLine(awaitsafeAgent.RunAsync("Get user statistics"));
69
70
```
70
71
72
+
> [!WARNING]
73
+
> `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.
.AsAIAgent(instructions: "You are a helpful weather assistant.");
55
+
AIAgentagent=newAIProjectClient(
56
+
newUri("<your-foundry-project-endpoint>"),
57
+
newDefaultAzureCredential())
58
+
.AsAIAgent(
59
+
model: "gpt-4o-mini",
60
+
instructions: "You are a helpful weather assistant.");
60
61
61
62
varagentWithOverride=agent
62
63
.AsBuilder()
@@ -66,6 +67,9 @@ var agentWithOverride = agent
66
67
Console.WriteLine(awaitagentWithOverride.RunAsync("What's the weather in Seattle?"));
67
68
```
68
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.
0 commit comments