Model + Harness: The Agent Architecture Behind Reliable AI Coding Agents
This article breaks down the Model + Harness paradigm for building AI agents, explaining why a stronger model alone does not produce a better agent. It covers the four core responsibilities of the harness layer, the data feedback loop that closes the gap between model and execution, the economics of high-frequency validation loops, a phased adoption path, and common pitfalls with their risk boundaries. Developers will learn how to structure context assembly, constrain the action space, orchestrate verification, and enforce convergence to achieve stable success rates on multi-step engineering tasks.
1. The Starting Point: Why a Stronger Model Is Not a Better Agent
Over the past two years, industry discussion has centered almost entirely on parameter counts, context length, and reasoning ability. Yet feedback from real development scenarios is consistent: models shine in single-turn question answering, but once they enter multi-step, long-horizon engineering tasks, their success rate drops noticeably.
The reason is not mysterious. The hard part of an engineering task is not “generating code that looks correct.” It is whether the output can be verified, localized, and converged after it is generated.
A typical loop looks like this: the model produces a patch, the toolchain runs compilation, compilation fails and returns an error, and the model tries again. What actually determines success or failure in this loop is whether the error message can be fed back to the model in a structured form, and whether the model has enough retry budget. If the shell merely forwards a natural-language prompt to a remote endpoint and pastes the result back into the editor, the model knows nothing about runtime state and can only patch by guessing. That is the root cause of results that fall just short.
As a result, the industry has gradually converged on an architectural judgment: the foundation model handles divergent generation, while the outer engineering system handles constraint, verification, correction, and convergence. The two must be co-designed within a single system. In engineering contexts, this control-and-constraint layer is commonly called the “Harness.” It is not a seat-belt-style add-on; it is the core mechanism that turns uncertain output into usable results.
2. Separation of Responsibilities: What the Harness Actually Does
Treating the Harness as a “collection of prompt templates” underestimates it. A mature constraint layer typically includes four capabilities.
- Context assembly: Retrieve relevant files, type definitions, callers, and commit history from the repository, then compress the truly relevant fragments into a limited context window instead of stuffing an entire directory into it.
- Action space constraint: Limit the actions the model can take to controlled tool calls, such as reading files, writing to specified paths, and running restricted commands, with permission and path validation on every step.
- Verification orchestration: Automatically trigger formatting, static analysis, unit tests, type checks, and builds after generation, and normalize the results into structured feedback the model can understand.
- Convergence control: Set a maximum iteration count, failure-mode detection, rollback strategy, and human handoff points to avoid infinite loops and destructive writes.
The orchestration logic can be abstracted schematically as:
def run_task(goal, repo, budget=12):ctx = assemble_context(goal, repo) # retrieval + compressionfor step in range(budget):action = model.plan(ctx, allowed=TOOLS) # constrained action spaceresult = sandbox.execute(action) # isolated executionif result.passed:return result.patchctx = ctx.append(structured_feedback(result)) # structured correction signalreturn escalate_to_human(ctx) # convergence fallback
The point of this pseudocode is not syntax but three design tradeoffs: an action whitelist, structured feedback, and a bounded iteration count. Missing any one of them degrades the system into uncontrolled free generation.
3. The Data Loop: The Fundamental Flaw of Separating Shell and Model
The structural problem with the third-party wrapping model is the break in the loop: model training and engineering execution live in two disconnected worlds. High-value signals such as real errors in the terminal, dependency conflicts, environment differences, and flaky tests stay local and cannot flow back. Meanwhile, the model’s optimization target is likelihood over general-purpose corpora, which has nothing to do with “whether this line in this repository compiles.”
Closing the loop means letting the shell and the model share the same data channel: desensitized failure traces, before-and-after diffs, and sequences of verified patches are organized into trainable preference data or feedback signals for later alignment and reinforcement-learning-style optimization. One engineering reality must be stressed here: any data flow-back must go through strict privacy and compliance handling. Credentials, keys, internal domain names, and business code fragments should be filtered and desensitized before entering the training pipeline, following the principle of least necessity.
The payoff from the loop is compounding: the model gradually learns this repository’s build conventions and common error patterns, while the shell needs fewer iterations because the model gets more accurate. Each side reduces the load on the other.
4. Cost Structure: The Economics of High-Frequency Validation Loops
High-frequency interactive validation depends on the marginal cost per call being low enough. The prefix caching mechanism widely used in the industry can bill repeated context portions at a cache-hit price, and the input cost after a hit can be one to two orders of magnitude lower than a miss. Exact pricing varies by vendor and time period, so engineering decisions should follow the official billing documentation rather than fixed numbers for capacity planning.
The transferable conclusion is a design principle: put stable, unchanging content in the prefix and volatile content at the tail.
[system constraints + repo conventions + tool definitions] <- stable prefix, cache-friendly[retrieved relevant code fragments] <- semi-stable[current error and test output] <- changes frequently, placed last
Combined with layered validation, this can compress overhead further: first use very lightweight syntax and formatting checks to intercept obvious errors, then run fast unit tests, and only then trigger the full build and integration tests. Most failures are absorbed in the first two layers, and the proportion of expensive validation calls drops significantly.
5. Implementation Reference: A Phased Build Path
- Phase 1, read-only capabilities: Implement repository retrieval, dependency resolution, and change summaries without granting write access, used to validate the quality of context assembly.
- Phase 2, controlled writes: Allow modifications to limited directories inside an isolated sandbox, and enforce automatic formatting checks and unit tests after every change.
- Phase 3, closed-loop flow-back: Build a desensitized data pipeline that turns failure and repair traces into an evaluation set, and measure each iteration with a reproducible benchmark.
- Phase 4, observability and governance: Connect logging services, metrics monitoring, and alerting; build dashboards for iteration count, verification pass rate, and human handoff rate; and retain a complete audit trail.
If this system is hosted on general-purpose cloud capabilities, it typically only needs a container platform for isolated execution, object storage for desensitized datasets, a message queue to decouple long-running tasks, and logging and monitoring services for observability. The loop can be completed without any proprietary interfaces.
6. Common Pitfalls and Risk Boundaries
- Pitfall 1: Treating the shell as prompt engineering. Without verification and convergence mechanisms, output quality depends entirely on luck.
- Pitfall 2: Chasing full automation. High-risk operations such as dependency upgrades and database changes should keep a human confirmation step.
- Pitfall 3: Ignoring evaluation set construction. Without a reproducible benchmark, both model iteration and shell optimization turn into subjective arguments.
- Risk boundaries: Sandbox escape, prompt injection, and supply-chain dependency poisoning all require explicit defenses. Least privilege and a network egress whitelist are the baseline configuration.
Conclusion
The value of the formula “model plus engineering shell equals agent” is that it shifts the focus of competition from single-point capability to systems engineering: whoever can make generation and constraint work together within one system, and whoever can safely and efficiently feed real execution feedback back into the loop, will achieve stable success rates on multi-step tasks. For developers, the actionable next step is clear: make verification orchestration and iteration limits solid first, then talk about model replacement and cost optimization.
