Cheat sheet · Module 12
Cheat sheet: Harness engineering
Generative AI · Cheat sheet · Harness engineering
Definition: Agent = model + harness. The harness is everything except the model: instructions, tools, infrastructure (filesystem, version control, sandbox), orchestration, enforcement (hooks, permissions, linters, tests) and observability. Harness engineering is designing that environment and improving it from observed failures.
Nested: prompt engineering (one call’s wording) sits inside context engineering (what the model sees now), which sits inside the harness (adds persistence, enforcement, orchestration and the improvement loop).
Arithmetic: n independent steps at per-step success p succeed with roughly p^n: 0.98^25 is about 0.60 and 0.99^40 is about 0.67. pass@k = 1 − (1 − p)^k and pass^k = p^k (p = 0.8, k = 5: about 0.9997 against 0.328). Cost per resolved task = attempt cost ÷ success rate. Steps before compaction = (threshold share × (window − output reserve) − fixed prompt) ÷ tokens per step.
Failure layers
| Layer | Symptom | Fix |
|---|---|---|
| Context | lacked the right information | retrieval, documents in the repo, tool output design |
| Constraint | acted outside its scope | permissions, sandbox, hooks, linters |
| Verification | wrong output went unchecked | tests, validators, a separate check, end-to-end checks |
| Planning | wrong approach, loops | decomposition, plan files, repeated-call detection |
Loop and tools
- The model proposes, the harness disposes. “No tool call” is a claim; verify it with tests, a schema or a required artefact.
- Stop controls: steps, budget, time, repeated-call detection, a verified exit, a human fallback.
- Errors are observations: what failed, why, what to try. Retry transient failures inside the harness; cap repair attempts.
- Tools: few, non-overlapping, hard to misuse, short readable output, read and write split, conditional edits. Fix tools, not prompts.
- Large output: keep head and tail, offload the rest to a file, redact first. Load tool definitions on demand.
- A shell is capable and risky: sandbox it. Replay after a crash is safe only with idempotent tools. Version tool schemas.
Context and long-running work
- Context rot: recall falls as the window fills. Cap outputs, clear old tool results, compact late and in one step.
- A compaction keeps the goal, constraints, decisions and reasons, open to-dos, files touched and the last error; it points to raw output instead.
- Across sessions: a feature list that starts failing, a progress file, version control, a startup routine with a smoke test, one feature per session.
- “Change only passes” in a prompt is not a lock; make the harness enforce it.
- Keep the instruction file a short map; knowledge the agent needs must live where it can read it; memory is scoped and fails closed.
Enforcement
- Guide (before) plus sensor (after). Computational checks first, inferential where meaning matters.
- Check early and cheaply; success silent, failure verbose and fixable.
- A prompt rule is a suggestion; a hook is a guarantee. Before-tool hooks can block; after-tool hooks cannot undo; a stop hook can refuse “done”.
- Tier permissions; limit both files and network in the sandbox; keep credentials out; fail closed.
- Lethal trifecta: private data, untrusted content, external communication. Remove one leg.
- The builder is not the only grader. Make success criteria hard to change. Behaviour is the hardest thing to check.
Orchestration
- Start with the simplest design that works. Subagents isolate context and cost extra tokens.
- Delegate with a contract: objective, constraints, tools, output format, stop condition. Pass artefacts, not transcripts. One owner per artefact.
- Separate builder and checker; route models by step; re-test routing on each new model.
- Parallel agents: a working copy per task, ownership by module, a queue, an integration step.
- People sit at intent, irreversible actions, escalations and the steering loop. Raise autonomy per action as evidence builds.
Evaluation and operations
- One change at a time, same held-out tasks, several trials, state-based grader. Read the transcripts.
- Loop: run, trace, classify by layer, structural fix, regression check, re-run, keep or revert.
- Re-baseline after a model upgrade; tie rules to failures; prune what you cannot justify; version the harness.
- Operate with checkpoints, budgets, a kill switch, rollback, safe degradation, a runbook; each incident ends in a new guide, sensor or hook.
- Gains reported in blog posts are claims to replicate on your own tasks.
A design answer in eight parts
Clarify · context · tools and environment · loop and state · enforcement · verification · orchestration · evaluation and operations. When a constraint changes, re-cost the design aloud and name the risk you accept.
Traps
Prompt-only guardrails · a giant instruction file · trusting “done” · writable tests · self-grading · multi-agent by default · uncapped tool output · copying a practice without its conditions · quoting a leaderboard gain as fact · confusing an evaluation harness with the agent harness.