乐于分享
好东西不私藏

Claude 如何使用计算机工具?

Claude 如何使用计算机工具?

相关阅读

  1. Agent Harness才是真正的产品

  2. OpenAI’s Harness Engineering

  3. OpenAI工程化赋能开发更好驾驭Codex能力

  4. Agentic Software Engineering(致AI开发者)

  5. 构建代理式软件的5级架构:从简单工具代理到生产系统

  6. Agentic Software Engineering(致AI开发者)

  7. Anthropic Multi-Agent Research System构建方法与经验

  8. Anthropic 高效的AI agents上下文工程设计理念和实践经验

  9. Anthropic通过MCP实现高效的Agent

  10. Anthropic Agentic coding最佳实践

  11. Anthropic:高效构建Agents设计理念

  12. Claude Agent Skills:从第一性原理深入剖析

  13. 如何保证Agent的上下文Memory清晰

  14. 重要推荐:Agent AI: Surveying the Horizons of Multimodal Interaction

  15. 基于llama.cpp理解LLM推理的工作原理

  16. LLM推理过程分析

  17. 回归基础!KVcache实现原理与优化!如何让LLM推理更快?

  18. 必知!大模型时代超常用的训练、微调、推理、部署框架

Claude 可以使用计算机吗?

Claude 具备完整的计算机使用能力,其本质是通过「工具调用(Tool Calling)」体系实现与计算机 / 外部系统的交互;Programmatic tool calling (PTC) 作为核心演进方向,解决了传统工具调用的效率损耗问题,成为 Claude 在搜索类任务中性能领先的关键。Tools 是对 Claude 可执行「行动(Actions)」的声明式抽象,通过定义 tool name、description、input arguments,将 bash 执行、网页搜索、文件编辑等计算机操作封装为标准化交互接口。

与每次工具调用都需要往返通过 Claude 的上下文不同,Claude 会编写代码,能够直接在容器内协调工具调用。中间工具结果返回到代码中,而非 Claude 的上下文窗口。这降低了 token 使用量,并提升了多步任务(如搜索)的性能。Opus 4.6 搭配 PTC 最近在 LMArena 的搜索基准测试中排名 1。详见我们的文档,了解更多关于 PTC 以及默认使用 PTC 的新 web search tool。

Computer use 是 Claude 最核心的能力之一。仅仅给 Claude 一个 bash tool 就能打开广阔的行动空间,并引发一个常见问题:bash 是否足够?以及如何决定给 agent 提供哪些其他工具?

Actions 是 Claude 与世界互动的方式。Tools 是一种声明式指定 Claude 可以采取的 actions 的方式。API 允许你通过提供 tool name、description 和 input arguments 来添加 tools。

如果 Claude 想要调用 tool,它会以 JSON 对象的形式响应 tool arguments 来运行。Tool handler(例如 MCP server、你编写的代码等)运行 tool 并传回 context。如果你循环运行这个,你就有一个 agent。例如,bash tool 通过生成包含 command 的 JSON 对象来产生 bash commands。它被传递给 bash tool handler 执行:

1

{"command": "pip install requests"}

何时使用工具

Claude 搭配 bash tool 在循环中运行是一个 computer-use agent。这是 Claude Code 的核心。但 Claude Code 并不仅仅使用 bash。它使用 tools 作为围绕某些 actions 的 control surface。详见 @trq212 对这些点的 breakdown。将一个 action 提升为 tool 在几种情况下是有意义的:

  • • UX:@trq212 谈到了 AskUserQuestion tool。这个例子表明 tools 在需要以特定方式捕获特定 actions 并渲染给用户的情况下很有用。
  • • Guardrails。某些 actions 需要 guardrails。例如,file edit tool 可以运行 staleness check 来验证文件自模型上次读取以来没有变化。
  • • Concurrency control。有时按 concurrency safety 分组 actions 很有用(例如,read-only tools 可以并行运行)。
  • • Observability。隔离特定 actions 用于 logging 很有用(例如,测量 latency 或 token usage)。
  • • Autonomy。你可能想按 autonomy-level 分组 actions。如果 harness 可以 undo 一个 action,它就可以更自由地批准该 action。

工具的问题

Tools 在 control 和 composability 之间进行权衡。考虑三个 actions 作为 tool calls。每个 tool call 的 context 返回给 Claude。每次往返都会消耗 latency,将 tool result 序列化到 context 中(例如,即使下一步只需要五行,它也会传递数千行),并引入一个 reasoning step。composition tax 会随着 actions 数量增加而增长。

Programmatic tool callingClaude 正在开发一项能力,将 code 的 composability 与 tools 的 control surface 结合起来。Claude 可以执行 programmatic tool calling(PTC,详见文档这里):你可以像往常一样定义 tools。但不是单独调用它们,Claude 可以将它们作为 functions 组合,并在 code execution container 中运行。每个 function 的输出返回到 container 而非 Claude 的上下文窗口。

https://x.com/RLanceMartin/article/2027450018513490419/media/2027081917716410368

当 code 调用 tool 时(例如,await web_search(query)),container 会暂停。该调用以 typed tool-use event 跨越 sandbox boundary。它像模型直接调用 tool 一样被履行(例如,通过 handler、MCP server 等)。但结果返回到正在运行的 code,而非 Claude 的上下文窗口。code 按照 Claude 指定的 control flow 处理它(例如,调用另一个 tool、过滤数据、累积结果)。只有最终输出到达 Claude。

使用 Opus 4.6,我们在非编码 evals(如 web search 的 BrowseComp 和 DeepsearchQA)中看到了 PTC 带来的 token 效率和性能提升。例如,与其将 50 个原始搜索结果拉入 context 供 Claude reasoning,不如让 code 以编程方式 parse、filter 和 cross-reference results。这保留相关内容并丢弃其余(例如,dynamic filtering)。在 BrowseComp 和 DeepsearchQA 上,它平均提高了 11% 的准确率,同时 input tokens 减少了 24%。Opus 4.6 with PTC 目前在 LMarena 的 Search Arena 中排名 #1。

考虑到这些收益,PTC 现在内置于 API 的 web search tool 中,以在使用 search 时提升性能并节省 token:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

{  "model": "claude-opus-4-6",  "max_tokens": 4096,  "tools": [    {      "type": "web_search_20260209",      "name": "web_search"    },  ],  "messages": [    {      "role": "user",      "content": < query >     }  ]}

PTC 是一种在保留 tools 的 control surface 的同时获得 code execution 好处(如 composability)的方式:tool implementations 运行在你这一侧的 sandbox,而非内部。tool handlers 仍然作为 control surface 位于每次调用的中间,能够 inspect、reject、log 或 queue for human approval。但它允许 Claude 以代码流畅地 orchestrate actions。

推荐阅读

本站文章均为手工撰写未经允许谢绝转载:夜雨聆风 » Claude 如何使用计算机工具?

猜你喜欢

  • 暂无文章