Skip to main content

Command Palette

Search for a command to run...

ReAct Pattern

Published
4 min readView as Markdown

What Is a ReAct Agent?

A ReAct agent is an AI system that combines reasoning (thinking through problems step-by-step) with acting (using tools or taking actions).
The term ReAct stands for Reasoning + Acting.

This approach was first introduced by Yao et al. (2023) in the paper “ReAct: Synergizing Reasoning and Acting in Language Models.”

In short:

  • The LLM (Large Language Model) serves as the “brain” of the agent.

  • The agent uses the LLM’s reasoning ability to decide what to do, and then acts by using tools (like a search engine, API, or calculator).

  • The process repeats — the agent thinks, acts, observes what happened, and thinks again — until it reaches a final answer.

This integration makes ReAct agents more powerful and flexible than older AI systems that separated thinking from doing.


How ReAct Agents Work

The ReAct framework mimics how humans solve problems:

  1. We think (“What’s the next step?”)

  2. We act (e.g., check something, calculate, or look it up)

  3. We observe the result

  4. We think again based on what we learned.

Example:

If you’re packing for a trip:

  • Thought: “What’s the weather like?”

  • Action: Check the forecast.

  • Observation: It’ll be cold.

  • Thought: “I need warm clothes.”

  • Action: Look in your closet.

  • Observation: Clothes are in storage.

  • Thought: “I’ll layer lighter clothes instead.”

ReAct agents do exactly this — but with prompt engineering guiding them.

Key Components

  • Thoughts (Reasoning): The LLM breaks the big problem into smaller parts using chain-of-thought (CoT) reasoning.

  • Actions: The model performs tasks using tools — like calling an API, querying a database, or searching the web.

  • Observations: The model reads results and decides what to do next.

The process repeats until the model finds a satisfactory answer or reaches a stopping condition (like a loop limit).


The ReAct Loop

The ReAct loop is the repeating cycle:

Diagram of a react path

Thought → Action → Observation → (repeat or end)

The agent keeps looping through this cycle until:

  • It’s confident in an answer, or

  • It hits a max loop limit (to save tokens, time, or cost).

This feedback loop lets the agent reason dynamically, adjusting to new data or unexpected results in real time.


ReAct Prompting

ReAct prompting is a special technique to teach an LLM to follow the “think–act–observe” cycle.
The prompt tells the model:

  • How to reason step by step (CoT reasoning)

  • What actions/tools it can use

  • How to make observations after each action

  • When to loop or stop

  • How to output the final answer

A simple ReAct prompt format looks like this:

Question: <user query>
Thought: <model reasoning>
Action: <chosen tool>
Action Input: <input for that tool>
Observation: <tool result>
... (repeats as needed)
Thought: I now know the final answer
Final Answer: <output>

Example tools (as in LangChain’s built-in ReAct module):

  • Wikipedia: to look up facts

  • DuckDuckGo Search: to check current events

  • Calculator: to handle math problems

This design lets the agent reason transparently while using external tools intelligently.


Benefits of ReAct Agents

QualityExplanation
VersatilityCan use many different tools/APIs with minimal setup.
AdaptabilityDynamically changes its strategy as conditions or information change.
ExplainabilityThe step-by-step reasoning is visible and easy to debug.
AccuracyReduces “hallucinations” because it checks facts using real-world data sources (like RAG systems).

ReAct’s mix of reasoning + tool use was a key milestone that led to more advanced AI agents, like Reflexion and modern reasoning models.


ReAct Agents vs. Function Calling

FeatureReAct AgentsFunction Calling
Core ideaThinks step by step, decides when/how to use tools dynamicallyUses structured JSON calls to pre-defined functions
FlexibilityVery high — adapts to complex or uncertain tasksMore rigid — good for predictable workflows
Speed/CostSlower, more tokens usedFaster, fewer tokens
TransparencyShows reasoning stepsTool use may be opaque
Best forComplex, dynamic problemsSimple, routine tasks

In short:

  • Function calling is efficient for fixed, well-defined APIs.

  • ReAct is better when the task requires adaptive reasoning or multiple uncertain steps.


Building ReAct Agents

You can build ReAct agents:

  • From scratch in Python or Javascript

  • Using frameworks like LangChain (LangGraph), LlamaIndex, or BeeAI, which provide ready-made ReAct modules.

These frameworks let developers easily plug in tools (APIs, search engines, calculators, etc.) and control the agent’s reasoning loop.


Summary

ReAct agents are AI systems that merge reasoning (thinking) with acting (tool use) in a feedback loop.
They:

  • Think → Act → Observe → Repeat

  • Use chain-of-thought reasoning and external tools

  • Are flexible, explainable, and accurate

  • Form the foundation of modern autonomous AI agents

In short:

A ReAct agent is an intelligent AI framework that doesn’t just think — it does, learns from results, and adapts in real time.