Planner and Executor Pattern: Separate Planning from Doing

JS
Jai Singh
16 Nov, 2026 4 min read 22 views

In the planner-executor pattern, one agent writes a step-by-step plan and a second agent carries out each step. The planner thinks about the whole task without being distracted by tool output. The executor focuses on one step at a time with a small context. This separation makes long tasks more predictable and makes the plan visible, so people can review it before anything runs.

How it differs from orchestrator-worker

The two patterns look alike. In orchestrator-worker, subtasks are usually independent and run in parallel, and the orchestrator merges answers. In planner-executor, steps are usually ordered, each step may depend on earlier ones, and the output of the process is an action or a final artifact. The planner does not do the work; the executor does not decide the strategy.

Benefits

  • Reviewable plan. You can show the plan to a user or run checks on it before spending money on execution.
  • Smaller contexts. The executor sees the current step and relevant results, not the entire reasoning history.
  • Model mix. Use a stronger model to plan and a faster one to execute routine steps.
  • Easier recovery. If step 4 fails, you retry step 4, not the whole task.

A working example

The planner returns a JSON list of steps. The executor runs each step, receiving the results of earlier steps as context. If a step reports failure, the planner is asked to revise the remaining plan.

import json
import re
import anthropic

client = anthropic.Anthropic()

def call(system, user, model="claude-sonnet-5-5"):
    r = client.messages.create(model=model, max_tokens=3000, system=system,
                               messages=[{"role": "user", "content": user}])
    return "".join(b.text for b in r.content if b.type == "text").strip()

PLANNER = ("You write plans. Given a goal and any progress so far, return a JSON array "
           "of 3 to 6 short, concrete steps still to do. Reply with JSON only.")
EXECUTOR = ("You carry out exactly one step. Use the earlier results if they help. "
            "Reply with the result of the step. If you cannot do it, start your reply with FAILED:")

def make_plan(goal, progress=""):
    text = call(PLANNER, "Goal: " + goal + "\nProgress so far:\n" + (progress or "none"))
    match = re.search(r"\[.*\]", text, re.DOTALL)
    return [str(s) for s in json.loads(match.group(0))] if match else [goal]

def run(goal, max_replans=2):
    done = []   # list of (step, result)
    plan = make_plan(goal)
    replans = 0
    while plan:
        step = plan.pop(0)
        context = "\n".join("- " + s + " => " + r for s, r in done) or "none"
        result = call(EXECUTOR, "Goal: " + goal + "\nEarlier results:\n" + context
                      + "\nCurrent step: " + step)
        if result.startswith("FAILED:") and replans < max_replans:
            replans += 1
            progress = context + "\nFailed step: " + step + " (" + result + ")"
            plan = make_plan(goal, progress)
            continue
        done.append((step, result))
    return done

for step, result in run("Outline a blog post about Python virtual environments"):
    print("STEP:", step, "\nRESULT:", result[:200], "\n")

The output shows each planned step and a truncated result. The FAILED: prefix is a simple protocol: the executor reports failure in a form code can detect, and the planner gets a chance to change the remaining steps.

Replanning rules

  • Cap replans. Without a cap, a hard task loops forever.
  • Give the planner the failure reason, not just "it failed".
  • Keep completed steps; only replace the remaining ones.
  • For safety-critical work, ask for human approval of the plan before the first execution.

When not to use it

For short tasks, planning is overhead. A single agent that thinks and acts in one loop is faster. Planner-executor pays off when tasks have five or more steps, when steps are expensive or irreversible, or when someone needs to approve the approach. Be aware that a plan written up front can be wrong, since the planner cannot see what the executor will discover. That is why replanning matters.

Plan quality matters most

In this pattern, the plan is the single biggest lever on the result. A vague step such as "handle the data" gives the executor too much freedom, and a step list that skips a necessary action produces a confident but incomplete outcome. Ask the planner for steps that are concrete, verifiable and small enough for one executor call. Good steps start with a verb and name their output: "List the three main sections of the post", not "think about structure". You can even add a plan-review step where a critic agent checks the plan for missing steps before execution begins.

Giving the executor tools

The example executor is a plain model call, but in real systems it often has tools: file access, a code runner, search. Keep those tools on the executor only. The planner does not need them, and withholding them keeps its context clean and its behaviour focused on strategy. If the plan needs information that only a tool can provide, make "look up X" an explicit first step rather than letting the planner guess.

Passing results forward

The code above passes every earlier result to each step. For long runs, that grows without bound. Pass only what the current step needs, or summarise earlier results as the run proceeds. A simple approach is to have each step declare in the plan which earlier steps it depends on, then include only those results in the executor's prompt. That also prepares you for running independent steps in parallel, which a later post on task dependency graphs covers.

Was this article helpful?

Comments

No comments yet. Have a question or a tip? Be the first to share it.

Leave a comment

Comments are reviewed before they appear.