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
    }
}
What the model seesnamecountErrorsdescriptionCount error log events for one servicein the last N minutes. Use this to checkfor a current error spike.serviceService name, for example checkoutminutesLook-back window in minutes, from 1 to 1440This is all it has to choose with.What it never seesthe method bodyreturn "checkout".equals(service)? 412 : 3; // fake datathe class nameLogTools
Figure 4.1. A tool, as the model sees it. A vague description on the left means a wrong choice, however good the code on the right is.

Attach the tool with .tools(logTools) on the prompt. Exercise: rename the tool, then remove its description. Compare the model’s choices each time.

docs