All writing
AI SystemsJun 20266 min read

The Model Doesn't Do Anything. Your While Loop Does.

I built two agents this week and realized the model barely does anything - it returns JSON. The loop, the memory dict, and the tool schemas do the real work. That is the actual engineering.

I built two AI agents this week and somewhere in the middle of debugging the second one, I had a moment that changed how I think about this whole field.

The first agent is a CRM Lead Qualifier. Feed it a lead, and it enriches the company info, pulls whatever history exists in the CRM, and spits out a score. The second is an IT Support agent. Point it at a server, and it investigates what's wrong, restarts a service if it needs to, or escalates to an actual human if the situation calls for it.

On paper these are completely different problems. One is sales ops, the other is infrastructure. But once I had both running, I noticed they were built out of the exact same parts. Same loop. Same pattern. Same shape.

And once I noticed that, I noticed something else, something a little uncomfortable: the model itself barely does anything.

Here's what I mean. When my CRM agent "looks up a company," the model does not go look up the company. It can't. It has no network connection, no API key, no hands to do anything with. What actually happens is the model pauses mid-response and hands back a small piece of structured text, something like this:

{"function": "lookup_domain_info", "arguments": {"domain": "acmecorp.com"}}

That's the entire contribution. A function name and some arguments, wrapped in JSON. My code is the thing that reads that request, makes the real HTTP call, gets a real result back, and feeds it to the model so it can decide what to do next.

Same story on the IT Support side. When people say "the agent restarted the server," what actually happened is the model emitted a request to call a function named restart_service. The restart only happened because I had already written a Python function that does the restarting, and a dispatch table connecting the model's text output to that real function:

AVAILABLE_FUNCTIONS = {
    "get_server_health": get_server_health,
    "fetch_recent_logs": fetch_recent_logs,
    "restart_service": restart_service,
    "escalate_to_engineer": escalate_to_engineer,
}

Strip that dictionary away and the model can talk about restarting the server all day long. Nothing happens.

The model proposes. The harness disposes.

Once I saw this, I went back through both notebooks and realized almost everything I'd been mentally filing under "the AI is doing this" was actually something I wrote.

The loop. A single call to the model is stateless. It reads a prompt, generates an answer, and forgets that the conversation ever existed. Any sense of the agent "working through" a multi-step problem is just my code calling the model again and again in a while loop, each time stuffing the growing conversation history back into the prompt so it looks like the model remembers what happened three steps ago. It doesn't. I'm just showing it the transcript every single time.

The memory. This one sounds the most impressive from the outside and turns out to be the least mysterious up close. In both agents, "memory" is nothing more than a dictionary I update as the agent runs and re-inject into the next prompt. There's no persistence, no understanding, no internal state carrying forward on its own. It's a variable.

The tools. The model only knows a function like restart_service exists because I wrote a schema describing its name, its purpose, and what arguments it takes. Write that description vaguely and the model will reach for the wrong tool at the wrong moment, confidently. The tool selection isn't intelligence, it's documentation quality.

Put those three things together, the loop, the memory, and the tool schemas, and you basically have the entire architecture of an "autonomous agent." None of it is the model being clever. All of it is code I wrote around a model that, left alone, would just answer one question and stop.

That reframes what I'm actually building when people ask me what I do. I'm not fine-tuning a smarter brain. I'm building the scaffolding that lets a fairly dumb, stateless text generator look like it's taking real action in the world. The model is the commodity here. Anyone can call the same API I'm calling. The harness, the loop, the memory design, the tool schemas, that's the actual engineering, and that's the part nobody can just copy from a model card.

So I've started catching myself mid-sentence. "The agent restarted the server." No, it didn't. The model returned some JSON. My while loop restarted the server.

Next up, I want to dig into a problem I glossed over this week: that memory dictionary works fine when a conversation is short, but it breaks down fast once a conversation gets long enough to blow past the context window. At some point you have to decide what the agent is allowed to forget. That's where this gets genuinely hard, and that's the post I'm writing next.

FAQ

Do AI agents actually execute code or commands?

No. The model returns structured text, usually JSON, describing the function it wants called. Your code reads that request, runs the real function, and feeds the result back. Strip away the dispatch table and nothing happens.

What is an agent harness?

The code around the model: the while loop that calls it repeatedly, the dispatch table that maps its requests to real functions, the state you re-inject each turn, and the tool schemas that tell it what it is allowed to attempt. The harness is where the engineering lives.

Why do AI agents seem to remember things?

They don't. Models are stateless between calls. "Memory" is state your code persists and re-injects into the next prompt. Every "the agent remembers" is really "someone is replaying state outside the model."

What is the difference between a model and an agent?

A model answers one prompt and stops. An agent is a loop wrapped around a model: call, run the requested tool, append the result, repeat until there is nothing left to call. Take the loop away and you have a vending machine.

— Amisha

Filed under: AI Systems

Next in this series
Your Agent Has Amnesia. Here's the Dict That Fakes Memory.
Week 2