Module 3 — The ReAct Pattern
Module 2's agent made a single tool call and was done. But most real questions are not one-shot. "How many more people live in Tokyo than Paris?" cannot be answered by one lookup — the agent has to find Tokyo's population, then Paris's, then subtract. It needs to think, act, see the result, and think again. That interleaving has a name that has become the default recipe for agents: ReAct — short for Reasoning + Acting.
Thought → Action → Observation, on repeat
ReAct structures the loop into a visible trace of three repeating moves:
- Thought — the agent reasons about what it still needs ("I need Tokyo's population first").
- Action — it calls a tool to get it (
population("Tokyo")). - Observation — it reads the tool's result, which informs the next Thought.
Those three repeat — Thought, Action, Observation, Thought, Action, Observation — until the agent has everything it needs and emits a final Answer. Crucially, each step is chosen after seeing the previous observation. The agent is not following a fixed recipe; it is reasoning its way forward one step at a time, exactly the loop from Module 1 but now with reasoning written out loud and real tools at each step.
Watch a multi-step question unfold
Pick a question that needs more than one tool. Press Step to reveal one Thought–Action–Observation at a time and watch the agent gather the pieces, or Run to see the whole trace. Notice how the final calculation only becomes possible after the two lookups have happened.
This activity needs JavaScript. The lesson below still covers everything.
state = {"goal": question, "history": []}
while not done:
thought, action = model(state) # reason, then choose a tool
if action.is_final:
answer = action.text; break
observation = tools[action.name](action.arg)
state["history"].append((thought, action, observation)) # feed it back
The whole growing history — every past Thought, Action, and Observation — is handed back to the model on each turn. That accumulated trace is the agent's working memory for the task (and, as we will see in Module 4, it has a size limit).
Check your understanding
A few questions about the ReAct loop. You will get a score.
This activity needs JavaScript.