.NET: .NET samples: migrate coding samples to Foundry-first AIProjectClient#6557
.NET: .NET samples: migrate coding samples to Foundry-first AIProjectClient#6557alliscode wants to merge 4 commits into
Conversation
Replace AzureOpenAIClient with AIProjectClient as the AI provider in all 02-agents/Agents samples, aligning with the Foundry-first approach. Changes: - 19 Program.cs files migrated to use AIProjectClient.AsAIAgent() - 19 .csproj files updated (Azure.AI.OpenAI -> Microsoft.Agents.AI.Foundry) - Environment variables: AZURE_OPENAI_* -> FOUNDRY_PROJECT_ENDPOINT/FOUNDRY_MODEL - Updated description comments to reflect Foundry backend - Provider-specific samples in AgentsWithFoundry/ intentionally unchanged Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…enTelemetry to AIProjectClient Replace AzureOpenAIClient with AIProjectClient as the AI provider. Environment variables: AZURE_OPENAI_* -> FOUNDRY_PROJECT_ENDPOINT/FOUNDRY_MODEL. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace AzureOpenAIClient with AIProjectClient as the AI provider in all 03-workflows samples that use an AI model. Environment variables: AZURE_OPENAI_* -> FOUNDRY_PROJECT_ENDPOINT/FOUNDRY_MODEL. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Migrates .NET agent/workflow samples from AzureOpenAIClient-based wiring to Foundry-first defaults using AIProjectClient and the Foundry agent helpers, aligning sample code with the framework’s current direction.
Changes:
- Updated sample code to use
AIProjectClient.AsAIAgent(...)and Foundry env vars (FOUNDRY_PROJECT_ENDPOINT,FOUNDRY_MODEL, etc.). - Reworked workflow helpers/factories to accept
AIProjectClient + modelinstead ofIChatClient. - Updated sample project references to use
Microsoft.Agents.AI.Foundry(project refs and/or package refs), removing old OpenAI/AzureOpenAI-specific references.
Show a summary per file
| File | Description |
|---|---|
| dotnet/samples/03-workflows/Observability/WorkflowAsAnAgent/WorkflowHelper.cs | Refactors workflow helper to build agents from AIProjectClient + model and adds clientFactory telemetry wiring. |
| dotnet/samples/03-workflows/Observability/WorkflowAsAnAgent/WorkflowAsAnAgentObservability.csproj | Switches dependencies to Foundry project reference (removes old OpenAI packages). |
| dotnet/samples/03-workflows/Observability/WorkflowAsAnAgent/Program.cs | Uses Foundry env vars and creates AIProjectClient instead of AzureOpenAIClient. |
| dotnet/samples/03-workflows/ConditionalEdges/03_MultiSelection/Program.cs | Uses AIProjectClient + model and sets ChatOptions.ModelId for schema-based agents. |
| dotnet/samples/03-workflows/ConditionalEdges/03_MultiSelection/03_MultiSelection.csproj | Replaces OpenAI package refs with Foundry project reference. |
| dotnet/samples/03-workflows/ConditionalEdges/02_SwitchCase/Program.cs | Uses AIProjectClient + model and sets ChatOptions.ModelId. |
| dotnet/samples/03-workflows/ConditionalEdges/02_SwitchCase/02_SwitchCase.csproj | Replaces OpenAI package refs with Foundry project reference. |
| dotnet/samples/03-workflows/ConditionalEdges/01_EdgeCondition/Program.cs | Uses AIProjectClient + model and sets ChatOptions.ModelId. |
| dotnet/samples/03-workflows/ConditionalEdges/01_EdgeCondition/01_EdgeCondition.csproj | Replaces OpenAI package refs with Foundry project reference. |
| dotnet/samples/03-workflows/Agents/WorkflowAsAnAgent/WorkflowFactory.cs | Updates workflow factory to accept AIProjectClient + model and create agents via Foundry. |
| dotnet/samples/03-workflows/Agents/WorkflowAsAnAgent/WorkflowAsAnAgent.csproj | Replaces OpenAI package refs with Foundry project reference. |
| dotnet/samples/03-workflows/Agents/WorkflowAsAnAgent/Program.cs | Updates to Foundry env vars + AIProjectClient and passes model into workflow factory. |
| dotnet/samples/03-workflows/Agents/GroupChatToolApproval/Program.cs | Migrates participant agents to aiProjectClient.AsAIAgent(model: ...). |
| dotnet/samples/03-workflows/Agents/GroupChatToolApproval/GroupChatToolApproval.csproj | Replaces OpenAI package refs with Foundry project reference. |
| dotnet/samples/03-workflows/Agents/CustomAgentExecutors/Program.cs | Updates custom executors to create agents via AIProjectClient.AsAIAgent(...) with ModelId. |
| dotnet/samples/03-workflows/Agents/CustomAgentExecutors/CustomAgentExecutors.csproj | Replaces OpenAI package refs with Foundry project reference. |
| dotnet/samples/03-workflows/_StartHere/07_WriterCriticWorkflow/Program.cs | Migrates writer/critic workflow to Foundry-first AIProjectClient + model. |
| dotnet/samples/03-workflows/_StartHere/07_WriterCriticWorkflow/07_WriterCriticWorkflow.csproj | Adds Foundry project reference and removes old OpenAI package refs. |
| dotnet/samples/03-workflows/_StartHere/06_MixedWorkflowAgentsAndExecutors/Program.cs | Migrates mixed workflow sample to Foundry-first AIProjectClient + model. |
| dotnet/samples/03-workflows/_StartHere/06_MixedWorkflowAgentsAndExecutors/06_MixedWorkflowAgentsAndExecutors.csproj | Replaces OpenAI package refs with Foundry project reference. |
| dotnet/samples/03-workflows/_StartHere/03_AgentWorkflowPatterns/Program.cs | Migrates sequential/concurrent/handoff/groupchat agents to AIProjectClient.AsAIAgent(model: ...). |
| dotnet/samples/03-workflows/_StartHere/03_AgentWorkflowPatterns/03_AgentWorkflowPatterns.csproj | Replaces OpenAI package refs with Foundry project reference. |
| dotnet/samples/03-workflows/_StartHere/02_AgentsInWorkflows/Program.cs | Migrates agents-in-workflows sample to Foundry-first client + model. |
| dotnet/samples/03-workflows/_StartHere/02_AgentsInWorkflows/02_AgentsInWorkflows.csproj | Replaces OpenAI package refs with Foundry project reference. |
| dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step05_Neo4jGraphRAG/Program.cs | Migrates Neo4j GraphRAG sample to Foundry-first client usage (but needs follow-up fixes). |
| dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step05_Neo4jGraphRAG/AgentWithRAG_Step05_Neo4jGraphRAG.csproj | Swaps prior OpenAI deps to Microsoft.Agents.AI.Foundry package reference. |
| dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step03_CustomRAGDataSource/Program.cs | Migrates custom RAG data source sample to AIProjectClient and sets ModelId. |
| dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step03_CustomRAGDataSource/AgentWithRAG_Step03_CustomRAGDataSource.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step02_CustomVectorStoreRAG/Program.cs | Migrates to Foundry; updates embeddings path to GetProjectOpenAIClient().GetEmbeddingClient(...); uses FOUNDRY_EMBEDDING_MODEL. |
| dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step02_CustomVectorStoreRAG/AgentWithRAG_Step02_CustomVectorStoreRAG.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/Program.cs | Migrates to Foundry; updates embeddings to GetProjectOpenAIClient().GetEmbeddingClient(...); uses FOUNDRY_EMBEDDING_MODEL. |
| dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/AgentWithRAG_Step01_BasicTextRAG.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step05_BoundedChatHistory/Program.cs | Migrates to Foundry; uses project OpenAI client for embeddings and sets ChatOptions.ModelId. |
| dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step05_BoundedChatHistory/AgentWithMemory_Step05_BoundedChatHistory.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step03_MemoryUsingValkey/Program.cs | Migrates to Foundry; removes OpenAI.Chat usage; sets ChatOptions.ModelId. |
| dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step03_MemoryUsingValkey/AgentWithMemory_Step03_MemoryUsingValkey.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step02_MemoryUsingMem0/Program.cs | Migrates to Foundry; creates AIProjectClient and sets ChatOptions.ModelId. |
| dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step02_MemoryUsingMem0/AgentWithMemory_Step02_MemoryUsingMem0.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step01_ChatHistoryMemory/Program.cs | Migrates to Foundry; uses project OpenAI client for embeddings and sets ChatOptions.ModelId. |
| dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step01_ChatHistoryMemory/AgentWithMemory_Step01_ChatHistoryMemory.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentWithCodeAct/AgentWithCodeAct_Step03_ManualWiring/Program.cs | Migrates to Foundry-first and passes model: explicitly. |
| dotnet/samples/02-agents/AgentWithCodeAct/AgentWithCodeAct_Step03_ManualWiring/AgentWithCodeAct_Step03_ManualWiring.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentWithCodeAct/AgentWithCodeAct_Step02_ToolEnabled/Program.cs | Migrates to Foundry; sets ChatOptions.ModelId; removes OpenAI.Chat dependency. |
| dotnet/samples/02-agents/AgentWithCodeAct/AgentWithCodeAct_Step02_ToolEnabled/AgentWithCodeAct_Step02_ToolEnabled.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentWithCodeAct/AgentWithCodeAct_Step01_Interpreter/Program.cs | Migrates to Foundry; sets ChatOptions.ModelId; removes OpenAI.Chat dependency. |
| dotnet/samples/02-agents/AgentWithCodeAct/AgentWithCodeAct_Step01_Interpreter/AgentWithCodeAct_Step01_Interpreter.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step06_McpBasedSkills/Program.cs | Migrates MCP skills sample to Foundry-first and sets ChatOptions.ModelId. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step06_McpBasedSkills/Agent_Step06_McpBasedSkills.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step05_SkillsWithDI/Program.cs | Migrates DI-based skills sample to Foundry-first and sets ChatOptions.ModelId. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step05_SkillsWithDI/Agent_Step05_SkillsWithDI.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step04_MixedSkills/Program.cs | Migrates mixed skills sample to Foundry-first and sets ChatOptions.ModelId. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step04_MixedSkills/Agent_Step04_MixedSkills.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step03_ClassBasedSkills/Program.cs | Migrates class-based skills sample to Foundry-first and sets ChatOptions.ModelId. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step03_ClassBasedSkills/Agent_Step03_ClassBasedSkills.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step02_CodeDefinedSkills/Program.cs | Migrates code-defined skills sample to Foundry-first and sets ChatOptions.ModelId. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step02_CodeDefinedSkills/Agent_Step02_CodeDefinedSkills.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step01_FileBasedSkills/Program.cs | Migrates file-based skills sample to Foundry-first and sets ChatOptions.ModelId. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step01_FileBasedSkills/Agent_Step01_FileBasedSkills.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step21_ShellWithEnvironment/Program.cs | Migrates shell tool sample to AIProjectClient.AsAIAgent(...) and sets ModelId. |
| dotnet/samples/02-agents/Agents/Agent_Step21_ShellWithEnvironment/Agent_Step21_ShellWithEnvironment.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step20_DynamicFunctionTools/Program.cs | Migrates dynamic tools sample to Foundry agent + clientFactory middleware wiring. |
| dotnet/samples/02-agents/Agents/Agent_Step20_DynamicFunctionTools/Agent_Step20_DynamicFunctionTools.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step19_InFunctionLoopCheckpointing/Program.cs | Migrates checkpointing sample to Foundry Responses client wiring for model; updates env vars. |
| dotnet/samples/02-agents/Agents/Agent_Step19_InFunctionLoopCheckpointing/Agent_Step19_InFunctionLoopCheckpointing.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step18_CompactionPipeline/Program.cs | Migrates compaction pipeline sample to Foundry-first client setup and responses chat clients. |
| dotnet/samples/02-agents/Agents/Agent_Step18_CompactionPipeline/Agent_Step18_CompactionPipeline.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step17_AdditionalAIContext/Program.cs | Migrates custom AIContextProviders sample to Foundry-first and sets ModelId. |
| dotnet/samples/02-agents/Agents/Agent_Step17_AdditionalAIContext/Agent_Step17_AdditionalAIContext.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step16_Declarative/Program.cs | Migrates declarative agent sample to Foundry-first; uses responses chat client from project. |
| dotnet/samples/02-agents/Agents/Agent_Step16_Declarative/Agent_Step16_Declarative.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step14_BackgroundResponses/Program.cs | Migrates background responses sample to Foundry-first agent construction. |
| dotnet/samples/02-agents/Agents/Agent_Step14_BackgroundResponses/Agent_Step14_BackgroundResponses.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step13_ChatReduction/Program.cs | Migrates chat reduction sample to Foundry-first and sets ModelId. |
| dotnet/samples/02-agents/Agents/Agent_Step13_ChatReduction/Agent_Step13_ChatReduction.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step12_Plugins/Program.cs | Migrates plugin/DI tools sample to Foundry-first agent creation. |
| dotnet/samples/02-agents/Agents/Agent_Step12_Plugins/Agent_Step12_Plugins.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step11_Middleware/Program.cs | Migrates middleware sample to Foundry-first with clientFactory pipeline customization. |
| dotnet/samples/02-agents/Agents/Agent_Step11_Middleware/Agent_Step11_Middleware.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step10_BackgroundResponsesWithToolsAndPersistence/Program.cs | Migrates background responses + persistence sample to Foundry-first agent construction. |
| dotnet/samples/02-agents/Agents/Agent_Step10_BackgroundResponsesWithToolsAndPersistence/Agent_Step10_BackgroundResponsesWithToolsAndPersistence.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step09_AsFunctionTool/Program.cs | Migrates “agent as tool” sample to Foundry-first; builds both agents from project client. |
| dotnet/samples/02-agents/Agents/Agent_Step09_AsFunctionTool/Agent_Step09_AsFunctionTool.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step08_UsingImages/Program.cs | Migrates vision sample to Foundry-first and passes model: explicitly. |
| dotnet/samples/02-agents/Agents/Agent_Step08_UsingImages/Agent_Step08_UsingImages.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step06_DependencyInjection/Program.cs | Migrates DI sample to Foundry-first by creating agent via AIProjectClient.AsAIAgent(...). |
| dotnet/samples/02-agents/Agents/Agent_Step06_DependencyInjection/Agent_Step06_DependencyInjection.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step05_Observability/Program.cs | Migrates observability sample to Foundry-first and uses agent-level OpenTelemetry builder. |
| dotnet/samples/02-agents/Agents/Agent_Step05_Observability/Agent_Step05_Observability.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step04_3rdPartyChatHistoryStorage/Program.cs | Migrates custom chat history provider sample to Foundry-first and sets ModelId. |
| dotnet/samples/02-agents/Agents/Agent_Step04_3rdPartyChatHistoryStorage/Agent_Step04_3rdPartyChatHistoryStorage.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step03_PersistedConversations/Program.cs | Migrates persisted conversations sample to Foundry-first AIProjectClient.AsAIAgent(model: ...). |
| dotnet/samples/02-agents/Agents/Agent_Step03_PersistedConversations/Agent_Step03_PersistedConversations.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step02_StructuredOutput/Program.cs | Migrates structured output sample to Foundry-first and updates structured output wiring. |
| dotnet/samples/02-agents/Agents/Agent_Step02_StructuredOutput/Agent_Step02_StructuredOutput.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/Agents/Agent_Step01_UsingFunctionToolsWithApprovals/Program.cs | Migrates approvals/tools sample to Foundry-first agent creation. |
| dotnet/samples/02-agents/Agents/Agent_Step01_UsingFunctionToolsWithApprovals/Agent_Step01_UsingFunctionToolsWithApprovals.csproj | Replaces OpenAI deps with Foundry project reference. |
| dotnet/samples/02-agents/AgentOpenTelemetry/Program.cs | Migrates end-to-end OTel sample to Foundry-first with clientFactory + agent-level OTel. |
| dotnet/samples/02-agents/AgentOpenTelemetry/AgentOpenTelemetry.csproj | Replaces OpenAI deps with Foundry project reference and trims unused packages. |
Copilot's findings
Comments suppressed due to low confidence (1)
dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step05_Neo4jGraphRAG/Program.cs:62
- This sample now calls AIProjectClient.AsIChatClient(deploymentName), but there is no AsIChatClient extension for AIProjectClient. Also, ChatClientAgentOptions.ChatOptions is missing ModelId, so AIProjectClient.AsAIAgent(options) will throw/ fail to compile. Create the agent directly from AIProjectClient and set ChatOptions.ModelId.
- Files reviewed: 98/98 changed files
- Comments generated: 9
There was a problem hiding this comment.
Automated Code Review
Reviewers: 5 | Confidence: 91%
✓ Correctness
No actionable issues found in this dimension.
✓ Security Reliability
No actionable issues found in this dimension.
✓ Test Coverage
No actionable issues found in this dimension.
✓ Failure Modes
No actionable issues found in this dimension.
✗ Design Approach
I found one blocking issue in the Foundry migration for these samples: the Neo4j GraphRAG sample switched to a chat-client construction pattern that is inconsistent with the repo’s established Foundry integration path and should be aligned before merge. I found one design issue in the migrated samples: a couple of programs now bypass the repo's Foundry wrapper path and construct raw Responses chat clients directly, which diverges from the centralized Foundry-first pattern the codebase added for uniform telemetry and request handling.
Flagged Issues
-
dotnet/samples/03-workflows/_StartHere/06_MixedWorkflowAgentsAndExecutors/06_MixedWorkflowAgentsAndExecutors.csproj:11-15anddotnet/samples/03-workflows/_StartHere/07_WriterCriticWorkflow/07_WriterCriticWorkflow.csproj:12-20drop the explicitAzure.Identityreference even though theirProgram.csfiles instantiateDefaultAzureCredential(06../Program.cs:46,07.../Program.cs:53).
Suggestions
- Update
dotnet/samples/03-workflows/_StartHere/07_WriterCriticWorkflow/Program.cs:39to describe Foundry prerequisites, since the sample now readsFOUNDRY_PROJECT_ENDPOINT/FOUNDRY_MODELat lines 51-52.
Automated review by alliscode's agents
|
Flagged issue
Source: automated DevFlow PR review |
- Add explicit Azure.Identity package references to migrated sample projects that use DefaultAzureCredential - Fix AgentWithRAG_Step05_Neo4jGraphRAG to use AIProjectClient.AsAIAgent() with ChatOptions.ModelId instead of AIProjectClient.AsIChatClient() - Keep migrated samples on AIProjectClient pattern (no FoundryAgent/AzureOpenAIClient) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Continues the dotnet sample modernization sequence after structural alignment (#6485) by applying the coding migration to Foundry-first defaults.
This revives and updates the original intent from the older sample-clean work (including the #4394 thread), but rebased onto current main with current directory structure and conventions.
What changed
02-agents/Agents
02-agents other groups
03-workflows
Notes
Contribution Checklist