All video posts

AI agents · AI engineering · Claude Code

Loop and Graph Engineering, Explained Simply

There is a lot of talk that instead of prompting agents you should be writing loops or defining graphs. My first reaction was suspicion: is this just a way to get us spending more tokens? My answer: they are real, they are not new, and you are probably already doing parts of them. But naming them changes how well you do them. I learned that the hard way when I lost most of a day to a bug.

Deric YeeDeric Yee 4 November 2026 8 min read 10 min video

Prefer to read? The full article is below. Watch on YouTube.

The short version

  1. 1A prompt runs once and you judge the result. A loop gives the agent a task plus a pass condition, and it keeps going until it passes.
  2. 2"Build me a levelling system" is a wish, not a success criterion. Write checks that are simply true or false.
  3. 3Four loop types are really four levels of trust: turn-based, goal-based, time-based and proactive. Climb one rung at a time.
  4. 4When one agent holds too big a job, its context window overflows and it forgets constraints. Split the work into a graph of focused agents.
  5. 5The compounding skill is no longer describing what to build. It is describing what done looks like.

The bug that taught me this

I run a learning platform for our students, and it has a levelling system: you earn XP, hit a threshold, and level up. A straightforward feature. I did what I always do: described it properly, gave the agent context, set a goal and let it run. It came back saying it was done. I tested it, and it looked good.

Except it had quietly broken another feature, our streaks logic, on the way through. I did not notice for two or three days. My first thought was that the model was not good enough. It was not that. I had told it what to build, but I never properly defined what done meant. Those are completely different things, and that gap is where I think most people are losing time right now.

Prompt vs loop

A normal prompt works like this: you ask, it does the thing once, hands it back, and you review it and decide if it is good. You are doing the quality check every round.

A loop moves that job to the agent. You give it the task and the condition it has to pass. It does the work, checks itself against the condition, and if it fails, goes again, and again, until it passes. Then it stops. There are three parts: a start (a schedule, a rule, or you kicking it off), the task, and the success criteria. Without an end criterion you get the famous infinite loop.

Of those three, only the success criteria is really interesting. "Build me a levelling system" is not a criterion. It is a wish. There is nothing for the agent to check itself against, so it builds something reasonable, decides it is probably fine, and hands you something 70 or 80% done. That is the worst outcome, because now you have to find the missing 20% yourself, and you will not know where it is until someone sends a bug report.

What I write now looks like: the tests pass, XP thresholds trigger correctly at the boundary, and streak logic still behaves. Every line is simply true or false. No judgement left anywhere. We go deeper on this in our written guide to loop engineering.

“I told it what to build, but I never properly defined what done meant. Those are completely different things.”

Deric Yee, in the video

Loops work outside code too

Our platform has computational thinking challenges for students, and writing them by hand is slow. But each challenge has hard, checkable requirements: exactly one correct answer, a reference solution that actually runs, a difficulty within the band we want rather than secretly brutal, and it must teach the specific concept it is meant to.

None of that is taste. All of it is checkable. So it loops: generate, test itself, bin the failures, go again. Instead of sitting through each challenge one by one, I review the whole batch at the end. That is how we produced hundreds of them.

Four kinds of loop, four levels of trust

Anthropic's engineering team wrote up different loop patterns, and it is worth reading. Here is the version that stuck with me:

01

Turn-based (your intern)

You prompt, it gathers context, acts, verifies what it can, and decides itself when to stop. It can live in a skill file: list the steps, then "if any step fails, fix it and rerun from step one".

02

Goal-based

You stop being the judge and give it a number: not "make the site faster" but "reach a Lighthouse score of 90+". In Claude Code that is the /goal command. Always cap the attempts, or a badly written condition grinds forever on your bill.

03

Time-based

Runs on an interval: check my PRs every five minutes, handle new comments, fix failing CI. /loop runs on your own machine (laptop off, loop off). /schedule runs in the cloud. I have one fixing errors overnight before I wake up.

04

Proactive (your senior hire)

A ticket lands and the agent picks it up and solves it; you find out afterwards. I rarely use it yet, because it may lack context on the product decisions I care about.

Climb the trust ladder one rung at a time

Those are not really four features. They are four levels of trust, the same ladder you use with people. With an intern you spell out each step: run Facebook ads, build creatives, click this, look at these numbers. With a senior hire you say "I want more revenue from ads" and they figure it out. That unsupervised judgement is what companies pay seniors a lot for.

