2026-03-04-【大模型】openClaw编程员工

云端 openclaw 通过 nodes 配对本地 macos 的相关代码和步骤(ssh 反向隧道)

目标:让云端 OpenClaw Gateway 把「写代码 / 跑测试」这类命令下发到你桌面上的 macOS,本地复用已有的 IDE、浏览器和开发环境,同时云端只负责编排和消息入口。

一、前置条件

  1. 一台云服务器(推荐国外 VPS),已经可以通过 ssh user@gateway-host 登录。
  2. 本地一台 macOS,已安装好常用开发工具(git、Node.js、Python 等)。
  3. 两边都已安装 OpenClaw CLI(任一方式均可):
    • npm install -g openclaw
    • curl -fsSL https://openclaw.ai/install.sh | bash
    • brew install openclaw

二、在云服务器上启动 Gateway

  1. 在云服务器上初始化 OpenClaw:

    1
    openclaw onboard --install-daemon
  2. 启动 Gateway(默认监听 18789 端口):

    1
    openclaw gateway start
  3. 确认服务正常:

    1
    curl http://127.0.0.1:18789/health

    返回 ok 即表示 Gateway 已经就绪。

三、在本地 macOS 上建立 SSH 隧道

适用场景:云服务器的 18789 端口未直接暴露到公网,只能通过 SSH 访问。

  1. 在本地 macOS 上执行(将 user@gateway-host 换成你自己的云服务器账号):

    1
    ssh -N -L 18790:127.0.0.1:18789 user@gateway-host
    • 含义:把本地 127.0.0.1:18790 转发到云端 127.0.0.1:18789(Gateway)。
    • 建议用 tmuxscreen 长期挂着这条 SSH。
  2. 新开一个本地终端,导出 Gateway 访问凭证(按你自己的配置填写 token):

    1
    export OPENCLAW_GATEWAY_TOKEN="<your-gateway-token>"

四、在 macOS 上以 Node 方式接入 Gateway

  1. 在本地 macOS 上运行 Node 客户端,让云端 Gateway 把它识别为一台可调度的「编程员工机器」:

    1
    2
    3
    4
    openclaw node run \
    --host 127.0.0.1 \
    --port 18790 \
    --display-name "mac-dev-node"
  2. 回到云服务器,在 Gateway 所在机器上查看待审批的设备:

    1
    openclaw devices list
  3. 根据上一步输出的 requestId 执行审批:

    1
    openclaw devices approve <requestId>
  4. 审批后,你就可以在 OpenClaw 中看到这台 mac-dev-node,并把它配置为默认执行节点,用于:

    • 运行 exec / nodes 相关的系统命令
    • 打开本地浏览器 / 应用做 E2E 测试
    • 在本地仓库里拉代码、跑构建和测试

五、限制可执行命令(推荐)

为了安全,建议在 macOS 节点上只白名单少量命令,例如 gitnpmpnpmpytest 等。示例:

1
2
3
openclaw approvals allowlist add \
--command "npm test" \
--node "mac-dev-node"

这样可以避免 Agent 在本机上执行危险命令。

team-tasks 多 agent

  1. team-tasks 线性流水线:按固定顺序(编写代码 code-agent -> 测试 test-agent -> 文档编写 docs-agent -> 审查 architect-agent 架构师)
  2. 依赖图并行:任务声明依赖关系,依赖满足后可并行派发多个 agent
  3. 多 agent 辩论(多阶段:初始立场、交叉评审、综合决策)

一、为每个角色创建独立 Agent

  1. 使用 OpenClaw 向导依次创建多名「编程员工」:

    1
    2
    3
    4
    openclaw agents add programmer   # 负责写代码
    openclaw agents add tester # 负责测试
    openclaw agents add docs # 负责文档
    openclaw agents add architect # 负责架构审查
  2. 在各自工作区中补充人设文件:

    • AGENTS.md:写清楚该角色的职责边界、输入输出格式。
    • SOUL.md:补充语气、风格、偏好的技术栈等。
  3. openclaw.json 里为不同 Agent 配置不同的工具权限,例如:

    • programmer:允许 execwriteapply_patch,并把默认 exec 节点指向上文的 mac-dev-node
    • tester:只允许 exec,主要运行 npm test / pytest 等命令。
    • docs:只允许 readbrowser
    • architect:允许 read + 少量 exec,强调审查和评估。

二、配置 team-tasks 线性流水线

以「代码 → 测试 → 文档 → 架构审查」为例,可以用 Lobster workflow 或自定义脚本表达一个确定性的流水线,这里给出一个接近实战的思路:

  1. 新建一个 dev-pipeline.lobster(示意):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    name: dev-pipeline
    args:
    project: {}
    task: {}

    steps:
    - id: code
    command: >
    openclaw.invoke --tool agent-send --args-json '{
    "agentId": "programmer",
    "message": "${task}",
    "sessionKey": "pipeline:${project}:programmer"
    }'

    - id: test
    command: >
    openclaw.invoke --tool agent-send --args-json '{
    "agentId": "tester",
    "message": "对刚才的改动跑完整测试",
    "sessionKey": "pipeline:${project}:tester"
    }'
    condition: $code.exitCode == 0

    - id: docs
    command: >
    openclaw.invoke --tool agent-send --args-json '{
    "agentId": "docs",
    "message": "为本次改动补充 README / 变更说明",
    "sessionKey": "pipeline:${project}:docs"
    }'
    condition: $test.exitCode == 0

    - id: review
    command: >
    openclaw.invoke --tool agent-send --args-json '{
    "agentId": "architect",
    "message": "请审查这次改动的设计和风险",
    "sessionKey": "pipeline:${project}:architect"
    }'
    condition: $docs.exitCode == 0
  2. 触发时,只要执行一条命令即可:

    1
    2
    3
    openclaw lobster run dev-pipeline.lobster \
    --arg project=demo-repo \
    --arg task="实现用户登录功能"
  3. 整个过程是确定性的:每一步是否继续由 exitCode / JSON 字段来判断,而不是由 LLM 在 prompt 里“自己记着”。

三、依赖图并行 & 多 Agent 辩论

在上面的基础上,可以逐步进阶:

  • 依赖图并行
    把任务拆成多个子任务(接口设计 / 前端页面 / 后端实现 / 文档),在 Lobster 的 steps 中为每个子任务声明依赖,所有依赖完成后再汇总到一个 architect 审查步骤,实现「能并行的并行,关键路径受控」。

  • 多 Agent 辩论
    为同一角色配置多名 Agent(例如两个不同风格的架构师),让 Lobster 依次调用 architect-aarchitect-b,最后再调用一个 llm-task 步骤汇总双方意见,产出「最终裁决 + 争议点记录」,方便你事后 review。

  • PM 视角总控
    你自己以「PM」身份只需要查看最终的汇总输出(或 Telegram / 飞书通知),决定是采纳还是回滚,把高频体力活全部交给多 Agent 团队。


2026-03-04-【大模型】openClaw编程员工
https://zhangyingxuan.github.io/2026-03-04-【大模型】openClaw编程员工/
作者
blowsysun
许可协议