Özer Cem KELAHMETKELAHMET
Articles · Plan-and-Execute

Plan-and-execute agents explained: planner, executor and replanner in LangGraph 1.2

Plan-and-execute splits an agent into a planner that writes the steps, an executor that does them one at a time, and a replanner that fixes the plan when reality disagrees. This guide traces the idea from the Plan-and-Solve paper to a runnable LangGraph graph with a failure and a replan.

Download Markdown
At a glance
Reading time
13 min
Sections
7
Code examples
5
Tables
1
Sources
7
Published
24 Nov 2026
In 30 seconds
What changed
The Plan-and-Solve prompting paper is posted
Why it matters
Use plan-and-execute for long, structured work.
What to do
Pick tasks with real structure

A ReAct agent decides only its next step. That works for short tasks, but on a long one it can wander: it forgets the overall goal, repeats work or stops halfway. Plan-and-execute fixes this by making the plan explicit. A planner model writes the full list of steps first. An executor, often a small ReAct agent with tools, carries out one step at a time. After each step a replanner looks at what happened and either keeps the plan, rewrites the remaining steps or declares the task done.

The pattern grew out of two strands of 2023 work: the Plan-and-Solve prompting paper, which showed that asking a model to "devise a plan" before solving reduces skipped steps, and agent projects such as BabyAGI that kept a running task list. LangChain shipped "plan-and-execute agents" in May 2023, crediting Plan-and-Solve, and the pattern lives on as a standard LangGraph design. This article explains the algorithm, runs a graph that hits an error and replans, and shows when the extra planner call pays off.

What happened

The Plan-and-Solve prompting paper is posted (May 2023)

Lei Wang and co-authors from Singapore Management University and collaborators published "Plan-and-Solve Prompting: Improving Zero-Shot Chain-of-Thought Reasoning by Large Language Models", later accepted to ACL 2023. They analysed where zero-shot chain-of-thought ("Let's think step by step") failed and grouped the errors into three kinds: calculation errors, missing-step errors and semantic misunderstanding errors. Plan-and-Solve targets the missing steps by asking the model to plan first.

LangChain adds plan-and-execute agents (May 2023)

The Plan-and-Solve authors note in their repository that their method was added to LangChain's core library as "Plan-and-Execute", with a LangChain blog post describing planner and executor agents. The design separated a planning model from an execution agent so each could be chosen and prompted separately.

The pattern lives on in LangGraph 1.2 (November 2026)

LangGraph's original plan-and-execute example notebook is now archived in its repository, and the material has moved into the consolidated LangChain documentation. The graph in this article was run on langgraph==1.2.24, released on 20 November 2026.

From Plan-and-Solve prompting to plan-and-execute agents

Plan-and-Solve is a prompting method, not an agent. It replaces the zero-shot trigger "Let's think step by step." with a longer instruction. The repository lists the exact trigger sentences:

PS:  Let's first understand the problem and devise a plan to solve the problem.
     Then, let's carry out the plan to solve the problem step by step.

PS+: Let's first understand the problem, extract relevant variables and their
     corresponding numerals, and devise a plan. Then, let's carry out the plan,
     calculate intermediate variables (pay attention to correct numeral calculation
     and commonsense), solve the problem step by step, and show the answer.

The paper evaluated these zero-shot prompts with GPT-3 (text-davinci-003) on ten datasets covering arithmetic, commonsense and symbolic reasoning. It reports that PS+ outperformed zero-shot chain of thought by a large margin across all of them, was comparable to or better than zero-shot program-of-thought prompting, and on maths was comparable to 8-shot chain-of-thought prompting, without any examples.

Plan-and-execute agents take the same idea one level up. Instead of a plan inside one completion, the plan becomes a data structure that the system keeps, executes and edits.

How a plan-and-execute agent works, step by step

Think of a home renovation. An architect draws the plan, builders do one job at a time, and after each job the site manager checks the result. If the builders find rotten beams behind a wall, the manager does not throw the plan away; they insert "replace beams" before "plaster the wall" and carry on. Plan-and-execute agents have the same three roles.

  1. Planner. One call to a capable model. Input: the task. Output: an ordered list of steps, usually as structured output such as {"steps": [...]}.
  2. Executor. Takes the first remaining step and completes it, typically with a small ReAct agent that has the tools. It returns a short result.
  3. Replanner. Reads the task, the original plan, the completed steps and their results. It returns either a final response or an updated list of remaining steps.
  4. Loop. Executor and replanner alternate until the replanner returns a response or a limit is hit.

A runnable plan-and-execute graph

The graph below uses scripted functions for the three roles so it runs without an API key. The interesting part is the second step: the fake finance API returns an error, and the replanner inserts a corrected step instead of failing.

import operator
from typing import Annotated, TypedDict
from langgraph.graph import StateGraph, START, END

class PlanState(TypedDict):
    task: str
    plan: list[str]                                   # remaining steps
    past_steps: Annotated[list[tuple[str, str]], operator.add]
    response: str
    replans: int

