Topic 1 of 5 · 4 min read
Reason, act, observe: the ReAct cycle
Goal: Trace a reason-act-observe transcript and point to the observation that should have changed the agent's next action.
An agent is a loop: the model reasons about what to do, calls a tool, reads the result, and reasons again, until it decides it is done. The result of each action is called the observation, and it is the only way the agent learns whether its guess was right.
Check yourself · 1 of 3
In an agent loop built on a tool-calling API, who actually runs the tool the model asks for?
Why it matters
The ReAct paper (Yao et al., 2022) showed that mixing reasoning steps with actions beats reasoning alone, which invents facts, and acting alone, which has no plan. Today you rarely write ReAct prompts by hand. Claude, ChatGPT and Gemini all support tool calling natively, and several can think before each call. The loop is still the shape of every coding agent, support bot and research agent. If you cannot read a loop, you cannot debug one.
How it works
Each turn has three parts:
- Reason. The model states what it knows and what to try next. With extended thinking this happens in a separate thinking block.
- Act. The model emits a tool call: a name and arguments. The model does not run anything. Your code does.
- Observe. Your code runs the tool and appends the result to the history. The model sees it on the next turn.
In code, the loop is small:
const messages = [{ role: "user", content: task }];
while (true) {
const reply = await model.call({ messages, tools });
messages.push(reply.message);
if (reply.stopReason !== "tool_use") break;
for (const call of reply.toolCalls) {
const result = await runTool(call.name, call.input);
messages.push({ role: "tool", id: call.id, content: result });
}
}
The model decides whether to continue. Your code decides what runs and what comes back.
Before and after
Weak: the agent ignores what it just saw.
Thought: the test failed, probably a flaky test.
Action: run_tests
Observation: FAIL parseDate: expected 2026-03-01, got 2026-02-29
Thought: flaky again.
Action: run_tests
The observation names a specific wrong value, which a rerun cannot fix. A good turn uses it:
Thought: 2026 is not a leap year, so parseDate accepts an invalid date. Read the function.
Action: read_file(src/date.ts)
What goes wrong
- Observations ignored. The next action repeats the last one although the result contradicted the plan.
- Reasoning without evidence. The thought states a fact nobody observed, such as "the file exists", and the next action builds on it.
- Noisy observations. A tool returns 5,000 lines of logs, the key line is buried, and the model reasons from the wrong part.
When you review a run, read it as pairs: for each observation, ask whether the next action changed because of it.
Examples
Reading one turn
Thought: I need the failing endpoint before I edit anything.
Action: grep("POST /orders", src/)
Observation: src/routes/orders.ts:41
Thought: Open it around line 41.
Action: read_file(src/routes/orders.ts, 30, 60)
Each action follows from the previous observation: the grep result gave a path and a line, and the read uses both.
An observation that should have changed the plan
Action: install_package("left-pad")
Observation: error: network unreachable
Action: install_package("left-pad")
The error says the network is down, not that the package is wrong. The next action should be a different one: check connectivity, use a vendored copy, or report the blocker.
Key points
- Each loop turn is reason, then act (a tool call), then observe (the tool result appended to history).
- The model only proposes a tool call; your code executes it and returns the result.
- The observation is the agent's only feedback, so an agent that ignores it is guessing.
- Native tool use and extended thinking run the same cycle without hand-written ReAct prompts.
- Debug a run by pairing each observation with the next action and asking what changed.
Common mistakes
- Treating the thought text as proof that the agent checked something.
- Returning huge raw tool output as the observation instead of the relevant part.
- Letting the model run tools itself in your design, instead of your code executing and validating every call.
- Judging a run by its final answer only, without reading the observations that led to it.
Check yourself · 2 of 3
What is an observation in a reason-act-observe loop?
Check yourself · 3 of 3
A run log shows: Observation: FAIL, expected 2026-03-01, got 2026-02-29. The next action is run_tests again. What is the best diagnosis?
Practice items, not counted towards your mastery.
Start here
- ReAct: Synergizing Reasoning and Acting in Language Models (opens in a new tab)PaperFree
The paper that named the pattern of interleaving reasoning steps with actions and observations.
- Building effective agents (Anthropic) (opens in a new tab)ArticleFree
Describes agents as models using tools in a loop, and why to add stopping conditions and checkpoints.
- LLM Powered Autonomous Agents (Lilian Weng) (opens in a new tab)ArticleFree
A long survey of planning, memory and tool use, including ReAct-style loops and their failure modes.
More for this topic
- Tool use overview (Claude docs) (opens in a new tab)DocsFree
How a tool-calling loop works at the API level: tool_use blocks, tool_result blocks and stop reasons.