# Programmatic Tool Calling

> Programmatic tool calling is a tool-use pattern in which the model writes code that calls tools as functions inside a sandboxed execution environment, so that several tool calls and the processing of their results happen in code rather than through a separate model turn for each call.

- Identifier: PTL-0223
- Category: Retrieval & Tool Use
- Canonical URL: https://protologue.com/t/programmatic-tool-calling/
- Also known as: code mode
- Introduced: 2025

## Description

Intermediate tool results stay in the execution environment and only the code's final output returns to the model, which reduces context usage and the number of model round trips for tasks that involve many calls or large data. Anthropic offers it as a feature of its API, and Cloudflare describes the same pattern for MCP tools under the name Code Mode.

## Broader terms

- [Function Calling](https://protologue.com/t/function-calling/)

## Related terms

- [Code Execution Tool](https://protologue.com/t/code-execution-tool/)
- [Tool Search](https://protologue.com/t/tool-search/)
- [Model Context Protocol](https://protologue.com/t/model-context-protocol/)
- [Program-Aided Language Models](https://protologue.com/t/program-aided-language-models/)

## Sources

- Anthropic (2025). Programmatic tool calling. https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling
- Anthropic (2025). Introducing advanced tool use on the Claude Developer Platform. https://www.anthropic.com/engineering/advanced-tool-use
- Cloudflare (2025). Code Mode. https://developers.cloudflare.com/agents/model-context-protocol/protocol/codemode/

## Cite this entry

Protologue. (2026). Programmatic Tool Calling. In Protologue: A Taxonomy of Prompting and LLM Techniques (v1.4.0, PTL-0223). https://protologue.com/t/programmatic-tool-calling/

License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
