[ ABORT TO HUD ]
SEQ. 1
SEQ. 2
SEQ. 3
SEQ. 4
SEQ. 5
Plan-and-Solve
Hierarchical Planning & Task Decomposition
While basic ReAct loops excel at short, reactive workflows (1 to 5 turns), they degrade rapidly on long-horizon objectives because error compounding and attention drift cause the agent to wander or get stuck in repetitive dead ends. Enter the Plan-and-Solve architecture.
The Three-Stage Plan-and-Solve Pattern
- Decomposition (Planner): Analyzes the macro objective, identifies edge-case dependencies, and constructs a Directed Acyclic Graph (DAG) or structured checklist of sub-tasks.
- Execution (Worker/Executor): Executes individual sub-tasks in isolation with dedicated tool bindings, keeping the worker's working context clean.
- Dynamic Replanning (Monitor): Intercepts tool execution outputs, marks milestones completed, and dynamically rewrites downstream steps when unexpected obstacles or new information emerge.
from typing import TypedDict, List
from langgraph.graph import StateGraph, END
class AgentPlanState(TypedDict):
objective: str
plan: List[str]
current_step: int
results: List[str]
def planner_node(state: AgentPlanState):
# Generates structured checklist from user objective
subtasks = [
"Clone repository & verify branch",
"Execute automated test suite",
"Extract stacktrace from failing unit test",
"Generate patch and verify fix"
]
return {"plan": subtasks, "current_step": 0}
def executor_node(state: AgentPlanState):
idx = state["current_step"]
step_desc = state["plan"][idx]
# Execute tool associated with step_desc...
return {"results": state["results"] + [f"Completed: {step_desc}"], "current_step": idx + 1}
def router_condition(state: AgentPlanState):
if state["current_step"] >= len(state["plan"]):
return END
return "executor"⌨ HANDS-ON LABDecompose Goal with Plan-and-Solve Prompting
⭐ +150 XPGenerate a structured multi-step execution plan and dispatch atomic subtasks to specialist executors.
1Execute planner decomposition script generating task JSON.
OBJECTIVE 1 / 1 — type "hint" if stuck
SYNAPSE VERIFICATION
QUERY 1 // 2
Why is the Plan-and-Solve architecture better than basic ReAct for complex goals?
It uses less tokens overall
It maintains an overarching checklist, preventing the agent from getting lost on long horizons
It allows the agent to bypass API rate limits
It executes tools twice as fast