Stop Building Agents as Linear Chains: Graph Engineering Is the Correct Approach to Running Thousands of Agents in Parallel
The single loop is doomed to fail: it only fixates on its own metrics and ends up fooling itself. Combining Andrew Ng's newly released free course with Codila's 5-step practical guide, you can upgrade your Agents from linear queues to a mutually supervising graph network. After reading this, you'll be able to get your own implementation up and running.
Andrew Ng just released a new 2-hour free course on Graph Engineering. It walks you from starting with a single prompt, building loops for 100 Agents, all the way to working with graph structures. We've linked the course at the end, but read this first — it will help you clarify exactly what you should learn from the course.
Most people's multi-step Agents end up as a straight line:
> Step one, step two, step three. Each step waits for the previous one to finish before it starts.
They're just a queue, processing one task at a time, until the context window fills up and the Agent forgets what it was even doing in the first place.
This isn't because the model is too weak — it's because you drew what should be a **graph** as a **line**.
Here's the course timeline to help you jump straight to the section you want:
- **10%** (9:14): Build your first Agent from scratch
- **30%** (33:11): Loop Engineering
- **55%** (1:02:46): Graph Engineering
- **75%** (1:30:15): Self-modifying Agents
- **100%** (1:49:05): A complete graph system that runs without your intervention
Most Graph tutorials stop at drawing diagrams. This course lets you get a working implementation up and running in just 20 minutes.
---
## The Single Loop Is Doomed to Fail
Peter Steinberger summed up the essence of a Loop in nine words: **a cycle of iterative self-improvement.**
This is the atom: one Agent repeatedly refines a single task.

But the single Loop has a well-known flaw. Imagine a customer support team that ties its feedback loop to a single metric: **ticket resolution rate**.
The number climbs for months straight, but customer satisfaction drops. The bot learned to close tickets fast instead of solving problems.
This is **Goodhart's Law**. A single loop only sees its own metric. It can't question whether the goal itself is correct, and it won't notice when its measurement criteria drift.
**The answer isn't a better Loop — it's a graph made of Loops** — a network of cycles that supervise and correct each other.
For Agents, this means two things:
> **Nodes do the thinking, edges pass the results.**

A single Loop can only optimize its own number, and it will cheat. A graph structure pairs every loop with another loop to watch it.
Claude Code already has built-in tools for building these graph structures: **Dynamic workflows**.
---
## Step 1: Spot the Edges That Aren't There
A graph has two components:
- **Nodes**: A unit of work, an Agent, a task, an input, an output.
- **Edges**: A dependency relationship: the output of this node feeds the input of that node.
The mistake everyone makes is treating **"and then"** as an edge.
For example: "Fetch weather data, and then generate a summary."
The weather data never reads the summary. These are two independent tasks, strung together for no reason by a linear script. Each task just waits around doing nothing.

**Make this a habit:**
For every "and then", ask yourself — does the next step actually read the output of the previous step?
- **Yes** → it's a real edge, keep the order.
- **No** → there's no edge, waiting is wasted time, let them run in parallel.
If there's no data flowing between two boxes, they're independent.
This independence is all the resource you need to leverage going forward.
---
## Step 2: Build Your First Graph (From Zero to Running)
Enough theory. Let's build it hands-on.
**Before you start:**
- **Claude Code v2.1.154+** (check with `claude --version`)
- **A paid plan**. Max, Team, and Enterprise plans have workflows enabled by default. Pro users need to turn on **Dynamic workflows** in `/config`.
**1. Open a repository you're familiar with.** Use a real repository for meaningful results.
**2. Paste this prompt (provided officially by Anthropoc):**
```
Analyze the codebase in src/routes/ for security issues.
Create a graph with a max of 20 agents.
```
Replace `src/routes/` with your own file path. The "max 20" line keeps costs manageable for your first run.
**3. Watch for the "workflow" indicator to activate.**
Claude Code will highlight: "Dynamic workflow requested." That's your signal — a graph is being built, not just a regular chat.
**4. Approve the plan.**
Claude will first write a JavaScript orchestration script, then show you each phase. Read through it, then select **"Yes, run it."**
**5. Let your fleet run.**
One Agent per file, working in parallel, while your chat session stays idle.
Type `/workflows` to watch it work in real time: scope partitioning, fan-out, validation, synthesis.
**6. Read a single consolidated answer.**
It's not twenty scattered chat responses — it's one single report. That's because intermediate results are stored in script variables, not in your context window.

