Harness Engineering in Practice: Building Controllable AI Agents
This article introduces Harness engineering, the systems practice of designing constraints, feedback loops, workflow control, and continuous improvement cycles around AI agents instead of tuning model parameters. It defines the scope of Harness engineering, explains a six-layer architecture from goals and guides to sensors and improvement loops, analyzes why agent bottlenecks usually sit in the harness, and provides a prioritized P0/P1/P2 rollout checklist with a minimal programmatic feedback loop. Readers will learn how to turn unpredictable model behavior into controllable, observable, and iterable agent systems.
Introduction: When the Model Is No Longer the Scarce Resource
A simple formula often circulates in the industry: agent = model + harness. After prompt engineering and context engineering, harness engineering has started to attract frequent discussion. It answers one core question: what determines the ceiling of an agent’s performance—the model itself, or the control system around it?
A commonly cited phenomenon illustrates the point. With the same model and the same set of tasks, merely changing the input/output interface format and constraints raised the evaluation pass rate from a single-digit percentage to nearly 70%. Not a single byte of the model weights changed. Only the environment around the model changed. This suggests that the marginal return on engineering effort is shifting from “switch to a stronger model” to “build a better environment.”
1. Defining Harness Engineering and Its Boundaries
Harness engineering is the systems engineering practice of designing constraint mechanisms, feedback loops, workflow control, and continuous improvement cycles around an agent. It does not optimize internal model parameters; it optimizes the external conditions under which the model runs.
The term comes from animal harness equipment—the complete guidance system made up of reins, saddles, and bits. The goal is not to weaken the animal’s power but to make that power predictable and controllable. The engineering meaning maps directly: the aim is not to make the model dumber, but to make it run fast and reliably.
Three boundaries need to be clear:
- Difference from prompt engineering: a prompt is a single-point input construction, while a harness is a closed-loop system that includes input construction, tool exposure, execution orchestration, and result verification.
- Difference from model selection: selection is a procurement decision, while a harness is a continuously operated capability.
- Difference from orchestration frameworks: orchestration is only the execution layer of a harness. Orchestration without sensors and an improvement loop is just a script.
The industry has gradually adopted a taxonomy of “guides” and “sensors,” dividing harness components into feedforward control and feedback control. This naming is now widely used.
2. The Six-Layer Architecture
Layer 1: Goals and policy. Define the agent’s success criteria, actionable boundaries, and prohibited actions. This layer outputs verifiable acceptance criteria, not vague statements like “do your best.”
Layer 2: Guides. This includes system prompts, project-level rule files, task templates, and example libraries. The engineering key is to write rules as structured, referenceable entries rather than long prose. Example:
# Project Constraints- Unit tests must pass before any commit, with coverage no lower than the existing baseline- Do not modify already-merged files under the migrations directory- All network calls must set a timeout and a retry limit
Layer 3: Data and context. This decides what the model “sees.” Retrieval strategy, document chunking granularity, code indexing, and conversation history trimming all live here. Most complaints that “the model got dumber” are rooted in context pollution rather than insufficient capability.
Layer 4: Tools and actions. Tool granularity, naming, parameter schema, and error message quality directly determine call success rates. One design principle: error messages should be actionable repair guidance, not internal stack traces.
Layer 5: Sensors. This includes automated evaluation sets, static checks, test execution, manual spot checks, and production monitoring alerts. An agent without sensors cannot iterate; it can only tune prompts by feel.
Layer 6: Improvement loop. Feed failure cases back as evaluation samples, rule entries, or tool changes to close the loop. This layer is the dividing line between a harness and a script.
3. Why the Bottleneck Is Usually the Harness
There are three reasons. First, interface impedance: when the model’s output format does not match what downstream systems expect, failures are misdiagnosed as reasoning errors. Second, missing feedback: without verification, errors accumulate and amplify across multi-step tasks. Third, context mismatch: the model cannot see the information required to complete the task, or it sees too much irrelevant information.
A reusable minimal feedback loop looks like this:
def run_task(task, agent, verifier, max_rounds=3):ctx = build_context(task) # Data and context layerfor i in range(max_rounds):draft = agent.invoke(ctx) # Action layerok, feedback = verifier(draft) # Sensor layerif ok:return draftctx = append_feedback(ctx, feedback) # Feedback loopraise TaskNotConverged(task.id)
The key is that verifier must be a programmatic, repeatable criterion. Any step that requires subjective human judgment should be pushed down into rules or tests wherever possible.
4. Rollout Checklist: P0 / P1 / P2
P0 (do not launch without it): verifiable acceptance criteria; a structured project rule file; a programmatic verifier; normalized tool error messages; full-chain logging.
P1 (determines stable operation): tiered evaluation sets and regression baselines; context trimming and retrieval strategy; a failure-case feedback mechanism; cost and latency budgets; least-privilege permissions and secondary confirmation for sensitive operations.
P2 (determines scalability): multi-agent division of labor and handoff protocols; automated evaluation pipelines linked with monitoring alerts; versioning and canary rollout of rule entries; reusable harness templates for different business lines.
In practice, container platforms can provide environment isolation, object storage can hold evaluation samples, message queues can smooth traffic peaks, and logging and monitoring services can handle observability. General-purpose capabilities from cloud providers such as Baidu AI Cloud typically cover these needs.
Conclusion
The essence of harness engineering is turning “praying the model performs well” into “using a system to guarantee controllable behavior.” The core philosophy can be summarized in eight words: humans steer, agents execute. As model quality gradually becomes a basic threshold, differentiation comes down to the guidance and sensing system outside the model—if you are not the model, then you are the harness.
