Production-grade Agent Harness combining execution discipline, knowledge compounding, and product thinking into a single adaptive workflow. Use when: (1) bui...
--- name: agent-harness description: "Production-grade Agent Harness combining execution discipline, knowledge compounding, and product thinking into a single adaptive workflow. Use when: (1) building features or fixing bugs with AI agents, (2) user says 'build', 'plan', 'spec', 'review', 'ship', 'debug', (3) managing multi-step or multi-agent tasks, (4) need structured engineering workflow with quality gates. Provides: task complexity auto-grading (simple/medium/complex), anti-rationalization guards, concurrent subagent scheduling (≤4 hard limit), tool-chain continuity enforcement, context budget management, verification protocols, and experience compounding. Triggers: 'agent harness', 'engineering workflow', 'build protocol', 'multi-agent task', 'coding discipline', 'subagent orchestration'." version: 2.0.1 --- # Agent Harness A unified engineering harness combining execution discipline, knowledge compounding, and product thinking. Born from ~450k characters of real-world AI textbook writing + 15+ production incidents. > **GAIA benchmark shows scaffold design = 30pp+ performance boost** — same model, HAL scaffold 74.6% vs bare model ~44%. The harness is the multiplier. ## Core Philosophy > Agent = Model + Harness. The model provides capability; the harness provides discipline. Three layers, one workflow: 1. **Challenge** — Is this the right thing to build? 2. **Execute** — Build it with engineering rigor 3. **Compound** — Learn from what happened ## Task Complexity Auto-Grading Before starting any task, assess complexity. This determines which workflow steps to run. **🟢 Simple** (bug fix, config change, small tweak) - Skip spec/plan → Direct edit → Verify → Done **🟡 Medium** (new feature, module, integration) - Plan → Build incrementally → Test → Review → Done **🔴 Complex** (architecture change, multi-module, new system) - Full pipeline: Challenge → Spec → Plan → Build → Test → Review → Ship When unsure, start at 🟡. Upgrade to 🔴 if you discover hidden complexity. Never downgrade mid-task. ## Layer 1: Challenge (🔴 Complex tasks only) Before writing any code, answer these questions: 1. **Problem validity** — Is the user solving a real problem? 2. **Simplest approach** — Is there a simpler way? 3. **Scope clarity** — Can you explain "done" in one sentence? 4. **Risk assessment** — What's the worst outcome if this goes wrong? Output: A one-paragraph problem statement the user confirms before proceeding. ## Layer 2: Execute ### Spec (🟡🔴 only) - **Goal**: One sentence describing the outcome - **Interface**: Inputs, outputs, API contracts - **Constraints**: What you will NOT do - **Acceptance criteria**: How to verify it works (must be testable) ### Plan (🟡🔴 only) Break the spec into atomic tasks: - Each task modifies ≤3 files - Each task has a clear verification step - Tasks ordered by dependency (independent tasks can parallelize) ### Build Execute tasks incrementally. After each task: 1. Verify the task works (run it, test it, check the output) 2. Checkpoint progress to file 3. Only then move to the next task **Critical rules:** - Never modify code you haven't read first - Don't add features beyond what was asked - Don't refactor "while you're at it" - If tests fail, report honestly — don't claim success ### Verify Every deliverable must have **evidence**, not just "looks good": | Deliverable type | Required evidence | |---|---| | Code change | Tests pass (show output) | | Config change | Restart + verify (show status) | | File generation | `wc -l` + `grep` key content | | API integration | Show actual response | | Documentation | Spot-check 3 claims for accuracy | 🔴 **Reading is not verification. Run it.** ### Review (🟡🔴 only) Self-review from 5 dimensions: 1. **Correctness** — Does it do what was asked? 2. **Edge cases** — Empty input, huge input, concurrent access? 3. **Security** — Injection points, leaked secrets, missing auth? 4. **Performance** — Will it work at 10x scale? 5. **Maintainability** — Will someone understand this in 6 months? ### Ship (🔴 only) Pre-ship checklist: - [ ] All tests pass - [ ] Rollback plan exists (undo in <5 min?) - [ ] Feature flag or gradual rollout if risky - [ ] Monitoring covers the new code path ## Layer 3: Compound After completing any task, spend 30 seconds on: 1. **What broke?** — Errors, retries, unexpected behavior? → Record the specific lesson 2. **What was slow?** — Bottlenecks? → Note them 3. **What would you do differently?** — Better approach with hindsight? Only record **specific, actionable lessons**. Not generic advice. **Good**: "Bedrock throttles at >4 concurrent requests. Use model rotation or serial execution." **Bad**: "Remember to handle API limits properly." ## Anti-Rationalization Table | Your excuse | Why it's wrong | Do this instead | |---|---|---| | "Too simple to need tests" | 40% of P0 incidents come from "too simple" code | Write the test. It takes 2 minutes. | | "I already checked, looks fine" | Reading ≠ verifying | Run it. `ls`, `wc -l`, `grep`, actual execution. | | "I'll write tests after the feature" | You won't. Test debt only grows. | Write the test NOW. | | "This old code looks unused, I'll delete it" | Chesterton's Fence: understand before removing | `git blame` first. Ask why it exists. | | "It should work" | "Should" is not evidence | Provide logs, output, or data. | | "Let me refactor while I'm here" | Scope creep. | File a separate TODO for the refactor. | | "I'll handle errors later" | Error handling IS the feature in production | Handle errors now. | | "The context is too long, I'll skip details" | Skipping details = skipping correctness | Checkpoint to file, compact context, continue with full fidelity. | | "I already ran it once, it should still work" | Stateful systems change. | Run it again. Every time. | ## Concurrent Subagent Scheduling **Hard limits:** - ≤4 subagents parallel (hard limit; check `subagents list` before spawning) - System hard ceiling: 8 - 5+? Re-slice into sequential batches first - Always check current count before spawning: `subagents(action=list)` **Task delegation rules:** - Instructions must be self-contained (paste content directly, don't reference files) - Each subagent writes to its own independent output file - Subagents never communicate directly — everything goes through coordinator - Use `sessions_yield` after spawning, not a poll loop **After yield returns — mandatory checks:** 1. `subagents(action=list)` — confirm all spawned subagents ended 2. `ls` output files — verify files exist with expected mtimes 3. If any subagent missing or no output file → investigate, don't assume success > Why: OpenClaw subagent completion announce has a known race condition. Never rely on announce as the sole signal. Active verification is the backup system. **Failure classification (before retrying):** - Design failure? → Fix the spec first - Alignment failure? → Clarify the instruction - Verification failure? → The work was done but not confirmed - See [references/mast-failure-taxonomy.md](references/mast-failure-taxonomy.md) for full taxonomy ## Tool-Chain Continuity (🔴 Critical) Every tool call return must be followed by one of: - Next tool call - Progress message to user - `sessions_yield` **Never**: respond with "I'll continue..." and then have no tool call. Pre-tool-return self-check: - [ ] Task complete? No → what's the next tool call? - [ ] Waiting for external input? → Send message explaining + yield - [ ] "Thinking about next step"? → Danger signal. Pick an action NOW. ## Context Budget Management | Water level | Mode | Action | |---|---|---| | < 70% | 🟢 Normal | Full mode, observation masking always on | | 70–85% | 🟡 Auto-Concise | No new large files, tool output truncated, subagent instructions <1500 chars | | 85–95% | 🟠 Preservation | No files >100 lines, force checkpoint to memory, delegate reads to subagent | | > 95% | 🔴 Emergency | Flush state, alert user to /reset, stop accepting new tasks | **Observation Masking** (apply immediately after consuming any tool output): - After reading a file and extracting conclusions: don't re-quote the raw content - After exec output: keep only key lines - After subagent delivery: extract deliverable + quality verdict, discard process noise ## Critical Safety Rules 🔫 **Never restart your own process from inside an agent turn.** - ❌ `systemctl restart <service>`, `pkill <process>`, `gateway restart` in cron prompts - ✅ Use the platform's safe restart tool (e.g., `gateway` tool's `restart` action) - Why: Agent terminal runs inside the gateway process. Restarting the service = SIGKILL yourself. 🔫🔫 **Never put restart commands in cron job prompts.** - once job + agent turn + restart = suicide loop: cron fires → agent runs → restart kills agent → turn never completes → scheduler sees incomplete once job → re-fires on next boot → infinite loop - Restart/self-check logic must live in an external wrapper (systemd ExecStartPost= or standalone systemd-run unit), completely outside the agent process. ## Verification Protocol For important deliverables, use an independent verifier: 1. Verifier does NOT read the original requirements 2. Verifier only reads the output/deliverable 3. Verifier independently assesses: correct? complete? well-formed? 4. Core principle: **"The implementer is an LLM. Reading is not verification. Run it."** ## Checkpoint Protocol Protect progress against crashes: 1. **Write to file after each step** — Don't accumulate results in memory 2. **Design tasks as idempotent** — Re-running produces the same result 3. **Only retry the failed step** — Don't restart from scratch 4. **Progress must be observable** — `ls` shows what's done, not model memory See [references/checkpoint-patterns.md](references/checkpoint-patterns.md) for detailed patterns. ## Known Tool Pitfalls - **`\n` literal in exec/write content**: In some platforms, multiline scripts passed as strings get `\n` treated as literal characters, not newlines. Always use real line breaks. Verify with `read` after writing. - **Concurrent writes**: Multiple subagents writing to the same file = corruption. Each subagent must have its own output file. - **Reading ≠ Verifying**: `grep` and `wc -l` are faster than `read` for verification. Use them. ## Quick Reference ``` 🟢 Simple: Edit → Verify → Done 🟡 Medium: Plan → Build → Test → Review → Done 🔴 Complex: Challenge → Spec → Plan → Build → Test → Review → Ship → Compound ``` After every tool call: next action or yield. Never stall.
don't have the plugin yet? install it then click "run inline in claude" again.
A unified engineering harness combining execution discipline, knowledge compounding, and product thinking. Born from ~450k characters of real-world AI textbook writing and 15+ production incidents.
GAIA benchmark shows scaffold design = 30pp+ performance boost. Same model, HAL scaffold 74.6% vs bare model ~44%. The harness is the multiplier.
Use this skill when building features, fixing bugs, planning specs, reviewing code, shipping changes, or debugging with AI agents. Triggers on "agent harness", "engineering workflow", "build protocol", "multi-agent task", "coding discipline", or "subagent orchestration". The harness wraps three layers (Challenge, Execute, Compound) around agent work to enforce correctness, prevent rationalization, and extract lessons from every task. Run this skill whenever you need structured engineering discipline with quality gates, especially for multi-step or multi-agent tasks.
Agent execution environment:
subagents list returns count and status)Task inputs:
External connections (if applicable):
AWS_BEDROCK_REGION, AWS_BEDROCK_MODEL_ID; rate limit: 4 concurrent requests max, use model rotation or serial fallback)GITHUB_TOKEN, scope: repo, read:org; auth expires, check before large operations)Context budget:
Input: User request + existing code (if any)
Output: Complexity level (🟢 simple, 🟡 medium, 🔴 complex) + reasoning
How to grade:
Decision: If unsure, pick 🟡. Upgrade to 🔴 during execution if you discover hidden dependencies. Never downgrade.
Next step: Go to Step 2.
Input: Task description, problem statement
Output: One-paragraph problem statement confirmed by user
Do this only if complexity = 🔴:
Answer these questions before any code:
Write a one-paragraph problem statement. Show it to the user. Wait for confirmation.
If user rejects: Stop, don't proceed. Refine the problem statement and re-submit.
If user confirms: Go to Step 3.
If complexity is 🟢 or 🟡: Skip this step, go to Step 3.
Input: Complexity level, problem statement (if 🔴), user request
Output: Spec document (written to spec.md or inline if <200 words)
Do this for 🟡 and 🔴:
Write a spec with four sections:
Show the spec to the user before proceeding.
If 🟢: Skip spec, go to Step 4 (Plan).
Next step: Go to Step 4.
Input: Spec, existing codebase
Output: Task list (written to plan.md)
Do this for 🟡 and 🔴:
Break the spec into atomic tasks:
Example format:
Task 1: [File] Create config schema
Changes: new file `config.schema.json`
Verify: `jq . < config.schema.json` (valid JSON)
Task 2: [Feature] Load config on startup
Changes: `app.py` lines 12-18
Verify: `python -m pytest tests/test_config.py -v` (pass)
Depends on: Task 1
Show the plan to the user. Refine if needed.
If 🟢: Skip plan, go to Step 5 (Build).
Next step: Go to Step 5.
Input: Plan (or task description if 🟢), codebase, spec (if written)
Output: Code changes, config changes, generated files
Critical rules:
For each task in the plan (or the single 🟢 task):
progress.md: "Task N complete. Changed files: X, Y, Z. Status: PASS.").If a task fails verification: Debug, fix, re-verify. Only mark PASS when verification succeeds.
Next step: Go to Step 6.
Input: Code change, config change, file, API response, or doc
Output: Evidence (test output, command output, grep results, response JSON)
Core rule: Reading is not verification. Run it.
| Deliverable type | Required evidence |
|---|---|
| Code change | Tests pass (show output, pytest -v or equivalent) |
| Config change | Restart + verify (show status, systemctl status or equivalent) |
| File generation | Line count + grep key content (wc -l, grep "keyword") |
| API integration | Show actual response (curl output, JSON, status code) |
| Documentation | Spot-check 3 claims for accuracy (e.g., "does the code actually do what the doc says?") |
For each deliverable:
Next step: If all tasks pass verification, go to Step 7. If any fail, debug and re-run Step 5-6 for that task.
Input: All code changes, all verification output
Output: Review summary (written to review.md)
Do this for 🟡 and 🔴:
Self-review from 5 dimensions:
For each dimension, pick one issue if you find one. Write it down with a fix (don't leave "TODO: think about this").
If 🟢: Skip review, go to Step 8.
Next step: Go to Step 8.
Input: All code changes, all verification output, review summary
Output: Deployment confirmation + rollback confirmation
Do this for 🔴 only:
Pre-ship checklist:
After checks pass:
If 🟢 or 🟡: Skip ship, go to Step 9.
Next step: Go to Step 9.
Input: What happened during the task (errors, retries, surprises, bottlenecks)
Output: Lesson recorded in lessons.md
After completing any task, spend 30 seconds on:
Record only specific, actionable lessons.
Good: "Bedrock throttles at >4 concurrent requests. Use model rotation or serial execution."
Bad: "Remember to handle API limits properly."
Write to lessons.md. If this is a lesson worth sharing, suggest it as a future skill refinement.
Task complete. Go to outcome signal section below.
If complexity is 🟢 (simple):
If complexity is 🟡 (medium):
If complexity is 🔴 (complex):
If user rejects the problem statement (Challenge step):
If a verification step fails:
If context budget exceeds 85%:
If context budget exceeds 95%:
/reset, stop accepting new tasks.If subagent count is at or near capacity (≤4 hard limit):
subagents list before spawning new subagents.If a task requires reading a large file and context is tight (70-85%):
grep and wc -l instead of read to extract key info.If tool call has no follow-up action:
Deliverables by complexity level:
progress.md with one entry: "Task complete. Changed files: X. Status: PASS."lessons.md if any surprises (optional).spec.md , Goal, Interface, Constraints, Acceptance criteria.plan.md , Numbered tasks, dependencies, verification steps.progress.md , One line per task: "Task N: [name]. Changed files: X, Y. Status: PASS."review.md , 5-dimension review summary (correctness, edge cases, security, performance, maintainability).lessons.md , Specific, actionable lessons.challenge.md , Problem statement (one paragraph).spec.md , Goal, Interface, Constraints, Acceptance criteria.plan.md , Numbered tasks with dependencies, verification steps.progress.md , One line per task.review.md , 5-dimension review.lessons.md , Specific, actionable lessons.File locations:
ls to confirm files exist.wc -l and grep to spot-check content.Data formats:
*.md).jq).Task is complete when:
lessons.md (or "no surprises" if genuinely clean run).User-facing signals:
progress.md shows all tasks with PASS status.Failure signal:
Reference this table whenever you feel the urge to skip a step or declare success without evidence.
| Your excuse | Why it's wrong | Do this instead |
|---|---|---|
| "Too simple to need tests" | 40% of P0 incidents come from "too simple" code. | Write the test. It takes 2 minutes. |
| "I already checked, looks fine" | Reading is not verifying. | Run it. ls, wc -l, grep, actual execution. |