Skip to content

Block 07 / 07

The agentic loop

An agent is a loop: perceive, decide, act, observe, under a resource bound.

A completion predicts tokens. An agent takes actions. The durable picture is a loop: perceive the state, decide (sample a thought or a typed call), act (your runtime runs a tool), observe (the result returns to context). Halt on a final channel, a budget, or a guard. ReAct, tool calling, computer use, MCP hosts: same loop, different envelopes.

The model emits a structured request; the host executes it and returns an observation. When the path can be enumerated, the graph belongs to the program and the model fills slots. An open loop is justified when the path cannot be listed. The loop is the invariant; framework names are implementations of it.

Figure

Agent loop · retrieve, then calculatenext hopPERCEIVEDECIDEACTOBSERVEHop 1 of max 5HALT: final channelPERCEIVEUser asks: "What’s 12% of last month’s revenue?"

Step 1 of 12 · hop 1, perceive

Drag the slider to walk the loop one stage at a time. Watch it halt on its own once the answer is ready.

The same four stages repeat every hop: perceive the state, decide on a thought or a typed call, act by running it, observe the result. This trace retrieves a revenue figure on hop one, calculates 12% of it on hop two, and halts on hop three because the model itself emits the final channel, not because the budget ran out. A guard or a hop limit would stop the loop just as well; the invariant is the cycle, not which of the three ways it ends.

Algorithms

The loop itself, perceive, decide, act, observe, is a fixed shape. What varies is the decide step: the concrete procedure that turns the current state into the next action. AIMA classes agents as reactive, deliberative, or search-based by exactly that choice. The three families below are that classification applied to LLM agents.

Reference

In practice

An agent is a loop: perceive, decide, act, observe, under a resource bound. Tool-calling products are envelopes around that loop.

Laboratory

A traced loop with two tools and a budget

Implement perceive → decide → act → observe with a max hop count. Two tools: one retrieve, one calculate (or equivalent). Errors come back as observations. Idempotent writes. Emit a JSON trace per hop. One query that must retrieve then calculate. One query that should halt in a single hop. Both are eval cases.