What 1.5 years of building agents taught me: loops, tools, and specs

November 20, 2026 • 9 min read

Diego Velázquez's painting Las Hilanderas: women spin and wind wool in a dim workshop around a turning spinning wheel, while a bright mythological tapestry scene plays out in the room behind them.

I actually don't know how this blog will end, but I will try my best to condense all my ideas into one train of thought that anyone needs to catch up in this agentic race.

You don't need to follow the latest trends, the latest model, or the latest "this will take my job" release. All these agentic trends are reheated, rehashed versions of the same dish, and I will present it the way I like to digest this influx of agent slop.

You can ask your Claude to explain this blog to you. Just ask it to create a few Excalidraw diagrams of the while loop that run() functions use across harnesses, and a bit about how tools work internally (which you can also learn from my other blog if you want to go deep). Basically, ask it to break down the run loop, tools (reflection), and the other important things for you.

I will use the terms harness and agent interchangeably in this blog, so just understand that I am talking about the core logic running this system.

This is all just what I can recall in my last 1.5 years of doing agentic engineering as you call it. It all started with langchain/camel-ai for me, and now has evolved into a full-blown area of engineering. This is my attempt to share all the alpha here.

It's all a while loop

Even when I write for others about their agentic infrastructure, I always try to sneak in how the whole agentic world is run by a while loop.

xkcd-style comic: a tall, wobbly tower of blocks labelled 'all of agentic engineering' rests on one thin block labelled 'a while loop()'. One stick figure asks 'Wait, it's all a while loop?' and another answers 'Always has been.'
Adapted from xkcd 2347.

You might think all the LLM harnesses and agents must be some complex reincarnation of a superintelligence, but in practice they all follow this logic:

history = [user_message]
while True:
    reply = llm.call(history)
    history += reply
    if not reply.tool_calls: break
    history += run_tools(reply.tool_calls)

Every harness and every agentic loop, from the most complex codebase to the simplest SDK, is just a wrapper around an LLM hosted somewhere. For the most part, you don't need to know the details of the model or its weights. All you care about is that you need to iterate this text stream on top of itself.

