A\
Lessons/Domain 1
1.612 min

Design task decomposition strategies for complex workflows

Complex work rarely fits reliably into one prompt. Choosing how to break a task into pieces, a fixed sequential chain versus a plan that adapts to discoveries, is what separates a system that produces consistent, complete output from one that gives contradictory, superficial results. In production this decision drives review quality, test coverage, and whether large investigations actually finish the job.

Prompt chaining (fixed)subtasks known up front, predictableDynamic decompositionsubtasks emerge from findingsre-planPer-file pass: A.tsPer-file pass: B.tsPer-file pass: C.tsCross-file integration passMerged reviewMap codebase structureIdentify high-impact areasPlan subtasks from findingstest coreedge casestrace depsLeft: fixed sequence. Right: plan adapts as new dependencies surface.
Prompt chaining (fixed, enumerable steps) versus dynamic decomposition (plan adapts as dependencies surface).

Two ways to break down a big task

A complex workflow usually exceeds what a single model call can handle with uniform quality. There are two decomposition strategies, and picking the right one is the core skill this task tests.

Fixed sequential decomposition, also called prompt chaining, predefines the steps. Each step's output feeds the next, and the sequence is identical on every run. You use it when you already know, before execution starts, which aspects the work has to cover.

Dynamic (adaptive) decomposition generates the subtasks at runtime based on what earlier steps discover. The plan is not written in advance, it emerges. You use it when the shape of the work depends on what you find. The deciding question is simple: can you enumerate the subtasks up front? If yes, chain them. If the subtasks only become knowable after exploring, decompose adaptively.

Prompt chaining for predictable multi-aspect work

In prompt chaining you split a task into a fixed pipeline of narrow, well-defined steps. Each call handles one subtask and passes structured output to the next. Because every step gets a clean, focused context, per-step accuracy rises and each stage is easy to test and debug in isolation.

The canonical pattern for code review is: analyze each changed file individually for local issues (a per-file pass), then run a separate cross-file integration pass that examines how the files interact. Splitting this way avoids attention dilution and prevents the contradictory verdicts you get when everything competes for attention in one prompt.

# Fixed pipeline: each step feeds the next
for f in changed_files:
    local[f] = review_file(f)          # per-file pass
integration = review_cross_file(local)  # cross-file pass
report = merge(local, integration)

Chaining suits any workload whose facets are known in advance: extract then validate then format, or review for correctness, then security, then style as distinct passes. The trade-off is added latency from sequential calls, which is acceptable given the reliability gain. Note that chaining is sequential and single-line; it is not the same as a coordinator fanning work out to parallel subagents.

Dynamic adaptive decomposition for open-ended work

When you cannot know the structure up front, the plan itself has to be produced at runtime. The agent explores first, generates subtasks from what it discovers, and adapts the plan as new dependencies surface.

The classic example is 'add comprehensive tests to a legacy codebase.' You cannot list the test files or priorities in advance. The right approach is to first map the codebase structure, then identify high-impact and high-risk areas (untested core modules, complex branching), then build a prioritized plan that reorders and expands itself as inter-module dependencies are discovered.

This is the orchestrator-workers pattern from Anthropic's agent guidance: a central step decomposes the problem based on the specific input rather than following a fixed script, delegates the discovered subtasks, and synthesizes the results. Adaptive decomposition is the right tool for investigations, migrations of unknown scope, and research where the questions to ask only emerge from earlier answers.

Attention dilution: why one giant pass fails

Cramming a large multi-part task into a single prompt causes attention dilution. The model spreads finite attention across everything, producing detailed feedback on some parts and superficial feedback on others, missing obvious issues, and even contradicting itself, for example flagging a pattern as a bug in one file while approving identical code in another file inside the same request.

This is closely tied to the 'lost in the middle' effect: content at the start and end of a long input is processed reliably, while material in the middle is under-weighted. The longer and more heterogeneous the input, the worse it gets.

Splitting the work into focused passes is the fix, not a bigger context window. A larger window lets more text fit but does not restore uniform attention across it, so dilution and contradictions persist. The per-file-plus-integration split gives each file a dedicated pass for consistent local analysis and reserves a separate pass for the genuinely cross-file concern, the data flow between modules.

Choosing and composing the two patterns

Use a single decision heuristic: are the subtasks enumerable before execution? Predictable multi-aspect work (a PR touching a known set of files, a document pipeline with fixed stages) maps to prompt chaining. Open-ended work whose subtasks depend on discoveries (exploring a legacy system, investigating an incident, researching a broad topic) maps to dynamic decomposition.

The two are composable, and the strongest production shape usually combines them. Use adaptive decomposition (or plan mode in Claude Code) to explore and produce a concrete plan, then execute the resulting fixed steps as a chain. Investigation is dynamic, execution is chained.

Guard against both failure directions. Forcing a rigid pipeline onto exploratory work guarantees you miss whatever the fixed steps did not anticipate. Conversely, running an open-ended agent loop over work whose steps you already know adds cost and variance for no benefit. Match the pattern to the predictability of the task, not to habit.

Anti-patterns to avoid

avoid
Reviewing a 14-file pull request in one all-files-at-once prompt.

Why it fails: Finite attention gets diluted across everything, yielding detailed feedback on some files, superficial or missing analysis on others, and contradictory verdicts on identical code. Middle-of-input content is under-weighted (lost in the middle).

instead Chain the review: one focused per-file pass for local issues, then a separate cross-file integration pass for data flow between modules.

avoid
Reaching for a larger-context-window model to fix inconsistent multi-file review output.

Why it fails: A bigger window lets more text fit but does not restore uniform attention across it, so dilution and contradictions persist. It treats a decomposition problem as a capacity problem.

