TnsAI
Intelligence

AutoTeamBuilder

TnsAI.Intelligence provides LLM-driven automatic team composition. Given a task description, `AutoTeamBuilder` decomposes it into subtasks, generates agent configurations, and selects the optimal coordination topology. Package: `com.tnsai.autoteam`.

Quick Start

Give AutoTeamBuilder a plain-English task description, and it returns a TeamSpec containing the agents, tools, and coordination topology needed to accomplish the task.

AutoTeamBuilder autoTeam = AutoTeamBuilder.builder()
    .llm(llmClient)
    .toolRegistry(toolRegistry)
    .build();

TeamSpec spec = autoTeam.buildTeam("Research quantum computing advances and write a summary report");

// spec contains:
//   - List of agent configs (roles, tools, system prompts)
//   - Selected topology (e.g., SEQUENTIAL, HIERARCHICAL)
//   - Subtask assignments

How It Works

AutoTeamBuilder performs three steps to go from a natural-language task to a ready-to-run team of agents. Each step uses an LLM to make intelligent decisions about decomposition, configuration, and coordination.

1. Task Decomposition

The LLM analyzes the input task and breaks it into subtasks, each with a name, description, and list of dependencies on other subtasks. Dependencies determine execution order and influence topology selection.

List<SubTask> subtasks = autoTeam.decompose("Build a market analysis dashboard");
// SubTask("research", "Gather market data", [])
// SubTask("analyze", "Analyze trends", ["research"])
// SubTask("visualize", "Create dashboard", ["analyze"])

2. Agent Configuration Generation

For each subtask, the builder generates an agent configuration with an appropriate role, a tailored system prompt, and the right tools selected from the registry.

// Each AgentConfig includes:
public record AgentConfig(
    String name,
    String role,
    String systemPrompt,
    List<String> tools,
    Map<String, Object> parameters
) {}

The builder selects tools from the registry based on the subtask requirements. For example, a research subtask gets search tools, while an analysis subtask gets data processing tools.

3. Topology Selection

Based on the dependency graph between subtasks, the builder selects the coordination topology that best fits the workflow. Independent tasks run in parallel, linear chains run sequentially, and complex graphs get a hierarchical coordinator.

Dependency PatternSelected Topology
No dependencies (all independent)PARALLEL
Linear chain (A -\> B -\> C)SEQUENTIAL
Tree structure (one root, many leaves)HIERARCHICAL
Complex graphHIERARCHICAL with a coordinator

Builder Parameters

Configure the builder with an LLM for task analysis, a tool registry listing the tools agents can use, and optional constraints on team size.

AutoTeamBuilder autoTeam = AutoTeamBuilder.builder()
    .llm(llmClient)                    // LLM for task analysis
    .toolRegistry(toolRegistry)        // Available tools to assign
    .maxAgents(8)                      // Maximum agents to create
    .preferredTopology(null)           // Override topology selection (null = auto)
    .build();
ParameterDefaultDescription
llmrequiredLLMClient for task decomposition and config generation
toolRegistryrequiredRegistry of available tools
maxAgents8Maximum number of agents to generate
preferredTopologynullForce a specific topology (null = auto-select)

TeamSpec

The output of buildTeam() is a complete blueprint for the agent team. It contains agent configurations, the selected topology, subtask assignments, and a dependency graph. You can inspect it, modify it, or pass it directly to the coordination module to run.

TeamSpec spec = autoTeam.buildTeam(task);

spec.getAgentConfigs();     // List<AgentConfig> -- one per subtask
spec.getTopology();         // String -- selected topology name
spec.getSubTasks();         // List<SubTask> -- decomposed subtasks
spec.getDependencyGraph();  // Map<String, List<String>> -- subtask dependencies

// Instantiate the team
Group group = spec.toGroup(agentFactory);
group.start();
String result = group.execute(task);

Integration with Coordination Module

The generated TeamSpec integrates directly with the Group Topologies from TnsAI.Coordination. This example shows how to take a spec, build real agents from the configurations, and run the team.

// AutoTeamBuilder generates the spec, Coordination module runs it
AutoTeamBuilder autoTeam = AutoTeamBuilder.builder()
    .llm(llmClient)
    .toolRegistry(toolRegistry)
    .build();

TeamSpec spec = autoTeam.buildTeam("Audit the codebase for security vulnerabilities");

// Build and run the team using Coordination topologies
Team team = Team.builder()
    .formation(TeamFormation.valueOf(spec.getTopology()))
    .build();

for (AgentConfig config : spec.getAgentConfigs()) {
    Agent agent = AgentBuilder.create()
        .model(config.parameters().getOrDefault("model", "claude-sonnet-4").toString())
        .systemPrompt(config.systemPrompt())
        .build();
    team.addMember(agent, TeamRole.MEMBER);
}

team.start();
String result = team.execute("Audit the codebase for security vulnerabilities");

On this page