Recommended resources
The freely available resources this lesson will direct you to.
Welcome to the fourth module of our course! Over the past few weeks, we've focused on building, optimizing, and evaluating Retrieval-Augmented Generation (RAG) systems. These systems are incredibly powerful for answering questions based on a given body of knowledge. However, their primary function is to retrieve and synthesize information.
In this module, we're making a significant leap from systems that answer to systems that act. We're entering the world of AI agents—autonomous entities that can reason, plan, and interact with their environment to accomplish goals. This shift is fundamental to building the next generation of AI applications.
Today's lesson marks our first step into this new domain. We will explore the foundational design pattern that powers most modern agents: ReAct, which stands for Reasoning and Acting. By the end of this lesson, you will be able to describe this crucial pattern and understand why it enables LLMs to solve complex, multi-step problems that are impossible with simple prompting alone.
From Reasoning to Acting
In the first module, we touched upon Chain-of-Thought (CoT) prompting, a technique that encourages a large language model (LLM) to "think out loud" by generating a sequence of reasoning steps. This dramatically improves performance on complex tasks. However, CoT has a critical limitation: the reasoning happens entirely inside the model's "head." The model can't verify its intermediate thoughts or access new information from the outside world.
An AI agent overcomes this by connecting the LLM's reasoning brain to "hands" that can perform actions.
ReAct AI Agents, clearly explained!
To start, watch this short, clear explanation from Akshay Pachaar on why we need agents and what the ReAct pattern is at a high level.
Pay attention to the distinction he draws between an LLM's ability to reason and an agent's ability to take action. Watch the first two segments, covering why we need agents and the high-level overview of what ReAct agents are.
The ReAct framework elegantly combines the internal monologue of Chain-of-Thought (the "Reasoning" part) with the ability to use tools and interact with external systems (the "Acting" part).
Understanding ReACT with LangChain
This video by Sam Witteveen provides an excellent conceptual bridge from Chain-of-Thought to ReAct.
Watch the segment from Reasoning and Action. It explains how ReAct synergizes the "reasoning only" approach of CoT and the "action only" approach into a more powerful, combined technique.
The Core Loop: Thought, Action, Observation
At its heart, the ReAct pattern is a simple, iterative loop. For any given task, the agent cycles through three distinct steps until it reaches a final answer. This structure should feel familiar, as it mirrors a stateful loop or a state machine pattern common in software engineering.
Create ReAct Agent from Scratch without any framework
This guide provides one of the clearest breakdowns of the ReAct loop. It walks through each phase with a concrete, multi-step example that makes the concept easy to grasp.
Read the entire section titled "Thought, Action, PAUSE, and Observation Loop". Focus on understanding the purpose of each of the four phases he describes: Thought, Action, PAUSE (which is the waiting period before Observation), and Observation. Then, carefully study the "Full Example" that solves the query about Isaac Newton.
Let's formalize those steps:
-
Thought 🧠: The agent uses the LLM to reason about the task. It analyzes the current state, breaks down the problem, and forms a plan for the next immediate step. It decides what to do and how to do it (e.g., "I need to find the birthplace of the Nobel Prize winner. I will use the search tool for this.").
-
Action ⚡️: The agent executes the plan formulated in the thought step. This almost always involves using a tool. A tool can be anything from a web search API, a calculator, a function to query a database, or even another AI model. The action is a specific invocation of that tool (e.g.,
search("2024 Nobel Prize winner in Physics")). -
Observation 👀: The agent receives the output from the tool. This is the result of the action (e.g., the text from the search result, the number from the calculator, or an error message). This observation provides new information from the external world.
This new observation is then fed back into the loop, starting a new Thought phase. The agent now reasons based on the original query plus the new information it just gathered. This cycle continues until the agent's thought process determines it has enough information to construct a final answer.
Why ReAct is a Game-Changer
To truly appreciate why this pattern is so effective, let's look at a side-by-side comparison of different prompting methods.

