Class AgentFactory

java.lang.Object
com.tnsai.server.agent.AgentFactory

public final class AgentFactory extends Object
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:

  • Constructor Summary

    Constructors
    Constructor
    Description
    AgentFactory(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 Type
    Method
    Description
    com.tnsai.agents.Agent
    createAgent(String agentId, String roleName)
    Create an agent with the given ID and role.
    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.
    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.
    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.
    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.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AgentFactory

      public AgentFactory(Supplier<com.tnsai.llm.LLMClient> llmClientSupplier)
    • AgentFactory

      public AgentFactory(Supplier<com.tnsai.llm.LLMClient> llmClientSupplier, Path workingDirectory)
    • 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

      public com.tnsai.agents.Agent createAgent(String agentId, String roleName)
      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 identifier
      roleName - 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 identifier
      roleName - role name (assistant, developer, etc.)
      provider - LLM provider (e.g. "ollama"), null/blank for default
      model - model name (e.g. "glm-5:cloud"), null for default
      goal - 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 - if provider is set and is not ollama
    • 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.