From 0bec2e81766fa265a8c0c7151a5ed062594771a1 Mon Sep 17 00:00:00 2001 From: Dooriya Li <10163840+dooriya@users.noreply.github.com> Date: Mon, 13 Jul 2026 17:07:03 +0800 Subject: [PATCH] fix: auto-load .env in all C# hosted-agent samples for consistency (#683) * feat: auto-load .env in all C# hosted-agent samples for consistency Add DotNetEnv (Env.TraversePath().Load()) to the 11 C# hosted-agent samples that did not already load a local .env file, so every C# sample picks up .env the same way. Adds the DotNetEnv 3.1.1 PackageReference to each project's existing package ItemGroup. * fix: readme * fix: use Env.NoClobber() so runtime env vars take precedence over .env Change all C# hosted-agent samples to Env.NoClobber().TraversePath().Load() so environment variables provided by azd, the hosted container, or CI are not overwritten by a local .env file. Applied to all 28 samples (the 11 added in this PR plus the 17 that already loaded .env) for consistency. --- .github/CODEOWNERS | 1 - samples/csharp/hosted-agents/README-template.md | 2 +- .../Program.cs | 2 +- .../Program.cs | 2 +- .../agent-skills/src/agent-skills/Program.cs | 2 +- .../azure-search-rag/src/azure-search-rag/Program.cs | 2 +- .../Program.cs | 2 +- .../file-tools/src/file-tools/Program.cs | 2 +- .../src/foundry-memory-rag/Program.cs | 2 +- .../src/foundry-toolbox-mcp-skills/Program.cs | 2 +- .../Program.cs | 2 +- .../agent-framework/hello-world/README.md | 7 +------ .../src/hello-world-dotnet-agent-framework/Program.cs | 4 ++++ .../hello-world.csproj | 2 ++ .../src/invocations-echo-agent/Program.cs | 4 ++++ .../invocations-echo-agent.csproj | 2 ++ .../local-tools/src/local-tools/Program.cs | 2 +- .../mcp-tools/src/mcp-tools/Program.cs | 2 +- .../observability/src/observability/Program.cs | 2 +- .../simple-agent/src/simple-agent/Program.cs | 2 +- .../teams-activity-dotnet-agent-framework/Program.cs | 2 +- .../text-search-rag/src/text-search-rag/Program.cs | 2 +- .../Program.cs | 2 +- .../workflows/src/workflows/Program.cs | 2 +- .../bring-your-own/invocations/HelloWorld/README.md | 7 +------ .../hello-world-dotnet-invocations/HelloWorld.csproj | 2 ++ .../src/hello-world-dotnet-invocations/Program.cs | 4 ++++ .../invocations/human-in-the-loop/README.md | 7 +------ .../human-in-the-loop-dotnet-invocations/Program.cs | 4 ++++ .../human-in-the-loop.csproj | 2 ++ .../invocations/notetaking-agent/README.md | 7 +++---- .../notetaking-agent-dotnet-invocations/Program.cs | 4 ++++ .../notetaking-agent.csproj | 2 ++ .../HelloWorld.csproj | 2 ++ .../src/hello-world-dotnet-invocations-ws/Program.cs | 4 ++++ .../bring-your-own/responses/HelloWorld/README.md | 7 +------ .../hello-world-dotnet-responses/HelloWorld.csproj | 2 ++ .../src/hello-world-dotnet-responses/Program.cs | 4 ++++ .../responses/background-agent/README.md | 7 +------ .../src/background-agent-dotnet-responses/Program.cs | 4 ++++ .../background-agent.csproj | 2 ++ .../src/browser-automation-csharp-byo/Program.cs | 4 ++++ .../browser-automation.csproj | 2 ++ .../bring-your-own/responses/env-vars-agent/README.md | 11 +++-------- .../EnvVarsAgent.csproj | 2 ++ .../src/env-vars-agent-dotnet-responses/Program.cs | 4 ++++ .../responses/notetaking-agent/README.md | 7 +++---- .../src/notetaking-agent-dotnet-responses/Program.cs | 4 ++++ .../notetaking-agent.csproj | 2 ++ 49 files changed, 98 insertions(+), 65 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index c1ce7c71f..314dbd9ce 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -65,7 +65,6 @@ /samples/typescript/quickstart/chat-with-agent/src/quickstart-chat-with-agent.ts @microsoft-foundry/AI-Platform-Docs /samples/typescript/quickstart/create-agent/src/quickstart-create-agent.ts @microsoft-foundry/AI-Platform-Docs /samples/typescript/quickstart/responses/src/quickstart-responses.ts @microsoft-foundry/AI-Platform-Docs -/samples/typescript/quickstart/agent-service/src/quickstart.ts @microsoft-foundry/AI-Platform-Docs #### Additional ownership entries (added via issue triage) ############################################## # Routing for sample paths that were uncovered during issue triage. diff --git a/samples/csharp/hosted-agents/README-template.md b/samples/csharp/hosted-agents/README-template.md index 970af5f11..9ab5d44cb 100644 --- a/samples/csharp/hosted-agents/README-template.md +++ b/samples/csharp/hosted-agents/README-template.md @@ -116,7 +116,7 @@ Press **F5** to start the agent. The agent starts and the **Agent Inspector** op ### Or run manually, then open the Inspector -1. Set the required environment variables and sign in to Azure with the Azure CLI (`az login`). +1. Configure the agent — copy `.env.example` to `.env` and fill in the values (the app loads `.env` automatically on startup) — then sign in to Azure with the Azure CLI (`az login`). 2. Start the agent: `dotnet run` (listens on `http://localhost:8088`). 3. Command Palette (`Ctrl+Shift+P`) → **Foundry Toolkit: Open Agent Inspector**, then send a message to test. diff --git a/samples/csharp/hosted-agents/agent-framework/a2a/01-delegation/caller/src/agent-framework-a2a-caller-responses-dotnet/Program.cs b/samples/csharp/hosted-agents/agent-framework/a2a/01-delegation/caller/src/agent-framework-a2a-caller-responses-dotnet/Program.cs index ff62ad1e6..44483955c 100644 --- a/samples/csharp/hosted-agents/agent-framework/a2a/01-delegation/caller/src/agent-framework-a2a-caller-responses-dotnet/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/a2a/01-delegation/caller/src/agent-framework-a2a-caller-responses-dotnet/Program.cs @@ -30,7 +30,7 @@ using Microsoft.Agents.AI.Foundry.Hosting; // Load .env file if present (for local development) -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")); diff --git a/samples/csharp/hosted-agents/agent-framework/a2a/01-delegation/executor/src/agent-framework-a2a-executor-responses-dotnet/Program.cs b/samples/csharp/hosted-agents/agent-framework/a2a/01-delegation/executor/src/agent-framework-a2a-executor-responses-dotnet/Program.cs index 889f991dc..d3c21565f 100644 --- a/samples/csharp/hosted-agents/agent-framework/a2a/01-delegation/executor/src/agent-framework-a2a-executor-responses-dotnet/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/a2a/01-delegation/executor/src/agent-framework-a2a-executor-responses-dotnet/Program.cs @@ -21,7 +21,7 @@ using Microsoft.Agents.AI.Foundry.Hosting; // Load .env file if present (for local development) -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")); diff --git a/samples/csharp/hosted-agents/agent-framework/agent-skills/src/agent-skills/Program.cs b/samples/csharp/hosted-agents/agent-framework/agent-skills/src/agent-skills/Program.cs index deefd09e4..030af9bda 100644 --- a/samples/csharp/hosted-agents/agent-framework/agent-skills/src/agent-skills/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/agent-skills/src/agent-skills/Program.cs @@ -50,7 +50,7 @@ using Microsoft.Extensions.AI; // Load .env file if present (for local development). -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")); diff --git a/samples/csharp/hosted-agents/agent-framework/azure-search-rag/src/azure-search-rag/Program.cs b/samples/csharp/hosted-agents/agent-framework/azure-search-rag/src/azure-search-rag/Program.cs index 3a10fed32..73005dc47 100644 --- a/samples/csharp/hosted-agents/agent-framework/azure-search-rag/src/azure-search-rag/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/azure-search-rag/src/azure-search-rag/Program.cs @@ -11,7 +11,7 @@ using Microsoft.Agents.AI.Foundry.Hosting; using Microsoft.Extensions.AI; -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")); diff --git a/samples/csharp/hosted-agents/agent-framework/browser-automation/src/browser-automation-csharp-maf-sample-foundry/Program.cs b/samples/csharp/hosted-agents/agent-framework/browser-automation/src/browser-automation-csharp-maf-sample-foundry/Program.cs index 57f3ac090..f3f5056e1 100644 --- a/samples/csharp/hosted-agents/agent-framework/browser-automation/src/browser-automation-csharp-maf-sample-foundry/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/browser-automation/src/browser-automation-csharp-maf-sample-foundry/Program.cs @@ -28,7 +28,7 @@ using Microsoft.Extensions.AI; using BrowserAutomation; -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); // ── Configuration ──────────────────────────────────────────────────────────── var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") diff --git a/samples/csharp/hosted-agents/agent-framework/file-tools/src/file-tools/Program.cs b/samples/csharp/hosted-agents/agent-framework/file-tools/src/file-tools/Program.cs index e15984cde..e0c892944 100644 --- a/samples/csharp/hosted-agents/agent-framework/file-tools/src/file-tools/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/file-tools/src/file-tools/Program.cs @@ -9,7 +9,7 @@ using Microsoft.Agents.AI.Foundry.Hosting; using Microsoft.Extensions.AI; -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")); diff --git a/samples/csharp/hosted-agents/agent-framework/foundry-memory-rag/src/foundry-memory-rag/Program.cs b/samples/csharp/hosted-agents/agent-framework/foundry-memory-rag/src/foundry-memory-rag/Program.cs index cd37f4cec..f1e57b6d3 100644 --- a/samples/csharp/hosted-agents/agent-framework/foundry-memory-rag/src/foundry-memory-rag/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/foundry-memory-rag/src/foundry-memory-rag/Program.cs @@ -19,7 +19,7 @@ using Microsoft.Agents.AI.Foundry.Hosting; using Microsoft.Extensions.AI; -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")); diff --git a/samples/csharp/hosted-agents/agent-framework/foundry-toolbox-mcp-skills/src/foundry-toolbox-mcp-skills/Program.cs b/samples/csharp/hosted-agents/agent-framework/foundry-toolbox-mcp-skills/src/foundry-toolbox-mcp-skills/Program.cs index a20b908b2..b66924278 100644 --- a/samples/csharp/hosted-agents/agent-framework/foundry-toolbox-mcp-skills/src/foundry-toolbox-mcp-skills/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/foundry-toolbox-mcp-skills/src/foundry-toolbox-mcp-skills/Program.cs @@ -35,7 +35,7 @@ using ModelContextProtocol.Client; // Load .env file if present (for local development). -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); string projectEndpoint = Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set."); diff --git a/samples/csharp/hosted-agents/agent-framework/foundry-toolbox-server-side/src/foundry-toolbox-server-side-dotnet-agent-framework/Program.cs b/samples/csharp/hosted-agents/agent-framework/foundry-toolbox-server-side/src/foundry-toolbox-server-side-dotnet-agent-framework/Program.cs index 01cea816c..4f9b843c9 100644 --- a/samples/csharp/hosted-agents/agent-framework/foundry-toolbox-server-side/src/foundry-toolbox-server-side-dotnet-agent-framework/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/foundry-toolbox-server-side/src/foundry-toolbox-server-side-dotnet-agent-framework/Program.cs @@ -25,7 +25,7 @@ using Microsoft.Agents.AI.Foundry.Hosting; // Load .env file if present (for local development) -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")); diff --git a/samples/csharp/hosted-agents/agent-framework/hello-world/README.md b/samples/csharp/hosted-agents/agent-framework/hello-world/README.md index d97533376..850740c1a 100644 --- a/samples/csharp/hosted-agents/agent-framework/hello-world/README.md +++ b/samples/csharp/hosted-agents/agent-framework/hello-world/README.md @@ -107,12 +107,7 @@ Press **F5** to start the agent. The agent starts and the **Agent Inspector** op dotnet restore ``` -2. Set the required environment variables: - - ```bash - export FOUNDRY_PROJECT_ENDPOINT="https://.services.ai.azure.com/api/projects/" - export AZURE_AI_MODEL_DEPLOYMENT_NAME="" - ``` +2. Configure the agent: copy `.env.example` to `.env` and fill in the values. The agent loads `.env` automatically on startup. 3. Sign in to Azure with the Azure CLI: diff --git a/samples/csharp/hosted-agents/agent-framework/hello-world/src/hello-world-dotnet-agent-framework/Program.cs b/samples/csharp/hosted-agents/agent-framework/hello-world/src/hello-world-dotnet-agent-framework/Program.cs index 4e74dc607..1b62414de 100644 --- a/samples/csharp/hosted-agents/agent-framework/hello-world/src/hello-world-dotnet-agent-framework/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/hello-world/src/hello-world-dotnet-agent-framework/Program.cs @@ -39,9 +39,13 @@ using Azure.AI.AgentServer.Core; using Azure.AI.Projects; using Azure.Identity; +using DotNetEnv; using Microsoft.Agents.AI; using Microsoft.Agents.AI.Foundry.Hosting; +// Load environment variables from a .env file if present (for local development). +Env.NoClobber().TraversePath().Load(); + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING"))) { Console.Error.WriteLine( diff --git a/samples/csharp/hosted-agents/agent-framework/hello-world/src/hello-world-dotnet-agent-framework/hello-world.csproj b/samples/csharp/hosted-agents/agent-framework/hello-world/src/hello-world-dotnet-agent-framework/hello-world.csproj index ddc775779..b07ea9446 100644 --- a/samples/csharp/hosted-agents/agent-framework/hello-world/src/hello-world-dotnet-agent-framework/hello-world.csproj +++ b/samples/csharp/hosted-agents/agent-framework/hello-world/src/hello-world-dotnet-agent-framework/hello-world.csproj @@ -15,6 +15,8 @@ + + diff --git a/samples/csharp/hosted-agents/agent-framework/invocations-echo-agent/src/invocations-echo-agent/Program.cs b/samples/csharp/hosted-agents/agent-framework/invocations-echo-agent/src/invocations-echo-agent/Program.cs index 1c6263de8..f2243ce61 100644 --- a/samples/csharp/hosted-agents/agent-framework/invocations-echo-agent/src/invocations-echo-agent/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/invocations-echo-agent/src/invocations-echo-agent/Program.cs @@ -2,9 +2,13 @@ using Azure.AI.AgentServer.Core; using Azure.AI.AgentServer.Invocations; +using DotNetEnv; using InvocationsEchoAgent; using Microsoft.Agents.AI; +// Load environment variables from a .env file if present (for local development). +Env.NoClobber().TraversePath().Load(); + var builder = AgentHost.CreateBuilder(args); // Register the echo agent as a singleton (no LLM needed). diff --git a/samples/csharp/hosted-agents/agent-framework/invocations-echo-agent/src/invocations-echo-agent/invocations-echo-agent.csproj b/samples/csharp/hosted-agents/agent-framework/invocations-echo-agent/src/invocations-echo-agent/invocations-echo-agent.csproj index 399a405cd..6710eb8e0 100644 --- a/samples/csharp/hosted-agents/agent-framework/invocations-echo-agent/src/invocations-echo-agent/invocations-echo-agent.csproj +++ b/samples/csharp/hosted-agents/agent-framework/invocations-echo-agent/src/invocations-echo-agent/invocations-echo-agent.csproj @@ -12,6 +12,8 @@ + + diff --git a/samples/csharp/hosted-agents/agent-framework/local-tools/src/local-tools/Program.cs b/samples/csharp/hosted-agents/agent-framework/local-tools/src/local-tools/Program.cs index 9ee902652..1e6aaf6aa 100644 --- a/samples/csharp/hosted-agents/agent-framework/local-tools/src/local-tools/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/local-tools/src/local-tools/Program.cs @@ -8,7 +8,7 @@ using Microsoft.Agents.AI.Foundry.Hosting; using Microsoft.Extensions.AI; -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")); diff --git a/samples/csharp/hosted-agents/agent-framework/mcp-tools/src/mcp-tools/Program.cs b/samples/csharp/hosted-agents/agent-framework/mcp-tools/src/mcp-tools/Program.cs index 57db1b6f4..50421836c 100644 --- a/samples/csharp/hosted-agents/agent-framework/mcp-tools/src/mcp-tools/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/mcp-tools/src/mcp-tools/Program.cs @@ -25,7 +25,7 @@ using ModelContextProtocol.Client; // Load .env file if present (for local development) -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")); diff --git a/samples/csharp/hosted-agents/agent-framework/observability/src/observability/Program.cs b/samples/csharp/hosted-agents/agent-framework/observability/src/observability/Program.cs index 68ea734d8..2315377d7 100644 --- a/samples/csharp/hosted-agents/agent-framework/observability/src/observability/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/observability/src/observability/Program.cs @@ -8,7 +8,7 @@ using Microsoft.Agents.AI.Foundry.Hosting; using Microsoft.Extensions.AI; -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")); diff --git a/samples/csharp/hosted-agents/agent-framework/simple-agent/src/simple-agent/Program.cs b/samples/csharp/hosted-agents/agent-framework/simple-agent/src/simple-agent/Program.cs index 4c404bdbe..fefc0c935 100644 --- a/samples/csharp/hosted-agents/agent-framework/simple-agent/src/simple-agent/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/simple-agent/src/simple-agent/Program.cs @@ -7,7 +7,7 @@ using Microsoft.Agents.AI; using Microsoft.Agents.AI.Foundry.Hosting; -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")); diff --git a/samples/csharp/hosted-agents/agent-framework/teams-activity/src/teams-activity-dotnet-agent-framework/Program.cs b/samples/csharp/hosted-agents/agent-framework/teams-activity/src/teams-activity-dotnet-agent-framework/Program.cs index e8a9d0b79..137cb301e 100644 --- a/samples/csharp/hosted-agents/agent-framework/teams-activity/src/teams-activity-dotnet-agent-framework/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/teams-activity/src/teams-activity-dotnet-agent-framework/Program.cs @@ -22,7 +22,7 @@ using Microsoft.Agents.AI.Foundry.Hosting; // Load .env file if present (for local development) -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")); diff --git a/samples/csharp/hosted-agents/agent-framework/text-search-rag/src/text-search-rag/Program.cs b/samples/csharp/hosted-agents/agent-framework/text-search-rag/src/text-search-rag/Program.cs index ff5f6b0d5..13a725c35 100644 --- a/samples/csharp/hosted-agents/agent-framework/text-search-rag/src/text-search-rag/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/text-search-rag/src/text-search-rag/Program.cs @@ -8,7 +8,7 @@ using Microsoft.Agents.AI.Foundry.Hosting; using Microsoft.Extensions.AI; -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")); diff --git a/samples/csharp/hosted-agents/agent-framework/toolbox-auth-paths/src/toolbox-auth-paths-dotnet-agent-framework/Program.cs b/samples/csharp/hosted-agents/agent-framework/toolbox-auth-paths/src/toolbox-auth-paths-dotnet-agent-framework/Program.cs index 783fbf231..be9108a29 100644 --- a/samples/csharp/hosted-agents/agent-framework/toolbox-auth-paths/src/toolbox-auth-paths-dotnet-agent-framework/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/toolbox-auth-paths/src/toolbox-auth-paths-dotnet-agent-framework/Program.cs @@ -37,7 +37,7 @@ using Microsoft.Extensions.DependencyInjection; // Load .env file if present (for local development) -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")); diff --git a/samples/csharp/hosted-agents/agent-framework/workflows/src/workflows/Program.cs b/samples/csharp/hosted-agents/agent-framework/workflows/src/workflows/Program.cs index bf5a63047..172449d4f 100644 --- a/samples/csharp/hosted-agents/agent-framework/workflows/src/workflows/Program.cs +++ b/samples/csharp/hosted-agents/agent-framework/workflows/src/workflows/Program.cs @@ -8,7 +8,7 @@ using Microsoft.Agents.AI.Foundry.Hosting; using Microsoft.Agents.AI.Workflows; -Env.TraversePath().Load(); +Env.NoClobber().TraversePath().Load(); var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")); diff --git a/samples/csharp/hosted-agents/bring-your-own/invocations/HelloWorld/README.md b/samples/csharp/hosted-agents/bring-your-own/invocations/HelloWorld/README.md index 4549448aa..6a9f12ac1 100644 --- a/samples/csharp/hosted-agents/bring-your-own/invocations/HelloWorld/README.md +++ b/samples/csharp/hosted-agents/bring-your-own/invocations/HelloWorld/README.md @@ -159,12 +159,7 @@ Press **F5** to start the agent. The agent starts and the **Agent Inspector** op dotnet restore ``` -2. Set the required environment variables (see [Environment variables](#environment-variables)): - - ```bash - export FOUNDRY_PROJECT_ENDPOINT="https://.services.ai.azure.com/api/projects/" - export AZURE_AI_MODEL_DEPLOYMENT_NAME="" - ``` +2. Configure the agent: copy `.env.example` to `.env` and fill in the values (see [Environment variables](#environment-variables)). The agent loads `.env` automatically on startup. 3. Sign in to Azure with the Azure CLI: diff --git a/samples/csharp/hosted-agents/bring-your-own/invocations/HelloWorld/src/hello-world-dotnet-invocations/HelloWorld.csproj b/samples/csharp/hosted-agents/bring-your-own/invocations/HelloWorld/src/hello-world-dotnet-invocations/HelloWorld.csproj index 2c197d48d..02687159f 100644 --- a/samples/csharp/hosted-agents/bring-your-own/invocations/HelloWorld/src/hello-world-dotnet-invocations/HelloWorld.csproj +++ b/samples/csharp/hosted-agents/bring-your-own/invocations/HelloWorld/src/hello-world-dotnet-invocations/HelloWorld.csproj @@ -19,6 +19,8 @@ + + diff --git a/samples/csharp/hosted-agents/bring-your-own/invocations/HelloWorld/src/hello-world-dotnet-invocations/Program.cs b/samples/csharp/hosted-agents/bring-your-own/invocations/HelloWorld/src/hello-world-dotnet-invocations/Program.cs index 183b6c7bc..d99d04acb 100644 --- a/samples/csharp/hosted-agents/bring-your-own/invocations/HelloWorld/src/hello-world-dotnet-invocations/Program.cs +++ b/samples/csharp/hosted-agents/bring-your-own/invocations/HelloWorld/src/hello-world-dotnet-invocations/Program.cs @@ -41,10 +41,14 @@ using Azure.AI.Extensions.OpenAI; using Azure.AI.Projects; using Azure.Identity; +using DotNetEnv; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using OpenAI.Responses; +// Load environment variables from a .env file if present (for local development). +Env.NoClobber().TraversePath().Load(); + // One-liner startup — wires up Kestrel on port 8088, OpenTelemetry, health probes, // and the Invocations API endpoints. Telemetry is configured automatically: // when APPLICATIONINSIGHTS_CONNECTION_STRING is set, traces and logs are sent to diff --git a/samples/csharp/hosted-agents/bring-your-own/invocations/human-in-the-loop/README.md b/samples/csharp/hosted-agents/bring-your-own/invocations/human-in-the-loop/README.md index 25ebd0087..f81ffabe8 100644 --- a/samples/csharp/hosted-agents/bring-your-own/invocations/human-in-the-loop/README.md +++ b/samples/csharp/hosted-agents/bring-your-own/invocations/human-in-the-loop/README.md @@ -171,12 +171,7 @@ Press **F5** to start the agent. The agent starts and the **Agent Inspector** op dotnet restore ``` -2. Set the required environment variables: - - ```bash - export FOUNDRY_PROJECT_ENDPOINT="https://your-resource.openai.azure.com/api/projects/proj" - export AZURE_AI_MODEL_DEPLOYMENT_NAME="gpt-5.4-mini" - ``` +2. Configure the agent: copy `.env.example` to `.env` and fill in the values. The agent loads `.env` automatically on startup. 3. Sign in to Azure with the Azure CLI: diff --git a/samples/csharp/hosted-agents/bring-your-own/invocations/human-in-the-loop/src/human-in-the-loop-dotnet-invocations/Program.cs b/samples/csharp/hosted-agents/bring-your-own/invocations/human-in-the-loop/src/human-in-the-loop-dotnet-invocations/Program.cs index 3bc3a2d26..29b1f8120 100644 --- a/samples/csharp/hosted-agents/bring-your-own/invocations/human-in-the-loop/src/human-in-the-loop-dotnet-invocations/Program.cs +++ b/samples/csharp/hosted-agents/bring-your-own/invocations/human-in-the-loop/src/human-in-the-loop-dotnet-invocations/Program.cs @@ -5,10 +5,14 @@ using Azure.AI.Extensions.OpenAI; using Azure.AI.Projects; using Azure.Identity; +using DotNetEnv; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using OpenAI.Responses; +// Load environment variables from a .env file if present (for local development). +Env.NoClobber().TraversePath().Load(); + // --------------------------------------------------------------------------- // Foundry project configuration // --------------------------------------------------------------------------- diff --git a/samples/csharp/hosted-agents/bring-your-own/invocations/human-in-the-loop/src/human-in-the-loop-dotnet-invocations/human-in-the-loop.csproj b/samples/csharp/hosted-agents/bring-your-own/invocations/human-in-the-loop/src/human-in-the-loop-dotnet-invocations/human-in-the-loop.csproj index 3e05cd2f5..e919b1f03 100644 --- a/samples/csharp/hosted-agents/bring-your-own/invocations/human-in-the-loop/src/human-in-the-loop-dotnet-invocations/human-in-the-loop.csproj +++ b/samples/csharp/hosted-agents/bring-your-own/invocations/human-in-the-loop/src/human-in-the-loop-dotnet-invocations/human-in-the-loop.csproj @@ -19,6 +19,8 @@ + + diff --git a/samples/csharp/hosted-agents/bring-your-own/invocations/notetaking-agent/README.md b/samples/csharp/hosted-agents/bring-your-own/invocations/notetaking-agent/README.md index e4606de29..b6219a907 100644 --- a/samples/csharp/hosted-agents/bring-your-own/invocations/notetaking-agent/README.md +++ b/samples/csharp/hosted-agents/bring-your-own/invocations/notetaking-agent/README.md @@ -128,15 +128,14 @@ Try sending `{"message": "save a note - book reservation for dinner"}`, then `{" ### Or run manually, then open the Inspector -1. Sign in to Azure with the Azure CLI (`az login`), build, and set env values: +1. Sign in to Azure with the Azure CLI (`az login`) and build: ```bash dotnet build - cp .env.example .env # then edit values (skip if .env already exists) - export FOUNDRY_PROJECT_ENDPOINT="https://your-project.services.ai.azure.com/api/projects/your-project" - export AZURE_AI_MODEL_DEPLOYMENT_NAME="gpt-5.4-mini" ``` + Copy `.env.example` to `.env` and fill in the values (the agent loads `.env` automatically on startup). + 2. Start the agent: `dotnet run` (listens on `http://localhost:8088`). 3. Command Palette (`Ctrl+Shift+P`) → **Foundry Toolkit: Open Agent Inspector**, then send a message to test. diff --git a/samples/csharp/hosted-agents/bring-your-own/invocations/notetaking-agent/src/notetaking-agent-dotnet-invocations/Program.cs b/samples/csharp/hosted-agents/bring-your-own/invocations/notetaking-agent/src/notetaking-agent-dotnet-invocations/Program.cs index 3b63d947a..1a69c97fa 100644 --- a/samples/csharp/hosted-agents/bring-your-own/invocations/notetaking-agent/src/notetaking-agent-dotnet-invocations/Program.cs +++ b/samples/csharp/hosted-agents/bring-your-own/invocations/notetaking-agent/src/notetaking-agent-dotnet-invocations/Program.cs @@ -5,10 +5,14 @@ using Azure.AI.Extensions.OpenAI; using Azure.AI.Projects; using Azure.Identity; +using DotNetEnv; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using OpenAI.Responses; +// Load environment variables from a .env file if present (for local development). +Env.NoClobber().TraversePath().Load(); + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING"))) Console.Error.WriteLine( "[WARNING] APPLICATIONINSIGHTS_CONNECTION_STRING not set — traces will not be sent " + diff --git a/samples/csharp/hosted-agents/bring-your-own/invocations/notetaking-agent/src/notetaking-agent-dotnet-invocations/notetaking-agent.csproj b/samples/csharp/hosted-agents/bring-your-own/invocations/notetaking-agent/src/notetaking-agent-dotnet-invocations/notetaking-agent.csproj index 0f2ee8f5e..22841cb98 100644 --- a/samples/csharp/hosted-agents/bring-your-own/invocations/notetaking-agent/src/notetaking-agent-dotnet-invocations/notetaking-agent.csproj +++ b/samples/csharp/hosted-agents/bring-your-own/invocations/notetaking-agent/src/notetaking-agent-dotnet-invocations/notetaking-agent.csproj @@ -20,6 +20,8 @@ + + diff --git a/samples/csharp/hosted-agents/bring-your-own/invocations_ws/HelloWorld/src/hello-world-dotnet-invocations-ws/HelloWorld.csproj b/samples/csharp/hosted-agents/bring-your-own/invocations_ws/HelloWorld/src/hello-world-dotnet-invocations-ws/HelloWorld.csproj index b28ba0e7b..7fee854c5 100644 --- a/samples/csharp/hosted-agents/bring-your-own/invocations_ws/HelloWorld/src/hello-world-dotnet-invocations-ws/HelloWorld.csproj +++ b/samples/csharp/hosted-agents/bring-your-own/invocations_ws/HelloWorld/src/hello-world-dotnet-invocations-ws/HelloWorld.csproj @@ -24,6 +24,8 @@ + + diff --git a/samples/csharp/hosted-agents/bring-your-own/invocations_ws/HelloWorld/src/hello-world-dotnet-invocations-ws/Program.cs b/samples/csharp/hosted-agents/bring-your-own/invocations_ws/HelloWorld/src/hello-world-dotnet-invocations-ws/Program.cs index 8a95d1495..f7e0f4baf 100644 --- a/samples/csharp/hosted-agents/bring-your-own/invocations_ws/HelloWorld/src/hello-world-dotnet-invocations-ws/Program.cs +++ b/samples/csharp/hosted-agents/bring-your-own/invocations_ws/HelloWorld/src/hello-world-dotnet-invocations-ws/Program.cs @@ -60,10 +60,14 @@ using Azure.AI.VoiceLive; using Azure.Core; using Azure.Identity; +using DotNetEnv; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +// Load environment variables from a .env file if present (for local development). +Env.NoClobber().TraversePath().Load(); + InvocationsServer.Run(configure: builder => { if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING"))) diff --git a/samples/csharp/hosted-agents/bring-your-own/responses/HelloWorld/README.md b/samples/csharp/hosted-agents/bring-your-own/responses/HelloWorld/README.md index 50ec91d7e..34f54b6f0 100644 --- a/samples/csharp/hosted-agents/bring-your-own/responses/HelloWorld/README.md +++ b/samples/csharp/hosted-agents/bring-your-own/responses/HelloWorld/README.md @@ -147,12 +147,7 @@ Press **F5** to start the agent. The agent starts and the **Agent Inspector** op dotnet restore ``` -2. Set the required environment variables (see [Environment variables](#environment-variables)): - - ```bash - export FOUNDRY_PROJECT_ENDPOINT="https://.services.ai.azure.com/api/projects/" - export AZURE_AI_MODEL_DEPLOYMENT_NAME="" - ``` +2. Configure the agent: copy `.env.example` to `.env` and fill in the values (see [Environment variables](#environment-variables)). The agent loads `.env` automatically on startup. 3. Sign in to Azure with the Azure CLI: diff --git a/samples/csharp/hosted-agents/bring-your-own/responses/HelloWorld/src/hello-world-dotnet-responses/HelloWorld.csproj b/samples/csharp/hosted-agents/bring-your-own/responses/HelloWorld/src/hello-world-dotnet-responses/HelloWorld.csproj index a6f43ae25..7c19f5ede 100644 --- a/samples/csharp/hosted-agents/bring-your-own/responses/HelloWorld/src/hello-world-dotnet-responses/HelloWorld.csproj +++ b/samples/csharp/hosted-agents/bring-your-own/responses/HelloWorld/src/hello-world-dotnet-responses/HelloWorld.csproj @@ -19,6 +19,8 @@ + + diff --git a/samples/csharp/hosted-agents/bring-your-own/responses/HelloWorld/src/hello-world-dotnet-responses/Program.cs b/samples/csharp/hosted-agents/bring-your-own/responses/HelloWorld/src/hello-world-dotnet-responses/Program.cs index 849faa2b1..276a1d2ab 100644 --- a/samples/csharp/hosted-agents/bring-your-own/responses/HelloWorld/src/hello-world-dotnet-responses/Program.cs +++ b/samples/csharp/hosted-agents/bring-your-own/responses/HelloWorld/src/hello-world-dotnet-responses/Program.cs @@ -32,9 +32,13 @@ using Azure.AI.Extensions.OpenAI; using Azure.AI.Projects; using Azure.Identity; +using DotNetEnv; using Microsoft.Extensions.Logging; using OpenAI.Responses; +// Load environment variables from a .env file if present (for local development). +Env.NoClobber().TraversePath().Load(); + // One-liner startup — wires up Kestrel on port 8088, OpenTelemetry, health probes, // and the Responses API endpoints. Telemetry is configured automatically: // when APPLICATIONINSIGHTS_CONNECTION_STRING is set, traces and logs are sent to diff --git a/samples/csharp/hosted-agents/bring-your-own/responses/background-agent/README.md b/samples/csharp/hosted-agents/bring-your-own/responses/background-agent/README.md index f12c00d3b..df1fa563d 100644 --- a/samples/csharp/hosted-agents/bring-your-own/responses/background-agent/README.md +++ b/samples/csharp/hosted-agents/bring-your-own/responses/background-agent/README.md @@ -135,12 +135,7 @@ Press **F5** to start the agent. The agent starts and the **Agent Inspector** op dotnet restore ``` -2. Set the required environment variables: - - ```bash - export FOUNDRY_PROJECT_ENDPOINT="https://your-resource.services.ai.azure.com/api/projects/your-project" - export AZURE_AI_MODEL_DEPLOYMENT_NAME="gpt-5.4-mini" - ``` +2. Configure the agent: copy `.env.example` to `.env` and fill in the values. The agent loads `.env` automatically on startup. 3. Sign in to Azure with the Azure CLI: diff --git a/samples/csharp/hosted-agents/bring-your-own/responses/background-agent/src/background-agent-dotnet-responses/Program.cs b/samples/csharp/hosted-agents/bring-your-own/responses/background-agent/src/background-agent-dotnet-responses/Program.cs index fac02aeea..a5d44c821 100644 --- a/samples/csharp/hosted-agents/bring-your-own/responses/background-agent/src/background-agent-dotnet-responses/Program.cs +++ b/samples/csharp/hosted-agents/bring-your-own/responses/background-agent/src/background-agent-dotnet-responses/Program.cs @@ -6,9 +6,13 @@ using Azure.AI.Extensions.OpenAI; using Azure.AI.Projects; using Azure.Identity; +using DotNetEnv; using Microsoft.Extensions.DependencyInjection; using OpenAI.Responses; +// Load environment variables from a .env file if present (for local development). +Env.NoClobber().TraversePath().Load(); + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING"))) Console.Error.WriteLine( "[WARNING] APPLICATIONINSIGHTS_CONNECTION_STRING not set — traces will not be sent " + diff --git a/samples/csharp/hosted-agents/bring-your-own/responses/background-agent/src/background-agent-dotnet-responses/background-agent.csproj b/samples/csharp/hosted-agents/bring-your-own/responses/background-agent/src/background-agent-dotnet-responses/background-agent.csproj index 2dee60a55..5031e285c 100644 --- a/samples/csharp/hosted-agents/bring-your-own/responses/background-agent/src/background-agent-dotnet-responses/background-agent.csproj +++ b/samples/csharp/hosted-agents/bring-your-own/responses/background-agent/src/background-agent-dotnet-responses/background-agent.csproj @@ -21,6 +21,8 @@ + + diff --git a/samples/csharp/hosted-agents/bring-your-own/responses/browser-automation/src/browser-automation-csharp-byo/Program.cs b/samples/csharp/hosted-agents/bring-your-own/responses/browser-automation/src/browser-automation-csharp-byo/Program.cs index 7bbc313d7..a1b61905d 100644 --- a/samples/csharp/hosted-agents/bring-your-own/responses/browser-automation/src/browser-automation-csharp-byo/Program.cs +++ b/samples/csharp/hosted-agents/bring-your-own/responses/browser-automation/src/browser-automation-csharp-byo/Program.cs @@ -20,6 +20,7 @@ using Azure.AI.Extensions.OpenAI; using Azure.AI.Projects; using Azure.Identity; +using DotNetEnv; using Microsoft.Extensions.DependencyInjection; using OpenAI.Responses; @@ -29,6 +30,9 @@ public class Program { public static void Main(string[] args) { + // Load environment variables from a .env file if present (for local development). + Env.NoClobber().TraversePath().Load(); + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING"))) Console.Error.WriteLine( "[WARNING] APPLICATIONINSIGHTS_CONNECTION_STRING not set — traces will not be sent " + diff --git a/samples/csharp/hosted-agents/bring-your-own/responses/browser-automation/src/browser-automation-csharp-byo/browser-automation.csproj b/samples/csharp/hosted-agents/bring-your-own/responses/browser-automation/src/browser-automation-csharp-byo/browser-automation.csproj index 7a858204c..65dd74e1b 100644 --- a/samples/csharp/hosted-agents/bring-your-own/responses/browser-automation/src/browser-automation-csharp-byo/browser-automation.csproj +++ b/samples/csharp/hosted-agents/bring-your-own/responses/browser-automation/src/browser-automation-csharp-byo/browser-automation.csproj @@ -20,6 +20,8 @@ + + diff --git a/samples/csharp/hosted-agents/bring-your-own/responses/env-vars-agent/README.md b/samples/csharp/hosted-agents/bring-your-own/responses/env-vars-agent/README.md index e49151215..c6435a673 100644 --- a/samples/csharp/hosted-agents/bring-your-own/responses/env-vars-agent/README.md +++ b/samples/csharp/hosted-agents/bring-your-own/responses/env-vars-agent/README.md @@ -165,19 +165,14 @@ what is TARGET? it is the target of an ApiKey connection. ### Or run manually, then open the Inspector -1. Sign in to Azure with the Azure CLI (`az login`), build, and set test env values: +1. Sign in to Azure with the Azure CLI (`az login`) and build: ```bash dotnet build - cp .env.example .env # then edit values — fill in any test values you like (skip if .env already exists) - export FOUNDRY_PROJECT_ENDPOINT="https://your-project.services.ai.azure.com/api/projects/your-project" - export AZURE_AI_MODEL_DEPLOYMENT_NAME="gpt-5.4-mini" - export SECRET_API_KEY="ab12-fake-test-key" - export TARGET="https://api.example.com" - export SECRET_KEY="p@ssw0rd-test-value" - export NON_SECRET_KEY="westus2" ``` + Copy `.env.example` to `.env` and fill in any test values you like (the agent loads `.env` automatically on startup). + 2. Start the agent: `dotnet run` (listens on `http://localhost:8088`). 3. Command Palette (`Ctrl+Shift+P`) → **Foundry Toolkit: Open Agent Inspector**, then send a message to test. diff --git a/samples/csharp/hosted-agents/bring-your-own/responses/env-vars-agent/src/env-vars-agent-dotnet-responses/EnvVarsAgent.csproj b/samples/csharp/hosted-agents/bring-your-own/responses/env-vars-agent/src/env-vars-agent-dotnet-responses/EnvVarsAgent.csproj index 8ae96dc41..6845849fe 100644 --- a/samples/csharp/hosted-agents/bring-your-own/responses/env-vars-agent/src/env-vars-agent-dotnet-responses/EnvVarsAgent.csproj +++ b/samples/csharp/hosted-agents/bring-your-own/responses/env-vars-agent/src/env-vars-agent-dotnet-responses/EnvVarsAgent.csproj @@ -20,6 +20,8 @@ + + diff --git a/samples/csharp/hosted-agents/bring-your-own/responses/env-vars-agent/src/env-vars-agent-dotnet-responses/Program.cs b/samples/csharp/hosted-agents/bring-your-own/responses/env-vars-agent/src/env-vars-agent-dotnet-responses/Program.cs index b65a281b9..70a246efb 100644 --- a/samples/csharp/hosted-agents/bring-your-own/responses/env-vars-agent/src/env-vars-agent-dotnet-responses/Program.cs +++ b/samples/csharp/hosted-agents/bring-your-own/responses/env-vars-agent/src/env-vars-agent-dotnet-responses/Program.cs @@ -6,9 +6,13 @@ using Azure.AI.Extensions.OpenAI; using Azure.AI.Projects; using Azure.Identity; +using DotNetEnv; using Microsoft.Extensions.DependencyInjection; using OpenAI.Responses; +// Load environment variables from a .env file if present (for local development). +Env.NoClobber().TraversePath().Load(); + // ────────────────────────────────────────────────────────────────── // Startup — wire up the Foundry Responses client // ────────────────────────────────────────────────────────────────── diff --git a/samples/csharp/hosted-agents/bring-your-own/responses/notetaking-agent/README.md b/samples/csharp/hosted-agents/bring-your-own/responses/notetaking-agent/README.md index 0cedeced2..956c0b102 100644 --- a/samples/csharp/hosted-agents/bring-your-own/responses/notetaking-agent/README.md +++ b/samples/csharp/hosted-agents/bring-your-own/responses/notetaking-agent/README.md @@ -128,15 +128,14 @@ get all my notes ### Or run manually, then open the Inspector -1. Sign in to Azure with the Azure CLI (`az login`), build, and set env values: +1. Sign in to Azure with the Azure CLI (`az login`) and build: ```bash dotnet build - cp .env.example .env # then edit values (skip if .env already exists) - export FOUNDRY_PROJECT_ENDPOINT="https://your-project.services.ai.azure.com/api/projects/your-project" - export AZURE_AI_MODEL_DEPLOYMENT_NAME="gpt-5.4-mini" ``` + Copy `.env.example` to `.env` and fill in the values (the agent loads `.env` automatically on startup). + 2. Start the agent: `dotnet run` (listens on `http://localhost:8088`). 3. Command Palette (`Ctrl+Shift+P`) → **Foundry Toolkit: Open Agent Inspector**, then send a message to test. diff --git a/samples/csharp/hosted-agents/bring-your-own/responses/notetaking-agent/src/notetaking-agent-dotnet-responses/Program.cs b/samples/csharp/hosted-agents/bring-your-own/responses/notetaking-agent/src/notetaking-agent-dotnet-responses/Program.cs index 4173c24ae..9907d3606 100644 --- a/samples/csharp/hosted-agents/bring-your-own/responses/notetaking-agent/src/notetaking-agent-dotnet-responses/Program.cs +++ b/samples/csharp/hosted-agents/bring-your-own/responses/notetaking-agent/src/notetaking-agent-dotnet-responses/Program.cs @@ -7,9 +7,13 @@ using Azure.AI.Extensions.OpenAI; using Azure.AI.Projects; using Azure.Identity; +using DotNetEnv; using Microsoft.Extensions.DependencyInjection; using OpenAI.Responses; +// Load environment variables from a .env file if present (for local development). +Env.NoClobber().TraversePath().Load(); + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING"))) Console.Error.WriteLine( "[WARNING] APPLICATIONINSIGHTS_CONNECTION_STRING not set — traces will not be sent " + diff --git a/samples/csharp/hosted-agents/bring-your-own/responses/notetaking-agent/src/notetaking-agent-dotnet-responses/notetaking-agent.csproj b/samples/csharp/hosted-agents/bring-your-own/responses/notetaking-agent/src/notetaking-agent-dotnet-responses/notetaking-agent.csproj index 6dab7cb1b..c60b657a1 100644 --- a/samples/csharp/hosted-agents/bring-your-own/responses/notetaking-agent/src/notetaking-agent-dotnet-responses/notetaking-agent.csproj +++ b/samples/csharp/hosted-agents/bring-your-own/responses/notetaking-agent/src/notetaking-agent-dotnet-responses/notetaking-agent.csproj @@ -20,6 +20,8 @@ + +