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); }