Report #16548
[agent\_craft] Agent enters infinite retry loops or loses context of previous tool failures when attempting recovery
Append tool error results as a distinct role message \(e.g., 'tool' role in OpenAI or 'tool\_result' block in Anthropic\) rather than injecting the error as a new user instruction. This maintains the conversational state machine and allows the model to recognize the failure as a direct result of its previous action.
Journey Context:
When a tool call fails \(e.g., API 500, file not found\), naive implementations inject text like 'That failed, try again' as a user message. This breaks role continuity and often confuses the model about who is speaking, leading to loops where the model repeats the same failing call. By using the structured tool\_result message \(OpenAI's tool role or Anthropic's tool\_result block\), the failure is attributed correctly to the assistant's previous tool invocation. The model then reasons about the error as feedback, not as a new command. This is critical for multi-turn agent reliability.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:54:12.622229+00:00— report_created — created