The Agentic Loop and the ReAct Pattern
Table of contents
- Key takeaways
- What is the reason-act-observe loop?
- The ReAct pattern explained
- A step-by-step example
- ReAct versus a single model call
- When does the loop stop?
- Frequently asked questions
- What does ReAct mean?
- How does ReAct differ from chain-of-thought?
- Do I need a framework to use ReAct?
- Conclusion
- Sources
The ReAct pattern (Reason + Act) organizes an agent as a repeating three-step loop: reason about what to do, take an action with a tool, and observe the result. Introduced by Yao and colleagues in 2022, it interleaves reasoning and acting so the model can plan, consult external sources, and fix its own mistakes as it goes.
The agentic loop is the engine that turns a language model into an agent: instead of answering in one shot, it thinks, acts and observes, and repeats that cycle until it is done. The ReAct pattern is the best-known way to write that loop, and understanding it is the first step toward building reliable agents. This guide covers how it works, a step-by-step example, and when to prefer it over a single model call. The same explanation is available in Spanish.
Key takeaways
- The ReAct pattern (Reason + Act) structures the agent as a three-step loop: reason, act and observe.
- Shunyu Yao and colleagues introduced it in the 2022 paper arXiv 2210.03629[1], which first joined explicit reasoning with tool use.
- On the ALFWorld benchmark, ReAct improved the success rate by 34% absolute over prior methods; on WebShop, by 10%.
- Each turn of the loop produces a thought, an action (a tool call) and an observation with its result.
- Compared with a single model call, ReAct can pull in fresh data and correct course, at the cost of more latency and more tokens.
What is the reason-act-observe loop?
A language model on its own only knows how to generate text from what sits in its context. It cannot query a database, check a product’s price or read a file. The agentic loop breaks that limit: it wraps the model in a program that lets it take actions on the world and returns the results so it can keep reasoning.
The cycle has three repeating steps:
- Reason (Thought). The model writes what it wants to do next and why.
- Act (Action). It picks a tool and its arguments; the program runs it.
- Observe (Observation). The tool’s result is added to the context.
With the new observation, the model reasons again, and so on. Anthropic sums it up precisely in its agents guide: agents are «just LLMs using tools based on environmental feedback in a loop». That feedback is what tells an agent apart from a workflow with fixed steps, as we explain in what is an AI agent.
The ReAct pattern explained
ReAct (from Reasoning and Acting) is the recipe that popularized this loop. Its core idea is to interleave thoughts and actions in the same stream of text rather than separating them. The model does not only decide which tool to call: first it writes a natural-language thought that justifies the choice and helps it keep track of what it already knows.
The authors put it this way in the paper’s abstract: «reasoning traces help the model induce, track, and update action plans as well as handle exceptions, while actions allow it to interface with external sources, such as knowledge bases or environments, to gather additional information». That combination is what makes the pattern robust: reasoning guides the action and the action feeds the reasoning.
In practice, ReAct is implemented in two ways. The original used a prompt with examples that taught the model to write the Thought:, Action: and Observation: labels. Today, with models that support native function calling, the thought lives in the text and the action is a structured tool call that is more reliable to parse. Frameworks such as LangGraph, which reached its stable 1.0 release in October 2025, ship this loop ready-made; you can see it applied in agent flows with LangGraph.
A step-by-step example
Suppose an agent has a single tool, search(query), that returns a fact from an encyclopedia. We ask it: "What is the capital of the country where Miguel de Cervantes was born?". It is a two-hop question: first find out where he was born, then the capital of that country. Here is the loop’s trace:
Question: What is the capital of the country where Miguel de Cervantes was born?
Thought 1: I need to know which country Cervantes was born in.
Action 1: search("birthplace of Miguel de Cervantes")
Observation 1: Alcala de Henares, Spain (1547).
Thought 2: He was born in Spain, so I need the capital of Spain.
Action 2: search("capital of Spain")
Observation 2: Madrid.
Thought 3: I now have both facts. I can answer.
Action 3: answer("Madrid")
Notice three things. The agent breaks the question down without being asked; each observation changes what it decides to do next; and the loop ends when the model decides it can answer, not after a fixed number of steps. In pseudocode, the engine that runs that trace fits in a few lines:
def react_agent(question, tools, model):
context = [question]
for step in range(10): # safety limit
output = model.generate(context) # produces thought + action
if output.is_final_answer():
return output.answer
result = tools.run(output.action)
context.append(output) # the thought and the action
context.append(result) # the observation
return "no answer within the step limit"
A real agent would use the model’s function calling so that output.action is a structure rather than loose text; the skeleton of the loop, however, is exactly this.
ReAct versus a single model call
The alternative to ReAct is to ask the model for the answer all at once, perhaps with chain-of-thought reasoning. It works for questions that fit within what the model already knows, but it fails when a fact is needed that is not in its weights or that has changed since training. There the model tends to make things up: it hallucinates a plausible but false answer.
The ReAct paper’s contribution was to measure that difference. On the HotpotQA question-answering and Fever fact-verification tasks, letting the model consult a knowledge base at each step reduced hallucinations compared with reasoning alone. And on interactive tasks, where you must act on an environment, the advantage was large: 34% absolute on ALFWorld and 10% on WebShop. The lesson is that access to tools, not a bigger model, is what solves many tasks.
The cost is real. Each turn of the loop is a model call, so an agent that takes five steps spends five times more tokens and is slower than a direct answer. That is why you should choose the pattern by the task, a topic we expand in plan-and-execute versus ReAct.
When does the loop stop?
An unchecked loop is dangerous: a confused agent can repeat actions forever and blow up the bill. There are three common ways to stop it:
- Final answer. The model emits a special "answer" action and the program returns that text to the user. This is the normal exit.
- Step limit. A maximum number of iterations (say, ten) prevents infinite loops even when the model fails to finish.
- Human intervention. For sensitive tasks, the loop pauses to ask for confirmation before an action with consequences, something we cover alongside the reflection pattern, where the agent reviews its own work.
Designing this stopping condition well matters as much as the reasoning itself: it is the difference between a useful agent and one that gets stuck.
Frequently asked questions
What does ReAct mean?
ReAct combines the words Reasoning and Acting. It names a pattern in which the agent alternates natural-language thoughts with actions on tools, all in the same stream of text, so that reasoning and acting reinforce each other on every turn of the loop.
How does ReAct differ from chain-of-thought?
Chain-of-thought makes the model think out loud before answering, but without leaving its own knowledge. ReAct adds the acting step: between one thought and the next the agent consults external sources, so it can work with fresh data and check facts instead of inventing them.
Do I need a framework to use ReAct?
It is not required. The loop fits in a few lines of code, as in this guide’s example. A framework such as LangGraph or your provider’s agents SDK saves you from managing state, retries and parsing tool calls, but the pattern is simple enough to write by hand in order to understand it.
Conclusion
The ReAct pattern is the foundation almost every current agent rests on: a loop of reasoning, acting and observing that repeats until the task is solved. Its strength is interleaving thought with tool use, which lets the model plan, consult real data and correct itself. Now that you know the loop, the next step is to see how an agent breaks tasks down and plans longer jobs.
Sources: [1] ReAct, Synergizing Reasoning and Acting in Language Models (Yao et al., 2022)[1], [2] Building effective agents (Anthropic, 2024)[2], [3] ReAct agents in LangGraph (LangChain documentation)[3], [4] react-agent template (LangChain repository)[4].