All posts
agentsplanning

AI Agent Planning: A Practical Guide for Full-Stack Developers

A practical guide to planning strategies for AI agents — decomposing tasks, plan-and-execute patterns, and handling replanning.

SR

Suhail Roushan

August 6, 2026

·
5 min read
·
0 views

An agent that decides its next action one step at a time, with no upfront plan, can wander — taking a locally reasonable step that doesn't actually serve the overall goal — and planning is the mechanism for giving an agent enough foresight to avoid that without removing all its ability to adapt.

AI agent planning means having a model decompose a goal into a sequence of steps before (or interleaved with) execution, rather than deciding purely reactively one action at a time — ranging from a simple upfront plan-then-execute pattern to more sophisticated approaches that replan as new information emerges during execution.

Why Agent Planning Matters (and When Reactive Step-by-Step Suffices)

Planning matters for tasks with real structure worth reasoning about upfront — a multi-step task where getting the order or dependencies wrong wastes significant work, or where an explicit plan makes the agent's approach reviewable before execution starts (useful for higher-stakes tasks where a human wants to approve the plan first).

Purely reactive step-by-step decision-making suffices for simpler tasks, or exploratory tasks where the right next step genuinely depends entirely on what the previous step revealed and can't be usefully planned in advance — for those, upfront planning adds overhead without benefit, since the plan would likely need to be discarded after the first step anyway.

Getting Started with AI Agent Planning

A plan-then-execute pattern, generating an explicit plan before acting:

async function planAndExecute(goal: string) {
  const planResponse = await model.generate({
    messages: [{ role: "user", content: `Break this goal into a sequence of concrete steps: ${goal}` }],
  });
  const steps = parseSteps(planResponse.text);

  const results = [];
  for (const step of steps) {
    const result = await executeStep(step, results);
    results.push(result);

    if (result.requiresReplanning) {
      const newSteps = await replan(goal, results);
      return planAndExecute2(newSteps, results);
    }
  }
  return results;
}

A simpler reactive loop, deciding one step at a time without an explicit upfront plan:

async function reactiveLoop(goal: string) {
  const history = [];
  while (true) {
    const nextAction = await model.generate({
      messages: [{ role: "user", content: `Goal: ${goal}\nHistory: ${JSON.stringify(history)}\nWhat's the next action?` }],
    });
    if (nextAction.isDone) return history;
    const result = await executeAction(nextAction);
    history.push({ action: nextAction, result });
  }
}

Core AI Agent Planning Concepts Every Developer Should Know

An explicit upfront plan makes an agent's intended approach reviewable before execution, which matters for higher-stakes tasks where a human wants to approve the general approach before the agent starts taking actions — this is a real advantage over purely reactive agents, where there's no plan to review since decisions are made one at a time as execution proceeds.

Replanning handles the reality that an upfront plan can become wrong as execution reveals new information — a step failing unexpectedly, or an early step revealing the task is different than assumed. A planning system needs an explicit mechanism to detect when the current plan is no longer valid and generate a revised one, rather than rigidly continuing an outdated plan.

Plan granularity is a real design choice. A very detailed plan (specifying exact tool calls) is easier to review but more brittle to unexpected results; a coarser plan (specifying goals for each step, with details decided at execution time) is more adaptable but harder to fully review upfront. The right granularity depends on how much foresight versus adaptability the task actually needs.

Reactive, step-by-step decision-making without upfront planning is simpler to implement and handles genuinely unpredictable tasks well, but risks locally-reasonable steps that don't serve the overall goal well, especially on longer tasks where early missteps compound.

Common Mistakes With AI Agent Planning and How to Fix Them

Mistake 1: generating an overly detailed upfront plan for a task with real uncertainty, then rigidly following it even as execution reveals the plan doesn't fit reality. Fix: build in explicit replanning triggers rather than treating the initial plan as fixed.

Mistake 2: using purely reactive step-by-step decisions for a task with genuine multi-step structure worth reasoning about upfront, risking locally reasonable but globally misdirected actions. Fix: use plan-then-execute for tasks where upfront decomposition provides real value, reserving purely reactive loops for genuinely unpredictable tasks.

Mistake 3: no mechanism to detect when a plan should be revised, continuing to execute an outdated plan after execution has revealed it no longer fits. Fix: check plan validity after unexpected step results and trigger replanning explicitly rather than assuming the original plan still applies.

When Should You Use Plan-Then-Execute Instead of a Purely Reactive Loop?

Use plan-then-execute for tasks with real multi-step structure where upfront decomposition provides genuine value, or where a reviewable plan matters for higher-stakes tasks. Use a purely reactive loop for tasks where the right next step genuinely can't be usefully predicted in advance — exploratory tasks, or ones where execution results at each step meaningfully change what should happen next.

AI Agent Planning in Production

Build explicit replanning into any plan-then-execute system, since a rigid plan that ignores unexpected execution results is often worse than no plan at all. Choose plan granularity deliberately based on how much foresight the task genuinely benefits from versus how much adaptability it needs, and make plans reviewable for any higher-stakes task where a human checkpoint before execution adds real value.

If you're deciding between planning approaches, consider whether the task's steps are knowable enough upfront to benefit from a reviewable plan — if yes, plan-then-execute with replanning; if the task is genuinely too unpredictable to plan usefully, a reactive loop will serve better.

Related posts

Written by Suhail Roushan — Full-stack developer. More posts on AI, Next.js, and building products at suhailroushan.com/blog.

Get in touch