Skip to main content
Contradiction (2026-11-01): “Why Harness Engineering Emerged” below says the harness pattern formalizes “fresh context per iteration” as the solution to summarization loss. State Of Harness Engineering 2026 finds the fresh-context Ralph variant rests on one uncontrolled toy-app run with no baseline, and argues the benefit comes from work being written to files, not from the wipe. Treat fresh-context-per-iteration as a plausible design, not a measured win.

Agent Harness

A harness is the system that wraps a language model to make its intelligence useful for completing real-world tasks. The model contributes intelligence; the harness contributes environment, tools, state management, and feedback loops. Agent = Model + Harness Without a harness, a model can only take in data and output text in a single turn. The harness is what turns that into a work engine. Term coined: February 2026, by OpenAI’s “Harness engineering” post (Harness Engineering Codex Openai); the “Agent = Model + Harness” formula is credited to Birgitta Böckeler (Thoughtworks), though the pattern existed before the term. Emerged as the third layer in an additive stack: Each layer is additive — harness does not deprecate context engineering.

Harness vs. Orchestrator vs. Framework

Three terms that are often conflated: A harness typically uses a framework. An orchestrator drives the harness. Together they determine real-world agent effectiveness more than model capability increments do. Example stack: LangChain (framework) → LangGraph (runtime/orchestrator) → DeepAgents (harness). Model-agnostic property: a harness built on standard tool-call interfaces (Anthropic tool use, OpenAI function calling) can swap the underlying model without rewriting harness logic — only prompt format details change. Some harnesses route across multiple models (smaller for simple steps, larger for complex ones). Caveat: models post-trained with a specific harness in the loop may overfit to its tool logic — changing tool behavior can degrade performance even if the interface is standard.

Why Harness Engineering Emerged

Context engineering (tool calling, MCP, RAG) enabled longer-duration tasks as context windows grew — but exposed a specific failure mode: context summarization as a fidelity bottleneck. When a task ran long enough to fill the context window, the agent would summarize its prior work and continue. In practice:
  • The agent was bounded by its own ability to accurately summarize prior work
  • Summarization caused false completion signals — the agent assumed tasks were done when they weren’t
  • Features were oversimplified or silently skipped; the summarized state marked them “verified”
  • Tasks appeared partially finished with no reliable way to resume accurately
Subagent hierarchies and swarms were early attempts to work around this. The harness pattern formalizes the solution: fresh context per iteration, with durable filesystem state carrying work forward. See Ralph Loop for the loop mechanism.

Core Components

1. Filesystem

The most foundational primitive. Provides:
  • A workspace for reading data, code, and documentation
  • Persistent state that outlasts a single context window
  • A collaboration surface: multiple agents and humans coordinate through shared files
Git adds versioning: agents can track progress, rollback errors, branch experiments, and bootstrap from history.

2. Bash / Code Execution

The general-purpose tool. Instead of pre-building a tool for every possible action, giving the agent bash lets it design its own tools on the fly. The default execution pattern is ReAct: reason → tool call → observe → repeat in a while loop. Bash as the primary tool extends this into “giving the model a computer.”

3. Sandbox

Safe, scalable execution environment:
  • Isolated from the host; agent-generated code runs contained
  • Can be created per task, fanned out across many parallel tasks, torn down on completion
  • Pre-configured with runtimes, CLIs, browsers, test runners
  • Security: allow-listed commands, network isolation

4. Context Management

Context is scarce. The harness must manage it actively: Token budget by component — what to protect vs. compress: Compaction thresholds: see Context Degradation Patterns for the canonical 70/80/90 ladder (plan / trigger / aggressive). Kept authoritative there to avoid drift. KV-cache rule: system prompt and tool definitions must be byte-identical across requests to get cache hits. Never put timestamps or session IDs in the system prompt. See Context Compression Strategies for the three compaction strategies (anchored iterative summarization is the default for coding sessions). See Context Degradation Patterns for the five failure modes compaction prevents. See Agent Context Instructions for the AGENTS.md / context spec approach to structuring what enters context.

5. Long-Horizon Execution Loop

Combines all primitives for autonomous multi-session work:
  • Ralph Loop: re-injects original prompt with clean context but durable filesystem state; forces continuation past early stopping
  • Planning: decompose goal into steps tracked in a filesystem plan file; update as work progresses
  • Self-verification: post-step correctness check; hooks run tests and feed errors back to the model

Harness Design Principles (from practice)

