Lesson 3: Decomposing a Complex Task into a Workflow
Learning goals:
- Master the three task-decomposition strategies
- Identify dependencies between tasks
- Turn a decomposition into an executable workflow
Prerequisites: Lesson 2: Workflow Building Blocks: Steps, State, Branches, Loops | Next: Lesson 4 >>
From "I don't know where to start" to clear steps
A task lands on your desk: "Split our monolithic Rails app into a microservices architecture." That's a complex task. You don't know where to begin, how many steps it takes, or what each step does.
Task decomposition is how you take a vague, oversized task and break it into small, clear steps.1
A good decomposition meets three standards:
- Each subtask is small enough to finish in a single agent call or function.
- Dependencies between subtasks are explicit — you know which must run in order and which can run in parallel.
- Each subtask has clear inputs and outputs — one step's output can feed directly into the next.
Decompose well and writing the workflow feels like snapping Lego together. Decompose badly and you'll discover, mid-execution, that steps are missing, the order is wrong, or data won't flow through.2
Strategy 1: Sequential Decomposition
When to use it: the task has a clear front-to-back order, and each step depends on the result of the one before it.
How: work backward from the end. Ask "what input does this step need? Where does that input come from?"
Example: generating technical docs
Task: generate user-facing docs for an API.
Backward decomposition:
Turned into a workflow:
Dependency chain:
Can step 2 run in parallel with step 1? No — step 2 needs step 1's endpoints.
Can step 3 run in parallel with step 2? No — step 3 needs step 2's examples.
What sequential decomposition is like: a long dependency chain, few chances to parallelize, but the logic is clear.3
Strategy 2: Parallel Decomposition
When to use it: the task splits into several independent subtasks that don't depend on each other.
How: spot the "do Y for every X" pattern — each X can be processed in parallel.
Example: security-auditing a codebase
Task: audit 100 files for security issues.
Parallel decomposition:
Shape:
Fan-out-reduce pattern: this is the most common shape for parallel decomposition.4
- Fan out: spread the task across many parallel agents.
- Reduce: merge every result into a final output.
The power of parallel decomposition: 100 files, 2 minutes to audit each. Sequential execution takes 200 minutes; parallel execution takes 2 (assuming no resource limits).
Strategy 3: Hybrid Decomposition
When to use it: most real tasks. Some parts run in parallel, some must run in order.
How: first find the high-level phases (which must run in order), then find the parallel opportunities inside each phase.
Example: a large-scale refactor
Task: upgrade 50 components from Vue 2 to Vue 3.
Hybrid decomposition:
Turned into a workflow:
Dependency graph for the hybrid:
The heart of hybrid decomposition: keep the ordering you truly need while squeezing out every chance to parallelize.3
Using an LLM to help you decompose
You can also hand the decomposition to an LLM. Three ways all work: zero-shot prompting, chain-of-thought prompting, and few-shot (example-guided) prompting.1
Zero-shot
Chain-of-thought
Few-shot
The upside of LLM decomposition: it drafts a first plan fast and catches steps you might have missed.
The downside of LLM decomposition: it can stay too abstract (say "analyze the data" instead of "compute the cyclomatic complexity of each file"), so it needs a human to sharpen it.1
Practical tips for spotting dependencies
Tip 1: ask "could this step run before the first one?"
If the answer is "yes," they can run in parallel. If it's "no, it needs the first step's result," there's a dependency.
Tip 2: draw the dependency graph
Can step 2 and step 3 run in parallel? Yes — both depend only on step 1.
Can step 3 and step 4 run in parallel? No — step 4 depends on step 2.
A graph where arrows mean dependency and never loop back to the start has a formal name: a DAG (directed acyclic graph). Step 1 depends on nothing, so it's a leaf the graph can run first. Ordering every step so you never violate an arrow's direction is called a topological sort.
Tip 3: check the data flow
List each step's input and output:
If step X's input comes from step Y's output, X depends on Y.
Common decomposition mistakes
Mistake 1: steps that are too big
What does "prepare the data" cover? Read files? Parse config? Connect to a database? Too vague.
Mistake 2: no error-handling steps
What if step 2 fails? Service A is already deployed but B isn't, and the system is in an inconsistent state.
Mistake 3: ignoring parallel opportunities
This processes each service one at a time. Slow.
Next: Lesson 4: State Management and Passing Context — learn how to pass and manage data correctly between the steps of a workflow.