AI创想

标题: OpenClaw 多代理协同工作模式配置指南 [打印本页]

作者: AI小编    时间: 6 天前
标题: OpenClaw 多代理协同工作模式配置指南
作者:由数入道
五、高级协同模式

1. Ping-Pong 交互模式

当需要代理间多轮对话时,sessions_send 自动支持 ping-pong 循环:
2. 使用 Lobster 实现确定性工作流

对于需要严格步骤控制和审批的场景,可以结合 Lobster 工具:
  1. # Lobster
  2. Lobster is a workflow shell that lets OpenClaw run multi-step tool sequences as a single, deterministic operation with explicit approval checkpoints.
  3. ## Hook
  4. Your assistant can build the tools that manage itself. Ask for a workflow,and 30 minutes later you have a CLI plus pipelines that run as one call. Lobster is the missing piece: deterministic pipelines, explicit approvals, and resumable state.
  5. ## Why
  6. Today, complex workflows require many back-and-forth tool calls. Each call costs tokens,and the LLM has to orchestrate every step. Lobster moves that orchestration into a typed runtime:-**Onecall instead of many**: OpenClaw runs one Lobster tool call and gets a structured result.
  7. -**Approvalsbuilt in**: Side effects (send email, post comment) halt the workflow until explicitly approved.
  8. -**Resumable**: Halted workflows return a token; approve and resume without re-running everything.
复制代码
3. 广播组用于专业团队

如果需要多个代理同时评审同一任务:
  1. {broadcast:{strategy:"parallel","+15555550123":["developer","tester","security-auditor"]}}
复制代码
所有代理会并行处理相同消息,各自提供专业视角。
六、最佳实践建议

1. 隔离性保障

2. 协同效率

3. 错误处理

Notes

关键配置要点:
OpenClaw 的这种架构设计使得代理既能保持完全独立(各自的工作空间、会话、权限),又能通过结构化的工具调用实现无缝协同,非常适合您描述的层级化任务委派场景。
Citations

File: /concepts/multi-agent.md
  1. An **agent** is a fully scoped brain with its own:
  2. - **Workspace** (files, AGENTS.md/SOUL.md/USER.md, local notes, persona rules).
  3. - **State directory** (`agentDir`) for auth profiles, model registry, and per-agent config.
  4. - **Session store** (chat history + routing state) under `~/.openclaw/agents/<agentId>/sessions`.
  5. Auth profiles are **per-agent**. Each agent reads from its own:
