What 1.5 years of building agents taught me: loops, tools, and specs
November 20, 2026 • 9 min read
Table of contents
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.
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:
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.
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.
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:
- one asks for too many inputs and dumps all its data back into the agent loop;
- one takes minimal input, does the processing on the agent's behalf, and returns a reference to the tool output back to the agent.
The second round trip carries so little bloat that it's very light on the context.
Some ideas that make a better tool:
- Less context bloat on each run (optimise your tools not to load everything, but to reference the inputs well).
- Outputs are referenced instead of dumped back into the context window.
- Better file hashes and inline edits.
- The tool itself can inherit context from other tools and agent artifacts (meta tools).
- Simplicity, actually (as pi proved).
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"
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:
- Long-running sessions and streams: Classic databases and backend systems deal with one-off static data that finishes its lifecycle in a single step (or a few deterministic ones), but with agents, a session can run for multiple minutes, stream data in batches, crash, and even recover when an error comes in. What you deal with and learn now are SSE streams, heartbeats for agent state, disconnects, reconnects, and more.
- Errors are a boon to the next turn, not a curse: If something fails in classic systems it shows something is brittle in the implementation, but in agents multiple things can coincide to produce an error: a misfired tool call, a bad implementation, permission access, and what not. Instead of only dumping them into logs, the errors you return back to the agent are golden in their own right, because they help the next step take a more focused approach.
- Cancellation, timeouts, and idempotency are the failure cases to account for: Users can interrupt a call, tools can stall, APIs hang, and in cases like these you need to make sure cancellation is wired down to the last HTTP call and subprocess. The system should know how to retry and when to wind down if nothing works.
- Protection from unbounded payloads: While data is a boon, all data is not. A SQL log can contain a lot of detailed information, but we need to be mindful of how that reaches the context. Instead of pumping it back into the LLM, our tool outputs need to truncate, spill large outputs to disk, and reference them back so nothing chokes the context window.
- Data is a loose cannon: Your payloads are no longer one fixed datatype. A stream carries mixed event types (text deltas, thinking, tool calls, tool results, errors) where the contract is a small envelope around flexible content, so make sure to account for those.
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.
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
- OpenAI Responses API - the list-in, list-out format every loop above is built on
- OpenAI function calling guide - how tool calls and their outputs travel through that format
- pydantic-ai agents and pi - two codebases where the run loop is easy to read
- How I built a tool calling engine for my Go agent SDK - tool registration, schemas, and execution from scratch
- Anatomy of Subagents - nested runs, isolation, and delegation
- Let's learn LLM streaming from first principles - SSE and streaming inside an agent loop
- WHATWG Server-Sent Events spec and JSON-RPC 2.0 spec - the old specs the new stuff is built on
Diagrams lettered in xkcd-script (CC BY-NC 3.0). Banner: Diego Velázquez, Las Hilanderas (c. 1657), Museo del Prado.