Lesson 1 of 8 · 3 min read
ReAct
In this lesson
TL;DR: ReAct decides one step at a time: reason briefly about what is known, take one action, read the observation, and reason again. Because every decision sees the latest evidence, it recovers from surprises and avoids inventing facts it could look up. Because it never commits to a whole plan, it can wander, repeat itself, or optimise each step while missing the goal. Use it when the path is unknown and short; add a plan, a state graph or budgets when the task is long, ordered or costly to get wrong.
After this lesson, you should be able to describe the ReAct pattern and how it is implemented with native tool calls, explain what grounding buys over reasoning alone, recognise its characteristic failures in a trace, and decide when it is the right control pattern.
Before you read
Commit to an answer now. The lesson that follows explains it, and having guessed first, even wrongly, makes the explanation easier to remember.
1An agent answers 'Which of our three warehouses can ship 400 units by Friday?' by reasoning through likely stock levels without calling the inventory tool, and gets it wrong. What would a ReAct-shaped agent have done differently?
The pattern
Yao et al. (2022), "ReAct: Synergizing Reasoning and Acting in Language Models", compared three ways of solving tasks that need outside information: reasoning only (chain of thought), acting only (a sequence of tool calls), and interleaving the two. The interleaved version did better on several knowledge and decision-making benchmarks, and its traces were easier for people to read and correct. Reasoning-only answers invented facts that a lookup would have caught; acting-only runs lost track of why they were taking each action.
Today the pattern is mostly expressed through native tool calling: the model writes a little reasoning (visible or as extended thinking), emits a tool call, the harness runs it and returns the result, and the loop continues. The paper's Thought: / Action: / Observation: text format is rarely needed.
Watch it adapt
- 01userWhich warehouse can ship 400 units of SKU 7731 by Friday?
- 02toolinventory_get(warehouse=pune sku=7731)
- 03result120 unitsok
Act on the most likely option
The model reasons that Pune usually has stock, checks it, and finds only 120 units.
What it costs and where it fails
Myopia. Each step picks the best next action given what it knows. Tasks that need a global ordering (migrate the schema before the code that reads it) or a budget across steps can be done locally right and globally wrong.
Wandering and repetition. Without a plan, a confused run can circle: search, read, search again with a slightly different query. Harness budgets and repeated-call detection catch this; ReAct itself does not.
Misleading observations. ReAct trusts what came back. A stale cache, a partial search result or an injected instruction in a page goes straight into the next decision. The grounding that prevents invention also imports whatever the tools return.
Cost of rereading. Every step rereads the whole history. Long ReAct runs spend most of their tokens on context, which is why the context-engineering techniques (clearing, notes, caching) matter most for this pattern.
A minimal loop
def react(model, tools, task, max_steps=8):
history = [("task", task)]
for _ in range(max_steps):
thought, action, arg = model(history)
history.append(("thought", thought))
if action == "finish":
return arg, history
observation = tools[action](arg)
history.append(("observation", f"{action}({arg}) -> {observation}"))
return None, history
STOCK = {"pune": 120, "chennai": 900, "delhi": 610}
SCRIPT = iter([
("Pune usually has stock; check it.", "stock", "pune"),
("Only 120. Try Delhi.", "stock", "delhi"),
("Delhi has 610, enough for 400.", "finish", "delhi"),
])
answer, trace = react(lambda h: next(SCRIPT), {"stock": STOCK.get}, "400 units of 7731")
print(answer, sum(kind == "observation" for kind, _ in trace)) # => delhi 2
The scripted model stands in for a real one. The shape is what matters: one action per step, every next thought written after the latest observation, and a step limit owned by the loop, not by the model.
When to use it
| Situation | ReAct? |
|---|---|
| Short task, unknown path, cheap reads | Yes: the natural default |
| Long task with an obvious order of phases | Add a plan (plan-and-execute) |
| Steps with rules that must be followed in order | An explicit state graph, with ReAct inside some nodes |
| Each step is expensive or irreversible | Plan, check, then act; ReAct only for reads |
| Quality matters more than latency, and answers can be checked | Consider search over several trajectories |
Say it in 30 seconds
"ReAct interleaves a short piece of reasoning with each action and reasons again after each observation, so decisions are grounded in evidence rather than guesses; that is why it beat reasoning-only and acting-only baselines in the original paper, and why most tool-using agents are shaped like it, through native tool calls. Its weaknesses are myopia, wandering and repetition, trusting misleading observations, and rereading cost on long runs. I use it for short, open-ended tasks and add plans, state graphs or budgets when order, length or risk demand it."
Check yourself
Answer aloud or on paper before revealing. Producing the explanation unaided is exactly what a panel listens for.
1Why did interleaving reasoning with actions beat reasoning alone on knowledge tasks in the ReAct paper?
2A ReAct agent migrates application code before migrating the database schema, and every step looked reasonable. What property of ReAct explains this, and what would you add?
3Why does ReAct's grounding also make it vulnerable to misleading or injected tool output?