Skip to content

.NET: [BREAKING] Bump Azure.AI.AgentServer to 2.0.0 protocol and migrate Foundry.Hosting#6800

Merged
alliscode merged 7 commits into
microsoft:mainfrom
rogerbarreto:dotnet/foundry-hosting-agentserver-2.0-protocol
Jun 29, 2026
Merged

.NET: [BREAKING] Bump Azure.AI.AgentServer to 2.0.0 protocol and migrate Foundry.Hosting#6800
alliscode merged 7 commits into
microsoft:mainfrom
rogerbarreto:dotnet/foundry-hosting-agentserver-2.0-protocol

Conversation

@rogerbarreto

Copy link
Copy Markdown
Member

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.Hosting must adopt it to keep hosting Foundry agents working on the new protocol.

Fixes #6799

Description & Review Guide

  • What are the major changes?

    • Bump Azure.AI.AgentServer.Core .25 to .26, Invocations .4 to .5, Responses .5 to .6.
    • Migrate off the removed ResponseContext.Isolation / IsolationContext to ResponseContext.PlatformContext. HostedSessionContext becomes user-only (UserIdKey from x-agent-user-id); the per-chat key is gone.
    • Forward the per-request CallId (x-agent-foundry-call-id, protocol 2.0.0) outbound to Foundry first-party services (toolbox/MCP).
    • Bug fix: the call id was being dropped before the toolbox/MCP egress because AsyncLocal writes inside the streaming response iterator are reverted across yield boundaries. The handler now re-applies HostedCallContext.CallId before each egress point. Covered by a unit test.
    • New HostedConversationKey: maps 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 one hosted MAF session, without using the container session id (which spans many conversations).
    • Sample agent.yaml / agent.manifest.yaml bump the responses protocol to 2.0.0 (invocations stays 1.0.0).
    • Integration tests: split store/session semantics into HostedResponsesStoreConfigTests (new store-config scenario), read stored responses through the per-agent endpoint client (the project-level client returns 403 session_not_accessible), and inject the model deployment into the container.
  • What is the impact of these changes?

    • Breaking for anyone implementing a custom HostedSessionIsolationKeyProvider or reading HostedSessionContext.ChatId.
    • store=false continuations chained via previous_response_id (or conversation_id) now transparently reuse an existing fork: they read its history without appending.

Validation

  • Build clean with --warnaserror on all changed projects.
  • 281 hosting unit tests pass.
  • CI-parity dotnet format --verify-no-changes clean (WSL2 + Docker, pinned SDK 10.0.301).
  • Integration tests validated live against a 2.0.0-enabled Foundry project (canadacentral): HostedResponsesStoreConfigTests 7/7, HappyPathHostedAgentTests 3/3.

Related Issue

Fixes #6799

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue.
  • This is not a breaking change. It IS a breaking change; the title carries the [BREAKING] prefix.

….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.
Copilot AI review requested due to automatic review settings June 29, 2026 14:58
@moonbox3 moonbox3 added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net breaking change Usage: [PRs], Target: all PRs that introduce changes that are not backward compatible labels Jun 29, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 5 | Confidence: 88% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Failure Modes, Design Approach


Automated review by rogerbarreto's agents

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 from ResponseContext.Isolation to ResponseContext.PlatformContext (user-only identity).
  • Add hosted conversation/session key derivation via conversation_id / previous_response_id partitioning 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.

@rogerbarreto rogerbarreto self-assigned this Jun 29, 2026
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.
@rogerbarreto rogerbarreto marked this pull request as ready for review June 29, 2026 21:15

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.CallId is 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 stale x-agent-foundry-call-id into 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.
@rogerbarreto rogerbarreto changed the title [BREAKING] .NET: Bump Azure.AI.AgentServer to 2.0.0 protocol and migrate Foundry.Hosting .NET: [BREAKING] Bump Azure.AI.AgentServer to 2.0.0 protocol and migrate Foundry.Hosting Jun 29, 2026
@@ -44,7 +43,6 @@ For local container runs only (the platform supplies these in production):

```env
HOSTED_USER_ISOLATION_KEY=alice

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@alliscode alliscode merged commit 0d53d11 into microsoft:main Jun 29, 2026
28 of 30 checks passed
This was referenced Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Usage: [PRs], Target: all PRs that introduce changes that are not backward compatible documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BREAKING] .NET: Bump Azure.AI.AgentServer to 2.0.0 protocol in Foundry.Hosting

5 participants