AI Coding Agents: Why Model + Harness Is the Key to a Closed Loop

    This article explains why a code-generating foundation model alone does not make a usable coding agent, and why the engineering harness around it must be built in-house. It covers what a harness does (constraint, verification, repair, convergence), where third-party API wrappers break the loop, how cached input cost shapes interaction strategy, and why the required talent profile is closer to distributed systems engineering. A practical checklist for building the loop is included.

    When Models Meet the Engineering Harness: Building a Closed Loop for AI Coding Agents

    1. The Starting Point: A Model That Writes Code Is Not a Usable Coding Agent

    Over the past two years, expectations for “AI coding” have moved from amazement to disillusionment. In demos, a model can generate hundreds of lines of code in one pass. Once that code enters a real repository, developers quickly hit three walls: the generated code does not compile, it compiles but violates the repository’s existing conventions, or it follows the conventions yet behaves differently at runtime.

    Behind this is a long-underestimated fact: a foundation model is optimized for divergent generation, while engineering delivery demands convergent correctness. These two objectives are not aligned, and at certain stages they actively conflict. Hand both to the same module and neither is done well; separate them completely and you lose the most important feedback path.

    The industry has gradually converged on an architectural statement: Model + Harness = Agent. The model generates candidate solutions; the harness constrains, verifies, repairs, and converges them. This article is about why that engineering shell must be built in-house, how to design it, and what it implies for cost and talent structure.

    2. What a Harness Actually Is: From a Safety Belt to a Driving System

    In engineering usage, “harness” originally means a safety belt or a set of reins, and by extension a driving or control system. In the AI agent context, it is not a UI, not a plugin marketplace, and not a collection of prompt templates. It is a control plane wrapped around the model runtime:

    • Constraint: limit the solution space during generation, for example repository conventions, dependency allowlists, directory boundaries, and callable interface signatures.
    • Verification: compile, static analysis, unit tests, integration tests, type checks, and security scans, forming multiple gates.
    • Repair: feed failure signals back to the model in structured form, producing bounded retries rather than blind resampling.
    • Convergence: define stopping conditions and confidence evaluation, avoiding infinite loops and false positives that merely “look done.”

    A simplified control loop looks like this (pseudocode, structure only):

    1. def run_task(task, repo, model, harness, max_rounds=6):
    2. ctx = harness.build_context(repo, task) # retrieval + convention injection
    3. for i in range(max_rounds):
    4. patch = model.generate(task, ctx) # divergent generation
    5. ok, signals = harness.apply_and_verify(patch) # constraint + verification
    6. if ok:
    7. return patch, {"rounds": i + 1, "confidence": harness.score(patch)}
    8. ctx = harness.encode_feedback(signals) # structured repair signals
    9. return None, {"reason": "not_converged"}

    The critical piece is encode_feedback: compile errors, lint warnings, and failed test assertions must be translated into structured context the model can understand, not reduced to “it failed, please retry.”

    3. First Key Point: Why Third-Party Wrappers Cannot Close the Loop

    A common industry approach is “foundation model plus external API wrapper,” packaging general model capability in a coding tool. The weakness of this pattern is not engineering skill but a structural break, in three places:

    1. Context break: when the tool hits a compile error in a local IDE, the model cannot see the full error context, build configuration, and dependency graph. It can only patch by guessing, and tends to break three things while fixing one.
    2. Runtime break: the toolchain executes locally, so runtime metrics, exception stacks, and resource usage never flow back to the model side. The model lacks real execution semantics.
    3. Feedback break: even when failure samples are collected, the model and the shell belong to different teams with different release cadences. The data cannot form a loop, and improvement stalls at the prompt level.

    Stacked together, these three breaks explain why every attempt at an “AI coding revolution” falls short: they optimize the look of a single generation, not the success rate of multi-round tasks.

    This is exactly the value of building the harness in-house: the model and the shell share one data path, and structured signals from the terminal side can be used directly for model iteration, creating a positive feedback loop that gets more accurate with use. This is not a product strategy choice but a precondition for architectural feasibility.

    4. Second Key Point: Cost Structure Caps the Interaction Strategy

    High-frequency verification loops are inherently expensive: one task may need 5 to 20 rounds of generation and checking, each carrying a large amount of repository context. If per-call input cost is too high, product design is forced to cut verification rounds, and reliability drops accordingly.

    So when evaluating this kind of architecture, what matters is the input cost after cache hits, not the list price per token. The common industry practice is to reuse stable context through prefix caching (repository structure, convention docs, dependency lists), which significantly reduces billing for the repeated portion. Only when the post-hit input cost drops by one or two orders of magnitude can architects afford to make “multi-round verification plus automatic repair” the default path.

    The engineering implications are direct:

    • Design context as a stable prefix with a variable suffix, placing volatile content at the end to maximize cache reuse.
    • Compress feedback before feeding it back, sending only the failing fragment and related code instead of rescanning the whole repository.
    • Tier the budget by task, fewer rounds for low-risk changes and a higher ceiling for high-risk ones.

    In public cloud environments, these needs are typically met by combining general-purpose container platforms, object storage, message queues, logging services, and monitoring and alerting, with no proprietary interfaces required to build the loop.

    5. The Third Underrated Variable: A Shift in Talent Structure

    One change worth noting is in team composition. Recently a group of engineers has moved from quantitative trading into AI infrastructure, and this background is no accident: quant systems require highly reliable multi-step decisions under extremely low latency, where fault tolerance, rollback, and state consistency are daily work. A harness for agents faces the same class of problems: multi-step tool calls, failure retries, idempotency, and state recovery.

    Put differently, the core competence of a harness is closer to distributed systems engineering than to prompt engineering. That also explains why simply expanding an algorithm team cannot fill this gap.

    6. A Practical Checklist

    To build a similar loop in your own stack, proceed in this order:

    1. Build the verification layer before generation: make compile, static analysis, tests, and security scans into unified, orchestrable gates that emit standardized signals.
    2. Define a structured feedback protocol: field-based error type, location, severity, and suggested action, avoiding natural-language noise.
    3. Layer context and make it cache-friendly: stable prefix plus variable suffix, keeping per-round token volume under control.
    4. Bounded retries and convergence criteria: set a round limit, a confidence threshold, and conditions for escalating to a human.
    5. Data return path: store failure samples after de-identification, forming an offline evaluation set and regression baseline.
    6. Observability first: trace the latency and success rate of every generation, verification, and repair step end to end, and let metrics drive optimization.

    7. Conclusion

    The real significance here is not another intelligent coding tool, but the industry starting to recognize that model capability and the engineering harness must be designed as a whole. Whoever controls the complete path from runtime signals back into model iteration controls the pricing power for agent reliability. For Chinese teams, having a full closed-loop capability at the “model plus engineering harness” layer to compete head-on for the first time carries symbolic weight far beyond the release of any single product.