fix: Avoid failure of the main agent process due to tool call failures (#1023)

* Avoid failure of the main agent process due to tool call failures or abnormal returns

* rename recover
This commit is contained in:
linhaolin1
2026-03-19 00:10:26 +08:00
committed by GitHub
parent 54654d2794
commit f93d2b4533
4 changed files with 295 additions and 9 deletions
+18 -1
View File
@@ -311,13 +311,30 @@ func (t *ExecTool) Execute(ctx context.Context, args map[string]any) *ToolResult
if err != nil {
if errors.Is(cmdCtx.Err(), context.DeadlineExceeded) {
msg := fmt.Sprintf("Command timed out after %v", t.timeout)
if output != "" {
msg += "\n\nPartial output before timeout:\n" + output
}
return &ToolResult{
ForLLM: msg,
ForUser: msg,
IsError: true,
Err: fmt.Errorf("command timeout: %w", err),
}
}
output += fmt.Sprintf("\nExit code: %v", err)
// Extract detailed exit information
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
exitCode := exitErr.ExitCode()
output += fmt.Sprintf("\n\n[Command exited with code %d]", exitCode)
// Add signal information if killed by signal (Unix)
if exitCode == -1 {
output += " (killed by signal)"
}
} else {
output += fmt.Sprintf("\n\n[Command failed: %v]", err)
}
}
if output == "" {