Minimum viable tool

public class WeatherTool implements Tool {
  public String name() { return "get_weather"; }
  public String description() { return "Get current weather for a city."; }
  public Schema schema() {
    return Schema.object()
        .property("city", Schema.string().required())
        .property("units", Schema.string().enumValues("metric","imperial").defaultValue("metric"));
  }
  public Object call(Map args) {
    return fetchWeather((String) args.get("city"), (String) args.get("units"));
  }
  public boolean isIdempotent() { return true; }
}
Advertisement

Handle errors gracefully

Throw ToolException with a message the LLM can read + recover from. Don't leak stack traces.

Advertisement

Return structured data

Return a Map or a serializable record. The runtime JSON-encodes for you. Objects with cycles will fail here.