Özer Cem KELAHMETKELAHMET
Tools · Agentic AI

ReAct loop

ReAct interleaves reasoning, actions and observations so an AI agent can think, use a tool, read the result and adjust. Learn how the loop works and when to use it.

Overview

ReAct, short for Reasoning and Acting, is the most widely used pattern for building AI agents. The model alternates between thinking about what to do, taking an action such as calling a tool, and observing the result. It repeats this cycle until it can answer.

Picture someone cooking from a recipe in an unfamiliar kitchen. They read the next step, think "I need a pan", open a cupboard, see only pots, think "a pot will do for now", take one, taste the sauce, decide it needs salt, and so on. They do not plan every movement in advance, and they do not act blindly either. They keep switching between thinking and doing, and each observation changes the next decision. A ReAct agent works the same way.

What it is

A ReAct agent produces a sequence of steps, each made of three parts:

  • Thought: a short piece of reasoning about the current situation and what to do next.
  • Action: a tool call, such as a search, a database query or a calculation.
  • Observation: the result of the action, returned by the environment.

The sequence ends with a final answer. The full record of thoughts, actions and observations is called the trajectory.

Step Example
Thought "I need the 2025 revenue figure before I can compute growth."
Action search_reports(company="Acme", year=2025, metric="revenue")
Observation "Revenue 2025: 412 million."
Thought "Now I need 2024 to compare."
Action search_reports(company="Acme", year=2024, metric="revenue")
Observation "Revenue 2024: 380 million."
Answer "Revenue grew about 8.4 percent from 2024 to 2025."

Where it came from

The pattern was introduced in a 2022 research paper by Shunyu Yao and colleagues, "ReAct: Synergizing Reasoning and Acting in Language Models", later published at ICLR 2023. Two ideas existed before it. Chain-of-thought prompting showed that models answer better when they reason step by step, but the reasoning could drift into invented facts. Action-only agents could use tools, but without explicit reasoning they struggled to plan and recover from errors.

ReAct combined them. Reasoning helps choose actions and track progress; actions bring in real information that keeps reasoning honest. In the original experiments, interleaving the two reduced hallucination on question answering and fact checking and improved success on interactive tasks.

Early ReAct agents wrote thoughts and actions as plain text that code parsed. Modern implementations use native function calling for actions, and many models now reason internally before each tool call, but the loop structure is the same.

How it works

The loop

  1. The agent receives a goal and a list of tools.
  2. The model reasons about the next step.
  3. If it needs information or must act, it emits a tool call.
  4. The runtime executes the call and appends the observation to the context.
  5. The model reasons again with the new observation.
  6. The loop stops when the model gives a final answer or a limit is hit.

Stopping conditions

A ReAct loop needs explicit limits: a maximum number of steps, a time budget and a token or cost budget. Many systems also stop when the agent repeats the same call with the same arguments, which signals that it is stuck.

Context growth

Every observation adds text to the context. Long tasks can fill the context window. Common fixes are to truncate or summarise old observations, keep only key facts in a scratchpad, and return compact tool results.

Error recovery

Observations include errors. A good agent reads "no results for this date range" and widens the range, or reads a validation error and fixes the argument. Clear, specific error messages from tools make recovery much more reliable.

Key concepts and terms

Term Meaning
Thought Reasoning text about the current state and next step.
Action A tool call chosen by the model.
Observation The result returned after an action.
Trajectory The full sequence of thoughts, actions and observations.
Scratchpad A working area in context that holds intermediate results.
Step budget The maximum number of loop iterations.
Stop condition A rule that ends the loop.
Grounding Basing reasoning on real observations rather than memory.

A worked example

An IT support agent has three tools: check_service_status, search_runbooks and restart_service (which needs approval).

