Agentic AI Notebook
Phase 17

Plan & Execute

~3 min read

Concept & How It Works

  • Key points are in the visual diagram above.

Why Does It Exist?

ReAct decides one step at a time — efficient for exploration but wasteful for predictable workflows. Plan-and-Execute front-loads the thinking: create a complete plan, then execute efficiently. Better for structured, repeatable tasks where the tool sequence is known.

Real-World Analogy

Plan-and-Execute is like a contractor who draws blueprints before building — more upfront planning, but construction proceeds smoothly without constant redesign.
Loading diagram...

Visual Workflows

What is Plan & Execute?

Loading diagram...

Example

Scenario

Goal: 'Generate weekly sales report.' Plan: (1) Query DB for weekly sales, (2) Calculate WoW change, (3) Generate chart, (4) Write summary, (5) Save PDF. Executor runs each step. Joiner compiles into final report.

Solution

In Agent Design Patterns, apply Plan & Execute to this scenario: Goal: 'Generate weekly sales report. 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 Plan & Execute (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 Plan & Execute happens in the code.

Plan & Execute
1def plan_and_execute(goal: str, tools: dict) -> str:  # define a reusable function2    plan = planner_llm(goal, list(tools.keys()))  # key line for Plan & Execute3    results = {}4
5    for step in plan["steps"]:  # key line for Plan & Execute6        try:7            result = tools[step["tool"]](**step["args"], context=results)8            results[step["id"]] = result9        except Exception as e:10            remaining = [s for s in plan["steps"] if s["id"] >= step["id"]]  # key line for Plan & Execute11            plan = replanner_llm(goal, remaining, error=str(e))  # key line for Plan & Execute12            continue13
14    return joiner_llm(goal, results)  # return the result

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

  • Using Plan-and-Execute for exploratory tasks — too rigid
  • No re-planning — stale plan after first failure
  • Same expensive model for planning and execution
  • Not validating plan feasibility before execution
  • Plans without dependency awareness

Cheat Sheet

Quick recap — the most important points from this module.

Cheat Sheet

quick ref
  • Plan → Execute → Join
  • Re-plan on failure
  • Structured tasks only
  • Validate before execute
  • Smart planner + fast executor
  • LLMCompiler for parallel steps