Planning
Without planning, agents wander, repeat work, and miss step dependencies.
Trip planning: flights first, then hotel, then car — not random bookings.
Visual Workflows
Start here — scroll inside each diagram frame to explore, then use + / − to zoom up to 200% if needed.
Scroll inside the frame to explore · use + / − to zoom up to 200%
Plan-Execute-Replan Loop
Scroll inside the frame to explore · use + / − to zoom up to 200%
How planning interacts with execution and failure recovery.
Hierarchical Planning
Scroll inside the frame to explore · use + / − to zoom up to 200%
High-level plan decomposes into sub-plans per major step.
Key Takeaways
- 1.Planning decomposes goals into ordered steps before acting.
- 2.Approaches: LLM plan hierarchical re-plan plan-and-execute.
- 3.Plan format: step tool dependencies expected output.
- 4.Validate plans and allow human review for risky tasks.
Real Example
Scenario
Goal: 'Board deck by Friday.' Plan: (1) SQL revenue by region, (2) chart, (3) competitor bullets via web search, (4) draft slides, (5) PDF export, (6) email board — step 3 can run in parallel after step 1.
What you would do
Planner emits JSON steps with `depends_on`. Validate that `run_sql`, `web_search`, and `export_pdf` exist before execution. Human approves before step 6 (external email). If step 3 fails, re-plan steps 3–6 only. Monitor: plan adherence (% steps run in dependency order).
Practice Task
Write a 5-step JSON plan for the board deck goal. Include `tool`, `depends_on`, and `expected_output` for each step.
Code Walkthrough
Highlighted lines show where Planning happens in the code.
1PLAN = [2 {"step": 1, "tool": "run_sql", "task": "Q3 revenue by region", "depends_on": []},3 {"step": 2, "tool": "create_chart", "task": "bar chart", "depends_on": [1]},4 {"step": 3, "tool": "web_search", "task": "competitor news", "depends_on": [1]},5 {"step": 4, "tool": "draft_slides", "task": "merge chart + bullets", "depends_on": [2, 3]},6]7
8REGISTERED_TOOLS = {"run_sql", "create_chart", "web_search", "draft_slides"}9
10assert all(s["tool"] in REGISTERED_TOOLS for s in PLAN) # key line for Planning11for step in sorted(PLAN, key=lambda s: s["step"]):12 print(f"Execute step {step['step']}: {step['tool']}") # show output for debuggingCheat Sheet
Quick recap
quick ref- •Plan first for known workflows
- •JSON plan with steps and tools
- •Re-plan on failure always
- •Human approve high-stakes plans
- •ReAct for exploratory tasks
Common Mistakes
- ✕Rigid plan with no re-planning
- ✕Over-planning simple one-step tasks
- ✕No plan validation before execution