def planner(state: PlanState):                        # real: model.with_structured_output(Plan)
    return {"plan": ["Get Q3 revenue for ACME from the finance API",
                     "Get Q3 revenue for ACME from last year",
                     "Compute the year-over-year growth"], "replans": 0}

FAKE_API = {"Get Q3 revenue for ACME from the finance API": "Q3 2026 revenue: 12.6M",
            "Get Q3 revenue for ACME from last year": "ERROR: endpoint needs fiscal_year param",
            "Get Q3 2025 revenue with fiscal_year=2025": "Q3 2025 revenue: 10.5M"}

def executor(state: PlanState):                       # real: a ReAct sub-agent with tools
    step = state["plan"][0]
    result = ("growth = 12.6 / 10.5 - 1 = 20%" if step.startswith("Compute")
              else FAKE_API.get(step, "no data"))
    print(f"execute: {step!r} -> {result}")
    return {"past_steps": [(step, result)], "plan": state["plan"][1:]}

def replanner(state: PlanState):                      # real: an LLM call with structured output
    last_step, last_result = state["past_steps"][-1]
    if last_result.startswith("ERROR"):
        print("replan: last step failed, inserting a fixed step")
        return {"plan": ["Get Q3 2025 revenue with fiscal_year=2025"] + state["plan"],
                "replans": state["replans"] + 1}
    if not state["plan"]:
        return {"response": last_result}
    return {}

def route(state: PlanState):
    return END if state.get("response") or state["replans"] > 2 else "executor"

g = StateGraph(PlanState)
g.add_node("planner", planner); g.add_node("executor", executor); g.add_node("replanner", replanner)
g.add_edge(START, "planner"); g.add_edge("planner", "executor"); g.add_edge("executor", "replanner")
g.add_conditional_edges("replanner", route, ["executor", END])
app = g.compile()

out = app.invoke({"task": "How much did ACME's Q3 revenue grow year over year?",
                  "past_steps": [], "response": ""})
print("ANSWER:", out["response"], "| steps run:", len(out["past_steps"]), "| replans:", out["replans"])

The trace:

execute: 'Get Q3 revenue for ACME from the finance API' -> Q3 2026 revenue: 12.6M
execute: 'Get Q3 revenue for ACME from last year' -> ERROR: endpoint needs fiscal_year param
replan: last step failed, inserting a fixed step
execute: 'Get Q3 2025 revenue with fiscal_year=2025' -> Q3 2025 revenue: 10.5M
execute: 'Compute the year-over-year growth' -> growth = 12.6 / 10.5 - 1 = 20%
ANSWER: growth = 12.6 / 10.5 - 1 = 20% | steps run: 4 | replans: 1

Three design choices in this code matter in real systems. The past_steps field uses an operator.add reducer, so completed work is appended and never lost when the plan changes. The replan counter is a hard stop: without it, a planner that keeps inserting failing steps loops forever. And the executor only ever sees one step, which keeps its prompt short and lets you use a cheaper model for it.

To make it real, give the planner and replanner a Pydantic schema such as class Plan(BaseModel): steps: list[str] and call model.with_structured_output(Plan), and make the executor a create_agent ReAct agent with your tools. Adding a checkpointer when you compile turns every step into a saved state you can inspect, interrupt for approval or replay; the LangGraph checkpoints simulation shows how.

Planner and replanner prompts

The quality of the whole system rests on two prompts. A planner prompt should state the goal, list the tools the executor can use with one line each, and ask for the smallest set of steps that completes the task, each written so that someone with only the tools and that one sentence could do it. Steps like "research the topic" are too vague; "search the finance API for ACME Q3 2025 revenue" is executable.

The replanner prompt needs four inputs: the original task, the original plan, the completed steps with their results and the remaining steps. Ask it to choose exactly one of two outputs, a final response or a new list of remaining steps, and to keep completed steps out of the new list. A schema makes that choice explicit and easy to validate:

from pydantic import BaseModel, Field

class Plan(BaseModel):
    steps: list[str] = Field(description="Remaining steps, in order, each executable on its own")

class Response(BaseModel):
    answer: str

class ReplanDecision(BaseModel):
    action: Plan | Response   # either a new plan or the final answer

With a real model, model.with_structured_output(ReplanDecision) returns an object your graph can branch on: a Response ends the run, a Plan replaces the remaining steps. Validate the new plan the same way as the first one, and reject it if it is longer than a cap or repeats a step that already failed twice.

Cost, speed and quality compared with ReAct

Plan-and-execute adds calls but can still save money, because most calls go to the cheap executor.

Table 1. Cost, speed and quality compared with ReAct
Property ReAct Plan-and-execute ReWOO
Who sees the whole task? One model, every step Planner and replanner Planner only
Calls for a 4-step task About 5 calls to one model 1 plan + 4 executions + 4 replans, or fewer with a skip rule 2
Can use a cheap model for steps? Not easily Yes, the executor Tools only
Recovers from surprises? Yes, step by step Yes, at replan points No
Keeps long tasks on track? Weakly Strongly, the plan is explicit Strongly, but rigidly

