Expected Behavior
I need to be able to get the values of the of the request being made to a Tool defined in the application.
Current Behavior Calling a tool does not provide you the request being passed to the Tool.
Context
This is a great way to generate JSON data from an AI model where the desired result is the request passed to the Tool.
Comment From: avanathan
- 💯 It would be good if we have same interfaces to Tools like we have for Advisors.
Comment From: enismustafaj
I was actually thinking about getting the tool calling information when the model has given the response and not wrapping the prompt with interceptors. I found out that getting the tool calling information is already implemented. For example, the following code gets the list of Generation
where the is tool calling:
Optional<Generation> toolCallGeneration = chatResponse.getResults()
.stream()
.filter(g -> !CollectionUtils.isEmpty(g.getOutput().getToolCalls()))
.findFirst();
And we can get the AssistantMessage
object from the Generation like:
AssistantMessage assistantMessage = toolCallGeneration.get().getOutput();
AssistantMessage
class provides the record ToolCall
and we get the argument fed to the tool by:
String arguments = assistantMessage.getToolCalls().get(0).arguments()
which we can later deserialize into objects...
Comment From: naveen22356
Hi @enismustafaj - I am using ChatClient with ToolCallbackProvider in an MCP Client. The solution you've posted above does not return any tools called. The tools called shows up as an empty list. Any advise on wha I might be missing?