huashu-agent-swarm

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Infinite Agent Loop - 无限Agent蜂群模式

Infinite Agent Loop - Infinite Agent Swarm Mode

受Nicholas Carlini用16个Claude实例自主构建C编译器的启发。 没有master agent,纯git自组织,每个agent独立认领任务、写代码、推送。
Inspired by Nicholas Carlini using 16 Claude instances to independently build a C compiler. No master agent, pure Git self-organization, each agent independently claims tasks, writes code, and pushes.

触发条件

Trigger Conditions

当用户提到「蜂群模式」「多agent并行」「infinite loop」「agent swarm」「启动蜂群」时使用此技能。
Use this skill when users mention "swarm mode", "multi-agent parallel", "infinite loop", "agent swarm", "start swarm".

前置要求

Prerequisites

  • tmux(
    brew install tmux
  • claude CLI(已安装)
  • git 仓库(已有或新建)
  • tmux (
    brew install tmux
    )
  • claude CLI (installed)
  • Git repository (existing or newly created)

使用流程

Usage Process

Step 1: 描述项目

Step 1: Describe the Project

用户告诉我:
  • 项目目录路径(必须是git仓库)
  • 项目目标和总体描述
  • 初始任务列表(或让agent自行拆解)
  • agent数量(默认8个)
  • 代码规范和测试命令
Users tell me:
  • Project directory path (must be a Git repository)
  • Project goals and overall description
  • Initial task list (or let agents break down tasks automatically)
  • Number of agents (default: 8)
  • Code specifications and test commands

Step 2: 初始化项目

Step 2: Initialize the Project

bash
bash SKILL_DIR/scripts/setup_project.sh <项目目录>
这会在项目中创建:
  • AGENT_PROMPT.md
    - 从模板生成,需要我根据用户需求定制
  • TASKS.md
    - 初始任务清单
  • current_tasks/
    - 任务认领目录
  • agent_logs/
    - 日志目录
然后我根据
references/agent-prompt-template.md
定制
AGENT_PROMPT.md
,填入项目具体信息。
bash
bash SKILL_DIR/scripts/setup_project.sh <project directory>
This will create in the project:
  • AGENT_PROMPT.md
    - Generated from template, needs to be customized according to user requirements
  • TASKS.md
    - Initial task list
  • current_tasks/
    - Task claim directory
  • agent_logs/
    - Log directory
Then I customize
AGENT_PROMPT.md
based on
references/agent-prompt-template.md
, filling in specific project information.

Step 3: 启动蜂群

Step 3: Start the Swarm

bash
bash SKILL_DIR/scripts/start_swarm.sh <agent数量> <项目目录>
这会:
  1. 为每个agent创建 git worktree(共享.git对象库,不浪费磁盘)
  2. 创建 tmux session,每个pane一个agent
  3. 每个agent进入无限循环:pull → 认领任务 → 执行 → push → 下一个
bash
bash SKILL_DIR/scripts/start_swarm.sh <number of agents> <project directory>
This will:
  1. Create a git worktree for each agent (shares .git object library, no disk waste)
  2. Create a tmux session, one agent per pane
  3. Each agent enters an infinite loop: pull → claim task → execute → push → next

Step 4: 打开观测台

Step 4: Open the Dashboard

bash
python3 SKILL_DIR/scripts/dashboard.py <项目目录> 8420
  • 实时查看所有agent状态、git log、任务进度
  • 查看每个agent的最新日志
  • 输入框直接发送指令给agent(写入HUMAN_INPUT.md)
  • 一键停止所有agent
也可以用命令行监控:
bash
undefined
bash
python3 SKILL_DIR/scripts/dashboard.py <project directory> 8420
Open http://localhost:8420 in browser, you can:
  • View real-time status of all agents, git log, task progress
  • View the latest logs of each agent
  • Send instructions directly to agents via input box (writes to HUMAN_INPUT.md)
  • Stop all agents with one click
You can also monitor via command line:
bash
undefined

终端状态

Terminal status

bash SKILL_DIR/scripts/status.sh <项目目录>
bash SKILL_DIR/scripts/status.sh <project directory>

发送指令

Send instructions

bash SKILL_DIR/scripts/send_input.sh <项目目录> "你的指令"
bash SKILL_DIR/scripts/send_input.sh <project directory> "your instruction"

直接进入tmux观察

Directly enter tmux to observe

tmux attach -t swarm-<项目名>
undefined
tmux attach -t swarm-<project name>
undefined

Step 5: 停止

Step 5: Stop

bash
bash SKILL_DIR/scripts/stop_swarm.sh <项目目录>
自动停止所有agent + 合并分支 + 清理worktrees。
bash
bash SKILL_DIR/scripts/stop_swarm.sh <project directory>
Automatically stops all agents + merges branches + cleans up worktrees.

核心机制

Core Mechanisms

Git自组织协调

Git Self-Organization Coordination

  • 每个agent通过
    current_tasks/*.lock
    文件认领任务
  • 通过
    TASKS.md
    了解全局进度
  • 通过
    git log
    了解其他agent的工作
  • 冲突由agent自行解决
  • Each agent claims tasks via
    current_tasks/*.lock
    files
  • Understands global progress through
    TASKS.md
  • Learns about other agents' work through
    git log
  • Conflicts are resolved by agents themselves

Git Worktree隔离

Git Worktree Isolation

  • 不用多份clone,用
    git worktree
    实现隔离
  • 所有worktree共享同一个
    .git
    对象库
  • 每个agent在自己的worktree独立工作
  • No multiple clones, uses
    git worktree
    for isolation
  • All worktrees share the same
    .git
    object library
  • Each agent works independently in its own worktree

无限循环

Infinite Loop

  • 每个agent完成一个session后自动开始下一个
  • 通过
    git pull
    获取其他agent的最新成果
  • 通过 sleep 间隔避免API限流
  • Each agent automatically starts the next session after completing one
  • Gets the latest results from other agents via
    git pull
  • Uses sleep intervals to avoid API rate limits

关键配置

Key Configurations

参数默认值说明
agent数量8可在启动时指定
sleep间隔5秒agent_loop.sh中可调
模型claude-opus-4-6agent_loop.sh中可调
ParameterDefault ValueDescription
Number of agents8Specifiable at startup
Sleep interval5 secondsAdjustable in agent_loop.sh
Modelclaude-opus-4-6Adjustable in agent_loop.sh

风险和应对

Risks and Countermeasures

风险应对
API限流sleep间隔 + 可调agent数量
合并冲突AGENT_PROMPT指导小粒度commit
死循环无用功日志监控 + 停止条件
磁盘空间stop_swarm.sh自动清理
成本失控可在AGENT_PROMPT中限制session数

花叔出品 | AI Native Coder · 独立开发者 公众号「花叔」| 30万+粉丝 | AI工具与效率提升 代表作:小猫补光灯(AppStore付费榜Top1)·《一本书玩转DeepSeek》
RiskCountermeasure
API rate limitsSleep intervals + adjustable number of agents
Merge conflictsAGENT_PROMPT guides small-grained commits
Infinite loop of useless workLog monitoring + stop conditions
Disk space issuesstop_swarm.sh automatically cleans up
Uncontrolled costsLimit number of sessions in AGENT_PROMPT

Produced by Uncle Hua | AI Native Coder · Independent Developer Official Account "Uncle Hua" | 300,000+ followers | AI Tools & Efficiency Improvement Masterpieces: Kitten Fill Light (Top 1 in AppStore Paid Charts) · "Mastering DeepSeek in One Book"