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


 ToolHandler handler = invocation -> {
 	Map<String, Object> args = (Map<String, Object>) invocation.getArguments();
 	String query = args.get("query").toString();

 	// Perform the tool's action
 	String result = performSearch(query);

 	return CompletableFuture.completedFuture(result);
 };
 
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