AgentSkillsCN

orchestration

多智能体编排的上下文管理与协同模式。在协调智能体团队、管理上下文预算、处理压缩操作,或调试编排问题时使用。

SKILL.md
--- frontmatter
name: orchestration
description: Context management and coordination patterns for multi-agent orchestration. Use when coordinating agent teams, managing context budgets, handling compaction, or debugging orchestration issues.

Orchestration Patterns Reference

This skill provides reference material for agent team orchestration. It supplements the /orchestrate command with detailed patterns.

Context Budget Management

Lead Orchestrator

  • Compact after every wave; always after 2+ waves
  • Write handoff to .claude/state/lead-handoff.md BEFORE compacting
  • Compact instruction: Preserve: orchestration plan, team roster, current wave, file ownership map, all ledger entries, blocker status
  • After compaction, immediately read your handoff note

Teammates

  • Compact every 3 tasks, or after 10+ file reads (the read-counter hook will warn you)
  • Write handoff to .claude/state/<your-name>-handoff.md BEFORE compacting
  • Compact instruction: Preserve: my tasks, file ownership, decisions from my handoff note
  • After compaction, immediately read your handoff note

Subagents

  • Disposable — no compaction needed
  • Return structured results only (use the scan/integration templates)

Structured Return Templates

Scan Results

code
SCAN RESULTS — [area investigated]
Relevant paths: [comma-separated file paths, no contents]
Key findings: [≤3 bullet points, one sentence each]
Risks/blockers: [≤2 bullet points, or "none"]

Integration Check

code
BUILD: [pass | fail — one-line error]
TESTS: [X passed, Y failed, Z skipped — failing test names]
IMPORTS: [pass | list of broken import paths]
TYPES: [pass | list of type mismatches]
BLOCKERS: [none | list of blocking issues]

Teammate Status File

code
## Status: working | blocked | done
## Context Pressure: low | mid | high
## Files Modified:
- path/to/file.ext (brief description)
## Current Task: <what you are working on now>
## Notes: <anything the lead or other teammates should know>

Single-Writer Ledger Pattern

The ledger (.claude/state/ledger.md) is maintained exclusively by the lead orchestrator. This prevents concurrent write corruption.

  • Lead: Writes to ledger.md. Reads teammate status files and aggregates them.
  • Teammates: Write to their own .claude/state/<name>-status.md. NEVER write to ledger.md.
  • Hooks: Write to .claude/state/compaction-events.log. NEVER write to ledger.md.

Worktree Path Rules

When working in a worktree:

  • All file operations must target files inside .worktrees/<name>/
  • The .claude/state/ directory is shared at the project root
  • Access shared state via ../../.claude/state/ (two levels up from worktree) or the absolute path
  • Your FIRST action after being spawned must be cd .worktrees/<name>/

Wave Execution Model

code
Wave 1 → Spawn all independent teammates in parallel
          ↓ Monitor status files for completion signals
Wave 2 → Spawn dependent teammates; include summaries from predecessor handoffs
          ↓ ...
Wave N → Final integration

Between waves, the lead:

  1. Reads all status files and compaction events
  2. Validates handoff compliance (handoff file exists for completed teammates)
  3. Checks for file-ownership violations
  4. Writes lead handoff and evaluates compaction need

Health States

StateSignalResponse
HealthyStatus file shows workingNo action
CompleteStatus shows doneCheck if next wave unblocked
BlockedStatus shows blockedRead notes, resolve, message
StalledNo status file or staleMessage → read handoff → respawn
Quality concernDone but handoff suspiciousSpawn review subagent

Max 2 retries per teammate. Then escalate to user.