Why programmatic tool calling works
Claude is trained on large amounts of code, so presenting tools as callable Python functions lets it use that strength:
- Tool composition: Chained calls, loops, and conditionals are ordinary Python control flow instead of a series of model round trips
- Result processing: Claude's code filters and aggregates large tool outputs, or writes them to files, and only the final output enters the context window
- Latency: The model is not re-sampled between the tool calls inside one code execution