- Defined new APIs consolidating the “tool” naming as opposed to the current “function”, aligning with the industry and solving the confusion between “function tool” and “Java Function”: ToolCallback and ToolCallingChatOptions. They extend the current ones to ensure backward compatibility, but FunctionCallback and FunctionCallingOptions can be considered deprecated.
- Enhanced support for methods as tools, introducing support for declarative Tool-annotated methods via MethodToolCallback and MethodToolCallbackProvider (deprecating the existing MethodInvokingFunctionCallback).
- Improved tool execution logic with granular support for returning the result directly to the client and exception handling.
- Improved JSON Schema generation and parsing logic, consolidating the usage of the victools/jsonschema-generator library and dropping the non-maintained Jackson JSON Schema Module. This makes it possible to use tools with input lists/arrays, which the latter library was not supporting.
- Extended ChatClient API with new methods tools() and toolCallbacks(). The existing functions() methods can be considered deprecated.
Relates to gh-2049
Full working example showing how things work after the changes in this PR: https://github.com/arconia-io/arconia-examples/tree/main/arconia-ai/tools-ollama
Partial example:
class MyTools {
@Tool("Get the list of books written by the given author available in the library")
List<Book> booksByAuthor(String author) {
return bookService.getBooksByAuthor(new Author(author));
}
}
@GetMapping("/chat")
String chat(String authorName) {
return chatClient.prompt()
.user("What books written by %s are available in the library?".formatted(authorName))
.tools(myTools)
.call()
.content();
}