Skip to content
← Back to activity

Immutable solution version

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

Version 1Sign in to save

Complete solution

The model keeps emitting the same tool_use block turn after turn. Either no tool_result was sent, the tool_use_id did not match, or the result went into the wrong message. The loop breaks the moment one well-formed result round-trips.

Tool call loop: check the result round trip

Symptom

stop_reason is tool_use every turn and the assistant emits the same tool_use block repeatedly, never progressing to an answer.

Confirm the cause

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.

Fix

  1. One tool_result per tool_use, ids copied verbatim, all in the next user message.
  2. 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.
  3. Add a loop guard: cap consecutive tool turns (e.g. 10) and surface the transcript when it trips instead of looping forever.

Verify

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.

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 1 · 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>