复制代码
~/.openclaw/agents//agent/auth-profiles.json
  1. Main agent credentials are **not** shared automatically. Never reuse `agentDir`
  2. across agents (it causes auth/session collisions). If you want to share creds,
  3. copy `auth-profiles.json` into the other agent's `agentDir`.
  4. Skills are per-agent via each workspace’s `skills/` folder, with shared skills
  5. available from `~/.openclaw/skills`. See [Skills: per-agent vs shared](/tools/skills#per-agent-vs-shared-skills).
复制代码
File: concepts/multi-agent.md
  1. `~/.openclaw/openclaw.json` (JSON5):
  2. ```js
  3. {
  4.   agents: {
  5.     list: [
  6.       {
  7.         id: "home",
  8.         default: true,
  9.         name: "Home",
  10.         workspace: "~/.openclaw/workspace-home",
  11.         agentDir: "~/.openclaw/agents/home/agent",
  12.       },
  13.       {
  14.         id: "work",
  15.         name: "Work",
  16.         workspace: "~/.openclaw/workspace-work",
  17.         agentDir: "~/.openclaw/agents/work/agent",
  18.       },
  19.     ],
  20.   },
  21.   // Deterministic routing: first match wins (most-specific first).
  22.   bindings: [
  23.     { agentId: "home", match: { channel: "whatsapp", accountId: "personal" } },
  24.     { agentId: "work", match: { channel: "whatsapp", accountId: "biz" } },
  25.     // Optional per-peer override (example: send a specific group to work agent).
  26.     {
  27.       agentId: "work",
  28.       match: {
  29.         channel: "whatsapp",
  30.         accountId: "personal",
  31.         peer: { kind: "group", id: "1203630...@g.us" },
  32.       },
  33.     },
  34.   ],
  35.   // Off by default: agent-to-agent messaging must be explicitly enabled + allowlisted.
  36.   tools: {
  37.     agentToAgent: {
  38.       enabled: false,
  39.       allow: ["home", "work"],
  40.     },
  41.   },
  42.   channels: {
  43.     whatsapp: {
  44.       accounts: {
  45.         personal: {
  46.           // Optional override. Default: ~/.openclaw/credentials/whatsapp/personal
  47.           // authDir: "~/.openclaw/credentials/whatsapp/personal",
  48.         },
  49.         biz: {
  50.           // Optional override. Default: ~/.openclaw/credentials/whatsapp/biz
  51.           // authDir: "~/.openclaw/credentials/whatsapp/biz",
  52.         },
  53.       },
  54.     },
  55.   },
  56. }
复制代码
File: concepts/multi-agent.md
  1. Starting with v2026.1.6, each agent can have its own sandbox and tool restrictions:
  2. ```js
  3. {
  4.   agents: {
  5.     list: [
  6.       {
  7.         id: "personal",
  8.         workspace: "~/.openclaw/workspace-personal",
  9.         sandbox: {
  10.           mode: "off",  // No sandbox for personal agent
  11.         },
  12.         // No tool restrictions - all tools available
  13.       },
  14.       {
  15.         id: "family",
  16.         workspace: "~/.openclaw/workspace-family",
  17.         sandbox: {
  18.           mode: "all",     // Always sandboxed
  19.           scope: "agent",  // One container per agent
  20.           docker: {
  21.             // Optional one-time setup after container creation
  22.             setupCommand: "apt-get update && apt-get install -y git curl",
  23.           },
  24.         },
  25.         tools: {
  26.           allow: ["read"],                    // Only read tool
  27.           deny: ["exec", "write", "edit", "apply_patch"],    // Deny others
  28.         },
  29.       },
  30.     ],
  31.   },
  32. }
  33. Note: `setupCommand` lives under `sandbox.docker` and runs once on container creation.
  34. Per-agent `sandbox.docker.*` overrides are ignored when the resolved scope is `"shared"`.
  35. **Benefits:**
  36. - **Security isolation**: Restrict tools for untrusted agents
  37. - **Resource control**: Sandbox specific agents while keeping others on host
  38. - **Flexible policies**: Different permissions per agent
  39. Note: `tools.elevated` is **global** and sender-based; it is not configurable per agent.
  40. If you need per-agent boundaries, use `agents.list[].tools` to deny `exec`.
  41. For group targeting, use `agents.list[].groupChat.mentionPatterns` so @mentions map cleanly to the intended agent.
  42. See [Multi-Agent Sandbox & Tools](/tools/multi-agent-sandbox-tools) for detailed examples.
复制代码
File: concepts/session-tool.md
  1. Fetch transcript for one session.
  2. Parameters:
  3. - `sessionKey` (required; accepts session key or `sessionId` from `sessions_list`)
  4. - `limit?: number` max messages (server clamps)
  5. - `includeTools?: boolean` (default false)
  6. Behavior:
  7. - `includeTools=false` filters `role: "toolResult"` messages.
  8. - Returns messages array in the raw transcript format.
  9. - When given a `sessionId`, OpenClaw resolves it to the corresponding session key (missing ids error).
复制代码
File: concepts/session-tool.md
  1. Send a message into another session.
  2. Parameters:
  3. - `sessionKey` (required; accepts session key or `sessionId` from `sessions_list`)
  4. - `message` (required)
  5. - `timeoutSeconds?: number` (default >0; 0 = fire-and-forget)
  6. Behavior:
  7. - `timeoutSeconds = 0`: enqueue and return `{ runId, status: "accepted" }`.
  8. - `timeoutSeconds > 0`: wait up to N seconds for completion, then return `{ runId, status: "ok", reply }`.
  9. - If wait times out: `{ runId, status: "timeout", error }`. Run continues; call `sessions_history` later.
  10. - If the run fails: `{ runId, status: "error", error }`.
  11. - Announce delivery runs after the primary run completes and is best-effort; `status: "ok"` does not guarantee the announce was delivered.
  12. - Waits via gateway `agent.wait` (server-side) so reconnects don't drop the wait.
  13. - Agent-to-agent message context is injected for the primary run.
  14. - After the primary run completes, OpenClaw runs a **reply-back loop**:
  15.   - Round 2+ alternates between requester and target agents.
  16.   - Reply exactly `REPLY_SKIP` to stop the ping‑pong.
  17.   - Max turns is `session.agentToAgent.maxPingPongTurns` (0–5, default 5).
  18. - Once the loop ends, OpenClaw runs the **agent‑to‑agent announce step** (target agent only):
  19.   - Reply exactly `ANNOUNCE_SKIP` to stay silent.
  20.   - Any other reply is sent to the target channel.
  21.   - Announce step includes the original request + round‑1 reply + latest ping‑pong reply.
复制代码
File: concepts/session-tool.md
  1. Behavior:
  2. - Starts a new `agent:<agentId>:subagent:<uuid>` session with `deliver: false`.
  3. - Sub-agents default to the full tool set **minus session tools** (configurable via `tools.subagents.tools`).
  4. - Sub-agents are not allowed to call `sessions_spawn` (no sub-agent → sub-agent spawning).
  5. - Always non-blocking: returns `{ status: "accepted", runId, childSessionKey }` immediately.
  6. - After completion, OpenClaw runs a sub-agent **announce step** and posts the result to the requester chat channel.
  7. - Reply exactly `ANNOUNCE_SKIP` during the announce step to stay silent.
  8. - Announce replies are normalized to `Status`/`Result`/`Notes`; `Status` comes from runtime outcome (not model text).
  9. - Sub-agent sessions are auto-archived after `agents.defaults.subagents.archiveAfterMinutes` (default: 60).
  10. - Announce replies include a stats line (runtime, tokens, sessionKey/sessionId, transcript path, and optional cost).
复制代码
File: tools/subagents.md
  1. # Sub-agents
  2. Sub-agents are background agent runs spawned from an existing agent run. They run in their own session (`agent:<agentId>:subagent:<uuid>`) and, when finished, **announce** their result back to the requester chat channel.
  3. ## Slash command
  4. Use `/subagents` to inspect or control sub-agent runs for the **current session**:
  5. - `/subagents list`
  6. - `/subagents stop <id|#|all>`
  7. - `/subagents log <id|#> [limit] [tools]`
  8. - `/subagents info <id|#>`
  9. - `/subagents send <id|#> <message>`
  10. `/subagents info` shows run metadata (status, timestamps, session id, transcript path, cleanup).
  11. Primary goals:
  12. - Parallelize “research / long task / slow tool” work without blocking the main run.
  13. - Keep sub-agents isolated by default (session separation + optional sandboxing).
  14. - Keep the tool surface hard to misuse: sub-agents do **not** get session tools by default.
  15. - Avoid nested fan-out: sub-agents cannot spawn sub-agents.
  16. Cost note: each sub-agent has its **own** context and token usage. For heavy or repetitive
  17. tasks, set a cheaper model for sub-agents and keep your main agent on a higher-quality model.
  18. You can configure this via `agents.defaults.subagents.model` or per-agent overrides.
复制代码
File: tools/subagents.md
  1. ## Tool
  2. Use `sessions_spawn`:
  3. - Starts a sub-agent run (`deliver: false`, global lane: `subagent`)
  4. - Then runs an announce step and posts the announce reply to the requester chat channel
  5. - Default model: inherits the caller unless you set `agents.defaults.subagents.model` (or per-agent `agents.list[].subagents.model`); an explicit `sessions_spawn.model` still wins.
  6. - Default thinking: inherits the caller unless you set `agents.defaults.subagents.thinking` (or per-agent `agents.list[].subagents.thinking`); an explicit `sessions_spawn.thinking` still wins.
  7. Tool params:
  8. - `task` (required)
  9. - `label?` (optional)
  10. - `agentId?` (optional; spawn under another agent id if allowed)
  11. - `model?` (optional; overrides the sub-agent model; invalid values are skipped and the sub-agent runs on the default model with a warning in the tool result)
  12. - `thinking?` (optional; overrides thinking level for the sub-agent run)
  13. - `runTimeoutSeconds?` (default `0`; when set, the sub-agent run is aborted after N seconds)
  14. - `cleanup?` (`delete|keep`, default `keep`)
复制代码
File: tools/subagents.md
  1. Allowlist:
  2. - `agents.list[].subagents.allowAgents`: list of agent ids that can be targeted via `agentId` (`["*"]` to allow any). Default: only the requester agent.
  3. Discovery:
  4. - Use `agents_list` to see which agent ids are currently allowed for `sessions_spawn`.
复制代码
File: tools/subagents.md
  1. Auto-archive:
  2. - Sub-agent sessions are automatically archived after `agents.defaults.subagents.archiveAfterMinutes` (default: 60).
  3. - Archive uses `sessions.delete` and renames the transcript to `*.deleted.<timestamp>` (same folder).
  4. - `cleanup: "delete"` archives immediately after announce (still keeps the transcript via rename).
  5. - Auto-archive is best-effort; pending timers are lost if the gateway restarts.
  6. - `runTimeoutSeconds` does **not** auto-archive; it only stops the run. The session remains until auto-archive.
复制代码
File: tools/subagents.md
  1. ## Announce
  2. Sub-agents report back via an announce step:
  3. - The announce step runs inside the sub-agent session (not the requester session).
  4. - If the sub-agent replies exactly `ANNOUNCE_SKIP`, nothing is posted.
  5. - Otherwise the announce reply is posted to the requester chat channel via a follow-up `agent` call (`deliver=true`).
  6. - Announce replies preserve thread/topic routing when available (Slack threads, Telegram topics, Matrix threads).
  7. - Announce messages are normalized to a stable template:
  8.   - `Status:` derived from the run outcome (`success`, `error`, `timeout`, or `unknown`).
  9.   - `Result:` the summary content from the announce step (or `(not available)` if missing).
  10.   - `Notes:` error details and other useful context.
  11. - `Status` is not inferred from model output; it comes from runtime outcome signals.
复制代码
File: channels/broadcast-groups.md
  1. ## Overview
  2. Broadcast Groups enable multiple agents to process and respond to the same message simultaneously. This allows you to create specialized agent teams that work together in a single WhatsApp group or DM — all using one phone number.
  3. Current scope: **WhatsApp only** (web channel).
  4. Broadcast groups are evaluated after channel allowlists and group activation rules. In WhatsApp groups, this means broadcasts happen when OpenClaw would normally reply (for example: on mention, depending on your group settings).
  5. ## Use Cases
  6. ### 1. Specialized Agent Teams
  7. Deploy multiple agents with atomic, focused responsibilities:
  8. Group: "Development Team"
  9. Agents:
  10.   - CodeReviewer (reviews code snippets)
  11.   - DocumentationBot (generates docs)
  12.   - SecurityAuditor (checks for vulnerabilities)
  13.   - TestGenerator (suggests test cases)
复制代码
File: channels/broadcast-groups.md
  1. ### Basic Setup
  2. Add a top-level `broadcast` section (next to `bindings`). Keys are WhatsApp peer ids:
  3. - group chats: group JID (e.g. `120363403215116621@g.us`)
  4. - DMs: E.164 phone number (e.g. `+15551234567`)
  5. ```json
  6. {
  7.   "broadcast": {
  8.     "120363403215116621@g.us": ["alfred", "baerbel", "assistant3"]
  9.   }
  10. }
  11. **Result:** When OpenClaw would reply in this chat, it will run all three agents.
复制代码
File: channels/broadcast-groups.md
  1. ### Session Isolation
  2. Each agent in a broadcast group maintains completely separate:
  3. - **Session keys** (`agent:alfred:whatsapp:group:120363...` vs `agent:baerbel:whatsapp:group:120363...`)
  4. - **Conversation history** (agent doesn't see other agents' messages)
  5. - **Workspace** (separate sandboxes if configured)
  6. - **Tool access** (different allow/deny lists)
  7. - **Memory/context** (separate IDENTITY.md, SOUL.md, etc.)
  8. - **Group context buffer** (recent group messages used for context) is shared per peer, so all broadcast agents see the same context when triggered
  9. This allows each agent to have:
  10. - Different personalities
  11. - Different tool access (e.g., read-only vs. read-write)
  12. - Different models (e.g., opus vs. sonnet)
  13. - Different skills installed
  14. ### Example: Isolated Sessions
复制代码
File: agents/tools/sessions-send-tool.ts
  1. const SessionsSendToolSchema = Type.Object({
  2.   sessionKey: Type.Optional(Type.String()),
  3.   label: Type.Optional(Type.String({ minLength:1, maxLength:SESSION_LABEL_MAX_LENGTH})),
  4.   agentId: Type.Optional(Type.String({ minLength:1, maxLength:64})),
  5.   message: Type.String(),
  6.   timeoutSeconds: Type.Optional(Type.Number({ minimum:0})),});
复制代码
File: tools/lobster.md
  1. # Lobster
  2. Lobster is a workflow shell that lets OpenClaw run multi-step tool sequences as a single, deterministic operation with explicit approval checkpoints.
  3. ## Hook
  4. Your assistant can build the tools that manage itself. Ask for a workflow, and 30 minutes later you have a CLI plus pipelines that run as one call. Lobster is the missing piece: deterministic pipelines, explicit approvals, and resumable state.
  5. ## Why
  6. Today, complex workflows require many back-and-forth tool calls. Each call costs tokens, and the LLM has to orchestrate every step. Lobster moves that orchestration into a typed runtime:
  7. - **One call instead of many**: OpenClaw runs one Lobster tool call and gets a structured result.
  8. - **Approvals built in**: Side effects (send email, post comment) halt the workflow until explicitly approved.
  9. - **Resumable**: Halted workflows return a token; approve and resume without re-running everything.
复制代码
原文地址:https://blog.csdn.net/cxr828/article/details/157825292




欢迎光临 AI创想 (https://llms-ai.com/) Powered by Discuz! X3.4