Multi-agent workflow orchestrator for coding, writing, analysis, and image tasks via tmux-driven Claude Code and Codex agents. Use when: (1) user requests a feature/fix that should be delegated to coding agents, (2) managing parallel coding tasks across front-end and back-end, (3) monitoring active agent sessions and coordinating review, (4) user says 'start task', 'assign to agents', 'swarm mode', or references the ayao-workflow-agent playbook. NOT for: simple one-liner edits (just edit directly), reading code (use read tool), or single quick questions about code.
Coordinate multiple coding agents (Claude Code + Codex) via tmux sessions on a single machine. You are the orchestrator — you decompose tasks, write prompts, dispatch to agents, monitor progress, coordinate cross-review, and report results.
Every commit pushes immediately.git add -A && git commit -m "..." && git push
You decompose tasks, not the agent. Each prompt has explicit scope + file boundaries.
Cross-review. Codex output → cc-review. CC output → codex-review.
File-isolation parallelism. Different agents may run concurrently only if their file scopes don't overlap.
⚠️ ALWAYS use dispatch.sh — never exec directly. Any time you run Codex or Claude Code within a swarm project (active-tasks.json exists or task is swarm-related), dispatch via dispatch.sh. Never use the exec tool or coding-agent skill pattern directly. Reason: dispatch.sh is the only path that guarantees on-complete.sh fires → status updated → openclaw system event fired → orchestrator (AI) wakes and responds. Direct exec = silent failure, no notification, no status tracking.
⚠️ ORCHESTRATOR NEVER TOUCHES PROJECT FILES — NO EXCEPTIONS.
You are a pure orchestrator and auditor. Your role: understand requirements, write prompts, dispatch to agents, review agent output, coordinate next steps, notify human. Nothing else.
NEVER use edit / write / exec tools to modify anything inside the project directory. This includes:
~/.openclaw/workspace/memory/* (your own memory files)
Task size is NOT a criterion. Even a 1-line fix goes through cc-plan + codex. The question is always: "Does this touch the project directory?" → YES → dispatch to agent. Always.
Role Definition
text
You (orchestrator) = auditor + dispatcher, independent from the codebase
✅ Your job:
- Understand requirements, decompose into atomic tasks
- When plan is needed: write requirements (docs/requirements/), dispatch cc-plan for design (docs/design/), then decompose tasks yourself
- Write precise prompts for cc-plan / codex / cc-frontend
- Dispatch all work via dispatch.sh
- Review agent output (read git diff, check scope, assess quality)
- Coordinate reviews, unblock dependencies, dispatch next tasks
- Notify human of progress, issues, completions
- Maintain swarm config files (active-tasks.json, agent-pool.json)
❌ Never:
- Edit, write, or create files inside the project directory
- Run build / test / deploy commands on the project
- "Save time" by doing small tasks yourself
- Use exec tool to run code in the project repo
New Module / Standalone Feature Flow
When a new module or standalone feature is requested (e.g., backtest, new microservice):
text
1. cc-plan → outputs plan document (written to docs/<feature>-plan.md in project repo)
→ outputs task list (registered in active-tasks.json)
2. codex → creates new directory + implements per plan
3. You → review plan document + code output (read-only)
→ never touch the new directory yourself
Documentation Rules — Plan 三层规范
三层分工
Requirements: 永远由编排层整理和落地,用于明确需求边界、目标、非目标和验收标准
Design: 需要代码探索时由 cc-plan 产出;不需要代码探索时由编排层直接写
Plan / 任务拆解: 永远由编排层负责,因为编排层最了解 swarm 粒度、文件边界和 agent 分配
三档任务判断
档位
判断标准
需求文档
设计文档
负责方
A
一句话任务,目标和实现路径都清楚
不写
不写;prompt / 分析文件放 docs/swarm/
编排层
B
目标清楚,但实现方案仍需设计
不写
写到 docs/design/
设计由 cc-plan 或编排层负责;任务拆解始终由编排层负责
C
复杂或模糊,需求本身仍不确定
先写到 docs/requirements/
再写到 docs/design/
Requirements 和 Plan 由编排层负责;Design 由 cc-plan 或编排层负责
Generate prompt from template (references/prompt-codex.md or references/prompt-cc-frontend.md)
The current prompt templates include ## 认知模式, ## Completeness Principle, and ## Contributor Mode(任务完成后填写). Keep those sections intact when adapting a task prompt.
Prompt quality rules:
Reference actual code files (e.g. "参考 src/persistence/db.ts 的 getPool() 模式"), never describe tech stack in words
Pre-write the exact git commit -m "..." command, don't let agent choose
List specific file paths in scope, not directory names
In "Do NOT" section, list files likely to be accidentally modified
Preserve the four cognitive checks in the prompt: DRY Check, Boring by Default, Blast Radius Check, Two-Week Smell Test
State the Completeness Principle explicitly when scope includes paired docs/files, so the agent finishes every in-scope artifact before stopping
Keep ## Contributor Mode(任务完成后填写) at the end of the prompt and require the agent to include the field report in the commit message body: what was done, issues hit, and what was intentionally left out
For cc-plan tasks: if a project memory file exists at projects/<slug>/context.md, dispatch.sh automatically injects it into the prompt so the planning agent has project-specific background context.
Dispatch using the wrapper script (auto: marks running + attaches completion callback + force-commits if agent forgets):
bash
如需检查历史批次或其它任务文件,可追加 --task-file /path/to/tasks.json。
Legacy single-string commands are still accepted for backward compatibility, but new docs should always use argv + --prompt-file.
dispatch.sh automatically:
Validates TASK_ID against a whitelist regex (rejects injection payloads)
Updates active-tasks.json status to running (with tmux session written to task.tmux field); verifies tmux session exists before mark-running to avoid orphan states
Executes agent via quoted heredoc (<<'SCRIPT', no shell interpolation) with variables passed as env vars — eliminates code injection surface
Appends a force-commit check after agent finishes (catches forgotten commits); cleanup trap rolls back status to failed on unexpected exit
Calls on-complete.sh which updates status to done/failed + fires openclaw system event to wake orchestrator (AI)
Preserves the agent's Contributor Mode field report via the commit body, so the completion record explains what changed, what went wrong, and what was skipped
Parallel dispatch: OK if file scopes don't overlap. Check before dispatching.
Phase 5: Event-Driven Monitor
Primary (instant — event-driven):
post-commit hook — fires on every git commit. Writes signal + auto-pushes.
on-complete.sh — fires when agent command finishes. Does three things:
a. update-task-status.sh — atomically updates active-tasks.json (status + commit + auto-unblock dependents)
b. openclaw system event --text "Done: $TASK_ID" --mode now — wakes the main session orchestrator (AI)
c. openclaw message send — Telegram notification to human.
Current notification format is the upgraded "20 分钟前通知" style: task name, token usage (Xk), elapsed time, and a suggested next step. When the whole swarm completes, the final notification also includes total duration.
The orchestrator (AI main session), once woken by the event, is responsible for:
Verifying commit scope (reading git diff)
Dispatching cross-review (full level)
Dispatching the next pending task
"Event-driven" here means AI orchestrator responds to events — not unattended script automation.
Fallback (heartbeat): HEARTBEAT.md checks the signal file periodically as a safety net.
Dispatch task → Agent works → Agent commits → post-commit hook fires
→ on-complete.sh: update status + openclaw system event → Orchestrator wakes (AI)
→ Orchestrator: verify commit scope → dispatch cross-review
→ Review agent finishes → on-complete.sh: update status + openclaw system event → Orchestrator wakes (AI)
→ Orchestrator: check review result → Pass: mark done, unblock & dispatch next
→ Fail: return to original agent with feedback
→ All tasks done → Notify human
No polling. No manual check-ins. "Automatic" means AI orchestrator responds to openclaw system event — not unattended script automation. Human only intervenes on escalations.
Dispatch Notification Format
Every time an agent is dispatched (via dispatch.sh or coding-agent), report a Dispatch Card to the user.
Verbose Mode (default: ON)
Read via the config system: swarm-config.sh resolve notify.verbose_dispatch (falls back to true if unset). dispatch.sh uses this to choose compact vs verbose format automatically.
The following WARN-level issues were identified during the v1.6.0 security review and left as-is:
task-not-found vs race-protection share exit 2 — update-task-status.sh uses exit 2 for both "task not found in JSON" and "race-condition rollback". Could be split into exit 2 / exit 3 for finer-grained caller handling. Low impact: callers currently treat both as non-success.
generate-image.sh --output path not validated — The output path is used as-is without directory-traversal checks. An agent could write to an arbitrary path via --output ../../etc/foo. Low risk in practice (agents run sandboxed and output is ephemeral).
/tmp/agent-swarm-token-warned.json not batch-isolated — The token milestone de-dup file is global across batches. A warning suppressed in batch N stays suppressed in batch N+1. Workaround: manually delete the file between batches if milestone alerts are desired.
references/task-schema.md — active-tasks.json schema and status definitions
scripts/swarm-config.sh — Unified config reader/writer for swarm/config.json. Commands: get <dot.path>, set <dot.path> <value>, resolve <dot.path> (expands ${ENV_VAR} templates), project get <dot.path>. Write path uses flock + tmpfile + fsync + os.replace; fail-fast on write error (never clears config)
scripts/generate-image.sh — Generic image generation interface. Backends: nano-banana (Gemini), openai (DALL-E 3), stub (testing). Configured via swarm/config.jsonimage_generation.*. Backend whitelist validation + subprocess execution (no source); parameter validation with exit 1 on failure
scripts/dispatch.sh — Dispatch wrapper: TASK_ID whitelist validation + mark running (with tmux pre-check + cleanup trap rollback) + mark agent busy + tee output + quoted heredoc runner (no shell interpolation, env-var injection) + force-commit + on-complete callback. Reads notify.verbose_dispatch via swarm-config.sh; auto-injects projects/<slug>/context.md for cc-plan tasks
scripts/swarm-new-batch.sh — Archive current batch and create fresh active-tasks.json. Refuses to archive when running tasks exist (prevents late completions landing in new batch)
scripts/on-complete.sh — Completion callback: parse tokens + update status + mark agent idle + sync agent-pool.json liveness + trigger cleanup-agents.sh when all tasks finish + openclaw system event (wake orchestrator) + milestone alert + upgraded "20 分钟前通知" style notify. Reads notify.target via swarm-config.sh resolve (fallback: legacy notify-target file). Includes first 300 chars of commit body as Field Report in Telegram notification. Auto-appends retro record to projects/<slug>/retro.jsonl
scripts/update-task-status.sh — Atomically update task status in active-tasks.json (flock + tmpfile + fsync + os.replace). Features: auto-unblock dependents, task-not-found returns exit 2, heartbeat support (running→running updates task.updated_at)
scripts/update-agent-status.sh — Update a single agent's status in agent-pool.json (idle/busy/dead). Uses flock + tmpfile + fsync + os.replace for atomic writes
scripts/check-memory.sh — Check available RAM; ok/warn/block thresholds for manual capacity checks before adding more agent load
scripts/review-dashboard.sh — Pre-deploy readiness dashboard; precise depends_on reverse-lookup (no T1/T10 false matches). Exits 1 when unfinished full-reviews exist (release gate)
scripts/health-check.sh — Inspect all running agent sessions; detect stuck/dead agents, mark their tasks as failed via update-task-status.sh, notify, and run prompt-reference validation. Uses flock + atomic write for agent-pool.json
scripts/validate-prompts.sh — Scan prompt templates under references/ and verify every referenced scripts/*.sh path exists
scripts/cleanup-agents.sh — Kill all dynamic agent sessions after swarm completes; preserve fixed sessions. Uses flock + atomic write for agent-pool.json
Full design doc: ~/.openclaw/workspace/docs/ayao-workflow-agent-playbook.md