Mod 3.6Constructing Plan-and-Execute Agent Systems
Level 3›Module 3.6
Level 3: Advanced Patterns & System DesignModule 3.6

Constructing Plan-and-Execute Agent Systems

Plan-and-Execute

Level 3 • Advanced Patterns & System Design
Est. ~12 mins
4 Key Topics
🎁 Free Learner Perk

Unlock Verified Certificate & Daily Streak Tracker

Ready to master Constructing Plan-and-Execute Agent Systems? Enable cloud sync to record your daily streak 🔥 and earn your Informational Completion Badge for your study milestones.

Day 1 Streak ActiveFree Completion BadgeSync Laptop & Phone
Module 3.6 • Strategic Patterns~20 min interactive

Constructing Plan-and-Execute Agent Systems

Pure ReAct agents wander off course on long, multi-step tasks. In this lesson, we build a Plan-and-Execute agent architecture in LangGraph: decoupling high-level strategic roadmapping from tactical tool execution with continuous replanning.

1. Core Mechanics of Plan-and-Execute

Select an architecture node to inspect

Plan-and-Execute Implementation

plan_and_execute.py • planner
# 1. THE STRATEGIC PLANNER NODE
from pydantic import BaseModel, Field
from langchain_openai import ChatOpenAI

class Plan(BaseModel):
    """Structured plan containing sequential action steps."""
    steps: list[str] = Field(
        description="Sequential list of distinct subtasks required to solve the goal."
    )

planner_llm = ChatOpenAI(model="gpt-4o", temperature=0)
planner = planner_llm.with_structured_output(Plan)

def plan_node(state: PlanExecuteState) -> dict:
    """Generates initial itinerary from user query."""
    user_query = state["input"]
    plan = planner.invoke(f"Decompose this task into distinct steps: {user_query}")
    return {"plan": plan.steps}

2. Interactive Plan-and-Execute Studio

Step-by-Step Execution Graph

Plan-and-Execute Agent Architecture Studio

Contrast single-step ReAct loops with structured Architect-Executor-Replanner workflows

"Research competitor pricing for Q3, generate financial comparison table, and draft executive summary."
1. ArchitectPlanner Node

Decomposes goal into ordered steps

2. WorkerExecutor Node

Executes current step using tools

3. SupervisorReplanner Node

Evaluates status: replan or complete

Current Plan State (State["plan"])0/3 Steps Completed
1
Search competitor website and extract pricing tiers
Tool: web_search(query='competitor SaaS pricing')
Pending
2
Format pricing data into a structured comparison table
Tool: data_formatter(schema='PricingTable')
Pending
3
Draft 200-word executive summary with recommendations
Tool: llm_writer(tone='executive')
Pending
📌 ReAct vs Plan-and-Execute: ReAct chooses its next action blindly after every step, making it wander off topic when goals exceed 5 steps. Plan-and-Execute creates a flight itinerary first, keeps the executor focused on one ticket at a time, and only recalibrates when a flight is delayed!

Common Engineering Traps

TRAP #1: The Rigid Unchanging Plan

Generating an 8-step plan and executing it blindly without a replanning step is fatal. If Step 2 discovers that an API endpoint requires authentication or a file does not exist, steps 3 through 8 will blindly execute on invalid assumptions. Always include a replanner node.

TRAP #2: Planner Prompt Bloat

Feeding the executor's full tool schema descriptions into the planner prompts causes the planner to hallucinate tool parameters rather than writing strategic natural language tasks. Let the planner write human-like directives, and let the executor choose the tools.

Key Architectural Takeaways

  • 1.Role Specialization: Separate strategic reasoning (Planner) from tactical tool calling (Executor). Smaller, cheaper models can run individual steps safely.
  • 2.Dynamic Replanning: The replanner inspects intermediate observations and dynamically prunes, inserts, or finishes steps as real-world data arrives.
  • 3.State Schema Isolation: Tracking state['plan'] and state['past_steps'] keeps the context clean, avoiding token exhaustion over long tasks.
Up Next • Module 3.7

Implementing Deep Planning Agents

Scale from simple lists to hierarchical tree search. Explore Monte Carlo Tree Search (MCTS), beam search, and backtracking for non-linear agent problem solving.

Continue to Module 3.7