跳转到内容

Programmatic tool calling

Programmatic tool calling 指模型不再通过自然语言一轮一轮地发起工具调用,而是在代码执行环境中用代码编排工具调用、处理中间结果、控制流程,并只把真正需要的最终输出返回给模型。在当前 wiki 语境里,它是 Anthropic 对大规模 tool use 的一个关键抽象。

  • 这个模式的核心价值在于把中间数据处理从模型上下文中拿走。模型负责写 orchestration 代码,代码负责调用工具、做循环、并行、过滤、聚合和错误处理。
  • 相比传统逐次 tool calling,它通常能同时改善三件事:减少上下文污染、减少多轮 inference 往返、降低模型在自然语言中“手工综合数据”时的错误率。
  • Anthropic 在 Claude Developer Platform 中把这种能力产品化为 Programmatic Tool Calling,要求工具显式通过 allowed_callers opt-in 给 code_execution 调用。
  • 这个概念与 Model Context Protocol (MCP)Tool ergonomics for agents 都直接相关:前者解决“大量工具如何接入”,后者解决“工具怎样更适合 agent 调用”,而程序化工具调用则解决“复杂工作流怎样更高效地跑起来”。
  • 它也与 Agent scaffold 相邻,因为一旦采用这种模式,scaffold 的边界会变化:很多原本要靠 prompt 中描述的步骤,会下沉为代码执行环境中的显式控制流。
  • Scaling Managed Agents-Decoupling the brain from the hands》补充了一个更底层的视角:当“手”被抽象成统一的 execute(name, input) -> string 接口时,程序化工具调用其实也可以被理解成脑通过稳定 runtime interface 去驱动 many hands。
  • The “think” tool- Enabling Claude to stop and think in complex tool use situations》则刚好提供了另一条对照路线:不是把推理下沉到代码,而是在自然语言工具链中插入一个显式的 Reasoning tools for agents 节点。

ℹ️ Conflict:

  • 程序化工具调用并不总是优于普通 tool calling。对于简单、单步、需要模型看到全部中间结果的任务,代码执行层反而可能只是额外开销。
  • 它对安全和系统设计提出更高要求,因为一旦引入代码执行环境,权限控制、沙箱边界、可重试性和可观测性都会变成必须认真设计的问题。
  • Anthropic, “Introducing advanced tool use on the Claude Developer Platform”, 2025-11-24: https://www.anthropic.com/engineering/introducing-advanced-tool-use-on-the-claude-developer-platform
  • 原文摘录:[llm-wiki/raw/anthropic/Introducing advanced tool use on the Claude Developer Platform](/raw/anthropic/Introducing advanced tool use on the Claude Developer Platform.md)
  • Anthropic, “Scaling Managed Agents-Decoupling the brain from the hands”.
  • 原文摘录:[llm-wiki/raw/anthropic/Scaling Managed Agents-Decoupling the brain from the hands](/raw/anthropic/Scaling Managed Agents-Decoupling the brain from the hands.md)
  • Anthropic, “The “think” tool- Enabling Claude to stop and think in complex tool use situations”, 2025-03-20.
  • 原文摘录:[llm-wiki/raw/anthropic/The “think” tool- Enabling Claude to stop and think in complex tool use situations](/raw/anthropic/The “think” tool- Enabling Claude to stop and think in complex tool use situations.md)