chapter seven

7 Planning and reflection for complex tasks

 

This chapter covers

  • The limitations of reactive agents on 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 requiring multiple steps. The agent loses direction, forgets what it has done, or fails to recover from errors. Planning and reflection address these limitations by giving agents "time to think." Planning decomposes 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.

We’ll examine why reactive agents fail and how human experts approach complex tasks differently. We’ll then 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 and 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 is planning necessary?

7.2.2 Implementing the planning tool

7.2.3 Planning tool usage example

7.2.4 Extension directions

7.3 Reflection: Checking and correcting

7.3.1 When is reflection 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

7.4.1 Failure modes and solutions

7.5 Summary