Agent loop
One loop and one tool bag: every request is ask, act or make behind one door, and every way the loop can end is an answer.
The problem
AI features tend to grow one route at a time: /chat, /generate-query, /explain, /dashboard. Each gets its own auth, timeout, context and trace. The same capability ends up written three times, once as a chat tool, once inside a builder, once for a form, and every fix lands in one copy.
Then the loops fail in boring ways. A timeout cuts a turn off and the person sees nothing. An answer stops mid-sentence at the length limit. One tool throws and takes the request with it.
What I concluded
Three verbs, one door
Everything the assistant does is one of three verbs:
- Ask reads: run a query, find a record. The model reads the result.
- Act changes the screen: filter, navigate. The person’s screen reads it.
- Make produces one typed thing, like a report. The person gets a card.
Chat, slash commands, in-app buttons and MCP are all just ways into one endpoint. A button sends make with what it has. A chat message gets to the same producer through one generate(kind) tool. Same producer, same cache, same result.
chat ──────┐ ┌─ turn ──── agent loop
/command ──┼─▶ POST /assistant ───┼─ command ─ registry entry
button ────┤ auth, trace, └─ make ──── producer, no routing
MCP ───────┘ version
Sort by who reads the result
Behind the verbs, a capability is a tool (the model reads it), a workflow (the person reads it, as a card) or an engine (only code reads it). One engine per capability, exposed as many ways as it has readers, with an import rule so there’s one door into it. Fix grounding once and every exposure gets it.
Every exit is an answer
The loop has hard caps on rounds, time and output, and each cap steers toward words instead of stopping:
| Limit | What the person gets |
|---|---|
| Time running out | a forced final answer from what’s gathered |
| Output length | one continuation, then a visible cut-off note |
| A tool throws | the model sees the error and works around it |
Deadlines are absolute and carved from the parent’s, so a slow part can’t outlive the request. When the prompt gets too big, it shrinks in a fixed order: page context first, oldest turns last, the question never.
Rules
- Register once, adapt the ingress. A new way in is an adapter, never a copy of the capability.
- One naming rule. Tools, commands and kinds are kebab-case and unique everywhere, so they map straight onto MCP.
- Every tool call gets a result, including an unknown tool or bad input.
- One of each recovery. At most one continuation and one nudge per turn, so recovery can’t loop.
- Traces keep shape, not values. Tools that touch customer data say so, and their results are logged as counts.
What you get
Gates, caching, tracing and versioning happen once, at the door. None of the limits got softer, they just all end somewhere useful: an answer, a partial answer with a note, or a card marked “took too long”.
Related: Event stream, Stateful or stateless, Step tree.