chapter seven

7 Planning and reflection for complex tasks

 

This chapter covers

  • The limitations of reactive agents in performing complex tasks
  • Planning tools that decompose problems into task lists
  • Reflection tools that enable progress checking and failure recovery
  • The complementary cycle of planning and reflection

We’ve built an agent that observes the current situation, decides which tool to call, and repeats this cycle. This reactive approach works well for simple tasks but struggles with complex problems that require multiple steps. Even with the memory systems from chapter 6, the agent can lose direction, fail to use what it has already gathered, or get stuck repeating failed attempts. Memory helps the agent remember what happened. Planning and reflection address these limitations by giving agents time to think. Planning breaks complex problems into manageable tasks before execution. Reflection pauses to check progress and adjust direction when things go wrong.

Figure 7.1 The roles of planning and reflection in AI agents

In this chapter (figure 7.1), we’ll examine why reactive agents fail and how human experts approach complex tasks differently. Then we’ll implement a simple planning tool that records task lists in the context, followed by a reflection tool that enables progress checking and failure recovery. Finally, we combine both strategies into a complementary cycle to see how they resolve the failure modes of reactive agents.

7.1 Giving agents time to think

7.1.1 The limitations of ReAct

7.1.2 How human experts work

7.1.3 Why time to think matters

7.2 Planning: Setting direction

7.2.1 When planning is necessary

7.2.2 Implementing the planning tool

7.2.3 Planning-tool example

7.2.4 Extension directions

7.3 Reflection: Checking and correcting

7.3.1 When reflection is necessary

7.3.2 Implementing the reflection tool

7.3.3 The real value of reflection: Failure recovery

7.3.4 Running an agent that uses reflection for research synthesis

7.4 Integrating planning and reflection

Summary