Thursday, December 3, 2026

Harness engineering


Harness engineering is the discipline of designing the systems, tools, constraints, and feedback loops wrapped around an AI model to make coding agents reliable at scale. Rather than swapping to a smarter model or tweaking a single prompt, it focuses on the environment the model operates in: Agent = Model + Harness

1. How It Differs from Prompt and Context Engineering

LayerScopeWhat It Controls
Prompt EngineeringSingle InteractionInstruction wording and formatting for one turn
Context EngineeringModel's context window across turnsToken selection, ordering, retrieval, and context compaction
Harness EngineeringEntire agent system across sessionsTool orchestration, state/memory persistence, deterministic verification loops, guardrails, and error recovery

2. Core Mental Model: Guides & Sensors

In his framework on harness engineering, Martin Fowler breaks user-built harnesses down into two control directions:

  • Guides (Feedforward Controls): Steer the agent before it writes code, so it gets things right on the first try.

    • Examples: Repo-level rules files (AGENTS.md, CLAUDE.md, .cursor/rules/*.mdc), project bootstrap scripts, and reusable agent skills.

  • Sensors (Feedback Controls): Observe the agent after it acts and feed error signals back so it can self-correct autonomously.

    • Examples: Test suites, type checkers, linters, architectural boundary tests, and LLM-as-a-judge code review skills.

Both guides and sensors split into two execution types:

  • Computational (Deterministic): Fast, cheap CPU checks (compilers, unit tests, linters, static analysis) that enforce hard boundaries rather than relying on the LLM to remember a rule.

  • Inferential (Semantic): GPU-backed checks (AI code review, subagent spec verification) that evaluate nuance and intent where rigid rules fall short.

3. Practical Patterns to Build in Your Workflow

  1. Persistent Rules Files: Move recurring prompt instructions into hierarchical repository files (AGENTS.md or CLAUDE.md) so conventions survive across sessions and directory trees.

  2. LLM-Optimized Linter & Test Messages: Configure custom linter errors or test assertions to output actionable fix instructions—when the agent runs the test suite, the error message tells it how to self-correct.

  3. The PEV Loop (Plan, Execute, Verify): Force the agent to write a structured plan first, execute changes against that plan, and run an automated verification step (tests + spec check) before finishing.

  4. Context Compaction & Fresh Subagents: Trim or summarize stale tool outputs to avoid context rot, and spin up clean, zero-history reviewer subagents to audit diffs against requirements.

  5. The Steering Loop: Every time an agent repeats a mistake during code review, treat it as a harness bug—add a rule, a script, or a pre-commit check so that failure mode cannot happen again.

No comments:

Post a Comment