Planning · Free preview

Plan, Then Act

Decide the route first

Plan-execute splits the work in two: first build the complete plan (a list of actions) for the world, then run that plan against the world state step by step.

Plan, then act

In the last lesson you turned a goal into an ordered list of subtasks. The tempting next move is to interleave thinking and doing: decide one step, run it, look around, decide the next. That reactive loop feels efficient, but it has a nasty property — nobody can see the whole route until it's already half-executed. If the third action is wrong, you only find out after the first two already touched the world. You can't review a plan that doesn't exist yet.

Plan-execute splits the work cleanly in two. First the agent builds the complete plan — the full list of actions — without moving anything. Then a separate phase runs that fixed plan against the world state, one action at a time. The payoff: the plan becomes a concrete artifact you can inspect, log, cost-estimate, or hand to a human for approval before any irreversible thing happens. An agent about to send emails or spend money should show its route first.

Think of a robot on a number line, start 0, goal 4. The plan phase emits ["right","right","right","right"] — four actions derived purely from goal - start, with the robot still at 0. Only then does execution walk it: pos goes 1, 2, 3, 4, and you can verify the printed plan matches what actually happened. If they ever diverge, you have a bug you can see.

The starter leaves plan empty and the robot never moves. Fill the plan first — push one "right" for every step from start to goal — print it, then let the execute loop run it. Done means the printed plan has four rights and the final line reads pos=4, landing exactly on the goal.

Plan, then act: when the route is written down before you move, you can check it before you trust it.

In the full academy, you write and run this — live, graded:

// A tiny world: a robot on a number line.
const start = 0;
const goal = 4;

// 1) PLAN. Build the FULL route up front — one action per step.
// Push "right" into plan for each step needed to get from start to goal.
const plan = [];
// TODO: fill the plan here (do NOT move the robot yet).

console.log("plan: " + plan.join(","));

// 2) EXECUTE. Now run the plan against the world, one action at a time.
let pos = start;
for (const action of plan) {
  if (action === "right") pos += 1;
  if (action === "left") pos -= 1;
  console.log(`after ${action}: pos=${pos}`);
}

console.log(`final: pos=${pos} (goal ${goal})`);

🔒 Live code execution, real agent runs, mastery tracking and verifiable credentials unlock with the full academy.

This is 1 of 50 lessons.

The full academy: write real code, watch real agents run, and earn verifiable credentials — across 8 tracks, in a 3D campus.

Unlock the full academy — $100 →

14-day refund · 🔒 Stripe-secured checkout · lifetime access

More free lessons: An LLM Is a Function  ·  The Agent Loop  ·  Define a Tool  ·  Give an Agent a Tool  ·  Durable State

← The Agent Marketplace