Skip to content

v0.19.1 · Apache 2.0 · Java 21+

An AI agent is one Java class. Get it wrong and it will not start.

TnsAI checks the class and the builder before the first answer, and tells you which line is wrong.

Break a line

ResearchAssistant.java

@RoleSpec(knowledge = @Knowledge(
name = "papers",
path = "library/papers"))
public class ResearchAssistant extends Role {
@Override
public RoleIdentity getIdentity()
@ActionSpec(
type = ActionType.LLM,
description = "Answer a question about the papers",
mustAlways = {"cite the paper the answer comes from"},
mustNever = {"cite a paper that is not in the library"},
knowledge = @Knowledge(name = "paper"))

IllegalStateException

Action ResearchAssistant.ask names knowledge 'paper', which is not declared; declared: [papers]

public String ask(String question) {
return question;
}
}

Main.java

Agent agent = AgentBuilder.create()
.llm(client)
.role(Role.create(ResearchAssistant.class))
.principal(principal)
.authorityScope(scope)
.build();

Refused before the first answerat ResearchAssistant.java:16: IllegalStateException: Action ResearchAssistant.ask names knowledge 'paper', which is not declared; declared: [papers]

Mistakes stop at startup, not in front of a user

Three checks run before the first answer, in this order. Each message is the one you will see.

  1. 1 · Role.create(…)

    The role is created

    The role declares the same source twice

    RoleInitializationException

    Failed to create role: ResearchAssistant

    Caused by IllegalStateException

    @RoleSpec on ResearchAssistant declares knowledge 'papers' twice

  2. 2 · .build()

    The agent is built

    No principal or no authority scope

    IllegalStateException

    AgentBuilder requires accountability wiring: principal=missing, authorityScope=set. Call .principal(...) and .authorityScope(...) on this builder before .build().

    Leave out .authorityScope(…) and it reads authorityScope=missing.

  3. 3 · agent.chat(…)

    The first call, before the model

    An action names a source the role never declared

    IllegalStateException

    Action ResearchAssistant.ask names knowledge 'paper', which is not declared; declared: [papers]

  4. The first answer

    Only an agent that got past all three gets here.

What TnsAI leaves to you

Prompt rules

mustAlways and mustNever are written into the system prompt beside the action on every run. The model is still the one that follows them. For a check at runtime, use a guardrail.

A missing folder

By default, a source that cannot be loaded does not stop the action (onFailure = CONTINUE), and the agent answers without it. Set @Search(onFailure = FAIL) and the first action stops instead:

RetrievalException

FILE knowledge source could not be loaded completely (source 'papers' on ResearchAssistant)

Take only the layers you need

Fourteen runtime modules under one BOM, in four layers. Add a layer as a dependency when you need it.

  1. Runtime

    The core every agent runs on, the models it talks to, and the ways to reach it.

    • The agent runtime

      tnsai-core

      Roles and actions, checked and run against the model.

    • Language models

      tnsai-llm

      One interface over 31 LLM providers, with streaming and cost tracking.

    • Model Context Protocol

      tnsai-mcp

      Use tools from any MCP server, or serve your own.

    • Web server

      tnsai-server

      Agents over HTTP and WebSocket, with a Dockerfile.

  2. Knowledge

    What an agent knows and can do: your documents, its plans and its tools.

    • Search over documents

      tnsai-rag

      Vector, keyword and graph search over PDF, Word, Markdown and more.

    • Database as a source

      tnsai-rag-jdbc

      A table or a query as a corpus, over plain JDBC.

    • Planning and memory

      tnsai-intelligence

      Planners, reasoning and compaction for long conversations.

    • Built-in tools

      tnsai-tools

      63 toolkits and 209 tools, from web search to finance.

  3. Teams and quality

    Agents working together, kept safe, and scored with numbers.

    • Agent teams

      tnsai-coordination

      Eight team shapes, negotiation and voting, in FIPA messages.

    • Safety and tracing

      tnsai-quality

      Guardrails, access control and OpenTelemetry tracing.

    • Scoring and benchmarks

      tnsai-evaluation

      LLM-judge scores and a regression gate for releases.

  4. Connections

    Where the agent meets people, pays for things, and is tested end to end.

    • Chat apps

      tnsai-channels

      Telegram, Slack, Discord, WhatsApp, email and the terminal.

    • Payments

      tnsai-payments

      Pays for web resources in USDC over x402, within your limits.

    • Integration tests

      tnsai-integration

      Tests that run the modules together, and the SCOP bridge.

Every module in the docs

Your first agent in three steps

Open the quickstart
  1. Add the repository and the BOM

    TnsAI is published to its own Maven repository. Import the BOM once and every TnsAI module you add takes the same version.

    pom.xml
    <repositories>
      <repository>
        <id>tnsai</id>
        <url>https://repo.tnsai.dev/maven2</url>
      </repository>
    </repositories>
    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>dev.tnsai</groupId>
          <artifactId>tnsai-bom</artifactId>
          <version>0.19.1</version>
          <type>pom</type>
          <scope>import</scope>
        </dependency>
      </dependencies>
    </dependencyManagement>
  2. Write a role

    A role says who the agent is and what it can do. Each @ActionSpec method is one thing it can do; this one runs locally, without a model.

    AssistantRole.java
    public final class AssistantRole extends Role {
        @Override
        public RoleIdentity getIdentity() {
            return new RoleIdentity(
                    "assistant", "Friendly conversational agent", "support");
        }
    
        @ActionSpec(type = ActionType.LOCAL, description = "Greet the user by name")
        public String greet(String name) {
            return "Hello, " + name + "!";
        }
    }
  3. Build it and run it

    AgentBuilder puts the role together with a model client, the principal the agent acts for and what it may do; here, anything for an hour. Start it and the answer comes back as a String.

    Main.java
    Agent agent = AgentBuilder.create()
            .llm(new AnthropicClient(model))
            .role(role)
            .principal(principal)
            .authorityScope(AuthorityScope.unrestricted(Duration.ofHours(1)))
            .build();
    
    agent.start();
    String response = agent.chat("Hi, my name is Alice");

Questions

TnsAI is an open-source Java 21 framework for building production AI agents. It has 14 runtime modules that share one version through one Maven BOM (dev.tnsai:tnsai-bom:0.19.1), published to https://repo.tnsai.dev/maven2. The license is Apache 2.0.

Start with one BOM

dev.tnsai:tnsai-bom:0.19.1