Most of the AI Agents on GitHub Are While Loops in a Trench Coat
I built an "agent" last year that embarrassed me. Not because it failed. Because it succeeded, and when I opened it up to see what made it work, I found a for-loop, a prompt, and a tool call. That's it. That was the agent. I had called it an agent in the README because "script" doesn't raise funding or upvotes.
So here's the provocation: most of the time, the agent is the wrong design, and the trench coat is hiding a workflow that should have been a chain. And when you build the wrong one, you pay every single run, in latency, in cost, and in the one currency nobody budgets, which is unpredictability.
Chain, Agent, and the Trench Coat
A chain is fixed steps: parse, retrieve, summarize, done. Same path every time, testable, cheap, boring. An agent is the loop: a model deciding, each iteration, what to do next. Powerful, and violently less predictable. The failure isn't capability. It's that people reach for the loop because it's the interesting one.
Before you build the loop, ask five questions.
Five Questions Before You Build the Loop
1. Does the task branch on what you find? If step three's outcome doesn't change step four, you have a chain. My "agent" had a fixed path with one conditional, which is a chain wearing a hat.
2. Can you name the decisions the model actually makes? Write them down. If the list is "pick the tool from a list of two" and "decide when to stop," you have a chain with a coin flip in the middle. A switch statement would be more honest and faster.
3. What happens when it makes the wrong call? Chain goes wrong: one step misfires, you see it in the log, you fix that step. Agent goes wrong: it can wander for six iterations before you notice, burning tokens the whole way. If your budget for surprise is zero, the loop is disqualified.
4. How will you test it? A chain gets unit tests. Each step is a function. An agent needs evals, traces, and a tolerance for runs that fail for no reason twice and then pass. If your team doesn't have eval infrastructure, the agent will ship with the test suite it deserves, which is none.
5. Is a human watching? The honest reason to use an agent is that the task is open-ended enough that scripting the path is harder than letting the model find it. That's real, and it's exactly why agent demos sing on stage and cry in production.
The Case I'll Concede
Here's the part I'll concede, because the counter-case is real: when the goal is genuinely open-ended, "explore this codebase and find the auth bug," the loop isn't overkill, it's the only tool that works. Chains can't explore. And there's a middle pattern that deserves more love: a chain with one agent-shaped step inside it, a stage where the model gets autonomy inside a box, then hands back a result the fixed steps verify.
But the burden of proof sits with the loop, always. "It might need flexibility" is how the trench coat gets sewn.
My rule after the embarrassment: start with the chain, and only grant the loop the one decision you can name, test, and afford to have made wrong. Every additional decision the model can make is an additional way the run can go sideways while you're asleep.
So look at your last agent. What decision did the model actually make that a switch statement couldn't have? If your answer takes more than a sentence, you already know what you built.
Top comments (7)
"A chain wearing a hat" is going straight into my vocabulary. The five-question filter matches what we landed on the hard way — I'd add a sixth: can you draw the state machine? Most of what we'd shipped as "agents" turned out to be three or four named states with legal transitions between them, and the moment we drew that out, the loop collapsed into a switch and the unpredictability budget dropped to near zero. The genuinely open-ended tasks — your "find the auth bug" case — are the ones where the transitions aren't enumerable in advance, and that's become my honest test: if I can list the states, it's a chain; if I can't, it's an agent and I'd better have eval infra and a human watching.
The cost point is underrated, too. The loop doesn't just cost more on average — it costs unpredictably, and unpredictable spend is the one line nobody can plan around. A chain's bill is a rounding exercise; an agent's bill has a tail.
I would separate having enumerable states from having a fixed decision policy. An agent can move among a small, explicit set of states while the model still decides which evidence warrants each transition. The useful boundary seems to be whether that decision can be specified reliably without the model, rather than whether the diagram can be drawn. For your boxed agent step, I would document the particular judgment it owns and compare it against a deterministic baseline before granting it more autonomy.
That is a better boundary than the one I drew, and it is testable where mine is not. 'Can you name the decisions' invites a list. 'Can this decision be specified reliably without the model' invites an answer, and the honest answer is often no, which is the useful part.
The baseline comparison is the piece I should have written down and did not. A deterministic policy that handles 80 percent of cases, plus a model that disagrees on the other 20, is a very different object from a model whose reasoning you cannot inspect. In the first case you know your exposure. In the second you have an opinion.
One wrinkle on the specification test: answering it costs work, because writing the deterministic version is work, and the model makes it easy to skip. So I would treat the baseline as the artifact rather than the discussion. If nobody can produce the switch statement, that is the finding, not a reason to move on.
What your framing changes in my practice: grant autonomy per decision, with the baseline as the comparison, instead of per box.
I would be careful with the step from 'nobody can produce the switch statement' to granting autonomy. That can mean the decision resists a reliable specification, but it can also mean the team has not resolved its policy yet. A useful baseline could explicitly defer those unresolved cases to a person instead of guessing. Then the comparison includes coverage, mistakes, and escalations, and you can ask which particular deferrals the model is actually safe to remove.
The state-machine question is the decisive one. A loop becomes an agentic system only when it can represent its state, know what evidence changes that state, and stop or escalate under uncertainty. Drawing the transitions also exposes where retries can repeat a side effect.
Yes, and drawing the transitions is what exposes retries that repeat a side effect. Most loops I've read have a retry edge with no idempotency key, and the diagram makes that edge hard to miss.
The stop-or-escalate condition is the part people skip. A loop that can't represent 'I don't know' keeps going until something else stops it, and that something is usually a rate limit or a human.