What planning strategies do agents use?
Learning path, stage 4 of 5: Agents, tools and MCP · question 8 of 10Agents plan either step by step (ReAct: decide one action at a time) or up front (plan-and-execute: write a full plan, then carry it out, re-planning when something fails). For harder problems, search-based methods like Tree of Thoughts explore and score several branches. In practice, modern reasoning models plan internally, and what you add is structure: todo lists, checkpoints and verification.
Strategies
- Step by step (ReAct): flexible, adapts to each observation, but can wander.
- Plan-and-execute / Plan-and-Solve: clear structure, cheaper executor steps, easier to show to users. Needs re-planning when the world doesn't match the plan.
- Decomposition: break the goal into sub-goals, recursively if needed.
- Tree of Thoughts: generate several candidate thoughts, evaluate them, search (BFS/DFS), backtrack.
- Reflection: criticise the plan or result and revise it.
Practical tips
- Keep the plan as an editable artefact (a todo list in context or in a file) that the agent updates as it goes.
- Show the plan to a person before expensive or risky execution.
- Add checks after each step: tests pass, the API returned 200.
Sources
Code example
1// Plan-and-execute with re-planning on failure.2interface Step { id: number; description: string; done: boolean }34declare function makePlan(goal: string): Promise<Step[]>;5declare function execute(step: Step): Promise<{ ok: boolean; output: string }>;6declare function replan(goal: string, steps: Step[], failure: string): Promise<Step[]>;78export async function planAndExecute(goal: string, maxReplans = 2) {9 let steps = await makePlan(goal);10 let replans = 0;11 const log: string[] = [];1213 while (steps.some((s) => !s.done)) {14 const step = steps.find((s) => !s.done)!;15 const result = await execute(step);16 log.push(`#${step.id} ${step.description}: ${result.output}`);1718 if (result.ok) step.done = true;19 else if (replans++ < maxReplans) steps = await replan(goal, steps, result.output);20 else throw new Error(`Failed at step ${step.id}: ${result.output}`);21 }22 return log;23}
To run it: follow the one-time setup guide, add npm i @anthropic-ai/sdk zod @modelcontextprotocol/sdk, save the code as a .ts file and run npx tsx file.ts. Anything marked declare is a part you supply.
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the AI Agents & LLMs set.