AI & Agents

What Is the ReAct Pattern?

How modern AI agents think out loud, take action, and learn from what they see.

Scroll to start

AI That Thinks Before It Acts

Imagine you're a detective solving a mystery. You don't just blurt out an answer. You think about what you already know, then go look for clues, then think again, then look for more clues. That back-and-forth is exactly how the ReAct pattern works.

ReAct is short for Reasoning + Acting. It's a way for AI to solve hard problems by thinking out loud, doing something based on that thinking, and then looking at the result before deciding what to do next.

Most older AI models just try to answer in one shot, like a student guessing on a test. ReAct AI is more like a student who works through the problem step by step, pulling out a calculator or looking up a fact whenever they need it.

Smarter Answers, Fewer Mistakes

Before ReAct, AI models were stuck with what they had memorized during training. Ask one a tricky question and it might "hallucinate" — confidently make something up. There was no way for the AI to check its own work.

ReAct changed that. By giving AI the ability to use tools mid-thought, the AI can now look things up, run code, do math, and read documents in real time. The result is answers that are far more accurate and trustworthy.

This pattern is the backbone of modern AI agents — the kind of AI that can book flights, research topics, write and run code, and manage multi-step tasks on your behalf.

💡 Key Insight

The magic of ReAct isn't that AI got smarter — it's that AI can now pause to use tools. By weaving reasoning and actions together, it can check its work in real time, just like a human would.

The Think → Act → Observe Loop

The ReAct pattern runs in a repeating loop with three core steps. The AI keeps looping until the task is fully done.

The ReAct Loop
🧠
Think
Reason about what to do next
Act
Use a tool or take an action
👀
Observe
Look at what happened
🔁
Repeat
Think again until done
loops back to Think

Each loop, the AI writes down its thought, then picks an action (like "search the web for X" or "calculate Y"), then reads the observation (the tool's result). The next thought can build on that observation. This is why ReAct is so powerful — every step uses fresh, real information instead of just memory.

A Simple ReAct Agent in Python

Here's a small Python program that shows the ReAct pattern in action. The AI "thinks" about what to do, then runs a tool (a web search or a calculator), then reads the result and decides what to do next.

react_demo.py
# A tiny ReAct agent — think, act, observe, repeat
def react_agent(question, max_steps=5):
    history = ""

    for step in range(max_steps):
        # 1. THINK — ask the AI what to do next
        thought = ask_ai(
            f"Question: {question}\nHistory: {history}\n"
            "What should I do next?"
        )

        # 2. ACT — if the AI says "use a tool", run it
        if thought.startswith("SEARCH:"):
            query = thought.split(":", 1)[1].strip()
            observation = search_web(query)
        elif thought == "DONE":
            return ask_ai(f"Final answer to: {question}")
        else:
            observation = thought

        # 3. OBSERVE — add the result to history, then loop
        history += f"Step {step}: {thought} -> {observation}\n"

    return "Could not finish in time."

Notice how the loop has three parts that match our diagram: think (the ask_ai call), act (the search_web call or final answer), and observe (the observation variable). The AI's history of thoughts and observations is what lets it build on what it learned each step.

Knowledge Check

Test what you learned with this quick quiz.

Quick Quiz — 3 Questions

Question 1
What does ReAct stand for?
Question 2
What does the AI do right after it takes an "action" in the ReAct loop?
Question 3
Why is the ReAct pattern more accurate than a one-shot AI answer?
🏆

You crushed it!

Perfect score on this module.