Package com.tnsai.server.agent
Class AgentFactory
java.lang.Object
com.tnsai.server.agent.AgentFactory
Creates agents for chat sessions. Uses the configured LLMClient supplier
to provision each agent with its own LLM instance.
Agents are created with built-in tools:
ServerShellTools— shell command execution with risk classificationServerFileTools— read + write file contentsServerGitTools— git read + write operations (per ADR-7)
-
Constructor Summary
ConstructorsConstructorDescriptionAgentFactory(Supplier<com.tnsai.llm.LLMClient> llmClientSupplier) AgentFactory(Supplier<com.tnsai.llm.LLMClient> llmClientSupplier, Path workingDirectory) AgentFactory(Supplier<com.tnsai.llm.LLMClient> llmClientSupplier, Path workingDirectory, com.tnsai.accountability.LiabilitySink liabilitySink, com.tnsai.identity.AgentPrincipalProvider principalProvider) Full-control constructor (TNS-298) — caller wires the optional retention sink and required identity provider. -
Method Summary
Modifier and TypeMethodDescriptioncom.tnsai.agents.AgentcreateAgent(String agentId, String roleName) Create an agent with the given ID and role.com.tnsai.agents.AgentcreateAgent(String agentId, String roleName, String provider, String model, String goal, String domain, List<com.tnsai.tools.method.DynamicToolMethod> additionalTools) Create an agent with full configuration: role identity (name/goal/domain), LLM provider/model, and additional tools.com.tnsai.agents.AgentcreateAgent(String agentId, String primaryRoleName, String provider, String model, List<WsProtocol.RoleDef> roleDefs, List<com.tnsai.tools.method.DynamicToolMethod> additionalTools) Create an agent with multiple roles from RoleDef list.com.tnsai.agents.AgentcreateAgent(String agentId, String roleName, String provider, String model, List<com.tnsai.tools.method.DynamicToolMethod> additionalTools) Create an agent with the given ID, role, provider, model, and additional tools.com.tnsai.agents.AgentcreateAgent(String agentId, String roleName, List<com.tnsai.tools.method.DynamicToolMethod> additionalTools) Create an agent with the given ID, role, and additional tools (e.g.
-
Constructor Details
-
AgentFactory
-
AgentFactory
-
AgentFactory
public AgentFactory(Supplier<com.tnsai.llm.LLMClient> llmClientSupplier, Path workingDirectory, com.tnsai.accountability.LiabilitySink liabilitySink, com.tnsai.identity.AgentPrincipalProvider principalProvider) Full-control constructor (TNS-298) — caller wires the optional retention sink and required identity provider. A null sink leaves liability recording disabled; no storage backend is created.
-
-
Method Details
-
createAgent
Create an agent with the given ID and role. Uses RoleBuilder to create a Role with the appropriate goal. -
createAgent
public com.tnsai.agents.Agent createAgent(String agentId, String roleName, List<com.tnsai.tools.method.DynamicToolMethod> additionalTools) Create an agent with the given ID, role, and additional tools (e.g. MCP proxy tools).- Parameters:
agentId- unique agent identifierroleName- role name (assistant, developer, etc.)additionalTools- extra tools to register on the agent (may be empty, never null)- Returns:
- the configured agent
-
createAgent
public com.tnsai.agents.Agent createAgent(String agentId, String roleName, String provider, String model, List<com.tnsai.tools.method.DynamicToolMethod> additionalTools) Create an agent with the given ID, role, provider, model, and additional tools. If provider/model are null, uses the default LLMClient supplier. -
createAgent
public com.tnsai.agents.Agent createAgent(String agentId, String roleName, String provider, String model, String goal, String domain, List<com.tnsai.tools.method.DynamicToolMethod> additionalTools) Create an agent with full configuration: role identity (name/goal/domain), LLM provider/model, and additional tools.- Parameters:
agentId- unique agent identifierroleName- role name (assistant, developer, etc.)provider- LLM provider (e.g. "ollama"), null/blank for defaultmodel- model name (e.g. "glm-5:cloud"), null for defaultgoal- custom role goal, null to use preset from buildGoal()domain- custom role domain, null defaults to "tnsai-server"additionalTools- extra tools to register on the agent- Returns:
- the configured agent
- Throws:
IllegalArgumentException- ifprovideris set and is notollama
-
createAgent
public com.tnsai.agents.Agent createAgent(String agentId, String primaryRoleName, String provider, String model, List<WsProtocol.RoleDef> roleDefs, List<com.tnsai.tools.method.DynamicToolMethod> additionalTools) Create an agent with multiple roles from RoleDef list. Falls back to single-role creation if roleDefs is null or empty.
-