Package com.tnsai.tools.method
Record Class StaticToolMethod
java.lang.Object
java.lang.Record
com.tnsai.tools.method.StaticToolMethod
- Record Components:
name- the LLM-facing tool name (defaults to method name)description- human-readable description for the LLM tool catalogkeywords- optional discovery keywords (not exposed to LLM)idempotent- hint for the retry / fallback layertarget- the POJO instance the method is invoked onmethod- the reflected Java methodparameters- parameter metadata in declaration orderreturnType- the method's static Java returnType
- All Implemented Interfaces:
ToolMethod
public record StaticToolMethod(String name, String description, List<String> keywords, boolean idempotent, Object target, Method method, List<ToolParameter> parameters, Type returnType)
extends Record
implements ToolMethod
A
ToolMethod backed by a discovered Tool-annotated
method on a POJO instance. The dispatch path is reflection: the registry holds the POJO
target and the Method, and invoke(Map, ObjectMapper) coerces the LLM's
argument map to the parameter's static Java type before calling
Method.invoke(Object, Object...).
Built by ToolMethodRegistry during construction. Equality is structural
(record-default) — two distinct instances over the same target+method are equal.
- Since:
- 0.7.0 (was
ToolMethodrecord in 0.5.7-0.6.0; split out whenDynamicToolMethodwas added — see RFC #188 v0.7.0 cleanup)
-
Constructor Summary
ConstructorsConstructorDescriptionStaticToolMethod(String name, String description, List<String> keywords, boolean idempotent, Object target, Method method, List<ToolParameter> parameters, Type returnType) Creates an instance of aStaticToolMethodrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thedescriptionrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanReturns the value of theidempotentrecord component.Dispatch a tool call.keywords()Returns the value of thekeywordsrecord component.method()Returns the value of themethodrecord component.name()Returns the value of thenamerecord component.Returns the value of theparametersrecord component.The JSON-Schema fragment forfunction.parameters(OpenAI) /input_schema(Anthropic).Returns the value of thereturnTyperecord component.target()Returns the value of thetargetrecord component.final StringtoString()Returns a string representation of this record class.Methods inherited from interface com.tnsai.tools.method.ToolMethod
requiresConfirmation
-
Constructor Details
-
StaticToolMethod
public StaticToolMethod(String name, String description, List<String> keywords, boolean idempotent, Object target, Method method, List<ToolParameter> parameters, Type returnType) Creates an instance of aStaticToolMethodrecord class.- Parameters:
name- the value for thenamerecord componentdescription- the value for thedescriptionrecord componentkeywords- the value for thekeywordsrecord componentidempotent- the value for theidempotentrecord componenttarget- the value for thetargetrecord componentmethod- the value for themethodrecord componentparameters- the value for theparametersrecord componentreturnType- the value for thereturnTyperecord component
-
-
Method Details
-
parametersSchema
Description copied from interface:ToolMethodThe JSON-Schema fragment forfunction.parameters(OpenAI) /input_schema(Anthropic). ForStaticToolMethodthis is computed fromToolMethod.parameters()viaJsonSchemaGenerator; forDynamicToolMethodit is supplied at construction time.- Specified by:
parametersSchemain interfaceToolMethod
-
invoke
public Object invoke(Map<String, Object> args, com.fasterxml.jackson.databind.ObjectMapper mapper) throws ExceptionDescription copied from interface:ToolMethodDispatch a tool call.- Specified by:
invokein interfaceToolMethod- 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
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
name
Returns the value of thenamerecord component.- Specified by:
namein interfaceToolMethod- Returns:
- the value of the
namerecord component
-
description
Returns the value of thedescriptionrecord component.- Specified by:
descriptionin interfaceToolMethod- Returns:
- the value of the
descriptionrecord component
-
keywords
Returns the value of thekeywordsrecord component.- Specified by:
keywordsin interfaceToolMethod- Returns:
- the value of the
keywordsrecord component
-
idempotent
public boolean idempotent()Returns the value of theidempotentrecord component.- Specified by:
idempotentin interfaceToolMethod- Returns:
- the value of the
idempotentrecord component
-
target
Returns the value of thetargetrecord component.- Returns:
- the value of the
targetrecord component
-
method
Returns the value of themethodrecord component.- Returns:
- the value of the
methodrecord component
-
parameters
Returns the value of theparametersrecord component.- Specified by:
parametersin interfaceToolMethod- Returns:
- the value of the
parametersrecord component
-
returnType
Returns the value of thereturnTyperecord component.- Returns:
- the value of the
returnTyperecord component
-