廣播群組

狀態: 實驗性 版本: 於 2026.1.9 新增

概覽

廣播群組讓多個代理能夠同時處理並回應同一則訊息。你可以建立專責的代理團隊,在單一 WhatsApp 群組或 DM 中協同工作,且全部使用同一個電話號碼。

目前範圍:僅限 WhatsApp(Web 頻道)。

廣播群組會在頻道允許名單和群組啟用規則之後才評估。在 WhatsApp 群組中,這表示廣播會在 OpenClaw 正常回覆時觸發(例如:根據你的群組設定,在被提及時)。

使用情境

1. 專責代理團隊

部署多個具有明確、專注職責的代理:

Group: "Development Team"
Agents:
  - CodeReviewer (reviews code snippets)
  - DocumentationBot (generates docs)
  - SecurityAuditor (checks for vulnerabilities)
  - TestGenerator (suggests test cases)

每個代理處理相同的訊息,並提供其專業觀點。

2. 多語言支援

Group: "International Support"
Agents:
  - Agent_EN (responds in English)
  - Agent_DE (responds in German)
  - Agent_ES (responds in Spanish)

3. 品質保證工作流程

Group: "Customer Support"
Agents:
  - SupportAgent (provides answer)
  - QAAgent (reviews quality, only responds if issues found)

4. 任務自動化

Group: "Project Management"
Agents:
  - TaskTracker (updates task database)
  - TimeLogger (logs time spent)
  - ReportGenerator (creates summaries)

設定

基本設定

