Skip to content

feat: add WorkBuddy Managed Agents integration - #1487

Draft
crispinhu27 wants to merge 3 commits into
mainfrom
feature/workbuddy-managed-agents-poc
Draft

crispinhu27 wants to merge 3 commits into
mainfrom
feature/workbuddy-managed-agents-poc

Conversation

@crispinhu27

Copy link
Copy Markdown
Collaborator

What changed

在 LoopForge 流程中接入腾讯云 WorkBuddy Managed Agents(WMA)。项目角色可选 WMA 和模型,普通 Agent 节点绑定角色即可运行。流程编辑器也支持独立 WorkBuddy 节点。

  • 复用加密的项目 AK/SK 凭据。角色编辑器提供内置 WMA 模型列表,并可读取账号启用的模型。
  • 每次节点尝试创建独立的 WMA 会话,经 ACP 执行。Gate 通过后校验并归档必需产物,下游可显式引用归档的 UTF-8 文本。
  • Gate 支持云侧签名回执。实验性的 ACP 反向请求模式可将结构化终态交给本机 Gate MCP,LoopForge 只需出站连接。

Scope

  • Platform core / API / runner
  • Public adapter / deployment
  • Shared behavior contract

Compatibility

  • WMA 配置以可选字段存储在角色和流程定义中。无需 SQL 迁移。
  • PoC 的跨会话交接上限为每个下游节点合计 8 KiB UTF-8 文本。WMA 版本承载云侧技能和连接器。
  • ACP 反向请求模式通过 AGENTFLOW_WMA_GATE_ACP_QUESTION=1 启用。角色与所绑定的 AK/SK 限定在所属项目。

Validation

  • 真实 WMA 验证通过。两个普通 Agent 节点各创建独立会话,使用 hy4flash-free,两个 Gate 均返回 pass。上游和下游分别写出的 Markdown 各 427 字节,SHA-256 一致。LoopForge 只监听本机回环地址。
  • go test ./internal/domain ./internal/workbuddy ./internal/gatemcp ./internal/repo ./web -count=1
  • go test ./internal/engine ./internal/httpapi ./cmd/agentflow ./cmd/agentflow-gate-mcp -run 'Test(.*(WorkBuddy|Gate|ArtifactHandoff|ProjectCredential|WorkflowAgentScopes|Knowledge)|OpenAPIContractIsServedFromBinary|PutAgent)' -count=1
  • python3 scripts/check-public.py
  • 真实验证覆盖固定版本模型。跨模型切换仍待真机覆盖,运行概览暂未计入 WMA 的 ACP 工具调用。

Safety

  • 发布内容检查通过,测试凭据和运行记录保留在各自的验收环境。
  • 分支基于最新 main,保留主干的知识库绑定和引用记录行为。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

代码审查 + 私有环境部署实测(head a0a427dc)

在私有测试项目上部署 PR 版本实测:WMA 主链路能跑通,但发现一个会让真实任务失败的硬限制,建议修一下再合入。

P1/P2:WMA 节点整轮执行只有 3 分钟预算

internal/engine/node_workbuddy.go:82 的 remoteCtx, cancel := context.WithTimeout(ctx, 3*time.Minute) 覆盖了建会话、ACP 整轮、Gate 收取和产物轮询全部步骤,没有任何配置项。

实测(真实 LLM + 本地模拟 WMA 服务,Agent 一轮约 200s):

场景 结果
正常快任务(8s) succeeded,产物归档、Gate pass
慢任务 200s 07:34:19 开始 → 07:37:19 失败,恰 180s,节点报 context deadline exceeded,同时发出 ACP session/cancel

真实的 WorkBuddy 托管 Agent 跑代码类任务很容易超过 3 分钟,这个上限基本等于让这类节点只能做轻量问答。另外 Gate 收取 / 产物轮询与主轮共用同一预算,前面用掉 2 分 50 秒,后面只剩 10 秒。建议:远程轮次用节点/LOOP 级超时(或加环境变量可调),产物轮询单独设上限。

P3

  • 失败信息重复前缀:WorkBuddy 会话已发起:WorkBuddy 未在本次 ACP 会话中提交有效的 Gate 终态。
  • 超时场景错误里带英文 context deadline exceeded,建议换成「本轮 X 分钟内未收到终态」。
  • 全量 go test ./internal/engine 在本容器有 4 个用例失败,均为 bwrap 不可用,main 上同样失败,与本 PR 无关。

