
如何启用 advisor_tool 让 Computer Use Agent 的 executor 模型在生成中咨询更强模型【免费下载链接】claude-quickstartsA collection of projects designed to help developers quickly get started with building deployable applications using the Claude API项目地址: https://gitcode.com/GitHub_Trending/an/claude-quickstarts本文针对 claude-quickstarts 仓库中computer-use-best-practices这个 macOS 参考实现讲如何把enable_advisor_tool打开让 executor 模型执行点击、输入等操作的模型在生成过程中调用 Anthropic 服务端的 advisor 工具实时向一个更强的模型默认 Opus请求策略性建议。启用后advisor 的咨询记录会以独立行显示在终端输出中token 也单独计费。适用前提该 demo 只支持macOS需要Python 3.11macOS 自带的 python3 是 3.9无法运行并在 System Settings → Privacy Security 中给终端授予Screen Recording和Accessibility权限。API key 通过ANTHROPIC_API_KEY环境变量或仓库根目录的.env文件提供。advisor tool 和服务器端 autocompaction 都是first-party-only beta 功能只有provider anthropic默认值可用。如果provider设为vertex或bedrock且enable_advisor_tool为 true启动时直接抛出ValueError报错文本会指明冲突的字段要求把它设为False或切换 provider。安装步骤venv、requirements.txt、Playwright Chromium 下载、.env配置见 computer-use-best-practices 的 README。启用 advisor_tool配置覆盖按以下优先级叠加后者覆盖前者见 constants.py 头部注释Configdataclass 默认值TOML 文件路径来自CU_CONFIG环境变量或--configCU_FIELD_NAME环境变量CLI 的--set FIELDVALUE对应地有两条启用路径方式一单次运行用环境变量最短路径CU_ENABLE_ADVISOR_TOOLtrue python -m computer_use open Notes and type helloenable_advisor_tool默认是falsetrue会被自动转换为布尔值True。方式二写进 TOML 配置文件可复用把config.example.toml复制为config.toml取消注释并设置字段再用CU_CONFIG指向它# config.toml enable_advisor_tool true # advisor_model claude-opus-4-6 # advisor_max_conversation_uses 6# 在 .env 或 shell 中 CU_CONFIGconfig.toml python -m computer_use open Notes and type hello完整的可覆盖字段模板见 config.example.toml。相关配置项以下字段都在 constants.py 的Configdataclass 中声明默认值与说明以此为准字段默认值作用advisor_modelclaude-opus-4-6被咨询的 advisor 模型可通过CU_ADVISOR_MODEL覆盖advisor_max_usesNone不限单次请求内的调用上限非None时写入 API 参数max_usesadvisor_max_conversation_uses6整个会话的累计上限达到后循环会移除 advisor 工具声明并从历史中剥离其advisor_tool_result块——因为 API 对没有工具声明却残留 result 块的请求返回 400advisor_caching5madvisor 侧 prompt caching可选off/5m/1h文档说明在每会话约 3 次 advisor 调用时打平成本所以5m默认适合 agent 循环advisor_reminder_interval20连续多少轮没有 advisor 调用后往一个工具结果里追加一条提醒防止长任务中 executor 忘记这个工具设为None关闭启用后请求的tools数组会追加一个声明见 loop.py 的_advisor_tool_param{ type: advisor_20260301, name: advisor, model: cfg.advisor_model, # 非 None 时追加 max_usescaching ! off 时追加: # caching: {type: ephemeral, ttl: 5m} }同时会附带 beta 头advisor-tool-20260301并且系统提示词会追加一段 advisor 使用指南ADVISOR_PROMPT_ADDENDUMadvisor 不接受任何参数调用advisor()时整段会话历史自动转发建议在执行实质性操作前、认为任务完成时、卡住时、考虑换方案时调用。关闭时该段不会出现在系统提示词中这一点由 tests/test_advisor.py 的test_advisor_prompt_addendum_gated固化。运行与验证CU_ENABLE_ADVISOR_TOOLtrue python -m computer_use open Notes and type hello运行后按顺序在终端确认三处输出即可判断 advisor 链路是否真正工作调用发起executor 决定咨询时终端输出一行格式来自 render.py 的advisor_call→ advisor (consulting claude-opus-4-6…)建议返回结果以暗色文本渲染格式为← advisor: 建议文本截断到 400 字符如果 advisor 侧出错会打印← advisor error: error_code。advisor 结果块会在后续轮次原样回传所以后续轮次的工具结果中也可能携带 advisor 的历史结果。单独计费每轮末尾的[usage]行会为每次 advisor 调用追加一行格式见 loop.py 的_format_usage[usage] in... cache_read... cache_write... out... | cache_eff...% | 12.3s [usage] advisor(claude-opus-4-6) in... cache_read... out...出现第二行即说明 advisor 的 token 被独立统计这部分从 executor 的 token 中单独计费。如果长任务中 executor 一直不咨询检查是否命中了advisor_reminder_interval默认 20 轮的提醒机制连续多轮无调用后工具结果里会附一条reminder.../reminder文本常量ADVISOR_REMINDER下一轮 executor 应能看到。限制与已知行为README 明确标注这是Experimental功能not a general recommendation应在自己的工作负载上实测判断质量收益是否值得额外成本与延迟。该工具是本仓库唯一不在computer_use/tools/中定义的工具它完全运行在 Anthropic 服务端客户端没有对应的execute()demo 只负责声明、渲染和回传结果块。会话累计调用达到advisor_max_conversation_uses默认 6后advisor 会被移出tools声明历史中残留的server_tool_use/advisor_tool_result块被就地剥离同一会话内后续轮次不会再有 advisor 咨询。advisor 调用只走 first-party APIprovider anthropicVertex 与 Bedrock 上启用会在启动时抛ValueError无法通过配置绕过只能关掉开关或换 provider。终端中 advisor 建议文本截断到 400 字符只是展示层面的处理完整建议仍在回传给模型的消息里需要完整复盘时用轨迹查看器python -m streamlit run dev_ui/trajectory_viewer/app.py查看runs/timestamp/下的 JSONL transcript。【免费下载链接】claude-quickstartsA collection of projects designed to help developers quickly get started with building deployable applications using the Claude API项目地址: https://gitcode.com/GitHub_Trending/an/claude-quickstarts创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考