using System.Collections.Concurrent; namespace Agent.Core.Sessions; public sealed class SessionStore { private readonly ConcurrentDictionary _sessions = new(); /// /// Enumerates all active sessions. Primarily for TaskGraphToolHandler to resolve graphs by TaskId. /// public IEnumerable Sessions => _sessions.Values; public AgentSession Create() { while (true) { var session = new AgentSession(Guid.NewGuid()); if (_sessions.TryAdd(session.SessionId, session)) return session; } } public bool TryGet(Guid sessionId, out AgentSession? session) => _sessions.TryGetValue(sessionId, out session); }