Package com.tnsai.server.session
Class SessionManager
java.lang.Object
com.tnsai.server.session.SessionManager
Maps sessionId to AgentGroup. Creates a default group with one assistant agent
on first connect (ADR-3: multi-agent day-1).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd an agent with the given role to the session's group.Add an agent with the given role, provider, and model to the session's group.Add an agent with role identity (goal/domain) and LLM configuration.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(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.addAgent(String sessionId, String primaryRole, String provider, String model, String name, List<WsProtocol.RoleDef> roleDefs) Add a multi-role agent with optional display name.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(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.booleangetOrCreate(String sessionId) Get or create a session.Returns (or lazily creates) theRagServicefor the given session.intvoidRemove a session and dissolve its group.booleanremoveAgent(String sessionId, String agentId) Remove an agent from the session's group.voidreplaceAgentsWithTools(String sessionId, List<com.tnsai.tools.method.DynamicToolMethod> additionalTools) Replaces all agents in the session with new ones that include the given tools.
-
Constructor Details
-
SessionManager
-
-
Method Details
-
getOrCreate
Get or create a session. On first access, creates an AgentGroup with one assistant agent. -
get
-
exists
-
addAgent
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
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 presetdomain- custom role domain, null defaults to "tnsai-server"name- optional display name, null to derive from roleadditionalTools- 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 nameroleDefs- 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 updateadditionalTools- tools to add to each agent
-
removeAgent
Remove an agent from the session's group.- Returns:
- true if removed
-
remove
Remove a session and dissolve its group. -
getRag
Returns (or lazily creates) theRagServicefor the given session.- Parameters:
sessionId- session identifier- Returns:
- the session's RAG service
-
getActiveSessions
-
getSessionCount
public int getSessionCount() -
getAllSessions
-