Harness Engineering in Practice: Building the Control Layer for AI-Assisted Coding from Scratch

Harness Engineering builds a three-layer environment around AI coding Agents for reliable, continuous output in real projects.
This article introduces a course on Harness Engineering — building a complete working environment around AI coding Agents to prevent drift during continuous real-project modifications. It frames AI engineering as three evolutionary stages: prompt engineering, context engineering, and harness engineering, arguing that the real pain point is cumulative drift over long multi-round sessions, not single-turn quality. The harness has three layers: an information layer for project comprehension, a constraint layer to prevent out-of-scope changes, and an automation layer for self-verification and correction. A Java project serves as the hands-on vehicle, and the course concludes with a landing checklist and retrospective.
Harness Engineering in Practice: Building the Control Layer for AI-Assisted Coding from Scratch
Most people hit the same wall when trying to get AI to help write code: a single Q&A session looks impressive, but the moment you ask it to make continuous changes to a real project, things go sideways — it modifies files you never mentioned, deletes logic you wanted to keep, and confidently declares "done" while the code won't even run. This Harness Engineering course on Bilibili tackles exactly that problem. The answer isn't fancier prompts — it's building a complete environment around the Agent so it can understand your project, respect its boundaries, and verify its own work when it's done.
What Is Harness Engineering
The word "harness" already has a traditional meaning in software engineering — a test harness is the scaffolding wrapped around code under test, responsible for feeding in inputs and validating outputs. In the context of AI-assisted coding, it refers to the complete working environment built around a coding Agent: how the project structure is presented to it, where constraint rules are declared, who verifies its changes, and how it returns to a correction loop when verification fails.
The course translates this as "驾驭工程" (control/harness engineering), a rendering that captures the essence. A harness is neither a specific tool nor a longer prompt. The prompt determines what the Agent says in a single turn; the harness determines what the Agent can see throughout the entire project lifecycle, what it's allowed to do, and how mistakes get caught. The former is one-shot; the latter runs continuously.
Historically, the concept of a test harness originated in unit and integration testing — a piece of auxiliary infrastructure that drives code execution, constructs inputs, triggers runs, captures outputs, and compares them against expected values. It's not part of the business logic itself, yet it determines whether testing can be automated. Classic frameworks like JUnit and pytest are concrete implementations of this idea. Transplanting this concept to the AI Agent world is a remarkably precise metaphor: the Agent is the execution unit being "harnessed," and the harness is the surrounding structure that controls what information it can access, what rules it operates under, and how its outputs are validated. The analogy also implies a core assumption of Harness Engineering — the Agent itself doesn't need to be perfect. As long as the external structure is robust enough, the overall system can run reliably, just as imperfect code can still be caught by a thorough test suite.
Three Paradigm Shifts in AI Engineering
The course divides AI engineering practice into three stages — a framework far more useful than simply listing tools:
Prompt Engineering focuses on the wording of individual interactions: how to phrase a question so the model answers well.
Context Engineering focuses on the information fed to the model — which files to include in the context window, which history to truncate, how to rank retrieved content.
Harness Engineering focuses on whether the entire closed loop, once assembled, can run reliably and sustainably.
The first two stages answer the question "did the model respond well this time?" The third answers "after a hundred consecutive modifications, is the overall output still under control?" In real projects, the persistent headache is never single-point quality — it's cumulative drift.
The concept of Context Engineering was explicitly articulated and widely cited by figures like Andrej Karpathy in recent years. The core argument: for modern large language models, what determines output quality is no longer the craft of prompt wording, but the quality and organization of information fed into the context window — which documents get retrieved, how conversation history is trimmed, how tool-call results are formatted. RAG (Retrieval-Augmented Generation) is essentially a context engineering practice. In Agent scenarios, the complexity of context engineering increases further, because Agents continuously generate new intermediate states across multiple execution rounds. Managing those states so they don't overflow the window or introduce noise is itself an engineering challenge. Harness Engineering takes one more step forward, focusing on the architecture of the entire execution loop rather than the assembly of a single context.
Why Agents Keep Going Off the Rails
The course dedicates a full section to common Agent failure patterns — arguably the most practically valuable part, because each failure mode maps directly to a missing piece in the harness:
- Scope drift: The Agent unilaterally expands its changes, casually refactoring modules it was never supposed to touch.
- Missing context: The Agent never saw a certain convention or past decision, so it reinvents the wheel or reverses an existing design.
- Hallucinated completion: The code is written but never compiled or tested, yet the report says "all done."
- Unverifiable output: The result lacks any checkable criteria, forcing humans to read every line of code to judge correctness.
What all these failures have in common: none of them are caused by insufficient model capability. They happen because the environment failed to provide the Agent with a basis for judgment.

