Part 14 of 15 · The House That Diligence BuiltNext: Don't Automate a Loop That Makes Slop →

The Agents That Work Are Mostly Software

Put code at the fixed steps and the model at the few points that need judgment. Gates fail closed, state lives outside the model, and runs start dry.

Clint JohnsonPublished 8 min read

This is move-in: getting real work through the door and into the rooms. The lesson that took me longest is that move-in should be run by ordinary code, with the model called only where someone has to decide.

The agents I've seen hold up in production are mostly software. There's a loop, a switch statement, some state, and a model call at the three or four points that need judgment. The ones that fail tend to run the other way: a long prompt that asks the model to follow a fixed sequence, stop at the right gates, and remember the rules.

I built several of the second kind before I noticed.

The easy 70 percent

Getting an agent prototype to about 70 percent is easy. It's enough to get everyone excited. Then the long tail arrives, and each remaining case is harder than the last. Teams that built on a framework end up several layers deep in a call stack, trying to work out how the prompt gets assembled and where the tools come from. Some throw it away. Some find the problem never needed an agent.

I think about agency and effectiveness as two separate axes. A brittle script has low agency and works until the input changes. A fully autonomous loop has high agency and is the hardest thing to measure or fix. The goal is to move toward more agency only while the system stays effective. In practice that means trying the simplest shape first:

  1. One chain of fixed steps. Easiest to measure, cheapest, most reliable.
  2. A tree, where the model picks a branch at a few known forks.
  3. A loop, only when the chains and trees have become too tangled to maintain.

The 90-second script

The clearest version of the mistake: you spend two hours adding detail to an agent's prompt until it lists the exact order of the build steps, then realize you could have written the shell script in ninety seconds.

My bots fleet was full of this. Each bot is a Claude Code session on a timer, driven by a skill file. Benji sweeps my test suites. Tao turns failures into issues and fixes. Ravi drafts outreach for a person to send. Their skill files described long fixed sequences in prose:

  • Benji ran the same steps every sweep: prepare the tree, run each lane, rerun each failure once, file or comment, hand off. The real judgment was the diagnosis: is this a broken test or a broken implementation?
  • Tao had a rule: rerun a failed CI job once, never twice. The model applied it from memory of recent messages.
  • Ravi had a set of hard gates, consent and suppression checks among them, that had to run in order and stop the lead on any failure. The order and the stop were prose. One gate was about 550 lines of instructions on its own.

A gate written in prose can be talked out of. A model that reads "this gate ALWAYS runs and fails CLOSED" follows it most of the time. Most of the time is not what a gate is for.

An agent you own has four parts

Strip away the framework and an agent is four things:

  • a prompt that picks the next step,
  • a switch that acts on the JSON the model returns,
  • a context builder that decides what the model sees,
  • a loop that decides when to stop.

A tool call isn't the model acting on the world. It's the model turning a sentence into JSON, and your code deciding what to do with it. Once you own those four parts, you can break out of the loop, summarize, add a judge, or pause wherever you like.

Owning the loop means owning the state. There are two kinds. Execution state is where you are: current step, next step, retry counts. Business state is what has happened: messages so far, what was shown to a person, what is waiting on approval. Both live in your database, not in the model's context. When a step waits on something slow, save the state, stop, and resume when the result comes back. The model never knows anything happened in between.

Errors need the same care. If every failed call and its stack trace gets pasted back into the context, the model loses the thread and spins. Summarize the error in a line or two, and clear the pending errors once a call succeeds.

Move the fixed parts into code

With that shape in mind, the change to my bots was mechanical.

Scripts for fixed sequences. Any step that runs the same way every pass is code. Benji's lanes, reruns, dedupe and filing became one script. The model is called inside it for the diagnosis.

Business rules in code. If an action should only happen when A, B and C are true, the model shouldn't be the one deciding whether they're true. Give it tools that set each state, validate each update, keep the state outside the model, and let code decide whether the action runs. Ravi's gates became one command that parses the lead, runs every check in order, stops at the first failure, and writes a receipt: a hash of the lead and each result. The command that posts a draft refuses to run without a passing receipt for that exact lead. Unknown input fails. A missing setting fails. The model can't skip a gate because it never decides whether the gate runs.

Rules that can't be broken twice. Tao's flake rule became a script that checks whether this exact failure was already rerun. If it was, the failure is real. A second rerun is impossible by construction, not by instruction.

Structured records between steps. Every bot writes its result as JSON (a triage verdict, a diagnosis, a draft) and a validator checks it against a schema before any script acts on it. A failure prints at most three lines, the bot gets one retry, and a second failure escalates to me.

Let code skip the model. The bot runner takes a cheap pre-pass command. If it says there's nothing to judge, the pass ends without starting a model at all.

Save the script the model keeps rewriting. If a model writes the same helper from scratch every run, save it and call it. Results get more consistent and cheaper.

The skill files got shorter as each fixed step moved into code. What's left in prose is judgment.

Small loops inside a fixed pipeline

None of this means no agents. It means small ones. The pattern that holds up is a mostly fixed pipeline with short agent loops, three to ten steps each, at the points that need them.

Tao's pass looks like this now:

def triage(failure):
    log = fetch_log(failure.run_id)                   # code
    if already_rerun(failure):                        # code: the flake rule
        return file_issue(failure, verdict="real")
    verdict = llm_judge(log, schema=Triage)           # judgment
    validate(verdict)                                 # code: schema check
    if verdict.kind == "flake":
        return rerun_once(failure)                    # code routes, not the model
    return diagnose_loop(log, max_steps=8)            # small agent loop

Code until a failure needs a diagnosis, a short loop for the diagnosis, then code again to file the result. As models improve, the loops can take on bigger pieces. The engineering doesn't go away. You find the task at the edge of what the model does reliably, then build the reliability around it.

My test for any proposed step boundary is one question: what does code do with this output before the next step sees it? If the answer is "pass it along," the boundary isn't buying anything.

Reaching a person is a step

Most agents bury the choice between calling a tool and asking a person inside a single first token. I'd rather the model choose in words: done, need clarification, need a person. Asking a person then becomes a normal tool call with its own state.

All my sessions work from one task list, and asking me is one command: the question, a recommended answer, and the session stops until I answer. The answer brings the task back to the top of the list. Nobody has to keep a chat tab open, and the request can come from wherever I already am.

Dry run first

Anything that changes the world gets a dry run. The workflow builds the full set of actions it would take, the issues it would file, the messages it would post, the reruns it would trigger, and writes them out without doing any of them. I ran each new script beside the old prompt-driven bot on the same inputs and compared. When they agreed, or the new one was right where they differed, the dry run came off.

Where a step already exists as working software, the agent calls it instead of reimplementing it. Where there's no step for something, it files a request for one instead of improvising.

How you know it's working

  • Prose describing fixed sequences shrinks. Count the lines in your skill files and prompts that describe an order of steps. Each is a script waiting to be written.
  • Gates leave receipts. Every gated action has a record of which checks passed, for that exact input. Done when posting without a receipt is impossible, not merely discouraged.
  • Unknown input fails. Feed each gate a misspelled value and an empty one. Both should stop the run.
  • Model starts per pass drop. Passes with nothing to judge end before a model starts.
  • Rejected records are visible. The validator's reject count is reported every pass. A rising count means a prompt drifted.
  • Failures name a step. When something breaks, the trace points at one step, not at "the agent."
Next in The House That Diligence Built · Part 15 of 15Don't Automate a Loop That Makes Slop →