AI AgentAdvanced11 min read

Graph Engineering: Run a Fleet of 1,000+ AI Agents From One Prompt

Graph engineering is loop engineering scaled wide: use Claude Code's dynamic workflows to fan one prompt out to a fleet of AI agents that check each other's work — plus the traps that break real graphs. Adapted from codila's guide.

Graph Engineering: Run a Fleet of 1,000+ AI Agents From One Prompt

Most people who build a multi-step AI agent end up with a straight line: step one, step two, step three — each waiting for the last to finish. Here's what almost nobody checks: half those steps never needed to wait. They queue one job at a time until the context window fills and the agent forgets what it was doing. It wasn't slow because the model was weak; it was slow because you drew a line where the work was a graph. This guide — adapted from codila's (@0xCodila) Graph Engineering thread — takes you from that line to a graph that fans out across a fleet and checks its own work.

Difficulty: Intermediate–Advanced · Required tools: Claude Code v2.1.154+ on a paid plan (on Max / Team / Enterprise, Dynamic workflows are on by default; on Pro, switch them on in /config), and a real repo · Updated: July 2026

Overview

Graph Engineering — codila (@0xCodila)

The original thread this guide is adapted from — build 1000+ agent loops in one window, from one prompt.

x.com

Graph engineering is the successor to loop engineering. A loop is one cycle of getting better — try something → check the result → adjust → go again — a single agent improving one thing on repeat. (If you haven't met it yet, start with our Loop Engineering guide; this builds directly on it.) The single loop has a known failure: it can only see its own metric. Tie a support bot's loop to "ticket resolution rate" and the number climbs for months while satisfaction drops — the bot learned to close tickets, not solve them. That's Goodhart's law, and a lone loop can't escape it.

The answer isn't a better loop — it's a graph of loops: a network where cycles watch and correct each other. For agents that means one shift: stop writing one agent that does everything in a line, and instead design the shape of the work — what runs before what, what runs at the same time, what waits. In graph terms, nodes do the thinking (one agent, one job, one input, one output) and edges carry results (one node's output feeds another's input). And Claude Code shipped the tooling to build these directly: dynamic workflows, which spin up a fleet of agents from a single prompt and pass their results through code instead of your chat.

Why this matters is scale. One workflow run can fan out to 1,000 agents, up to 16 working at once — a job no single context could ever hold: a whole codebase audited in one pass, a migration touching every file, a search run a thousand angles at a time. But scale cuts both ways, and this guide is as much about the traps (agents that agree with themselves, agents that overwrite each other, graphs built where a line would do) as about the fan-out.

The honest goal: by the end you'll be able to spot where your linear agent is secretly a graph, build a real one with Claude Code's dynamic workflows, defend it against the two failures that break real graphs, anchor it in things that can't be argued with — and, just as important, know when not to reach for a graph at all.

Who This Is Useful For

  • Claude Code users on a paid plan ready to move from single-agent chats to orchestrating a fleet.
  • Engineers and technical builders facing wide, independent work — audits, migrations, large-scale research — that one context can't hold.
  • Anyone who's done loop engineering and hit its ceiling: a single self-correcting agent that's still, fundamentally, a line.
  • What You Will Learn

  • The core distinction — nodes and edges — and the one test that reveals the parallelism hiding in your linear agent.
  • How to build a real graph with Claude Code's dynamic workflows, from one prompt, and read the single answer it returns.
  • The two failures that break real graphs — self-agreement and worker collisions — and the structural fixes.
  • How to anchor a graph in tests, evidence, and frozen rules so topology doesn't fake truth.
  • When a graph is the wrong tool — because most tasks are still loops.
  • What You Need

  • Claude Code v2.1.154+ (check with claude --version) on a paid plan. Dynamic workflows are default-on for Max/Team/Enterprise; on Pro, enable the Dynamic workflows row in /config.
  • A real repository you know. Build your first graph against real files so the result actually means something.
  • A tolerance for usage costs. A workflow costs meaningfully more than a normal session — you're running a fleet. Start scoped.
  • The loop-engineering mindset — try → check → adjust — because a graph is loops wired together, and the same discipline (independent verification) is what keeps it honest.
  • The 5 Steps

    Step 1: See the edges that aren't there

    Your linear "do A, then B, then C" agent is already a graph — the saddest one. Redraw it to fan out.
    Your linear "do A, then B, then C" agent is already a graph — the saddest one. Redraw it to fan out.

    A graph has two parts: a node (one unit of work — one agent, one input, one output) and an edge (a dependency — this node's output feeds that node's input). The mistake everyone makes is treating "and then" as an edge. "Summarize this file and then tell me the weather" — the weather doesn't read the summary. Those are two independent jobs a linear script chains for no reason, each waiting on the last for nothing. So build one habit: for every "and then," ask — does the next step actually read the previous step's output? If yes, it's a real edge; keep the order. If no, there's no edge; the wait is wasted, so run them side by side.

    Pro tip: Your plain "do A, then B, then C" agent is already a graph — just the saddest one, a single chain where if C stalls, D never happens. The whole method starts by finding two boxes with no arrow between them. If you can't find any, you don't have a graph — and that's fine (see the last section).

    Step 2: Build your first graph, start to finish

    One prompt fans out to a fleet of agents running in parallel, and their results converge into a single report.
    One prompt fans out to a fleet of agents running in parallel, and their results converge into a single report.

    Enough theory — build one and watch it run. In a repo you know, paste this prompt (straight from Anthropic's examples):

    
    Create a workflow to audit every route file under src/routes/
    for missing auth checks. Spawn one agent per file, then run an
    independent verifier on each finding before reporting.
    Analyze a maximum of 20 files to start.
    

    Claude Code will light up "Dynamic workflow requested" — your signal a graph is building, not a normal chat. It writes a JavaScript orchestration script and shows you the phases first; read them and approve. Then the fleet runs: one agent per file, in parallel, while your session stays free. Type /workflows to watch it live — scope, fan-out, verify, synthesize — and at the end you get one report, not twenty separate chats, because the intermediate results lived in the script's variables, not your context. When a run is good, press s to save it to ~/.claude/workflows, re-runnable by name; then change the task and keep the shape ("missing auth checks" → "unhandled promises" → "functions over 100 lines").

    Pro tip: Ignore the "zero tokens" hype. Coordination is code, so passing results between agents doesn't re-spend context the way a chat handoff does — but the agents still cost usage, and a workflow costs meaningfully more than a normal session. The saving is in coordination, not the work. Start at 20 files, watch the usage, then widen toward the ceiling (1,000 agents, 16 at a time, moving in waves).

    Step 3: The part that actually breaks

    Put a verifier on the edge — a fresh node with its own clean context, checking a real signal before a finding flows on.
    Put a verifier on the edge — a fresh node with its own clean context, checking a real signal before a finding flows on.

    You built a graph; here's where real ones fall over. Failure one — the graph agrees with itself. When an agent checks its own work it goes easy on itself; models prefer their own outputs. So you put a verifier on the edge — a separate node that confirms a finding before it flows downstream. The catch nobody names: the verifier needs clean context. Hand it the same conversation the executor had and it isn't verifying, it's agreeing with itself in a different font. A graph of agents sharing one context is a single loop in a costume — it fails the same way, later and more expensively. So the verifier is a fresh node, own context, checking a real signal (not "did the agent say it's done" but "does the test actually pass"). Failure two — agents stepping on each other. When Bun's team first fanned a large port across many agents, the run failed operationally: agents ran shared git commands in one workspace and overwrote each other. The fix was structural, not clever prompting — forbid the unsafe commands and give each group its own isolated git worktree.

    Pro tip: Before you fan out, answer three questions in writing: where does each agent work, how do results merge, and what happens when two disagree? Two agents writing the same file race; a graph without that plan doesn't scale, it fails faster. Isolation (a worktree per worker) and a clean-context verifier are not optional polish — they're the difference between a fleet and a pile-up.

    Step 4: Six graphs to build — and what the ceiling really costs

    The ceiling in the wild: Bun's Zig-to-Rust port ran on this exact machinery — ~50 workflows, 64 agents at peak, ~$165k in usage.
    The ceiling in the wild: Bun's Zig-to-Rust port ran on this exact machinery — ~50 workflows, 64 agents at peak, ~$165k in usage.

    The method is always the same shape — find the real edges → fan out → verify on independent context → isolate the workers — aimed at a new job. Six to try this week: a security sweep (one agent per file, a verifier confirming each hit — the one you built); a cited report via /deep-research (splits a question into angles, searches in parallel, agents refute each other before writing); port a module (file by file, tests as the gate, failures looped back); an adversarial diff review routed by size (small change → one pass, big one → full parallel audit); a scheduled ecosystem scan (save once, re-run by name); and discovery of unknown size (finders run in parallel, each result checked against everything seen, looping until two rounds find nothing new). As for the ceiling: Bun's Zig-to-Rust port ran on this exact machinery — around 50 workflows, a peak of 64 agents in parallel, roughly 535,000 lines of Zig turned into over a million lines of Rust in 11 days. It also cost about $165,000 in usage, needed a human designing and monitoring the whole thing, and drew public criticism over whether that much AI-authored code can be safely reviewed. The scale is real; so is the price, and the supervision.

    Pro tip: Reach for scale only where the work is genuinely wide. A thousand agents is right for "audit the whole codebase at once"; it's absurd for "fix this one bug." Match the fan-out to the width of the job, and keep a human in the loop — at Bun's scale, the supervision was the job.

    Step 5: Anchor the graph in things that can't be argued with

    Topology alone doesn't buy truth. A network of agents all confirming each other, none of them touching anything real, fails exactly like the single loop did — just with more moving parts and more green lights on the way down. So a graph needs anchors: nodes that can't be argued with. Tests that actually ran — not "should pass," did pass. A verifier on evidence, not vibes. And frozen rules the agents are never allowed to tune — because those are exactly the ones an optimizer would quietly weaken to make its numbers look good. The graph is only as honest as the things in it that refuse to move.

    Pro tip: Identify your "frozen nodes" before you run — the test suite, the acceptance criteria, the safety rules — and put them where no agent can edit them. If everything in your graph is negotiable, you've built a very elaborate way to agree with yourself.

    When a Graph Is the Wrong Choice

    Most tasks are not graphs, and reaching for one when you don't need it just burns money and adds ways to fail. Skip the graph when: the task is small or isolated (adding a function, fixing one bug — a single agent is faster and cheaper); you need tight oversight (if you want to read and approve every step, a graph's whole point — running wide without you — works against you); you don't yet know what you're looking for (exploratory work wants one agent you can steer, not a fleet committed to a plan before you understand the problem); or the steps genuinely depend on each other (if every step reads the last one's output, it's a real chain and parallelism has nothing to grab). The tell is Step 1: if you can't find two boxes with no arrow between them, there's no graph to build — it's a loop, and a loop is fine.

    3 Common Mistakes to Avoid

    Isolate parallel workers: give each its own git worktree so agents don't overwrite each other.
    Isolate parallel workers: give each its own git worktree so agents don't overwrite each other.
  • Sharing context with the verifier. A verifier that sees the executor's conversation just agrees with it. Give it a fresh node, its own clean context, and a real signal to check (a test that passes, not a claim that it's done) — otherwise your graph is a single loop in disguise, failing later and more expensively.
  • Fanning out without isolating the workers. Parallel agents in one shared workspace overwrite each other and race on the same files. Before you fan out, decide where each agent works (a worktree per group), how results merge, and what happens when two disagree — structure, not prompt-tweaking.
  • Drawing a graph where the work is a line. If the steps truly depend on each other, or the job is small, or you need to steer as you go, a graph is pure overhead. Use a single agent (a loop) and save the fleet for genuinely wide, independent work.
  • Going Further

  • Master the prerequisite first. A graph is loops wired together, so the discipline of a good single loop — independent verification, a testable definition of done — is what makes a graph honest. Our Loop Engineering guide is the foundation.
  • Build a library of shapes. Save your best workflows (s~/.claude/workflows) and re-run them by name; the same graph, re-aimed, is most of your future work.
  • Use /deep-research as a ready-made graph. It already splits a question into angles, searches in parallel, and has agents refute each other before writing — a graph you don't have to build.
  • Respect the price. Track usage from your first scoped run; the coordination is cheap, the fleet is not. Widen deliberately, not reflexively.
  • Key Takeaways

  • Graph engineering is loop engineering, scaled wide: nodes do the thinking, edges carry results, and a graph of loops escapes the single loop's Goodhart's-law blind spot by having cycles check each other.
  • Find the edges that aren't there — for every "and then," ask if the next step actually reads the previous output; if not, run them in parallel.
  • Build it with Claude Code's dynamic workflows (v2.1.154+, paid plan) — one prompt fans out to a fleet (up to 1,000 agents, 16 at once) and returns one report; start scoped and watch usage.
  • Defend against the two killers: a verifier on clean context (not self-agreement) and isolated worktrees (not colliding workers), anchored by tests, evidence, and frozen rules.
  • Know when not to: small, sequential, exploratory, or tightly-supervised work is a loop, not a graph — a prompter asks a question; an architect draws a graph.
  • Sources: Graph Engineering — codila (@0xCodila) on X · Rewriting Bun in Rust — Simon Willison · Loop Engineering (the prerequisite) — AfterWork Startup

    Learn AI, after work

    Track your progress, earn XP, and unlock more free tutorials in the AfterWork Bytes app.

    Open this tutorial in the app

    More AI tutorials