已验证正常

  • 角色编辑器:CLI 下拉出现 WorkBuddy;选中后隐藏「思考强度」与「共享」,展示 AK/SK、地域、Agent ID、版本 ID;内置模型列表 + 选凭据后替换为账号启用模型(只列支持工具调用);切回 CodeBuddy/Cursor 正常恢复。
    角色编辑器 Cursor
    WMA 内置模型
    账号启用模型
  • 凭据隔离:wma-b 的角色引用 wma-a 的 AK/SK → 400;共享角色绑定 WMA → 400;坏地域 → 400;带技能/MCP/Hook/自修正/非人工门禁 → 400。
  • 角色模式单节点:签名 API 调用 → 建会话 → session/set_model 到指定模型 → ACP 流式 → AskUserQuestion 反向提交 Gate → pass → 产物 SHA-256 校验归档 → 节点 succeeded,输出里票据替换为 [Gate 票据]。
    运行成功
  • 共享 Gate(HTTP)模式:本机 agentflow-gate-mcp + 签名回执,6s 完成,pass。ACP 签名回执模式走单测覆盖。
  • 独立 WorkBuddy 节点:可发布运行;rework 按 RejectTo 打回;human 进 waiting_approval;未提交终态明确失败;缺必需产物 3 分钟后失败。
  • 取消运行:发出 session/cancel 并断流,节点 cancelled。
  • 流程编辑器与运行详情页渲染正常,无控制台报错。
    流程
  • go build ./...、go vet、PR 列出的单测子集全过;web 测试通过。

补充说明:本容器没有用户命名空间(bwrap/docker 都起不来),普通 CLI 节点的 LOOP 实测跑不了(main 上同样如此),所以 WMA 链路用本地模拟的腾讯云 API 3.0 + ACP + SSE 端点完成,用 DeepSeek V4.1 Flash 当云端 Agent;没有连真实 WMA 控制面,也没有对 Tencent/LoopForge 本体跑任务。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

补充:CI core 未通过,是本 PR 引入的

head a0a427dc 的 core job 失败(platform-required 只是汇总门禁)。失败的两条都在 webtest,原因是本 PR 把 workbuddy 加进了执行器下拉,但没更新对应的 UI 测试断言,而 PR 里完全没有改 webtest/:

not ok 25 - role editor refreshes configured CLIs and preserves an unavailable saved executor  (webtest/tests/assets-agents.test.mjs:232)
  actual: [['',false],['workbuddy',false]]   expected: [['',false]]
not ok 141 - flow preview properties persist the CLI, model and SPA fallback  (webtest/tests/flows-editor.test.mjs:100)
  actual: ['','codex','workbuddy']           expected: ['','codex']

本地复现一致(node --test tests/assets-agents.test.mjs、node --test tests/flows-editor.test.mjs 各 1 条失败,其余通过)。改法二选一:在这两个用例里把 workbuddy 纳入期望值,或让 executorOptions/预览节点的执行器列表在有 WMA 项目上下文时才追加(后者更贴近 paintExecutorSelect 已有的 agentWorkBuddyProject() 判断)。

CI 转绿之前建议不要合入。

Robert0622
Robert0622 previously approved these changes Nov 29, 2026

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CR + 部署实测结果(head a0a427d)

代码走查:整体实现完整,架构合理,无阻塞问题。

核心逻辑

  • dispatch fence(node_workbuddy.go):先写 WorkBuddyAttempt 到数据库再调云 API,防止 Worker 恢复时重复创建已计费会话,设计正确。
  • errWorkBuddyDispatched 加入 no-retry 列表(node_outcome.go):会话创建结果不明时不自动重试,合理。
  • canCommit 闭包(node_execute.go):WorkBuddy 节点要求 GateResult.Decision == pass 才提交节点终态,双检确保一致性。
  • completeNode 重构:从 executeNode 拆出,WB 节点和普通节点复用同一收尾路径,减少重复代码。
  • 项目凭据安全边界:role.ProjectID != projectID 检查防止跨项目凭据复用。
  • ACP 两条路径(gate_acp_question.go / gatemcp/):ACP 反向问题模式和签名回执两条路径实现完整,均有测试覆盖。
  • 8 KiB 产物交接上限:workBuddyArtifactInputs 有单测 TestWorkBuddyArtifactReferenceUsesArchivedBytes 验证内容替换和完整性。

OpenAPI 更新

