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.