← Back to Aigentz
The Brain · 03 of 09

The Eleven Steps

One run, from a cold trigger to a committed result, and the flow chart it draws.

A run is one trip from a cold trigger to a committed result. The ring is the part that repeats: every trip around it is one pass, and every pass costs one model call. The run below takes two passes, which is the minimum for any run that uses a tool: one pass to ask for the tool, one pass to read what came back and answer.

  1. 01Triggergate · pass 1Something wakes the agent: a cron tick, a queue row claimed, an inbound message, a webhook. It fires once and hands control to context assembly. The model is not involved.
  2. 02Contextring · pass 1The runtime builds the whole input: system prompt, tool definitions, retrieved documents, prior turns, and the live input at the tail. Static parts sit at the front so they can be cached. Rebuilt from scratch every pass.
  3. 03Breakerring · inline guardBudget check before the model call: passes used, tokens spent, dollars spent, wall clock. Checking here is what stops you paying for the inference you meant to prevent. Under the ceiling, current passes.
  4. 04Modelring · inferenceThe context goes out, one reply comes back. This is the only place thinking happens and the only thing that costs tokens. The reply is either a tool request or a final answer, never both.
  5. 05Decidering · branchThe runtime reads the reply's stop reason. Tool request routes down to dispatch. Final answer routes right to the exit. This single junction is the whole loop.
  6. 06Dispatchring · pass 1The runtime executes the request, never the model. The model wrote JSON saying which tool and which arguments; the runtime is the one with a network, a database handle, a file system.
  7. 07Executelegs · fan-outOne reply can carry several tool requests, so the legs run in parallel and every one must return before the ring closes. A leg can be gated: a human approves, denies, or edits the arguments before a database write.
  8. 08Returnring · pass 2 beginsResults and errors ride the same wire back into context, as text. A timeout or a 500 is not a thrown exception; it is a message the model can read and correct on the next pass. Context is now bigger than it was.
  9. 09Finalexit · pass 2Second trip through the ring: breaker, model, decide. This time the model returns a final answer instead of a tool request, so the junction routes to the exit and the loop breaks.
  10. 10Validateexit · typecheckThe answer is coerced into a schema before anything downstream touches it. Malformed output bounces back for one more pass with the parse error in context, rather than reaching storage.
  11. 11Commitexit · persistWrite the result, respond to whoever asked, release the lock, log the cost. The run ends here. The agent is not running until the next trigger.

gatethe ringlegs (tools)exit

Count the model calls: two, at steps 04 and 09. Every other step is code. That is the point of the whole page.

The flow chart

Solid lines are pass one. Dashed cyan is the ring closing: the return wire that makes it a loop. Read it as: wake, build, guard, think, branch. Branch down means another pass. Branch right means the run ends.

Runtime · your codeWakeTriggerAssembleContextBreakerInferenceModelthe only model call · $BranchDecideTypecheckValidatePersistCommitDispatchTool busLeg · gatedDatabaseLegAPILegSearchHITLtool_use → another passend_turnReturn · results and errors, as textmalformed → bounce, one more passpass 1 → pass 2 → …each pass = one model call
The loop. Only the Model box is the model. Everything else is the runtime.