Building an Agent Graph: From Rules to Runs
updated 21 min
Confidence the artifacts and the mechanising are built; the compiler is specified and unbuilt, and the matrix pilots came back null twice — the second time across ten real pull requests, where the narrowing did not reduce the reviewer's self-disagreement at all
“Beware of bugs in the above code; I have only proved it correct, not tried it.” — Donald Knuth (1977)
Part two of three, sections 7 to 10. Starts where Where to Cut finished: you have stages and schemas, and now the rules have to become something a program can run. How You Know is part three.
Bottom line up front
- Pick one source of truth for each rule, and price the derivation you did not build. Ours derives two artifacts of seven; the other five are kept in sync by discipline, which is a cost rather than a solution.
- Moving work off the model is the only lever that does not cost recall on the rule as written — and what it does cost is the fuzziness that was catching the adjacent case nobody wrote down.
- Read a detector’s false positives as a prompt to check what you lost, not as a tuning problem in isolation — and not as a measure of it. When I ran the comparison on ten real pull requests, the narrowing device removed almost nothing, so there was no removal for a rate to estimate.
- A demo is an example of the rule’s edge, not of the rule. If your example set is all violations you have written a recall test; the information is in the pair.
- A matrix moves the judgment somewhere observable. The model stops answering “is this a violation” and starts answering “did I observe C1”, which is a question a program can check.
- Four ceilings stop mechanisation, and the one worth internalising is a proxy pointed backwards: check the direction of a proxy before you check its strength.
7. One source of truth — and the compiler that isn’t there
I planned to write this section as a pipeline: the rule file is the source, everything else is a build of it, and the authoring gauntlet is the compiler.
That was wrong, and finding out how wrong made this the strongest section in the
guide. The compiler does not exist. It is specified, in detail, in a
document that reads like a description of a working program, and the binary it
specifies was never written. I discovered this by running ls instead of reading the spec (see Write Down the
Negatives).
So here is the honest shape, which is more useful to you than the clean diagram would have been.
What is actually a single source
Inside each rule’s detail file sits a machine-readable condition block. It’s parsed at authoring time, computed from at review time, and validated. Here’s the shape, genericised, for a rule about comments that restate the code they sit above:
<!-- conditions:<RULE>
mode: any
confirm C1 [comment-restates-code]: the comment restates what the adjacent <=3 lines of code literally do
confirm C2 [comment-contradicts-code]: the comment contradicts the code it describes (stale or sense-inverted)
confirm C3 [redundant-framework-comment]: a verbose comment re-explains well-known framework/library behavior the audience already knows
refute R1: the comment explains a non-obvious platform/runtime quirk, magic value, workaround, or perf reason not derivable from the line
refute R2: the comment records a data-model / serialization / API constraint that survives refactoring
refute R3: an open-question/caveat marker (verify, only works for X), a license/banner, or JSDoc
refute R4: the comment cites a specific regression/incident/ticket number, documenting real context not derivable from the code
-->
Four parts of that are load-bearing and three of them are non-obvious.
mode: is any or all — whether the confirms are alternatives or a
conjunction. Two rules shipped on all and neither could confirm its own
curated bad example, because a rule’s shapes are usually alternatives, not a
conjunction. That bug was found by making the rule executable against its own
documentation. It is exactly what the missing compiler would do everywhere.
The [slug] on each confirm is a stable identifier for that condition. It
becomes the issue code on the finding, which is what stops the model inventing a
fresh name for the same defect on every run — see §12, where this is worth a measurement.
Refutes are bound to specific confirms. This is the part I’d steal if I were reading someone else’s system. An unbound refutation is a general fact that defeats one defect class while quietly vetoing all of them: “this comment documents an API constraint” is a fine reason to keep a comment that restates code, and a terrible reason to keep a comment that contradicts the code. The convention that was supposed to prevent this — “word your refutes narrowly” — is unenforceable, because nothing checks wording. A binding is structural.
Refute wins, and a missing tick is false. Both defaults are deliberate. Refute-wins makes the escape hatches actually escape. Missing-is-false means a model that ignores a condition can’t accidentally confirm through it.
Of seven artifacts I expected to be derived, two are
Derived from the block: the deep reviewer’s decision procedure, and the issue
code. Plus two I hadn’t listed — the mode semantics and refute scope.
Not derived: the scout’s short summary of the rule, the deterministic detector, the test fixtures, the rule’s human-readable prose, and the decision matrix as a standalone document. Five artifacts kept in sync by discipline.
Price that honestly before you build the same thing. Discipline works right up until it doesn’t, and here’s what “doesn’t” looks like.
What the missing compiler costs: the detector-only refutation class
A rule can have two entry points — a deterministic detector, and the scout reading the diff. When you discover a false-positive class and kill it in the detector, the rule’s other arm doesn’t know. The same false positive still arrives via scout → deep.
The mechanism guarantees the class stays open. I found no sweep for it, and the one instance we know about turned up by accident while writing something else. How many others are like it is unmeasured. Where a refutation lives decides whether the class actually closes, and nothing in the system enforces that it lives in both places.
That’s the shape of the cost: not “the docs drift,” but “a fix you believe you shipped is only half-shipped, and nothing tells you.”
It isn’t a symptom of scale
If you want to see this from outside our system: there’s a widely-forked prompting skill on GitHub that carries its rule set twice — a diagnostic checklist inside the skill file, and a 37-row pattern table in a reference file beside it. Hand-maintained, with rows that already restate each other. Neither copy is generated from the other and nothing validates one against the other.
Three files. Same problem. You do not need a large system to earn it.
Related: Rules Are the Alpha, Mechanize the Rules, Teaching the Reviewer.
8. Mechanising — and what it silently drops
Three tiers, cheapest first: a deterministic detector, a prompted check, a prose rule the model reads. Push work down the tiers whenever the rule allows it.
The reason is the single most useful measured result in this build:
Reducing what the model reasons over costs recall. Reorganizing it or forcing coverage does not. Averaging N noisy draws inflates precision cost without buying real recall. Moving work off the model is the only lever that doesn’t cost recall.
Every other lever trades recall for whatever it was buying. This one does not for the rule as written — with the condition that the detector actually covers the rule, which is its own piece of work. A detector that implements 80% of a rule has cost you the other 20% and will not mention it. See The Only Free Lever.
What it does trade is the fuzziness, and that is easy to miss because the measurement cannot see it. A detector covers its scope exactly. The model covered that scope loosely — and the loose part was sometimes catching the adjacent case nobody had written down, the near-miss that is not quite the rule but is the same bug wearing different clothes. Mechanise and you keep every in-scope catch and lose the out-of-scope ones, which never appear in a recall number computed against the rule you specified.
The tell that this has happened is a detector producing false positives. They mean the boundary you encoded is not the boundary the model was using — and a boundary wrong at one edge is usually wrong at the other, so there are probably misses you cannot see. That is a direction, not a quantity, and I want to be exact because both readers of this post caught me overstating it. A false-positive rate does not measure what you lost; nothing about the count of wrong flags tells you the count of missed ones. What it licenses is a prompt to go and look — run the rule with the detector and without it on the same corpus and diff the findings, which is the comparison that would actually size it.
I have since run the nearest version of it available — not on a detector, but on the other narrowing device, a conditions block, with the leads and the pull requests held still and only the conditions changing in between. What it taught is a trap rather than a number, so here is the trap.
It looked like a clear win. It was an artifact, and the giveaway was in my own commit message: encode decision procedures for 15 rules measured to flip. I had chosen what to repair by measuring what was broken, which means the group I fixed was selected on the very thing I then measured — and anything picked for wobbling steadies on its own next time you look. Two screens would have caught that before a single model ran, and they are the part worth taking. Could the control group have moved in the measured direction at all? Mine could not: it was the complement of “rules that flipped”, so it had no flicker to lose and nowhere to go but worse. And did the total across both groups change? It had not. The instability moved from the group I repaired to the group I ignored.
So the comparison is run and the finding is a null: the narrowing device removed almost nothing. Which means a false-positive rate was never going to estimate what it removed — the direction above stands, and the quantity it was reaching for may not exist.
But it isn’t free of effort, and it doesn’t always work. Here’s when it won’t.
The four-way ceiling: why a rule can’t mechanise
| Ceiling | What it looks like | Example measurement |
|---|---|---|
| Not in the type system | the advice is real but nothing in the language expresses it | — |
| A repo fact, not a file fact | the signal you’d gate on lives outside the file you’re looking at | an in-file conformance gate measured 25% precision |
| Two populations, one name | the rule’s name covers two different defects with different base rates | 140.0 → 54.2 → 25.2 per 400 as the unit narrowed |
| Wholly semantic | the judgment is about meaning; there’s no syntactic shadow of it | — |
The second row is the one worth internalising. We tried gating a rule on whether the file already followed the convention — a reasonable-sounding proxy. It measured 25% precision — three flags in four were wrong. The reading I take from that is that the proxy is pointed backwards: files that already follow a convention belong to authors who know the convention, so the gate was in effect a detector for careful engineers. Strictly, precision alone cannot establish direction — that needs the base rate, or the same rule run with and without the gate. I have the mechanism and the precision, not the comparison.
Check the direction of your proxy before you check its strength.
The third row is the one that produces a real fix: when a rule fires at a high rate and is mostly wrong, the usual cause isn’t a bad detector, it’s two different defects living under one name. Narrowing the unit took a rule from 140.0 findings per 400 down to 54.2, then to 25.2 — a yield cut, twice, from splitting the name rather than tightening the detector.
One warning about what a bimodal precision distribution means. Ours splits cleanly into rules that mechanise beautifully and rules that don’t, and that looks like a discovery about rule kinds. It’s a selection effect: the rules with clean detectors are the ones whose exceptions happened to be expressible. Don’t read your own bimodality as a law of nature.
Negative space is a shippable artifact
One of the more useful things this build produced is a decision not to build something. We considered a second accessor model for a shape we expected to be common. We checked every instance of the shape in a large codebase and found zero. That measurement is preserved as a fixture, so the next person who proposes it re-runs the check rather than re-arguing the design.
A fixture that encodes “this doesn’t happen here” is documentation the code can contradict — the §12 property, arrived at from a different direction.
The trap: mechanising silently drops checks
When a check moves from a prose rule into a detector, the prose rule usually gets trimmed — and the trimmed version is what the model reads on every path that doesn’t hit the detector. §7’s detector-only refutation class is one face of this. The general form is: mechanising a stage can demote a check nobody notices is gone, because the mechanised path is the one you test.
The guard is boring and works: when you mechanise a check, write down what the model is no longer being told, and check it’s covered on every arm.
And the unread instrument
The mechanisation process here is documented candidate by candidate, with the reason each one succeeded or died. It has never been aggregated. So I can tell you why any individual rule failed to mechanise, and I cannot tell you the pass rate. A team that writes down every decision and still can’t tell you its own conversion rate. This is the closing of part three again.
Related: Buy Back the Coverage.
9. The runner — what actually walks the graph
You now have stages, schemas and a failure ladder, and nothing yet executes them. The runner is the program that does: it validates each boundary, classifies failures on the ladder, decides what a retry even means, and keeps enough per-item record that a crashed run can resume.
It is also mostly a solved problem with mature engines behind it, which is worth knowing before you write one. That, the retry unit, and the three things a first hand-rolled runner is always missing are in Every Node Needs Its Own Runner.
10. Demos and decision matrices
A rule that ships without a boundary example is a rule the model will guess at.
A demo is not an example of the rule — it’s an example of the rule’s edge
Here’s the pair for the comments rule from §5. Both are comments above code. Only the boundary distinguishes them.
// expect: CONFIRM — a what-comment restating the line below it
function load(user: User) {
// Get the user's email
const email = user.email;
return email;
}
// expect: REFUTE — a why-comment recording a platform quirk
function onWheel(el: HTMLElement, e: WheelEvent) {
// MacOsX uses negative scrollLeft to trigger the swipe-back gesture
if (e.deltaX < 0 && el.scrollLeft === 0) return;
}
If your example set is all violations, you’ve written a recall test. The information is in the pair.
The harness is two-sided, and that’s the whole design
Ours validates each snippet against the rule’s current text, read live from disk, so the demo can’t drift away from the rule it’s demonstrating. It checks both that the violation stably confirms and that each refute pole stably refutes, over N draws with a default of 6. All snippets batch into one call, and per-run tallies persist, so an interrupted run doesn’t lose completed draws.
Two implementation notes worth copying. Demos live in the rule’s own detail file — one authoring act, four consumers, because the passes partition a shared catalog and none of them re-authors. And the harness carries one documented exclusion, in the code, with its reason: a rule whose axis is a package-creation event, which isn’t expressible as a single-file flip. An excluded case with a written reason is a known gap. An excluded case with no reason is a bug in six months.
Demos fix judgment, not attention
Refute density varies enormously by pass. The rules pass is refutation-rich — its deep drops leads constantly. One pass sits at roughly a coin flip.
That last one is not a refutation problem at all. It’s a noticing problem, and better boundary examples buy it exactly nothing, because the failure happens before any judgment is made. Diagnose which failure you have before buying the fix for the other one.
Related: The Cue Lifts Recall.
Matrix vs prompt, precisely
A prompt asks for a judgment and gets an opinion. A matrix asks for observations and computes the judgment.
The model ticks conditions. Host-language code computes the verdict from the ticks. Two consequences follow, and the second is the one people miss:
- The verdict is deterministic given the ticks. Same ticks, same verdict, forever.
- A tick is attributable. When a verdict flips between runs you can see which condition flipped. That is the only reason automated tuning of the condition wording is possible at all — you cannot tune a holistic opinion, because you can’t localise its error.
There’s a corollary about what a flip means. When a verdict still flips run- to-run, the operating principle here is that the condition is not written well enough. A genuine decision procedure should be unambiguous to any model that can read it.
That is a stance rather than a finding, and it is sometimes wrong: a case can be genuinely borderline, and a model can vary on wording that is perfectly clear. I hold it anyway because of what the two options do. “The wording is ambiguous” sends you to a specific line you can fix. “The model is flaky” sends you nowhere, and it is available as an excuse for every flip you would rather not look at.
That principle needs a guard, and this generalises to any determinism objective you might set: the tuner disqualifies candidate conditions that are vacuous or trivial, because those would drive flips to zero by deleting the decision. Any determinism objective can be maximised by removing the decision. Write the disqualifier before you write the optimiser — see The Agent Invents the Bar.
The honest null
Matrix flicker-reduction has not been demonstrated. The piloted rule didn’t flip in the corpus, so the matrix had nothing to fix. That’s a null, not a refutation, and the document describing matrices says so — but a reader will still take it as a result.
The one positive datum is a four-arm probe at N=5 on a borderline case: a matrix
condition took it from 2/5 wobbles to 0/5. Mined demos took it from 2/5 to
0/5 as well. Identically. [0,0,0,5,0] for both. Which means, for that case,
the two mechanisms are the same lever in different costumes, and you should pick
on maintenance cost: a condition is checkable by code and a demo isn’t.
Scope, so you don’t over-read the above: six piloted rules, two on any and
four on all, and all of them flat. The tree shape is implemented, unit-tested,
and used by nothing that ships.
The escape hatch, and the loop closing once
Two fields exist for what the conditions don’t cover.
An override requires both a valid disposition and a non-empty reason, and the bar written into the schema is inapplicability, not disagreement. Measured usage: 0% override rate on two piloted rules across the first corpus. Interpret that honestly — an escape hatch nobody uses is either a well-specified system or a dead feature, and n=1 corpus cannot tell you which.
An out-of-list factors free-text field harvests whatever the model wanted to say and couldn’t. A recurring factor is read as a missing condition.
And that loop closed once, which is the whole human-in-the-loop design in a
single artifact: the harvest surfaced that a comment citing a specific
regression or incident number is a legitimate reason to keep it. A model wrote
the factor into free text, the harvest noticed it recurring, and a human
promoted it to R4 — the refute condition you can see in the block in §5.
Build the free-text field. Read it on a schedule.
The one external citation this guide takes
A public catalogue of agentic architectures arrives independently at the same discipline and names it the deterministic-picker pattern: the model commits to booleans and enums, and the host language composes the decision.
It also names a failure we’d described and never named — the LLM-as-Scorer flat-band pathology. Ask a model for one number on a 1–5 scale and it returns 4, essentially regardless of how strict your rubric is, so anything that ranks or selects on that number is choosing arbitrarily. Their mechanism claim is the sharp bit, and I would put it one notch weaker than they do: flat-banding five independent booleans is harder than flat- banding one number. A model can certainly return the same boolean vector every time — the difference is that when it does, you can see which boolean is stuck, where a 4-out-of-5 tells you nothing about where it came from. Their fourth step is our §4 line arrived at separately — keep the model’s own number on the trace for comparison, never as the deciding value.
Cite that as convergence, not as evidence. The tutorial’s only data is a four-sample illustrative block; there’s no before/after spread in it. It does not discharge the null above, and treating it as though it does would be exactly the error §10 is about.
Related: Familiarity Isn’t Trust.
How sure I am: the rule artifacts and the mechanising are built and in use, and the four-way ceiling is four real attempts rather than a taxonomy I invented. Two things are explicitly not results. The compiler that would derive the rule artifacts from one source does not exist — five of seven artifacts are kept in sync by discipline, and I am reporting the cost of that rather than a solution to it. And the matrix pilots came back null twice. The first time, a single piloted rule never flipped in the corpus, so the mechanism had nothing to fix. The second time is the one that costs something: seventeen piloted rules over 58 firings and ten pull requests, plenty to fix, and the corpus disagreed with itself as often afterwards as before — 24 flipping cells against 22. A null is not a refutation and it is not support either, but the second null is stronger than the first, because the first only says the test was empty.
The anti-correlated proxy is still a reading of a 25% precision figure rather than a measured direction. The comparison that would establish direction is the same rule run with and without the gate, and that one I have not run: the sweeps above predate deterministic detectors, so they measure a conditions block instead and transfer as a direction, not a number.
Sources
- Knuth (1977) — “Beware of bugs in the above code; I have only proved it correct, not tried it.” The epigraph, and the gap this part is about.
- The free-lever result — Shrink, Reorganise, Relocate, where reducing what the model reasons over was measured to cost recall and relocating it was not.
- The attention limit — A Big Rule Set Is an Attention Problem, including Anthropic’s reported removal of over 80% of Claude Code’s system prompt with no measurable loss on their own evals.
- The deterministic-picker pattern and the flat-band pathology — a public catalogue of agentic architectures, cited in §11 and credited there; the mechanism claim is stated one notch weaker than the source does.
- My own build: the seven artifacts, the two derivations, the mechanised detectors and the demo harness.
Related: Where to Cut — part one, where the seams and schemas come from; How You Know — part three; Every Node Needs Its Own Runner — the runner at length; Rules Are the Alpha — why the rule corpus is the asset this part is organising; A Big Rule Set Is an Attention Problem — what happens to a corpus that only ever grew.