ProjekinAja. Agentic AI Stage 2 · How Agents Work Lesson 2.5
● Stage 2 · Lesson 2.5

Planning & Decomposition

Big goals are too big to do in one step. The skill that separates a capable agent from a flailing one is breaking a goal into a plan.

⏱ ~14 min read 🗺️ The map-making skill 🌳 Task trees

🎯 By the end you'll understand

Why a fuzzy goal must become concrete sub-tasks before an agent can act on it, the two main planning styles (plan-then-execute vs interleaved) and their trade-offs, how task trees and dependencies organize work, why agents re-plan when reality breaks an assumption, and the failure modes — over-planning, under-planning, and decomposition that doesn't add up to the goal.

KEY INSIGHTThe one idea to take away

An agent can't do a goal. It can only do the next small, concrete step. Planning is the work of turning a goal into a sequence of those steps.

"Plan my trip to Japan" is not something anyone — human or machine — can execute directly. There's no single button for it. What you can execute is "search flights from June 12–15," then "compare three hotels in Shibuya," then "book the cheapest refundable option." Decomposition is the act of breaking the impossible-to-do goal into do-able pieces. A great agent is, above all, a great decomposer.

🔑 Hold onto this

Tools (2.2) give an agent hands. The loop (2.1) gives it a heartbeat. Planning gives it a map — so each beat of the loop moves toward the goal instead of wandering. Without a plan, an agent is just a fast machine for getting lost confidently.

CORE CONCEPTWhy decompose at all

The problem is a mismatch of grain. A goal is coarse and fuzzy — "research and write a market summary." An action is fine and concrete — call web_search("EV market size 2026"). The agent's tools only operate at the fine grain. So something has to bridge the gap, translating the coarse goal into a chain of fine actions. That bridge is the plan.

Decomposition does three useful things at once:

Think of a good plan like a recipe. "Make dinner" is a goal; the recipe is the decomposition. The recipe is what lets you cook one concrete step at a time without holding the whole meal in your head at once — and it's what lets someone else check whether you're on track.

It's worth saying plainly what decomposition is not: it is not the agent secretly knowing the answer in advance. The agent doesn't have a hidden database of "how to plan a Tokyo trip." It's generating the plan on the fly from patterns it learned in training — which is exactly why a plan can be wrong, incomplete, or subtly off-goal. Decomposition is a skill the model performs, not a fact it looks up. Treat every plan as a draft to be checked, not gospel handed down.

📖 Decomposition

Decomposition is breaking a high-level goal into smaller sub-tasks that are concrete enough for an agent to act on directly — and that, taken together, actually accomplish the goal.

COMPARISONTwo ways to plan: upfront vs as-you-go

There are two broad styles for how an agent relates planning to acting. They're not religions — most real systems blend them — but understanding the pure forms makes the trade-off clear.

Plan-then-execute 📋Interleaved (plan-as-you-go) 🔁
Shapemake the whole plan first, then run every stepplan one step, act, look at the result, plan the next
Ties toa planning pass, then a quiet execution passthe agent loop you met in 2.1
Best whenthe world is predictable; steps are independentthe world is messy; later steps depend on what you learn
Strengthcheap, coherent, easy to review before runningadapts to surprises; recovers from bad assumptions
Weaknessbrittle — one wrong assumption breaks the restmore LLM calls, can lose the thread on long tasks
Analogyprinted itinerary you follow to the letterGPS that reroutes the moment you miss a turn

Plan-then-execute is efficient and legible: the agent thinks once, produces a numbered list, and a human (or a cheaper model) can run the list. It shines when steps don't surprise you — generating a report from known data, say. Its fragility is the flip side of its confidence: if step 2 returns something the plan didn't anticipate, steps 3–7 may now be nonsense, and the agent charges ahead anyway.

Interleaved planning folds planning into the loop. After each action the agent observes the result and decides the next step in light of it. This is the dominant pattern for capable modern agents because reality almost always differs from the plan. The cost is more model calls and a risk of "losing the plot" on very long tasks — which is exactly why memory (2.4) matters: it's how an interleaved agent remembers the goal and what it has already tried.

