TnsAI

Schema, Identity, and Enums

TnsAI.Core provides typed schemas for LLM tool definitions, agent identity and communication style modeling, decentralized identifiers (DIDs), and a set of enums that control agent behavior.

ToolDefinition

com.tnsai.schema.ToolDefinition is a typed record representing an LLM tool/function definition. It replaces untyped Map<String, Object> schemas with compile-time safety.

Record Fields

public record ToolDefinition(
    String name,            // required, non-blank
    String description,     // defaults to ""
    Map<String, Object> parameters,  // JSON Schema object, never null
    String endpoint,        // optional API endpoint, defaults to ""
    String apiKeyEnvVar     // optional env var name for API key
)

Creating Definitions

// Builder (recommended)
ToolDefinition tool = ToolDefinition.builder()
    .name("search_weather")
    .description("Get weather for a city")
    .addParameter("city", "string", "City name", true)
    .addParameter("unit", "string", "Temperature unit", false)
    .addEnumParameter("format", "Output format", List.of("json", "text"), false)
    .endpoint("https://api.weather.com/v1")
    .apiKeyEnvVar("WEATHER_API_KEY")
    .build();

// Simple (no parameters)
ToolDefinition simple = ToolDefinition.of("get_time", "Returns current UTC time");

// From OpenAI-format map
ToolDefinition parsed = ToolDefinition.fromMap(existingMap);

Conversion

// To OpenAI function calling format
Map<String, Object> map = tool.toMap();
// {"type": "function", "function": {"name": ..., "description": ..., "parameters": ...}}

// Batch conversions
List<ToolDefinition> defs = ToolDefinition.fromMaps(listOfMaps);
List<Map<String, Object>> maps = ToolDefinition.toMaps(listOfDefs);

Query Methods

MethodReturnDescription
hasParameters()booleanTrue if properties map is non-empty
requiredParameters()List<String>Names of required parameters
properties()Map<String, Object>Parameter property schemas
requiresApiKey()booleanTrue if apiKeyEnvVar is set

Builder API

MethodDescription
name(String)Set tool name
description(String)Set description
addParameter(name, type, description, required)Add a parameter
addEnumParameter(name, description, values, required)Add enum-constrained parameter
parameters(Map<String, Object>)Set raw parameters schema
endpoint(String)Set API endpoint URL
apiKeyEnvVar(String)Set API key environment variable
noApiKeyRequired()Clear API key requirement

ToolSchemaGenerator

com.tnsai.schema.ToolSchemaGenerator generates tool/function schemas for LLM function calling from roles and tools.

Generating Schemas

ToolSchemaGenerator generator = new ToolSchemaGenerator();

// Typed ToolDefinition records (preferred)
List<ToolDefinition> defs = generator.generateToolDefinitions(roles);

// Single action
ToolDefinition def = generator.generateToolDefinition(action);

// From a standalone Tool
ToolDefinition def = generator.generateToolDefinition(tool);

// Legacy Map format
List<Map<String, Object>> schemas = generator.generateToolSchemas(roles);
Map<String, Object> schema = generator.generateToolSchema(action);

// Human-readable description for system prompts
String desc = generator.generateToolsDescription(roles);

Configuration

// Enable/disable example inclusion in schemas
generator.withExamples(true);

Java-to-JSON-Schema Type Mapping

Java TypeJSON Schema Type
String, char, Character"string"
int, Integer, long, Long, short, byte"integer"
double, Double, float, Float"number"
boolean, Boolean"boolean"
Arrays, List"array"
Enums"string" (with enum constraint)
Other"object"

AgentIdentity

com.tnsai.models.agent.AgentIdentity represents a personality trait or characteristic that shapes agent behavior. Identities are included in the system prompt to influence communication style.

public final class AgentIdentity {
    private final String name;        // required, non-blank
    private final String description; // required, non-blank
}

Usage

AgentIdentity analytical = new AgentIdentity(
    "analytical",
    "Takes a data-driven approach to problem solving"
);

AgentIdentity empathetic = new AgentIdentity(
    "empathetic",
    "Shows understanding and consideration for user emotions"
);

// In an Agent subclass
@Override
protected List<AgentIdentity> getIdentities() {
    return List.of(
        new AgentIdentity("expert", "Deep knowledge in software engineering"),
        new AgentIdentity("patient", "Takes time to explain concepts clearly"),
        new AgentIdentity("thorough", "Considers all aspects before responding")
    );
}

