Module 13 Lesson 1: The Planner-Executor Pattern
Division of Labor. How to split 'Thinking' and 'Doing' between two different agents for higher reliability.
Multi-Agent Patterns: Planner-Executor
As tasks get more complex, a single agent often gets "Confused." It tries to do too many things and loses track of the goal. The Planner-Executor pattern solves this by separating the Strategy from the Action.
1. The Roles
- The Planner: A smart, slow model (e.g., Claude 3.5 Sonnet). It looks at the big goal and breaks it into a 5-step checklist.
- The Executor: A fast, specialized agent (e.g., Llama 3 8B). It takes one step at a time from the checklist and runs the tools.
2. Why this is better
- Safety: The Planner can review the Executor's work after every step.
- Cost: Use the expensive model only for the "Thinking" and the cheap model for the "Doing."
- Isolation: If the Executor fails at step 3, the Planner can decide to retry or skip to step 4 without crashing the whole mission.
3. Visualizing the Pattern
graph TD
User[Goal: Market Report] --> P[Planner Agent]
P --> S1[Step 1: Get Stock]
P --> S2[Step 2: Get News]
P --> S3[Step 3: Graph Data]
S1 --> E[Executor Agent]
E -->|Tools| Data[Market Data]
Data --> P
P -->|Approved| S2
4. Engineering Tip: Shared State
For this to work, both agents need a Shared Memory (often a simple database or a JSON object). The Planner writes the "To-do List" to the state, and the Executor writes the "Results" to the state.
Summary
- Split Thinking and Doing to reduce agent confusion.
- Planner models the strategy; Executor handles the tool calls.
- This pattern enables Cost Optimization across models.
- Shared State is the glue that connects the team.