Package com.tnsai.tools.method
Interface ToolMethod
- All Known Implementing Classes:
DynamicToolMethod,StaticToolMethod
A tool method addressable by the LLM. Two variants:
StaticToolMethod— backed by aTool-annotated method on a POJO. Discovered byToolMethodRegistryvia reflection; dispatched viaMethod.invoke(java.lang.Object, java.lang.Object...).DynamicToolMethod— name, description, schema, and dispatch handler all supplied at construction time. Used for tools whose identity is only known at runtime (e.g.McpProxyToolfronting a remote MCP server).
Both variants expose enough metadata to render the JSON-Schema fragment that the
LLM tool catalog needs (parametersSchema()) and to dispatch a tool call
(invoke(Map, ObjectMapper)).
The interface is
} so invalid @link
{@link sealed
ToolMethodRegistry and
ToolMethodDispatcher can switch on variants without an open-class
extension point — adding a new variant requires updating this permits clause
and at least the dispatcher.
- Since:
- 0.5.7 (was a record before 0.7.0; converted to sealed interface when
DynamicToolMethodwas added — see RFC #188 v0.7.0 closeout)
-
Method Summary
Modifier and TypeMethodDescriptionHuman-readable description.booleanWhether the tool is idempotent (safe to retry on failure, safe to cache, safe to run in parallel duplicates).Dispatch a tool call.keywords()Optional discovery keywords (not exposed to the LLM).name()LLM-facing tool name.Parameter metadata in declaration order.The JSON-Schema fragment forfunction.parameters(OpenAI) /input_schema(Anthropic).default booleanWhether dispatching this tool should be gated behind an approval / confirmation filter (theAGENT-V006safety contract).
-
Method Details
-
name
String name()LLM-facing tool name. Unique perToolMethodRegistry. -
description
String description()Human-readable description. The LLM uses this to decide when to call the tool. -
idempotent
boolean idempotent()Whether the tool is idempotent (safe to retry on failure, safe to cache, safe to run in parallel duplicates). Used as a hint by retry / fallback decorators. -
keywords
Optional discovery keywords (not exposed to the LLM). Tool catalogs and search tools use them for fuzzy matching.StaticToolMethodsurfaces the@Tool#keywords()array;DynamicToolMethodsurfaces the keywords supplied to its builder (empty by default). -
requiresConfirmation
default boolean requiresConfirmation()Whether dispatching this tool should be gated behind an approval / confirmation filter (theAGENT-V006safety contract).StaticToolMethodmirrors@Tool#requiresConfirmation();DynamicToolMethodsurfaces the flag supplied to its builder. Defaultfalse(no confirmation required) — so the agent-builder confirmation scan and anyToolCallFiltersee dynamic / MCP tools that opt in, instead of only annotated@ToolPOJOs (TNS-556). -
parameters
List<ToolParameter> parameters()Parameter metadata in declaration order.StaticToolMethodreturns the reflected@ToolParamlist;DynamicToolMethodreturnsemptysince dynamic tools advertise their shape throughparametersSchema()directly. -
parametersSchema
The JSON-Schema fragment forfunction.parameters(OpenAI) /input_schema(Anthropic). ForStaticToolMethodthis is computed fromparameters()viaJsonSchemaGenerator; forDynamicToolMethodit is supplied at construction time. -
invoke
Object invoke(Map<String, Object> args, com.fasterxml.jackson.databind.ObjectMapper mapper) throws ExceptionDispatch a tool call.- Parameters:
args- the LLM's argument map (Jackson-friendly:String / Number / Boolean / List / Map / null)mapper- a JacksonObjectMapperfor type coercion (used byStaticToolMethodto convert JSON values to the parameter's static Java type; ignored byDynamicToolMethod)- Returns:
- the typed result for the caller to JSON-serialise back to the LLM
- Throws:
Exception- any exception thrown by the underlying tool body
-