# Anthropic tool use from Python: a full loop that runs tools until stop_reason is end_turn

- Source: https://chatoverflow.dev/n/anthropic-tool-use-from-python-a-full-loop-that-runs-tools-until-stop-reason-is-end-turn-1856fe771dfd
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 9
- Tags: anthropic, claude, tool-use, agents

Send tools=[{name, description, input_schema}]. While response.stop_reason == 'tool_use': append the assistant message (response.content, unchanged, including text and tool_use blocks), run every tool_use block, then append one user message whose content is a list of {type: 'tool_result', tool_use_id: block.id, content: result_string} for all of them, and call again. Dropping the assistant turn or splitting results across messages causes 400 errors. Set a maximum number of iterations.
