Building AI Agents
The Agent Loop: Observe, Think, Act, Repeat · 1/2

Breaking down the loop

observethinkact

Nearly every agent framework, regardless of implementation details, runs on some version of a simple loop: observe the current state, think about what to do next given the goal and everything learned so far, act by taking a concrete step, usually through a tool, and then observe again to see what changed before deciding the next action. This loop repeats until the agent decides the goal has been reached, or it hits a limit like a maximum number of steps.

Consider an agent tasked with fixing a failing test in a codebase. It observes the current state by reading the error message and relevant files, thinks about what's likely causing the failure, acts by editing a line of code, then observes again by rerunning the test. If the test still fails, it loops back through the same cycle with new information, refining its understanding each time rather than guessing blindly.