ReAct Pattern (Reason + Act)
Think a little, do a little, look at what happened
Imagine you're cooking a new dish. You don't plan the whole meal perfectly in your head and then cook blindly. You think ("I should taste the sauce"), you act (you taste it), you observe ("too salty!"), and then you think again based on what you just learned. ReAct (short for Reason + Act ) is exactly this: the agent alternates between thinking and doing, using real results to guide its next thought.
Key points
- ReAct = Reason (a Thought) + Act (use a tool) repeated in a loop.
- After each Action it reads an Observation (the real result).
- It thinks ONE step at a time instead of planning everything upfront.
- Real tool results keep the agent grounded so it guesses less.
The one-line definition
ReAct is a pattern where the agent repeatedly produces a Thought (its reasoning out loud), takes an Action (calls a tool), and reads an Observation (the tool's result) — looping until it has enough to give a final answer.
Note: Thought → Action → Observation, on repeat, until done.
The ReAct loop (memorise this picture)
┌─────────────────────────────────────────────────┐ │ │ ▼ │ ┌──────────┐ ┌──────────┐ ┌─────────────────┐ │ │ THOUGHT │ ──► │ ACTION │ ──► │ OBSERVATION │──┘ │ "I need │ │ call a │ │ "search says │ │ the │ │ tool: │ │ it is 31°C" │ │ weather"│ │ search() │ │ (real result) │ └──────────┘ └──────────┘ └─────────────────┘ ▲ │ │ still need more info? │ └─────────────────────────────────────┘ │ enough info ▼ ✅ FINAL ANSWER
A worked example: "What's the weather in Mumbai and should I carry an umbrella?"
Thought 1: I don't know the weather. I should look it up. │ ▼ Action 1: search("weather in Mumbai today") │ ▼ Observation 1: "31°C, 80% chance of rain this afternoon." │ ▼ Thought 2: 80% rain is high. The answer is yes, carry one. │ I have everything I need now. ▼ ✅ Final Answer: "It's 31°C with an 80% chance of rain — yes, carry an umbrella!"
Notice: the agent did NOT guess the weather. It fetched a REAL result, then reasoned about it. That grounding is the whole point of ReAct.
The 3 moves of ReAct
- Thought (Reason) — The agent reasons out loud about what it knows and what it should do next. Example: "I still don't know the price, so I should search for it."
- Action (Act) — It picks one tool and the arguments to call it with. Example: search("iPhone 15 price India")
- Observation — The real result of the tool comes back and is fed into the next Thought. Example: "₹79,900 on the official store."
A tiny code example (read it like English)
Here is a bare-bones ReAct loop. See how each turn produces a Thought, then either an Action or a final answer, and how the Observation is appended back into the history?
goal = "Weather in Mumbai? Should I carry an umbrella?"
history = []
for step in range(10): # safety cap on the loop
reply = llm(goal, history) # 1. THOUGHT (reason)
history.append(reply.thought)
if reply.is_final_answer:
print(reply.answer) # done!
break
obs = run_tool(reply.tool, # 2. ACTION (act)
reply.args)
history.append(obs) # 3. OBSERVATION
▶ Try it: a ReAct loop (Thought → Action → Observation)
Add a new fact and a new step, then Run to watch the loop grow.
# A fake search tool so the loop actually runs.
FACTS = {
"capital of France": "Paris",
"population of Paris": "2.1 million",
}
def search(q):
return FACTS.get(q, "unknown")
steps = ["capital of France", "population of Paris"]
for q in steps:
print("Thought : I need the", q)
print("Action : search(", repr(q), ")")
print("Observation :", search(q))
print("-" * 30)
print("Final answer: Paris, about 2.1 million people")
When should you reach for ReAct?
| Scenario | Recommendation | Why |
|---|---|---|
| The task needs live data the model can't know | ✅ Use ReAct | It fetches real results instead of hallucinating. |
| You can't predict the steps in advance | ✅ Use ReAct | It decides one step at a time as it learns more. |
| A fixed, known sequence of steps every time | ❌ Use a simple script/chain | No need to re-decide each step; a chain is cheaper. |
| Pure text rewrite with no tools needed | ❌ Plain LLM call | There is nothing to 'act' on. |
Beginner ReAct mistakes
| Mistake | Consequence | Fix |
|---|---|---|
| Letting the agent answer without ever acting. | It hallucinates facts it should have looked up. | Make tools available and prompt it to look things up before concluding. |
| Throwing away the Observation. | The agent loops forever, re-asking the same thing. | Always feed the real Observation back into the next Thought (the history). |
| No max-step limit on the loop. | It can spin forever and burn money. | Cap the loop (e.g., 10 steps) and handle hitting the cap gracefully. |
Remember these 3 lines
- ReAct = Thought → Action → Observation, looped until done.
- Real Observations keep the agent grounded — it guesses far less.
- It decides ONE step at a time, unlike Planning which plans everything upfront.
Key takeaways
- ReAct interleaves a Thought (reasoning), an Action (tool call), and an Observation (result) in a loop.
- Feeding real tool Observations back into reasoning keeps the agent grounded and reduces hallucination.
- It chooses one step at a time, adapting as new information arrives.
- Always cap the loop and always feed Observations back into the history.
Frequently Asked Questions
What is ReAct Pattern?
Imagine you're cooking a new dish. You don't plan the whole meal perfectly in your head and then cook blindly.
How does ReAct Pattern work?
ReAct is a pattern where the agent repeatedly produces a Thought (its reasoning out loud), takes an Action (calls a tool), and reads an Observation (the tool's result) — looping until it has enough to give a final answer.
What are the key takeaways about ReAct Pattern?
ReAct interleaves a Thought (reasoning), an Action (tool call), and an Observation (result) in a loop. Feeding real tool Observations back into reasoning keeps the agent grounded and reduces hallucination. It chooses one step at a time, adapting as new information arrives. Always cap the loop and always feed Observations back into the history.
Related topics
Practice this on DevInterviewMaster
Read the full ReAct Pattern (Reason + Act) breakdown with interactive demos, quizzes, and Hinglish notes.
800+ system-design, LLD, coding, and design-pattern topics. Unlock everything with Pro (₹499, one-time) or Ultimate (₹999, one-time) — lifetime access, no subscription.