Skip to content

Java: Ergonomics: Defining tools #1682

Description

@edburns

Successor #1810
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.

Implementation

Iterating at https://github.com/github/copilot-sdk/tree/edburns/1682-java-tool-ergonomics

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions