Communitygithub.com

AgentHub — 多智能體協作

啟動 N 個並行 AI 子智能體,在隔離的 Git worktree 中競爭同一任務。協調器(Coordinator)評估結果並合併優勝者。

AgentHub — 多智能體協作 是什麼?

AgentHub 是一個專為 Claude Code 設計的多智能體協作技能。它允許使用者啟動 N 個並行子智能體,每個子智能體在獨立的 Git worktree 中隔離工作,針對相同任務嘗試不同方法。協調器(主 Claude Code 會話)會根據預先定義的指標或 LLM 評審來評估各智能體的結果,選出最佳方案並將其合併回主分支。此技能支援多種工作模板(例如優化器、重構器、測試撰寫者、除錯器),並提供完整的對話生命週期管理(初始化、發送、監控、評估、合併),非常適合程式碼優化、內容變體生成、研究探索等需要平行嘗試多種方法的場景。使用者可以通過斜杠命令(/hub:init、/hub:spawn、/hub:eval、/hub:merge 等)輕鬆控制整個流程,而子智能體之間則透過共享的訊息看板(Message Board)與協調器溝通,保持隔離與競賽的公平性。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/SamuelChien/mega-skills-collection/tree/HEAD/agenthub

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

AgentHub — 多智能體協作 是做什麼的?

啟動 N 個並行 AI 智能體,在相同任務上相互競爭。每個智能體在隔離的 Git worktree 中工作。協調器評估結果並合併優勝者。

斜杠命令

指令說明
/hub:init建立新的協作工作階段 — 任務、智能體數量、評估標準
/hub:spawn在隔離的 worktree 中啟動 N 個並行子智能體
/hub:status顯示 DAG 狀態、智能體進度、分支狀態
/hub:eval以指標或 LLM 評審對智能體結果進行排名
/hub:merge合併優勝分支,封存落敗分支
/hub:board讀取/寫入智能體訊息看板
/hub:run一次性生命週期:初始化 → 基準線 → 啟動 → 評估 → 合併

智能體模板

使用 --template 啟動時,智能體會遵循預定的迭代模式:

模板模式使用案例
optimizer編輯 → 評估 → 保留/捨棄 → 重複 x10效能、延遲、大小
refactorer重構 → 測試 → 迭代直到通過程式碼品質、技術債
test-writer撰寫測試 → 測量覆蓋率 → 重複測試覆蓋率缺口
bug-fixer重現 → 診斷 → 修復 → 驗證錯誤修復方法

模板定義在 references/agent-templates.md。

技能觸發時機

觸發短語:

  • "嘗試多種方法"
  • "讓智能體競爭"
  • "平行最佳化"
  • "啟動 N 個智能體"
  • "比較不同解決方案"
  • "分散出去" 或 "錦標賽"
  • "生成內容變體"
  • "比較不同草稿"
  • "A/B 測試文案"
  • "探索多種策略"

協調器協定

主 Claude Code 會話作為協調器。它遵循這個生命週期:

INIT → DISPATCH → MONITOR → EVALUATE → MERGE

1. 初始化

執行 /hub:init 建立工作階段。這會產生:

  • .agenthub/sessions/{session-id}/config.yaml — 任務配置
  • .agenthub/sessions/{session-id}/state.json — 狀態機
  • .agenthub/board/ — 訊息看板頻道

2. 發送

執行 /hub:spawn 啟動智能體。對於每個智能體 1..N:

  • 將任務指派發佈到 .agenthub/board/dispatch/
  • 透過 Agent 工具以 isolation: "worktree" 啟動
  • 所有智能體在單一訊息中啟動(平行)

3. 監控

執行 /hub:status 檢查進度:

  • dag_analyzer.py --status --session {id} 顯示分支狀態
  • 看板的 progress/ 頻道有智能體更新

4. 評估

執行 /hub:eval 對結果排名:

  • 指標模式:在每個 worktree 中執行評估命令,解析數值結果
  • 評審模式:讀取 diff,協調器根據品質排名
  • 混合模式:先看指標,平手時以 LLM 評審決定

5. 合併

執行 /hub:merge 完成:

  • git merge --no-ff 將優勝者合併到基礎分支
  • 標記落敗者:git tag hub/archive/{session}/agent-{i}
  • 清理 worktree
  • 將合併摘要發佈到看板

