Welcome to our third lesson on the foundations of LLM-based agents. In our last session, we deconstructed the core agent loop into its fundamental stages: perceive, reason, act, and observe. We established that this iterative cycle is what gives an agent its power to tackle complex, multi-step problems.
Today, we move from the general "what" to the specific "how." You'll learn about ReAct, a seminal and highly effective prompting pattern that provides a concrete structure for the agent's reasoning and action-taking process. By the end of this lesson, you will be able to explain the ReAct (Reason and Act) pattern and understand how it enables an LLM to articulate its thought process before selecting and using a tool. This is a cornerstone of building transparent and reliable agents.
From Separated Thoughts to Interleaved Action
Before ReAct, prompting strategies largely fell into two camps. The first was "reasoning-only," exemplified by Chain-of-Thought (CoT) prompting, where the model was encouraged to "think step by step" to improve its reasoning on complex problems. The second was "action-only," where models were prompted to directly output a command, like a search query, without showing their reasoning.
The breakthrough of ReAct was to interleave reasoning and acting within the same loop. The model doesn't just think and then act; it thinks, acts, observes the result, and then thinks again based on that new information.

This combination proved to be more powerful than either approach alone. The reasoning trace makes the model's behavior more interpretable and less prone to hallucination, while the ability to act allows it to gather new information and interact with the world to solve the problem.
The following video provides an excellent overview of this evolution, explaining how ReAct builds upon earlier ideas to create a more robust system.
Understanding ReACT with LangChain
This video from Sam Witteveen's channel clearly explains the conceptual leap from Chain-of-Thought to ReAct.
Watch the first three minutes, from the introduction of ReAct to the end of the conceptual explanation. Focus on how ReAct synergizes the "reasoning upfront" of CoT with the "taking an action" paradigm.
The ReAct Prompting Strategy: A Text-Based Conversation
At its core, ReAct is a prompting technique. It instructs the LLM to format its output in a specific, structured way that exposes its internal monologue. This structure typically follows a Thought, Action, Observation cycle.
Let's break down how this "conversation" between the agent's controlling code (the "Agent Executor") and the LLM unfolds:
-
Initial Prompt: The agent executor sends a prompt to the LLM containing:
- The user's question.
- A list of available tools and their descriptions.
- Instructions to follow the ReAct format, often including a few examples (few-shot prompting).
- The prompt ends with the label
Thought:, signaling the LLM to begin its reasoning process.
-
LLM Response (Turn 1): The LLM generates text that follows the prescribed format. It starts with its reasoning and then specifies which tool to use.
- Thought: The LLM articulates its plan. e.g., "I need to find the current price of Bitcoin."
- Action: The LLM specifies the tool to call and the input for that tool. e.g.,
search(query="current price of Bitcoin").
-
Agent Execution: The agent executor intercepts this response. It parses out the
Actionand its input. Crucially, it stops the LLM's generation and executes the specified tool call—in this case, by calling a search API. -
Observation: The tool returns a result. e.g., "The current price of Bitcoin is $65,000." This result is labeled as the
Observation. -
Next Prompt (Turn 2): The executor appends the entire sequence from Turn 1 (
Thought,Action, and the newObservation) to a "scratchpad" in the prompt context. It then sends this updated context back to the LLM, again ending withThought:. -
Looping: The cycle repeats. The LLM, now with the new information from the observation in its context, generates the next
ThoughtandAction. This continues until the LLM'sThoughtprocess concludes that it has enough information to answer the original question. -
Final Answer: Once the task is complete, the LLM outputs a final thought and then uses a special
ActionlikeFinishor simply provides theFinal Answer. The agent executor recognizes this as the end of the loop and returns the answer to the user.
The following article provides a crystal-clear, step-by-step walkthrough of this textual exchange.
Understanding LangChain Agents: create_react_agent vs ...
This article by Anil Goyal provides one of the clearest explanations of the ReAct prompting strategy.
Start by reading the definition of ReAct. Then, carefully study the step-by-step example under The ReAct Prompting Strategy. This demonstrates the full, multi-turn conversation between the agent and the LLM.
The Role of the Agent Executor
As you've seen, the LLM itself doesn't execute any code. It only generates text. The magic of ReAct is enabled by a crucial piece of wrapper code, often called an Agent Executor. Your Python background will make this concept intuitive; it's a control loop that orchestrates the entire process.
The Agent Executor is responsible for:
- Formatting the initial prompt with tools and instructions.
- Parsing the LLM's text output to find
Actionblocks. - Calling the appropriate Python functions or APIs that correspond to the requested tools.
- Taking the output of those tools and formatting it as an
Observation. - Appending the
Thought-Action-Observationtriplet to the context (the "agent scratchpad"). - Looping until it detects a
Final Answer.
This video explains the critical role of the Agent Executor in bridging the gap between the LLM's textual output and actual tool execution.
LLM Chronicles #6.4: LLM Agents with ReAct (Reason + Act)
This segment from a video by Donato Capitella clearly explains why an agent executor is necessary to make ReAct work.
Watch the section from this timestamp. Pay close attention to the distinction he makes: the LLM only generates text, and the executor is the component that parses that text and executes the corresponding tool.
ReAct in Code: A LangChain Example
Let's translate this into practice. The article you just read provides a Python example using LangChain's create_react_agent function. The most important part of this code is the prompt template, which explicitly codifies the ReAct structure we've been discussing.
Understanding LangChain Agents: create_react_agent vs ...
Now, let's examine the code that brings this pattern to life.
Focus on the Python code block under the heading How create_react_agent Works. Specifically, analyze the template string. You'll see the explicit instructions for Thought, Action, Action Input, and Observation. This template is the "source code" for the ReAct behavior. Finally, review the list of key characteristics which provides a great summary.
The prompt template is the contract between you and the LLM. By providing clear instructions and a structured format, you guide the LLM to produce the interleaved reasoning and actions that make ReAct so powerful.
This entire flow, from the theoretical design to a framework-specific implementation, can be visualized as a flowchart.

