From 22a2fb15efc8aae3fd524bc777fac52dc88e174f Mon Sep 17 00:00:00 2001 From: alliscode Date: Tue, 21 Apr 2026 12:16:04 -0700 Subject: [PATCH] Address PR review comments: experimental attrs, doc fixes, token propagation - Add [Experimental(OPENAI001)] to all 7 public Hosting types per reviewer request - Fix McpConsentContext XML doc: 'Thread-static' -> 'Async-local' (AsyncLocal flows with ExecutionContext, not thread-static) - Expand UserAgentMiddleware test regex to match prerelease versions (e.g. 1.0.0-rc.4) - Propagate CancellationToken in AgentFrameworkResponseHandler session save Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../AgentFrameworkResponseHandler.cs | 5 ++++- .../Microsoft.Agents.AI.Foundry.Hosting/AgentSessionStore.cs | 3 +++ .../FoundryAIToolExtensions.cs | 3 +++ .../FoundryToolboxOptions.cs | 3 +++ .../FoundryToolboxService.cs | 3 +++ .../InMemoryAgentSessionStore.cs | 3 +++ .../Microsoft.Agents.AI.Foundry.Hosting/McpConsentContext.cs | 4 ++-- .../ServiceCollectionExtensions.cs | 3 +++ .../Hosting/UserAgentMiddlewareTests.cs | 2 +- 9 files changed, 25 insertions(+), 4 deletions(-) diff --git a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/AgentFrameworkResponseHandler.cs b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/AgentFrameworkResponseHandler.cs index d55dd02812..1c5a57eb49 100644 --- a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/AgentFrameworkResponseHandler.cs +++ b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/AgentFrameworkResponseHandler.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Threading; using Azure.AI.AgentServer.Responses; @@ -9,6 +10,7 @@ using Azure.AI.AgentServer.Responses.Models; using Microsoft.Extensions.AI; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Microsoft.Shared.DiagnosticIds; namespace Microsoft.Agents.AI.Foundry.Hosting; @@ -17,6 +19,7 @@ namespace Microsoft.Agents.AI.Foundry.Hosting; /// with agent-framework instances, enabling agent-framework agents and workflows /// to be hosted as Azure Foundry Hosted Agents. /// +[Experimental(DiagnosticIds.Experiments.AIOpenAIResponses)] public class AgentFrameworkResponseHandler : ResponseHandler { private readonly IServiceProvider _serviceProvider; @@ -275,7 +278,7 @@ public class AgentFrameworkResponseHandler : ResponseHandler // Persist session after streaming completes (successful or not) if (session is not null && !string.IsNullOrWhiteSpace(sessionConversationId)) { - await sessionStore.SaveSessionAsync(agent, sessionConversationId, session, CancellationToken.None).ConfigureAwait(false); + await sessionStore.SaveSessionAsync(agent, sessionConversationId, session, cancellationToken).ConfigureAwait(false); } } } diff --git a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/AgentSessionStore.cs b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/AgentSessionStore.cs index c61584e9e0..fe63dcfca7 100644 --- a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/AgentSessionStore.cs +++ b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/AgentSessionStore.cs @@ -1,7 +1,9 @@ // Copyright (c) Microsoft. All rights reserved. +using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; +using Microsoft.Shared.DiagnosticIds; namespace Microsoft.Agents.AI.Foundry.Hosting; @@ -13,6 +15,7 @@ namespace Microsoft.Agents.AI.Foundry.Hosting; /// allowing conversations to be resumed across HTTP requests, application restarts, /// or different service instances in hosted scenarios. /// +[Experimental(DiagnosticIds.Experiments.AIOpenAIResponses)] public abstract class AgentSessionStore { /// diff --git a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FoundryAIToolExtensions.cs b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FoundryAIToolExtensions.cs index a3dc42968e..1e69d09189 100644 --- a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FoundryAIToolExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FoundryAIToolExtensions.cs @@ -1,8 +1,10 @@ // Copyright (c) Microsoft. All rights reserved. using System; +using System.Diagnostics.CodeAnalysis; using Azure.AI.Projects.Agents; using Microsoft.Extensions.AI; +using Microsoft.Shared.DiagnosticIds; namespace Microsoft.Agents.AI.Foundry.Hosting; @@ -10,6 +12,7 @@ namespace Microsoft.Agents.AI.Foundry.Hosting; /// Extension methods for that require Azure.AI.Projects 2.1.0-beta.1+ /// types (e.g. , ). /// +[Experimental(DiagnosticIds.Experiments.AIOpenAIResponses)] public static class FoundryAIToolExtensions { /// diff --git a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FoundryToolboxOptions.cs b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FoundryToolboxOptions.cs index 79ea9cc7b7..78430f40bf 100644 --- a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FoundryToolboxOptions.cs +++ b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FoundryToolboxOptions.cs @@ -1,12 +1,15 @@ // Copyright (c) Microsoft. All rights reserved. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using Microsoft.Shared.DiagnosticIds; namespace Microsoft.Agents.AI.Foundry.Hosting; /// /// Options for Foundry Toolbox MCP integration. /// +[Experimental(DiagnosticIds.Experiments.AIOpenAIResponses)] public sealed class FoundryToolboxOptions { /// diff --git a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FoundryToolboxService.cs b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FoundryToolboxService.cs index aace2f723e..7a8bc71e02 100644 --- a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FoundryToolboxService.cs +++ b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FoundryToolboxService.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Net.Http; using System.Threading; using System.Threading.Tasks; @@ -11,6 +12,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; +using Microsoft.Shared.DiagnosticIds; using ModelContextProtocol.Client; namespace Microsoft.Agents.AI.Foundry.Hosting; @@ -33,6 +35,7 @@ namespace Microsoft.Agents.AI.Foundry.Hosting; /// lazily connected otherwise. /// /// +[Experimental(DiagnosticIds.Experiments.AIOpenAIResponses)] public sealed class FoundryToolboxService : IHostedService, IAsyncDisposable { private readonly FoundryToolboxOptions _options; diff --git a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/InMemoryAgentSessionStore.cs b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/InMemoryAgentSessionStore.cs index 4ae94ed4fe..78d4638635 100644 --- a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/InMemoryAgentSessionStore.cs +++ b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/InMemoryAgentSessionStore.cs @@ -1,9 +1,11 @@ // Copyright (c) Microsoft. All rights reserved. using System.Collections.Concurrent; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Threading; using System.Threading.Tasks; +using Microsoft.Shared.DiagnosticIds; namespace Microsoft.Agents.AI.Foundry.Hosting; @@ -25,6 +27,7 @@ namespace Microsoft.Agents.AI.Foundry.Hosting; /// such as Redis, SQL Server, or Azure Cosmos DB. /// /// +[Experimental(DiagnosticIds.Experiments.AIOpenAIResponses)] public sealed class InMemoryAgentSessionStore : AgentSessionStore { private readonly ConcurrentDictionary _sessions = new(); diff --git a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/McpConsentContext.cs b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/McpConsentContext.cs index aba28a5314..96ea08383b 100644 --- a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/McpConsentContext.cs +++ b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/McpConsentContext.cs @@ -31,9 +31,9 @@ internal sealed class RequestConsentState } /// -/// Thread-static (AsyncLocal) context that enables +/// Async-local context that enables /// to signal a consent error back to through the -/// tool loop. +/// tool loop. Flows with the async ExecutionContext. /// internal static class McpConsentContext { diff --git a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/ServiceCollectionExtensions.cs b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/ServiceCollectionExtensions.cs index 4192599bd0..dda822ef66 100644 --- a/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/ServiceCollectionExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/ServiceCollectionExtensions.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. using System; +using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Threading.Tasks; using Azure.AI.AgentServer.Responses; @@ -11,6 +12,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Shared.DiagnosticIds; namespace Microsoft.Agents.AI.Foundry.Hosting; @@ -18,6 +20,7 @@ namespace Microsoft.Agents.AI.Foundry.Hosting; /// Extension methods for registering agent-framework agents as Foundry Hosted Agents /// using the Azure AI Responses Server SDK. /// +[Experimental(DiagnosticIds.Experiments.AIOpenAIResponses)] public static class FoundryHostingExtensions { /// diff --git a/dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/UserAgentMiddlewareTests.cs b/dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/UserAgentMiddlewareTests.cs index 64f7458852..008e3f3347 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/UserAgentMiddlewareTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/UserAgentMiddlewareTests.cs @@ -20,7 +20,7 @@ namespace Microsoft.Agents.AI.Foundry.UnitTests.Hosting; /// public sealed partial class UserAgentMiddlewareTests : IAsyncDisposable { - private const string VersionedUserAgentPattern = @"agent-framework-dotnet/\d+\.\d+\.\d+"; + private const string VersionedUserAgentPattern = @"agent-framework-dotnet/\d+\.\d+\.\d+(-[\w.]+)?"; private WebApplication? _app; private HttpClient? _httpClient;