The Core Components of a Harness: Three Layers
The structure the course proposes breaks down into three layers, each building on the last:
The Information Layer solves "helping the Agent understand the project." How the project is organized, the relationships between modules, where key conventions are documented — all of this should be discoverable by the Agent without asking a human.
The Constraint Layer solves "preventing the Agent from making mistakes." Boundaries that shouldn't be crossed and standards that must be followed are declared explicitly, rather than relying on the model to behave itself. This layer is the primary mechanism for preventing runaway changes.
The Automation Layer solves "who validates the work when it's done." After development, the Agent runs its own verification; when problems are found, it loops back to correction. This layer determines whether the entire workflow is self-sustaining or requires human intervention at every step.
All three layers together form a loop that can work continuously. With only the information layer, the Agent understands the project and then makes arbitrary changes. With only the constraint layer, the Agent follows rules but can't get anything done.
In practice, the automation layer is typically implemented using CI/CD infrastructure or local scripts. After the Agent completes code changes, a predefined validation pipeline is triggered: first the compiler checks for syntax errors, then the unit test suite runs, and optionally static analysis or code style checks follow. If any step fails, its error output is structured and fed back to the Agent as input for the next correction round. This aligns closely with the philosophy of Continuous Integration (CI) — the key difference being that traditional CI feeds results back to human developers, whereas here the feedback recipient is the Agent itself. This design makes "human-in-the-loop" optional rather than mandatory: humans only need to intervene when the Agent repeatedly fails to pass verification, not after every single change. This is the central mechanism that makes the entire Harness "sustainably operational."
Distilling Principles from Others' Best Practices
The course references publicly shared engineering practices from teams at OpenAI and other leading AI organizations. Their approaches differ in specifics, but a few common lessons emerge that are worth internalizing:
- Write constraints as explicit files in the project, not verbal agreements in chat history — chat disappears, files don't.
- Give the Agent executable verification tools; tests and type checks are far more reliable than "does this look right to you?"
- Every step's output should have a clear completion criterion, to avoid the "looks done" problem.
- When errors recur, encode the fix into the environment itself rather than manually correcting it each time.
Understanding these principles is a prerequisite for putting them into practice. As the course puts it: once you've internalized the principles, integrate them into your own project development workflow.

Hands-On: Building a Java Project from Scratch
The practical portion of the course uses Java, building a Harness development environment from zero with the goal of completing an entire workflow by describing requirements — with minimal hand-written code. The choice of Java is pragmatic: Java projects have relatively standardized structures and build toolchains, and mature verification tools (compiler, test frameworks) are readily available, which amplifies the impact of the automation layer.
The hands-on work follows the layered structure described earlier: first helping the Agent build an understanding of the project, then establishing constraint rules, then connecting automated verification and correction. Along the way, the course draws comparisons between mainstream AI coding tools, explaining which one to reach for at each stage of the workflow. This perspective is more useful than simply recommending a single tool, because the right tool depends entirely on where you are in the process.


A Landing Checklist and Lessons Learned
The course closes on two fronts: a retrospective on the completed project, summarizing common mistakes and pitfalls; and a Harness Engineering landing checklist that breaks down the entire workflow into individually verifiable items.
For anyone ready to get started, a checklist is more useful than a step-by-step tutorial. A tutorial can only reproduce one specific path; a checklist can be applied to your own project. The value of the retrospective lies in this insight: the pitfalls you'll encounter are usually not model failures — they're gaps in your environment design.
At its core, Harness Engineering addresses an engineering problem, not a prompt technique problem. Models will continue to get stronger, but "making an autonomous Agent reliably produce usable code" has always depended on environment design: what it can see, what range of actions it's constrained to, and how mistakes get caught. Get those three things right, and it's worth more than chasing any new tool.
The checklist format has solid methodological backing in software engineering. Research on pilots using pre-flight checklists shows that even highly experienced experts benefit from systematic item-by-item verification in high-complexity, multi-step tasks — it significantly reduces omission rates. Breaking down Harness construction into independently verifiable items also facilitates team collaboration: when different members are responsible for different layers, the checklist provides a shared acceptance standard and reduces the "I assumed you handled that" communication overhead. This is especially important for AI Agent projects — gaps in environment design rarely surface immediately. They become visible only after the Agent has accumulated several rounds of erroneous behavior, at which point tracing the root cause is expensive. Using a checklist for structured upfront review is an effective way to control this kind of cumulative risk at the source.
Related articles

Random Pruning of the DPO Computation Graph: 1.4x Training Speedup and Lower Peak Memory
DPO training too slow and memory-hungry? This paper proposes a random pruning framework for the DPO computation graph, sampling independently across position, sequence, and branch dimensions; branch pruning achieves a 1.426x step-time speedup and cuts training time by about 30%, with in-depth attribution of memory and time gains.

Why Does JEPA Underperform MLM in Longitudinal EHR Representation Learning?
New study compares JEPA and MLM for longitudinal EHR representation learning on MIMIC-IV: three JEPA variants train stably without collapse but underperform MLM; target size, not heterogeneity, drives prediction error.

Transfer Learning + Visible Light Communication: A New Approach to Energy-Efficient Indoor Positioning
A study proposes a transfer learning-based visible light communication indoor positioning method, achieving 47% accuracy improvement on the BOSCH factory dataset, 67.5% model efficiency under high noise, and introducing the ME composite metric for energy-efficient positioning in energy-constrained industrial IoT scenarios.