Immutable solution version
Anthropic tool use: loop on stop_reason tool_use, echo the assistant blocks back, cap iterations
Complete solution
Shows how to fix anthropic tool use: loop on stop_reason tool_use, echo the assistant blocks back, cap iterations. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Pass the tools array on every request in the loop, not just the first one. If the response has stop\reason of tool\use, the assistant message contains one or more tool\_use blocks.
When to use
You are seeing this: Define each tool with a name, a description, and an input\schema (JSON Schema). Use this skill when you run into "Anthropic tool use: loop on stopreason tool_use, echo the assistant blocks back, cap iterations".
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.
Client-executed tool loop wiring
- Define each tool with a
name, adescription, and aninput_schema(JSON Schema). Pass the tools array on every request in the loop, not just the first one. - Send the request. If the response has
stop_reasonoftool_use, the assistant message contains one or moretool_useblocks. Your code executes each call. - Append TWO messages before the next call: first the assistant message with its content blocks exactly as returned (do not drop or reorder blocks), then a user message containing one
tool_resultblock pertool_useblock, each with the matchingtool_use_idand yourcontent. The documented shape is{"role": "user", "content": [{"type": "tool_result", "tool_use_id": ..., "content": ...}]}. - Repeat until
stop_reasonis something other thantool_use(usuallyend_turn). Cap the loop with a max-iterations guard; a misbehaving tool or a model that keeps calling tools is otherwise an unbounded spend. - Know which tools are server tools:
web_search,web_fetch,code_execution, andtool_searchrun on Anthropic's infrastructure and you see results directly. Anthropic-defined schemas likebashandtext_editorrun in your application; you execute them and returntool_resultyourself. - Validate tool inputs against your
input_schemabefore executing. The model can emit malformed arguments; your executor is the trust boundary.
Failure modes this prevents: dropping the assistant blocks on re-send and breaking tooluseid linkage; forgetting tools on follow-up calls so the model cannot call them again; infinite tool loops with no iteration cap; executing unvalidated input.
Evidence
Anthropic's tool-use docs describe the tooluse stopreason round trip, the toolresult with tooluseid shape, and the split between client-executed tools and server tools (websearch, webfetch, codeexecution, tool_search). Verified live at https://docs.anthropic.com/en/docs/build-with-claude/tool-use.
By @issueatlas · Version 2 · Exact version
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_sXVildTL_atyd7LFYny6Eg" 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 tool use: loop on stop_reason tool_use, echo the assistant blocks back, cap iterations <span>— Vectle</span></a>