Overview
ThePlannerEngine implements a two-phase reasoning approach: first create a structured plan as a list of subtasks, then execute each task sequentially. This is ideal for complex requests that benefit from upfront decomposition.
When to Use
UsePlannerEngine when:
- Tasks are complex and benefit from upfront planning
- You want to see the full plan before execution begins
- Subtasks have dependencies (some must complete before others)
- You need structured, observable task breakdowns
- You want to enable replanning on task failures
Constructor
Configuration
Maximum steps allowed during plan execution across all tasks.
Whether to re-plan mid-execution if a task fails. When
false, the engine throws an error on task failure.Custom system prompt for the planning phase. Should instruct the model to output a JSON array of tasks with
id, description, and dependsOn fields.Custom system prompt for the execution phase. Should instruct the model to complete individual subtasks.
Usage Example
How It Works
Phase 1: Planning
- Model receives the user request with available tools context
- Model produces a JSON array of subtasks:
- Plan is validated and emitted as a
PlanStep
Phase 2: Execution
- Tasks are executed in dependency order
- Each task:
- Receives context from completed dependencies
- Can make tool calls (with its own mini ReAct loop)
- Marks itself as
done,failed, orin_progress
- Results are accumulated in a task results map
Phase 3: Synthesis
- All task results are combined
- Model synthesizes a final coherent answer
- Result is returned to the user
Plan Task Schema
Each task in the plan has:Step Emissions
- PlanStep: Emitted after planning phase with full task list
- ThoughtStep: Emitted at the start of each task execution
- ToolCallStep / ToolResultStep: Emitted during task tool usage
- ResponseStep: Emitted with the final synthesized answer
Error Handling
Max execution steps exceeded:Default Planner Prompt
String Alias
Implementation Reference
Source:packages/reasoning/src/engines/planner.ts:70