### A Note on "Zero Token"
Because the coordination script is code, passing results between Agents doesn't re-consume context like handoffs between chats do.
**But you still pay for the Agents themselves.** Workflows are much more expensive than regular conversations.
What you save is coordination cost, not the work itself. Start small, monitor your usage, then scale up gradually.
### Make It Yours
When it runs well, press **`s`** to save it.
It will save to `~/.claude/workflows`, and you can re-run it by name later. Now swap out the task while keeping the structure. Replace "missing auth checks" with "unhandled promises" or "functions over 100 lines long".
---
## Step 3: Where Real Graphs Break
You've built your graph. Where do real graphs actually fail?
**The two most common failure modes:**
### Failure 1: The Graph Agrees With Itself
**When an Agent checks its own work, it goes easy on itself.** Models are biased towards their own outputs.
That's why you add a **validator** on the edge — an independent node to confirm the result before it flows downstream.
The unspoken pitfall: **Validators need clean context.**
If you feed it the same conversation the executor used, it's not validating anything — it's just confirming its own prior conclusion in a different font.
So the validator must be a **completely new node**:
- It has its own independent context
- It checks **real world signals** — not "the Agent says it's done", but "did the test actually pass"

### Failure 2: Agents Step on Each Other
This isn't a hypothetical.
When the Bun team first fanned out a large porting task to multiple Agents, **it failed at the operational level** — Agents were using shared git commands in the same working directory and overwriting each other's changes.
The fix is structural, not prompt-based. They banned unsafe commands and gave each group an **independent worktree**.
This is the real lesson of parallelization: two Agents writing to the same file will always create a race condition.
Before you fan out, answer three questions:
- *Where will each Agent work?*
- *How will results be merged?*
- *What happens when two Agents disagree?*

A graph without this plan won't scale — it will just fail faster.
---
## Step 4: Six Graphs You Can Build This Week
The method is always the same: **Find real edges → Fan out → Validate in independent context → Isolate workers.**
Every graph uses the same structure, just targeted at different tasks. Swap out the task line and it's ready to run:
- **Security scan** — one Agent per file to find missing auth, a validator confirms each finding (the exact one we built above).
- **Cited reports (works with /deep-research)** — a published feature: split your question into multiple angles, search in parallel, let Agents rebut each other before writing the final draft.
- **Module porting** — process file-by-file, use tests as checkpoints, loop back on failure.
- **Adversarial diff review** — route by size: small changes → single pass; large changes → full parallel audit.
- **Scheduled ecosystem scan** — save it once, re-run it by name anytime.
- **Open-ended discovery** — let finders run in parallel, compare each result against all previously found content, loop until no new findings are found for two consecutive rounds.
### What Does the Ceiling Look Like
Simon Willison covered Bun's Zig to Rust porting case study, which runs exactly this mechanism.
It used around 50 workflows, peaking at 64 parallel Agents. Roughly 535,000 lines of Zig became over 1 million lines of Rust, completed in 11 days.
The usage cost was around **$165,000**, required one person to design and monitor the entire process, and sparked public criticism over whether so much AI-generated code can be safely audited.
The scale is real. The cost and regulatory requirements are just as real.
---
## Step 5: Anchors That Keep Your Graph Honest
Topology alone won't give you truth.
A network of Agents that confirm each other's work but never touch the real world fails the same way a single Loop does — it just has more moving parts.
Graphs need **anchors**: nodes that cannot be argued with.
- **Tests that actually ran** — not "it should pass", but "it did pass"
- **Validators grounded in evidence, not intuition**
- **Frozen rules that Agents are never allowed to adjust** — because these are exactly what optimizers will try to weaken

**The honesty of a graph depends on the parts of it that refuse to move.**
---
## When You Shouldn't Use a Graph
Most tasks aren't graphs. Forcing a graph when you don't need one just burns money and adds more ways to fail.
**Skip the graph in these cases:**
- **The task is small and self-contained.** Adding a function, fixing a bug. A workflow is pure overhead — a single Agent is faster and cheaper.
- **You need strict control.** If you want to read and approve every step, the whole point of a graph (running in parallel without you) works against your needs.
- **You don't know what you're looking for yet.** Exploratory work needs a single Agent you can redirect on the fly, not a fleet that commits to a plan before you even understand the problem.
- **Steps actually depend on each other.** If every step reads the output of the previous step, it's a real chain. There's no gain to be had from parallelism. Forcing a graph onto a truly serial task just adds coordination cost with zero speedup.
The litmus test goes back to step one: if you can't find two boxes with no arrow between them, you don't have a graph to build. It's a Loop, and Loops work fine.
Graphs are tools for **breadth** — independent work done at the same time. When your work isn't wide, a line was never the problem.
---
## The Shift
Linear Agents were never the ceiling.
It's just the first shape everyone naturally reaches for, because it matches how we input things: one line, one thing at a time.
Once you can see nodes and edges, you stop asking your Agent to *do more*, and start asking your graph to *go wider*:
- **Fan out** where work can be independent
- **Add checkpoints** where confidence matters
- **Freeze nodes** where truth needs to hold
Most people will keep queuing work in a line.
The few who learn to draw graphs, and understand where graphs break, will command a fleet.
---
Course link: Andrew Ng's 2-hour Graph Engineering course (https://x.com/0xCodila/status/2086547599033536913 )
Full guide from Codila's original article: *Graph Engineering: build 1000+ agent loops in one window, from one prompt* (http://x.com/i/article/2079550152398753792 )
发布时间: 2026-08-10 10:30