Annotation 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 -
Optional Element Summary
Optional Elements
-
Element Details
-
name
-
value
String valueTool description surfaced to the model.
-