Skip to content
AI360XpertBeta

ReAct Pattern

ReAct makes the model think out loud, use one tool, and read the result before thinking again. That loop turns guessing from memory into checking the world.

ReAct answers a Seattle weather question in one loop: a Thought calls a search, the tool returns 65 degrees and raining, and the next Thought turns that into a raincoat answer.
ReAct answers a Seattle weather question in one loop: a Thought calls a search, the tool returns 65 degrees and raining, and the next Thought turns that into a raincoat answer.

Why Does This Exist?

Ask about today's weather in Seattle and a bare model still answers. It has to. Everything it knows stopped changing when training ended, so it reaches into memory, finds something shaped like weather, and says it with a straight face. You've seen this confident guess. It's fluent, specific, and unchecked.

Handing the same model a search box without discipline fails the other way. It fires queries, skims nothing, and stitches scraps into an answer. Acting without thinking is guessing with extra steps, and the extra steps cost you tokens.

ReAct is the middle that holds. The model writes a Thought, takes one Action through a tool, reads the Observation back, and only then thinks again. That cycle repeats until the model has enough to answer. A question that needs a live fact gets a checked answer instead of a memorized one.

One grounding idea first, briefly. A model call keeps nothing by itself. Each call sees only the tokens handed to it right now, so plain code outside the model must carry the transcript forward and run each tool. That code is the harness, and the call itself lives in tool use and function calling. This page covers the loop the harness runs: the three lines, who writes each one, and where it stops. The production stops live in agent harness design, and the retrieval version lives in agentic RAG.

Think of It Like This

Fixing a leak with trips to the hardware store

Water is pooling under your sink. You look, decide the washer failed, drive to the store, buy one, and fit it. Still dripping. So you think again with new evidence, drive back, and replace the whole valve. No trip was planned upfront. Each one depends on what the last one taught you.

The look is the Thought. The drive and purchase is the Action. The drip test when you get home is the Observation. Three lines, same order, every round.

Where it stops: your drip test never lies and the clerk hands over what you asked for. Model tools are less honest. A search can return junk, a call can use the wrong argument, and the model can misread both. The loop only helps if the harness checks each call and writes each result down faithfully.

How It Actually Works

Call StS_t everything the model sees at step tt. In plain words, that is the question plus every Thought, Action, and Observation kept so far. Call TtT_t the Thought written at that step, in plain words the model's plan in words. Call AtA_t the Action, in plain words one tool name plus its input. Call OtO_t the Observation, in plain words the tool's result as text. Call NN the step cap, in plain words the harness's hard limit on passes.

Each pass does the same small job. The harness hands StS_t to the model and reads back TtT_t plus either AtA_t or a final answer. When an action arrives, only the harness runs the tool, turns the result into OtO_t, and builds St+1S_{t+1} by appending TtT_t, AtA_t, and OtO_t to StS_t. When a final answer arrives, the harness stops and returns it. If passes run out against NN, the harness ends the run with a fixed message instead of asking the model whether it feels done. The model writes. The harness acts. That split is the whole safety story, because nothing the model typed touches the world until code checks it.

Who writes which line

Two lines belong to the model and one never does. TtT_t and AtA_t come from the model, so they can be vague, wrong, or badly formatted. OtO_t comes from the tool through the harness, so it is the only grounded line in the loop. That gives the strictest rule in the pattern: stop the model's text at the word Observation and let the harness append the real OtO_t. A model allowed to write its own Observations invents tool results in the tool's voice, and nothing downstream can tell.

Worked example: rain in Seattle

Take the question "What should I wear in Seattle today?" Fix a dress rule so the answer is checkable: rain means a raincoat, and anything below 70 degrees means a layer. Here 70−65=570 - 65 = 5, so 65 sits 5 degrees under the layer line.

Pass 1 starts with S1S_1 holding the question. The model writes T1T_1: "I need live weather, not memory." It writes A1A_1: a search with the input "Seattle weather". The harness runs the search and appends O1O_1: "65 degrees, raining." Count it: one Thought, one Action, one Observation.

Pass 2 starts with S2S_2 holding all four lines. The model writes T2T_2: "Rain, so raincoat. 65 is below 70, so a layer too." No new tool is needed, so it writes the final answer: "Raincoat and a layer. It is 65 degrees and raining." Call TT the total pass count. Here T=2T = 2 passes with 1 tool call, the same run the diagram draws.

Every pass costs latency, tokens, and one more chance for the model to wander, and you pay it for grounding: each claim in the answer traces to an OtO_t the harness wrote down. Don't pay it blindly. A single price check or one database read with no follow-up wants a plain tool call, not a loop, because no later step needs an earlier result. The loop assumes tools answer quickly with short parseable text. It fails when they return slowly, dump pages of markup, or act in the world before failing, like placing a hold before the booking call errors.

Code

This snippet counts the lines of the Seattle run and checks the 5-degree gap. No API calls, no keys. Run it as is.

transcript: list[str] = [    "Thought: I need Seattle weather.",    "Action: search('Seattle weather')",    "Observation: 65 degrees, raining.",    "Thought: Rain means raincoat; 65 is 5 below 70, so add a layer.",]
actions: int = sum(1 for line in transcript if line.startswith("Action:"))print(actions)  # -> 1print(len(transcript))  # -> 4print(70 - 65)  # -> 5

Four lines, one action, and the 5-degree gap the second Thought cites. Count your own runs the same way: lines appended per pass, actions executed, and every number in the answer recomputed outside the model.

Watch Out For

Letting the model write its own Observation

Symptom: the final answer quotes a temperature no tool ever returned, and the transcript shows an Observation written in the model's own generation, in the same breath as its Thought. The cause is a missing stop: without one the model keeps writing past the Action line and roleplays the tool, inventing results in the tool's voice.

Fix: stop generation at the word Observation and append the tool's text server-side. Log who wrote each line so the audit is trivial. Never accept an Observation the harness did not write.

Parsing free text with a hopeful regex

Symptom: the model writes Action: [search] (Seattle) or renames the tool mid-run, your pattern finds nothing, and the loop burns passes appending apologies until it hits the step cap or the context limit. You learn about it from the bill.

Fix: constrain the output shape with a strict schema or function calling, validate every call before executing, truncate tool outputs, and cap passes with a small NN. The full gate pattern lives in agent harness design.

The Quick Version

  • ReAct is a loop of Thought, Action, and Observation: the model writes a plan, names one tool call, and reads the tool's result before thinking again.
  • The model never runs code and never writes Observations. The harness runs each tool, appends each result, and ends stuck runs at a step cap.
  • Each Thought sees the full transcript, so a failed search becomes a revised plan instead of a hallucinated answer.
  • The Seattle run takes 2 passes and 1 tool call: a search returns 65 degrees and raining, and 5 degrees under a 70-degree line means a raincoat plus a layer.
  • A single lookup with no follow-up wants a plain tool call, not the loop. Later steps must need earlier results for the passes to earn their cost.