Class SessionManager

java.lang.Object
com.tnsai.server.session.SessionManager

public final class SessionManager extends Object
Maps sessionId to AgentGroup. Creates a default group with one assistant agent on first connect (ADR-3: multi-agent day-1).
  • Constructor Details

    • SessionManager

      public SessionManager(AgentFactory agentFactory)
  • Method Details

    • getOrCreate

      public SessionInfo getOrCreate(String sessionId)
      Get or create a session. On first access, creates an AgentGroup with one assistant agent.
    • get

      public Optional<SessionInfo> get(String sessionId)
    • exists

      public boolean exists(String sessionId)
    • addAgent

      public Optional<String> addAgent(String sessionId, String role)
      Add an agent with the given role to the session's group.
      Returns:
      the new agent's ID, or empty if session not found
    • addAgent

      public Optional<String> addAgent(String sessionId, String role, String provider, String model)
      Add an agent with the given role, provider, and model to the session's group.
    • addAgent

      public Optional<String> addAgent(String sessionId, String role, String provider, String model, String goal, String domain)
      Add an agent with role identity (goal/domain) and LLM configuration.
    • addAgent

      public Optional<String> addAgent(String sessionId, String role, String provider, String model, String goal, String domain, String name)
      Add an agent with role identity, LLM, and optional display name.
    • addAgent

      public Optional<String> addAgent(String sessionId, String role, List<com.tnsai.tools.method.DynamicToolMethod> additionalTools)
      Add an agent with the given role and additional tools to the session's group.
      Parameters:
      additionalTools - extra tools (e.g. MCP proxy tools) to register on the agent
      Returns:
      the new agent's ID, or empty if session not found
    • addAgent

      public Optional<String> addAgent(String sessionId, String role, String provider, String model, List<com.tnsai.tools.method.DynamicToolMethod> additionalTools)
      Add an agent with the given role, provider, model, and additional tools.
    • addAgent

      public Optional<String> addAgent(String sessionId, String role, String provider, String model, String goal, String domain, String name, List<com.tnsai.tools.method.DynamicToolMethod> additionalTools)
      Add an agent with full configuration: role identity, LLM, name, and tools.
      Parameters:
      goal - custom role goal, null to use preset
      domain - custom role domain, null defaults to "tnsai-server"
      name - optional display name, null to derive from role
      additionalTools - extra tools (e.g. MCP proxy tools) to register
      Returns:
      the new agent's ID, or empty if session not found
    • addAgent

      public Optional<String> addAgent(String sessionId, String primaryRole, String provider, String model, String name, List<WsProtocol.RoleDef> roleDefs)
      Add a multi-role agent with optional display name.
      Parameters:
      name - optional display name
      roleDefs - list of role definitions (name, goal, domain)
    • replaceAgentsWithTools

      public void replaceAgentsWithTools(String sessionId, List<com.tnsai.tools.method.DynamicToolMethod> additionalTools)
      Replaces all agents in the session with new ones that include the given tools. Used when MCP tools arrive and need to be registered on all existing agents.
      Parameters:
      sessionId - session to update
      additionalTools - tools to add to each agent
    • removeAgent

      public boolean removeAgent(String sessionId, String agentId)
      Remove an agent from the session's group.
      Returns:
      true if removed
    • remove

      public void remove(String sessionId)
      Remove a session and dissolve its group.
    • getRag

      public RagService getRag(String sessionId)
      Returns (or lazily creates) the RagService for the given session.
      Parameters:
      sessionId - session identifier
      Returns:
      the session's RAG service
    • getActiveSessions

      public Set<String> getActiveSessions()
    • getSessionCount

      public int getSessionCount()
    • getAllSessions

      public Map<String,SessionInfo> getAllSessions()