智能體協定

每個子智能體會收到以下提示模式:

你是 hub 工作階段 {session-id} 中的 agent-{i}。
你的任務:{任務描述}

指示:
1. 在 .agenthub/board/dispatch/{seq}-agent-{i}.md 閱讀你的指派任務
2. 在你的 worktree 中工作 — 進行變更、執行測試、迭代
3. 提交所有變更並附上描述性訊息
4. 將你的結果摘要寫入 .agenthub/board/results/agent-{i}-result.md
5. 完成後退出

智能體不會看到彼此的工作。它們不會互相通訊。它們只寫入看板供協調器讀取。

DAG 模型

分支命名

hub/{session-id}/agent-{N}/attempt-{M}
  • 工作階段 ID:基於時間戳記(YYYYMMDD-HHMMSS)
  • 智能體 N:依序(1 到 agent-count)
  • 嘗試 M:重試時遞增(通常為 1)

邊界偵測

邊界 = 沒有子分支的分支提示。等同於 AgentHub 的 "leaves" 查詢。

python scripts/dag_analyzer.py --frontier --session {id}

不可變性

DAG 是僅附加的:

  • 永遠不要 rebase 或 force-push 智能體分支
  • 永遠不要刪除提交(僅在封存後刪除分支參考)
  • 每種方法都透過 git tag 保留

訊息看板

位置:.agenthub/board/

頻道

頻道寫入者讀取者用途
dispatch/協調器智能體任務指派
progress/智能體協調器狀態更新
results/智能體 + 協調器所有人最終結果 + 合併摘要

文章格式

---
author: agent-1
timestamp: 2026-03-17T14:30:22Z
channel: results
parent: null
---

## 結果摘要

- **方法**:以 hash map 取代 O(n²) 排序
- **變更檔案數**:3
- **指標**:142ms(基準線:180ms,差異:-38ms)
- **信心度**:高 — 所有測試通過

看板規則

  • 僅附加:永遠不要編輯或刪除文章
  • 唯一檔名:{seq:03d}-{author}-{timestamp}.md
  • 所有文章都需要 YAML frontmatter

評估模式

基於指標

最適合:基準測試、測試通過率、檔案大小、回應時間。

python scripts/result_ranker.py --session {id} \
  --eval-cmd "pytest bench.py --json" \
  --metric p50_ms --direction lower

排名器會在每個智能體的 worktree 目錄中執行評估命令,並從 stdout 解析指標。

LLM 評審

最適合:程式碼品質、可讀性、架構決策。

協調器會讀取每個智能體的 diff(git diff base...agent-branch)並根據以下條件排名:

  1. 正確性(是否解決任務?)
  2. 簡潔性(更少的變更行數優先)
  3. 品質(乾淨的執行、良好的結構)

混合模式

先執行指標評估。如果排名頂尖的智能體結果相差在 10% 以內,則使用 LLM 評審來打破平手。

工作階段生命週期

init → running → evaluating → merged
                            → archived (若無優勝者)

狀態轉換由 session_manager.py 管理:

從到觸發條件
initrunning/hub:spawn 完成
runningevaluating所有智能體返回
evaluatingmerged/hub:merge 完成
evaluatingarchived無優勝者 / 全部失敗

主動觸發

協調器應在以下情況採取行動:

訊號動作
所有智能體崩潰張貼失敗摘要,建議以不同限制重試
相對於基準線無改進封存工作階段,建議不同方法
偵測到孤立 worktree執行 session_manager.py --cleanup {id}
工作階段卡在 running檢查看板進度,考慮超時

安裝

# 複製到你的 Claude Code skills 目錄
cp -r engineering/agenthub ~/.claude/skills/agenthub

# 或透過 ClawHub 安裝
clawhub install agenthub

指令稿

指令稿用途
hub_init.py初始化 .agenthub/ 結構和工作階段
dag_analyzer.py邊界偵測、DAG 圖形、分支狀態
board_manager.py訊息看板 CRUD(頻道、文章、討論串)
result_ranker.py以指標或 diff 品質對智能體排名
session_manager.py工作階段狀態機與清理

相關技能

  • autoresearch-agent — 單智能體最佳化迴圈(當你想要 N 個智能體競爭時,使用 AgentHub)
  • self-improving-agent — 自我修改智能體(當你想要外部競爭時,使用 AgentHub)
  • git-worktree-manager — Git worktree 工具(AgentHub 內部使用 worktree)

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

