0
Phase 9

Planner Pattern

~3 min read

Concept & How It Works

    Why Does It Exist?

    Ad-hoc ReAct loops are hard to debug ('why did it call that tool?'). An explicit plan gives users visibility, enables human approval gates, and lets you validate feasibility before spending tokens on execution.

    Real-World Analogy

    A planner is an architect's blueprint — everyone agrees on the design before construction starts, avoiding costly rework mid-build.
    Loading diagram...

    Visual Workflows

    What is Planner Pattern?

    Loading diagram...

    Example

    Scenario

    User: 'Onboard new employee Jane.' Planner outputs: 1) Create Google account, 2) Add to Slack, 3) Assign laptop from inventory, 4) Send welcome email. Manager approves → executor runs each step.

    Solution

    In Agent Design Patterns, apply Planner Pattern to this scenario: User: 'Onboard new employee Jane. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.

    Practice Task

    Do this before moving to the next module — reading alone is not enough.

    Open the Code Walkthrough below and run it locally. Change one parameter related to Planner Pattern (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.

    Code Walkthrough

    Highlighted lines show where Planner Pattern happens in the code.

    Planner Pattern
    1plan = planner.invoke({  # key line for Planner Pattern2    "goal": user_request,3    "tools": [t.schema for t in tools],4    "constraints": "Must complete within 10 minutes",5})6if require_approval:7    await wait_for_approval(plan)8for step in plan.steps:9    result = execute_step(step)10    if result.failed:11        plan = replanner.invoke(goal, completed_steps, error=result.error)  # key line for Planner Pattern

    Commands to Remember

    Commands to Remember

    • pip install langchain langchain-openai # patterns work with any LLM SDK
    • python react_agent.py # run a ReAct-style agent loop
    • pip install tenacity # retry logic for agent steps

    Common Mistakes

    • Treating Planner Pattern as a black box without evaluation
    • Ignoring cost and latency in production
    • Skipping error handling for planner pattern

    Cheat Sheet

    Quick recap — the most important points from this module.

    Cheat Sheet

    quick ref
    • Planner Pattern
    • Structured Plan
    • Human-in-the-Loop
    • Replanning