No history yet

Reasoning and Planning Patterns

The Agent's Inner Monologue

A simple prompt to a large language model (LLM) is like asking a question and getting a direct answer. This works for straightforward tasks, but complex problems require more than a single response. They demand strategy, adaptation, and a series of intermediate steps. This is where agentic workflows come in, transforming the LLM from a simple respondent into a goal-oriented problem-solver.

At the heart of this transformation are reasoning and planning patterns. Instead of just executing a command, an agent needs a way to think, plan its next move, and learn from the results. These patterns provide the cognitive architecture for an LLM to break down a high-level goal, like "research the impact of AI on the film industry," into a sequence of deliberate actions.

An AI Agent is an integrated system that uses an LLM as its core reasoning engine to: Perceive a high-level, often complex, goal from a user. Plan a sequence of actions to achieve that goal. Execute those actions by leveraging a suite of tools (APIs, functions, code execution). Observe the outcomes and iterate on the plan recursively until the goal is met or a termination condition is reached.

The ReAct Framework

One of the most foundational patterns for agentic behavior is ReAct, which stands for "Reason and Act." It creates a tight loop between thinking and doing. Instead of trying to solve a problem in one go, the agent iterates through a cycle of thought, action, and observation. This mirrors how a person might tackle a research task: you think about what to search for, perform the search, see the results, and then use that new information to decide on the next step.

The process looks like this:

  1. Thought: The agent analyzes the current state and the overall goal. It generates a short, internal monologue about what it should do next. For example: "I need to find recent articles on AI in filmmaking. I should use the search tool to look for 'AI impact on movie production 2024'."
  2. Action: The agent executes the action it just decided on. It calls a specific tool, like a web search API, with the exact parameters it formulated in its thought process.
  3. Observation: The agent receives the output from the tool—a list of search results, an error message, or data from a database. This is new information about the environment.

This cycle repeats. The observation from the previous step feeds into the next thought, allowing the agent to dynamically adjust its approach based on what it discovers. This interleaving of with action makes the agent's process transparent and easier to debug.

Planning and Self-Correction

While ReAct is powerful for its dynamic nature, some problems benefit from more upfront thinking. This leads to 'Plan-and-Execute' architectures, where the agent first generates a complete, step-by-step plan and then carries it out. This is a form of static planning. Think of it like a detailed recipe: all steps are defined before you start cooking. This approach is useful when the task is well-defined and the environment is predictable.

The real power, however, comes from blending these approaches. An agent can create an initial plan but then critique and refine it based on new information. This is where reflection loops come in. After executing a step (or the whole plan), the agent pauses to evaluate the outcome.

It asks itself questions like:

  • Did the last action get me closer to my goal?
  • Was there an error? If so, why?
  • Based on what I've learned, is my original plan still the best one?

This self-correction allows the agent to recover from mistakes and adapt its strategy. For instance, if a web search returns no results, a loop would prompt the agent to analyze its query, identify it as too specific, and generate a new, broader search term. This process of dynamic task decomposition—breaking down a goal and then re-evaluating those sub-goals—is critical for tackling complex, real-world problems.

Lesson image

More advanced frameworks take this even further. Some, like , treat the user's request as a high-level program to be compiled. The 'compiler' breaks the task into a graph of dependencies and required tool calls. It identifies which parts can be run in parallel and handles the flow of data between steps. This creates a highly structured and efficient execution plan, moving beyond a simple linear loop to a complex, optimized task graph.

The key trade-off is between dynamic flexibility and static efficiency. ReAct adapts on the fly but can be inefficient. Plan-and-Execute is efficient for predictable tasks but brittle when things go wrong. The most robust agents combine planning with reflection to get the best of both worlds.

Now, let's test your understanding of these core agentic patterns.

Quiz Questions 1/6

What is the primary difference between a simple prompt to an LLM and an agentic workflow?

Quiz Questions 2/6

The ReAct pattern creates an iterative loop for an LLM agent. What are the three core components of this cycle?

By mastering these reasoning and planning patterns, you can build agents that don't just answer questions, but that strategize, adapt, and solve truly complex problems.