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.

Comment From: anupsajjan

Hi @sunyuhan1998 , tried to reproduce 1st question, its working now :) I am not sure what was the issue, wondering if it was intermittent, I will share details if I tumble across it again.

Coming to second question, are you able to reproduce? Because I am able to consistently reproduce it. I will share github repo in some time with example, you can have a look.

https://github.com/anupsajjan/spring-ai-issues

Comment From: ThomasVitale

About issue #2, it's failing because the toolNames support is for "functions-as-tool" and not for "methods-as-tools". You can find more info here: https://docs.spring.io/spring-ai/reference/api/tools.html#_dynamic_specification_bean

Comment From: anupsajjan

Hi @ThomasVitale , thanks for pointing it out, I tried it out, but even with Function as tool, I am still getting same error. Can you check here GithubLink?

Basically my expectation is to have a way to make "Tools configurable at runtime". Hence if we can have dynamic way of figuring out the Tool based on "name" or any other way would be great. Can we add support for toolNames ""methods-as-tool" as well? Since I see there are some limitations with "functions-as-tools".

Comment From: 1426354517

我也遇到了这种情况,当我把版本从1.0.0-M6升级到1.0.0时,原本能注册的@Tool工具类就提示不能注册了,我的解决方案是,只过出带有@Tool注解的方法,然后重新注册 ` private Collection getServiceInstances() { Map serviceBeans = applicationContext.getBeansWithAnnotation(Service.class); Collection instances = new ArrayList<>(serviceBeans.values());

    log.info("检测到 {} @Service beans", instances.size());
    instances.forEach(instance -> log.debug("服务实例: {}", instance.getClass().getName()));
    List<Object> collect = instances.stream().filter(bean -> {
        Method[] declaredMethods = bean.getClass().getDeclaredMethods();
        return Arrays.stream(declaredMethods).anyMatch(method -> method.isAnnotationPresent(Tool.class));
    }).collect(Collectors.toList());

    return Collections.unmodifiableCollection(collect);
}`
.