Progressive disclosure over front-loading. A short entry point (AGENTS.md as table of contents, ~100 lines) pointing to structured deeper sources is better than one large instruction file. Large files: crowd out task context, become non-guidance when everything is “important,” rot instantly, can’t be mechanically verified. CI enforces the knowledge base: linters validate cross-links, coverage, and freshness. A recurring doc-gardening agent scans for stale docs and opens fix PRs. Repository as the system of record. Anything not in the repo doesn’t exist for the agent. Slack decisions, tribal knowledge, undocumented conventions — all illegible. Push context into versioned repo artifacts. Enforce invariants, not implementations. Architectural rules encoded as custom linters with remediation instructions in error messages are more reliable than documentation. They apply to every line simultaneously. Application legibility. Wire the app’s own observability (logs, metrics, traces, screenshots) into the agent runtime so it can self-validate without human QA involvement. Codex case study implementation: per-worktree app boot, Chrome DevTools Protocol for DOM snapshots + screenshots, ephemeral Loki/Victoria metrics+traces per worktree (torn down after task). Prompts like “ensure service startup < 800ms” become tractable. Single Codex runs regularly work 6+ hours unattended. Entropy / garbage collection. Agent-generated code replicates existing patterns — including bad ones. Background cleanup agents scanning for deviations on a daily cadence prevent debt from compounding. Build each piece in reaction to a failure. Vercel’s harness course orders every component by the failure it answers (unbounded reads → output caps and pruning; bash → execute-level gates; “explains instead of acting” → Agency/Guardrails prompt sections). See Build Ai Agent Harness Vercel.

Empirical State of the Practice (2026)

From marmelab’s audit of 246 harness repositories, a 145-project non-AI counter-test and 57 publications (State Of Harness Engineering 2026; the authors disclose that one of their own harnesses is a finalist):
  • Harness choice matters, but is barely measured. The one controlled comparison found: same model, provider and tools across 8 harnesses on 25 tasks gave 68% to 88% success (third-party, unreplicated).
  • Instructions are common, enforcement is rare. 63% of large projects ship an instruction file, but only 12 of 391 repositories commit a deny rule and 22 a PreToolUse hook; in the median repo with subagents, 1 in 4 has a restricted tool list. Separately, only 4.4% of security rules in 481 public CLAUDE.md files could be fully expressed by a built-in Claude Code control (arXiv 2608.23550, Do Not Is Not Deny Claude Md; the survey misreports this as rules “backed by a real control”). See Rules vs. Hooks.
  • Harnesses rarely test themselves. 60% of 97 testable harnesses have neither tests nor evals.
Practices the survey recommends, on top of the principles above: Multi-agent limits. Azure SRE Agent found that problems requiring more than four agent-to-agent handoffs “almost always failed” and collapsed 50+ specialists into a few generalists with wide tools (az, kubectl) and on-demand knowledge files (Azure Sre Agent Context Engineering). In the NLAH ablation (arXiv 2603.25723), adding a second reviewer agent lowered success by 8% from a 41% base; a four-role team beat the best single agent by only 0.4 points on SWE-bench 500 (arXiv 2602.01465). These are single studies; the survey authors report the opposite experience with their own reviewer role. Harnesses rot as models improve. A harness encodes what the model cannot do; when the model learns it, the control becomes cost. Anthropic’s context resets for “context anxiety” became dead weight with Opus 4.5.

Model + Harness Co-evolution

Frontier coding agents (Claude Code, Codex) are post-trained with harness in the loop. Models improve at primitives their harness designers prioritized. Side effects:
  • Models can overfit to their training harness; changing tool logic degrades performance
  • The best harness for a specific task may not be the one the model was trained with — harness optimization per domain is a real lever. Example: LangChain improved a benchmark from Top 30 → Top 5 on Terminal Bench 2.0 via harness changes alone, with no model change.

Minimal Harness Example

Karpathy’s autoresearch is a deliberately minimal harness:
  • Context: program.md skill file
  • Tool: code modification + bash
  • Verification: single val_bpb metric
  • Loop: 5-min train → eval → keep/discard → repeat
See Autoresearch Karpathy for details.

Real-World Harness Examples

Minimal vs. feature-heavy trade-off: Terminal Bench 2.0 found the most minimal harness (tmux keystrokes + read output, no file tools, no subagents) outperformed native model harnesses across model families. LangChain improved Terminal Bench from Top 30 → Top 5 via harness changes alone — no model change. Domain matters: game-playing benefits from structured perception/memory; coding tasks favor minimalism. Harness optimization per domain is a real lever.
  • Ralph Loop — the long-horizon loop pattern
  • Agent Context Instructions — standards docs / AGENTS.md as context injection
  • Agentic Sandbox Controls — OS-level security for sandbox execution
  • Autoresearch Karpathy — minimal harness instantiation for autonomous ML research
  • Tool Design for Agents — dual audience principle; error messages as agent recovery instructions
  • Agent Diff Viewer — localhost real-time diff viewer over the harness PostToolUse hook stream
  • Harness Engineering Codex Openai — the OpenAI post that named the discipline
  • State Of Harness Engineering 2026 — empirical survey of 246 harness repos and 57 publications
  • Build Ai Agent Harness Vercel — build-along course: failure-driven harness components
  • Azure Sre Agent Context Engineering — wide tools, generalists, four-handoff cliff
  • Swe Bench Mobile — same model scores 12% vs 2% task success across harnesses on 50 iOS tasks
  • What Is An Agent Harness Parallel Ai — source definition of the harness and its components
  • LSP as Agent Baseline — language servers as a lazy, project-scoped execution-substrate capability: diagnostics and symbols before tests

Linked pages