Skip to content

Java: Ergonomics: Defining tools #1682

@edburns

Description

@edburns

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.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions