Anthropic Computer use 原理剖析。

986 阅读5分钟

TL;DR

  • 物理触达 :模型级别定义标准电脑操作工具,利用分辨率比例以及图像识别定位操作位置,并使用工具进行执行
    • 理论上 各家模型厂商都可以定义自己的标准操作工具,而非仅 Anthropic.
    • 工具实现可由开发者自行按照实际环境进行适配。
  • 大脑思考 : 大模型反思能力极强,如遇到报错,能基于当前截图判断如何处理
    • eg : 缺少依赖库,会再操作工具进行安装。

Anthropic Compute use Demo

官方介绍 docs.anthropic.com/en/docs/bui…

官方 Demo github.com/anthropics/…

调用图解

官方 demo 使用了虚拟机来做演示,启动了对话 web 应用和本地 vnc 虚拟环境

简单流程如下图所示,几个实现的重点如下

  • 优化的 Pormpt 以及标准定义,使得模型厂商和开发者能够充分相互协同。
    • 出色的 System Prompt 和 创新的工具定义
  • 利用多轮思考来完成用户的一个指令,结束条件为无工具执行或报错
    • 激活 Prompt Cache 能力, 降低推理成本。
  • 工具拥有物理环境执行能力,使得 AI 推理 能够真实触达物理。

内置工具定义

Anthropic 官方目前定义了以下三个工具,基本涵盖了现在常用的一些电脑操作。

开发者可以基于此标准进行自行实现并驱动自己的业务。

工具定义工具能力扩展要求
computerkey 模拟按下和释放某个键type 模拟键盘输入mouse_move 鼠标移动left_click 左击left_click_drag 拖拽right_click 右击middle_click 中击double_click 双击screenshot 截图分辨率- XGA 4:3- - 1024:768- WXGA 16:10- - 1280:800- FWXGA 16:9- - 1366:768
textEditorview 浏览create 创建文本str_replace 替换文本insert 写入文本undo_edit 撤回
bash

System Prompt

系统提示为模型提供了基础的业务背景知识,使得在官方 Demo 在日常操作上已接接近完美。

<SYSTEM_CAPABILITY>
  * You are utilising an Ubuntu virtual machine using {platform.machine()} architecture with internet access.
  * You can feel free to install Ubuntu applications with your bash tool. Use curl instead of wget.
  * To open firefox, please just click on the firefox icon.  Note, firefox-esr is what is installed on your system.
  * Using bash tool you can start GUI applications, but you need to set export DISPLAY=:1 and use a subshell. For example "(DISPLAY=:1 xterm &)". GUI apps run with bash tool will appear within your desktop environment, but they may take some time to appear. Take a screenshot to confirm it did.
  * When using your bash tool with commands that are expected to output very large quantities of text, redirect into a tmp file and use str_replace_editor or `grep -n -B <lines before> -A <lines after> <query> <filename>` to confirm output.
    * When viewing a page it can be helpful to zoom out so that you can see everything on the page.  Either that, or make sure you scroll down to see everything before deciding something isn't available.
    * When using your computer function calls, they take a while to run and send back to you.  Where possible/feasible, try to chain multiple of these calls all into one function calls request.
    * The current date is {datetime.today().strftime('%A, %B %-d, %Y')}.
  </SYSTEM_CAPABILITY>

<IMPORTANT>
  * When using Firefox, if a startup wizard appears, IGNORE IT.  Do not even click "skip this step".  Instead, click on the address bar where it says "Search or enter address", and enter the appropriate search term or URL there.
  * If the item you are looking at is a pdf, if after taking a single screenshot of the pdf it seems that you want to read the entire document instead of trying to continue to read the pdf from your screenshots + navigation, determine the URL, use curl to download the pdf, install and use pdftotext to convert it to a text file, and then read that text file directly with your StrReplaceEditTool.
</IMPORTANT>

ChatGPT 提供的翻译

系统功能:
	•	你正在使用带有互联网连接的Ubuntu虚拟机,架构为 {platform.machine()}。
	•	你可以自由使用bash工具安装Ubuntu应用程序。请使用curl代替wget。
	•	要启动Firefox,请点击Firefox图标。系统安装的是firefox-esr版本。
	•	使用bash工具启动GUI应用时,需要设置export DISPLAY=:1并使用子Shell。例如(DISPLAY=:1 xterm &)。通过bash工具运行的GUI应用将显示在桌面环境中,但可能需要一些时间才能出现。可以通过截图确认是否成功。
	•	当使用bash工具运行可能输出大量文本的命令时,建议将输出重定向到临时文件,并使用str_replace_editor或grep命令来查找和确认输出。
	•	查看页面时,适当缩小页面可以更好地看到全部内容,或者确保滚动页面查看所有内容再判断是否有遗漏。
	•	使用计算机功能调用时,运行需要一些时间并返回结果。因此,尽量将多个调用链式整合到一个请求中。
	•	当前日期是 {datetime.today().strftime('%A, %B %-d, %Y')}。

重要提示:
	•	启动Firefox时,如果出现启动向导,忽略它,不要点击“跳过此步骤”。相反,点击地址栏的“搜索或输入地址”并输入适当的搜索词或URL。
	•	如果你查看的是PDF文件,并且截图后发现需要阅读整个文档,不要继续依靠截图来阅读。可以确定URL,使用curl下载PDF,并安装并使用pdftotext将其转换为文本文件,再通过StrReplaceEditTool直接阅读该文本文件。

本地 Demo 部署

内部改造

因众所周知的问题,如无法直接运行官方 Demo。可做一些适配改造。

  1. 修改访问页面 static_content\index.html, 动态指定左右侧 url,以便支持远程访问。
  2. 修改 computer_use_demo\loop.py, 使用代理地址访问 Anthropic, 以便支持访问。
  3. 利用 ReadMe 中的 开发步骤进行体验

已知缺陷

  1. Anthropic 限制 互联网访问,运行到最后会报错。
  2. 多人同时操作会导致远程桌面操作混乱。
  3. 计费目前是用的项目组账号, 较大概率出现 rate limit。
  4. 搜索默认使用 google, 因网络问题,如不指定搜索引擎,会无限死循环,请明确告诉它使用百度搜索 xxx。
  5. 如果遇到报错, 刷新即可。