Module 1 — The Agent Loop
A chatbot answers and stops. An agent keeps going: it takes an action, looks at what happened, and decides what to do next — over and over — until it reaches its goal. That repeating cycle is the single most important idea in this whole course. Strip away the buzzwords and every agent ever built is just a loop with four moves:
- Perceive — read the current situation (the goal, and whatever the last action revealed).
- Decide — choose the next action. This is where a real agent calls a language model; here it follows a simple rule.
- Act — actually do the thing (call a tool, make a guess, take a step).
- Observe — read the result of that action, and feed it back into the next "perceive."
The magic is the feedback: because each observation flows into the next decision, the agent adapts. It is not running a fixed script — it is reacting, step by step, to a world it cannot fully see ahead of time.
Drive the loop yourself
Below is the simplest possible agent. It has one goal — guess a hidden number between 1 and 100 — and one move: guess a number and get told "too high," "too low," or "correct." Watch how it perceives the range it knows, decides on the middle, acts, and observes the answer narrowing the range. Press Step to walk one perceive–decide–act–observe cycle at a time, or Run to let it finish.
This activity needs JavaScript. The lesson below still covers everything.
Why "middle of the range" is a smart decision
The agent never guesses wildly. By always choosing the middle of the range it still believes possible, every guess throws away half of what is left — so it homes in on any number from 1 to 100 in at most seven steps. That is the agent's tiny "brain": a rule that turns the current observation into the best next action. In a real agent, that rule is a language model. The loop around it is identical.
while not done: obs = perceive(state) # what do I know right now? action = decide(obs) # the "brain" — an LLM in a real agent result = act(action) # take the step / call the tool state = observe(result, state) # fold the result back in, then loop
Every framework — LangChain, the OpenAI Assistants API, Claude's tool use — is a more elaborate version of these four lines. The decide step gets smarter; the loop stays exactly this shape.
Check your understanding
A few questions about the agent loop. You will get a score.
This activity needs JavaScript.