spring-projects / spring-projects/spring-ai
The overload `tools` or `defaultTools` method in `ChatClientBuilder` causes FunctionToolCallback not taking effect.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ChatClientBuilder tools/defaultTools overloads and the ChatClientRequestSpec.tools(Object...) entry point shown in the report. Trace how ToolCallbacks.from(toolObjects) handles FunctionToolCallback, then add regression coverage showing that the reported registration form takes effect. Done means FunctionToolCallback registrations are handled as intended without the misleading overload behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100