Benefits and Considerations
The ReAct pattern is foundational for a reason, but it's important to understand its trade-offs, especially with your goal of building production-grade, cost-effective systems.
Benefits:
- Interpretability and Debugging: The
Thoughtprocess is written out, creating an audit trail. When an agent fails, you can read its "mind" to understand why it made a mistake. - Reduced Hallucination: By grounding its reasoning in
Observationsfrom real tools, the agent is less likely to make things up. - Robustness: The iterative nature allows the agent to self-correct. If an action fails or yields unexpected results, it can reason about the failure in the next thought step and try a different approach.
- Model Agnostic: ReAct is a prompting strategy, so it works with any sufficiently capable text-generation model.
Considerations:
- Cost and Latency: Every
Thought-Action-Observationcycle is another call to the LLM. This increases both the total token count (cost) and the end-to-end time (latency) compared to a single-pass generation. This is a critical factor for the "economics" you're interested in. - Model Dependence: While model-agnostic in theory, ReAct's reliability heavily depends on the LLM's ability to consistently follow the structured format. Weaker models may fail to generate the correct
Actionsyntax or get stuck in loops. - Prompt Engineering: The effectiveness of a ReAct agent can be sensitive to the quality of the tool descriptions and the few-shot examples provided in the prompt.
Conclusion
In this lesson, we dove deep into the mechanics of the ReAct prompting pattern. You've seen how it structures an agent's inner monologue, enabling it to robustly reason and interact with its environment.
Here are the key takeaways:
- ReAct stands for Reason and Act, a pattern that interleaves reasoning (
Thought) with tool use (Action) in an iterative loop. - It operates via a structured prompting format: The LLM is instructed to generate text following a Thought -> Action -> Observation cycle.
- An Agent Executor is the external code that orchestrates this loop by parsing the LLM's output, calling tools, and feeding the results back into the LLM's context.
- ReAct offers significant benefits in interpretability, robustness, and reliability, but comes with trade-offs in cost and latency due to its multi-step nature.
You now understand the most common pattern for how agents think and act on a step-by-step basis. However, not all problems are best solved one step at a time. In our next lesson, we will compare ReAct to other agent planning strategies, such as "plan-and-execute" and "reflexion," which take different approaches to breaking down and solving complex tasks.