Harness, Loops, Graphs: What Each Layer Fixes and What It Breaks
From the publisher’s feed, collected in the ZeroLabs newsroom.
From chat to a system that learns: eight levels of agent maturity, what each layer adds, what it fixes, and the exact failure that forces you to climb.You are not using your agent. You are its loop. It writes, you read. It says “done,” you check. It breaks something, you explain what broke, and then you type again. Many “autonomous” setups still rely on a person to do three jobs the system was supposed to do: give the model a place to work, verify whether it was right, and decide what happens next.Those three jobs have names: harness, loop, graph. Most write-ups put them side by side like three tools on a shelf, and that is exactly why they feel confusing. They are not a menu. They are a ladder. Each layer exists because the one below it breaks in a specific, predictable way.The eight levels below — zero through seven — are my working model, not an industry standard. The point is not the numbering. The point is to identify the first missing capability that forces a person back into the system. One example runs through all of it: a bug report comes in, and an agent has to fix it and open a PR.Who This Is ForThis guide is for engineers and builders who run coding agents and want to know which layer to build next, instead of adding tools at random.This is for you if:✅ You spend more time checking your agent’s work than the work saves you✅ You want a diagnosis of where your current setup breaks, not another tool list✅ You care about evidence, gates, and failure modes more than demos✅ You are designing multi-step agent systems that must run unattendedThis is not for you if:❌ You want a prompt pack or a framework recommendation❌ You expect one product to solve every layer at once❌ You are not willing to write the check before the agent writes the codeTL;DRThe problem: In many agent setups, the person still provides the environment, verifies the result, and decides what happens next.The solution: Treat harness, loop, and graph not as a menu of tools but as a ladder of layers, where each layer fixes a specific failure of the one below it.The 30-second map:HARNESS = what the agent CAN do → environmentLOOP = what is actually TRUE → evidenceGRAPH = what happens NEXT → authorityThe ladder:LEVEL 0 chat you are the harness, loop, and graphLEVEL 1 harness: hands the agent can actLEVEL 2 harness: memory the agent can continue safelyLEVEL 3 loop: check the agent can be wrong out loudLEVEL 4 loop: feedback the agent can get un-wrongLEVEL 5 graph: shape the work has the right structureLEVEL 6 graph: gates failures stay localLEVEL 7 learning the same failure costs less next timeThe key insight: Skip a dependency and something else has to absorb it — usually you. The goal is not an agent that never needs you. It is a system that needs you once, at the right place.Level 0: ChatYou paste the bug report. The model suggests a fix. You copy it into your editor, run the tests, paste the error back, and ask again. Look at who is doing what:HARNESS you your hands run the codeLOOP you your eyes decide whether it workedGRAPH you your head decides what happens nextThe model is a smart function. You are the program around it. That works for a one-off question but is a terrible system for anything you do repeatedly.What breaks: you. You are the bottleneck on all three jobs at once.Level 1: Harness — Give It HandsThe first fix is obvious: let the agent touch the world. Shell, file access, a test runner, git, and a browser if the task needs one. Here is the cleanest definition of a harness I know: remove the model from your architecture diagram, and everything still on the page is the harness. Now the agent reads the repo, edits the file, and runs the tests itself. No more copy-paste.But notice what the harness actually is. It is not “more tools.” Every tool you add is one more choice the model can get wrong, so ten narrow, documented tools will usually beat forty overlapping ones. The interface matters as much as the capability. Anthropic makes a similar point in its guidance on building effective agents: tool interfaces should be clear, deliberate, and tailored to the task. Give the agent the smallest environment that can finish the job.What breaks: it acts with no durable memory and weak boundaries. Forty minutes in, the context is full of test logs; it may be compacted, and the agent forgets which fix it already tried, so it tries it again. And it has write access to everything, including the one configuration file it should never touch.Level 2: Harness — Memory and WallsTwo things are missing: state that outlives the context window, and limits that do not depend on the model behaving. Memory lives outside the model:PROGRESS.md goal fix #482: login redirect loop tried reorder auth middleware → still red known only happens when the session cookie is expired next inspect auth/refresh.py never touch migrations/Add git commits as checkpoints and pass artifacts by reference instead of pasting entire transcripts. The context window is working memory; the harness is permanent storage. The model forgets. Files do not.Walls are everything that holds even when the model is wrong: least-privilege permissions, an isolated worktree or sandbox, command allow-lists, protected paths, and hard token and time budgets. A wall is not an instruction. “Please do not touch migrations” is a wish; a permission the agent does not have is a wall. Microsoft’s guidance for agentic systems similarly recommends deterministic controls, least privilege, restricted tool access, and approval for high-risk actions rather than relying only on model instructions.Now the agent can work for an hour, resume after a crash, and stay inside a defined blast radius.What breaks: it finishes with “Fixed. All tests should pass now.” Should. The harness made the agent capable; nothing in the system makes it correct. A capable agent with no check is a faster way to be confidently wrong.Level 3: Loop — A Check That Can FailA loop is four moves: produce, check, correct, repeat. Everyone focuses on “repeat,” but the check determines whether the loop improves or merely repeats the mistake. Not all evidence is equal, so rank it by how hard it is to fake:STRONGEST deterministic tests exit 0, schema validates, build compiles observable the trace: did it really run the test, or just say so? independent a reviewer in a separate context, with a separate promptWEAKEST self-report “I’m confident,” “looks good,” “no errors”This ordering is a default, not a universal law. Different tasks require different evidence. The governing rule is simpler: a check is only as strong as the weakest evidence it accepts as proof. If your loop accepts “the model says it’s done,” your loop is based on self-report, no matter how many steps it has.So write the check for the bug before the agent writes any code:GREEN when a new test reproduces #482 the test FAILS on the current code the same test PASSES after the fix the full suite remains green the diff touches only the approved scopeLook at the first line: a test that already passes before the fix proves very little about whether the bug was reproduced. This fail-before, pass-after structure is also central to execution-based software-engineering evaluation. For example, SWE-bench constructs tasks from real issues and evaluates proposed patches by running repository tests, including tests that change from failing to passing.There is a hidden bonus here: if you cannot write the check, you probably do not understand the task well enough yet. Writing the check is writing the specification.What breaks: the agent fails, retries, and fails the same way six times. Because “red” is not feedback. It is only a verdict.Level 4: Loop — Feedback That ConvergesA verdict says “wrong.” Feedback says “wrong here, in this way, and you already tried that.” The simplest shape for it is the gap between what the agent expected and what the world did:FAILED test_expired_session_redirectEXPECTED 302 → /loginSAW 302 → /dashboardLOCATION auth/refresh.py:61FENCE auth/refresh.py onlyDEAD ENDS middleware reorderEXPECTED and SAW turn a red light into a direction. LOCATION narrows the search. FENCE constrains the next attempt. DEAD ENDS prevents attempt three from quietly becoming attempt one. This is the difference between retrying and learning inside a run. Anthropic describes a related pattern as an evaluator-optimizer workflow: one component produces work, another evaluates it against clear criteria, and the result is refined through feedback.Then come the exits, because a loop without them is not persistence. It is a cost leak:EXIT when green → done the same result returns twice → stop and escalate budget is exhausted → stop and escalateThe middle rule matters. When the agent gets the same result twice after different attempts, the loop may no longer be producing new information. The missing piece may be hidden state, unavailable data, an incorrect assumption, or a badly framed task. A loop can improve the work. It cannot always repair the question.What breaks: the work becomes excellent, one unit at a time. But the real ticket said: fix the login loop, check whether billing uses the same refresh helper, check whether admin uses it, update the documentation, and open the PR. The agent performs them serially in one context. The admin audit inherits the billing audit’s assumptions. Every individual step may be reasonable, but the whole process is slow, serial, and shaped around one opinion. No amount of loop tuning fixes this, because the failure is no longer inside a step — it is between the steps.Level 5: Graph — Give the Work the Right ShapeIn this article, a graph has three parts: a node is one bounded job with a defined input and output; an edge is a real dependency where one result determines another step; state is the information that must survive between nodes. This maps closely to concrete graph runtimes such as LangGraph, whose Graph API models workflows using shared state, nodes, and fixed or conditional edges.But the useful idea is broader than any framework. Most arrows in a workflow are not real dependencies — they are habits, the order in which someone happened to think of the steps. So run the early-start test on every arrow: what would break if B started before A finished? If the answer is “nothing,” the arrow is probably a habit. Start the billing audit before the fix lands and nothing breaks; start the final PR before the fix lands and the package is incomplete. That second dependency is real.┌─ FIX auth/refresh.py ─────┐ ├─ AUDIT billing ───────────┤ISSUE #482 → SCOPE ──────┼─ AUDIT admin ────────────┼→ MERGE → GATE → PR └─ UPDATE docs ─────────────┘A few choices determine whether the graph helps or merely looks impressive. Cut where things fail separately: if two pieces can fail for different reasons, they probably deserve separate nodes; if they always succeed and fail together, separating them may add orchestration without adding control. Separate contexts when independent judgment matters, because four agents reading and writing the same growing context are not four independent perspectives — the first conclusion can anchor the other three.Use code where the answer should be stable. Ask the same-answer question: should this step produce the same output every time it receives the same input? If yes, prefer deterministic code for merging, sorting, deduplication, validation, counting, permission checks, and policy enforcement. Use a model where multiple defensible answers are possible — not where inconsistency is merely expensive.Put gates at node boundaries. Do not wait until the final PR to discover that one audit had no evidence or the documentation changed the wrong file. Gate work when it leaves a node. A loop asks “is this piece correct?” while a graph asks “are these the correct pieces, connected by real dependencies?” You need both — each FIX or AUDIT node can run its own Level 4 loop.What breaks: two new problems appear. First, one audit fails and the entire batch runs again; the three results that already passed are regenerated — not necessarily better, only different. Second, every passing result moves at the same speed: a typo in the documentation and a change to authentication receive identical review and approval. The graph has shape, but it still lacks selective recovery and risk-sensitive gates.Level 6: Graph — Gates and Return PathsFirst rule: freeze what passed. Once a node’s output gets through its gate, treat it as read-only for the current run. If another node fails, rerun only the failed node with its feedback. Do not reopen successful work unless the failed result invalidates one of its inputs. Every unnecessary rerun of good model-generated work is another chance to introduce drift. Checkpointed graph runtimes can support this behavior by resuming from stored state rather than replaying every earlier step, although retries and external side effects still need careful, idempotent boundaries.Then gate work by the price of undo. Model confidence is the model grading its own exam; a better question is: if this action is wrong, what will it cost to reverse?ONE-CLICK UNDO revert one commit examples: docs, tests, one isolated function gate: ships when deterministic checks passCLEANUP UNDO repair dependent work examples: shared helpers, schemas, auth flows gate: green checks + trace + independent reviewNO CLEAN UNDO the action has already escaped examples: destructive migration, deletion, sent email, money movement gate: explicit human approvalThese are policy examples, not universal categories. Your thresholds should reflect your system and risk. The last tier should not have a confidence score — not 0.95, not 0.99. No number for the model to beat. For irreversible or high-impact actions, approval is a separate authority boundary. Microsoft’s guidance likewise recommends human approval for high-risk or irreversible agent actions.Inside the lower-risk tiers, read evidence in order: deterministic checks, execution trace, independent review, model confidence. The model may classify a change as “authentication-related,” but code decides what that label unlocks. The policy should exist before the run starts. Your attention is expensive. Spend it where the cost of being wrong is high, and the path back is weak.In this example, one possible policy is: the documentation change ships when its checks pass; the authentication fix waits for review on the PR; destructive or external actions require explicit approval; you read the audits only when their conclusions disagree.What breaks: the system works. Then another login bug arrives next week. The agent makes the same wrong first attempt, burns the same retries, and rediscovers the same lesson. The system has memory within one run, but it does not yet learn across runs.Level 7: The System Learns at the Layer That Owns the FailureMost teams add one feedback edge to the planner and call it learning. That is not enough. Every recurring failure belongs to a layer, and the lesson only sticks when it changes the layer that caused the failure:FAILURE LESSON BECOMES LAYERagent could not inspect production logs read-only log tool HARNESSagent retried last week’s dead approach entry in the never-list HARNESS / MEMORYagent said “fixed” without a test new required check LOOPbilling and admin audits overlapped new decomposition rule GRAPHagent attempted a destructive action stronger approval gate GRAPH / POLICYPut the lesson on the wrong layer and it becomes advice. “Be careful not to duplicate work” in a prompt is a hope; a decomposition rule in the planner is structure. “Remember to run the test” is a reminder; a gate that rejects untested work is enforcement. And a lesson is not a transcript — do not feed next week’s agent every log from this week. Extract the smallest durable constraint the failure taught you.The standard for Level 7 is not that failure disappears forever. That would be another false promise. The better standard is: the same class of failure should cost less the second time.Which Level Are You On?SYMPTOM NEXT MISSING LAYERyou copy-paste between chat and terminal 1 harness: handsthe agent retries approaches it already tried 2 harness: memory“done” means nothing until you check it 3 loop: checkretries burn budget on the same result 4 loop: feedbackevery step is reasonable, but the whole is slow 5 graph: shapeone failure causes broad rework 6 graph: gatesthe same mistake returns every week 7 learningFind the first symptom from the top. That is probably your next layer — not the most impressive one, not the one a framework demo happens to emphasize, but the first missing one.How to ClimbYou do not need to build all eight levels. Many bounded tasks can stop at Level 4. A coding task with a safe environment, durable state, a reproducing test, useful failure feedback, and a clear exit condition may not need a graph at all. Climb only when the failure at the current level costs more than building the next layer.And while dependencies matter, implementation does not always happen in a perfectly linear order. One framework may bundle memory, graphs, and checkpoints; another may give you tools before permissions. The labels are less important than the missing capability. Ten agents without checks do not give you ten times the useful output; they give you ten sources of work to verify. A perfect loop without a harness still has nowhere to run its tests. A sophisticated graph without clear node-level checks only organizes uncertainty.Before building anything, write the Level 3 check on paper. If you can describe what green means, you can work backward: which tools must the harness provide? Which state must survive? Where should work split? Which outputs need gates? Which actions require a person? What lesson should survive into the next run? If you cannot define green, another layer will not save you.Conclusion: The Short VersionA harness makes the agent capable. A loop makes its claims testable. A graph gives the work structure and authority boundaries. Learning makes the next run cheaper than the last one. Skip a dependency and something else has to absorb it. Usually, that something is you.The goal was never an agent that never needs you. It is a system that needs you once, at the right place.Which symptom is your current stack showing — and which layer is actually missing?Sources and Further ReadingAnthropic, “Building Effective AI Agents” — tools, workflows, evaluator-optimizer loops, environmental feedback, and stopping conditions.LangChain, “LangGraph Graph API” — state, nodes, edges, checkpoints, retries, and execution boundaries.Jimenez et al., “SWE-bench: Can Language Models Resolve Real-World GitHub Issues?”, ICLR 2024 — repository-scale tasks and execution-based evaluation.Microsoft, “Identify Risk for Autonomous Agentic AI Systems” — least privilege, deterministic controls, oversight, logging, and approval for irreversible actions.Harness, Loops, Graphs: What Each Layer Fixes and What It Breaks was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.