0Pricing
AI Agents · 课时

计算机使用模式(Anthropic Computer-Use)

Anthropic 的 Computer Use 将屏幕截图、鼠标和键盘作为工具提供给 Claude。

计算机使用模式(Anthropic Computer-Use) 是 CoddyKit 上的免费 AI Agents 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 AI Agents 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 AI Agents 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

什么是 Computer Use

Anthropic 的“Computer Use”能力(Claude 3.5 及更高版本)将截图、鼠标和键盘公开为工具。模型可以端到端地操控虚拟桌面。

工具集

三个核心工具:

  • computer — 截图、点击、输入、滚动
  • bash — 运行 shell 命令
  • text_editor — 读取和写入文件

Quickstart

from anthropic import Anthropic
client = Anthropic()

response = client.beta.messages.create(
    model='claude-sonnet-4-5',
    max_tokens=4096,
    tools=[{'type': 'computer_20241022', 'name': 'computer', 'display_width_px': 1280, 'display_height_px': 720}],
    messages=[{'role': 'user', 'content': 'Open Firefox and search for the weather.'}]
)

返回的工具调用

模型会发出如下形式的 tool_use 块:

{
    'type': 'tool_use',
    'name': 'computer',
    'input': {
        'action': 'screenshot'  # or 'left_click', 'type', 'mouse_move'
    }
}

操作类型

  • screenshot — 截取并返回截图
  • left_click {coordinate: [x, y]} — 点击
  • type {text: "hello"} — 输入文字
  • key {text: "Return"} — 按下按键
  • mouse_move {coordinate: [x, y]}
  • scroll {coordinate: [...], scroll_direction: "down"}

由您构建执行器

Anthropic 提供工具 DEFINITION;您负责实现执行。通常通过 Playwright、X11 或 Docker 中的无头桌面来实现:

from playwright.sync_api import sync_playwright
p = sync_playwright().start()
browser = p.chromium.launch()
page = browser.new_page(viewport={'width': 1280, 'height': 720})

def execute(action_input):
    action = action_input['action']
    if action == 'screenshot':
        return page.screenshot()
    if action == 'left_click':
        x, y = action_input['coordinate']
        page.mouse.click(x, y)
        return page.screenshot()
    if action == 'type':
        page.keyboard.type(action_input['text'])
        return page.screenshot()
    # ... etc.

Returning the Result

tool_result_content = [
    {'type': 'image', 'source': {'type': 'base64', 'media_type': 'image/png', 'data': screenshot_b64}}
]

messages.append({
    'role': 'user',
    'content': [{
        'type': 'tool_result',
        'tool_use_id': tc.id,
        'content': tool_result_content
    }]
})

必须使用沙箱

Computer Use 允许模型点击 ANYWHERE。请在沙箱化的 VM 中运行它(Docker + Xvfb + 无头浏览器),绝不要在您的笔记本电脑上运行。

Anthropic 参考 Docker 镜像

Anthropic 提供了一个参考 Docker 镜像,其中包含 Xvfb、Firefox、桌面环境和执行器。这是很好的起点。

速度和成本

  • 每个步骤需要 1–5 秒(截图 + LLM + 操作)
  • 每张截图都会向上下文添加令牌
  • 较长的工作流每次运行可能花费 0.50–5 美元

失败模式

  • 点击错元素(偏差 10 像素)
  • 卡在弹窗或 Cookie 横幅上
  • 页面尚未加载完成(请等待!)
  • 验证码

OpenAI Operator

OpenAI 发布了类似的产品(Operator)——概念相同,实现方式不同。两者存在一些细微差异,但能力相近。

使用场景

  • 填写旧版内网应用中的表单
  • 跨多个浏览器进行测试自动化
  • QA 探索性测试
  • “替我使用任意网页应用”的助手

Computer Use 工具

Anthropic 的 Computer Use 向模型公开了哪些工具?

回顾

Anthropic 的 Computer Use 让 Claude 操控桌面。您通过 Playwright 或 X11 实现截图、点击和输入。只能在沙箱中运行。速度较慢,但灵活性高。

常见问题解答

「计算机使用模式(Anthropic Computer-Use)」课时是免费的吗?

是的 — 「计算机使用模式(Anthropic Computer-Use)」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 AI Agents 课程的其余内容,请升级到 CoddyKit PRO。 AI Agents 课程共包含 4 节课。

「计算机使用模式(Anthropic Computer-Use)」这节课中我会学到什么?

Anthropic 的 Computer Use 将屏幕截图、鼠标和键盘作为工具提供给 Claude。 你通过在浏览器中直接运行的动手代码来练习 AI Agents,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 AI Agents 需要有经验吗?

无需任何先前经验。CoddyKit 上的 AI Agents 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。

「计算机使用模式(Anthropic Computer-Use)」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 AI Agents 课中编写并运行代码吗?

能。每节 AI Agents 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 使用 Playwright 进行浏览器自动化
  2. 用于屏幕理解的视觉模型
  3. 计算机使用模式(Anthropic Computer-Use)
  4. 构建可靠的表单填写代理
← 返回 AI Agents