All they do is call an LLM Responses API (read the OpenAI docs for this if you don't know what a Responses API is).

It's just a format. You send a list of items (your messages, the instructions, and the tools the model is allowed to call), and you get a list of items back (a text reply, a tool call, maybe some reasoning). Whatever comes back gets added to the list you send next time, and that defines the whole contract:

xkcd-style diagram titled 'A list goes in. A list comes out.' On the left, what you send: instructions, your messages, tools it may call, and what came back last time. An arrow goes into a stick figure labelled 'the model', and another comes out to what comes back: a reply, a tool call, some reasoning. A loop carries those back onto the next list.

Most of these providers follow the same API format. I would suggest you just stick to OpenAI for the most part, as they are the industry standard; they explain the internals of conversation state and function calling in their docs (Anthropic and Google do things a bit differently, but the core ideas behind these APIs remain the same).

Every codebase will have something called a run() function that accumulates all the important pieces to run the modern harness (messages, history, tool calls, outputs, errors, etc.) and outputs the final response. All the loop cares about is how it wants to exit. It can be a finish reason, hitting a turn limit, or maybe just an error. All they do is run the same loop again and again, and each new output becomes the tail of the input for the next message.

xkcd-style diagram titled 'Every turn, the whole pile goes back in.' Turn 1 sends a system prompt and the user's message, turn 2 adds the model's read_file call and 400 lines of tool output, turn 3 adds two more, and by turn 40 an 80-message stack wobbles. Already-sent messages are shaded grey and sent again anyway, while a stick figure says 'It's still one array.'

The TL;DR of it all: you call an API, it turns into a message vector, the message vectors stack on top of each other to form history, and the loop keeps running until the model stops calling tools and ends with a message.

Understand this pattern and every harness will be demystified. That is why I love pydantic-ai and pi: both present this simple idea very evidently in their loops, which makes it very easy for me to trace how all the other helpers fit together.

It's also just a tool call

When you go one layer below, into the harness space (or just the place where the while loop runs), what separates a good run from a bad run is a tool call. Tool calls are the connective tissue, an abstraction that allows agents to perform actions on your machine.

Tool calls are just functions (yes, really), but they flip the conversation: instead of you manually putting the parameters in and expecting a result, the agent does it and gets a response back. That response gets fed back and affects the next action the agent takes.

xkcd-style diagram titled 'The model asks. Your machine does it.' The model asks the harness on your machine to read the README, the harness opens it and hands the file back, the model then asks for main.py, gets it the same way, and finally answers 'Here's how your app works' with no tool call, so the loop ends.

While this is basic, most agents need only four tools in their catalogue, as the pi harness suggests: read, write, edit, and bash. (Maybe all this actually hints that we can get better outputs with fewer basic tools than by burying ourselves in detailed abstractions and a plethora of tool definitions.)

But the reason I ask people to work on optimising their tools is that the more optimal the tool is (it preserves context and needs minimal tokens from the agent to execute), the cheaper and more effective your agent will be.

One way to present this idea is to think about two tools:

xkcd-style diagram titled 'Both tools find the crash. One also buries it.' Tool 1 makes the model fill in eight inputs and sends back all 4,000 matching log lines, burying the context window while a stick figure says 'I needed one line.' Tool 2 takes one input, reads and sums up the logs itself, and returns one short line pointing to crashes.txt, leaving room to think.

The second round trip carries so little bloat that it's very light on the context.

Some ideas that make a better tool:

The subagent dilemma

You might have heard about subagents, a smaller fleet of agents that your main agent can spawn. That's also just a tool call.

Subagents are just tools a main agent calls to provision agents that run in an isolated session with a timeout.

start_subagent(task="Find every caller of refund() and list the files", model="gpt-5.4", timeout_s=300)
# -> the same run() loop, with a fresh history; only the final answer comes back:
# "3 callers: billing.py, api.py, jobs.py"
xkcd-style diagram titled '30 turns in the subagent. One line in your history.' The main loop hands a task to a subagent, which starts a fresh history and stacks 30 turns of searching and reading. Only its final answer, 'billing, api, jobs', comes back as a single line in the main loop's history.

One who masters tools can master the run loop in their harness.

Sadly, it's still backend engineering

I feel a lot of basic frontend is solved for devs. You decide on a schema, build a React app around it, and from there the agents can create a usable place for you to run your apps through a visual medium. You don't need to understand a library that renders a visual medium (graphs, charts, UI components). For most of my understanding and my work, I like to think of it as a black box that needs a certain JSON schema going in and generates the UI I want. If your focus is the core agentic part, focus on the schema rather than the spectacle; the rest is solvable by most models in their current state. It's surely not polished, or maybe even production-level, but it removes the barrier of waiting for a frontend developer to build a skeleton around your APIs to test with.

The neat part is that the fancy decor of your agentic journey, be it MCP or A2A, is not going to take you very far.

All you actually need to focus on is the fundamentals of systems, specifically the backend.

You should not approach this the basic way of doing backend, but rather invert the approach, because agents stream their data very differently from a classic backend.

Your agent can't magically spit data to the frontend, so here are a few mental models to keep in mind when building the backend for agents:

I like to visualise all my data in a schema/struct first and then approach things from the POV of a cannon shooting deltas of streams.

xkcd-style comic titled 'Draw the shape first. Then fire.' A sheet of paper reads 'Every shot has: what kind it is, which run it came from, what is inside.' Below it a stick figure says 'I know the shape of every shot' beside a cannon labelled 'your backend', which fires grey boxes labelled text, thinking, tool call, tool result and error in an arc to a stick figure labelled 'your frontend'. A note says grey is the same small envelope and anything can be inside.

How to learn: old is where the gold is

I see people asking for resources to learn AI agents, and people talking to their LLMs about it. As I discussed in the backend section above, whatever I told you is not special knowledge. Heck, it's not knowledge that appeared 3 years ago at the inception of ChatGPT, but rather fundamentals of systems and CS that have been built over the last 20 years or so.

Where is the alpha then? What is the real resource to learn it all, actually?

Specs (yes, really, that's the real gold).

While writing my blog on streaming, I did not go to how OpenAI does its streaming (even though I did use it for reference), but rather to the SSE specs that were written properly 20 years or so ago.

During my time at ACI, my CTO told me to focus on nothing more than the specs. That advice holds today and always will: learning the general system behind a problem, instead of just one framework built on top of it, is where the learning alpha lies.

All these protocols we see every other day promising to revolutionise how we talk to agents, tools, and what not, be it MCP, A2A, or ACP, are built on JSON-RPC 2.0 under the hood. They all follow the same underlying architecture with a few tweaks here and there. Do I need to learn all these protocols? No. Just learn how JSON-RPC works from the spec, and let specs be the ultimate source of what to learn. Everything in specs written 20 years ago gets packed and repurposed again and again (every six months). It's on us to learn the fundamentals first rather than trying to absorb the new buzz every time.

The same way, the real alpha for the internals of sandboxing does not lie in modern abstractions like E2B or Daytona. It lives in the older OS and networking primitives underneath them: Linux namespaces, cgroups, microVMs, and how processes and networks get isolated.

Get your fundamentals right; this has never been more true.

So I guess this is how the blog ends. Underneath all the new frameworks, protocols, and weekly releases, it is still a while loop calling tools on top of solid backend fundamentals and specs written by some grumpy old guy. Learn those once, and every new "breakthrough" in your feed starts converging to similar pointers.

I will probably start writing more around this topic: sandboxes, how Replit and similar apps are built, and a lot more. Follow me to stay tuned!

Connect with me

Twitter / GitHub / LinkedIn / Email


Further reading

Diagrams lettered in xkcd-script (CC BY-NC 3.0). Banner: Diego Velázquez, Las Hilanderas (c. 1657), Museo del Prado.

Connect with me