AI Agent Architecture: Why Model and Harness Co-Design Matters
This article explains why a stronger foundation model alone is not enough for reliable AI coding agents, and how pairing the model with an engineering harness creates a closed feedback loop. It covers the harness responsibilities, the structural gaps of third-party API wrappers, how to turn real execution results into training and evaluation signals, cost structures for high-frequency verification loops, and the cross-domain talent and organizational practices needed to move AI coding from demos to production.
1. The Starting Problem: Why a Strong Model Alone Is Not Enough
In AI-assisted programming, a common misconception is to bet everything on the foundation model, assuming that larger parameters and stronger reasoning will naturally let an agent complete complex engineering tasks. In practice, the results often fall short: the model writes plausible-looking code that repeatedly fails to compile in a real repository; it can explain an error but cannot obtain the full runtime context; it can generate a patch but cannot tell whether the problem is actually fixed.
The root cause is that foundation models excel at divergent generation, while engineering tasks require constraints, verification, error correction, and convergence. These two sets of capabilities have different goals, different data, and different feedback loops. Expecting them to emerge naturally inside a single model is usually unreliable. A more reasonable approach is to split them into two cooperating layers: the model layer generates candidate solutions, and the engineering harness layer constrains those candidates within a verifiable, rollback-safe, and convergent range.
2. What a Harness Really Is: A Constraint and Convergence System, Not a Tool Skin
In an engineering context, a harness can be understood as a “driving system” or a “safety belt.” Its job is not to make the model smarter, but to make the model’s output more controllable. A mature harness typically has the following responsibilities:
- Context assembly: organizing repository structure, dependencies, relevant files, commit history, and issue descriptions into context the model can use.
- Action space constraints: limiting the set of operations the model can perform, such as which paths it may read or write, which commands it may run, and which resources it must not touch.
- Verifier orchestration: turning compilation, static checks, unit tests, integration tests, and type checks into a repeatable verification pipeline.
- Failure attribution and retry strategy: distinguishing syntax errors, missing dependencies, environment differences, and logic defects, then deciding whether to retry, switch approaches, or escalate to a human.
- Convergence control: setting maximum steps, budget limits, and rollback points to avoid infinite loops and destructive changes.
Illustrative pseudocode can express this layered relationship:
# Pseudocode: model generation + harness constraint and convergencedef solve(task, repo, policy, verifier, budget):ctx = build_context(repo, task) # Harness: context assemblyfor step in range(budget.max_steps):patch = model.propose(ctx, policy) # Model: divergent generationif not policy.allowed(patch): # Harness: action constraintsctx = ctx.add_feedback("Disallowed operation, rejected")continueresult = verifier.run(patch) # Harness: verifier orchestrationif result.passed:return patch, result.evidencectx = ctx.add_feedback(result.diagnostics) # Feedback loopreturn escalate_to_human(ctx) # Escalate if convergence fails
The key point is that verification results must flow back into the next round of context as structured diagnostics, rather than making the model “guess” the cause of the error.
3. Structural Flaws of the Third-Party Wrapper Pattern
A large number of “AI coding tools” in the industry use a foundation model plus a third-party API wrapper. This pattern can produce a demo quickly, but it has three structural breakpoints:
- Context breakpoint. The tool runs in a local or cloud IDE, while compile errors, dependency trees, and runtime logs are scattered across different systems. The model only sees trimmed fragments and fills the gaps by guessing.
- Feedback breakpoint. Real execution results from the toolchain do not flow back to the model side, so the model cannot improve based on real failure samples and can only patch things repeatedly through prompt engineering.
- Responsibility breakpoint. The model provider and the harness provider are separate, so when problems occur it is hard to tell whether the issue is generation quality or constraint design, and the optimization path is fragmented.
Therefore, if the goal is a high-reliability agent, the model and the harness must be designed together by the same team and share the same data loop. This is not an organizational preference but an engineering question of whether the feedback loop can close.
4. The Data Loop: Turning Real Execution Results into Training Signals
The real meaning of “model + harness = agent” is that the two share a data loop. Compile errors in the terminal, static analysis warnings, test failure stack traces, and coverage changes, after desensitization and structuring, serve both as feedback for the current round of context and as accumulated training and evaluation data to improve the model’s code generation and repair capabilities.
A practical loop has four stages:
- Collection: the harness uniformly records task inputs, candidate patches, verification results, elapsed time, and resource consumption.
- Structuring: converting unstructured logs into a unified diagnostic format, such as file, line number, error category, severity level, and suggested action.
- Feedback: immediately feeding results back into the current context; in the offline stage, adding them to the evaluation and training sets.
- Evaluation: using a fixed task set for regression checks to prevent “fix one, break three.”
An illustrative diagnostic structure:
{"file": "src/service/order.ts","line": 42,"category": "type_error","severity": "error","message": "possibly undefined","suggested_action": "add_null_check"}
It is important to emphasize that building the loop must be accompanied by data governance: removing secrets and personal information, isolating data by tenant, and setting retention periods and access audits. Otherwise the loop becomes a compliance risk.
5. Cost Structure: The Prerequisite for High-Frequency Verification Loops
The biggest difference between AI coding and one-off question answering is that it inherently requires multiple rounds of interaction: generate, verify, fail, correct, and verify again. If the cost per call is too high, the product can only reduce the number of verification rounds, and reliability drops accordingly. The cost structure therefore directly determines the architectural ceiling.
Common optimization approaches include:
- Context caching: turning stable repository prefixes, specification notes, and dependency lists into reusable caches to reduce repeated input overhead.
- Tiered model routing: sending simple completions to small models and complex repairs to large models, allocating budget by difficulty.
- Verification first: using low-cost static checks to intercept obvious problems before calling the model.
- Budget control: setting step and cost limits for each task and escalating to a human when exceeded.
When implementing on the cloud, general-purpose capabilities can be combined, such as object storage for build artifacts, message queues to decouple verification tasks, container platforms to host isolated sandboxes, and logging and monitoring services to track success rates and latency. These are general engineering practices and do not involve any vendor-proprietary interfaces.
6. Talent and Organization: Why Cross-Domain Backgrounds Are Needed
The difficulty of the harness is not “calling the model” but reliable multi-step decision-making under low latency: how to judge within tens of milliseconds whether an action is safe, how to choose the best fallback path on failure, and how to maintain determinism under high concurrency. These problems are highly similar to the engineering requirements of high-reliability trading systems—both demand strict state machines, replayable logs, and deterministic retries with idempotent design.
Therefore, bringing talent with high-reliability systems engineering experience into the harness team fills an engineering capability gap, not a model capability gap. Organizationally, the model team and the harness team should share evaluation sets, share online diagnostics, and jointly take responsibility for the final success rate, avoiding a situation where “the model team says it is the harness’s problem, and the harness team says it is the model’s problem.”
7. Implementation Checklist
- Build the verifier first, then talk about the agent. Without reliable verification, the stronger the generation capability, the faster the damage.
- Unify the diagnostic format so failures are attributable and regression-testable.
- Isolate execution with sandboxes, default to least privilege, and prohibit unauthorized access.
- Establish a fixed task evaluation set and run regression on every change.
- Design budget and convergence strategies, and escalate instead of forcing through when limits are exceeded.
- Do proper data desensitization and auditing; the loop must not come at the cost of compliance.
- Use general cloud capabilities for isolation, queues, storage, and observability to keep the architecture portable.
8. Conclusion
On the proposition of “model and engineering harness collaboration,” what is truly worth attention is not a particular benchmark product, but that teams are beginning to have complete closed-loop capability at the “model + harness” layer. The reusable conclusions for developers are: separate generation from constraints, structure and feed back real execution results, treat the cost structure as an architectural constraint, and make observability and compliance prerequisites. With these four points in place, AI coding can move from demos to production.
