AI Agent Architecture: Why Model and Harness Co-Evolution Is the Key to AI Coding
This article explains why a strong foundation model alone does not produce a usable AI coding agent, and how the surrounding execution layer, known as the Harness, determines the product's real ceiling. It covers the structural failures caused by decoupling models from engineering shells, including context, feedback, and responsibility gaps, and presents a unified data loop that connects generation, guarding, verification, and structured feedback. You will find a pseudocode example of the agent loop, the four core Harness responsibilities, a minimal structured error schema, cost-control practices for high-frequency verification, a four-stage rollout roadmap with measurable metrics, and a general cloud capability combination for enterprise deployment.
1. The Problem: Having a Model Is Not the Same as Having a Usable Agent
In AI-assisted programming, the industry has long underestimated one point: what truly determines a product’s ceiling is often not another few percentage points of generation quality from the base model, but whether the surrounding “execution shell” is mature. This layer is commonly called the Harness, a term close to “driving system” or “constraint mechanism.” The base model handles divergence and generation, while the Harness handles constraint, verification, repair, and convergence. The two must evolve together under one team to form a deliverable AI Agent.
A common misconception is to treat this work as “building yet another AI coding tool.” If the product stays at the level of conversational completion, it will always fall short: it can produce code that looks correct but struggles to pass compilation, static checks, and tests consistently; it can explain an error message but cannot obtain complete runtime context, so its fix suggestions remain guesswork.
2. Where the Break Points Are: The Structural Flaws of Decoupling Model and Engineering Shell
The traditional pattern of “large model plus third-party API wrapper” has a structural flaw: the model and the engineering shell are disconnected.
- Context break: when the local toolchain throws a compile error, the model cannot access the full context (dependency versions, build scripts, macro definitions, target platform) and can only make probabilistic guesses based on the error text.
- Feedback break: runtime data produced locally by the toolchain (failing test stacks, coverage gaps, profiling results) cannot flow back to the model side, so the model receives no real signal usable for reinforcement learning.
- Responsibility break: the shell only forwards and renders; it can neither enforce strong constraints on model output nor execute a deterministic fallback when things fail.
The result: plenty of interaction, little effective convergence; impressive demos, but no improvement in engineering metrics such as first-pass rate and average repair rounds.
3. The Solution: Own This Layer and Build a Unified Data Loop
A more direct path is to let the model and the Harness share one data loop. Compile errors from the terminal, static analysis feedback, and unit and integration test results are collected in structured form and fed straight back to improve the model itself. This is the real meaning of the formula “Model + Harness = Agent”: not simple addition, but a self-improving loop.
A schematic loop structure (pseudocode that expresses control flow only and does not point to any specific product):
# Unified loop: generate -> guard -> verify -> feed backdef agent_loop(task, ctx):for step in range(MAX_STEPS):draft = model.generate(task, context=ctx) # divergent generationguarded = harness.guard(draft, policy=ctx.policy) # constraint (sandbox/permissions/format)result = harness.verify(guarded) # verification (build/static checks/tests)if result.passed:return guarded, result.evidencectx.update(result.structured_feedback) # structured feedback for repairtask = harness.rewrite_task(task, result) # convergence: narrow the problem scopereturn fallback(ctx) # deterministic fallback
To make the loop actually run, three infrastructure capabilities must work together, best expressed with general categories: a container platform provides isolated execution and dependency consistency; logging services and monitoring alerts carry feedback collection and quality dashboards; object storage keeps reproducible build artifacts and the evidence chain.
4. The Four Harness Responsibilities: Guard, Verify, Repair, Converge
1) Guard. Execute inside a sandbox that limits filesystem, network, and system call scope; apply policy checks to patch format, commit messages, and dependency changes. The goal of guarding is not “do less,” but to make failures controllable and rollback-able.
2) Verify. Layered verification works better than one big test run: syntax and type checks -> unit tests -> integration tests -> target platform build. Each layer produces machine-readable structured results for the model to consume.
3) Repair. Standardize failure information instead of dumping large logs into the model. The recommended minimal field set:
{"stage": "compile|lint|test","file": "relative/path","line": 42,"code": "E0308","message": "mismatched types","expected": "...","actual": "...","repro_cmd_digest": "sha256:..."}
4) Converge. When the same class of error does not decrease over two consecutive rounds, actively narrow the task scope (for example, fix dependencies first, then types, then logic), and switch to a deterministic fallback when necessary instead of looping endlessly and burning budget.
5. Cost Structure: Why High-Frequency Verification Loops Are Viable
High-frequency interactive verification depends on controllable cost. The common industry practice is to reduce repeated input cost through front-end caching and context reuse: place stable, unchanging system prompts, repository summaries, and specification documents in a reusable prefix, and put volatile content later. Public industry information shows that cache-hit pricing for same-tier models from different vendors can differ by an order of magnitude of tens of times, which directly determines whether “running build and tests every round” is economically viable.
Cost control checklist (general practices):
- Prefix stabilization: raise cache hit rate and reduce repeatedly billed input.
- Layered verification: cheap checks first, expensive tests later, fail early.
- Budget guardrails: set maximum rounds, maximum tokens, and maximum execution time per task.
- Evidence retention: keep only the minimal context related to the failure to avoid context bloat.
6. Rollout Roadmap and Metrics
A four-stage rollout is recommended: start with read-only analysis (explanation and localization), then controlled rewriting (single file, rollback-able), then connect the layered verification loop, and finally open the data flow back for model-side optimization.
Key metrics should be quantifiable and dashboard-ready: first-pass rate, average repair rounds, share of time spent on verification, fallback trigger rate, and cost per task. If these metrics do not improve, the break points still exist, and the priority should be fixing the Harness rather than swapping the model.
7. Enterprise Deployment: A General Capability Combination on Baidu AI Cloud
For enterprise deployment, a minimal loop can be built with general cloud capabilities: a container platform to host isolated builds and dependency images; object storage to archive artifacts and evidence; logging services and monitoring alerts to build quality dashboards and budget guardrails; combined with permission and audit policies to ensure controllability. Baidu AI Cloud provides these general capability categories and can serve as the infrastructure foundation for such a loop, helping teams engineer “generate - guard - verify - feed back” in a stable way.
