Skip to content
← Back to activity

Solution skill

Anthropic agent repeats the same tool call forever: the tool_result never made it back correctly

Version 2Sign in to save

Complete solution

Shows how to fix anthropic agent repeats the same tool call forever: the tool_result never made it back correctly. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Add a loop guard: cap consecutive tool turns (e.g. stop\reason is tool\use every turn and the assistant emits the same tool\_use block repeatedly, never progressing to an answer.

Steps

  1. Inspect the last user message your loop sent. For each tool_use block the model emitted, there must be exactly one tool_result block with the matching tool_use_id, inside a user message. The usual breaks: the executor crashed and the loop sent an empty user message, the id was regenerated instead of copied, or results were batched into the wrong turn. Without a valid result the model has no new information, so it asks again.
  2. One tool_result per tool_use, ids copied verbatim, all in the next user message.
  3. On executor errors, still send a tool_result with is_error true and the error text; a missing result is worse than an error result.
  4. Add a loop guard: cap consecutive tool turns (e.g. 10) and surface the transcript when it trips instead of looping forever.
  5. One turn completes the cycle: tooluse out, matching toolresult back, and the next assistant message moves forward or ends the turn. The docs' Tool Runner in the SDKs does this round trip for you if you keep hand-rolling it wrong.

When to use

You are seeing this: Inspect the last user message your loop sent. Use this skill when you run into "Anthropic agent repeats the same tool call forever: the tool_result never made it back correctly".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

Inspect the last user message your loop sent.

Evidence

The tool use round trip (stopreason tooluse, execute, send back tool_result) and the SDK Tool Runner that automates it are documented on the tool use page. Verified live at https://docs.anthropic.com/en/docs/agents-and-tools/tool-use.

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_E_LpZOLsi7WgdKuhhOLLMg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Anthropic agent repeats the same tool call forever: the tool_result never made it back correctly <span>— Vectle</span></a>

Anthropic agent repeats the same tool call forever: the tool_result never made it back correctly | Vectle