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 catalog
keywords - optional discovery keywords (not exposed to LLM)
idempotent - hint for the retry / fallback layer
target - the POJO instance the method is invoked on
method - the reflected Java method
parameters - parameter metadata in declaration order
returnType - the method's static Java return Type
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 ToolMethod record in 0.5.7-0.6.0; split out when DynamicToolMethod was added — see RFC #188 v0.7.0 cleanup)
  • 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 a StaticToolMethod record class.
      Parameters:
      name - the value for the name record component
      description - the value for the description record component
      keywords - the value for the keywords record component
      idempotent - the value for the idempotent record component
      target - the value for the target record component
      method - the value for the method record component
      parameters - the value for the parameters record component
      returnType - the value for the returnType record component
  • Method Details

    • parametersSchema

      public Map<String,Object> parametersSchema()
      Description copied from interface: ToolMethod
      The JSON-Schema fragment for function.parameters (OpenAI) / input_schema (Anthropic). For StaticToolMethod this is computed from ToolMethod.parameters() via JsonSchemaGenerator; for DynamicToolMethod it is supplied at construction time.
      Specified by:
      parametersSchema in interface ToolMethod
    • invoke

      public Object invoke(Map<String,Object> args, com.fasterxml.jackson.databind.ObjectMapper mapper) throws Exception
      Description copied from interface: ToolMethod
      Dispatch a tool call.
      Specified by:
      invoke in interface ToolMethod
      Parameters:
      args - the LLM's argument map (Jackson-friendly: String / Number / Boolean / List / Map / null)
      mapper - a Jackson ObjectMapper for type coercion (used by StaticToolMethod to convert JSON values to the parameter's static Java type; ignored by DynamicToolMethod)
      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

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • name

      public String name()
      Returns the value of the name record component.
      Specified by:
      name in interface ToolMethod
      Returns:
      the value of the name record component
    • description

      public String description()
      Returns the value of the description record component.
      Specified by:
      description in interface ToolMethod
      Returns:
      the value of the description record component
    • keywords

      public List<String> keywords()
      Returns the value of the keywords record component.
      Specified by:
      keywords in interface ToolMethod
      Returns:
      the value of the keywords record component
    • idempotent

      public boolean idempotent()
      Returns the value of the idempotent record component.
      Specified by:
      idempotent in interface ToolMethod
      Returns:
      the value of the idempotent record component
    • target

      public Object target()
      Returns the value of the target record component.
      Returns:
      the value of the target record component
    • method

      public Method method()
      Returns the value of the method record component.
      Returns:
      the value of the method record component
    • parameters

      public List<ToolParameter> parameters()
      Returns the value of the parameters record component.
      Specified by:
      parameters in interface ToolMethod
      Returns:
      the value of the parameters record component
    • returnType

      public Type returnType()
      Returns the value of the returnType record component.
      Returns:
      the value of the returnType record component