From 8c097a5f0a736edb4397a38e1441243df7c16f39 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 4 Mar 2026 19:11:58 +0000
Subject: [PATCH 1/9] Initial plan
From da8a06d5eed735b0fb34afc5b72358d1ca27bc39 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 4 Mar 2026 19:15:07 +0000
Subject: [PATCH 2/9] Update HostedAgents samples to
Azure.AI.AgentServer.AgentFramework 1.0.0-beta.9 and MEAI 10.3.0
Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
---
.../HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj | 4 ++--
.../HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj | 2 +-
.../AgentWithLocalTools/AgentWithLocalTools.csproj | 2 +-
.../AgentWithTextSearchRag/AgentWithTextSearchRag.csproj | 4 ++--
.../HostedAgents/AgentWithTools/AgentWithTools.csproj | 2 +-
.../HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj | 4 ++--
6 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj
index 17b90fd6e2..40acd79245 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj
@@ -36,11 +36,11 @@
-
+
-
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj
index 361848c27d..d6cdf97805 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj
@@ -35,7 +35,7 @@
-
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/AgentWithLocalTools.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/AgentWithLocalTools.csproj
index 43cdbfb025..dbc9aa6671 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/AgentWithLocalTools.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/AgentWithLocalTools.csproj
@@ -36,7 +36,7 @@
-
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj
index 03ffaf1824..3c08f4558e 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj
@@ -35,11 +35,11 @@
-
+
-
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj
index ce8a739757..57d5d35de0 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj
@@ -35,7 +35,7 @@
-
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj
index a434e07d33..906c3db8de 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj
@@ -35,11 +35,11 @@
-
+
-
+
From 2bee67b2206bee583d7e1af8731cc86f6e232b0d Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Date: Wed, 4 Mar 2026 20:55:58 +0000
Subject: [PATCH 3/9] Fix HostedAgents samples for Microsoft.Agents.AI
1.0.0-rc2 API changes
- Rename CreateAIAgent -> AsAIAgent (AgentThreadAndHITL, AgentWithHostedMCP, AgentWithTextSearchRag)
- Rename AsAgent -> AsAIAgent (AgentsInWorkflows)
- Replace AIContextProviderFactory with AIContextProviders and simplified TextSearchProvider ctor (AgentWithTextSearchRag)
- Update Microsoft.Agents.AI.OpenAI to 1.0.0-rc2 (AgentThreadAndHITL, AgentWithTextSearchRag, AgentWithTools)
- Update Microsoft.Agents.AI.Workflows to 1.0.0-rc2 (AgentsInWorkflows)
- Add Microsoft.Agents.AI 1.0.0-rc2 reference (AgentWithHostedMCP)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
.../AgentThreadAndHITL/AgentThreadAndHITL.csproj | 2 +-
.../HostedAgents/AgentThreadAndHITL/Program.cs | 2 +-
.../AgentWithHostedMCP/AgentWithHostedMCP.csproj | 1 +
.../HostedAgents/AgentWithHostedMCP/Program.cs | 2 +-
.../AgentWithTextSearchRag/AgentWithTextSearchRag.csproj | 2 +-
.../HostedAgents/AgentWithTextSearchRag/Program.cs | 6 +++---
.../HostedAgents/AgentWithTools/AgentWithTools.csproj | 2 +-
.../HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj | 2 +-
.../05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs | 2 +-
9 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj
index 40acd79245..7494a69fba 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj
@@ -39,7 +39,7 @@
-
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs
index 305b9835ed..0abb63623b 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs
@@ -28,7 +28,7 @@ static string GetWeather([Description("The location to get the weather for.")] s
new AzureCliCredential())
.GetChatClient(deploymentName)
.AsIChatClient()
- .CreateAIAgent(
+ .AsAIAgent(
instructions: "You are a helpful assistant",
tools: [new ApprovalRequiredAIFunction(AIFunctionFactory.Create(GetWeather))]
);
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj
index d6cdf97805..f41d4323f7 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj
@@ -38,6 +38,7 @@
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs
index 0898bc0252..8bcde40ec0 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs
@@ -29,7 +29,7 @@
new DefaultAzureCredential())
.GetResponsesClient(deploymentName)
.AsIChatClient()
- .CreateAIAgent(
+ .AsAIAgent(
instructions: "You answer questions by searching the Microsoft Learn content only.",
name: "MicrosoftLearnAgent",
tools: [mcpTool]);
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj
index 3c08f4558e..95f5599cba 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj
@@ -38,7 +38,7 @@
-
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs
index ae94a52f67..d31a72beda 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs
@@ -9,7 +9,6 @@
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
-using OpenAI.Chat;
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
@@ -28,13 +27,14 @@
new Uri(endpoint),
new DefaultAzureCredential())
.GetChatClient(deploymentName)
- .CreateAIAgent(new ChatClientAgentOptions
+ .AsIChatClient()
+ .AsAIAgent(new ChatClientAgentOptions
{
ChatOptions = new ChatOptions
{
Instructions = "You are a helpful support specialist for Contoso Outdoors. Answer questions using the provided context and cite the source document when available.",
},
- AIContextProviderFactory = ctx => new TextSearchProvider(MockSearchAsync, ctx.SerializedState, ctx.JsonSerializerOptions, textSearchOptions)
+ AIContextProviders = [new TextSearchProvider(MockSearchAsync, textSearchOptions)]
});
await agent.RunAIAgentAsync();
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj
index 57d5d35de0..9fe52d270c 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj
@@ -38,7 +38,7 @@
-
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj
index 906c3db8de..ad14a2f70c 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj
@@ -38,7 +38,7 @@
-
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs
index bd37a8311f..b1647fe81c 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs
@@ -32,7 +32,7 @@
.AddEdge(frenchAgent, spanishAgent)
.AddEdge(spanishAgent, englishAgent)
.Build()
- .AsAgent();
+ .AsAIAgent();
await agent.RunAIAgentAsync();
From 2762526c09ba1e744923b9c765dccc230d01f371 Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Date: Thu, 5 Mar 2026 10:57:43 +0000
Subject: [PATCH 4/9] Update HostedAgents samples for beta.9 API changes and
add missing projects to slnx
- Use DefaultAzureCredential consistently across all samples
- Add AgentThreadAndHITL, AgentWithLocalTools, AgentWithTools to slnx
- Apply dotnet format
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
dotnet/agent-framework-dotnet.slnx | 3 +++
.../05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs | 2 +-
.../05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs | 3 ---
.../05-end-to-end/HostedAgents/AgentWithLocalTools/Program.cs | 2 +-
.../HostedAgents/AgentWithTextSearchRag/Program.cs | 3 ---
.../05-end-to-end/HostedAgents/AgentWithTools/Program.cs | 2 +-
.../05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs | 3 ---
7 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/dotnet/agent-framework-dotnet.slnx b/dotnet/agent-framework-dotnet.slnx
index 9801ccc105..b31a7695bc 100644
--- a/dotnet/agent-framework-dotnet.slnx
+++ b/dotnet/agent-framework-dotnet.slnx
@@ -284,8 +284,11 @@
+
+
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs
index 0abb63623b..4b9dc9e43e 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs
@@ -25,7 +25,7 @@ static string GetWeather([Description("The location to get the weather for.")] s
#pragma warning disable MEAI001 // Type is for evaluation purposes only
AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
- new AzureCliCredential())
+ new DefaultAzureCredential())
.GetChatClient(deploymentName)
.AsIChatClient()
.AsAIAgent(
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs
index 8bcde40ec0..0a244bbea5 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs
@@ -21,9 +21,6 @@
};
// Create an agent with the MCP tool using Azure OpenAI Responses.
-// WARNING: 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.
AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new DefaultAzureCredential())
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/Program.cs
index 72eb938047..e9094d4b56 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/Program.cs
@@ -84,7 +84,7 @@ string GetAvailableHotels(
}
}
-var credential = new AzureCliCredential();
+var credential = new DefaultAzureCredential();
AIProjectClient projectClient = new(new Uri(endpoint), credential);
ClientConnection connection = projectClient.GetConnection(typeof(AzureOpenAIClient).FullName!);
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs
index d31a72beda..b3f918283b 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs
@@ -20,9 +20,6 @@
RecentMessageMemoryLimit = 6,
};
-// WARNING: 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.
AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new DefaultAzureCredential())
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/Program.cs
index 3bb68d6e31..d7330e6cfb 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/Program.cs
@@ -13,7 +13,7 @@
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
var toolConnectionId = Environment.GetEnvironmentVariable("MCP_TOOL_CONNECTION_ID") ?? throw new InvalidOperationException("MCP_TOOL_CONNECTION_ID is not set.");
-var credential = new AzureCliCredential();
+var credential = new DefaultAzureCredential();
var chatClient = new AzureOpenAIClient(new Uri(openAiEndpoint), credential)
.GetChatClient(deploymentName)
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs
index b1647fe81c..f959d52ce9 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs
@@ -15,9 +15,6 @@
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
-// WARNING: 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.
IChatClient chatClient = new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
.GetChatClient(deploymentName)
.AsIChatClient();
From 507de88d86b45c1edea546eec89b1ef0373056ac Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Date: Thu, 5 Mar 2026 11:02:42 +0000
Subject: [PATCH 5/9] Remove unnecessary Microsoft.Agents.AI.* package
references (transitive from AgentFramework)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
.../HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj | 3 +--
.../HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj | 1 -
.../AgentWithTextSearchRag/AgentWithTextSearchRag.csproj | 1 -
.../HostedAgents/AgentWithTools/AgentWithTools.csproj | 1 -
.../HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj | 3 +--
5 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj
index 7494a69fba..e1d0939fae 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj
@@ -1,4 +1,4 @@
-
+
Exe
@@ -39,7 +39,6 @@
-
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj
index f41d4323f7..d6cdf97805 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj
@@ -38,7 +38,6 @@
-
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj
index 95f5599cba..7aa8207c00 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj
@@ -38,7 +38,6 @@
-
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj
index 9fe52d270c..5ee9c1c4ba 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj
@@ -38,7 +38,6 @@
-
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj
index ad14a2f70c..b2f373a5e4 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj
@@ -1,4 +1,4 @@
-
+
Exe
@@ -38,7 +38,6 @@
-
From 0a266349a5f31a6af28cebb8e051d738b2da5275 Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Date: Thu, 5 Mar 2026 11:06:06 +0000
Subject: [PATCH 6/9] Add DefaultAzureCredential production warning comments to
all HostedAgents samples
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
.../05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs | 3 +++
.../05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs | 3 +++
.../05-end-to-end/HostedAgents/AgentWithLocalTools/Program.cs | 3 +++
.../HostedAgents/AgentWithTextSearchRag/Program.cs | 3 +++
.../05-end-to-end/HostedAgents/AgentWithTools/Program.cs | 3 +++
.../05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs | 3 +++
6 files changed, 18 insertions(+)
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs
index 4b9dc9e43e..afeee264c8 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs
@@ -22,6 +22,9 @@ static string GetWeather([Description("The location to get the weather for.")] s
// Create the chat client and agent.
// Note: ApprovalRequiredAIFunction wraps the tool to require user approval before invocation.
// User should reply with 'approve' or 'reject' when prompted.
+// WARNING: 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.
#pragma warning disable MEAI001 // Type is for evaluation purposes only
AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs
index 0a244bbea5..8bcde40ec0 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs
@@ -21,6 +21,9 @@
};
// Create an agent with the MCP tool using Azure OpenAI Responses.
+// WARNING: 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.
AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new DefaultAzureCredential())
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/Program.cs
index e9094d4b56..481b74bdb3 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/Program.cs
@@ -84,6 +84,9 @@ string GetAvailableHotels(
}
}
+// WARNING: 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.
var credential = new DefaultAzureCredential();
AIProjectClient projectClient = new(new Uri(endpoint), credential);
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs
index b3f918283b..d31a72beda 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs
@@ -20,6 +20,9 @@
RecentMessageMemoryLimit = 6,
};
+// WARNING: 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.
AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new DefaultAzureCredential())
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/Program.cs
index d7330e6cfb..8360f083ea 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/Program.cs
@@ -13,6 +13,9 @@
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
var toolConnectionId = Environment.GetEnvironmentVariable("MCP_TOOL_CONNECTION_ID") ?? throw new InvalidOperationException("MCP_TOOL_CONNECTION_ID is not set.");
+// WARNING: 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.
var credential = new DefaultAzureCredential();
var chatClient = new AzureOpenAIClient(new Uri(openAiEndpoint), credential)
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs
index f959d52ce9..b1647fe81c 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs
@@ -15,6 +15,9 @@
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
+// WARNING: 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.
IChatClient chatClient = new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
.GetChatClient(deploymentName)
.AsIChatClient();
From 8d7dfe6796c63f99486d88ff58d85bb2e150d99a Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Date: Thu, 5 Mar 2026 11:28:36 +0000
Subject: [PATCH 7/9] Update HostedAgents READMEs to reflect
DefaultAzureCredential usage
Replace AzureCliCredential references with DefaultAzureCredential in all
HostedAgents README files to match the actual sample code.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
.../05-end-to-end/HostedAgents/AgentWithHostedMCP/README.md | 2 +-
.../05-end-to-end/HostedAgents/AgentWithTools/README.md | 4 ++--
.../05-end-to-end/HostedAgents/AgentsInWorkflows/README.md | 2 +-
dotnet/samples/05-end-to-end/HostedAgents/README.md | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/README.md b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/README.md
index 8d8ddba330..106e08e720 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/README.md
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/README.md
@@ -18,7 +18,7 @@ Before running this sample, ensure you have:
2. A deployment of a chat model (e.g., gpt-4o-mini)
3. Azure CLI installed and authenticated
-**Note**: This sample uses Azure CLI credentials for authentication. Make sure you're logged in with `az login` and have access to the Azure OpenAI resource.
+**Note**: This sample uses `DefaultAzureCredential` for authentication, which probes multiple sources automatically. For local development, make sure you're logged in with `az login` and have access to the Azure OpenAI resource.
## Environment Variables
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/README.md b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/README.md
index 5a80ecda9f..55333f9940 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/README.md
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/README.md
@@ -6,7 +6,7 @@ Key features:
- Configuring Foundry tools using `UseFoundryTools` with MCP and code interpreter
- Connecting to an external MCP tool via a Foundry project connection
-- Using `AzureCliCredential` for Azure authentication
+- Using `DefaultAzureCredential` for Azure authentication
- OpenTelemetry instrumentation for both the chat client and agent
> For common prerequisites and setup instructions, see the [Hosted Agent Samples README](../README.md).
@@ -36,7 +36,7 @@ $env:MCP_TOOL_CONNECTION_ID="SampleMCPTool"
## How It Works
-1. An `AzureOpenAIClient` is created with `AzureCliCredential` and used to get a chat client
+1. An `AzureOpenAIClient` is created with `DefaultAzureCredential` and used to get a chat client
2. The chat client is wrapped with `UseFoundryTools` which registers two Foundry tool types:
- **MCP connection**: Connects to an external MCP server (Microsoft Learn) via the project connection name, providing documentation fetch and search capabilities
- **Code interpreter**: Allows the agent to execute code snippets when needed
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/README.md b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/README.md
index 72019bbf22..0f2f188f1b 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/README.md
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/README.md
@@ -19,7 +19,7 @@ Before you begin, ensure you have the following prerequisites:
- Azure OpenAI service endpoint and deployment configured
- Azure CLI installed and authenticated (for Azure credential authentication)
-**Note**: This demo uses Azure CLI credentials for authentication. Make sure you're logged in with `az login` and have access to the Azure OpenAI resource. For more information, see the [Azure CLI documentation](https://learn.microsoft.com/cli/azure/authenticate-azure-cli-interactively).
+**Note**: This demo uses `DefaultAzureCredential` for authentication, which probes multiple sources automatically. For local development, make sure you're logged in with `az login` and have access to the Azure OpenAI resource. For more information, see the [Azure CLI documentation](https://learn.microsoft.com/cli/azure/authenticate-azure-cli-interactively).
Set the following environment variables:
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/README.md b/dotnet/samples/05-end-to-end/HostedAgents/README.md
index f7a3bdc94b..cf90a97005 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/README.md
+++ b/dotnet/samples/05-end-to-end/HostedAgents/README.md
@@ -23,7 +23,7 @@ Before running any sample, ensure you have:
### Authenticate with Azure CLI
-All samples use `AzureCliCredential` for authentication. Make sure you're logged in:
+All samples use `DefaultAzureCredential` for authentication, which automatically probes multiple credential sources (environment variables, managed identity, Azure CLI, etc.). For local development, the simplest approach is to authenticate via Azure CLI:
```powershell
az login
From db6023b0fc40de5e4132c41e35872cbe6f6991f6 Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Date: Thu, 5 Mar 2026 12:37:37 +0000
Subject: [PATCH 8/9] Replace Microsoft.Extensions.AI.OpenAI with
Microsoft.Agents.AI.OpenAI and remove AsIChatClient()
Swap package references from Microsoft.Extensions.AI.OpenAI to
Microsoft.Agents.AI.OpenAI across all 6 HostedAgents samples. This enables
using the AsAIAgent() extension directly on ChatClient/ResponsesClient
(from OpenAI.Chat/OpenAI.Responses namespaces), removing the intermediate
AsIChatClient() call in 3 samples where it was unnecessary.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
.../HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj | 2 +-
.../05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs | 2 +-
.../HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj | 2 +-
.../05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs | 2 +-
.../HostedAgents/AgentWithLocalTools/AgentWithLocalTools.csproj | 2 +-
.../AgentWithTextSearchRag/AgentWithTextSearchRag.csproj | 2 +-
.../HostedAgents/AgentWithTextSearchRag/Program.cs | 2 +-
.../HostedAgents/AgentWithTools/AgentWithTools.csproj | 2 +-
.../HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj | 2 +-
9 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj
index e1d0939fae..1398a60228 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj
@@ -39,7 +39,7 @@
-
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs
index afeee264c8..5f7493cf89 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs
@@ -11,6 +11,7 @@
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
+using OpenAI.Chat;
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
@@ -30,7 +31,6 @@ static string GetWeather([Description("The location to get the weather for.")] s
new Uri(endpoint),
new DefaultAzureCredential())
.GetChatClient(deploymentName)
- .AsIChatClient()
.AsAIAgent(
instructions: "You are a helpful assistant",
tools: [new ApprovalRequiredAIFunction(AIFunctionFactory.Create(GetWeather))]
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj
index d6cdf97805..e854cfcd40 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj
@@ -38,7 +38,7 @@
-
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs
index 8bcde40ec0..adc30f228d 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs
@@ -9,6 +9,7 @@
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
+using OpenAI.Responses;
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
@@ -28,7 +29,6 @@
new Uri(endpoint),
new DefaultAzureCredential())
.GetResponsesClient(deploymentName)
- .AsIChatClient()
.AsAIAgent(
instructions: "You answer questions by searching the Microsoft Learn content only.",
name: "MicrosoftLearnAgent",
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/AgentWithLocalTools.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/AgentWithLocalTools.csproj
index dbc9aa6671..975333e584 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/AgentWithLocalTools.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/AgentWithLocalTools.csproj
@@ -40,7 +40,7 @@
-
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj
index 7aa8207c00..32e00f832b 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj
@@ -38,7 +38,7 @@
-
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs
index d31a72beda..23965c850e 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs
@@ -9,6 +9,7 @@
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
+using OpenAI.Chat;
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
@@ -27,7 +28,6 @@
new Uri(endpoint),
new DefaultAzureCredential())
.GetChatClient(deploymentName)
- .AsIChatClient()
.AsAIAgent(new ChatClientAgentOptions
{
ChatOptions = new ChatOptions
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj
index 5ee9c1c4ba..959cca1db5 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/AgentWithTools.csproj
@@ -38,7 +38,7 @@
-
+
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj
index b2f373a5e4..56a55a428d 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj
@@ -38,7 +38,7 @@
-
+
From b28847f1e4cfd2e590b8023bb3e1da723e9ed093 Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Date: Thu, 5 Mar 2026 12:49:06 +0000
Subject: [PATCH 9/9] Use explicit types and AsAIAgent() extensions across all
HostedAgents samples
Replace var with explicit types for clarity in all 6 samples. Replace
new ChatClientAgent() constructor calls with chatClient.AsAIAgent()
extension method in AgentWithLocalTools and AgentsInWorkflows.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
.../AgentThreadAndHITL/Program.cs | 6 ++---
.../AgentWithHostedMCP/Program.cs | 4 +--
.../AgentWithLocalTools/Program.cs | 26 +++++++++----------
.../AgentWithTextSearchRag/Program.cs | 4 +--
.../HostedAgents/AgentWithTools/Program.cs | 12 ++++-----
.../HostedAgents/AgentsInWorkflows/Program.cs | 8 +++---
6 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs
index 5f7493cf89..c816b018e9 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs
@@ -13,8 +13,8 @@
using Microsoft.Extensions.AI;
using OpenAI.Chat;
-var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
-var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
+string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
+string deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
[Description("Get the weather for a given location.")]
static string GetWeather([Description("The location to get the weather for.")] string location)
@@ -37,5 +37,5 @@ static string GetWeather([Description("The location to get the weather for.")] s
);
#pragma warning restore MEAI001
-var threadRepository = new InMemoryAgentThreadRepository(agent);
+InMemoryAgentThreadRepository threadRepository = new(agent);
await agent.RunAIAgentAsync(telemetrySourceName: "Agents", threadRepository: threadRepository);
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs
index adc30f228d..972205cfe2 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs
@@ -11,8 +11,8 @@
using Microsoft.Extensions.AI;
using OpenAI.Responses;
-var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
-var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
+string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
+string deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
// Create an MCP tool that can be called without approval.
AITool mcpTool = new HostedMcpServerTool(serverName: "microsoft_learn", serverAddress: "https://learn.microsoft.com/api/mcp")
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/Program.cs
index 481b74bdb3..78a0aa62e9 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/Program.cs
@@ -15,21 +15,21 @@
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
-var endpoint = Environment.GetEnvironmentVariable("AZURE_AI_PROJECT_ENDPOINT")
+string endpoint = Environment.GetEnvironmentVariable("AZURE_AI_PROJECT_ENDPOINT")
?? throw new InvalidOperationException("AZURE_AI_PROJECT_ENDPOINT is not set.");
-var deploymentName = Environment.GetEnvironmentVariable("MODEL_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
+string deploymentName = Environment.GetEnvironmentVariable("MODEL_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
Console.WriteLine($"Project Endpoint: {endpoint}");
Console.WriteLine($"Model Deployment: {deploymentName}");
-var seattleHotels = new[]
-{
+Hotel[] seattleHotels =
+[
new Hotel("Contoso Suites", 189, 4.5, "Downtown"),
new Hotel("Fabrikam Residences", 159, 4.2, "Pike Place Market"),
new Hotel("Alpine Ski House", 249, 4.7, "Seattle Center"),
new Hotel("Margie's Travel Lodge", 219, 4.4, "Waterfront"),
new Hotel("Northwind Inn", 139, 4.0, "Capitol Hill"),
new Hotel("Relecloud Hotel", 99, 3.8, "University District"),
-};
+];
[Description("Get available hotels in Seattle for the specified dates. This simulates a call to a hotel availability API.")]
string GetAvailableHotels(
@@ -54,21 +54,21 @@ string GetAvailableHotels(
return "Error: Check-out date must be after check-in date.";
}
- var nights = (checkOut - checkIn).Days;
- var availableHotels = seattleHotels.Where(h => h.PricePerNight <= maxPrice).ToList();
+ int nights = (checkOut - checkIn).Days;
+ List availableHotels = seattleHotels.Where(h => h.PricePerNight <= maxPrice).ToList();
if (availableHotels.Count == 0)
{
return $"No hotels found in Seattle within your budget of ${maxPrice}/night.";
}
- var result = new StringBuilder();
+ StringBuilder result = new();
result.AppendLine($"Available hotels in Seattle from {checkInDate} to {checkOutDate} ({nights} nights):");
result.AppendLine();
- foreach (var hotel in availableHotels)
+ foreach (Hotel hotel in availableHotels)
{
- var totalCost = hotel.PricePerNight * nights;
+ int totalCost = hotel.PricePerNight * nights;
result.AppendLine($"**{hotel.Name}**");
result.AppendLine($" Location: {hotel.Location}");
result.AppendLine($" Rating: {hotel.Rating}/5");
@@ -87,7 +87,7 @@ string GetAvailableHotels(
// WARNING: 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.
-var credential = new DefaultAzureCredential();
+DefaultAzureCredential credential = new();
AIProjectClient projectClient = new(new Uri(endpoint), credential);
ClientConnection connection = projectClient.GetConnection(typeof(AzureOpenAIClient).FullName!);
@@ -99,14 +99,14 @@ string GetAvailableHotels(
openAiEndpoint = new Uri($"https://{openAiEndpoint.Host}");
Console.WriteLine($"OpenAI Endpoint: {openAiEndpoint}");
-var chatClient = new AzureOpenAIClient(openAiEndpoint, credential)
+IChatClient chatClient = new AzureOpenAIClient(openAiEndpoint, credential)
.GetChatClient(deploymentName)
.AsIChatClient()
.AsBuilder()
.UseOpenTelemetry(sourceName: "Agents", configure: cfg => cfg.EnableSensitiveData = false)
.Build();
-var agent = new ChatClientAgent(chatClient,
+AIAgent agent = chatClient.AsAIAgent(
name: "SeattleHotelAgent",
instructions: """
You are a helpful travel assistant specializing in finding hotels in Seattle, Washington.
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs
index 23965c850e..bb28fc0d9b 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs
@@ -11,8 +11,8 @@
using Microsoft.Extensions.AI;
using OpenAI.Chat;
-var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
-var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
+string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
+string deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
TextSearchProviderOptions textSearchOptions = new()
{
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/Program.cs
index 8360f083ea..f564a0d8d3 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentWithTools/Program.cs
@@ -9,16 +9,16 @@
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
-var openAiEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
-var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
-var toolConnectionId = Environment.GetEnvironmentVariable("MCP_TOOL_CONNECTION_ID") ?? throw new InvalidOperationException("MCP_TOOL_CONNECTION_ID is not set.");
+string openAiEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
+string deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
+string toolConnectionId = Environment.GetEnvironmentVariable("MCP_TOOL_CONNECTION_ID") ?? throw new InvalidOperationException("MCP_TOOL_CONNECTION_ID is not set.");
// WARNING: 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.
-var credential = new DefaultAzureCredential();
+DefaultAzureCredential credential = new();
-var chatClient = new AzureOpenAIClient(new Uri(openAiEndpoint), credential)
+IChatClient chatClient = new AzureOpenAIClient(new Uri(openAiEndpoint), credential)
.GetChatClient(deploymentName)
.AsIChatClient()
.AsBuilder()
@@ -26,7 +26,7 @@
.UseOpenTelemetry(sourceName: "Agents", configure: (cfg) => cfg.EnableSensitiveData = true)
.Build();
-var agent = new ChatClientAgent(chatClient,
+AIAgent agent = chatClient.AsAIAgent(
name: "AgentWithTools",
instructions: @"You are a helpful assistant with access to tools for fetching Microsoft documentation.
diff --git a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs
index b1647fe81c..f5ea72e7f7 100644
--- a/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs
+++ b/dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs
@@ -12,8 +12,8 @@
using Microsoft.Extensions.AI;
// Set up the Azure OpenAI client
-var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
-var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
+string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
+string deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
@@ -36,5 +36,5 @@
await agent.RunAIAgentAsync();
-static ChatClientAgent GetTranslationAgent(string targetLanguage, IChatClient chatClient) =>
- new(chatClient, $"You are a translation assistant that translates the provided text to {targetLanguage}.");
+static AIAgent GetTranslationAgent(string targetLanguage, IChatClient chatClient) =>
+ chatClient.AsAIAgent($"You are a translation assistant that translates the provided text to {targetLanguage}.");