Annotation Interface Tool


@Retention(RUNTIME) @Target(METHOD) public @interface Tool
Marks a method as a tool callable by an AI model. Annotate parameters with ToolParam; convert a class containing annotated methods into CallableTools with Tools.fromAnnotated(Object...).

Each annotated method becomes one tool. Supported parameter types are String, int/Integer, long/Long, double/Double, float/Float, boolean/Boolean, enum types (surfaced to the model as a string constrained to the constant names), List<String>, and record types (surfaced as a nested object whose properties are the record components). The return value is sent back to the model: a String is sent verbatim, anything else is JSON-encoded, and void or null is reported as "Success".

Example:

public class CalculatorTools {

  @Tool("Adds two integers and returns the sum.")
  public int sum(
      @ToolParam(name = "a", description = "first addend") int a,
      @ToolParam(name = "b", description = "second addend") int b) {
    return a + b;
  }
}

// In your Agent implementation:
@Override
public List<CallableTool> getTools() {
  return Tools.fromAnnotated(new CalculatorTools());
}
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Tool description surfaced to the model.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Tool name surfaced to the model.
  • Element Details

    • name

      String name
      Tool name surfaced to the model. Defaults to the method name when blank.
      Default:
      ""
    • value

      String value
      Tool description surfaced to the model.