From a61e0f24d6db7bb5265610dc6eaf1e4533e590bf Mon Sep 17 00:00:00 2001 From: Jacob Alber Date: Wed, 13 May 2026 11:30:42 -0400 Subject: [PATCH] Harden default for A2A hosting by using an IsolationKeyScopedAgentSessionStore when no store is available. --- .../A2AServerServiceCollectionExtensions.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.A2A/A2AServerServiceCollectionExtensions.cs b/dotnet/src/Microsoft.Agents.AI.Hosting.A2A/A2AServerServiceCollectionExtensions.cs index 29ab28c250..8b7ff6d28b 100644 --- a/dotnet/src/Microsoft.Agents.AI.Hosting.A2A/A2AServerServiceCollectionExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.Hosting.A2A/A2AServerServiceCollectionExtensions.cs @@ -140,9 +140,17 @@ public static class A2AServerServiceCollectionExtensions var agentSessionStore = serviceProvider.GetKeyedService(agent.Name); var runMode = options?.AgentRunMode ?? AgentRunMode.DisallowBackground; + // Ensure that we have an IsolationKeyScopedAgentSessionStore registered. + var isolationKeyProvider = serviceProvider.GetService(); + if (agentSessionStore?.GetService() is null) + { + agentSessionStore ??= new InMemoryAgentSessionStore(); + agentSessionStore = new IsolationKeyScopedAgentSessionStore(agentSessionStore, isolationKeyProvider, new()); + } + var hostAgent = new AIHostAgent( innerAgent: agent, - sessionStore: agentSessionStore ?? new InMemoryAgentSessionStore()); + sessionStore: agentSessionStore); agentHandler = new A2AAgentHandler(hostAgent, runMode); }