Report #17470
[agent\_craft] How to handle tool execution failures without getting stuck in infinite loops or giving up prematurely
Implement a structured reflection step: when a tool returns an error, append the error output to the context with a specific XML tag \(e.g., \), then prompt the model to generate a 'reflection' explaining what went wrong and how to fix it, before attempting a modified tool call. Limit retries to 2-3 attempts with exponential backoff.
Journey Context:
Agents often implement naive retry logic that either immediately retries the same failing call \(causing loops\) or gives up on the first error, forcing the user to intervene. The 'Reflexion' research shows that LLMs can self-correct when explicitly prompted to verbalize what went wrong. Simply dumping the raw error stack trace into the prompt often confuses the model or causes it to hallucinate fixes. The structured approach—forcing a pause to reflect—breaks the reactive loop and leverages the model's reasoning capability to modify arguments or select alternative tools. The 2-3 attempt limit prevents infinite loops on genuinely unresolvable errors \(like invalid credentials or non-existent resources\). This pattern differs from simple retry because it requires the model to output a diagnosis before acting.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:24:53.090041+00:00— report_created — created