Package com.tnsai.actions


package com.tnsai.actions
Action execution framework for agent tool/function calling.

This package provides the infrastructure for defining and executing actions that agents can perform. Actions bridge the gap between LLM tool calls and actual functionality.

Action Flow

 ┌─────────────────────────────────────────────────────────────┐
 │                      Action Execution                        │
 ├─────────────────────────────────────────────────────────────┤
 │                                                              │
 │  LLM ────► ToolCall ────► ActionDiscovery ────► Method      │
 │                                │                   │         │
 │                                │                   │         │
 │                                ▼                   ▼         │
 │                          ActionRegistry     ActionExecutor   │
 │                                │                   │         │
 │                                │                   │         │
 │                                ▼                   ▼         │
 │  LLM ◄──── ToolResult ◄──── Result ◄───── Execution        │
 │                                                              │
 └─────────────────────────────────────────────────────────────┘
 

Defining Actions

Actions are defined using the ActionSpec annotation:


 public class WeatherAgent extends Agent {

     @ActionSpec("Get the current weather for a location")
     public String getWeather(
         @ActionParam(description = "City name") String city,
         @ActionParam(description = "Temperature unit", required = false) String unit
     ) {
         // Implementation
         return weatherService.getWeather(city, unit);
     }
 }
 

Key Components

ComponentPurpose
ActionDiscoveryFinds @Action methods via reflection
ActionRegistryStores and retrieves action metadata
ActionExecutorInvokes actions with parameters
ActionResultEncapsulates execution result

Action Executors

The com.tnsai.actions.executors sub-package provides specialized executors for different action types:

  • WebServiceExecutor: HTTP API calls
  • LLMRoleExecutor: LLM-typed actions (tool calls dispatched by the agent's ToolMethodDispatcher)
  • McpToolExecutor: MCP (Model Context Protocol) tools

JSON Schema Generation

Actions are automatically converted to JSON Schema for LLM tool definitions, including parameter types, descriptions, and required fields.

Thread Safety

Action execution is thread-safe. Multiple concurrent calls to the same action are supported, provided the action implementation is thread-safe.

See Also:
  • Class
    Description
    Discovers actions from Role classes using reflection.
    Main router for action execution in the TnsAI framework.
    Holds parameters for action execution, supporting transformation between LLM-provided parameters and actual action parameters.
    Wrapper for action execution results.
    Framework-owned helpers for action-body wiring.
    Dedicated exception type so tests can assert the cause without string-matching and operators can wire dedicated alerts on this failure mode.
    Reflectively maps a typed input bean (Java record or POJO with accessors / public fields) to a Map<String, Object> suitable for the framework's existing executeAction(String, Map) dispatch path.
    Utility class for converting values between types in action parameter handling.