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] 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 @@ AITool mcpTool = new HostedMcpServerTool(serverName: "microsoft_learn", serverAd
};
// 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 @@ TextSearchProviderOptions textSearchOptions = new()
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 openAiEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
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 @@ using Microsoft.Extensions.AI;
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();