A worked example: a large model costs ten times more per token than a small one. In ReAct, all five calls go to the large model. In plan-and-execute, the planner and replanners use the large model with short prompts (the task, the plan, a few results), while the four executions use the small model with tools. If replanning is skipped when a step succeeds and nothing changes, you may pay for only one or two large-model calls. That is the same idea as model routing: spend expensive reasoning where it matters.

Latency is the cost. Every replan is a sequential call between steps. LLMCompiler, a later design from Berkeley researchers, attacks this by planning a dependency graph of tasks and running independent ones in parallel. The parallel tool calls simulation shows why that shortens the critical path.

What it means in practice

Use plan-and-execute for long, structured work. Reports, migrations, data pipelines and research tasks with several known phases benefit from an explicit plan that people can read and approve. Plans are also natural places for human-in-the-loop approval: show the plan, let a person edit it, then execute.

Do not over-plan short tasks. For one or two tool calls, the planner call is pure overhead. A plain ReAct agent is simpler and faster.

Make the replanner cheap to skip. Only call it when a step fails, returns something unexpected, or the plan is finished. Many implementations replan after every step and pay for it.

Keep plans as data. A list of steps in state can be logged, diffed, shown in a UI and evaluated. The agentic patterns simulation compares the visible plan with ReAct's implicit one.

What to do now

  1. Pick tasks with real structure. Start where your traces show long ReAct runs that lose track of the goal or repeat work.
  2. Use structured output for plans. Define a schema with a list of steps, and reject plans that are empty, too long or reference unknown tools.
  3. Give the executor one step at a time. Pass the step plus only the results it needs, not the whole history.
  4. Split models by role. Use a strong model for planning and replanning and a cheaper one for execution, and measure quality per role.
  5. Cap replans and total steps. Stop after a fixed number of replans and surface the partial result.
  6. Replan on signals, not on every step. Trigger it on errors, empty results, or when the plan is exhausted.
  7. Add approval for risky plans. Interrupt before execution when a plan includes writes, payments or emails.
  8. Evaluate plans separately. Score plan quality (coverage, order, no redundant steps) as well as the final answer, using evals on a fixed task set.

Risks and open questions

Bad plans are executed faithfully. A planner that misunderstands the task produces a confident wrong plan, and the executor follows it. Plan review, by a person or a judge model, catches some of this.

Replanning can oscillate. A replanner may keep swapping between two approaches. Track plan history and stop when a step repeats.

Context splits hide information. The executor sees only its step. If a later step needs a detail from an earlier result that was not passed along, quality drops. Decide explicitly what each step receives.

Evidence is mostly from prompting papers. Plan-and-Solve measured single-completion reasoning, not tool-using agents. The agent pattern is widely used, but its gains depend on your tasks; measure against ReAct.

Watch next: planners that output dependency graphs for parallel execution, plan approval steps in agent UIs, and evaluation suites that score plans as well as answers.

Frequently asked questions

How is plan-and-execute different from ReAct?

ReAct decides one step at a time with no explicit plan. Plan-and-execute writes the plan first, executes steps one by one and revises the plan when results demand it, which keeps long tasks on track.

What is Plan-and-Solve prompting?

It is a zero-shot prompting method from an ACL 2023 paper. It replaces "Let's think step by step" with an instruction to understand the problem, devise a plan and then carry it out, which the paper found reduced missing-step errors.

Do I need a replanner?

For anything beyond trivial tasks, yes. Without one, a single failed step breaks the run. You can keep costs down by calling it only on failures, surprises or when the plan runs out.

Can the executor be a small model?

Often yes, because it handles one well-defined step at a time. Test it on your tools and steps; if it struggles with tool arguments, upgrade only the executor.

How is it different from ReWOO?

ReWOO writes the plan with placeholders and runs all steps without looking at results until the end. Plan-and-execute looks at results between steps and can change the plan, at the cost of more calls.

Summary

Plan-and-execute agents separate planning from doing: a planner writes the steps, an executor completes one at a time, and a replanner revises the remaining plan after surprises. The idea draws on Plan-and-Solve prompting, which showed that asking models to plan first reduces missed steps, and on early task-list agents. In LangGraph 1.2 it is a three-node graph with an append-only list of past steps and a replan limit. It shines on long, structured tasks and lets you use a cheap model for execution, but it adds sequential calls and can only be as good as its plans.

Sources

Cite this article

Kelahmet, Ö. C. (2026, November 24). Plan-and-execute agents explained: planner, executor and replanner in LangGraph 1.2. Özer Cem KELAHMET. https://www.ozercemkelahmet.com/articles/plan-and-execute-agents-replanning-langgraph

BibTeX
@online{kelahmet2026plan,
  author = {Kelahmet, {\"O}zer Cem},
  title  = {{Plan-and-execute agents explained: planner, executor and replanner in LangGraph 1.2}},
  year   = {2026},
  month  = {nov},
  url    = {https://www.ozercemkelahmet.com/articles/plan-and-execute-agents-replanning-langgraph}
}
Version historyfirst version
  1. Published

Factual corrections are listed here with what changed. Wording and formatting edits are not listed.

Last updated Nov 24, 2026
Type to search.
    ↑↓ navigate↵ open