Let's analyze the top example, "HotpotQA," which asks a complex question requiring multiple pieces of information.
- (1a) Standard Prompting: The model gets the answer completely wrong. It has no process for breaking down the problem.
- (1b) Chain-of-Thought (Reason-Only): The model correctly reasons about the steps needed ("let's think step by step..."). However, because it can't interact with the world to verify its intermediate findings, it hallucinates a plausible but incorrect final answer. It reasons correctly but acts on flawed internal knowledge.
- (1c) Act-Only: The model tries to use tools but lacks a coherent plan. It searches for "Front Row" but doesn't know what to do with the result. Without a reasoning component to guide its actions, it flounders and fails.
- (1d) ReAct (Reason + Act): This is where the magic happens.
- Thought 1: "I need to search Apple Remote..." -> Action 1: Search -> Observation 1: Gets info about the remote.
- Thought 2: "Now I need to find what other device can control it..." -> Action 2: Search -> Observation 2: Finds info about Front Row being discontinued.
- Thought 3: "Front Row is discontinued... I need to search what controls the current Apple TV..." -> Action 3: Search -> Observation 3: Finds the answer about keyboard function keys.
- Thought 4: "I have the final answer." -> Final Answer: Provides the correct, verified answer.
ReAct succeeds because it combines the planning of CoT with the grounding of external tools, creating a feedback loop that allows the agent to self-correct and navigate complex information spaces.
The Architecture of a ReAct System
As a software engineer, you can think of the ReAct pattern not just as a prompting technique, but as a system architecture.

The diagram on the left formalizes the loop we've been discussing. To build such a system, you need a few key components.
Create ReAct Agent from Scratch without any framework
Let's return to the "from scratch" guide to see how these conceptual pieces are defined as architectural components.
Please read the section titled "Key Components of a ReAct Agent". It details the four essential pillars of the system: the LLM, the Tools, the Memory (or scratchpad), and the Prompt Engineering that stitches it all together.
These four components—LLM, Tools, Memory, and Prompts—are the essential building blocks you will work with when designing any agentic system.
From Theoretical Loop to Implementation Pattern
The theoretical loop is a great mental model, but in a production system, it needs to be translated into a robust and scalable software architecture. This is often done by implementing the ReAct loop as a state machine or, more commonly, a graph.
The diagram on the right side of the "Agents Powered by ReAct" flowchart shows such an implementation pattern from the LangGraph framework. Don't worry about the specific details of LangGraph; the key insight is the architectural pattern:
- The system's current state (including the conversation history, or "scratchpad") is passed around.
- Nodes in the graph represent the major processing steps: one node for the "Thought" phase (calling the
Model) and another for the "Action" phase (callingTools). - Edges in the graph represent the control flow, deciding whether to call a tool, loop back to the model for another thought, or finish.
Building Production ReAct Agents From Scratch Is Simple
This article from Decoding AI deconstructs a production-grade ReAct implementation, but we'll focus on how it maps the theoretical concepts to an architectural graph structure.
Read the section "The ReAct LangGraph Graph". Focus on the conceptual mapping, not the specific code. Pay attention to the bullet points that map the six core points of the theoretical loop to the nodes and edges of the graph. Also, note the definition of AgentState, which represents the memory or "scratchpad" that is passed between steps.
This graph-based approach is powerful because it makes the control flow explicit and manageable. It allows you to define the agent's behavior, error handling, and stopping conditions in a structured way—a crucial requirement for building reliable production systems.
Conclusion
In this lesson, you've been introduced to the ReAct pattern, the cornerstone of modern AI agent design. You've moved beyond simple question-answering and into the realm of goal-oriented action.
Key Takeaways:
- Agents Act: Unlike basic LLM applications, agents can interact with external environments using tools.
- ReAct = Reasoning + Acting: This pattern combines the internal reasoning of Chain-of-Thought with the ability to take actions and observe their outcomes.
- The Core Loop is Thought -> Action -> Observation: This iterative cycle allows an agent to break down complex problems, gather information, and self-correct its way to a solution.
- System Components: A ReAct system is an architecture composed of an LLM (the brain), Tools (the hands), Memory (the scratchpad), and structured Prompts (the operating instructions).
- Implementation as a Graph: In production, the ReAct loop is often implemented as a stateful graph, where nodes represent thinking/acting and edges represent the control flow.
You now have the foundational mental model for how autonomous agents work. In our next lesson, we will put this theory into practice. You'll move from describing ReAct to implementing it, building your first single-purpose agent using Python and the native tool-calling capabilities of modern LLMs.