Most agent-built code fails in a quiet way. The code runs, the demo looks fine, and a rule nobody wrote down gets broken a week later.
An AI agent builder can avoid much of that by writing a plan first and letting a person or a script check it before any code appears.
The plan is short, and it can be checked like any other input, which is why a missing role or a vague goal shows up on day one and not in production.
This post builds a tiny plan gate in Python, runs it, and then ties every acceptance criterion to a test result so you can see which promises hold.
What does an AI agent builder need to write down before it writes code?
A plan that a reviewer can reject has five parts. Without each one, a gap stays hidden until the code is already built around it. The table shows what each part holds and what goes wrong when it is missing.
| Plan part | What it holds | What breaks without it |
|---|---|---|
| Modules | The pieces the system is split into | Logic lands in one file and nobody owns it |
| User roles | Who can do what | Every user ends up with every permission |
| API endpoints | The calls the system accepts | Features appear that nobody asked for |
| Data models | What is stored and how it links | Fields drift between screens and storage |
| Acceptance criteria | Statements a test can pass or fail | "Done" means whatever the agent says it means |
Quick check: Pick any feature you shipped last month. Can you point to the sentence that says what "working" meant before the first line was written?
When teams ask what a good AI agent builder should produce first, the useful answer is a plan in this shape, not a screen or a snippet. The rest of this post makes that plan concrete.
How do you turn requirements into a plan an AI agent can be held to?
Start from one plain requirement and write it as data. Data is easy to check, easy to diff and easy to hand to a reviewer.
Research on self-planning code generation points the same way: in one preprint, planning before generation lifted Pass@1 by up to 25.4% relative to direct generation and up to 11.9% relative to chain-of-thought prompting. It is a preprint, so treat the numbers as a signal and not a promise.
Here is the plan for a small booking feature: staff can book a meeting room and cancel their own bookings. Each acceptance criterion names the endpoint it belongs to.
PLAN = {
"requirement": "Staff can book a meeting room and cancel their own bookings.",
"modules": ["bookings", "rooms"],
"roles": ["staff", "admin"],
"endpoints": [
{"id": "E1", "method": "POST", "path": "/bookings", "role": "staff"},
{"id": "E2", "method": "DELETE", "path": "/bookings/{id}", "role": "staff"},
],
"data_models": {
"Room": ["id", "name"],
"Booking": ["id", "room_id", "user_id", "start", "end"],
},
"criteria": [
{"id": "C1", "text": "A staff user can book a free room", "endpoint": "E1"},
{"id": "C2", "text": "An overlapping booking is rejected", "endpoint": "E1"},
{"id": "C3", "text": "A user can cancel only their own booking", "endpoint": "E2"},
],
}
Quick check: Does every criterion in your own plans name the thing it tests? If one does not, nobody can tell when it has been met.
Notice that the criteria are plain sentences with one observable outcome each. "An overlapping booking is rejected" can pass or fail. "Booking should be nice" cannot.
What should a plan gate check before anyone approves it?
A gate is a function that returns a list of reasons to say no. It runs before any code exists, so rejecting a plan costs a minute and not a rebuild.
The gate below checks four things: every part is present, every endpoint uses a declared role, every criterion is testable and points at a real endpoint, and every endpoint has at least one criterion. That rule is what plan before code with an AI agent builder means in practice, and a gate like this is how you enforce it.
REQUIRED = ["modules", "roles", "endpoints", "data_models", "criteria"]
VAGUE = ("fast", "quick", "easy", "friendly", "properly", "nice", "good")
def gate(plan):
problems = []
for part in REQUIRED:
if not plan.get(part):
problems.append(f"missing part: {part}")
ids = {e["id"] for e in plan.get("endpoints", [])}
for e in plan.get("endpoints", []):
if e["role"] not in plan.get("roles", []):
problems.append(f"{e['id']} uses unknown role '{e['role']}'")
for c in plan.get("criteria", []):
if c["endpoint"] not in ids:
problems.append(f"{c['id']} points at unknown endpoint {c['endpoint']}")
if any(w in c["text"].lower().split() for w in VAGUE):
problems.append(f"{c['id']} is not testable: '{c['text']}'")
covered = {c["endpoint"] for c in plan.get("criteria", [])}
for e in plan.get("endpoints", []):
if e["id"] not in covered:
problems.append(f"{e['id']} has no acceptance criterion")
return problems
bad = {k: v for k, v in PLAN.items() if k != "data_models"}
bad["criteria"] = [PLAN["criteria"][0],
{"id": "C9", "text": "Booking is quick", "endpoint": "E1"}]
print("bad plan:", *gate(bad), sep="\n - ")
print("good plan:", gate(PLAN) or "approved for build")
When you run the first two blocks together, the output is:
bad plan:
- missing part: data_models
- C9 is not testable: 'Booking is quick'
- E2 has no acceptance criterion
good plan: approved for build
The bad plan fails three ways, and the gate names each one. That matters because vague input is a real cost. A study called What Prompts Don't Say found that models guess unspecified requirements 41.1% of the time.
It also found that some underspecified prompts lose more than 20% accuracy, and that they are about twice as likely to regress when the model or prompt changes.
Quick check: If your reviewer reads a plan and says "looks fine", what exact check did they run? A gate turns that feeling into a list.
How do acceptance criteria turn into tested output?
An approved plan still needs proof. The last block ties each criterion to a test with a small decorator, then prints one row per criterion. A criterion with no test shows up as NO TEST, so a gap cannot hide behind a green run.
BOOKINGS = {}
def book(user, room, start, end):
for b in BOOKINGS.values():
if b["room"] == room and start < b["end"] and b["start"] < end:
return None
bid = len(BOOKINGS) + 1
BOOKINGS[bid] = {"user": user, "room": room, "start": start, "end": end}
return bid
def cancel(user, bid):
BOOKINGS.pop(bid, None) # bug: never checks who owns the booking
return bid not in BOOKINGS
TESTS = {}
def covers(cid):
def wrap(fn):
TESTS[cid] = fn
return fn
return wrap
@covers("C1")
def test_book_free_room():
BOOKINGS.clear()
assert book("ana", "R1", 9, 10)
@covers("C2")
def test_overlap_rejected():
BOOKINGS.clear()
book("ana", "R1", 9, 11)
assert book("raj", "R1", 10, 12) is None
@covers("C3")
def test_cancel_own_only():
BOOKINGS.clear()
bid = book("ana", "R1", 9, 10)
assert cancel("raj", bid) is False
def trace(plan):
rows = []
for c in plan["criteria"]:
fn = TESTS.get(c["id"])
if fn is None:
rows.append((c["id"], "NO TEST"))
continue
try:
fn()
rows.append((c["id"], "pass"))
except AssertionError:
rows.append((c["id"], "FAIL"))
return rows
for cid, result in trace(PLAN):
print(f"{cid} {result}")
Run all three blocks as one file and the trace prints:
C1 pass
C2 pass
C3 FAIL
C3 fails because cancel never checks who owns the booking, so one user can delete another user's booking. The plan said "only their own", the code did not, and the trace caught it before anyone shipped.
After a small fix that compares the owner before deleting, all three rows print pass. I also added a fourth criterion with no test and confirmed the trace reports it as NO TEST.
This is the same idea behind the first proof in a vendor test that starts with plan before code: the plan comes first, and the test evidence has to point back to it.
Quick check: Count the criteria in your latest spec. How many have a named test? The gap is your unverified work.
Where does a person approve the plan?
The gate catches shape problems, not judgment calls. Whether "staff" should be allowed to cancel at all is a question for a person.
The simplest place for that decision is right after the gate passes: the reviewer sees the plan, the gate result, and later the trace, and signs off on each.
A longer treatment of this pattern, with evidence bundles and audit log fields, is in approval gates and audit logs for governing AI agents in code.
Keep the approval small. One page showing the plan, the gate output and the criterion trace is enough for most features. If the page is hard to read, the plan was probably too vague.
A plan is a promise you can check
Anything that builds software from a request makes promises, whether it says so or not. The only question is whether those promises are written where someone can read them.
A plan in plain data, a gate that refuses vague input, and a trace from each criterion to a test result turn the promises into something a reviewer can hold. None of it needs a large framework.
The examples here are around a hundred lines of Python, and you can run them on a laptop in a second.
What changes is the conversation: instead of asking whether the output feels right, the team asks which criterion failed and who owns the fix.
That is a smaller, calmer argument, and it ends with a test that goes green. Small, checkable plans also age well.
When a requirement changes, you edit one line of data, the gate checks it again, and the trace shows exactly which tests need to move.



Top comments (0)