From Harness to Loop: Engineering AI Agents for Reliable Delivery and Continuous Improvement
This article explains why strong model capabilities do not automatically translate into reliable software delivery, and how engineering systems determine the lower bound of AI agent performance. It covers capability unevenness across tasks, the hidden costs that appear after high code generation rates, and the distinction between a Harness, which stabilizes task execution, and a Loop, which adds feedback for continuous improvement. The article also outlines key design principles, a practical three-step adoption path, and the remaining gap in giving agents access to human context.
1. Where the Problem Starts: Why Writing Code Is Not the Same as Delivering
Over the past two years, expectations for AI agents have gone through a clear roller coaster. At first, seeing models generate long, runnable code led people to assume software development was about to be fully automated. Then, after many pilot projects failed in real business environments, teams swung toward skepticism. The real issue is not whether models are smart enough, but that we conflate model capability with agent system capability.
Model capability is the ability to produce reasonable output for a given input, bounded by training data, context window, and reasoning mechanisms. Agent system capability is the ability to reliably complete tasks and deliver usable results in open environments, over long time horizons, and under multiple constraints. The former is a point capability; the latter is an engineering capability. Strong performance on a benchmark does not mean a model can work reliably in the complex environment formed by your code repositories, permission systems, build pipelines, and production monitoring.
This leads to the first key judgment: models set the upper bound of capability, while the engineering system sets the lower bound of delivery. The upper bound defines how good things can be in theory; the lower bound defines whether the worst case causes an incident. What enterprises actually buy is not the upper bound but a predictable lower bound.
2. Capability Jaggedness: Why a “Stronger Model” Is Often Just a Stronger Narrative
Agent capability does not follow a smooth upward curve; it is jagged. A model that performs better on task set A may degrade noticeably on task set B. There are three reasons:
- Training distribution shift: A model is more familiar with certain code styles or knowledge domains and degrades in a different context.
- Context organization differences: With the same model, retrieval strategies, code chunking methods, and prompt structures can produce vastly different results.
- Tool and protocol fit: A model may be more sensitive to certain invocation patterns, and the quality of tool descriptions directly affects whether it can call them correctly.
As a result, “a certain model is stronger” is often a narrative rather than a transferable capability fact. Engineering teams must build their own task benchmarks and judge fit using real business samples rather than public leaderboards. A transferable way to frame this is:
Capability assessment = f(real task distribution, context construction quality, tool protocol clarity, acceptance criteria clarity)
If any factor is zero, the overall result approaches zero. This is also why switching to a stronger model usually does not solve delivery problems.
3. After 90% Code Generation: Cost Is Only Shifted
A common misconception is treating the share of generated code as the core metric. Suppose the generation rate reaches 90%. Is the problem solved? No. Cost shifts from development to testing, review, regression, and production operations. The faster code is generated, the larger the surface area that must be verified.
A more accurate cost model should cover the full lifecycle:
- Generation cost: Invocation and waiting.
- Verification cost: Writing tests, case coverage, and static checks.
- Integration cost: Handling conflicts with existing architecture, dependencies, and standards.
- Operations cost: Diagnosing production anomalies, rollbacks, and fixes.
If verification and integration systems are not built in parallel, a higher generation rate only amplifies downstream pressure. Therefore, the metrics for agent value should not be generation volume but delivery-side metrics such as first-pass rate, mean time to repair, and regression defect density.
4. Harness: Getting the Task Done
A Harness is the engineering system wrapped around a model that enables it to complete tasks reliably. It typically includes context assembly, tools and protocols, permissions and sandboxing, execution orchestration, logging and trace recording, and result validation. It answers the question of how an agent completes a specific task.
The key design principles of a Harness are:
- Least privilege: Grant only the minimum read, write, and execution permissions required for a task, with explicit confirmation for sensitive operations.
- Rollback capability: Land all changes in a reviewable and reversible way, such as branch-based commits and change lists.
- Observability: Record the complete execution trace, including input context summaries, tool calls, returned results, and failure reasons.
- Verifiability: The definition of task completion must be machine-checkable, such as compilation passing, tests passing, or metrics meeting targets.
It is important to emphasize that a Harness is essentially a static system: its rules are designed by humans in advance, its capability boundaries are fixed, and it does not change automatically based on execution feedback.
5. Loop: Getting Continuously Stronger
A Loop adds a feedback cycle on top of the Harness: execution results are collected, evaluated, and attributed, then used to adjust context strategies, tool descriptions, validation rules, and task decomposition. It answers the question of how an agent keeps improving.
A minimal runnable loop typically has five stages:
Execute -> Trace collection -> Automated evaluation -> Attribution analysis -> Strategy update -> Re-execute
Implementation priorities:
- Trace-level observability: Look beyond final results and be able to reconstruct the basis for each decision.
- Automated Eval: Continuously run regression against a fixed benchmark set to prevent strategy updates from introducing regressions.
- Attribution to the engineering layer: Attribute failures first to missing context, unclear protocols, or insufficient permissions, rather than “the model is not good enough.”
- Controlled changes: Version and canary strategy updates so the loop does not become uncontrolled automatic rule rewriting.
The boundary between Harness and Loop is clear: the former is a static system, and the latter is an evolving system.
6. Changing Production Relationships: From Execution to Decision and Acceptance
The most fundamental change from Harness to Loop is not a stack of technology but a shift in production relationships. Humans no longer carry the responsibility of line-by-line execution; they step in after the agent completes work to judge whether the goal is correct, the approach is acceptable, and the risk is controllable.
This imposes a hard constraint: what can be automated in a Loop is execution; what cannot be automated is decision-making and acceptance. Goal definition, priority trade-offs, business semantics, and the final call on release must still be made by humans. Any design that tries to fully automate acceptance ultimately pushes risk into production.
Therefore, the division of labor in mature teams becomes: humans define what “correct” means, agents handle how to get there faster, and the system handles how to prove it was achieved.
7. The Biggest Gap: Agents Lack Human Context
There is still a considerable distance from true self-evolution, and the core gap is that agents do not possess human context: why the business does something this way, why historical decisions made certain trade-offs, which constraints are implicit, and what results are truly usable. Most of this knowledge exists in meetings, reviews, and experience and has not been accumulated as structured assets that agents can read.
Viable directions to close this gap include:
- Build agent-readable knowledge systems: Write standards, domain constraints, and historical decisions into structured, searchable documents.
- Make code and documentation machine-readable: Clear module boundaries, explicit contracts, and parseable metadata.
- Adopt common tool protocols and isolated sandboxes: Unify invocation patterns and limit the blast radius.
- Establish multi-agent collaboration and permission control: Define role boundaries and approval chains.
- Rely on general cloud capabilities for infrastructure, such as container platforms, message queues, object storage, logging services, and monitoring and alerting, and accumulate traces and evaluation results as queryable data assets.
8. A Practical Path: Three Steps
- First, stabilize the lower bound: Improve sandboxing, permissions, rollback, and observability to ensure the worst case is controllable.
- Second, make acceptance machine-checkable: Define compilation, testing, and metrics gates for tasks to form a unified acceptance standard.
- Third, introduce the loop: On top of a stable Harness, connect automated evaluation and attribution, and update strategies incrementally with canary releases.
Baidu AI Cloud continues to invest in agent engineering and observability systems, helping teams move from “demoable” to “deliverable.”
