The Agent Loop: Perceive → Plan → Act
The three-phase loop
Perceive: gather current information (a tool result, user input, environment state). Plan: reason about what to do next given the goal and current state. Act: execute one step (call a tool, respond, or finish). Then the loop repeats.
Why looping beats a single generation
A single-shot prompt can't adjust based on real results. The loop lets the agent try something, see if it worked, and correct course — this is what makes agents capable of handling tasks with unpredictable intermediate results.
Knowing when to stop
Every agent loop needs a clear stopping condition: the goal is achieved, a maximum number of steps is reached, or the agent explicitly decides it cannot proceed. Without this, loops can run indefinitely and burn cost.
Key Takeaways
- The agent loop is: perceive → plan → act, repeated until done.
- Looping lets agents adjust based on real intermediate results.
- Always define an explicit stopping condition.
- Unbounded loops are a real cost and safety risk.
Trace a manual agent loop
Pick a multi-step task and manually write out each perceive-plan-act cycle you'd go through to complete it, including your stopping condition.