This chapter explains that reactive agents, while good at choosing the next immediate action, often break down on complex tasks because they lack an overall strategy and do not pause to assess progress. They can lose direction, repeat unsuccessful steps, overlook information they already gathered, or prematurely claim success before the job is truly done. To address this, the chapter introduces planning and reflection as ways to give agents “time to think,” mirroring how human experts handle difficult problems.
Planning is presented as the act of decomposing a broad problem into smaller, manageable tasks before execution begins. Using examples such as the Kipchoge-to-the-Moon question, the chapter shows how a plan clarifies order, progress, and completion criteria, making it easier for the agent to stay on track. A simple planning tool is implemented by storing task lists in context with status markers like pending, in progress, and completed, while careful tool descriptions help the model decide when planning is actually worth the overhead.
Reflection complements planning by adding a deliberate pause to evaluate what has happened so far, detect errors, synthesize information, and decide whether the current plan should continue or be revised. The chapter demonstrates reflection for progress review, failure recovery, research synthesis, and final self-checking, using a lightweight tool that records the model’s analysis and an optional replan signal. Together, planning and reflection form a cycle: plan the work, execute it, check the results, and, when needed, revise the plan so the agent can recover from failures and complete complex tasks more reliably.
The roles of planning and reflection in AI agents.
The Planning-Reflection cycle in agent execution.
Summary
Planning and reflection give agents "time to think." Instead of reacting moment by moment, agents plan before acting and check after acting. This grants metacognition: the ability to examine their own process.
Planning decomposes complex problems into clear, manageable units. When "1. Research Kipchoge's record, 2. Research Moon distance, 3. Calculate time" is recorded in the context, the LLM references this plan to maintain direction across multiple steps.
Reflection is valuable when problems arise, not when everything goes smoothly. When tools fail or results are unexpected, Reflection enables cause analysis and alternative strategies instead of repeating the same failures.
Planning and reflection form a complementary cycle. Planning provides direction, reflection checks the direction, and when necessary, it triggers re-planning. Neither works in isolation.
From a context engineering perspective, both are generation strategies. Planning adds "what to do next" to the context, while reflection adds "evaluation and direction so far." These texts influence the LLM's subsequent decisions.
FAQ
```html
What is the main limitation of a reactive ReAct agent on complex tasks?Reactive agents only decide what to do next based on the current moment, which works for simple tasks but breaks down on complex problems that require multi-step reasoning, keeping track of progress, and recovering from mistakes.Why does planning help AI agents perform better on difficult problems?Planning gives the agent time to think before acting by breaking a complex problem into smaller, manageable tasks. This helps the agent maintain direction and decide what to do next more reliably.How is planning similar to how human experts solve problems?Human experts usually decompose a problem first, work through one part at a time, and check whether each step is complete before moving on. Planning makes agents follow the same approach.When should an agent use a planning tool?A planning tool is useful for problems that require multiple steps of research or combining information from different sources. It is not necessary for simple one-search questions or tasks with obvious procedures.What should a simple task plan include?A simple plan should list the key tasks in order, along with each task’s status such as pending, in progress, or completed. This helps the agent know what has been done and what comes next.Why does the chapter recommend regenerating the full plan instead of editing only small parts?Regenerating the full plan is simpler and less error-prone than tracking partial updates. It avoids bugs from wrong indices or state mismatches, and the token cost is usually small for short plans.What is the purpose of the reflection tool?The reflection tool lets the agent pause, review progress, analyze failures, and decide whether the current approach is still working. It adds self-checking and recovery to the agent’s workflow.When should reflection be used?Reflection is most useful after completing a meaningful step, when a tool fails, when combining multiple sources of information, or before giving the final answer. It should not be used after every single action.How does reflection help an agent recover from failure?When a tool fails, reflection records the cause and suggests an alternative approach. This prevents the agent from repeating the same failed action and helps it switch strategies.How do planning and reflection work together in a complete agent cycle?Planning sets direction by decomposing the task, reflection checks progress during execution, and if needed, reflection triggers re-planning. Together they help the agent avoid losing direction, answering too early, forgetting progress, and getting stuck in failures.
```
pro $24.99 per month
access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!