ReAct (reasoning + acting) framework
What Is ReAct?
Why This Architecture?
Pure chain-of-thought (CoT) can reason deeply but cannot interact with external knowledge or tools—it's trapped in its training data. Pure action agents can use tools but often hallucinate or make britle decisions without explicit reasoning. ReAct gets both:
- Grounding: Observations from real tools prevent hallucination
- Transparency: Reasoning traces make decisions interpretable
- Error recovery: The agent can recognize mistakes in observations and change course
- Dynamic planning: Each thought can revise the plan based on what was just learned
The ReAct Loop: From First Principles
Let's derive how ReAct operates step-by-step.
Starting point: You have a question and a set of available tools (e.g., search, calculator, database).
Goal: Generate answer by alternating reasoning and acting.
Step 1: Initial Reasoning
The LM receives the question and generates a thought :
This thought analyzes what information is needed. Example: "To find the population of Paris in 2023, I need to search for current demographic data."
Why this step? Without reasoning first, the agent might search for the wrong thing or not know why it's searching.
Step 2: Action Selection
Based on , the LM choses an action from the tool set:
Example: Action: Search["Paris population 2023"]
Why this step? Reasoning without action is useless for questions requiring external knowledge. The action must match the thought's intent.
Step 3: Environment Observation
The environment (tool executor) runs and returns observation :
Example: Observation: Paris had a population of approximately 2.1 million in 2023 within city limits.
Why this step? The observation provides grounding—real data that the LLM's parametric knowledge might lack or get wrong.
Step 4: Reasoning with New Information
The LLM now generates conditioned on everything so far:
Example: "The city limits population is 2.1M, but the question might be asking about the metropolitan area. I should search for that."
Why this step? The agent uses the observation to refine its understanding. This is where error recovery happens—if was unexpected, can pivot.
Step 5: Iteration Until Done
Repeat steps 2-4, building a trajectory:
The loop terminates when the LLM generates:
Example: Action: Finish[The population of Paris is 2.1 million in the city and 12.4 million in the metro area as of 2023]
Mathematical Formulation
The probability of the entire trajectory given the question is:
Where:
- is the LM's reasoning distribution
- is the action selection distribution
- is deterministic (the environment's response)
Why this matters: This factorization shows that ReAct is a sequential decision process where each step depends on all prior steps. The LLM is doing multi-step inference, not just one-shot generation.
Concrete Example: Multi-Hop Question
Question: "What is the capital of the country where the Eiffel Tower is located?"
Trajectory:
Thought 1: I need to find which country the Eiffel Tower is in.
Action 1: Search["Eiffel Tower location"]
Observation 1: "The Eiffel Tower is in Paris, France."
Why this step? The agent identifies it lacks country information and uses search to ground its knowledge.
Thought 2: Now I know it's in France. I need to find France's capital.
Action 2: Search["capital of France"]
Observation 2: "Paris is the capital of France."
Why this step? The observation from Action 1 enables a dependent second query. This is multi-hop reasoning—each step builds on the last.
Thought 3: I have all information needed. Paris is both the city with the Eiffel Tower and France's capital.
Action 3: Finish["Paris"]
Why this step? The agent recognizes the task is complete and synthesizes the answer from accumulated observations.
Contrast with Pure CoT
A pure CoT approach would try to answer from memory:
Let me think step by step:
1. The Eiffel Tower is in Paris
2. Paris is in France (I think?)
3. The capital of France is Paris
Answer: Paris
Risk: If the LLM halucinates step 2 (e.g., says "Paris is in Belgium"), there's no correction mechanism. ReAct's observations enforce correctness.
Common Mistakes and How to Fix Them
When ReAct Fails
ReAct is not magic. It struggles with:
- Poor tool design: If tools return noisy or irrelevant observations, the agent can't recover. Garbage in, garbage out.
- Ambiguous questions: If the question is underspecified, the agent might not know what to search for. Reasoning traces expose this, but don't solve it.
- Long trajectories: Each thought-action-observation cycle uses tokens. Very long tasks (20+ steps) can exceed context limits or become expensive.
- Irreducible hallucination: If the LM misinterprets a correct observation (e.g., reads "2.1 million" as "21 million"), ReAct can't fix that—it's a model capability issue.
Connections to Other Concepts
- Chain-of-Thought (CoT): ReAct extends CoT by adding actions. CoT is "think then answer"; ReAct is "think, act, observe, think, act, ..."
- Tool Use in LLMs: ReAct is a structured framework for tool use, ensuring tools are called for good reasons (the thoughts).
- Agent Architectures: ReAct is a specific agent loop. Compare with Reflexion (self-reflection) and MRKL (modular reasoning).
- Self-Consistency: ReAct can be combined with self-consistency by sampling multiple trajectories and picking the most common answer.
- Retrieval-Augmented Generation (RAG): ReAct often uses search as a tool, making it a form of interactive RAG where the agent decides when to retrieve.
Recall Explain to a 12-Year-Old
Imagine you're solving a mystery. You don't just sit and think about the answer—you think "I need to check the library," then you go to the library, find a book, read it, and then think "Okay, now I know the villain was in Paris, so I need to search Paris records." You keep going back and forth between thinking and doing.
That's ReAct! A computer (AI) thinks about what it needs to know, does something to find out (like searching Google or doing math), looks at what it found, then thinks again. If it finds something surprising, it can change its plan. It's like having a smart assistant who explains their thinking and actually looks things up instead of guessing.
#flashcards/ai-ml
What are the three components of a ReAct loop? :: Thought (reasoning trace), Action (tool call), and Observation (environment feedback).
Why does ReAct interleave reasoning and acting instead of doing all reasoning first?
What is the key advantage of ReAct over pure Chain-of-Thought?
What is the key advantage of ReAct over pure action-only agents?
In the ReAct formula , what does represent?
What is a multi-hop question in ReAct context?
How does ReAct handle errors or unexpected observations?
When does a ReAct trajectory terminate?
Finish[answer], indicating it has sufficient information to answer the question.What is the "hallucination-then-act" problem that ReAct solves?
Why must each ReAct action be preceded by a thought?
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
ReAct framework ek bahut powerful idea hai AI agents ke liye. Socho agar tumhe koi sawaal solve karna hai jiska answer tumhe pata nahi, toh tum kya karoge? Pehle sochoge "mujhe kya information chahiye," phir actually jake Google pe search karoge ya calculator use karoge, jo milega usse dekhoge, phir wapas sochoge "acha ab next kya karna hai." Yahi ReAct ka concept hai—AI model bhi exactly yehi karta hai.
Traditional LMs sirf apne dimag (training data) pe depend karte the. Agar unhe 2023 ki Paris ki populationucho aur training 2021 mein ruki thi, toh wo guess karenge ya purana data denge. Lekin ReAct framework mein, AI sochta hai "mujhe latest data chahiye," phir actual search tool call karta hai, real result pata hai (observation), phir us result ko dekhke next decision leta hai.Isse hallucination (galat guess) bahut kam hoti hai kyunki har step pe real-world se feedback mil raha hai.
Ye approach multi-hop questions ke liye bhi perfect hai jahan ek answer dosre question ko unlock karta hai. For example, "Eiffel Tower jis country mein hai uski capital kya hai?"—pehle find karo country (France), phir uski capital (Paris). ReAct mein AI transparent tareke se har step explain karta hai: "Thought: mujhe country find karni hai. Action: Search karo. Observation: France mila. Thought: Ab France ki capital find karo."Isse debugging aur trust dono easy ho jate hain.
Iska real-world impact bada hai—customer support bots, research assistants, coding agents sab isse better ban sakte hain kyunki wo na sirf blindly act karte hain, na sirf hallucinate karte hain, balki think-act-learnrepeat ka cycle follow karte hain jaise ek intelligent human karta hai.