Hello! In our previous lessons, we've assembled the essential parts of an AI agent: the core agent loop (the engine), tool use (the hands and eyes), and memory systems (the context). We have all the individual pieces, but a pile of parts doesn't make a machine. The critical question now is: how do we orchestrate these components to solve complex, multi-step problems dynamically?
This is where the ReAct pattern comes in. It's a powerful framework that enables an agent to reason about a problem, act on its reasoning, and learn from the results in a continuous cycle. Today's lesson is dedicated to deconstructing this pattern into its core components. By the end, you will be able to identify and explain the role of Thought, Action, and Observation in any ReAct-based agent.
What is ReAct? Reasoning + Acting
The name "ReAct" is a portmanteau of Reasoning and Acting. It was designed to overcome the limitations of earlier prompting techniques like Chain-of-Thought (CoT).
- Chain-of-Thought (CoT) prompts an LLM to "think out loud," generating a reasoning trace before giving a final answer. This improves performance on complex problems but happens in a vacuum. The model can't access new information, so it's prone to hallucinating facts if the knowledge isn't in its training data.
- ReAct enhances this by interleaving reasoning with actions. The agent doesn't just plan once; it plans a small step, executes it using a tool, observes the outcome, and then uses that new information to plan the next step.
To get a high-level overview of this idea, let's watch the beginning of the following video.
Understanding ReACT with LangChain
The video 'Understanding ReACT with LangChain' from Sam Witteveen's channel provides an excellent introduction to the ReAct concept and how it advances beyond Chain-of-Thought by combining reasoning with actions.
Watch from the beginning to 02:54. Focus on how ReAct synergizes the 'reasoning-only' paradigm of CoT with the 'action-taking' paradigm to create a multi-step, iterative problem-solving process.
As the video explains, ReAct allows an agent to build a plan, execute parts of it, gather external information, and then refine its plan based on new facts. This creates a much more robust and reliable system.
The Three Core Components of the ReAct Cycle
The ReAct pattern operates in a tight, iterative loop composed of three distinct components.

