Bug description Two parts in this issue 1. When using toolObjects 2. when using toolNames
1 ) ToolObjects -
Lets say I have created a class MyDbTools and its a component and it has a service class autowired to help in tool logic execution.
`@Component
public class MyDbTools {
@Autowired
private MyDBService myDbService;
@Tool(description = "Execute SQL Query on DB")
String runSQL(@ToolParam(description = "valid SQL query that needs to be run against database") String sql) {
System.out.println("Running sql query");
myDbService.run(sql);
..... .. . .. ... .
}
}
````
When I am trying to configure toolObjects on chatClient, I cannot directly instantiate like `new MyDbTools()` as it has a autowire. Hence I do it as shown below (`.tools(myDbTools)`)
`@Autowired private MyDbTools myDbTools; . . . . String response = chatClient.prompt() .options(chatOptions) .system(enhancedPrompt) .user(request.getUserQuery()) .tools(myDbTools) .call() .content();
But this results in error inside MethodToolCallbackProvider -> assertToolAnnotatedMethodsPresent saying
``'No @Tool annotated methods found in com.test.xyz.ai.tools.MyDbTools$$SpringCGLIB$$0@5d41afe4.Did you mean to pass a ToolCallback or ToolCallbackProvider? If so, you have to use .toolCallbacks() instead of .tool()' error. ``
But I do have @ tool defined already inside it.
This method ReflectionUtils.getDeclaredMethods returns 8 methods, none having annotation called Tool. Hence it fails. I suspect something to do with spring proxy objects for beans and how they are being handled.
If I configure like shown below (where 'DateTimeTools' is a simple class with one tool and no Autowired classes. It works just fine.
```
`String response = chatClient.prompt()
.options(chatOptions)
.system(enhancedPrompt)
.user(request.getUserQuery())
.tools(new DateTimeTools())
.call()
.content();
Can somebody let me know is this a bug or am I doing something wrong?
### 2nd Part of issue with tool calling
2. ToolNames
If I configure chatOptions with toolNames
@Component
public class DateTimeTools {
@Tool(description = "Set a user alarm for the given time")
void setAlarm(@ToolParam(description = "Time in ISO-8601 format") String time) {
LocalDateTime alarmTime = LocalDateTime.parse(time, DateTimeFormatter.ISO_DATE_TIME);
System.out.println("Alarm set for " + alarmTime);
}
}
And call llm
``
String response = chatClient.prompt()
.options(chatOptions)
.system(enhancedPrompt)
.user(request.getUserQuery())
.toolNames("setAlarm")
.call()
.content();
Then it throws error at runtime saying -
Caused by: java.lang.IllegalStateException: No ToolCallback found for tool name: setAlarm at org.springframework.ai.model.tool.DefaultToolCallingManager.resolveToolDefinitions(DefaultToolCallingManager.java:111) ~[spring-ai-model-1.0.0.jar:1.0.0] at org.springframework.ai.ollama.OllamaChatModel.ollamaChatRequest(OllamaChatModel.java:473) ~[spring-ai-ollama-1.0.0.jar:1.0.0] ````
Isnt the expectation of it resolving automatically based on toolName correct? https://docs.spring.io/spring-ai/reference/api/tools.html
Environment spring AI version: 1.0.0 Java 21 Spring boot 3.3.4
Steps to reproduce As shown above, create a class for tool, and use it in chatClient interface and run the application.
Expected behavior Tools should be detected and be available to chatModels. Please do let me know if additional information is required.
Comment From: sunyuhan1998
Hi @anupsajjan , Regarding the first question:
But this results in error inside MethodToolCallbackProvider -> assertToolAnnotatedMethodsPresent saying 'No @Tool annotated methods found in com.test.xyz.ai.tools.MyDbTools$$SpringCGLIB$$0@5d41afe4.Did you mean to pass a ToolCallback or ToolCallbackProvider? If so, you have to use .toolCallbacks() instead of .tool()' error.
I tried to reproduce the issue based on the latest Spring AI code, but I couldn't reproduce it, in my tests the tool was called properly, can you provide a minimal demo that can reproduce the issue?
Comment From: anupsajjan
Hi @anupsajjan , Regarding the first question:
But this results in error inside MethodToolCallbackProvider -> assertToolAnnotatedMethodsPresent saying 'No @tool annotated methods found in com.test.xyz.ai.tools.MyDbTools$$SpringCGLIB$$0@5d41afe4.Did you mean to pass a ToolCallback or ToolCallbackProvider? If so, you have to use .toolCallbacks() instead of .tool()' error.
I tried to reproduce the issue based on the latest Spring AI code, but I couldn't reproduce it, in my tests the tool was called properly, can you provide a minimal demo that can reproduce the issue?
Hi @sunyuhan1998 . Sure will share a sample demo code give me some time.