What this is about
In the last article we drew the agent loop: choose an action, run it, read the result, decide again. This article opens the middle of that loop. How does a model that only writes text "run" anything?
The answer is that it does not. It writes a request. A separate, ordinary program reads the request, does the work and hands the result back as more text. That request is called a tool call.
Why it matters
Once you see this, agents stop looking like magic.
You can see where the power lives: in the tools, which are normal programs you can read and test. You can see where the risk lives: in what each tool is allowed to do. And you can see why agents fail in odd ways, because the model has to write the request in exactly the right shape, every time.
How it works: one round trip
Here is one round trip, in six steps.
- The model is told what tools exist. Before the task starts, the model receives a short list. Each entry has a name, a one-line purpose and the inputs it takes. For example: "calc: does arithmetic, input is an expression."
- The model gets a question. Say, "What is 17 times 23?"
- The model writes a request instead of an answer. It does not guess. It writes something like a name and a few fields: the tool is
calc, the input is17*23. This is plain text in a fixed shape, so a program can read it. - A program runs it. The surrounding software spots the request, calls the real calculator and gets
391. The model did no arithmetic here. - The result goes back as text. The software adds "calc returned 391" to the conversation, so the model can see it.
- The model writes the final answer. "17 times 23 is 391." The loop ends.
That is the whole mechanism. Notice that steps 4 and 5 are not the model at all. The model only writes in step 3 and step 6.
Why the shape matters
The software that reads step 3 is strict. If the request is missing a bracket, the program cannot run it. So tools work best when the model is pushed toward valid shapes.
One way to push is a grammar. A grammar here means a rule that only lets the model write well-formed tool-call text. It is like a form with boxes: you can only fill in boxes that exist.
We train a small model, Metis, with 72.6 million parameters, to call four of our tools: calc, brain_ask, web_fetch and run_js. In the series "Training Metis" we describe a test of 56 prompts, each expecting one particular tool call. One earlier round scored 55 of 56. A later model scored 50, including 19 of 20 prompts that needed brain_ask.
When the loop does not stop
Here is the failure we promised. On row 42 of that test, Metis wrote 223 brain_ask calls in a single message. Our worst case in another sample was 280.
Why? The model had learned the format. It had not learned to stop. In the failing case it wrote the start of an argument, then a lone quote mark. After that, the grammar allowed only two continuations, and the model kept picking from them. It was boxed in.
We tried 20 different fixes in 6 families, and none of them cured the loop. We say so because a beginner should know that agents fail in ordinary, mechanical ways, not only in mysterious ones. The honest response is a limit and a test, not a clever story. After this, we changed our test harness so a looping row counts as one failed row and not a crashed run.
The lesson for you: any agent needs a cap on how many calls it can make in one turn.
Who runs the tool, and where
Where the tool runs is a design choice with real consequences.
On your own machine. Tools run with your files and your permissions. That is handy and a little scary. You want checks on what they may touch. Our article on permissions covers that.
In a proxy in the middle. Our project ctxd sits between a client and a model API. When a long chat is folded into a summary, ctxd offers the agent three small tools of its own: ctx_expand to get back the original messages behind a summary, ctx_search to find an exact piece of text in the session, and compress to fold older history now. ctxd runs those calls itself and answers the client with the final message. The client never sees the extra round trips.
In a terminal built for agents. Dynoshell is our own terminal for AI agents. One window runs Claude Code, codex and plain shells side by side, and the panes live in a server, so closing the window does not stop the agents. Its control socket is itself a set of tools: another agent can list panes, spawn one, send keys and read what a pane shows. So here an agent's tool is another agent's terminal. That makes the question "what may it touch?" a design question from the first day.
Three habits for using tools well
- Give each tool one clear job and a clear name. A tool called
do_stuffinvites wrong calls. - Keep results short. Everything a tool returns is text the model must read, and reading costs tokens. The article on token costs explains why that adds up.
- Cap the loop. Set a maximum number of calls per turn, and a maximum per task.
Glossary
- Tool call: a request written by the model, in a fixed text shape, asking a program to do something.
- Tool: the program that does it. It can be small, like a calculator.
- Grammar: a rule that limits which text the model may write next, so the shape stays valid.
- Proxy: a program that sits between two others and passes messages along, sometimes changing them.
- Pane: one shell or agent view inside a terminal window.
- Held-out question: a test question the model never saw while it was trained.
Try it
- Read how ctxd handles tools on the ctxd project page. Look for the section on
ctx_expandandctx_search. It is a real, small example of tools an agent can call. - See where agents run at Dynoshell, our terminal for AI agents. Read how its control socket lets one agent drive another's panes, and ask what each tool in that list would let an agent touch. It is not available for download yet, so this is a read.
- Do a paper exercise. Pick a chore, such as "tidy my downloads folder." Write down the three tools an agent would need, and for each one, the worst thing it could do by mistake. That list is how real agent designs begin.
Next in the series: why agents forget, and what memory fixes.

Commenti
Ancora nessun commento.
Accedi per commentare.