instead Split the work into focused passes. Decomposition, not window size, is what restores consistent per-item attention.

avoid
Splitting a review into per-file passes but skipping the integration pass.

Why it fails: Per-file passes catch local defects but are blind to bugs that only appear across files, such as a caller and callee that disagree on a contract or shared state mutated in two modules.

instead Always add a dedicated cross-file integration pass after the per-file passes to examine inter-file data flow.

avoid
Forcing an open-ended task like 'add comprehensive tests to a legacy codebase' into a fixed predefined pipeline.

Why it fails: You cannot enumerate the right subtasks before exploring. A rigid chain covers only what you guessed up front and cannot adapt when dependencies surface, leaving high-risk modules untested.

instead Use dynamic decomposition: map structure first, identify high-impact areas, then build a prioritized plan that adapts as dependencies are discovered.

Worked example: Restructuring an inconsistent 14-file PR review (CI/CD scenario)

A pull request modifies 14 files across the stock tracking module. Your CI review sends all 14 files to Claude in a single prompt and asks for issues. The output is unreliable: detailed feedback for a few files, superficial one-liners for others, obvious bugs missed, and, worst of all, contradictory feedback. It flags a null-check pattern as problematic in inventory.ts while approving identical code in orders.ts in the same run.

Diagnose the real cause. This is not a model-quality problem or a prompt-tone problem, it is attention dilution plus lost-in-the-middle. One prompt cannot give 14 files uniform, consistent attention, and files buried in the middle of the input get short-changed. Two tempting fixes do not work: switching to a larger-context model just fits more text without restoring uniform attention, and telling the model to 'be thorough and consistent' does not change how attention is distributed.

Apply prompt chaining. Decompose the review into focused passes:

Step 1  Per-file local pass (x14)
        For each file, review in isolation for local issues:
        logic bugs, error handling, style within that file.
Step 2  Cross-file integration pass (x1)
        Feed the diff plus the per-file findings; analyze
        only cross-file concerns: shared contracts, data
        flow between modules, consistency of patterns.
Step 3  Merge and dedupe into a single review comment.

Each per-file pass now sees one file with full attention, so a pattern is judged the same way everywhere, eliminating the contradiction. The integration pass is the only place cross-file logic is evaluated, and it has room to reason about it because it is not also trying to lint 14 files line by line.

Why this is the right decomposition. The subtasks here are fully enumerable up front (the set of changed files is known), so a fixed chain is correct, not a dynamic agent loop. Contrast this with 'add tests to this legacy module,' where you would instead explore first and let the plan adapt. Same domain, opposite decomposition strategy, chosen by whether the subtasks are knowable in advance.

Exam tips

  • Enumerable subtasks known before execution point to prompt chaining (fixed sequential). Subtasks that depend on runtime discoveries point to dynamic (adaptive) decomposition.
  • Large multi-file reviews: split into per-file local passes PLUS a separate cross-file integration pass. This beats both a single all-files pass and a bigger-context model.
  • Attention dilution and the lost-in-the-middle effect explain contradictory or superficial single-pass output; the cure is decomposition, not more context window.
  • 'Add comprehensive tests to a legacy codebase' is dynamic decomposition: map structure, find high-impact/high-risk areas, then build a prioritized plan that adapts as dependencies emerge.
  • Prompt chaining is a sequential single-line pipeline where each step feeds the next; it is not the same as parallel coordinator-subagent orchestration.
  • Common production combo: explore and plan adaptively (or in plan mode), then execute the resulting concrete steps as a fixed chain.
Official exam objectives for 1.6
Knowledge of
  • When to use fixed sequential pipelines (prompt chaining) versus dynamic adaptive decomposition based on intermediate findings
  • Prompt chaining patterns that break reviews into sequential steps (e.g., analyze each file individually, then run a cross-file integration pass)
  • The value of adaptive investigation plans that generate subtasks based on what is discovered at each step
Skills in
  • Selecting task decomposition patterns appropriate to the workflow: prompt chaining for predictable multi-aspect reviews, dynamic decomposition for open-ended investigation tasks
  • Splitting large code reviews into per-file local analysis passes plus a separate cross-file integration pass to avoid attention dilution
  • Decomposing open-ended tasks (e.g., "add comprehensive tests to a legacy codebase") by first mapping structure, identifying high-impact areas, then creating a prioritized plan that adapts as dependencies are discovered

Flashcards from this lesson

How should a large multi-file code review be decomposed?

Per-file local analysis passes for local issues, plus a separate cross-file integration pass for data flow and shared contracts between files.

Why does a single all-files review produce contradictory and superficial results?

Attention dilution and the lost-in-the-middle effect: finite attention is spread across everything and mid-input content is under-weighted.

Will switching to a larger-context-window model fix inconsistent multi-file review output?

No. A larger window fits more text but does not restore uniform attention. Decompose into focused passes instead.

How do you decompose 'add comprehensive tests to a legacy codebase'?

Dynamically: map structure, identify high-impact and high-risk areas, then build a prioritized plan that adapts as dependencies are discovered.

Is prompt chaining the same as multi-agent orchestration?

No. Chaining is a sequential single-line pipeline where each step feeds the next. Orchestration fans out to subagents, often in parallel, under a coordinator.

What is the value of an adaptive investigation plan?

It generates subtasks from what is discovered at each step, so coverage includes what a fixed set of steps could not have anticipated.

When do you use prompt chaining versus dynamic decomposition?

Chaining when subtasks are predictable and enumerable up front (multi-aspect reviews, fixed pipelines). Dynamic decomposition when subtasks depend on runtime discoveries (open-ended investigation, unknown-scope migrations).

Study all flashcards with spaced repetition