The loop
An agent runs a cycle until a stopping condition:
- Reason — the model decides what to do next given the goal + history.
- Act — it emits a tool call (function calling; see Foundations Ch. 1).
- Observe — your code executes the tool and returns the result into the context.
- Repeat — the model, now conditioned on the result, either calls another tool or produces the final answer.
ReAct (Reason + Act)
The canonical pattern (Yao et al., 2022): interleave Thought → Action → Observation steps. The model writes a reasoning trace ("I need the user's plan, let me query the DB"), takes an action (tool call), sees the observation (result), and reasons again. Making the reasoning explicit improves tool selection and gives you a trace to debug. Most agent frameworks are ReAct under the hood.
Tools are the agent's hands
An agent is only as good as its tools. From Foundations: few, high-level, consolidated tools; descriptions written for the model; low-token, curated results; enums over free strings; and actionable error messages the model can recover from. A vague tool or a raw error dump derails the whole loop.
Stopping criteria (don't skip this)
An agent needs to know when to stop: task complete, a max-steps/iteration cap, a max-cost/token budget, a timeout, or explicit "give up and ask the human." Without a hard cap, a confused agent loops forever, burning tokens — the #1 way agent bills explode. Always bound the loop.
Context grows fast
Every step appends the thought, the tool call, and the (possibly large) result to the context. Long loops blow the window and cost. Manage it: summarize old steps, truncate/curate tool outputs, and keep only what the next decision needs.