The current way of defining tools in Java is quite awful.
var session = client.createSession(new SessionConfig()
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setSystemMessage(systemMessageConfig)
.setAvailableTools(new ToolSet().addCustom("*").addBuiltIn("web_fetch"))
.setTools(List.of(
ToolDefinition.create("set_current_phase", "Sets the current phase of the agent. Use this to report progress.",
Map.of("type", "object",
"properties", Map.of("phase", Map.of("type", "string", "enum", List.of("searching", "analyzing", "done"))),
"required", List.of("phase")),
invocation -> {
Phase phase = invocation.getArgumentsAs(PhaseArgs.class).phase();
this.phase = phase;
updateUi();
return CompletableFuture.completedFuture("Phase set to " + phase);
}),
ToolDefinition.createOverride("report_intent", "Reports the agent's intent",
Map.of("type", "object", "properties", Map.of(/* ... */)),
invocation -> { /* ... */ }),
ToolDefinition.create("search_properties", "Search property listings",
Map.of("type", "object", "properties", Map.of(/* ... */)),
invocation -> database.searchProperties(invocation.getArguments()))
))).get(30, TimeUnit.SECONDS);
Compare that with what you get in langchain4j:
@Tool("Get current weather for a location")
String getWeather(@P("City name") String location,
@P(value = "Unit", required = false) String unit) {
return fetchWeather(location, unit);
}
We simply must do better.
The current way of defining tools in Java is quite awful.
Compare that with what you get in langchain4j:
We simply must do better.