SamuelChien/mega-skills-collection

Security audit, hardening, threat modeling (STRIDE/PASTA), Red/Blue Team, OWASP checks, code review, incident response, and infrastructure security for any project.

SamuelChien/mega-skills-collection

Arquitecto de Soluciones Principal y Consultor Tecnológico de Andru.ia. Diagnostica y traza la hoja de ruta óptima para proyectos de IA en español.

SamuelChien/mega-skills-collection

Ingeniero de Sistemas de Andru.ia. Diseña, redacta y despliega nuevas habilidades (skills) dentro del repositorio siguiendo el Estándar de Diamante.

SamuelChien/mega-skills-collection

Estratega de Inteligencia de Dominio de Andru.ia. Analiza el nicho específico de un proyecto para inyectar conocimientos, regulaciones y estándares únicos del sector. Actívalo tras definir el nicho.

SamuelChien/mega-skills-collection

2D game development principles. Sprites, tilemaps, physics, camera.

SamuelChien/mega-skills-collection

3D game development principles. Rendering, shaders, physics, cameras.

SamuelChien/mega-skills-collection

Expert in building 3D experiences for the web - Three.js, React Three Fiber, Spline, WebGL, and interactive 3D scenes. Covers product configurators, 3D portfolios, immersive websites, and bringing depth to web experiences.

SamuelChien/mega-skills-collection

Accessibility audit skill for scanning, fixing, and verifying WCAG 2.2 Level A and AA compliance across React, Next.js, Vue, Angular, Svelte, and plain HTML codebases. Use when auditing accessibility, fixing a11y violations, checking color contrast, generating compliance reports, or integrating accessibility checks into CI/CD pipelines.

SamuelChien/mega-skills-collection

Ab Test Analyzer - Auto-activating skill for Data Analytics. Triggers on: ab test analyzer, ab test analyzer Part of the Data Analytics skill category.

SamuelChien/mega-skills-collection

A B Test Config Creator - Auto-activating skill for ML Deployment. Triggers on: a b test config creator, a b test config creator Part of the ML Deployment skill category.

SamuelChien/mega-skills-collection

When the user wants to plan, design, or implement an A/B test or experiment. Also use when the user mentions "A/B test," "split test," "experiment," "test this change," "variant copy," "multivariate test," "hypothesis," "conversion experiment," "statistical significance," or "test this." For tracking implementation, see analytics-tracking.

SamuelChien/mega-skills-collection

Acceptance Criteria Creator - Auto-activating skill for Enterprise Workflows. Triggers on: acceptance criteria creator, acceptance criteria creator Part of the Enterprise Workflows skill category.

SamuelChien/mega-skills-collection

Use when a coding task should be driven end-to-end from issue intake through implementation, review, deployment, and acceptance verification with minimal human re-intervention.

SamuelChien/mega-skills-collection

Accessibility Audit Runner - Auto-activating skill for Frontend Development. Triggers on: accessibility audit runner, accessibility audit runner Part of the Frontend Development skill category.

SamuelChien/mega-skills-collection

You are an accessibility expert specializing in WCAG compliance, inclusive design, and assistive technology compatibility. Conduct audits, identify barriers, and provide remediation guidance.

SamuelChien/mega-skills-collection

Web accessibility patterns for WCAG 2.2 compliance including ARIA, keyboard navigation, screen readers, and testing

SamuelChien/mega-skills-collection

Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed, or change policy for the Discord channel.

SamuelChien/mega-skills-collection

Create unified specification packages across Business, Development, and Design teams. Staged elaboration (L0 Vision → L1 Requirements → L2 Team Detail → L3 Acceptance Criteria) to build shared understanding. Does not write code.

SamuelChien/mega-skills-collection

Research a company or person and get actionable sales intel. Works standalone with web search, supercharged when you connect enrichment tools or your CRM. Trigger with "research [company]", "look up [person]", "intel on [prospect]", "who is [name] at [company]", or "tell me about [company]".

SamuelChien/mega-skills-collection

Validate messaging consistency across website, GitHub repos, and local documentation generating read-only discrepancy reports. Use when checking content alignment or finding mixed messaging. Trigger with phrases like "check consistency", "validate documentation", or "audit messaging".

相關技能