spring-projects / spring-projects/spring-ai
ToolCallAdvisor uses hardcoded hasToolCalls() instead of ToolExecutionEligibilityPredicate for tool call detection
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
Problem
The ToolCallAdvisor is currently using a hardcoded check to detect tool calls:
isToolCall = chatResponse != null && chatResponse.hasToolCalls();
This approach works fine in some cases but it doesn't consider how certain models (like Anthropic or Bedrock) detect tool calls. For example models like Anthropic also check the "finish reason" (e.g., tool_use) along with tool calls to determine if a tool is being used. Because ToolCallAdvisor ignores this additional check it might miss important tool call detection when working with such models.
Fix
To solve this problem a ToolExecutionEligibilityPredicate has been added to ToolCallAdvisor. This predicate is used in the tool call detection process instead of the hardcoded hasToolCalls() check.
The new approach involves:
-
Adding the ToolExecutionEligibilityPredicate to the ToolCallAdvisor which defaults to a basic predicate (DefaultToolExecutionEligibilityPredicate).
-
Using this predicate in both the non streaming method (adviseCall) and the streaming method (handleToolCallRecursion).
-
Allowing customization: A toolExecutionEligibilityPredicate() method has been added to the Builder class so users can inject their own custom predicates if needed.
Why?
This change ensures that ToolCallAdvisor behaves consistently with how different models (like AnthropicChatModel) detect tool calls. By using a customizable predicate the tool call detection process can now be aligned with the specific behavior of various models making it more accurate and flexible.
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 by reading ToolCallAdvisor, focusing on adviseCall and handleToolCallRecursion, then inspect ToolExecutionEligibilityPredicate and DefaultToolExecutionEligibilityPredicate. Done means both paths use the predicate for tool-call detection and the Builder exposes toolExecutionEligibilityPredicate() for custom predicates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- ai, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 67/100