Bug Desception

I have the following FunctionToolCallback instance created and registered to ChatClient Builder as below:

FunctionToolCallback toolCallback1 = ...
FunctionToolCallback toolCallback2 = ...
ChatClient.create(chatModel)
    .prompt("What's the weather like in Copenhagen?")
    .tools(toolCallback1, toolCallback2)
    .call()
    .content();

The above tool registration will not take effect because it actually calls the Builder defaultTools(Object... toolObjects); overload method instead of the Builder defaultTools(List<ToolCallback> toolCallbacks);.

Builder defaultTools(Object... toolObjects); method only works for Method tool, because inside ToolCallbacks.from(toolObjects) it only accepts Method tools:

@Override
public ChatClientRequestSpec tools(Object... toolObjects) {
    Assert.notNull(toolObjects, "toolObjects cannot be null");
    Assert.noNullElements(toolObjects, "toolObjects cannot contain null elements");
    this.functionCallbacks.addAll(Arrays.asList(ToolCallbacks.from(toolObjects))); // here only accepts Method tools
    return this;
}

Only the following form is correct:

ToolCallback toolCallback1 = ... // must be ToolCallback type but not FunctionToolCallback type.
ToolCallback toolCallback2 = ... // must be ToolCallback type but not FunctionToolCallback type.
ChatClient.create(chatModel)
    .prompt("What's the weather like in Copenhagen?")
    .tools(toolCallback1, toolCallback2)
    .call()
    .content();

It's very easy to make the above mistake. There's no compilation error because of the overload methods and it's not easy to debug and find the problem.

Environment

1.0.0-M6

Comment From: Ga-Ol-St

Same issue here: https://github.com/spring-projects/spring-ai/issues/2510#issue-2928554749 Yes, this error is not obvious in some cases... there is simple workaround just call .tool() second time as it's implementation is adding tools to registry, like this:

 .tools(toolCallback1)
 .tools(toolCallback2)

Comment From: yuluo-yx

Same issue here: #2510 (comment) Yes, this error is not obvious in some cases... there is simple workaround just call .tool() second time as it's implementation is adding tools to registry, like this:

.tools(toolCallback1) .tools(toolCallback2)

emm,I also encountered this, but I don't think is a good solution,