Each rung up is not more capacity. It is more unsupervised judgement, which means more mistakes can happen while you are not watching. So you climb one rung at a time, only after the rung below has earned it.

Why one agent with a big job goes weird: graphs

Loops did not fix my second problem. After the levelling feature I got ambitious and handed one agent a much bigger job: build the feature, write the tests, update the docs and check it against the design. It started fine, then got progressively weirder. It forgot constraints from the beginning and contradicted decisions it had made 40 steps earlier.

That is not a model problem. It is a context window problem. The agent is holding the entire job in one context, and past a certain load it stops being reliable in ways that are hard to spot. Like your brain: remembering one thing is easy, remembering a thousand is not. It is the same reason you do not give one person on your team every job. You give them one goal and a few tasks to focus on.

The fix is to stop using one agent and draw a map instead: this agent does this, that one does that, here is the order, here is what depends on what. That map is a graph, and each agent gets its own clean context. If you have ever told Claude Code to spin up sub-agents in parallel, one hunting for frontend inspiration, one fixing the backend, one writing tests, all reporting back, you have already built one. It does not have to be parallel either: implement, then verify, then advise, then fix is a sequential graph. Our written guide on graph engineering goes further.

Loops inside graphs, and when to use which

The part I found most useful is that they nest. Any node in a graph can itself be a loop. Give that research node a success criterion for what a good frontend reference looks like, and now it loops inside your graph. It was never loops versus graphs. A loop is just a graph with a cycle in it. If you want to push further, look at dynamic workflows in Claude Code, which are scripts that orchestrate those dependencies for you, for example auditing every route handler for missing auth checks file by file.

None of this is new. LangChain's LangGraph library has done this for years. The vocabulary just became famous in 2026.

The simple rule: a repeating task with a finish line is a loop, one agent. A job with real dependencies between parts is a graph, multiple agents. Not because it is elegant, but because each agent starts clean, does one job, and hands over a finished result instead of everything it weighed and discarded along the way.

The real lesson: brief properly and define done

What I really took away was neither loops nor graphs. I spent two years getting good at describing what I wanted to build and almost no time getting good at describing what finished looks like. The second is now the whole game.

So the compounding skill is not coding or design any more. It is briefing properly and knowing how much judgement you are willing to hand over. That is management. Same job, different hire.

Writing pass conditions that actually catch bugs, like my broken streaks, still requires understanding the system you are building: what can break, where, and how to test it. That is why our AI-Native Software Development Programme teaches fundamentals and agentic workflows together. You can try the first lessons in the free trial, and if agents are still new to you, start with AI agents explained like you're 10.

Questions people ask

  • What is loop engineering in AI?

    Loop engineering means giving an AI agent a task plus a clear pass condition, so it keeps working, checking itself, and retrying until the condition is met. The key is writing success criteria that are simply true or false, such as tests passing or a Lighthouse score above 90, rather than vague goals the agent judges for itself. Always cap the number of attempts.

  • What is graph engineering for AI agents?

    Graph engineering splits a large job across several focused agents with defined order and dependencies, like a map of who does what. Each agent gets its own clean context window, which avoids the forgetting and contradictions that happen when one agent holds too much. Parallel sub-agents and sequential pipelines are both graphs.

  • When should I use a loop versus a graph?

    Use a loop for a repeating task with a clear finish line that one agent can handle. Use a graph when the job has real dependencies between parts, such as build, test, document and review. They also combine: any node in a graph can be its own loop with its own success criteria.

  • Why does my AI agent forget instructions on long tasks?

    Usually because the job overflows its context window. Past a certain amount of information, the model becomes less reliable at remembering early constraints and decisions. Splitting the work into smaller agents, each with a focused task and a clean context, is the standard fix.

Your next step

Our 12-week AI-Native Software Development Programme is a live, mentor-reviewed cohort where you build and ship real products with AI, and learn to explain every line. Start with the free trial to see how we teach, then decide.

Watch next

All videos

Learn the fundamentals that pay off in any direction.
Coding plus AI, taught properly.

Whatever you end up doing, the people who understand how software and AI actually work get to direct them. Try the first lessons free, no card needed, or see the full 12-week AI-Native Software Development Programme.