Communitygithub.com

AgentHub — 多智能体协作

这是一个多智能体协作插件,可以生成 N 个并行子智能体,在独立的 Git worktree 中竞争完成同一任务。协调器评估结果并合并获胜分支。

AgentHub — 多智能体协作 是什么?

AgentHub 是一个面向开发者与 AI 代理(如 Claude Code、Cursor 等)的多智能体协作技能。它允许用户一次性启动 N 个并行的子代理,每个子代理在一个独立的 Git worktree 中工作,互不干扰。协调器(主会话)通过一组斜杠命令(如 `/hub:spawn`、`/hub:eval`、`/hub:merge`)来管理完整的生命周期:初始化会话、分派任务、监控进度、评估结果(通过指标或 LLM 评判)、合并最佳分支并归档其他分支。该技能特别适合需要并行尝试多种方案的场景,例如代码优化、内容变体生成、研究探索或 A/B 测试。它通过一个 DAG 模型追踪所有尝试,并使用一个消息白板系统实现协调器与代理间的异步通信。AgentHub 要求当前工作目录是一个 Git 仓库,并且依赖于项目中的几个 Python 脚本来执行深层的状态管理和评估逻辑。

兼容平台✓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 中运行评估命令,解析数值结果
  • 评判器模式:读取差异,由协调器根据质量排名
  • 混合模式:先看指标,指标相同时用 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 到代理数量)
  • 尝试 M:重试时递增(通常为 1)

前沿检测

前沿 = 没有子分支的分支提示。等同于 AgentHub 的 "leaves" 查询。

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

不可变性

DAG 仅支持追加:

  • 永远不要 rebase 或 force-push 代理分支
  • 永远不要删除提交(归档后仅删除分支引用)
  • 每次尝试都通过 git 标签保留

消息白板

位置:.agenthub/board/

通道

通道写入者读取者用途
dispatch/协调器代理任务分配
progress/代理协调器状态更新
results/代理 + 协调器所有人最终结果 + 合并摘要

发布格式

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

## 结果摘要

- **方法**:将 O(n²) 排序替换为哈希映射
- **更改的文件**:3
- **指标**:142ms(基准:180ms,差值:-38ms)
- **置信度**:高 — 所有测试通过

白板规则

  • 仅追加:永不编辑或删除帖子
  • 唯一文件名:{seq:03d}-{author}-{timestamp}.md
  • 所有帖子必须包含 YAML 前置元数据

评估模式

基于指标

最适合:基准测试、测试通过率、文件大小、响应时间。

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

排行器在每个代理的 worktree 目录中运行评估命令,并从标准输出中解析指标。

LLM 评判器

最适合:代码质量、可读性、架构决策。

协调器读取每个代理的差异(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 技能目录
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根据指标或差异质量对代理排名
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".

相关技能