Anthropic Agents — Computer Use + MCP + Tool Use¶
更新日期:2026-04-26
Anthropic 在 agent 应用层是当前最主动定标准的实验室:Computer Use API(2024.10)+ MCP(2024.11)一组合,成为 LLM agent 工程的事实参考。本篇梳理工程链路 + 设计取舍。
主要参考:
- Anthropic Computer Use API docs
- Computer Use 公告 (2024.10)
- Model Context Protocol 规范 (modelcontextprotocol.io)
- Building Effective AI Agents (Anthropic blog 2024.12)
一、Computer Use(2024.10)¶
让 Claude 控制 GUI(截图 → 点击 / 输入 / 滚动)。
1.1 工程链路¶
flowchart LR
user["用户 prompt"]
claude["Claude"]
tool["Tool Call<br/>screenshot / click / type"]
env["Sandbox / VM"]
obs["Observation<br/>新截图 + DOM"]
user --> claude
claude --> tool
tool --> env
env --> obs
obs --> claude
classDef stage fill:#fff,stroke:#cc785c,color:#1a1a1a;
class user,claude,tool,env,obs stage
1.2 Tool 定义(公开 API)¶
Computer Use API 暴露的 tools:
{
"type": "computer_20241022", # version-locked
"name": "computer",
"display_width_px": 1280,
"display_height_px": 800,
}
支持 actions:
| Action | 参数 | 说明 |
|---|---|---|
screenshot |
(none) | 截当前屏幕 |
mouse_move |
x, y | 移动鼠标 |
left_click |
(optional x, y) | 点击 |
right_click |
x, y | 右键 |
double_click |
x, y | 双击 |
type |
text | 键盘输入 |
key |
key_combo | 按键("ctrl+c" 等) |
scroll |
direction, amount | 滚动 |
1.3 关键工程难点¶
- Vision-language:模型必须看截图 + 推理坐标
- Action grounding:"click the blue button" → (420, 380)。Claude 3.5 训练时加了大量 GUI screenshot + element coordinate 数据
- State tracking:长任务里截图累积,每张图占数千 tokens
- Latency:每步推理 + 等环境响应,端到端 5-30 秒/步
- Recovery:误点 / loading / popup 干扰下的容错
1.4 跟 OpenAI Operator 对比¶
| 维度 | Anthropic Computer Use | OpenAI Operator |
|---|---|---|
| 部署模式 | API(开发者自接) | Integrated(ChatGPT 内置) |
| Sandbox | 用户提供 | OpenAI 提供 |
| 模型 | Claude 3.5/4 Sonnet | GPT-4 / o-series |
| 跨平台 | 只要支持 screenshot 都行 | 限定 OpenAI 的浏览器 |
Anthropic 走"协议优先"路线(暴露能力,让生态接),OpenAI 走"集成体验"路线(不暴露 API,做封闭产品)。
二、Model Context Protocol(MCP)¶
2.1 设计动机¶
LLM 工具调用碎片化:每家有自己 schema(OpenAI function calling / Google function call / Anthropic tools),跨模型不通用。MCP 想做"USB" —— 标准协议,任何模型 / 应用都能接。
2.2 三个角色¶
flowchart LR
client["Client<br/>(Claude Desktop /<br/>Claude Code / Cursor)"]
server["Server<br/>(暴露 tools / resources)"]
transport["Transport<br/>(stdio / HTTP+SSE)"]
client <--> transport
transport <--> server
classDef stage fill:#fff,stroke:#cc785c,color:#1a1a1a;
class client,server,transport stage
- Server:暴露 tools / resources / prompts 给 LLM 应用
- Client:LLM 应用本身(Claude Desktop、Claude Code、Cursor、VS Code)
- Transport:stdio(本地进程)/ HTTP+SSE(远程)
2.3 三类资源¶
MCP 把 LLM 能用的"东西"分三类:
- Tools:可调用函数(read_file、execute_sql、send_email)
- Resources:可读取的数据(文件 / DB / API endpoint)
- Prompts:可复用的 prompt 模板("summarize this code" 等)
跟 OpenAI function calling 比:
| 维度 | OpenAI Function | MCP |
|---|---|---|
| Schema | JSON Schema | JSON Schema(同样) |
| 跨模型 | OpenAI-specific | 通用 |
| 资源类型 | 仅 tools | tools + resources + prompts |
| 状态 | stateless | stateful(session 内) |
| 协议 | HTTP REST | JSON-RPC over stdio/SSE |
2.4 实际生态(2026.04 状态)¶
- Anthropic 自家:Claude Desktop、Claude Code、Claude API 全支持
- 第三方 IDE:VS Code、Cursor、Cline 都已加 MCP 支持
- Server 生态:filesystem / git / postgres / brave-search / slack 等数十个官方 + 社区 server
- 跨厂商:Kimi K2、Qwen3 等也开始支持 MCP(Anthropic 不持有,是开放标准)
2.5 工程范例(Server 实现)¶
最小 Python MCP server:
from mcp.server import Server
from mcp.types import Tool
server = Server("my-tools")
@server.list_tools()
async def list_tools():
return [Tool(
name="get_weather",
description="Get current weather for a city",
inputSchema={
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
)]
@server.call_tool()
async def call_tool(name, arguments):
if name == "get_weather":
return await fetch_weather(arguments["city"])
if __name__ == "__main__":
import asyncio
asyncio.run(server.run_stdio())
启动后任何 MCP-compatible client(Claude Desktop / Cursor)都能调用。
三、Tool Use 设计取舍¶
Anthropic blog Building Effective AI Agents 总结的设计原则:
3.1 工作流 vs Agent¶
定义两类系统:
- Workflow:固定 LLM 调用序列(Plan-and-Execute / Prompt chains)
- Agent:LLM 动态决定下一步(ReAct loop / Computer Use)
取舍:
| 维度 | Workflow | Agent |
|---|---|---|
| 可预测性 | 高 | 低 |
| 灵活性 | 低 | 高 |
| 调试 | 简单 | 难(LLM 决策不透明) |
| 适合任务 | 重复结构化 | 开放探索 |
| Token 成本 | 低 | 高 |
Anthropic 建议:能用 workflow 不用 agent,agent 留给真正需要 dynamic decision 的任务。
3.2 Augmented LLM = 基础原子¶
"An augmented LLM has access to retrieval, tools, and memory."
任何 agent 系统都是这个原子的组合 —— 单 LLM 调 retriever / tool / memory,迭代直到完成任务。
3.3 Agent 设计 pattern¶
Anthropic blog 列举 5 种 pattern(按复杂度递增):
- Augmented LLM:单 LLM + tools
- Prompt chaining:固定 LLM 调用序列
- Routing:LLM 决定走哪个 sub-workflow
- Parallelization:多 LLM 并行处理
- Orchestrator-workers:LLM 拆任务给 sub-LLM
- Evaluator-optimizer:LLM 生成 + LLM 评估迭代
- Agents:完全 dynamic loop(最复杂)
Walker 实操:先看任务能不能用 #1-#3 解决,不行再上 agent。
四、Claude Code(agent 实例)¶
Anthropic 自家 IDE agent,2024.10 发布。
4.1 工程栈¶
- 用 Computer Use API 控制终端 / 编辑器
- 用 MCP 接 git / filesystem / shell
- 推理用 Claude 3.5/4 Sonnet
- 部分功能(如 long-running tasks)用 Extended Thinking
4.2 Subagent / Skill / Hook¶
Claude Code 暴露 3 个高级抽象(参考 H4 章节):
- Subagent:fork 一个 context isolation 的 LLM 子任务
- Skill:参数化的 prompt + system prompt 模板(自动 / 显式触发)
- Hook:事件驱动的自动化(commit 前跑 lint 等)
这套抽象比 LangChain / AutoGPT 更产品化,是 agent 工程的当前 SOTA 之一。
五、复现度自评¶
| 组件 | 公开度 | 复现路线 |
|---|---|---|
| Computer Use API tool schema | ✅ 公开 | 直接实现(开源 GUI agent 已多个) |
| Computer Use 训练数据 | ❌ | 自己合成 GUI screenshot + label |
| MCP 协议 | ✅ 完全开源 | 直接 implement |
| Claude Code agent loop | 部分 | 用 ReAct + Subagent + MCP 自己拼 |
| Building Effective Agents 范式 | ✅ blog 公开 | 直接借鉴 |
实操路径:
- MCP server 实现:1 天能跑通基本(filesystem + shell)
- ReAct + tool loop:vLLM / SGLang + 自己写 agent 框架,1 周
- Computer Use 等价:模型层面需要 GUI grounding 训练(需要 vision-language 训过 GUI 数据);如果直接用现有模型(Claude API / GPT-4V),1 天能拼 demo
总结¶
- MCP 是 2024-2026 LLM 工具调用的事实标准 —— 跟进协议比绑死 OpenAI function calling 更长期
- Computer Use 是产品级 GUI agent 的 reference 实现 —— 数据 + 模型集成的工程难,单纯 API 调用容易
- Anthropic Agent 设计哲学:workflow > agent,能不 dynamic 不 dynamic
- Claude Code 是当前最完整的 agent 抽象,复刻它的 subagent / skill / hook 模式可以直接套到自家 IDE
- 跨厂商兼容:Kimi / Qwen / DeepSeek 都跟进 MCP,意味着 agent 应用层正在标准化
参考文献¶
- Anthropic. Computer Use API. 2024.10. docs.anthropic.com
- Anthropic. Building Effective AI Agents. 2024.12. anthropic.com/research/building-effective-agents
- Model Context Protocol Specification. 2024.11. modelcontextprotocol.io
- Anthropic. Computer Use 公告. 2024.10. anthropic.com/news/3-5-models-and-computer-use
- Yao et al. ReAct: Synergizing Reasoning and Acting. 2022. arXiv:2210.03629
↑ 上级 · Anthropic