All writing
AI SystemsJun 20267 min read

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

Function calling means the model emits a request and your code runs it. The dispatch table, the loop, the state dict: that is the engineering. Build the loop well and a mediocre model behaves like an agent.

Everyone keeps asking which model is “the agent.” Wrong question. The agent is the code you wrote around it — and that code is mostly a loop.

Function calling gets sold as magic, but it is almost aggressively mundane. You hand the model a list of tools with typed parameters. When it decides one is relevant, it does not call anything — it cannot. It emits a small structured request that says, in effect, “I would like you to run get_weather with these arguments.” That is the entire trick.

The model returns JSON. That is all it ever returns. Whether anything happens next is entirely up to you.

The model only returns JSON

Here is what actually comes back from a tool-calling turn. No execution, no side effects — a proposal:

// the model's response — a request, not an action
{
  "tool_call": {
    "name": "get_weather",
    "arguments": { "city": "Berkeley", "units": "metric" }
  }
}

Nothing has happened. There is no weather. There is a string that describes wanting the weather. The gap between that string and an actual answer is your program.

The loop is the agent

An “agent” is not a model with a personality. It is a while loop that reads the model's proposal, runs the matching function, feeds the result back, and repeats until there is nothing left to call. The dispatch table is the whole cast:

# your code, not the model's
AVAILABLE_FUNCTIONS = {
    "get_weather": get_weather,
    "search_docs": search_docs,
    "send_email": send_email,
}

while True:
    step = model.next(state)
    if step.done:
        break
    fn = AVAILABLE_FUNCTIONS[step.name]     # you route it
    result = fn(**step.arguments)           # you run it
    state.append(result)                    # you remember it

The intelligence proposes. The harness disposes.

Swap the model for a weaker one and, if your loop is good, the system barely flinches. Swap the loop for a sloppy one and the best model on earth will feel unreliable. That asymmetry is the whole job.

Memory is a dict

The model is stateless and frozen. It remembers nothing between turns. What looks like memory is you, deciding what to carry forward:

  • Keep the facts the next step needs.
  • Summarize what is getting long.
  • Drop what no longer earns its tokens.

Short-term memory is context-window management with a nicer name. It lives in a dictionary you own, not in the weights.

The schema is the prompt engineering

Most “prompt engineering” for tools is really schema design. Clear names, tight types, and one-line descriptions do more than any incantation in the system prompt. If the model keeps misusing a tool, the fix is almost always in the signature, not the personality.

The take, stated plainly

The model is a commodity that emits structured intentions. The harness — the loop, the dispatch table, the state dict, the schemas — is the craft. Build that well and a mediocre model behaves like an agent. Build it badly and no model will save you.

— Amisha

Filed under: AI Systems

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