Velamuvi AIAcademy

Lesson 1 of 5 · Planning

Task Decomposition

How AI agents break goals into steps: plan-then-execute vs step-by-step, plans as validated data with dependencies, parallel steps and a real LLM planner.

  • 8 min read
  • Advanced
  • Reviewed
In this lesson you will learn
  • Explain why agents break big goals into smaller steps
  • Compare planning everything up front with deciding one step at a time
  • Represent a plan as data with dependencies, and validate it in code
  • Work out which steps can run in parallel
  • Describe what makes a good step

Big goals need steps

“Organise a team offsite” isn't something an agent can do in one tool call. It's a dozen smaller jobs: find dates, get the budget approved, shortlist venues, book one, order food, send invitations. Some depend on others, and some don't.

Decomposition helps in three ways. Each small step is easier for a model to get right than the whole goal at once. Steps can be checked one at a time, so errors are caught early. And a written plan can be shown to a person, who can approve or adjust it before anything happens.

Plan first, or one step at a time?

Agents use two styles, and many combine them:

Plan-then-executeStep by step (ReAct-style)
HowA planner writes the whole plan; an executor carries it outThe agent decides only the next action, sees the result, then decides again
StrengthsPredictable, easy to review, steps can run in parallel, cheaper models can executeAdapts to surprises; good when you can't know the steps in advance
WeaknessesThe plan can go stale when something unexpected happensHarder to predict and review; can wander or loop
Good forWell-understood tasks: reports, bookings, data pipelinesExploration: debugging, research, open-ended questions

A common hybrid: plan up front, execute step by step, and replan when a step fails or the results change the picture (lesson 5).

A plan as data

When the planner is a model, ask for the plan as structured data, not prose. Then your code can check it before anything runs, and schedule it. Here a planner returned six steps for the offsite, each with a tool and the steps it needs:

Try it yourselfPython
import json

# What a planner model might return for: "Organise a one-day team offsite for 12 people in Lyon"
plan_json = """[
  {"id": 1, "step": "Collect dates everyone can make",      "tool": "send_poll",      "needs": []},
  {"id": 2, "step": "Get the budget approved",               "tool": "request_budget", "needs": []},
  {"id": 3, "step": "Shortlist venues near a train station", "tool": "search_venues",  "needs": [2]},
  {"id": 4, "step": "Book the venue",                        "tool": "book_venue",     "needs": [1, 3]},
  {"id": 5, "step": "Order lunch, noting diets",             "tool": "order_catering", "needs": [4]},
  {"id": 6, "step": "Send the invitation with the agenda",   "tool": "send_email",     "needs": [4, 5]}
]"""

ALLOWED_TOOLS = {"send_poll", "request_budget", "search_venues", "book_venue", "order_catering", "send_email"}

def validate(plan):
    ids = {s["id"] for s in plan}
    problems = []
    for s in plan:
        if s["tool"] not in ALLOWED_TOOLS:
            problems.append(f"step {s['id']}: unknown tool {s['tool']}")
        for n in s["needs"]:
            if n not in ids:
                problems.append(f"step {s['id']}: needs missing step {n}")
    return problems

def waves(plan):
    """Group steps into waves: every step in a wave only needs steps from earlier waves."""
    done, result, left = set(), [], list(plan)
    while left:
        ready = [s for s in left if set(s["needs"]) <= done]
        if not ready:
            raise ValueError("circular dependencies: no step can start")
        result.append(ready)
        done |= {s["id"] for s in ready}
        left = [s for s in left if s["id"] not in done]
    return result

plan = json.loads(plan_json)
print("Problems:", validate(plan) or "none")
for i, wave in enumerate(waves(plan), start=1):
    print(f"Wave {i}: " + " | ".join(f"{s['id']}. {s['step']}" for s in wave))

# A flawed plan: an unknown tool and two steps that wait for each other
bad = [
    {"id": 1, "step": "Pay the deposit", "tool": "pay_deposit", "needs": [2]},
    {"id": 2, "step": "Book the venue",  "tool": "book_venue",  "needs": [1]},
]
print("\nProblems:", validate(bad))
try:
    waves(bad)
except ValueError as e:
    print("Can't schedule:", e)

The validator catches the flawed plan's unknown tool before anything runs, and the scheduler refuses a plan whose steps wait for each other forever. For the good plan, the scheduler finds that collecting dates and getting the budget approved don't depend on anything, so they can start at the same time in wave 1. Everything else must wait for something before it.

A real planner

The planner is usually a strong model with a prompt listing the available tools and the exact output format:

import json
import anthropic

client = anthropic.Anthropic()          # reads ANTHROPIC_API_KEY from the environment

PLANNER_PROMPT = """You are the planner for an assistant that organises events.
Break the goal into 3 to 8 steps. Each step must be done with exactly one of these tools:
{tools}
Answer with JSON only: a list of objects with
  "id" (1, 2, 3...), "step" (what to do, in a few words),
  "tool" (one of the tool names above), "needs" (ids of steps that must finish first),
  "done_when" (how we can check the step succeeded).

Goal: {goal}"""

def make_plan(goal, tools):
    response = client.messages.create(
        model="MODEL_NAME",
        max_tokens=1000,
        messages=[{"role": "user", "content": PLANNER_PROMPT.format(goal=goal, tools="\n".join(tools))}],
    )
    plan = json.loads(response.content[0].text)
    problems = validate(plan)            # the validate() function from the demo above
    if problems:
        raise ValueError(f"Planner returned an invalid plan: {problems}")
    return plan

Two details matter. The prompt lists the only tools allowed, so the planner doesn't invent abilities the agent lacks. And each step gets a done_when field, so the executor (or a check in code) can tell whether it really succeeded.

What makes a good step

  • One action: a step should be one tool call or one clear piece of work. “Research and book a venue” is two steps.
  • Checkable: you can tell when it's done (“venue booked, confirmation number received”).
  • The right size: too coarse and the step is as hard as the goal; too fine and the plan becomes long, slow and expensive, with many chances to fail.
  • Honest about dependencies: if a step uses another step's result, say so; otherwise the scheduler may run it too early.

Common mistakes

Practice exercise

Turn a plan's dependencies into an order of execution that never starts a step before the steps it needs.

Your solutionPython
needs = {"A": [], "B": ["A"], "C": ["A"], "D": ["B", "C"]}    # step: the steps it waits for
done = set()
order = []

# Repeatedly pick the steps whose needs are all done (in alphabetical order),
# add them to order and to done, until every step is scheduled. Then print order.
Knowledge check

Which kind of task suits a plan-then-execute agent best?

Summary

  • Task decomposition splits a goal into small, checkable steps that respect dependencies.
  • Plan-then-execute is predictable and parallel; step by step adapts to surprises; many agents combine them.
  • Ask planners for structured plans, then validate tools and dependencies in code.
  • Steps with no dependencies between them can run in parallel waves.
  • Good steps are one action, checkable and the right size.

Next: reasoning before acting.

Finished reading? Tick it off to track your progress.