# Planner-Executor Agent

> Split a task into an explicit plan, execute steps one at a time, and re-plan only when a step fails.

Category: AI Agent Workflows  
Tags: planning, decomposition, multi-step  
Setup time (estimate): 2-4 hours  
Estimated cost: One planning call plus one call per step; replanning adds more.  
Last verified: not yet independently verified

Separating planning from execution makes long tasks more reliable and cheaper: a strong model plans once, a cheaper model can execute individual steps.

## Steps

1. **Plan**: ask the planner model for a JSON list of steps, each with `id`, `goal`, and `done_when`.
2. **Execute**: for each step, give the executor only the overall goal, the current step, and results of prior steps.
3. **Check**: verify the step against `done_when` (programmatically where possible).
4. **Re-plan**: on failure, send the plan, completed results, and the error back to the planner for a revised remaining plan.
5. **Finish**: synthesize a final answer from step results.

## Planner prompt

```text
You are a planner. Break the user's goal into 3-8 sequential steps.
Return ONLY JSON: {"steps":[{"id":1,"goal":"...","done_when":"..."}]}
Each step must be independently executable and verifiable.
Do not include steps that require information the user has not provided
unless a tool can obtain it. Goal: {{goal}}
```

## Control flow

```yaml
max_replans: 2
planner_model: strong-reasoning-model
executor_model: fast-cheap-model
on_step_failure: replan
on_replan_exhausted: return_partial_with_error
```

## Failure modes

- Plans that are too coarse or too fine waste steps; tune step granularity.
- Executor failures without replanning leave tasks half done.
- Unbounded replanning loops; cap replans.
