.NET: [BREAKING] Bump Azure.AI.AgentServer to 2.0.0 protocol and migrate Foundry.Hosting#6800
Conversation
….Hosting Bumps Core .25->.26, Invocations .4->.5, Responses .5->.6 and adopts the 2.0.0 container protocol. Breaking change: IsolationContext (UserIsolationKey + ChatIsolationKey) is replaced by PlatformContext (UserIdKey from x-agent-user-id, CallId from x-agent-foundry-call-id). The per-chat key is gone; HostedSessionContext is now user-only and the per-request CallId is forwarded outbound to Foundry first-party services (toolbox/MCP). Also fixes a real call-id egress bug: AsyncLocal writes inside the streaming response iterator are reverted across yield boundaries, so the call id was dropped before the toolbox/MCP egress ran. The handler now re-applies HostedCallContext.CallId before each egress point. Adds HostedConversationKey to map a request to a stable MAF AgentSession via conversation_id, else the partition key embedded in previous_response_id, else the minted response id. This keeps store=false previous_response_id chains and conversation_id forks on a single hosted MAF session without using the container session id. Sample manifests bump the responses protocol to 2.0.0 (invocations stays 1.0.0). Integration tests split store/session semantics into HostedResponsesStoreConfigTests with its own scenario, read stored responses through the per-agent endpoint client, and inject the model deployment into the container.
There was a problem hiding this comment.
Pull request overview
This PR migrates Microsoft.Agents.AI.Foundry.Hosting to the Azure.AI.AgentServer 2.0.0 container protocol, updating hosting/session identity to the new PlatformContext model and ensuring the platform per-request CallId is forwarded to Foundry first-party services (toolbox/MCP). It also updates tests, integration scenarios, and sample manifests to align with the new protocol and revised session/store semantics.
Changes:
- Bump
Azure.AI.AgentServer.*package versions and migrate identity mapping fromResponseContext.IsolationtoResponseContext.PlatformContext(user-only identity). - Add hosted conversation/session key derivation via
conversation_id/previous_response_idpartitioning and update unit/integration tests for store/session behavior. - Forward the platform per-request call id (
x-agent-foundry-call-id) on toolbox/MCP egress and add coverage to prevent regressions across streaming/yield boundaries.
Reviewed changes
Copilot reviewed 64 out of 64 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/HostedSessionIdentityContextTests.cs | Updates identity-context tests to user-only PlatformContext. |
| dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/HostedFoundryMemoryProviderServiceCollectionExtensionsTests.cs | Updates hosted-session tagging for memory provider tests (user-only). |
| dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/HostedFoundryMemoryProviderScopesTests.cs | Removes per-chat/per-(user,chat) scope tests; retains per-user scoping. |
| dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/HostedConversationKeyTests.cs | Adds tests for HostedConversationKey partition/key resolution. |
| dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/FoundryToolboxBearerTokenHandlerTests.cs | Adds call-id forwarding tests for toolbox egress. |
| dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/FakeHostedSessionIsolationKeyProvider.cs | Updates fake provider to user-only HostedSessionContext. |
| dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/AgentFrameworkResponseHandlerTests.cs | Adds tests for previous_response_id partition reuse + call-id AsyncLocal behavior. |
| dotnet/tests/Foundry.Hosting.IntegrationTests/scripts/it-bootstrap-agents.ps1 | Adds the new store-config integration scenario. |
| dotnet/tests/Foundry.Hosting.IntegrationTests/README.md | Documents the new store-config fixture/scenario split. |
| dotnet/tests/Foundry.Hosting.IntegrationTests/HostedResponsesStoreConfigTests.cs | New integration tests for store=true/false + fork/history semantics. |
| dotnet/tests/Foundry.Hosting.IntegrationTests/HappyPathHostedAgentTests.cs | Narrows happy-path tests to basic streaming + container instruction behavior. |
| dotnet/tests/Foundry.Hosting.IntegrationTests/Fixtures/HostedResponsesStoreConfigFixture.cs | New fixture provisioning the store-config agent scenario. |
| dotnet/tests/Foundry.Hosting.IntegrationTests/Fixtures/HostedAgentFixture.cs | Switches responses protocol to 2.0.0 and adds per-agent OpenAI client + model deployment injection. |
| dotnet/tests/Foundry.Hosting.IntegrationTests.TestContainer/Program.cs | Adds store-config agent scenario; updates happy-path instruction behavior. |
| dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/PlatformHostedSessionIsolationKeyProvider.cs | Maps hosted session identity from PlatformContext.UserIdKey. |
| dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/HostedSessionIsolationKeyProvider.cs | Updates contract/docs to user-only identity. |
| dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/HostedSessionContext.cs | Removes ChatId; documents protocol 2.0.0 user-only partitioning. |
| dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/HostedFoundryMemoryProviderScopes.cs | Removes per-chat/per-(user,chat) scope helpers; keeps per-user. |
| dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/HostedConversationKey.cs | New helper to derive stable hosted session key from conversation/response partitions. |
| dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/HostedCallContext.cs | New AsyncLocal ambient holder for platform per-request call id. |
| dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FoundryToolboxBearerTokenHandler.cs | Forwards x-agent-foundry-call-id on outbound toolbox requests. |
| dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/AgentFrameworkResponseHandler.cs | Uses HostedConversationKey for session lookup and re-applies call id before egress points. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Simple/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Simple/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Handoff/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflow-Handoff/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ToolboxMcpSkills/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ToolboxMcpSkills/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Toolbox/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Toolbox/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Toolbox-AuthPaths/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Toolbox-AuthPaths/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Observability/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Observability/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-MemoryAgent/scripts/smoke.ps1 | Removes chat env var injection (but still needs script API cleanup). |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-MemoryAgent/README.md | Updates identity docs to x-agent-user-id (still has some stale header mentions). |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-MemoryAgent/Program.cs | Updates sample comments to PlatformContext.UserIdKey. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-MemoryAgent/Dockerfile.contributor | Removes chat env var mention from contributor Dockerfile docs. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-MemoryAgent/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-MemoryAgent/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-MemoryAgent/.env.example | Removes chat env var; local-dev env template needs comment wording tweak. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalCodeAct/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalCodeAct/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Files/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Files/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-AzureSearchRag/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-AzureSearchRag/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-AgentSkills/scripts/smoke.ps1 | Removes chat env var injection for local smoke. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-AgentSkills/Dockerfile.contributor | Removes chat env var mention from contributor Dockerfile docs. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-AgentSkills/agent.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-AgentSkills/agent.manifest.yaml | Bumps responses protocol version to 2.0.0. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-AgentSkills/.env.example | Removes chat env var; local-dev env template needs comment wording tweak. |
| dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted_Shared_Contributor_Setup/DevTemporaryLocalSessionIsolationKeyProvider.cs | Updates dev fallback provider to user-id only (PlatformContext). |
| dotnet/Directory.Packages.props | Bumps Azure.AI.AgentServer package versions to beta.26/.5/.6. |
AgentServer 1.0.0-beta.26 (pulled transitively via Foundry.Hosting) requires Azure.Core 1.59.0. This sample disables transitive pinning and references Azure.Core directly, so override just this project to the SDK-required version without moving the solution-wide central pin.
There was a problem hiding this comment.
Automated Code Review
Reviewers: 5 | Confidence: 79%
✓ Correctness
No actionable issues found in this dimension.
✓ Security Reliability
No actionable issues found in this dimension.
✓ Test Coverage
Test coverage for the new features is generally strong. The HostedConversationKey, HostedCallContext, and the call-id propagation through FoundryToolboxBearerTokenHandler are all unit-tested. However, the deduplication guard in the bearer token handler (skip adding x-agent-foundry-call-id when already present) lacks a dedicated test, and there is no handler-level unit test verifying that a conversation_id request routes to the correct MAF session (only the previous_response_id chain path is tested).
✓ Failure Modes
No actionable issues found in this dimension.
✗ Design Approach
I found one request-scoping issue in the new call-id flow: the added tests prove that
HostedCallContext.CallIdis visible during agent execution, but the production handler still never clears that AsyncLocal after the response stream finishes, which violates the documented request-lifetime contract and can leak a stalex-agent-foundry-call-idinto later first-party egress on the same async flow.
Automated review by rogerbarreto's agents
Asserts HostedCallContext.CallId does not leak into the caller's execution context after CreateAsync's stream completes, while confirming the agent run still observed the call id. Documents the request-scoped contract and guards against stale-header leakage across requests handled on the same thread.
Updates stale docs to match the shipped code: the MemoryAgent README now describes the x-agent-user-id user-identity header (chat isolation key removed) feeding HostedSessionContext.UserId; the IntegrationTests README corrects the scenario count (six to eleven), adds the missing memory scenario row, and stops claiming all scenarios are skipped now that several are validated and active.
Documents the migration from ResponseContext.Isolation (UserIsolationKey/ChatIsolationKey) to ResponseContext.PlatformContext (UserIdKey/CallId): user-only HostedSessionContext, the request-scoped HostedCallContext call-id forwarded on egress, HostedConversationKey session keying, and removal of the PerChat/PerUserAndChat memory scopes. Marks ADR 0026 as superseded.
Augments the package Description and adds PackageReleaseNotes stating this release targets the Foundry Responses container protocol v2.0 only, is not compatible with v1, and directs consumers to a previous release for the v1 protocol definition.
| @@ -44,7 +43,6 @@ For local container runs only (the platform supplies these in production): | |||
|
|
|||
| ```env | |||
| HOSTED_USER_ISOLATION_KEY=alice | |||
There was a problem hiding this comment.
How about this one env var?
|
|
||
| /// <summary> | ||
| /// Derives the stable per-conversation key used to map a hosted request to a persisted MAF | ||
| /// <see cref="AgentSession"/>. The key mirrors how the AgentServer Responses SDK colocates |
There was a problem hiding this comment.
I am curious why .Net has to maintain the agent sessions. History is managed by Foundry and we can pass the entire history to the agent for each invocation.
Motivation & Context
The
Azure.AI.AgentServer.*packages shipped a new 2.0.0 container protocol with a breaking change to the isolation model.Microsoft.Agents.AI.Foundry.Hostingmust adopt it to keep hosting Foundry agents working on the new protocol.Fixes #6799
Description & Review Guide
What are the major changes?
Azure.AI.AgentServer.Core.25 to .26,Invocations.4 to .5,Responses.5 to .6.ResponseContext.Isolation/IsolationContexttoResponseContext.PlatformContext.HostedSessionContextbecomes user-only (UserIdKeyfromx-agent-user-id); the per-chat key is gone.CallId(x-agent-foundry-call-id, protocol 2.0.0) outbound to Foundry first-party services (toolbox/MCP).yieldboundaries. The handler now re-appliesHostedCallContext.CallIdbefore each egress point. Covered by a unit test.HostedConversationKey: maps a request to a stable MAFAgentSessionviaconversation_id, else the partition key embedded inprevious_response_id, else the minted response id. This keepsstore=falseprevious_response_idchains andconversation_idforks on one hosted MAF session, without using the container session id (which spans many conversations).agent.yaml/agent.manifest.yamlbump theresponsesprotocol to2.0.0(invocations stays1.0.0).HostedResponsesStoreConfigTests(newstore-configscenario), read stored responses through the per-agent endpoint client (the project-level client returns 403session_not_accessible), and inject the model deployment into the container.What is the impact of these changes?
HostedSessionIsolationKeyProvideror readingHostedSessionContext.ChatId.store=falsecontinuations chained viaprevious_response_id(orconversation_id) now transparently reuse an existing fork: they read its history without appending.Validation
--warnaserroron all changed projects.dotnet format --verify-no-changesclean (WSL2 + Docker, pinned SDK 10.0.301).HostedResponsesStoreConfigTests7/7,HappyPathHostedAgentTests3/3.Related Issue
Fixes #6799
Contribution Checklist
[BREAKING]prefix.