spring-projects / spring-projects/spring-ai

ToolCallAdvisor uses hardcoded hasToolCalls() instead of ToolExecutionEligibilityPredicate for tool call detection

Open
#5,877 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
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:
  1. Adding the ToolExecutionEligibilityPredicate to the ToolCallAdvisor which defaults to a basic predicate (DefaultToolExecutionEligibilityPredicate).

  2. Using this predicate in both the non streaming method (adviseCall) and the streaming method (handleToolCallRecursion).

  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.