Recently, Anthropic introduced a new practice based on the Model Context Protocol (MCP) - "Code Execution Mode" in its latest release. This innovative approach aims to make AI Agents more efficiently call external tools and data services, addressing performance bottlenecks encountered with traditional methods when handling a large number of tools.

As the use of AI Agents becomes more widespread, especially in scenarios that require connecting hundreds or even thousands of tools, traditional methods that directly include all tool definitions and intermediate results in the model context not only increase token consumption but also prolong response times, and may even cause context overflow. Anthropic points out that these are the main challenges faced by large Agent systems today.
The new code execution mode transforms MCP tools into "code APIs," allowing Agents to dynamically call tools by generating and executing code. The advantage of this approach is that tool definitions are loaded only when needed, and data processing is completed in the execution environment, with only the final result returned to the model. This significantly reduces the amount of data the model needs to process, improving the efficiency of tasks such as logical control, loop processing, and data filtering.
For example, when extracting 10,000 rows of data from a Google Sheet, through code execution, the Agent can first filter the data and return only a small number of results, rather than putting all the data into the context. Official tests show that this new code execution mode reduced context usage from about 150,000 tokens to about 2,000 tokens, achieving a savings rate of nearly 99%. In addition, code execution can also improve data privacy and security, allowing sensitive data to be preprocessed in the execution environment before being returned to the model.
Anthropic also emphasizes that this mode enhances the combination capabilities and maintainability of tools, but it requires the support of infrastructure such as secure sandboxes and resource limits to ensure the safety of the execution process. The company encourages developers to explore more practical application scenarios within the MCP ecosystem to achieve broader technological implementation.
Key Points:
✨ The code execution mode significantly improves the efficiency of AI Agents by dynamically calling tools.
🔍 The new method reduces the amount of data processed by the model, saving about 99% of the context usage.
🔒 This mode enhances data privacy and security, allowing sensitive data to be preprocessed in the execution environment.