Let's break down each phase of this cycle.
-
Thought (🧠): The Internal Monologue
- What it is: The reasoning step. This is where the LLM acts as the agent's "brain," analyzing the user's request, the conversation history, and any previous observations. It formulates a plan or decides on the immediate next step needed to solve the task.
- Its purpose: To decompose the problem, strategize, and decide what information is missing or what action needs to be taken. It's the "Reasoning" in ReAct.
-
Action (🎬): Interacting with the World
- What it is: The agent's decision to use a tool to interact with the external environment. The action is a specific, executable instruction, such as
Search[Apple Remote]orCalculator[29^0.23]. - Its purpose: To gather information that the LLM doesn't have, perform precise calculations, or interact with any external API. This is the "Acting" in ReAct. A special action, often called
FinishorFinal Answer, is used when the agent determines it has solved the problem.
- What it is: The agent's decision to use a tool to interact with the external environment. The action is a specific, executable instruction, such as
-
Observation (👀): The Feedback Loop
- What it is: The information returned from executing the action. If the action was a search, the observation is the search result. If it was a calculation, the observation is the numerical answer.
- Its purpose: To provide new, external information to the agent. This result is added to the agent's context (its short-term memory or "scratchpad") and becomes a critical input for the next Thought step, closing the loop.
The following video from IBM Technology provides a very crisp breakdown of these three steps using a practical financial example.
4 Methods of Prompt Engineering
In this segment of '4 Methods of Prompt Engineering', the speaker clearly deconstructs ReAct into its three-step process.
Watch the clip from 09:43 to 10:48. Pay attention to how the task of comparing earnings from two different years is broken down into a sequence of Thought, Action, and Observation steps.
A Detailed Walkthrough of the T-A-O Cycle
Now that we understand the individual components, let's see how they work together to solve a more complex query. The best way to understand this is to read through a full "reasoning trace" of an agent.
The following resource provides a clear definition of ReAct and shows a great example of an agent figuring out the elevation range of a geographical area, a task that requires multiple search queries.
The 'ReAct Prompting' article from PromptingGuide.ai offers a concise yet detailed explanation of the pattern, complete with an excellent example trace.
Read the sections 'How it Works?' and 'ReAct Prompting'. Focus on the example trace that starts with the question about the 'Colorado orogeny'. Follow the interleaved sequence of Thought, Action, and Observation and see how the agent refines its search based on the observations it receives.
In the example from the article, you can see the agent's intelligence at work:
- Thought 1: Decomposes the problem correctly.
- Observation 1: The initial search is too broad.
- Thought 2: The agent realizes it needs to narrow its search to the "eastern sector."
- Observation 4: The search for "High Plains" gives an ambiguous result.
- Thought 4: The agent refines the search again to "High Plains (United States)" to get the correct information.
This ability to self-correct based on feedback is the core strength of the ReAct pattern.
How is the ReAct Pattern Triggered?
As a software engineer, you might be wondering how this structured output is generated. It's not a special feature of the LLM itself, but rather a result of clever few-shot prompting.
The system prompt sent to the LLM includes several examples of a task being solved using the Thought, Action, Observation format. The model then uses these examples as a template for solving the new query you give it.
Let's watch a demonstration of this. The video shows how a prompt is constructed with these examples and then fed to the LLM. It even shows what happens when the tools aren't actually connected—the LLM still follows the pattern, but it hallucinates the observation, which is a fascinating failure mode to understand.
Understanding ReACT with LangChain
We'll return to Sam Witteveen's video, where he masterfully demonstrates how few-shot examples in the prompt guide the LLM to produce the ReAct structure.
Watch the segments from 03:27 to 05:03 and from 08:39 to 11:38. In the first part, you'll see a clean example trace. In the second, you'll see the underlying prompt that makes it happen and witness the model hallucinating observations when no tools are available.
When you use a framework like LangChain, this prompting is handled for you by the initialize_agent function. The output you see in the console, with the Thought:, Action:, and Observation: lines, is the raw text being generated by the LLM before the framework parses it to execute the tool call. The ReAct Prompting article we read earlier shows this clearly in its "LangChain ReAct Usage" section.
Test your understanding!
An agent is asked: "What is the capital of France, and what is its current population?" The agent has access to two tools: search[query] and get_population[city_name].
Deconstruct how the agent would solve this task by writing out the sequence of Thought, Action, and Observation steps it would likely take.
Show answer
Here is a likely sequence:
- Thought 1: The user is asking for two pieces of information: the capital of France and its population. First, I need to find the capital of France.
- Action 1:
search[capital of France] - Observation 1: The result of the search is "Paris".
- Thought 2: I have found that the capital is Paris. Now I need to find the population of Paris. I have a specific tool for that.
- Action 2:
get_population[Paris] - Observation 2: The result is "2.141 million".
- Thought 3: I have found both the capital (Paris) and its population (2.141 million). I have all the information needed to answer the user's question.
- Action 3:
Finish[The capital of France is Paris, and its current population is 2.141 million.]
Conclusion
Today, we've dissected the ReAct pattern, the orchestrating mechanism that brings an agent's capabilities to life.
Key Takeaways:
- ReAct = Reasoning + Acting: It combines the internal reasoning of Chain-of-Thought with the ability to interact with the external world through tools.
- The Core Components form a loop:
- Thought: The agent's internal reasoning and planning step.
- Action: A decision to use a tool to gather information or perform a task.
- Observation: The result returned from the tool, which informs the next thought.
- It's Prompt-Driven: The ReAct structure is not native to LLMs but is induced through carefully crafted few-shot prompts that provide examples of the T-A-O cycle.
We now have a clear understanding of the individual components of the agent loop, tool use, memory, and the ReAct pattern. In our next lesson, we will synthesize all of this knowledge. We'll illustrate how the ReAct pattern is the "conductor" that orchestrates the entire agent architecture—driving the agent loop, selecting tools, and updating memory—to solve a complete task from start to finish.