DEV Community

Debashish Ghosal
Debashish Ghosal

Posted on

Most of the AI Agents on GitHub Are While Loops in a Trench Coat

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 (0)