← All AI Agents & Tool Use modules

Module 3 — The ReAct Pattern

Reasoning across steps · hands-on · about 30 minutes.

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:

  1. Thought — the agent reasons about what it still needs ("I need Tokyo's population first").
  2. Action — it calls a tool to get it (population("Tokyo")).
  3. 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.

The ReAct loop in code — read only, nothing to install
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).

AI anchor — ReAct is the default agent recipe The 2022 ReAct paper showed that making a model write its reasoning and act in the same loop beats doing either alone — reasoning keeps the tool use on track, and observations keep the reasoning grounded in real results instead of made-up ones. Almost every agent framework today (LangChain agents, the OpenAI Assistants API, Claude's tool use) runs some version of this Thought–Action–Observation loop. When you see an AI assistant "thinking," then searching, then thinking again, you are watching ReAct.

Check your understanding

A few questions about the ReAct loop. You will get a score.

This activity needs JavaScript.

Why this matters next The agent kept its whole trace in view to finish the task — but that working memory is not unlimited. Module 4 looks at the context window: what fits, what falls out, and how a long-term memory lets an agent remember across the gap.
One-sentence summary: ReAct interleaves Reasoning and Acting — the agent writes a Thought, takes an Action (a tool call), reads the Observation, and repeats, choosing each step only after seeing the last result, until it has enough to give a final Answer.

Next: Memory — Context & Recall →