Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
public class ToolCallResponse {

public final static String SUCCESS_STATUS = "SUCCESS";
private final String result;
private final String toolName;
private final String toolCallId;
Expand All @@ -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);
}
Comment on lines 29 to +63

/**
* Creates an error response for a failed tool execution.
* @param toolCallId the tool call ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,16 @@ public ToolCallResponse interceptToolCall(ToolCallRequest request, ToolCallHandl
Exception lastException = null;
int attempt = 0;

while (attempt <= maxRetries) {
while (attempt < maxRetries) {
try {
Comment on lines +86 to 87
return handler.call(request);
ToolCallResponse response = handler.call(request);
if (ToolCallResponse.SUCCESS_STATUS.equals(response.getStatus())) {
return response;
Comment on lines +86 to +90
}
else {
// fail, continue run in while method
throw new RuntimeException(response.getResult().toString());
}
Comment on lines +88 to +95
Comment on lines +88 to +95
}
catch (Exception e) {
lastException = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ private ToolCallResponse executeAsyncTool(AsyncToolCallback callback, ToolCallRe
}
}

return ToolCallResponse.of(request.getToolCallId(), request.getToolName(), result);
return ToolCallResponse.success(request.getToolCallId(), request.getToolName(), result);
}
catch (CompletionException e) {
Throwable cause = e.getCause() != null ? e.getCause() : e;
Expand Down Expand Up @@ -785,7 +785,7 @@ private ToolCallResponse executeSyncTool(ToolCallback callback, ToolCallRequest
}
}

return ToolCallResponse.of(request.getToolCallId(), request.getToolName(), result);
return ToolCallResponse.success(request.getToolCallId(), request.getToolName(), result);
}
catch (ToolExecutionException e) {
logger.error("Tool {} execution failed, handling with processor: {}", request.getToolName(),
Expand Down
Loading