Agent Harness Architecture: The Three Layers That Make an AI Agent Run, Last, and Stay Stable
A recent leak of internal implementation code from a mainstream AI coding tool offers a rare look inside a production-grade agent system. This article uses that material to explain what an Agent Harness actually is, why calling it a "wrapper" undersells it, and how a three-layer architecture — execution, state, and governance — separates agents that merely run from agents that run for hours and stay controllable. You will find the core design points of each layer, a pseudocode sketch of the execution loop, and practical takeaways for auditing your own agent system.
Agent Harness Architecture: Reading a Source Code Leak to Understand the Three Engineering Layers
1. Background: A Rare Teaching Specimen
Not long ago, part of the internal implementation code of a mainstream AI coding tool was leaked unintentionally. For anyone working on agents, this is close to a teaching specimen falling out of the sky. Until now, we could only guess from the outside, treating large agent systems as black boxes and speculating about what they actually do internally. This time, the design thinking behind key modules was laid out in full in front of developers.
During a period of rapid technical change, deliberately studying first-hand material like this tends to produce a far larger gain in understanding than routine day-to-day accumulation. This article abstracts those observations into general engineering principles for agent developers.
2. What an Agent Harness Is: From “Wrapper” to Engineering System
“Agent Harness” is often jokingly described as another name for a “wrapper,” but that framing badly underestimates its engineering value. Strictly speaking, an Agent Harness is the runtime environment and control system built around a large model’s capabilities: the model itself is only responsible for “thinking,” while the harness is what makes those thoughts actually land — scheduling tools, managing context, maintaining state, and handling failures.
The analogy: the large model is the engine, and the harness is the chassis, transmission, and control system of the whole car. Without the latter, no amount of engine power turns into a vehicle that can be driven on a road. Understanding this is the first step from “calling an API” to “building an agent system.”
3. The Three-Layer Framework: Runs → Runs Long → Runs Reliably
The leaked material yields a clear three-layer architecture, which also maps to three stages in the evolution of an agent system.
3.1 Execution Layer: Making the Agent Run
The execution layer solves the most basic problem: receive task → build prompt → call model → parse output → execute tool → feed result back. Its core design points are:
- Standardized tool protocols: declare each tool’s name, parameter schema, and return format in a structured way, so model output can be parsed and executed deterministically;
- Loop-driven task execution: an agent is not a single question-and-answer exchange but a continuous loop of observe–think–act. The execution layer must keep this loop drivable, interruptible, and resumable;
- Error fallback: when a tool call fails, the failure must be turned into feedback the model can understand, so the agent can correct itself instead of crashing outright.
Illustrative pseudocode:
while not task.done:observation = env.get_current_state()action = model.plan(observation, task.goal)result = env.execute(action) # wrapped in exception handlingtask.log(action, result)if retries > MAX: task.mark_failed(); break
3.2 State Layer: Making the Agent Run Long
The execution layer handles a single loop iteration; the state layer handles long-horizon tasks. When a task runs for hours and spans thousands of tool calls, the context window will inevitably overflow, which requires a dedicated state management mechanism.
Several key ideas revealed in the leaked material are worth borrowing:
- The “zero-context management” philosophy: do not expect the model to “remember everything.” Instead, externalize state as much as possible into persistent media such as the file system or a database. Keep only the minimum information needed right now in context, and load historical detail on demand through retrieval. This converts unreliable “memory” into auditable “storage”;
- Relay-style handoff: when a long task reaches the context boundary, rather than truncating crudely, have the previous segment produce a structured handoff summary — goal, completed steps, remaining work, key decisions, and caveats — to serve as the starting point for the next segment. This is similar to a work handoff in a team, and lets a task cross the lifetime of a single session like a relay race;
- Checkpointing: periodically persist snapshots of task state, together with a log service, which supports resume-from-breakpoint and makes after-the-fact auditing easier.
3.3 Governance Layer: Making the Agent Run Reliably
The governance layer answers: how do we keep agent behavior controllable, observable, and improvable?
- Permissions and sandboxing: which files can be written, which commands can be executed, which network destinations can be reached — all need explicit permission declarations and the principle of least privilege. The tiered approach of “more context, less control” for routine work versus “strong control on critical operations” is the most thought-provoking point in the leaked material: give the model ample freedom on low-risk operations, and introduce human confirmation or hard constraints on high-risk ones such as deletion, commits, and deployments;
- Observability: record the input, output, tool calls, and elapsed time of every step in full, and connect them to a unified logging, monitoring, and alerting stack so agent behavior can be replayed and diagnosed;
- “Dreaming”-style memory maintenance: one interesting mechanism is to have the agent tidy up, distill, and consolidate accumulated session records during idle periods — much like memory consolidation during human sleep. Systematically settling frequently encountered experience into reusable knowledge entries and retiring outdated information makes the agent “smarter the more it is used.” In essence, this is an automated process for turning individual experience into organization-level assets.
4. Practical Takeaways for Developers
- Build the skeleton first, intelligence second: most agent projects fail not because the model is too weak but because the state layer and governance layer are missing. The execution loop is only the beginning; persistence and handoff for long-horizon tasks are the real dividing line;
- Treat context as a scarce resource: externalized state, on-demand retrieval, and structured handoff are the general-purpose trio for long tasks;
- Tier your controls: draw the line at risk — grant freedom for low-risk work, add gates for high-risk work — to balance efficiency and safety;
- Establish a learning loop: design a mechanism that automatically accumulates experience and consolidates it periodically, and the agent’s value will compound with usage time.
5. Conclusion
The greatest value of this source code leak lies not in any specific implementation detail but in restoring “agent system” from a buzzword to engineering language that can be learned and reproduced: the execution layer makes an agent run, the state layer makes it run long, and the governance layer makes it run reliably. Developers building agent applications should audit their own systems against these three layers — wherever a layer is missing, that is the layer to add. Understanding these general principles will let you build a more robust, continuously evolvable intelligent system regardless of which model service or cloud platform you use.
