Skip to content

fix: fix ToolRetryInterceptor maxRetries invalid#4399

Open
humdeef wants to merge 2 commits intoalibaba:mainfrom
humdeef:main
Open

fix: fix ToolRetryInterceptor maxRetries invalid#4399
humdeef wants to merge 2 commits intoalibaba:mainfrom
humdeef:main

Conversation

@humdeef
Copy link
Copy Markdown

@humdeef humdeef commented Mar 10, 2026

Describe what this PR does / why we need it

ToolRetryInterceptor maxRetries invalid

Does this pull request fix one issue?

Describe how you did it

Reference #4386

Describe how to verify it

Write test case

Special notes for reviews

Only sync ,not test async method . Maybe you need scan.

@humdeef
Copy link
Copy Markdown
Author

humdeef commented Mar 10, 2026

fix ToolRetryInterceptor maxRetries invalid

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 10, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ yuluo-yx
❌ 111hh111
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to fix ToolRetryInterceptor not honoring maxRetries by making retry decisions based on ToolCallResponse success/error status (instead of only catching thrown exceptions), addressing issue #4386 where tool failures were converted into responses and therefore not retried.

Changes:

  • Adjust tool execution nodes to return a “success” response variant on normal completion.
  • Update ToolRetryInterceptor to treat non-success responses as retryable failures.
  • Add a success status constant/factory on ToolCallResponse.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/node/AgentToolNode.java Uses a new success response factory on sync/async successful tool completion.
spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/interceptor/toolretry/ToolRetryInterceptor.java Changes retry loop bounds and adds status-based retry triggering.
spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/interceptor/ToolCallResponse.java Introduces SUCCESS_STATUS and a success(...) factory method.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +88 to +95
ToolCallResponse response = handler.call(request);
if (ToolCallResponse.SUCCESS_STATUS.equals(response.getStatus())) {
return response;
}
else {
// fail, continue run in while method
throw new RuntimeException(response.getResult().toString());
}
Comment on lines 29 to +63
@@ -48,6 +49,19 @@ public static ToolCallResponse of(String toolCallId, String toolName, String res
return new ToolCallResponse(result, toolName, toolCallId);
}

/**
* <p>
* Rewrite the status field of the source code to SUCCESS, and then make a judgment in the tool interceptor
* </p>
* @param toolCallId toolCallId
* @param toolName toolName
* @param result response
* @return
*/
public static ToolCallResponse success(String toolCallId, String toolName, String result) {
return new ToolCallResponse(result, toolName, toolCallId, SUCCESS_STATUS, null);
}
}

return ToolCallResponse.of(request.getToolCallId(), request.getToolName(), result);
return ToolCallResponse.success(request.getToolCallId(), request.getToolName(), result);
}

return ToolCallResponse.of(request.getToolCallId(), request.getToolName(), result);
return ToolCallResponse.success(request.getToolCallId(), request.getToolName(), result);
Comment on lines +86 to +90
while (attempt < maxRetries) {
try {
return handler.call(request);
ToolCallResponse response = handler.call(request);
if (ToolCallResponse.SUCCESS_STATUS.equals(response.getStatus())) {
return response;
Comment on lines +86 to 87
while (attempt < maxRetries) {
try {
Comment on lines +88 to +95
ToolCallResponse response = handler.call(request);
if (ToolCallResponse.SUCCESS_STATUS.equals(response.getStatus())) {
return response;
}
else {
// fail, continue run in while method
throw new RuntimeException(response.getResult().toString());
}
@robocanic
Copy link
Copy Markdown
Collaborator

@yuluo-yx

@yuluo-yx
Copy link
Copy Markdown
Collaborator

yuluo-yx commented Mar 21, 2026

@humdeef hi pls assign CLA, and pls take a look. copilot review, if needs, can accept.

@yuluo-yx yuluo-yx changed the title fix ToolRetryInterceptor maxRetries invalid fix: fix ToolRetryInterceptor maxRetries invalid Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants