From Harness to Graph: A Three-Layer Engineering Method for Agent System Architecture
As large language models move from prompt experiments into production agents, results often depend less on the model itself than on the engineering around it. This article explains a three-layer method—Harness, Loop, and Graph—covering what each layer owns, where it fails, and how the layers work together.
From Harness to Graph: A Three-Layer Engineering Method for Agent System Architecture
As large language models improve, model-based agent systems are moving from prompt toys toward production use. Many teams find that the same model can produce very different results under different engineering implementations. The reason is that agent quality depends not only on the model, but on the architecture built around it. A shared layered framework has emerged: Harness engineering, Loop engineering, and Graph engineering. This article examines the responsibilities, core challenges, and engineering practice of each layer.
1. Why a layered view is needed
Before going further, consider a common question: why not design an agent as one whole system?
The reason is complexity control. A production agent faces three kinds of problems that are fundamentally different:
- Environment problems: how the model reads and writes the outside world safely and reliably, including files, databases, and APIs.
- Decision problems: how the model plans, acts, reflects, and corrects errors within a single task.
- Collaboration problems: how multiple agents, or multiple roles, divide work, communicate, and combine results.
These problems have different failure modes, debugging methods, and rates of change. If they are mixed into one design, the code quickly becomes an untestable ball of mud. The value of layering is that each layer has clear responsibilities and interfaces, so it can evolve and be tested independently.
2. Layer one: Harness engineering—letting the model touch the world safely
The term harness comes from testing frameworks, where it means the runtime environment wrapped around the system under test. In an agent context, Harness engineering addresses the boundary between the model and the outside world.
2.1 Core responsibilities
- Tool registration and description: Expose capabilities such as file operations, code execution, and retrieval through a normalized schema. Description quality directly affects how accurately the model calls tools, and this step is easy to underestimate.
- Sandboxing and permission control: Every model-triggered action must run in a restricted environment. Code execution should isolate the file system and network; command execution should use an allowlist and time out with a circuit breaker.
- Input and output normalization: Parameters returned by the model often do not strictly match the schema. The Harness layer should validate, correct, and retry them instead of letting dirty data pass into business systems.
- Observability instrumentation: Inputs, outputs, latency, and errors for every tool call should be recorded in a structured form. This is the foundation for all later debugging.
2.2 A minimal example
@tooldef read_file(path: str) -> str:"""Read the contents of a text file inside the workspace"""if not is_within_workspace(path):raise PermissionError("Path is outside the allowed workspace")return Path(path).read_text()[:MAX_CHARS]
Two details matter: the path-boundary check (a security boundary) and content truncation (a context budget). Both should happen in the Harness layer, not depend on the model policing itself.
2.3 Engineering points
The design principle for the Harness layer is “thin but hard”: keep the logic thin, with no business decisions mixed in, and keep the constraints hard so that validation cannot be bypassed. A common anti-pattern is writing business rules into tool descriptions, which can mislead the model on unrelated tasks.
3. Layer two: Loop engineering—the quality of the single-task loop sets the floor
Above the harness is Loop engineering: the familiar observe–think–act cycle. The model receives a goal, chooses a tool, observes the result, and decides the next step until the task is complete or a stop condition is met.
3.1 Four core problems in the Loop layer
- Context management: As rounds accumulate, history and tool results grow quickly. Compression strategies are needed—for example, summarizing early tool output and trimming redundant failed retries—so that critical information stays inside the context window.
- Stop conditions: Do not rely only on the model saying it is finished. Combine multiple signals: goal verification, a maximum number of rounds, a cost budget, and detection of consecutive lack of progress.
- Error recovery: When a tool call fails, should the raw error be returned to the model, or should the system first classify the cause and add guidance? The latter can significantly improve recovery. For example, classify a network timeout as a temporary, retryable failure and attach a retry suggestion.
- Reflection and self-correction: Insert checks at key points so the model compares current output with the original goal and backtracks when it finds a gap. This is more robust than a naive loop that follows one path to the end.
3.2 A pseudocode skeleton
while steps < MAX_STEPS and not budget_exceeded():action = llm.decide(context)result = harness.execute(action) # safe executioncontext = compact(context, result) # context compressionif goal_checker.verify(context): # independent verificationbreak
The central insight of Loop engineering is that the loop structure itself carries a large amount of prior knowledge. When to compress, when to verify, and when to force replanning are engineering decisions that often improve results more than switching to a stronger model.
4. Layer three: Graph engineering—from a single agent to structured collaboration
When a task is too complex for one agent, Graph engineering is needed. Multiple agents—or multiple role configurations of the same agent—are organized as a directed graph. Nodes are execution units with specific duties; edges are control flow and data flow.
4.1 What the Graph layer solves
- Task decomposition and routing: A planning node splits the overall goal into subtasks and routes them to execution nodes by semantics or rules.
- Parallelism and aggregation: Independent subtasks run in parallel, and their results are merged at an aggregation node. This matters especially for latency-sensitive scenarios.
- Human intervention points: Human approval at critical decision nodes is a sign that a production system is moving from a demo toward something trustworthy.
- State persistence and recovery: Intermediate graph state should be persisted so long-running tasks can resume from a checkpoint after a failure instead of starting over.
4.2 The payoff of layering
The value of the Graph layer is not that “more agents are always better than one.” It is the maintainability that comes from separation of concerns: each node has a single responsibility and can be tested and replaced independently, and the overall flow can be visualized so bottlenecks and failure points are clear. Forcing a simple task into a multi-agent graph only adds communication overhead and the risk of cascading failure. Graph structure should follow task complexity, not technical fashion.
5. The three layers together: a complete engineering mental model
Taken together, the three layers form a mental model:
| Layer | Focus | Key metrics | Typical failures |
|---|---|---|---|
| Harness | Environment and tool boundaries | Call accuracy, safety | Unauthorized actions, schema errors |
| Loop | Single-task decision cycle | Task completion rate, cost | Infinite loops, context overflow |
| Graph | Multi-node orchestration | End-to-end success rate, recoverability | Routing errors, lost state |
When debugging, work from the bottom up: first confirm that tool calls are reliable (Harness), then check whether the loop converges (Loop), and finally review whether orchestration is sound (Graph). When building, design from the top down: draw the task graph first, then define the loop strategy for each node, and finally implement tools and sandboxes.
6. Conclusion
Agent engineering is evolving from prompt tuning into serious systems engineering. The main value of the Harness, Loop, and Graph framework is a map of complexity: what each layer should solve, how to verify it, and when to evolve it. For teams preparing to take agents into production, a stronger foundation across these three layers matters more than chasing every new model release. Model capability will rise over time; solid engineering architecture is what turns that capability into stable results.
