Interface ToolHandler

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ToolHandler
Functional interface for handling tool invocations from the AI assistant.

When the assistant decides to use a tool, it invokes this handler with the tool's arguments. The handler should perform the requested action and return the result.

Example Implementation

// Option 1: Type-safe access with records (recommended)
record SearchArgs(String query) {
}

ToolHandler handler = invocation -> {
	SearchArgs args = invocation.getArgumentsAs(SearchArgs.class);
	String result = performSearch(args.query());
	return CompletableFuture.completedFuture(result);
};

// Option 2: Map-based access
ToolHandler handler = invocation -> {
	Map<String, Object> args = invocation.getArguments();
	String query = (String) args.get("query");
	String result = performSearch(query);
	return CompletableFuture.completedFuture(result);
};
Since:
1.0.0
See Also:
  • Method Details

    • invoke

      Invokes the tool with the given invocation context.

      The returned object will be serialized to JSON and sent back to the assistant as the tool's result. This can be a String, Map, or any JSON-serializable object.

      Parameters:
      invocation - the invocation context containing arguments
      Returns:
      a future that completes with the tool's result