Language

InMemoryAgentSessionStore Class

Definition

Provides an in-memory implementation of AgentSessionStore for development and testing scenarios.

public sealed class InMemoryAgentSessionStore : Microsoft.Agents.AI.Hosting.AgentSessionStore
type InMemoryAgentSessionStore = class
    inherit AgentSessionStore
Public NotInheritable Class InMemoryAgentSessionStore
Inherits AgentSessionStore
Inheritance
InMemoryAgentSessionStore

Remarks

This implementation stores threads in memory using a concurrent dictionary and is suitable for:

  • Single-instance development scenarios
  • Testing and prototyping
  • Scenarios where session persistence across restarts is not required

Warning: All stored threads will be lost when the application restarts. For production use with multiple instances or persistence across restarts, use a durable storage implementation such as Redis, SQL Server, or Azure Cosmos DB.

Multi-user warning. This store keys threads by (agent.Id, conversationId) only — it has no principal/owner dimension. When the conversation identifier originates from the wire (for example, an AG-UI RunAgentInput.ThreadId or an A2A contextId), any caller who knows or guesses another caller's identifier can resume that other caller's persisted thread. Multi-user hosts must wrap this store in IsolationKeyScopedAgentSessionStore (typically by calling UseClaimsBasedSessionIsolation(...) from Microsoft.Agents.AI.Hosting.AspNetCore or by registering a custom SessionIsolationKeyProvider) so that the conversation namespace is scoped per principal. See the trust-model remarks on AgentSessionStore for the full background.

Constructors

Name Description
InMemoryAgentSessionStore()

Methods

Name Description
GetService(Type, Object)

Asks the AgentSessionStore for an object of the specified type serviceType.

(Inherited from AgentSessionStore)
GetService<TService>(Object)

Asks the AgentSessionStore for an object of type TService.

(Inherited from AgentSessionStore)
GetSessionAsync(AIAgent, String, CancellationToken)

Retrieves a serialized agent session from persistent storage.

SaveSessionAsync(AIAgent, String, AgentSession, CancellationToken)

Saves a serialized agent session to persistent storage.

Applies to