Module 4 · Lesson 2 · 15 min read

Breaking tasks down into steps

Task Decomposition

Introduction

A big task seems impossible until it is divided. Task decomposition is the skill that turns a goal such as "Write a report on the job market" into small steps, each with inputs, outputs and a completion criterion. In this lesson we learn decomposition strategies, how to represent dependencies, and how to order execution automatically.

Learning objectives

  • Apply hierarchical decomposition of a compound goal into subtasks
  • Identify the dependencies between tasks and represent them as a directed acyclic graph
  • Write a clear, checkable completion criterion for each subtask
  • Compute a valid execution order and detect tasks that can run in parallel

Why do we break tasks down?

A language model works better when what is asked of it is specific and small. Asking it to "Write a comprehensive report on the job market for programmers" in a single step pushes the model towards general, superficial text. But if we break the request down into: gathering sources, extracting the required skills, classifying them, then writing each section, every step becomes possible to master and to check.

The Plan-and-Solve paper (Wang and colleagues, 2023) proposes a similar idea: the model first makes a plan that divides the task into subtasks, then carries them out, instead of jumping straight to the answer. Anthropic's guide describes a pattern it calls "orchestrator-workers", in which a central model breaks down the task dynamically and distributes it.

Main goalAnalyze the sales, then write a report1. Read the datadata_reader2. Compute the indicatorssummarizer3. Interpret the resultstext_analyzer4. Write the reportoutputCheck that the plan succeededSuccess Criteria
Task decomposition: a main goal turns into ordered subtasks, each with a tool and a success criterion.

Decomposition strategies

  • Hierarchical decomposition: we divide the goal into subgoals, and each subgoal into smaller tasks, until we reach tasks that a single tool or a single model call carries out.
  • Sequential decomposition: a chain of stages, each feeding the next, such as: collect, then clean, then analyze, then write.
  • Parallel decomposition: independent tasks that can be run at the same time, such as searching three different sources.

In practice most plans combine all three: a hierarchical tree in which some branches are sequential and some are parallel.

Dependencies and completion criteria

For each subtask we need to know two things:

  1. Dependencies: which tasks must be complete before it? We represent this as a directed acyclic graph (DAG), and a cycle in it means an impossible plan.
  2. Completion criterion: how do we know the task is complete? "Gather sources" is a weak criterion, while "a list of at least five sources, each with a title, a link and a date" is a checkable criterion.

A practical example: a job market report

The goal: "A two-page report on the skills required of beginner AI developers." The decomposition:

IDTaskDepends onCompletion criterion
ADefine the report's scope and questions—Three written research questions
BCollect job ads from the databaseAAt least 20 ads
CCollect summaries of career guides from the knowledge baseAAt least 5 summaries
DExtract the skills and their frequencyB, CA table of skill and number of occurrences
EWrite the reportDTwo pages that answer the three questions

Notice that B and C are independent, so they can be run in parallel, while D waits for both.

Ordering execution automatically

Once we represent the dependencies clearly, the code can compute a valid order and the groups of parallel tasks, and detect cycles. The following example in plain Python applies Kahn's algorithm for topological sorting by levels:

python
tasks = {
    "A": [],
    "B": ["A"],
    "C": ["A"],
    "D": ["B", "C"],
    "E": ["D"],
}

def execution_waves(tasks: dict) -> list:
    remaining = {t: set(deps) for t, deps in tasks.items()}
    for t, deps in remaining.items():
        missing = deps - set(tasks)
        if missing:
            raise ValueError(f"{t} depends on tasks that do not exist: {missing}")
    waves = []
    while remaining:
        ready = sorted(t for t, deps in remaining.items() if not deps)
        if not ready:
            raise ValueError(f"A cycle in the dependencies between: {sorted(remaining)}")
        waves.append(ready)
        for t in ready:
            del remaining[t]
        for deps in remaining.values():
            deps.difference_update(ready)
    return waves

for i, wave in enumerate(execution_waves(tasks), 1):
    print(f"Wave {i}: {wave}")

try:
    execution_waves({"X": ["Y"], "Y": ["X"]})
except ValueError as e:
    print("Error:", e)

The program prints four waves: A, then B and C together, then D, then E, and detects the cycle in the last example. This simple step protects the agent from running a task before its inputs are available.

Where is the plan stored?

In long tasks the context window is not enough to hold the plan and its status. It is better to store it in an external store such as a task_manager tool that updates the status of each task: pending, in progress, completed, failed. This links planning with what you studied in the memory module.

Summary

Task decomposition turns a big goal into small subtasks that can be carried out and checked. Decomposition can be hierarchical, sequential or parallel, and often a mix of these. Each task has dependencies represented as a directed acyclic graph and a checkable completion criterion. Topological sorting determines a valid order and reveals parallel tasks and cycles, and any generated plan must be checked before execution.

Terms

TermEnglishDefinition
Task decompositionTask DecompositionDividing a compound goal into smaller subtasks
DependencyDependencyA relationship that requires one task to be complete before another starts
Directed acyclic graphDAGA representation of dependencies that contains no cycles
Topological sortTopological SortAn order that runs each task after all its dependencies
Completion criterionDone CriterionA checkable standard that determines when a task is complete
Orchestrator and workersOrchestrator-WorkersA pattern in which a central component breaks down the task and distributes it to executors

Review questions

  1. Break down the goal "Organize a university programming contest" into five subtasks with their dependencies.
  2. Why is "Gather sources" a weak completion criterion? Rewrite it.
  3. What does a cycle in the dependency graph mean, and how do you detect it automatically?
  4. When does decomposition become excessive, and what is its effect on cost?

References