Agents & loops

ReAct (Reason + Act)

ReAct (Reason + Act) is a prompting pattern for AI agents in which the model alternates between a written thought, an action such as a search or tool call, and the observation that action returns, repeating until it can answer. Grounding each reasoning step in real tool results reduces hallucinated facts compared with reasoning alone.

Best for
Tool-using agents, research and multi-hop questions
Difficulty
Intermediate
Updated

What is ReAct (Reason + Act)?

Chain-of-thought lets a model reason, but only from what it already “knows”. Tool use lets it fetch facts, but without a plan it flails. ReAct joins them: the thought decides what to look up next, the observation corrects the thought, and the loop continues until the evidence is enough.

Almost every modern agent framework is a descendant of this loop. With native function calling in today’s APIs you rarely write “Action:” lines by hand any more — the model emits a structured tool call and your code inserts the result — but the design decisions are the same: which tools, how they are described, how many steps, and what happens when a tool returns nothing.

When to use it — and when not to

Use it when

  • Questions that need facts the model does not have or cannot be trusted to remember: current prices, documentation, your own database.
  • Multi-hop questions where the answer to step one decides what to search in step two.
  • Agents that operate tools: a CRM, a file system, a calculator, an API.
  • When you need a trace of what was looked up so a human can audit the answer.

Skip it when

  • Questions answerable from the prompt alone — the loop just adds latency.
  • When you cannot give the model real tools. Without real observations, a “ReAct” prompt makes the model invent its own results.
  • High-stakes actions (sending, paying, deleting) without a human approval step.

Copyable template

ReAct system prompt
You are solving: [TASK]

You can use these tools:
- search(query): web search; returns the top results with snippets
- [TOOL NAME]([ARGUMENTS]): [WHAT IT RETURNS]

Work in this loop, one step at a time:
Thought: what you know so far and what you need next
Action: exactly one tool call, e.g. search("...")
Observation: (the tool result is inserted here — never write an observation yourself)

Repeat Thought / Action / Observation until the observations are enough to answer. Then write:
Final Answer: [the answer], naming which observation supports each claim.

Rules:
- At most [N] actions.
- If two actions in a row return nothing useful, change strategy instead of repeating yourself.
- If the evidence is not enough, say what is missing rather than guessing.

If you run this as plain text rather than with native tool calling, set a stop sequence on “Observation:” so the model hands control back to your code instead of imagining the result.

Replace everything in [SQUARE BRACKETS] before you run it.

Worked example: A two-hop question

The answer needs two separate facts, and the second search depends on the first.

Prompt
Task: Which company was founded first — the one that makes Pixel phones or the one that makes Kindle e-readers?
(Tools: search)
Illustrative outputWritten to show the pattern, not a recorded model run
Thought: I need the maker of each product, then each company's founding date.
Action: search("Pixel phone manufacturer")
Observation: Pixel is a line of smartphones developed by Google...
Thought: Pixel = Google. Now Kindle.
Action: search("Kindle e-reader manufacturer")
Observation: Kindle is a series of e-readers designed and marketed by Amazon...
Thought: Now the founding dates.
Action: search("Google founded date Amazon founded date")
Observation: Google was founded on September 4, 1998... Amazon was founded on July 5, 1994...
Final Answer: Amazon (maker of Kindle) was founded first, in July 1994 — about four years before Google (maker of Pixel), founded in September 1998. Sources: observations 1–3.

Why it works: Each thought is short and decides the next action; every claim in the final answer points back to an observation, so a reviewer can check it.

Common mistakes

  1. The model writes its own observations. In a plain-text loop the model will happily continue past “Observation:” and invent results. Use native tool calling or a stop sequence.
  2. No step limit. Agents can loop forever on an unanswerable question. Cap actions and require a “not enough evidence” answer.
  3. Vague tool descriptions. The model chooses tools from their descriptions. Say exactly what each returns, its limits and when to use it.
  4. Too many tools. Twenty overlapping tools lead to wrong choices. Offer the few the task needs.
  5. Thoughts that ramble. Long thoughts burn tokens and drift. Ask for one or two sentences per thought.

Origin & sources

Introduced by Shunyu Yao and colleagues (Princeton and Google) in 2022 and published at ICLR 2023. They interleaved reasoning traces with actions on question answering (HotpotQA), fact verification (FEVER) and interactive tasks (ALFWorld, WebShop), and reported that ReAct beat imitation- and reinforcement-learning baselines on the two interactive benchmarks while producing more interpretable, fact-grounded traces.

Try it on The Prompt Index

Frequently asked questions

What does ReAct stand for in AI?

Reason + Act. The model alternates between reasoning about what it needs and acting with a tool, then reads the result before reasoning again.

Is ReAct the same as function calling?

Not exactly. Function calling is the API mechanism that lets a model request a tool. ReAct is the reasoning pattern that decides which tool to call, reads the result and decides what to do next. Most agents today implement ReAct on top of function calling.

How is ReAct different from chain-of-thought?

Chain-of-thought reasons only from what the model already knows. ReAct adds actions, so each reasoning step can be checked against real search results or tool outputs.

How many steps should a ReAct agent be allowed?

Set a limit that fits the task, often five to fifteen actions, and tell the agent to stop and report what is missing when it reaches the limit.