# The Agent Loop **Track:** Models, Tools & Agents — AI-Native Full-Stack Development — complete (30) **Framework / surface:** web dev (agent runtime) **Level:** Intermediate **Prerequisites:** Tool Calling: Giving Models Capabilities **In one line:** Model → choose action → call tool → observe result → update context → continue or stop. ## Theory, aesthetics & inspiration Strip the mystique and an agent is a loop. The runtime sends input and context to a model; the model returns either a final answer or a request to use tools; the runtime executes the permitted calls, appends the results, and asks again — until the model finishes, a stopping rule fires, or a safety limit trips. The shape was formalized in the ReAct paper (Yao et al., 2022), which interleaved reasoning traces with actions, and Anthropic's "Building Effective Agents" (December 2024) distilled the production consensus: simple, composable loops beat elaborate frameworks. The harness matters as much as the model — it caps turns, validates tool calls, records traces, applies approval rules, and decides what context flows forward; a bare while(true) around an LLM is not an architecture, it is an unbounded failure mode. Build one minimal loop by hand before adopting a framework's: once you can see the state transition after every step, cost, latency, runaway loops, and error recovery all become things you can reason about precisely. **Builder question:** What are the explicit stopping conditions that prevent this agent from continuing forever or taking unnecessary actions?