在最上層新增 broadcast 區段(與 bindings 同層)。鍵為 WhatsApp peer ID:

  • 群組聊天:群組 JID(例如 [email protected]
  • DM:E.164 電話號碼(例如 +15551234567
{
  "broadcast": {
    "[email protected]": ["alfred", "baerbel", "assistant3"]
  }
}

效果: 當 OpenClaw 在這個聊天中回覆時,會執行全部三個代理。

處理策略

控制代理如何處理訊息:

並行(預設)

所有代理同時處理:

{
  "broadcast": {
    "strategy": "parallel",
    "[email protected]": ["alfred", "baerbel"]
  }
}

循序

代理依序處理(每個等前一個完成):

{
  "broadcast": {
    "strategy": "sequential",
    "[email protected]": ["alfred", "baerbel"]
  }
}

完整範例

{
  "agents": {
    "list": [
      {
        "id": "code-reviewer",
        "name": "Code Reviewer",
        "workspace": "/path/to/code-reviewer",
        "sandbox": { "mode": "all" }
      },
      {
        "id": "security-auditor",
        "name": "Security Auditor",
        "workspace": "/path/to/security-auditor",
        "sandbox": { "mode": "all" }
      },
      {
        "id": "docs-generator",
        "name": "Documentation Generator",
        "workspace": "/path/to/docs-generator",
        "sandbox": { "mode": "all" }
      }
    ]
  },
  "broadcast": {
    "strategy": "parallel",
    "[email protected]": ["code-reviewer", "security-auditor", "docs-generator"],
    "[email protected]": ["support-en", "support-de"],
    "+15555550123": ["assistant", "logger"]
  }
}

運作原理

訊息流程

  1. 收到訊息進入 WhatsApp 群組
  2. 廣播檢查:系統檢查 peer ID 是否在 broadcast
  3. 若在廣播名單中
    • 所有列出的代理處理該訊息
    • 每個代理有自己的 session key 和隔離的上下文
    • 代理以並行(預設)或循序方式處理
  4. 若不在廣播名單中
    • 套用正常路由(第一個匹配的 binding)

注意:廣播群組不會繞過頻道允許名單或群組啟用規則(提及/指令等)。它們只改變在訊息有資格被處理時_由哪些代理執行_。

工作階段隔離

廣播群組中的每個代理維持完全獨立的:

  • Session keyagent:alfred:whatsapp:group:120363... vs agent:baerbel:whatsapp:group:120363...
  • 對話歷史(代理看不到其他代理的訊息)
  • 工作區(如有設定,使用獨立的沙盒)
  • 工具存取權(不同的允許/拒絕清單)
  • 記憶/上下文(獨立的 IDENTITY.md、SOUL.md 等)
  • 群組上下文緩衝區(用作上下文的近期群組訊息)按 peer 共享,因此所有廣播代理在觸發時看到相同的上下文

這讓每個代理可以擁有:

  • 不同的性格
  • 不同的工具存取權(例如唯讀 vs. 讀寫)
  • 不同的模型(例如 opus vs. sonnet)
  • 不同的已安裝技能

範例:隔離的工作階段

在群組 [email protected] 中有代理 ["alfred", "baerbel"]

Alfred 的上下文:

Session: agent:alfred:whatsapp:group:[email protected]
History: [user message, alfred's previous responses]
Workspace: /Users/pascal/openclaw-alfred/
Tools: read, write, exec

Baerbel 的上下文:

Session: agent:baerbel:whatsapp:group:[email protected]
History: [user message, baerbel's previous responses]
Workspace: /Users/pascal/openclaw-baerbel/
Tools: read only

最佳實務

1. 保持代理專注

設計每個代理時賦予單一、明確的職責:

{
  "broadcast": {
    "DEV_GROUP": ["formatter", "linter", "tester"]
  }
}

好的做法: 每個代理負責一件事 ❌ 不好的做法: 一個通用的「dev-helper」代理

2. 使用描述性名稱

讓每個代理的功能一目了然:

{
  "agents": {
    "security-scanner": { "name": "Security Scanner" },
    "code-formatter": { "name": "Code Formatter" },
    "test-generator": { "name": "Test Generator" }
  }
}

3. 設定不同的工具存取權

只給代理它們需要的工具:

{
  "agents": {
    "reviewer": {
      "tools": { "allow": ["read", "exec"] } // Read-only
    },
    "fixer": {
      "tools": { "allow": ["read", "write", "edit", "exec"] } // Read-write
    }
  }
}

4. 監控效能

當代理數量較多時,請考慮:

  • 使用 "strategy": "parallel"(預設)以提升速度
  • 將廣播群組限制在 5-10 個代理
  • 對較簡單的代理使用更快的模型

5. 優雅處理失敗

代理獨立失敗。一個代理的錯誤不會阻擋其他代理:

Message → [Agent A ✓, Agent B ✗ error, Agent C ✓]
Result: Agent A and C respond, Agent B logs error

相容性

提供者

廣播群組目前支援:

  • ✅ WhatsApp(已實作)
  • 🚧 Telegram(規劃中)
  • 🚧 Discord(規劃中)
  • 🚧 Slack(規劃中)

路由

廣播群組與現有路由並行運作:

{
  "bindings": [
    {
      "match": { "channel": "whatsapp", "peer": { "kind": "group", "id": "GROUP_A" } },
      "agentId": "alfred"
    }
  ],
  "broadcast": {
    "GROUP_B": ["agent1", "agent2"]
  }
}
  • GROUP_A:只有 alfred 回應(正常路由)
  • GROUP_B:agent1 和 agent2 都回應(廣播)

優先順序: broadcast 優先於 bindings

疑難排解

代理沒有回應

檢查:

  1. 代理 ID 存在於 agents.list
  2. Peer ID 格式正確(例如 [email protected]
  3. 代理不在拒絕清單中

除錯:

tail -f ~/.openclaw/logs/gateway.log | grep broadcast

只有一個代理回應

原因: Peer ID 可能在 bindings 中但不在 broadcast 中。

解法: 將其加入 broadcast 設定,或從 bindings 中移除。

效能問題

如果代理太多導致速度慢:

  • 減少每個群組的代理數量
  • 使用較輕量的模型(sonnet 而非 opus)
  • 檢查沙盒啟動時間

範例

範例 1:程式碼審查團隊

{
  "broadcast": {
    "strategy": "parallel",
    "[email protected]": [
      "code-formatter",
      "security-scanner",
      "test-coverage",
      "docs-checker"
    ]
  },
  "agents": {
    "list": [
      {
        "id": "code-formatter",
        "workspace": "~/agents/formatter",
        "tools": { "allow": ["read", "write"] }
      },
      {
        "id": "security-scanner",
        "workspace": "~/agents/security",
        "tools": { "allow": ["read", "exec"] }
      },
      {
        "id": "test-coverage",
        "workspace": "~/agents/testing",
        "tools": { "allow": ["read", "exec"] }
      },
      { "id": "docs-checker", "workspace": "~/agents/docs", "tools": { "allow": ["read"] } }
    ]
  }
}

使用者傳送: 程式碼片段 回應:

  • code-formatter:「已修正縮排並新增型別提示」
  • security-scanner:「⚠️ 第 12 行有 SQL 注入漏洞」
  • test-coverage:「覆蓋率 45%,缺少錯誤情境的測試」
  • docs-checker:「函式 process_data 缺少 docstring」

範例 2:多語言支援

{
  "broadcast": {
    "strategy": "sequential",
    "+15555550123": ["detect-language", "translator-en", "translator-de"]
  },
  "agents": {
    "list": [
      { "id": "detect-language", "workspace": "~/agents/lang-detect" },
      { "id": "translator-en", "workspace": "~/agents/translate-en" },
      { "id": "translator-de", "workspace": "~/agents/translate-de" }
    ]
  }
}

API 參考

設定結構

interface OpenClawConfig {
  broadcast?: {
    strategy?: "parallel" | "sequential";
    [peerId: string]: string[];
  };
}

欄位

  • strategy(選填):如何處理代理
    • "parallel"(預設):所有代理同時處理
    • "sequential":代理依陣列順序處理
  • [peerId]:WhatsApp 群組 JID、E.164 號碼或其他 peer ID
    • 值:應處理訊息的代理 ID 陣列

限制

  1. 最大代理數: 無硬性限制,但 10 個以上可能會較慢
  2. 共享上下文: 代理看不到彼此的回應(設計如此)
  3. 訊息排序: 並行回應可能以任意順序到達
  4. 速率限制: 所有代理計入 WhatsApp 速率限制

未來增強

規劃中的功能:

  • 共享上下文模式(代理可看到彼此的回應)
  • 代理協調(代理可互相發送信號)
  • 動態代理選擇(根據訊息內容選擇代理)
  • 代理優先順序(某些代理先回應)

另請參閱