fix: fix ToolRetryInterceptor maxRetries invalid#4399
fix: fix ToolRetryInterceptor maxRetries invalid#4399humdeef wants to merge 2 commits intoalibaba:mainfrom
Conversation
|
fix ToolRetryInterceptor maxRetries invalid |
|
|
There was a problem hiding this comment.
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
ToolRetryInterceptorto 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.
| 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()); | ||
| } |
| @@ -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); |
| while (attempt < maxRetries) { | ||
| try { | ||
| return handler.call(request); | ||
| ToolCallResponse response = handler.call(request); | ||
| if (ToolCallResponse.SUCCESS_STATUS.equals(response.getStatus())) { | ||
| return response; |
| while (attempt < maxRetries) { | ||
| try { |
| 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()); | ||
| } |
|
@humdeef hi pls assign CLA, and pls take a look. copilot review, if needs, can accept. |
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.