What is a ReAct agent?
Definition
A ReAct agent is an LLM agent that alternates reasoning and acting: it writes a thought about the task, calls a tool, reads the tool's result as an observation, and repeats until it can answer. The pattern, short for Reason + Act, comes from a 2022 paper by Yao et al. It is unrelated to React.js.
How does a ReAct agent work?
ReAct stands for Reason + Act. The pattern comes from the paper ReAct: Synergizing Reasoning and Acting in Language Models by Yao et al. (first posted October 2022, published at ICLR 2023). It is an older source, but it is still the primary one. The name has nothing to do with React.js.
The loop has four moves:
- Question. The task goes into the prompt, along with a list of tools and a few worked examples (the paper used 6 for HotpotQA and 3 for Fever).
- Thought. The model writes a short plan in plain text: what it knows, what it still needs, which tool to try.
- Action. The model names a tool and its input. Your code parses that line and runs the tool.
- Observation. The tool result is appended to the transcript, and the model writes its next thought.
The cycle repeats until the model emits a final answer. In the paper's Wikipedia setup the agent had three actions: search[entity] (returns the first 5 sentences of the matching page), lookup[string] (the next sentence containing the string, like Ctrl+F) and finish[answer]. The authors list what the thoughts did in practice: break the goal into steps, pull the useful part out of an observation, track progress, and change plans when a search came back empty.
What did the ReAct paper actually measure?
The headline results come from PaLM-540B with few-shot prompts. On two interactive benchmarks, ReAct beat imitation and reinforcement learning methods by 34 points (ALFWorld) and 10 points (WebShop) of absolute success rate, with only one or two in-context examples (abstract).
The question-answering results are more mixed, and most explainers skip them. Table 1 of the paper:
| Method (PaLM-540B, prompting) | HotpotQA exact match | Fever accuracy |
|---|---|---|
| Standard prompt | 28.7 | 57.1 |
| Chain-of-thought (CoT) | 29.4 | 56.3 |
| CoT with self-consistency (CoT-SC) | 33.4 | 60.4 |
| Act only (no thoughts) | 25.7 | 58.9 |
| ReAct | 27.4 | 60.9 |
| CoT-SC, then ReAct as fallback | 34.2 | 64.6 |
| ReAct, then CoT-SC as fallback | 35.1 | 62.0 |
ReAct alone trailed plain chain-of-thought on HotpotQA (27.4 vs 29.4) and won on Fever. The best scores came from combining it with CoT-SC, switching method when one failed. The authors capped ReAct at 7 steps on HotpotQA and 5 on Fever before falling back, because more steps did not improve its results.
The error analysis explains why. The authors hand-labeled 50 trajectories per group. Hallucination caused 56% of chain-of-thought failures and 0% of ReAct failures, because ReAct grounds its facts in tool results. But 47% of ReAct failures were reasoning errors, including a loop where the model repeats earlier thoughts and actions. Another 23% came from searches that returned nothing useful. Those are small samples on a 2022 model, so read them as failure modes to test for, not as rates you will see.
How is a ReAct agent different from chain-of-thought and tool calling?
| Approach | Reasons in text | Calls tools | Grounded in outside data | How actions are passed |
|---|---|---|---|---|
| Chain-of-thought | Yes | No | No | None |
| Act-only agent | No | Yes | Yes | Text actions |
| ReAct agent | Yes | Yes | Yes | Text lines parsed by your code |
| Native tool calling | Optional | Yes | Yes | Structured tool calls from the API |
Text-based ReAct relies on parsing. The classic LangChain create_react_agent uses a Thought, Action, Action Input, Observation prompt and adds Observation: as a stop token by default to avoid hallucinated tool output (LangChain reference).
Model APIs now return tool requests as data instead. With Claude tool use, the response carries stop_reason: "tool_use" and one or more tool_use blocks; your code runs the operation and sends back a tool_result. The reason, act, observe cycle is the same. Only the transport changed, from parsed text to structured calls.
Example: a minimal ReAct loop in TypeScript
This loop runs without an API key. A stub model replays four scripted steps, and the tools answer from a two-line knowledge base built from the paper's Table 1. Replace model with a real LLM call that returns the same text format.
// Minimal ReAct loop: the model writes Thought + Action, the code runs the tool
// and appends an Observation, until the model calls finish[...] or hits MAX_STEPS.
type Tool = (input: string) => string;
const docs: Record<string, string> = {
"react fever": "ReAct (PaLM-540B) scored 60.9 accuracy on Fever.",
"act fever": "Act-only (PaLM-540B) scored 58.9 accuracy on Fever.",
};
const tools: Record<string, Tool> = {
search: (q) => docs[q.toLowerCase()] ?? "No results.",
subtract: (q) => {
const [a, b] = q.split(",").map(Number);
return (a - b).toFixed(1);
},
};
// Stub model: replays a fixed script so the loop runs without an API key.
// Swap in a real LLM call that returns the same "Thought/Action" text.
const script = [
"Thought: I need the ReAct score first.\nAction: search[ReAct Fever]",
"Thought: ReAct has 60.9. Now the Act-only score.\nAction: search[Act Fever]",
"Thought: Act-only has 58.9. Subtract.\nAction: subtract[60.9,58.9]",
"Thought: The gap is 2.0 points.\nAction: finish[2.0 points]",
];
const model = (transcript: string): string =>
script[(transcript.match(/Observation:/g) ?? []).length];
const MAX_STEPS = 6; // ReAct agents can repeat themselves; always cap the loop.
function runAgent(question: string): string {
let transcript = `Question: ${question}\n`;
for (let step = 1; step <= MAX_STEPS; step++) {
const output = model(transcript);
transcript += output + "\n";
const action = output.match(/Action: (\w+)\[(.*)\]/);
if (!action) return "stopped: no action parsed";
const [, name, input] = action;
if (name === "finish") {
console.log(transcript);
return input;
}
const tool = tools[name];
const observation = tool ? tool(input) : `Unknown tool: ${name}`;
transcript += `Observation: ${observation}\n`;
}
return "stopped: step limit reached";
}
console.log("Answer:", runAgent("How far ahead of Act-only was ReAct on Fever?"));
Run it with bun run react.ts (Bun 1.2) or node --experimental-strip-types react.ts (Node 22.9). Output:
Question: How far ahead of Act-only was ReAct on Fever?
Thought: I need the ReAct score first.
Action: search[ReAct Fever]
Observation: ReAct (PaLM-540B) scored 60.9 accuracy on Fever.
Thought: ReAct has 60.9. Now the Act-only score.
Action: search[Act Fever]
Observation: Act-only (PaLM-540B) scored 58.9 accuracy on Fever.
Thought: Act-only has 58.9. Subtract.
Action: subtract[60.9,58.9]
Observation: 2.0
Thought: The gap is 2.0 points.
Action: finish[2.0 points]
Answer: 2.0 points
Three details matter more than the rest. Unknown tools return an observation instead of throwing, so the model can correct itself. A missing action line stops the run. And MAX_STEPS ends the loop the paper warned about.
When should you use a ReAct agent?
Use it when the path to the answer is unknown up front: multi-hop questions, lookups that depend on the previous result, or tasks where a reviewer must see why the agent did what it did. The written thoughts make the trace readable, and the paper shows people correcting an agent mid-run by editing a thought.
Skip it when the steps are fixed. A known sequence (fetch record, validate, write) is cheaper and easier to test as plain code or a fixed agentic workflow. Also skip it when your tools return weak results: the paper's 23% search-error share is a reminder that the loop is only as good as what it observes. For retrieval-heavy agents, see agentic RAG.
What should you check before running one in production?
- A step budget. LangChain's
create_agentstops a tool-calling loop only at its recursion limit, set to 9,999 steps by default, and its docs advise a lowerrecursion_limitor a model-call limit for production (LangChain agents docs). - Repetition detection. Flag runs where the same action and input repeat. The paper names this loop as a ReAct-specific failure.
- Structured calls over text parsing. The LangChain reference calls its classic ReAct agent older and not well-suited for production, and points to
create_agentinstead. - Tool errors as observations. Return failures as text the model can read, and log them.
- Tests on traces, not only answers. An agent can reach the right answer by a wrong path. Our guide to AI agent testing covers how to score both.
SDCLabs builds AI agents with senior engineers in control: agents draft code and tests, engineers review what ships, and automated tests verify every change.
Sources
- ReAct: Synergizing Reasoning and Acting in Language Models (arXiv 2210.03629, v3, ICLR 2023), Yao et al., Princeton University and Google Research, 2023-03
- create_react_agent, langchain_classic API reference, LangChain, 2026-11
- Agents (create_agent, fault tolerance and recursion limit), LangChain, 2026-11-17
- Tool use with Claude: overview, Anthropic, 2026-11
Frequently asked questions
Is a ReAct agent related to React.js?
No. ReAct is short for Reason + Act, a prompting pattern for language model agents from a 2022 research paper. React.js is a JavaScript UI library, and the two only share a spelling.
Is ReAct still used in 2026?
The loop is, though the name appears less often. LangChain still ships its classic ReAct agent, calls it older and not well-suited for production, and recommends its create_agent function instead. Claude's tool use API runs the same reason, act, observe cycle with structured tool calls.
Do you need a very large model for a ReAct agent?
Not necessarily. In the original paper, a PaLM-8B model fine-tuned on 3,000 ReAct trajectories beat every prompting method on the 62B model for HotpotQA. With prompting alone, ReAct ranked last of four methods on the 8B and 62B models.
How do you write a ReAct agent?
Give the model a tool list and a prompt format with Thought, Action and Observation lines, then run a loop: call the model, parse the action, run the tool, append the result, and stop on a final answer or a step cap. The TypeScript example on this page does exactly that in about 50 lines.
Services
Read next
Related terms
Mykhailo PoliarushFounder and CEOLeads SDCLabs, an AI development company founded in Krakow in 2011.LinkedInGitHub