AI Agent Architecture: Why the Harness Matters as Much as the Model in AI Coding Loops
This article explains why the engineering layer around a foundation model, known as the Harness, often determines the real capability users experience in AI coding tools. It covers the four core Harness responsibilities (constraint, verification, correction, and convergence), why third-party API wrappers struggle to close the loop, how cost structure shapes interaction frequency, the talent profile required for reliable multi-step decisions, a five-layer reference architecture with a minimal viable implementation, an evaluation system based on metrics, and key risks and boundaries. The closing guidance is to build constraints and verification first, establish observability and budgets, and only then increase loop frequency.
1. Why Building the Harness Matters More Than Building the Model
Discussions of AI coding tools tend to focus on parameter counts and benchmark scores. Engineering practice repeatedly shows that the ceiling of a foundation model’s capability is not the same as the ceiling users actually perceive. What shapes the experience is the engineering system outside the model, the layer responsible for constraint, verification, correction, and convergence. The industry commonly calls this layer the Harness, which can be understood as a control or constraint shell.
Its responsibilities break down into four parts:
- Constraint: keep the model’s divergent generation within a legal action space, for example allowing only registered tools to be called and only whitelisted paths to be modified.
- Verification: run static and dynamic checks on model output, including syntax parsing, type checking, compilation, unit tests, and rule validation.
- Correction: feed failure signals back to the model in a structured form, creating a bounded loop of regenerate and re-verify.
- Convergence: define deterministic termination conditions and fallback strategies before the budget (time, tokens, number of calls) is exhausted.
The foundation model handles divergence; the Harness handles convergence. If the two are advanced separately by different teams and different data pipelines, you get the breakpoint problem this article focuses on.
2. The First Key: Why Third-Party Wrappers Fail to Close the Loop
The traditional pattern is foundation model plus external API wrapper. Its structural flaw is that the model and the engineering shell are disconnected.
- Context breaks. When a tool hits a compile error in the local environment, the model often receives only a single line of error text, without the full dependency graph, build configuration, or recent changeset, and can only patch by guessing.
- Feedback breaks. Runtime data produced by the toolchain locally (test results, coverage, performance metrics, logs, and monitoring alerts) is hard to return to the model side in a structured way, so no effective reinforcement learning signal is formed.
- Responsibility breaks. The shell vendor cannot change the model, and the model vendor does not have the real end-user environment, so problems get passed back and forth between the two.
Illustrative pseudocode shows the difference between a closed loop and a broken one:
# Broken loop: the model only sees text, and failure signals cannot flow backdef naive_fix(error_text):return model.generate(prompt=error_text)# Closed loop: structured context + bounded loop + data returndef harness_fix(ctx, budget=3):for step in range(budget):patch = model.generate(prompt=render(ctx), # errors, dependencies, changeset, constraintstools=ctx.registered_tools # only controlled actions allowed)result = ctx.verify(patch) # compile / test / static checksctx.record(step, patch, result) # key: sample returnif result.passed:return patchctx.update(result) # structured correction signalreturn ctx.degrade() # deterministic fallback
The real meaning of the formula “model + Harness = Agent” is that the two share the same data loop: end-user compile errors, code style feedback, and test results are collected, cleaned, and deduplicated, then fed back to optimize the model itself, rather than stopping at a one-off prompt patch.
3. The Second Key: Cost Structure Determines Interaction Frequency
A high-reliability coding agent depends on frequent generate, verify, regenerate loops, and a single task may trigger dozens of model calls. This turns cost from a unit-price question into a feasibility question.
Cost-reduction measures widely adopted in the industry include prefix caching and context reuse, batch scheduling, distilled small models handling routing and initial screening, and pushing deterministic logic down to a rule engine rather than the model. Only when the input cost after a cache hit is pushed to a very low level do architects dare to raise the default budget of the verification loop, which improves the first-pass rate.
Note that specific prices and billing rules should follow each cloud provider’s public documentation; this article cites no unconfirmed numbers. The more robust architectural practice is to make cost a first-class observable:
budget:max_steps: 6max_tokens: 400000cost_ceiling: 0.20 # per-task cost ceilingprefer_cache: true # prefer reusing stable prefixesobservability:metrics: [pass_rate, steps, cache_hit, latency_p95]logs: structured logsalerting: monitoring alerts
In general capability systems on cloud platforms such as Baidu AI Cloud, this kind of requirement is typically carried by a container platform for runtime, object storage for samples, a message queue for peak shaving, and logging plus monitoring and alerting for observability, which is a common combination in the industry.
4. The Third Key: Filling the Talent Gap
The hard part of the Harness is not writing prompts, but reliable multi-step decisions under low latency. This is highly similar to the engineering requirements of quantitative trading systems: latency-sensitive, high cost of failure, must be rollback-capable, must be auditable. So engineers with a trading or risk-control background join the constraint system team to fill the gap in deterministic engineering and stability governance, not model training capability.
A mature Harness team usually needs four roles working together: model and training, compiler and toolchain, testing and quality, and platform and observability. Missing any one of them degrades the loop into something that can be demoed but not run in production.
5. Reference Architecture: Five Layers and a Minimal Viable Implementation
- Access layer: unified authentication, quotas, and auditing, shielding differences between underlying models.
- Orchestration layer: task decomposition, plan generation, step scheduling, and budget control.
- Constraint layer: tool registry, path whitelist, second confirmation for dangerous operations, and policy as code.
- Verification layer: syntax and type checks, unit tests, static scanning, and sandbox execution.
- Return layer: sample collection, desensitization, labeling, evaluation set construction, and canary release.
For a minimal viable implementation, start with read-only analysis, single-file modification, and mandatory tests, then gradually open up multi-file and multi-step tasks after verification passes. Policy constraints can be expressed with declarative configuration:
policy {allowed_paths = ["src/**", "tests/**"]allowed_actions = ["read_file", "write_file", "run_tests"]require_approval = ["run_shell", "delete_path"]sandbox = true}
6. Evaluation: Replace Subjective Feelings With Metrics
- First-pass rate: the proportion of cases that pass all verification on the first generation.
- Average convergence steps: the average number of iterations needed to complete a task.
- Regression rate: the proportion of fixes that introduce new problems.
- Cost and latency P95 per task: determines whether the high-frequency loop can be enabled by default.
- Security violation interception rate: effectiveness of blocking unauthorized paths and dangerous commands.
The evaluation set should come from real desensitized repositories and keep a hard-case set for regression, avoiding self-validation with constructed samples.
7. Risks and Boundaries
- Security risk: execution must be sandboxed, permissions minimal, and dangerous actions confirmed by a human.
- Data compliance: returned samples must be desensitized and authorized, with a clear retention period.
- Over-automation: set a hard budget and deterministic fallback for the loop to avoid infinite retries.
- Vendor coupling: abstract the access layer and keep the ability to swap models.
8. Conclusion
As foundation model capabilities gradually converge, the focus of competition shifts to the complete loop of model plus engineering shell: whoever holds real end-user feedback, whoever can push cost into an affordable range, and whoever has a talent structure for deterministic engineering can turn a demo into production. For Chinese vendors, the real signal is not another benchmark product, but the start of end-to-end engineering loop capability at this layer. The practical advice for developers is to build constraints and verification first, then talk about automation; establish observability and budget first, then raise the loop frequency.