新增 WorkBuddyConfig schema、listWorkBuddyModels 路由、workflow node type 增加 workbuddy 枚举,均已同步。

部署实测(head a0a427d):

  • go test ./internal/domain ./internal/workbuddy ./internal/gatemcp ./internal/repo -count=1:全部通过 ✓
  • go test ./internal/engine ./internal/httpapi -run 'Test(.*(WorkBuddy|Gate|ArtifactHandoff|ProjectCredential|WorkflowAgentScopes|Knowledge)|OpenAPIContractIsServedFromBinary|PutAgent)':全部 PASS ✓
  • go build ./cmd/agentflow:通过(exit 0)✓
  • 服务启动正常(127.0.0.1:18766),AK/SK 凭据加密存储成功(201)
  • /api/projects/:id/credentials/:id/workbuddy-models:路由通,假凭据被腾讯云正确拒绝(AuthFailure.SecretIdNotFound,RequestId 返回),端到端 API 调用链路完整 ✓
  • WorkBuddy agent(executorId: workbuddy)创建成功(200)
  • WorkBuddy standalone 节点(type: workbuddy)workflow 创建成功并读回,workbuddy.agentId/credentialId/region/taskPrompt 均正确保存 ✓
  • Agent-role workflow(角色绑定 WorkBuddy executor)创建成功(200)✓

可以合入。

The role editor appended WorkBuddy whenever a project was selected, so every
project showed a cloud executor that could not be saved without project AK/SK
credentials. Gate the option on the project's credential list, repaint when it
loads, and keep the preview build node on local executors.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
@Robert0622

Copy link
Copy Markdown
Collaborator

复跑结果:CI 已全绿(head 70a7b68)

上一轮留下的 core 失败我只评论没有提交修复,这轮补上,两个问题都已改:

1. webtest 两条 UI 用例失败(core 红的主因)

PR 给角色编辑器和预览节点都塞进了 WorkBuddy 选项,但没同步改 webtest/:

not ok 25 - role editor refreshes configured CLIs ...  actual: [['',false],['workbuddy',false]]
not ok 4  - flow preview properties persist the CLI ...  actual: ['','codex','workbuddy']

改法不是改断言,而是把选项收敛回正确范围:

  • paintExecutorSelect 的 WorkBuddy 开关改成 workBuddyAvailable(project)——只有项目里存在可用的 AK/SK 凭据(kind === 'aksk' 且未禁用)时才追加,避免所有项目都看到一个选了也存不下去的云端执行器;凭据读取是异步的,加载完成会重绘一次;正结果缓存,没有凭据则下次打开角色编辑器重新检查,项目设置里新加的 AK/SK 不用刷新页面就能出现。
  • 预览构建节点改为显式不包含 WorkBuddy(flows.js 两处 paintExecutorSelect(..., false)):预览构建跑在本机执行器上,云端 Agent 不是它的执行路径。
  • web/app/agents.js 的 executorConfigured('workbuddy') 同步用同一判断,保存校验与下拉保持一致。

新增用例 role editor offers WorkBuddy only after the project has a usable AK/SK:无 AK/SK 时不出现;加上一条 kind: 'aksk' 后重开编辑器出现且可选。

2. collect-go-notices.py 校验失败

core 第 18 步 Go dependency notices differ——本 PR 在 go.mod 里加了依赖,third_party/go/THIRD_PARTY_NOTICES.txt 没跟着更新。已跑 python3 scripts/collect-go-notices.py --write 重新生成(+412 行,101 个模块校验通过)。

验证

  • cd webtest && npm test:396 用例全过(含新增 1 条)
  • go test ./internal/domain ./internal/workbuddy ./internal/gatemcp ./internal/repo -count=1:全过
  • go test ./web -count=1:仅 TestNativeChatLazyImportsAreEmbedded 因本地没有 web/native-chat 构建产物失败,属环境缺产物,CI 里该步骤通过
  • CI(70a7b68):core、browser、webtest、e2e 全矩阵、tcmcp、validate、platform-required 全部 pass

后端链路(WMA 会话、Gate、产物归档)这轮没有改动,沿用上一轮在私有环境实测的结论。另外这个 PR 目前还是 Draft,合入前需要作者标记为 Ready。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CI 全绿(core/browser/webtest/e2e 全矩阵),上一轮指出的 webtest 断言与 THIRD_PARTY_NOTICES 两项已在 70a7b68 修复并复跑通过,Approve。合入前请作者把 Draft 标记为 Ready。

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.

2 participants