.NET: Migrate 01-get-started samples to Foundry as canonical default#6555
.NET: Migrate 01-get-started samples to Foundry as canonical default#6555alliscode wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Migrates the canonical .NET “01-get-started” samples to use Microsoft Foundry (Foundry Responses API) as the default backend, updating code, environment variables, and project references so the onboarding path aligns with the Foundry-first direction of the Agent Framework samples.
Changes:
- Switch
01-get-startedsamples from Azure OpenAI (AzureOpenAIClient) to Foundry (FoundryAgent) and rename env vars toFOUNDRY_PROJECT_ENDPOINT/FOUNDRY_MODEL. - Update sample project dependencies to reference
Microsoft.Agents.AI.Foundryand remove Azure OpenAI-specific packages/references. - Refresh
dotnet/samples/AGENTS.mdto document Foundry as the default provider and point readers to other provider samples.
Show a summary per file
| File | Description |
|---|---|
| dotnet/samples/AGENTS.md | Updates documentation to state Foundry is the default backend for canonical samples and updates the example/env vars accordingly. |
| dotnet/samples/01-get-started/01_hello_agent/Program.cs | Migrates the “hello agent” sample to instantiate and run a FoundryAgent. |
| dotnet/samples/01-get-started/01_hello_agent/01_hello_agent.csproj | Removes Azure OpenAI deps and references the Foundry project. |
| dotnet/samples/01-get-started/02_add_tools/Program.cs | Migrates the tools sample to use FoundryAgent and keeps function tool wiring. |
| dotnet/samples/01-get-started/02_add_tools/02_add_tools.csproj | Removes Azure OpenAI deps and references the Foundry project. |
| dotnet/samples/01-get-started/03_multi_turn/Program.cs | Migrates multi-turn conversation sample to FoundryAgent with Foundry env vars. |
| dotnet/samples/01-get-started/03_multi_turn/03_multi_turn.csproj | Removes Azure OpenAI deps and references the Foundry project. |
| dotnet/samples/01-get-started/04_memory/Program.cs | Migrates memory sample to Foundry and updates how the IChatClient is obtained and passed into the memory provider. |
| dotnet/samples/01-get-started/04_memory/04_memory.csproj | Removes Azure OpenAI deps and references the Foundry project; swaps to MEAI abstractions. |
| dotnet/samples/01-get-started/06_host_your_agent/Program.cs | Migrates Azure Functions hosting sample to use FoundryAgent and Foundry env vars. |
| dotnet/samples/01-get-started/06_host_your_agent/06_host_your_agent.csproj | Removes Azure OpenAI deps and references the Foundry project. |
Copilot's findings
- Files reviewed: 11/11 changed files
- Comments generated: 1
There was a problem hiding this comment.
Automated Code Review
Reviewers: 5 | Confidence: 92%
✓ Correctness
This PR cleanly migrates the 01-get-started samples from Azure OpenAI to Microsoft Foundry. The API usage is correct: FoundryAgent constructor signatures match, GetService() delegation chain works properly, and transitive dependencies (Microsoft.Extensions.AI for AIFunctionFactory) are satisfied through the Foundry project reference. The only issue is a missing using directive in the AGENTS.md documentation snippet.
✓ Security Reliability
This PR migrates 01-get-started samples from Azure OpenAI to Microsoft Foundry. The changes are straightforward provider swaps with no security or reliability regressions. All samples properly validate required environment variables, include appropriate warnings about DefaultAzureCredential in production, hardcode no secrets, and the FoundryAgent constructor validates all parameters (null/whitespace checks on model, instructions, endpoint, credential). The 04_memory sample correctly handles the nullable return from GetService() with an explicit null check and throw.
✓ Test Coverage
The PR migrates 01-get-started samples from Azure OpenAI to Microsoft Foundry but does not update the sample verification harness (dotnet/eng/verify-samples/GetStartedSamples.cs). That file still declares RequiredEnvironmentVariables as ['AZURE_OPENAI_ENDPOINT'] and OptionalEnvironmentVariables as ['AZURE_OPENAI_DEPLOYMENT_NAME'] for samples 01–04 and 06, but the samples now require FOUNDRY_PROJECT_ENDPOINT and optionally FOUNDRY_MODEL. This means the harness will incorrectly skip these samples when only Foundry env vars are set, or attempt to run them (then fail at startup) when only the old OpenAI env vars are set.
✓ Failure Modes
This PR cleanly migrates 01-get-started samples from Azure OpenAI to Microsoft Foundry. The most complex change (04_memory) creates a FoundryAgent to bootstrap the IChatClient, extracts it via GetService(), and wraps it in a new ChatClientAgent with different options. This pattern is safe: the null check properly handles the failure case, the middleware deduplication in WithDefaultAgentMiddleware prevents double-decoration, and the baseAgent's instructions don't propagate through the raw IChatClient. All other samples are straightforward constructor swaps with no new failure paths introduced.
✓ Design Approach
I found one non-blocking design inconsistency in the
04_memorysample. The PR updates the canonical01-get-startedstory to say these samples use Foundry viaFoundryAgentorAIProjectClient.AsAIAgent(), but this sample still drops down to a genericIChatClient.AsAIAgent(...)path after constructing a temporaryFoundryAgent. The repo already provides anAIProjectClient.AsAIAgent(ChatClientAgentOptions)overload for exactly this kind of customized setup, so the current approach weakens the new canonical provider story without adding capability.
Automated review by alliscode's agents
Change canonical provider from Azure OpenAI to Microsoft Foundry Responses API: Code changes: - Updated all 01-get-started samples (01_hello_agent, 02_add_tools, 03_multi_turn, 04_memory, 06_host_your_agent) to use FoundryAgent or AIProjectClient.AsAIAgent() - Updated environment variables: AZURE_OPENAI_* → FOUNDRY_PROJECT_ENDPOINT/FOUNDRY_MODEL - Updated .csproj files to reference Microsoft.Agents.AI.Foundry instead of Azure.AI.OpenAI - Added warning comments about DefaultAzureCredential production usage - 05_first_workflow unchanged (workflow pattern only, no AI model) Documentation changes: - Updated AGENTS.md Default provider section to reflect Foundry as canonical - Updated code example to use FoundryAgent constructor pattern - Updated env var documentation Note: 04_memory (AIContextProvider sample) extracts IChatClient from FoundryAgent to maintain the memory pattern while using Foundry backend. All samples verified to build successfully. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
e7bc35a to
199fbe7
Compare
- Add Microsoft.Agents.AI.Foundry using to AGENTS.md Foundry snippet - Update verify-samples GetStarted env vars to FOUNDRY_PROJECT_ENDPOINT/FOUNDRY_MODEL - Remove unnecessary usings flagged by dotnet format in 01_get_started samples Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…AIAgent() Use AIProjectClient.AsAIAgent() as the canonical pattern for all 01-get-started samples. Reserve FoundryAgent only for samples that specifically demonstrate the Foundry-managed (prompt) agent — i.e. 02-agents/AgentsWithFoundry/. Changes: - 01_hello_agent, 02_add_tools, 03_multi_turn, 06_host_your_agent: swap FoundryAgent constructor for AIProjectClient.AsAIAgent(model, instructions) - 04_memory: get IChatClient via AIProjectClient.AsAIAgent(options).GetService() instead of extracting from a throwaway FoundryAgent - AGENTS.md: update default-provider snippet and note on when to use FoundryAgent Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This pull request updates the canonical "01-get-started" .NET samples to use Microsoft Foundry as the default AI provider instead of Azure OpenAI. It replaces all references to Azure OpenAI with Microsoft Foundry, updates environment variables, and adjusts project dependencies accordingly. The documentation is also revised to reflect these changes.
Provider migration and environment variables:
01-get-startednow useFoundryAgentfromMicrosoft.Agents.AI.Foundryinstead ofAzureOpenAIClientfromMicrosoft.Agents.AI.OpenAI. [1] [2] [3] [4] [5]AZURE_OPENAI_ENDPOINTandAZURE_OPENAI_DEPLOYMENT_NAMEtoFOUNDRY_PROJECT_ENDPOINTandFOUNDRY_MODELthroughout code, sample verification, and documentation. [1] [2] [3] [4] [5] [6]Project and package dependency updates:
.csprojfiles now referenceMicrosoft.Agents.AI.FoundryandMicrosoft.Extensions.AI.Abstractionsinstead of OpenAI-specific packages. [1] [2]Sample code and logic changes:
FoundryAgent, including for advanced scenarios like memory and Azure Functions hosting. [1] [2] [3]Documentation updates:
AGENTS.mdis updated to show Foundry as the default provider, including code snippets and environment variable descriptions. [1] [2]