A user writes: "The reporting dashboard has been blank since this morning."

  1. Thought: "First check whether the reporting service is up." Action: check_service_status("reporting"). Observation: "reporting-api: healthy. reporting-worker: crashed at 06:12, error: disk full."
  2. Thought: "The worker crashed because of a full disk. Look for the runbook." Action: search_runbooks("reporting-worker disk full"). Observation: "Runbook 14: clear the temp export folder, then restart the worker."
  3. Thought: "Clearing the folder is not one of my tools. I should tell the user and offer the restart after cleanup." Answer: The agent explains the cause, links runbook 14 and offers to restart the worker once the folder is cleared.

The agent never guessed. Each step was grounded in an observation, and it stopped at the edge of its permissions.

Strengths and limitations

Strengths

  • Simple and general. One loop handles many kinds of tasks.
  • Grounded answers. Observations replace guesses with facts.
  • Adaptive. The agent changes course when results surprise it.
  • Transparent. Trajectories show why the agent did what it did, which helps debugging and audit.

Limitations

  • Greedy. It decides one step at a time and can wander on long tasks that need a plan.
  • Costly on long tasks. Each step is a model call, and context grows with every observation.
  • Sensitive to tool quality. Vague tools and unhelpful errors lead to poor decisions.
  • Loops and drift. Without limits it can repeat actions or lose sight of the goal.

How it compares with alternatives

Pattern Idea Best for
ReAct Think, act, observe, repeat Open-ended tasks with uncertain steps
Plan-and-execute Make a full plan, then run steps Long tasks with predictable structure
Reflection Review and critique output, then revise Quality-sensitive writing and code
Tree-of-thoughts Explore several reasoning branches Puzzles and problems with dead ends
Orchestrator-workers A lead agent delegates to workers Large tasks that split into parallel parts

In practice these are combined. A planner may create steps, each executed by a small ReAct loop, with reflection at the end.

Practical guidance and best practices

  1. Set hard limits. Cap steps, time and cost; detect repeated calls.
  2. Give few, clear tools. Each tool should have a precise description and good errors.
  3. Keep observations short. Return the fields the agent needs, not whole payloads.
  4. Summarise as you go. Compress old steps on long tasks to keep the context focused.
  5. Log trajectories. Store every step for debugging, evaluation and audit.
  6. Evaluate on real tasks. Measure success rate, steps per task and cost, not only final answer quality.
  7. Gate risky actions. Require approval for anything with side effects.

Common mistakes

  • No step limit. The agent burns budget in a loop.
  • Huge observations. A single tool result fills the context.
  • Silent tool failures. Empty results with no explanation mislead the agent.
  • Using ReAct for fixed workflows. A deterministic pipeline is cheaper and more reliable when the steps never change.

Frequently asked questions

What does ReAct stand for?

Reasoning and Acting. The agent alternates between reasoning about the task and acting through tools, reading each result before the next step.

Who introduced ReAct?

Shunyu Yao and colleagues introduced it in a 2022 paper, later published at ICLR 2023.

Do modern agents still use ReAct?

Yes. Most tool-using agents run a ReAct-style loop. The difference is that actions now use native function calling, and models often reason internally rather than in visible text.

How many steps should a ReAct agent take?

As few as the task needs. Start with a small cap, often five to fifteen steps, and raise it only if evaluation shows more steps improve results.

Is ReAct better than planning first?

Neither is always better. ReAct adapts well to surprises; plan-and-execute is more efficient when the structure is known. Many systems combine both.

Glossary

  • Chain of thought: step-by-step reasoning written before an answer.
  • Context window: the amount of text a model can read at once.
  • Function calling: structured tool requests produced by a model.
  • Hallucination: confident output that is not supported by facts.
  • Runbook: a documented procedure for handling an operational issue.
  • Tool: a callable capability available to an agent.

Summary

ReAct is the basic loop of agentic AI: think, act, observe, repeat. Reasoning chooses the next action, and actions bring back real information that keeps reasoning grounded. It is simple, general and transparent, but greedy and costly on long tasks. Hard limits, small tool sets, compact observations, logged trajectories and approval for risky actions make it dependable.

It belongs to Patterns in my stack, under Agentic AI. Others in the same group:

Type to search.
    ↑↓ navigate↵ open