Module 3 — The ReAct Pattern
The agent in Module 2 performed a single tool invocation. Most real questions, however, are not single-step. "How many more people live in Tokyo than in Paris?" cannot be answered by a single lookup — the agent must retrieve Tokyo's population, then Paris's, then compute the difference. It must reason, act, observe the result, and reason again. This interleaving of reasoning and tool use is formalized in the ReAct paradigm — Reasoning + Acting — which has become the de facto standard for agent design.
The Thought–Action–Observation cycle
ReAct organizes the agent loop into an explicit trace consisting of three recurring operations:
- 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.
These three operations repeat — Thought, Action, Observation, Thought, Action, Observation — until the agent has gathered sufficient information to emit a final Answer. Each step is selected after observing the result of the previous one. The agent is not executing a fixed plan; it is reasoning incrementally, exactly as in the Module 1 loop, but with reasoning made explicit and tool calls available at each step.
Trace a multi-step question
Select a question that requires more than one tool invocation. Click Step to advance one Thought–Action–Observation iteration at a time, or Run to display the complete trace. The final computation is performed only once the prerequisite lookups have completed and their results have been observed.
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 complete history — every prior Thought, Action, and Observation — is supplied to the model at each iteration. This accumulated trace constitutes the agent's working memory for the task. As discussed in Module 4, this memory has a finite capacity.
Check your understanding
Answer a short set of questions on the ReAct loop.
This activity needs JavaScript.