.NET [WIP] Foundry Hosted Agents Support#5312
Conversation
Implement Microsoft.Agents.AI.Hosting.AzureAIResponses to host agent-framework AIAgents and workflows within Azure Foundry as hosted agents via the Azure.AI.AgentServer.Responses SDK. - AgentFrameworkResponseHandler: bridges ResponseHandler to AIAgent execution - InputConverter: converts Responses API inputs/history to MEAI ChatMessage - OutputConverter: converts agent response updates to SSE event stream - ServiceCollectionExtensions: DI registration helpers - 336 unit tests across net8.0/net9.0/net10.0 (112 per TFM) - ResponseStreamValidator: SSE protocol validation tool for samples - FoundryResponsesHosting sample app Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…mainline Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move source and test files from the standalone Hosting.AzureAIResponses project into the Foundry package under a Hosting/ subfolder. This consolidates the Foundry-specific hosting adapter into the main Foundry package. - Source: Microsoft.Agents.AI.Foundry.Hosting namespace - Tests: merged into Foundry.UnitTests/Hosting/ - Conditionally compiled for .NETCoreApp TFMs only (net8.0+) - Deleted standalone Hosting.AzureAIResponses project and test project - Updated sample and solution references Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- OpenTelemetry/Api/Exporter.Console/Exporter.InMemory: 1.13.1 -> 1.15.0 - OpenTelemetry.Exporter.OpenTelemetryProtocol: already 1.15.0 - OpenTelemetry.Extensions.Hosting: already 1.14.0 - OpenTelemetry.Instrumentation.AspNetCore/Http: already 1.14.0 - OpenTelemetry.Instrumentation.Runtime: 1.13.0 -> 1.14.0 - Azure.Monitor.OpenTelemetry.Exporter: 1.4.0 -> 1.5.0 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- InputConverter: stop propagating request.Model to ChatOptions.ModelId Hosted agents use their own model; client-provided model values like 'hosted-agent' were being passed through and causing server errors. - Add FoundryResponsesRepl sample: interactive CLI client that connects to a Foundry Responses endpoint using ResponsesClient.AsAIAgent() - Bump package version to 0.9.0-hosted.260403.1 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Previously, unhandled exceptions from agent execution would bubble up to the SDK orchestrator, which emits a generic 'An internal server error occurred.' message — hiding the actual cause (e.g., 401 auth failures, model not found, etc.). Now AgentFrameworkResponseHandler catches non-cancellation exceptions and emits a proper response.failed event containing the real error message, making it visible to clients and in logs. OperationCanceledException still propagates for proper cancellation handling by the SDK. Also bumps package version to 0.9.0-hosted.260403.2. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Rename AddAgentFrameworkHandler to AddFoundryResponses and add MapFoundryResponses - Rename extension methods: AddAgentFrameworkHandler -> AddFoundryResponses, MapAgentFrameworkHandler -> MapFoundryResponses - AddFoundryResponses now calls AddResponsesServer() internally - Add MapFoundryResponses() extension on IEndpointRouteBuilder - Update sample and tests to use new API names - Remove redundant AddResponsesServer() and /ready endpoint from sample Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fixing numbering in sample. --------- Co-authored-by: alliscode <bentho@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…gn Consumption vs Hosting
Demonstrates two MCP integration layers in a single hosted agent: - Client-side MCP: McpClient connects to Microsoft Learn, agent handles tool invocations locally (docs_search, code_sample_search, docs_fetch) - Server-side MCP: HostedMcpServerTool delegates tool discovery and invocation to the LLM provider (Responses API), no local connection Includes DevTemporaryTokenCredential for Docker local debugging, Dockerfile.contributor for ProjectReference builds, and the openai/v1 route mapping for AIProjectClient compatibility in Development mode.
…fix br… (#5287) * Bump Azure.AI.AgentServer packages to 1.0.0-beta.1/beta.21 and fix breaking API changes - Azure.AI.AgentServer.Core: 1.0.0-beta.11 -> 1.0.0-beta.21 - Azure.AI.AgentServer.Invocations: 1.0.0-alpha.20260408.4 -> 1.0.0-beta.1 - Azure.AI.AgentServer.Responses: 1.0.0-alpha.20260408.4 -> 1.0.0-beta.1 - Azure.Identity: 1.20.0 -> 1.21.0 (transitive requirement) - Azure.Core: 1.52.0 -> 1.53.0 (transitive requirement) - Remove azure-sdk-for-net dev feed (packages now on nuget.org) - Fix OutputConverter for new builder API (auto-tracked children, split EmitTextDone/EmitDone) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fixing small issues. --------- Co-authored-by: alliscode <bentho@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…coding and style Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add InMemoryAgentSessionStore registration to all ServiceCollection setups in AgentFrameworkResponseHandlerTests and WorkflowIntegrationTests. This is needed after the AgentSessionStore infrastructure was introduced in the responses-hosting feature. Tests still have NotImplementedException stubs for CreateSessionCoreAsync which will be fixed when the session infrastructure is fully available. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add Hosted-Invocations-EchoAgent: a minimal echo agent hosted via the Invocations protocol (POST /invocations) using AddInvocationsServer and MapInvocationsServer, bridged to an Agent Framework AIAgent through a custom InvocationHandler. Add SimpleInvocationsAgent: a console REPL client that wraps HttpClient calls to the /invocations endpoint in a custom InvocationsAIAgent, demonstrating programmatic consumption of the Invocations protocol. Both samples default to port 8088 for consistency with other hosted agent samples.
…oft/agent-framework into hosted-agent-adapter # Conflicts: # dotnet/nuget/nuget-package.props # dotnet/samples/04-hosting/FoundryHostedAgents/HostedAgentsV2/Hosted-ChatClientAgent/Program.cs # dotnet/samples/04-hosting/FoundryHostedAgents/HostedAgentsV2/Hosted-FoundryAgent/Program.cs # dotnet/samples/04-hosting/FoundryHostedAgents/HostedAgentsV2/Hosted-LocalTools/Program.cs # dotnet/samples/04-hosting/FoundryHostedAgents/HostedAgentsV2/Hosted-McpTools/Program.cs # dotnet/samples/04-hosting/FoundryHostedAgents/HostedAgentsV2/Hosted-Workflows/Program.cs # dotnet/samples/04-hosting/FoundryResponsesHosting/Program.cs # dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/AgentFrameworkResponseHandlerTests.cs # dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/InputConverterTests.cs # dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/OutputConverterTests.cs # dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/ServiceCollectionExtensionsTests.cs # dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/WorkflowIntegrationTests.cs
Align dotnet hosted agent samples with the Python side (PR #5281) by reorganizing the directory structure: - Remove HostedAgentsV1 entirely (old API pattern) - Split HostedAgentsV2 into invocations/ and responses/ based on protocol - Move Using-Samples accordingly (SimpleAgent to responses, SimpleInvocationsAgent to invocations) - Update slnx with new project paths and add previously missing invocations projects - Update README cd paths from HostedAgentsV2 to invocations or responses - Rename .env.local to .env.example to match Python naming convention - Fix format violations in newly included invocations projects
- Delete all launchSettings.json files (port 8088 now comes from ASPNETCORE_URLS in .env) - Add DotNetEnv to Hosted-Invocations-EchoAgent so it loads .env like the responses samples - Create .env.example for EchoAgent with ASPNETCORE_URLS and ASPNETCORE_ENVIRONMENT - Add AGENT_NAME to ChatClientAgent and FoundryAgent .env.example (required by those samples) - Add AZURE_BEARER_TOKEN=DefaultAzureCredential to all .env.example files - Update DevTemporaryTokenCredential in all 6 samples to treat the sentinel value as unavailable, allowing ChainedTokenCredential to fall through to DefaultAzureCredential - Update EchoAgent README with Configuration section
… GetResponsesClient
…doff to Hosted-Workflow-Handoff
…ed-Workflow-Handoff - Add Dockerfile and Dockerfile.contributor for Docker-based testing - Add agent.yaml and agent.manifest.yaml with triage-workflow as primary agent - Add README.md following sibling pattern, noting Azure OpenAI vs Foundry endpoint - Add DevTemporaryTokenCredential and ChainedTokenCredential for Docker auth - Register triage-workflow as non-keyed default so azd invoke works without model - Update .env.example with AZURE_BEARER_TOKEN sentinel - Add .gitignore to 04-hosting to suppress VS-generated launchSettings.json - Fix docker run image name in Hosted-Workflow-Simple README
…y Hosted Agents (#5316) * Auto-instrument resolved AIAgents with OpenTelemetry using Core ResponsesSourceName * Add OTel telemetry capture tests for Foundry hosted agent handler
* Prepare Foundry preview release 1.2.0-preview.* Bump VersionPrefix to 1.2.0 and update the preview stamp date. Invert packaging opt-in so only the Foundry preview set produces NuGet packages: - Microsoft.Agents.AI.Abstractions - Microsoft.Agents.AI - Microsoft.Agents.AI.Workflows - Microsoft.Agents.AI.Workflows.Generators - Microsoft.Agents.AI.Foundry Flip IsReleased=false on the preview set so they pick up the -preview.YYMMDD.N suffix. Gate GeneratePackageOnBuild on IsPackable=true. Remove the global IsPackable=true from nuget-package.props so the repo-level default (false) applies to everything else. * Lower preview VersionPrefix to 0.0.1 Retroactive preview publish: bump VersionPrefix and GitTag from 1.2.0 to 0.0.1 so the 5 Foundry preview packages emit as 0.0.1-preview.260417.1.
Revises the Foundry pre-release approach to publish ALL normally packable src projects as preview packages stamped 0.0.1-preview.260417.2, including projects previously flagged IsReleased=true or with a non-default VersionSuffix (rc/alpha). nuget-package.props: - Collapse the four conditional PackageVersion expressions (IsReleaseCandidate, VersionSuffix, default preview, IsReleased stable) into a single unconditional 0.0.1-preview.260417.2. On this preview-only branch every package ships with the same pre-release stamp regardless of per-project flags. - Restore the global IsPackable=true default (offsetting the repo-wide IsPackable=false in Directory.Build.props). Projects that opt out (Mem0, Declarative) already set IsPackable=false AFTER importing this file so they remain non-packable. - Remove the IsReleased-gated EnablePackageValidation line. Package validation does not apply to a 0.0.1 preview. csproj reverts (Abstractions, Agents.AI, Workflows, Workflows.Generators, Foundry): - Revert the IsPackable=true opt-in block introduced in #5336 (now redundant since the props default is true again). - Restore IsReleased=true to its pre-PR value. The setting is now a no-op because the props no longer branches on it.
) - Bump PackageVersion to 0.0.1-preview.260420.1 - Bump Azure.AI.AgentServer.Core beta.21 -> beta.22 (required by Azure.AI.AgentServer.Responses beta.3) - Replace AgentHostTelemetry.ResponsesSourceName with local constant (type made internal in AgentServer.Core beta.22) Co-authored-by: alliscode <bentho@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds initial .NET support for hosting Agent Framework agents as “Foundry Hosted Agents” via the Azure AI Responses Server SDK, plus a new set of hosting samples and related packaging/build updates.
Changes:
- Introduces Foundry hosting wiring (DI + endpoint mapping) and session storage abstractions for hosted agents.
- Adds unit tests for DI registration and User-Agent middleware behavior in the hosting pipeline.
- Reworks samples: removes older
05-end-to-end/HostedAgentssamples and adds new04-hosting/FoundryHostedAgents(Responses + Invocations) samples; updates solution and packaging/versioning files.
Show a summary per file
| File | Description |
|---|---|
| dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Microsoft.Agents.AI.Foundry.UnitTests.csproj | Adds hosting-test dependencies and excludes hosting tests on non-.NETCore TFMs. |
| dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/UserAgentMiddlewareTests.cs | Adds tests validating User-Agent middleware behavior. |
| dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/ServiceCollectionExtensionsTests.cs | Adds tests for DI registration and OpenTelemetry wrapping helper. |
| dotnet/src/Microsoft.Agents.AI.Foundry/Microsoft.Agents.AI.Foundry.csproj | Adds hosting-only dependencies for .NETCoreApp and suppresses additional warnings. |
| dotnet/src/Microsoft.Agents.AI.Foundry/AzureAIProjectChatClientExtensions.cs | Makes ChatClientAgentOptions optional for AsAIAgent(...). |
| dotnet/src/Microsoft.Agents.AI.Foundry/Hosting/ServiceCollectionExtensions.cs | Adds Foundry hosting extensions (DI registration, route mapping, User-Agent middleware, OTel helper). |
| dotnet/src/Microsoft.Agents.AI.Foundry/Hosting/AgentSessionStore.cs | Introduces abstract session store contract for hosted sessions. |
| dotnet/src/Microsoft.Agents.AI.Foundry/Hosting/InMemoryAgentSessionStore.cs | Adds in-memory session store implementation for dev/test. |
| dotnet/src/Microsoft.Agents.AI.Foundry/Hosting/AgentFrameworkResponseHandler.cs | Implements Responses ResponseHandler bridging requests to AIAgent + session management. |
| dotnet/samples/05-end-to-end/HostedAgents/README.md | Removes older HostedAgents sample index README. |
| dotnet/samples/05-end-to-end/HostedAgents/FoundrySingleAgent/run-requests.http | Removes older request examples. |
| dotnet/samples/05-end-to-end/HostedAgents/FoundrySingleAgent/agent.yaml | Removes older agent manifest. |
| dotnet/samples/05-end-to-end/HostedAgents/FoundrySingleAgent/README.md | Removes older sample documentation. |
| dotnet/samples/05-end-to-end/HostedAgents/FoundrySingleAgent/Program.cs | Removes older sample implementation. |
| dotnet/samples/05-end-to-end/HostedAgents/FoundrySingleAgent/FoundrySingleAgent.csproj | Removes older sample project. |
| dotnet/samples/05-end-to-end/HostedAgents/FoundrySingleAgent/Dockerfile | Removes older sample container build file. |
| dotnet/samples/05-end-to-end/HostedAgents/FoundryMultiAgent/run-requests.http | Removes older request examples. |
| dotnet/samples/05-end-to-end/HostedAgents/FoundryMultiAgent/appsettings.Development.json | Removes older local dev config. |
| dotnet/samples/05-end-to-end/HostedAgents/FoundryMultiAgent/agent.yaml | Removes older agent manifest. |
| dotnet/samples/05-end-to-end/HostedAgents/FoundryMultiAgent/README.md | Removes older sample documentation. |
| dotnet/samples/05-end-to-end/HostedAgents/FoundryMultiAgent/Program.cs | Removes older sample implementation. |
| dotnet/samples/05-end-to-end/HostedAgents/FoundryMultiAgent/FoundryMultiAgent.csproj | Removes older sample project. |
| dotnet/samples/05-end-to-end/HostedAgents/FoundryMultiAgent/Dockerfile | Removes older sample container build file. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/run-requests.http | Removes older request examples. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/agent.yaml | Removes older agent manifest. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/README.md | Removes older sample documentation. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Program.cs | Removes older sample implementation. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/Dockerfile | Removes older sample container build file. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentsInWorkflows/AgentsInWorkflows.csproj | Removes older sample project. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/run-requests.http | Removes older request examples. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/agent.yaml | Removes older agent manifest. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/README.md | Removes older sample documentation. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Program.cs | Removes older sample implementation. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/Dockerfile | Removes older sample container build file. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithTextSearchRag/AgentWithTextSearchRag.csproj | Removes older sample project. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/run-requests.http | Removes older request examples. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/agent.yaml | Removes older agent manifest. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/README.md | Removes older sample documentation. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/Program.cs | Removes older sample implementation. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/Dockerfile | Removes older sample container build file. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/AgentWithLocalTools.csproj | Removes older sample project. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithLocalTools/.dockerignore | Removes older docker ignore rules. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/run-requests.http | Removes older request examples. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/agent.yaml | Removes older agent manifest. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/README.md | Removes older sample documentation. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Program.cs | Removes older sample implementation. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/Dockerfile | Removes older sample container build file. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj | Removes older sample project. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/run-requests.http | Removes older request examples. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/agent.yaml | Removes older agent manifest. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/README.md | Removes older sample documentation. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Program.cs | Removes older sample implementation. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/Dockerfile | Removes older sample container build file. |
| dotnet/samples/05-end-to-end/HostedAgents/AgentThreadAndHITL/AgentThreadAndHITL.csproj | Removes older sample project. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Using-Samples/SimpleAgent/SimpleAgent.csproj | Adds a simple client sample project for calling hosted Responses agents. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Using-Samples/SimpleAgent/Program.cs | Adds a simple REPL client for calling a hosted agent endpoint. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Simple/agent.yaml | Adds container agent YAML for workflow sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Simple/agent.manifest.yaml | Adds manifest metadata for workflow sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Simple/README.md | Documents workflow sample setup/run. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Simple/Program.cs | Implements hosted workflow agent using Responses protocol. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Simple/HostedWorkflowSimple.csproj | Adds workflow sample project file. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Simple/Dockerfile.contributor | Adds pre-published (ProjectReference-friendly) Dockerfile. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Simple/Dockerfile | Adds standard Dockerfile. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Simple/.env.example | Adds env template for workflow sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Handoff/agent.yaml | Adds container agent YAML for handoff workflow sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Handoff/agent.manifest.yaml | Adds manifest metadata for handoff workflow sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Handoff/README.md | Documents handoff workflow sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Handoff/HostedWorkflowHandoff.csproj | Adds handoff workflow sample project file. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Handoff/Dockerfile.contributor | Adds contributor Dockerfile for handoff sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Handoff/Dockerfile | Adds standard Dockerfile for handoff sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Handoff/.env.example | Adds env template for handoff sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/agent.yaml | Adds container agent YAML for RAG sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/agent.manifest.yaml | Adds manifest metadata for RAG sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/README.md | Documents RAG sample setup/run. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/Program.cs | Implements hosted RAG agent using Responses protocol. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/HostedTextRag.csproj | Adds RAG sample project file. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/Dockerfile.contributor | Adds contributor Dockerfile for RAG sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/Dockerfile | Adds standard Dockerfile for RAG sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/.env.example | Adds env template for RAG sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/agent.yaml | Adds container agent YAML for MCP tools sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/agent.manifest.yaml | Adds manifest metadata for MCP tools sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/README.md | Documents MCP tools sample setup/run. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/Program.cs | Implements MCP tools hosted agent. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/HostedMcpTools.csproj | Adds MCP tools sample project file. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/Dockerfile.contributor | Adds contributor Dockerfile for MCP tools sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/Dockerfile | Adds standard Dockerfile for MCP tools sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/.env.example | Adds env template for MCP tools sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/agent.yaml | Adds container agent YAML for local tools sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/agent.manifest.yaml | Adds manifest metadata for local tools sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/README.md | Documents local tools hosted sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/Program.cs | Implements local-tools hosted agent using Responses protocol. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/HostedLocalTools.csproj | Adds local tools sample project file. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/Dockerfile.contributor | Adds contributor Dockerfile for local tools sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/Dockerfile | Adds standard Dockerfile for local tools sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/.env.example | Adds env template for local tools sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/agent.yaml | Adds container agent YAML for Foundry-managed agent hosting sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/agent.manifest.yaml | Adds manifest metadata for Foundry-managed agent hosting sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/README.md | Documents Foundry-managed agent hosting sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/Program.cs | Implements Foundry-managed agent host using Responses protocol. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/HostedFoundryAgent.csproj | Adds Foundry-managed hosting sample project file. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/Dockerfile.contributor | Adds contributor Dockerfile for Foundry-managed sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/Dockerfile | Adds standard Dockerfile for Foundry-managed sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/.env.example | Adds env template for Foundry-managed sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/agent.yaml | Adds container agent YAML for inline ChatClientAgent hosting sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/agent.manifest.yaml | Adds manifest metadata for ChatClientAgent hosting sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/README.md | Documents ChatClientAgent hosted sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/Program.cs | Implements inline ChatClientAgent host using Responses protocol. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/HostedChatClientAgent.csproj | Adds ChatClientAgent sample project file. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/Dockerfile.contributor | Adds contributor Dockerfile for ChatClientAgent sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/Dockerfile | Adds standard Dockerfile for ChatClientAgent sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/.env.example | Adds env template for ChatClientAgent sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Using-Samples/SimpleInvocationsAgent/SimpleInvocationsAgent.csproj | Adds a simple client for Invocations protocol samples. |
| dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Using-Samples/SimpleInvocationsAgent/Program.cs | Adds REPL client that calls the Invocations endpoint. |
| dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Using-Samples/SimpleInvocationsAgent/InvocationsAIAgent.cs | Adds an AIAgent wrapper for plain-text Invocations endpoint calls. |
| dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/agent.yaml | Adds container agent YAML for Invocations echo agent. |
| dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/agent.manifest.yaml | Adds manifest metadata for Invocations echo agent. |
| dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/README.md | Documents Invocations echo agent sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Program.cs | Implements Invocations server wiring for echo agent. |
| dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Hosted-Invocations-EchoAgent.csproj | Adds Invocations echo agent project file. |
| dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/EchoInvocationHandler.cs | Adds handler that adapts HTTP Invocations requests to the echo agent. |
| dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/EchoAIAgent.cs | Adds minimal echo AIAgent implementation. |
| dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Dockerfile.contributor | Adds contributor Dockerfile for Invocations echo sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Dockerfile | Adds standard Dockerfile for Invocations echo sample. |
| dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/.env.example | Adds env template for Invocations echo sample. |
| dotnet/samples/04-hosting/.gitignore | Ignores launchSettings.json under hosting samples. |
| dotnet/nuget/nuget-package.props | Alters repo-wide NuGet versioning/pack settings. |
| dotnet/agent-framework-dotnet.slnx | Updates solution structure to include new hosting samples and remove old ones. |
| dotnet/Directory.Packages.props | Adds/updates centralized package versions for new hosting dependencies. |
| dotnet/.gitignore | Adds ignore rules for Foundry CLI artifacts and pre-published out/ folder. |
| .gitignore | Adds ignore rules for Foundry CLI artifacts at repo root. |
Copilot's findings
- Files reviewed: 139/140 changed files
- Comments generated: 7
| internal static AIAgent ApplyOpenTelemetry(AIAgent agent) | ||
| { | ||
| if (agent.GetService<OpenTelemetryAgent>() is not null) | ||
| { | ||
| return agent; | ||
| } | ||
|
|
||
| return agent.AsBuilder() | ||
| .UseOpenTelemetry(sourceName: ResponsesSourceName) | ||
| .Build(); | ||
| } |
There was a problem hiding this comment.
ApplyOpenTelemetry creates a new instrumented agent wrapper via AsBuilder().UseOpenTelemetry().Build() whenever the resolved agent isn’t already an OpenTelemetryAgent. Because the resolved agent comes from DI, this will typically wrap a singleton on every request, creating extra allocations and leaving OpenTelemetryAgent instances undisposed. Consider instrumenting once during registration (e.g., in AddFoundryResponses(...)) or caching the wrapped instance (e.g., keyed singleton) rather than wrapping per request.
| <NoWarn>$(NoWarn);OPENAI001;MEAI001;NU1903</NoWarn> | ||
| <CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled> |
There was a problem hiding this comment.
The project is suppressing NU1903 via NoWarn. NU1903 is a NuGet security/vulnerability warning; suppressing it at the project level can hide vulnerable dependency chains and makes it easy to ship known-vulnerable packages. Prefer addressing/upgrading the vulnerable package (or scoping suppression to a specific known-safe package/version with a clear justification).
| ENV ASPNETCORE_URLS=http://+:8088 | ||
| ENTRYPOINT ["dotnet", "HostedWorkflows.dll"] |
There was a problem hiding this comment.
The Dockerfile entrypoint references HostedWorkflows.dll, but the project’s AssemblyName is HostedWorkflowSimple (so the published output will be HostedWorkflowSimple.dll). This will cause the container to fail at startup. Update the entrypoint to match the actual published DLL name (or align AssemblyName/project name accordingly).
| Using the Azure Developer CLI: | ||
|
|
||
| ```bash | ||
| azd ai agent invoke --local "The quick brown fox jumps over the lazy dog" | ||
| ``` | ||
|
|
||
| Or with curl: | ||
|
|
||
| ```bash | ||
| curl -X POST http://localhost:8088/responses \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"input": "The quick brown fox jumps over the lazy dog", "model": "hosted-workflow-simple"}' | ||
| ``` |
There was a problem hiding this comment.
The README’s curl example uses "model": "hosted-workflow-simple", but the sample’s configured agent name defaults to hosted-workflows (see agent.yaml and Program.cs). With the current code, using the wrong model/agent name will route to a non-existent agent. Please align the README examples with the actual agent name (or update the agent name to match the docs).
| A hosted agent demonstrating **two layers of MCP (Model Context Protocol) tool integration**: | ||
|
|
||
| 1. **Client-side MCP (GitHub)** — The agent connects directly to the GitHub MCP server via `McpClient`, discovers tools, and handles tool invocations locally within the agent process. | ||
|
|
||
| 2. **Server-side MCP (Microsoft Learn)** — The agent declares a `HostedMcpServerTool` which delegates tool discovery and invocation to the LLM provider (Azure OpenAI Responses API). The provider calls the MCP server on behalf of the agent with no local connection needed. | ||
|
|
||
| ## How the two MCP patterns differ | ||
|
|
||
| | | Client-side MCP | Server-side MCP | | ||
| |---|---|---| | ||
| | **Connection** | Agent connects to MCP server directly | LLM provider connects to MCP server | | ||
| | **Tool invocation** | Handled by the agent process | Handled by the Responses API | | ||
| | **Auth** | Agent manages credentials (e.g., GitHub PAT) | Provider manages credentials | | ||
| | **Use case** | Custom/private MCP servers, fine-grained control | Public MCP servers, simpler setup | | ||
| | **Example** | GitHub (`McpClient` + `HttpClientTransport`) | Microsoft Learn (`HostedMcpServerTool`) | | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0) | ||
| - An Azure AI Foundry project with a deployed model (e.g., `gpt-4o`) | ||
| - Azure CLI logged in (`az login`) | ||
| - A **GitHub Personal Access Token** (create at https://github.com/settings/tokens) | ||
|
|
There was a problem hiding this comment.
This README says the client-side MCP integration is GitHub-based and requires a GITHUB_PAT, but the accompanying Program.cs connects client-side to the Microsoft Learn MCP endpoint and does not use GITHUB_PAT. Please update the README (and prerequisites/config section) to reflect the actual implementation, or update the code to match the documented GitHub scenario.
| <VersionPrefix>0.0.1</VersionPrefix> | ||
| <RCNumber>1</RCNumber> | ||
| <PackageVersion Condition="'$(IsReleaseCandidate)' == 'true'">$(VersionPrefix)-rc$(RCNumber)</PackageVersion> | ||
| <PackageVersion Condition="'$(IsReleaseCandidate)' != 'true' AND '$(VersionSuffix)' != ''">$(VersionPrefix)-$(VersionSuffix).260410.1</PackageVersion> | ||
| <PackageVersion Condition="'$(IsReleaseCandidate)' != 'true' AND '$(VersionSuffix)' == ''">$(VersionPrefix)-preview.260410.1</PackageVersion> | ||
| <PackageVersion Condition="'$(IsReleased)' == 'true'">$(VersionPrefix)</PackageVersion> | ||
| <GitTag>1.1.0</GitTag> | ||
| <!-- Preview-only branch: all publishable packages ship as 0.0.1-preview.260417.2 regardless of IsReleaseCandidate/VersionSuffix. --> | ||
| <PackageVersion>$(VersionPrefix)-preview.260420.1</PackageVersion> | ||
| <GitTag>0.0.1</GitTag> |
There was a problem hiding this comment.
nuget-package.props now hard-codes VersionPrefix to 0.0.1 and sets a single unconditional PackageVersion for all builds, removing the prior conditional logic for RC/preview/VersionSuffix. This is a repo-wide packaging change (affects every packable project) and isn’t reflected in the PR description. If this is meant only for a specific preview branch or internal build, consider gating it behind an MSBuild condition (or keeping the existing conditional versioning) and documenting the intent explicitly.
| // 2. Load or create a new session from the interaction | ||
| var sessionConversationId = request.GetConversationId() ?? Guid.NewGuid().ToString(); | ||
|
|
||
| var chatClientAgent = agent.GetService<ChatClientAgent>(); | ||
|
|
||
| AgentSession? session = !string.IsNullOrEmpty(sessionConversationId) | ||
| ? await sessionStore.GetSessionAsync(agent, sessionConversationId, cancellationToken).ConfigureAwait(false) | ||
| : chatClientAgent is not null | ||
| ? await chatClientAgent.CreateSessionAsync(sessionConversationId, cancellationToken).ConfigureAwait(false) | ||
| : await agent.CreateSessionAsync(cancellationToken).ConfigureAwait(false); |
There was a problem hiding this comment.
sessionConversationId is always non-null because it falls back to a new GUID. That makes the subsequent conditional always take the sessionStore path and also causes sessions to be persisted even when the client didn’t provide a conversation id (the generated id is never returned to the caller), which can lead to unbounded growth in the session store and prevents clients from resuming the session. Consider only using/persisting sessions when a conversation id is present on the request (or ensure the generated id is emitted back in the response payload).
* feat: Add Foundry Toolbox (MCP) support to AgentFrameworkResponseHandler Adds support for Foundry Toolsets MCP proxy integration in the hosted agent response handler. Toolsets connect at startup via IHostedService, gating the readiness probe per spec §3.1. MCP tools are injected into every request's ChatOptions and OAuth consent errors (-32006) are intercepted and surfaced as mcp_approval_request + incomplete SSE events. New files: - FoundryToolboxOptions.cs: configuration POCO for toolset names and API version - FoundryToolboxBearerTokenHandler.cs: DelegatingHandler with Azure Bearer token auth, Foundry-Features header injection, and 3x exponential backoff on 429/5xx - McpConsentContext.cs: AsyncLocal-based per-request consent state shared between the tool wrapper and the response handler - ConsentAwareMcpClientTool.cs: AIFunction wrapper that catches -32006 errors and signals consent via shared state and linked CancellationTokenSource - FoundryToolboxService.cs: IHostedService that creates McpClient per toolset at startup and exposes cached tools Modified files: - AgentFrameworkResponseHandler.cs: injects toolbox tools into ChatOptions, sets up linked CTS consent interception, emits mcp_approval_request on -32006 - ServiceCollectionExtensions.cs: adds AddFoundryToolboxes(params string[]) extension - Microsoft.Agents.AI.Foundry.csproj: adds ModelContextProtocol and Azure.Identity dependencies under NETCoreApp condition Sample: - Hosted-Toolbox: minimal hosted agent sample using AddFoundryToolboxes * Rename toolset to toolbox in user-facing API; rename ConsentAwareMcpClientTool to ConsentAwareMcpClientAIFunction * Add HostedMcpToolboxAITool for client-selectable Foundry toolboxes Introduces HostedMcpToolboxAITool, a marker tool subclassing HostedMcpServerTool that rides the OpenAI Responses 'mcp' wire format to let clients request a specific Foundry toolbox per request. - New FoundryAITool.CreateHostedMcpToolbox(name, version?) factory. - FoundryToolboxOptions.StrictMode (default true) rejects unregistered toolboxes; set to false to allow lazy-open on first use. - FoundryToolboxService.GetToolboxToolsAsync(name, version?) resolves cached or lazy-opened MCP tools. - AgentFrameworkResponseHandler parses request.Tools for foundry-toolbox://name[?version=v] markers and injects resolved tools per request, merging with pre-registered ones. - Unit tests for marker parsing and strict-mode resolution. * Bump Azure.AI.Projects to 2.1.0-alpha; add ToolboxRecord/ToolboxVersion factory overloads + tests * Fix PR review issues: retry off-by-one, URI encoding, docs, tests, build - Fix off-by-one in FoundryToolboxBearerTokenHandler retry loop (4 attempts → 3) - URI-encode version parameter in HostedMcpToolboxAITool.BuildAddress - Add XML doc clarifying version pinning is reserved for future use - Add comment clarifying AddHostedService deduplication safety - Fix DevTemporaryTokenCredential expiry to use DateTimeOffset.MaxValue - Fix AgentCard ambiguity in A2AServer sample with using alias - Add 18 new unit tests for retry handler and ReadMcpToolboxMarkers Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com> Co-authored-by: alliscode <bentho@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Motivation and Context
Description
Contribution Checklist