💡 The practical blend

Most strong agents do both: sketch a rough plan upfront (so there's a map and a checkpoint to approve), then execute it interleaved — treating each plan step as a goal to be re-examined, and re-planning when an observation contradicts the map. Plan loosely, hold it lightly.

FRAMEWORKTask trees and dependencies

Real plans aren't flat lists — they're trees. A sub-task can itself be too coarse to act on, so it gets its own sub-steps. "Book accommodation" splits into "set budget → shortlist three → book one." Decomposition is recursive: you keep splitting until every leaf is a single tool call away.

Steps also have dependencies — an ordering constraint where one step must finish before another can sensibly start. You can't book a hotel for specific dates before you've fixed the flight dates. Dependencies are why a plan is more than an unordered to-do list: they encode what has to be true before a step makes sense.

🎯 Plan a 3-day Tokyo trip 1 · Lock travel dates 2 · Book accommodation 3 · Plan daily itinerary then 2a · Set budget 2b · Shortlist 3 2c · Book one Step 2 depends on step 1: you can't book dates you haven't set. "Book accommodation" was too coarse — so it became its own little tree. Leaves (2a, 2b, 2c…) are concrete enough for a single tool call.
A task tree: the goal at the root, sub-tasks below, and sub-steps below those. Arrows are dependencies.
▸ Two relationships, don't confuse them

Parent → child means "is made of" (Book accommodation is made of 2a, 2b, 2c). Dependency (→) means "must come before" (dates before booking). A tree captures the first; arrows capture the second. A good plan needs both.

SEE ITGoal Decomposer

Pick a high-level goal. Press Decompose and watch the agent break it into a task tree, one node at a time — sub-tasks, sub-steps, and the dependency that orders them. Then press Inject a surprise to see a step fail and the agent re-plan by inserting a new sub-task.

🌳 Interactive · Goal → task tree

CORE CONCEPTRe-planning: when reality breaks the map

A plan is a set of bets about how the world will behave. "Book the 7:30 table" bets the table is available. "Use the API's /users endpoint" bets that endpoint exists. The moment an observation contradicts a bet — table's full, endpoint returns 404, the chosen hotel is sold out — the rest of the plan is built on sand.

A flailing agent ignores the contradiction and barrels on, executing steps that no longer make sense. A good agent does what you'd do: it notices the broken assumption and re-plans — revising the remaining steps, or inserting a new sub-task to handle the surprise. In the demo above, when a step fails, the agent doesn't abandon the goal; it splices in a recovery step and continues. That's adaptive planning, and it's only possible because the agent kept the goal in mind, not just the plan.

📖 Re-planning

Re-planning is revising the plan mid-execution because an observation contradicted an assumption it was built on. It's the difference between following a map and following the territory — the loop (2.1) is what makes it possible to do it every step.

Notice the connection: interleaved planning and re-planning are two views of the same habit — re-examining the plan after every observation. Plan-then-execute systems struggle here precisely because they committed to the whole plan before seeing any results.

PRACTICALHow the LLM actually does this

There's no separate "planner module" bolted onto the model. The plan comes out of the same thing every agent output does — the LLM generating tokens. We just prompt it to plan before it acts. Two patterns dominate:

So the same instinct — "say what you'll do before you do it" — is both a planning technique and a reasoning technique. That's why this lesson hands off directly to the next one.

A worked example ties it together. Take the goal "research and write a market summary." Prompted to think step by step, a capable agent might emit: (1) define scope — which market and timeframe; (2) gather data — search for market size, then key players; (3) write the summary synthesizing the findings; (4) review every claim for a source. Notice three things baked into that list. It's a tree: step 2 has its own sub-steps. It has dependencies: you can't write (3) before gathering (2), and can't search well before scoping (1). And it sums to the goal: a write step exists, so the leaves actually produce a summary. If step 2 then returns "no reliable figure for that scope," the agent re-plans — inserting "estimate from adjacent data, labeled as an estimate" rather than fabricating a number. That single example contains every idea in this lesson; the demo above lets you run it live.

💡 You can do this in your prompts

Even with a plain chatbot, asking "before you answer, list the sub-tasks and their order" often produces visibly better results — because you've forced decomposition. You're doing the agent's planning step by hand. (More on briefing agents this way in Lesson 3.2.)

WEAKNESSCommon mistakes to avoid

✗ Over-planning

Spending ten reasoning steps mapping out a task that needed two actions. Elaborate plans for trivial goals waste tokens, money, and time — and add places to go wrong. Match the plan's depth to the goal's difficulty; a one-step task needs no tree.

✗ No re-planning (following a dead map)

Committing to the upfront plan and executing it even after an observation has made later steps nonsense. The booking failed but the agent still "confirms the reservation" in step 5. A plan you never revise is a script, not a strategy.

✗ Decomposition that doesn't add up to the goal

The most dangerous one: sub-tasks that are each fine but, summed, don't accomplish the actual goal. "Write a market summary" decomposed into "find the market size" + "find two competitors" — and no step that writes the summary. Always check: do the leaves, completed, equal the goal?

KEY INSIGHTWhere this connects in your course

  • The agent loop (2.1) — interleaved planning and re-planning are the loop, applied to the plan itself: act → observe → revise the next step.
  • Memory (2.4) — what lets a long-running plan stay on track: the agent remembers the goal, the plan, and what it has already tried.
  • Reasoning (2.6) — the very next lesson. "Think step by step" is how the LLM produces a plan; planning and reasoning are the same skill seen twice.
  • Multi-Agent Systems (2.7) — a big plan can be split across several specialized agents, each owning a sub-task; decomposition is what makes that division of labor possible.
  • Delegation (3.5) — a written plan is exactly the checkpoint where a human reviews and approves work before delegating the next step, especially before anything irreversible happens.

Hold the picture: a goal is too coarse to do, tools are too fine to aim, and planning is the bridge — built as a tree, ordered by dependencies, and revised the moment reality disagrees.

GLOSSARYKey terms introduced

Decomposition
Breaking a high-level goal into smaller sub-tasks concrete enough to act on.
Sub-task
A smaller piece of a goal; a node in the plan. May split further into sub-steps.
Task tree
A plan organized hierarchically: goal at the root, sub-tasks and sub-steps below.
Dependency
An ordering constraint — one step must finish before another can sensibly begin.
Plan-then-execute
Making the full plan upfront, then running every step without revising.
Interleaved planning
Planning one step, acting, observing, then planning the next — folded into the loop.
Re-planning
Revising the plan mid-execution because an observation broke an assumption it relied on.

ACTIVE RECALLCheck your understanding

Answer in your own words first, then reveal.

1Why can't an agent just "do" a high-level goal directly?›

Because of a grain mismatch: a goal is coarse and fuzzy ("plan my trip"), but the agent's tools only act at a fine, concrete grain ("search flights for these dates"). Decomposition bridges that gap — turning the goal into a chain of actions the tools can actually perform.

2What's the core trade-off between plan-then-execute and interleaved planning?›

Plan-then-execute is cheap, coherent, and easy to review — but brittle: one wrong assumption breaks every later step. Interleaved planning adapts to surprises by re-planning after each observation, at the cost of more model calls and the risk of losing the thread on long tasks. Most real agents blend them: sketch a rough plan, then execute it interleaved.

3What is re-planning, and what triggers it?›

Re-planning is revising the remaining plan mid-execution. It's triggered when an observation contradicts an assumption the plan was built on — the hotel's sold out, the endpoint 404s. A good agent inserts a recovery step or revises the path instead of barreling ahead on a dead map.

4What's the single most important check on a decomposition, and why?›

Ask: do the completed leaves actually equal the goal? It's easy to produce sub-tasks that are individually fine yet don't sum to the goal — e.g. a "write a market summary" plan with research steps but no step that writes the summary. A decomposition that doesn't add up to the goal fails silently, which is what makes it the most dangerous mistake.

You can break a goal into a plan. Next: how the LLM reasons its way through it →