Common Identity Types

CategoryExamples
Cognitiveanalytical, creative, logical, intuitive
Socialfriendly, professional, empathetic, direct
Behavioralproactive, thorough, efficient, cautious
Domainexpert, specialist, generalist

The class is immutable and thread-safe. It supports Jackson JSON serialization via @JsonCreator/@JsonProperty.

Communication (Style)

com.tnsai.models.agent.Communication is a record that defines how an agent expresses itself.

public record Communication(
    Tone tone,
    Formality formality,
    Verbosity verbosity
)

Usage

Communication style = new Communication(
    Tone.FRIENDLY,
    Formality.CASUAL,
    Verbosity.CONCISE
);

// Default style
Communication defaultStyle = Communication.defaultStyle();
// Tone.PROFESSIONAL, Formality.NEUTRAL, Verbosity.MODERATE

// Get description
String desc = style.getDescription();
// "Tone: Warm and approachable, Formality: ..., Verbosity: ..."

// Generate prompt section for LLM
String promptSection = style.generatePromptSection();

Null values default to: Tone.PROFESSIONAL, Formality.NEUTRAL, Verbosity.MODERATE.

DID (Decentralized Identifier)

com.tnsai.identity.DID implements W3C DID Core for agent identification.

Format: did:<method>:<method-specific-id>

// Parse from string
DID did = DID.parse("did:wba:example.com:agent-123");

// Create from components
DID did = new DID("wba", "example.com:agent-123");

// Factory methods
DID wba = DID.createWba("example.com", "agent-123");
// did:wba:example.com:agent-123

DID web = DID.createWeb("example.com");
// did:web:example.com

Methods

MethodReturnDescription
getMethod()StringDID method (e.g., "wba", "web", "key")
getMethodSpecificId()StringMethod-specific identifier
getDidString()StringFull DID string
asString()StringAlias for getDidString()
toURI()URIDID as a java.net.URI
isWba()booleanCheck if did:wba
isWeb()booleanCheck if did:web

Validation: method must be lowercase alphanumeric ([a-z0-9]+). Invalid format throws IllegalArgumentException.

Core Enums

ActionType

com.tnsai.enums.ActionType -- execution method for actions.

ValueDescription
LOCALDirect Java method invocation
WEB_SERVICEHTTP API calls
LLMLLM with tool selection
MCP_TOOLModel Context Protocol

AgentVariant

com.tnsai.enums.AgentVariant -- quality/speed/cost tiers.

VariantQualitySpeedCostDescription
HIGHMAXSLOWHIGHComplex/critical tasks
MEDIUMBALANCEDNORMALMEDIUMRegular development
MINIBASICFASTLOWQuick fixes
AUTOADAPTIVEADAPTIVEOPTIMALTask-based selection
agent.setVariant(AgentVariant.HIGH);

// Auto-select based on task keywords
AgentVariant suggested = AgentVariant.forTask("Complex refactoring");  // HIGH
AgentVariant suggested = AgentVariant.forTask("Fix typo");             // MINI

Key methods: isQualityFocused(), isSpeedFocused(), isCostOptimized(), forTask(String).

Sub-enums: Quality (MAX/BALANCED/BASIC/ADAPTIVE), Speed (SLOW/NORMAL/FAST/ADAPTIVE), Cost (HIGH/MEDIUM/LOW/OPTIMAL).

Tone

com.tnsai.enums.agent.Tone -- communication tone.

ValueDescription
ANALYTICALAnalytical and logical
EMPATHETICUnderstanding and compassionate
ASSERTIVEDirect and confident
FRIENDLYWarm and approachable
PROFESSIONALFormal and business-like
CREATIVEImaginative and innovative

Formality

com.tnsai.enums.agent.Formality -- language formality level.

Verbosity

com.tnsai.enums.agent.Verbosity -- response length preference.

AuthType

com.tnsai.enums.AuthType -- authentication types for web service actions: NO_AUTH, BEARER, BASIC.

HttpMethod

com.tnsai.enums.HttpMethod -- HTTP methods: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS.

  • Action System -- how ActionType routes to executors
  • Tools -- the Tool interface that ToolDefinition describes
  • Variants -- detailed variant configuration
  • Advanced Agent Features -- how identities and variants are used
  • Roles -- role-based action discovery with @ActionSpec

On this page