Yashotantra Academy logo
level 1
Curious · 0 XP
streak
0d
perfect
0
badges
0

100 XP to Apprentice

Patterns · easy

4. Planner-executor separation

One model call makes a plan; cheaper calls execute the steps.

1 min read2 questionsup to 50 XPtopic 4/14

Read in another language

AI translates the explanation and quiz text while preserving code and answer scoring.

For multi-step work, splitting planning from execution improves both cost and debuggability. A strong model writes a typed plan once; a cheap model (or plain code) runs each step.

ts
const Plan = z.object({
  steps: z.array(z.object({
    id: z.string(),
    tool: z.enum(["search", "fetch_page", "summarize"]),
    args: z.record(z.string()),
    depends_on: z.array(z.string()).default([]),
  })),
});

const plan = Plan.parse(await planWithStrongModel(goal));      // one expensive call
const done: Record<string, unknown> = {};

for (const step of topoSort(plan.steps)) {                     // deterministic execution
  done[step.id] = await tools.run(step.tool, resolve(step.args, done));
}

Benefits: the plan is inspectable before anything runs, steps without dependencies run in parallel, and a failed step can be retried without re-planning the whole task.

When not to use it: highly interactive tasks where each result changes the goal. There, a plain ReAct loop adapts better than a frozen plan. A common hybrid is *re-plan after every N steps*.

Exercise: add `depends_on` handling and run independent steps with `Promise.all`. Measure wall time against the sequential version.

How to study this topic

  1. 1. Read the explanation once end to end, skipping the code.
  2. 2. Re-read the code snippets and say out loud what each line does.
  3. 3. Answer the quiz without scrolling back — that is the real check.
  4. 4. Read every explanation, even for the answers you got right.

Scoring

  • · Up to 30 XP from quiz accuracy.
  • · +15 XP for a perfect first attempt.
  • · +5 XP while a 3-day streak is running.
  • · 75% or higher marks the topic complete.

Check your understanding

  1. 1. Main advantage of a separate planning step?

  2. 2. When is a frozen upfront plan a poor fit?

Badges

First light
Pass your first topic
Sharp shooter
3 perfect first-try quizzes
On a roll
Study 3 days in a row
Week warrior
Study 7 days in a row
Grinder
Earn 500 XP
Deep diver
Earn 1500 XP