Think, act, observe, repeat
The four steps of the loop, walked through with a real coding example.
Every agent loop, no matter how it is built, is the same four steps running in a cycle. Learn these four words and you understand the machinery behind agentic AI.
- Think — decide what to do next, based on the goal and everything seen so far.
- Act — take one action: call a tool, run some code, search the web, read or edit a file.
- Observe — look at the actual result of that action: the output, the error message, the search results.
- Repeat — feed that result back in and think again.
The loop keeps turning until the task is finished or a stopping rule kicks in (Module 2).
A worked example: fix a failing test. Say you ask an AI to fix the one failing test in a small project. A single prompt would read the code you pasted and return its best guess. A looping agent does what a careful developer does:
- reads the relevant files (act) and sees how the code is structured (observe),
- makes a change (act),
- runs the tests (act) and sees that 2 of 5 still fail (observe),
- reads the error messages (observe) and reasons about the cause (think),
- makes another change (act),
- runs the tests again (act), sees them pass (observe),
- and stops, because the goal is met.
Notice that every pass is informed by the real result of the previous one. The agent did not need to guess whether its fix worked — it ran the tests and looked. That is the loop doing exactly what a single prompt cannot.
This is why tools like Claude Code, Cursor, and Devin can take a whole task rather than just answer a question. Under the hood they are running this loop: think, act, observe, repeat, against a goal, with real tools (a code editor, a terminal, a test runner). Strip away the branding and it is these four steps.
Recap. The agent loop is four steps on repeat: think (decide the next action), act (do one thing with a tool), observe (look at the real result), repeat (feed it back and think again), until the goal is met or a rule stops it. The fix-the-failing-test walkthrough shows why it works — each attempt is informed by the actual outcome of the last, so the agent corrects course instead of guessing once. Coding agents like Claude Code, Cursor, and Devin are exactly this loop wrapped around real developer tools.
Pick a multi-step task (planning a trip, researching a purchase, fixing something). Write it out as one turn of the loop: what would the AI THINK first, what one ACTION would it take, what would it OBSERVE from that action, and what would it likely do on the next repeat? Doing this once makes the loop concrete.
Enjoying the free lessons? Get an email when we publish new courses and updates — no spam, unsubscribe anytime.
Discussion (0)
Ask a question or share what worked for you. Comments are reviewed before they appear.
No comments yet. Be the first to start the discussion!