# Philipp Schmid explains how Code Mode collapses agent tools into one exec call

> Original title: Agent 很快只剩一个工具：用代码把动作串完再回来

- Source: meng shao
- Published: 2026-11-03T01:27:31.000Z
- Bad Influence: https://badinfluence.news/items/b4prhqimwiqlw9xx2pe884f3w
- Original: https://x.com/shao__meng/status/2117428427380957442

## Summary

Philipp Schmid describes Code Mode, where a model gets only an exec(code) tool and runs chained tool calls in a TypeScript or Python sandbox. Intermediate results mostly stay out of the model's context, and the post argues a typed sandbox can beat raw bash for agents.

## Post

Agent 很快只剩一个工具：用代码把动作串完再回来

来自 @_philschmid 的分享，他发现 Agent 工具调用正在从「每轮一次 JSON 动作」收敛成 Code Mode：模型只拿到一个 exec(code)，在沙箱里用 TypeScript/Python 把查、滤、改、并行全串完，中间结果大多不进上下文。
https://www.philschmid.de/code-mode

过去两年做 Agent，核心工作是设计工具、拆粒度、改 schema 和系统提示。Philipp 认为方向在反过来：整本工具目录浓缩成一个 exec，这就是 Code Mode。Harness 不再把几十个 JSON Schema 工具塞进模型接口，而编成紧凑的类型声明（declare namespace tools { ... }）；模型要做事就写一小段脚本，在隔离沙箱里 await tools. xxx(...)，用 Promise.all、过滤、分支把依赖动作一次做完。

工具调用大致走过几步：模型弱时只能给少量工具；变强后又接上几十个工具或 MCP，撞上上下文上限，于是用工具搜索、按需披露；即便动态加载，标准调用仍基本是「一回合一个动作」，出结构化调用、等原始输出回写历史、再推理下一步。最近模型在「单次生成里组合依赖动作」上明显更稳，Code Mode 才站得住：调研可以一轮里查询、过滤、抽答案；多文件改动能同脚本里改完再跑校验；浏览器/电脑操作不必每个点击都回模型；并行扇出可以 await Promise.all 再喂给下一步，中间不反复挤进上下文。推动因素包括：前沿模型大量训代码、厂商开始为 Code Mode 做后训练，以及 MCP 越来越多同时给 inputSchema 和 outputSchema，模型在跑之前就知道返回类型，便于在同一脚本里把 Tool A 接到 Tool B。

实现上，表面只暴露 exec(code)。大目录不必一次全挂上，可继续用工具搜索，或在沙箱里挂全局 ALL_TOOLS 让模型用代码筛选。text() / image() / audio() 决定哪些输出进下一轮上下文；store / load 把状态放在宿主内存，避免大 JSON 每轮占 token。文中 Linear 例子：列出项目 → 并行拉 issue → 滤出未指派 → 并行归档，沙箱里可跑几十次底层 API，回模型的往往只有一行摘要。

为什么偏 JS/Python 沙箱而不是只给 bash：类型化函数直接对应 MCP/内部 API，有原生对象、Promise.all、try/catch，少受 shell 转义之苦；自定义 CLI 常逼模型先 --help、读源码摸旗标，类型契约能省这层探索税；shell 基本只有 stdout，多模态要看图还得另挂工具，而 image(screenshot) 可直接挂到下一轮；每次 tools.* 走宿主桥，可在沙箱外注入 OAuth、校验 schema、对破坏性操作暂停确认；标准工具调用几乎只能靠 prompt 历史当状态库，KV 则能跨回合省 token。

文中给了一个用 Gemini Interactions API、gemini-4-argon 的可跑伪示例：只注册 exec，脚本里列 PR 文件、按条件筛、跑安全扫描、发评论，中间文件对象和扫描原始结果不进模型，第二轮只收回一行摘要。生态上，Pi、Factory Droid、OpenAI Codex 等已默认或支持 Code Mode；Factory 把 Droid 1.0 切过去后，Terminal-Bench 4 准确率约 +3.5，模型花费约 -15%。Pydantic AI、LangChain、Cloudflare Agents SDK 等也有类似能力。作者也留了余地：未必每个 Agent 真只剩一个工具；很多为 bash 和人类可读文本优化的 CLI、Skills，接到类型化执行上未必顺，可能要回过头清点 Agent 真正需要什么。

![](https://badinfluence.news/api/img-proxy?u=https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FHWKd7GFawAADoOb.jpg&mode=thumb&exp=1795651200&sig=8166c3ec2ec1abdf)

## Quoted post @_philschmid

> Are Agents soon going to have only 1 tool? We went from a handful of tools, to dynamic tool search, and now to collapsing everything into code mode. 
> 
> Wrote down how Code Mode works, why a typed JS/Python sandbox can beat raw bash, and why MCP is going to go back strong in 2027.  With an a minimal example for Gemini 4 Argon.
> 
> https://www.philschmid.de/code-mode
> 
> If you plan to explore code mode i can recommend testing with pi! Easily hackable and comes with strong foundation.

https://x.com/_philschmid/status/2117278154918092817
