Chapter 4: Tools
A tool is a Java method. The model chooses tools using only their names and descriptions. A vague description causes wrong choices.
@Component
public class LogTools {
@Tool(description = "Count error log events for one service in the last N minutes. Use this to check for a current error spike.")
public int countErrors(
@ToolParam(description = "Service name, for example checkout") String service,
@ToolParam(description = "Look-back window in minutes, from 1 to 1440") int minutes) {
return "checkout".equals(service) ? 412 : 3; // fake data
}
}
Attach the tool with .tools(logTools) on the prompt. Exercise: rename the tool, then remove its description. Compare the model’s choices each time.