DevInterviewMasterStart free →
Agentic AI PatternsFree to read

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

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

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?

ScenarioRecommendationWhy
The task needs live data the model can't know✅ Use ReActIt fetches real results instead of hallucinating.
You can't predict the steps in advance✅ Use ReActIt decides one step at a time as it learns more.
A fixed, known sequence of steps every time❌ Use a simple script/chainNo need to re-decide each step; a chain is cheaper.
Pure text rewrite with no tools needed❌ Plain LLM callThere is nothing to 'act' on.

Beginner ReAct mistakes

MistakeConsequenceFix
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

Key takeaways

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.

Browse all Agentic AI Patterns topics →

Practice this on DevInterviewMaster

Read the full ReAct Pattern (Reason + Act) breakdown with interactive demos, quizzes, and Hinglish notes.

Open the interactive topic →

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.