Skip to content

fix(agent-runtime): 修复开启电脑操作后 Agent 拿不到 Computer 工具 - #2483

Merged
vastsa merged 1 commit into
vastsa:mainfrom
zszz3:fix/sidecar-computer-use-flag
Nov 21, 2026
Merged

vastsa merged 1 commit into
vastsa:mainfrom
zszz3:fix/sidecar-computer-use-flag

Conversation

@zszz3

@zszz3 zszz3 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

问题

#2468:在设置里打开了电脑操作(Computer use),并配置了操作模型,但在 Agent 会话里看不到 Computer 工具。用 ToolSearch 精确搜索 Computer,返回的是 No matching on-demand tool。

原因

Electron 主进程在 Agent 会话、且电脑操作开关打开时,会给 sidecar 传 computerUseEnabled: true(apps/desktop/electron/main/runtime/session-launch.ts)。DesktopAgentRuntime 也是按这个值决定要不要提供 Computer 工具。

但 packages/agent-runtime/src/sidecar.ts 里的 runtimeFor 没有把这个参数传下去,有两处遗漏:

  1. 没有传给 DesktopAgentRuntime,所以运行时一直当作开关是关着的,Computer 不会进工具目录;
  2. 没有放进判断能否复用运行时的配置里,所以在同一个会话里切换开关后,还会继续用按旧值创建的运行时。

修复

在 runtimeFor 中补上 computerUseEnabled 的转发,传给运行时,同时放进复用比较的配置。只改了 4 行,审批、授权和窗口拒绝等安全检查都没有改。

测试

  • 新增 apps/desktop/test/sidecar-computer-use.test.mjs:启动真实的 sidecar,只模拟宿主和模型接口,检查发给模型的请求里有没有 Computer。覆盖四种情况:一开始就打开、一开始就关闭、从关到开、从开到关。不带修复时测试失败,带修复后通过。
  • E2E 测试:启动完整应用(Electron 主进程、渲染进程、host-core、sidecar),只模拟模型接口。打开电脑操作后,ToolSearch 能找到 Computer;在同一个会话里关闭后,Computer 不再提供;再次打开后又恢复。不带修复时失败,失败信息和 issue 报告的一致。
  • 真实桌面测试:在完整应用里打开电脑操作,Agent 调用 Computer 并经过审批后,通过系统辅助功能在 TextEdit 新建的文档里输入了指定文字;之后读出文档内容核对,结果一致。不带修复时,ToolSearch 返回 No matching on-demand tool,Computer 没有被调用。
  • @pi-desktop/agent-runtime 单元测试;agent-runtime 和 desktop 的 typecheck;lint;architecture 检查;pnpm check:pr-base。

fixes #2468

…ntime

Electron main already sends computerUseEnabled for Agent sessions with
computer use switched on, and DesktopAgentRuntime gates the Computer tool
on it, but the sidecar's runtimeFor dropped the flag. The runtime always
saw it as off, so Computer never reached the tool catalog and ToolSearch
answered "No matching on-demand tool".

Forward the flag into the runtime and into the reuse config, so turning
the switch on or off retires a runtime built under the old value.

fixes vastsa#2468

@aiuo-codepilot aiuo-codepilot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AIUO CodePilot · Preliminary review

Diff-only preliminary review: the change forwards `computerUseEnabled` from `runtimeFor` into `DesktopAgentRuntime` and includes it in the reuse comparison, plus a sidecar integration test. No evidenced defects found in the added lines. I could not run the sidecar test, typecheck, or inspect surrounding code; verification is limited to the supplied patch and does not confirm the DesktopAgentRuntime option name or RPC parameter match.

No evidenced findings in the supplied diff.

Head: 107e238
Base: 48a6558
CI: success; mergeable: true.

Validation: code/tests NOT EXECUTED. Diff-only preliminary analysis; not approval. Human review and repository gates remain required.

@vastsa
vastsa merged commit e0708da into vastsa:main Nov 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 0.23.0 开启电脑操作后 Computer 工具仍缺失:运行时工厂漏传 computerUseEnabled

2 participants