Learn/Generative AI, RAG & Agents/MODULE 3: AGENTIC AI
Lesson 25 of 37 · 2 min read

3.4 Planning and Reasoning (The ReAct Pattern)

Once the LLM has tools, it needs a way to use them well on multi-step tasks.

The most influential pattern for doing this is called ReAct — short for "Reasoning and Acting." It comes from a 2022 research paper and underpins most agentic systems today.

How ReAct Works

ReAct interleaves three things in a loop:

  1. Thought: The model reasons in natural language about what to do next.
  2. Action: The model picks a tool and calls it.
  3. Observation: The system runs the tool and feeds the result back.

These three steps repeat — Thought, Action, Observation, Thought, Action, Observation — until the task is done.

A Worked Example

User task: "What was the population of the largest city in Brazil in 2020?"

A ReAct agent might internally produce something like:

Thought: I need to figure out which city was the largest in Brazil in 2020, then find its population. I'll start by searching for the largest city in Brazil.

Action: search_web("largest city in Brazil")

Observation: "São Paulo is the largest city in Brazil and South America."

Thought: São Paulo is the largest city. Now I need its 2020 population specifically.

Action: search_web("São Paulo population 2020")

Observation: "According to the 2020 census estimates, São Paulo had a population of approximately 12.33 million."

Thought: I have what I need.

Final Answer: São Paulo, the largest city in Brazil, had a population of approximately 12.33 million in 2020.

Notice the structure: the agent reasoned about what to do, acted (searched), observed the result, reasoned again, and so on.

This explicit thinking-out-loud isn't just for show.

Research has shown that prompting models to reason explicitly before acting produces meaningfully better results than just having them call tools blindly.

It also makes the agent's behavior much easier to debug — you can read the trail of thoughts and see why it made each decision.

Beyond Simple ReAct: Plan-and-Execute

For longer tasks, more sophisticated patterns exist.

One is plan-and-execute:

  1. Plan phase: The LLM produces a multi-step plan up front. (E.g., "Step 1: search for flights. Step 2: filter for direct. Step 3: compare prices. Step 4: book the cheapest. Step 5: add to calendar.")
  2. Execute phase: The agent works through each step, using tools as needed.
  3. Replan if needed: If a step fails or the plan turns out to be flawed, the agent revises the plan.

This works better than pure ReAct for very long tasks because it forces the model to think holistically before diving in.

Other Patterns

  • Self-reflection: After producing an answer, the agent critiques its own work and revises if needed.
  • Tree-of-thought: The agent explores multiple possible reasoning paths and picks the best.
  • Chain-of-thought + verification: Reasoning steps are produced, then a separate check confirms each step is valid before moving on.

You don't need to memorize these.

The main idea: agents do better when they think explicitly, plan ahead, and check their work.

Keep going with a free account

A free account saves your progress across lessons and lets you pick up where you left off.