Skill

Divide and Conquer

Break big jobs into parallel, subagent-driven task graphs

Use in Claude Code
/amplify:divide-and-conquer

Divide and conquer turns a large job into a folded task graph of typed nodes — agent, fn, expand, and switch — executed on the amplify engine. Independent work fans out across isolated subagent contexts while values pass by reference so payload bytes never flood the orchestrator. It supports both human-reviewed decomposition of bare prompts and direct execution of skills that ship their own authored graphs.

Key Insights

Isolated Subagent Fan-Out

Each parallel unit runs in its own subagent context, so wide fan-outs never degrade a single long context. One agent per unit means independent work scales horizontally instead of serially.

Typed Folded Task Graph

Graphs compose from four node kinds — agent for non-deterministic work, fn for pure transforms, expand for fan-out, and switch for branching. Every node carries an explicit output_schema and the engine validates the whole shape before running.

Values by Reference, Never Bytes

The orchestrator only handles ids and handles; payload bytes stay out of its context. Cross-node data flows through the value store, keeping the orchestrator lean and the contexts clean.

Two Entry Modes

Mode A decomposes a bare prompt into a draft graph for human review and editing before running. Mode B loads and runs a skill that ships its own authored graph plus helper modules, with no review gate.

How It Works

1

Decompose or Load

Spawn a sub-agent to draft a graph, or load a skill's shipped graph.json.

Mode A spawns one decomposition sub-agent that turns the bare prompt into a draft folded-graph declaration with a real expand fan-out and gather reducer. Mode B loads an authored graph plus its fn modules directly.

2

Validate the Graph

Validate against the task-graph schema and dry-run init.

Write the draft to a temp file, validate against task-graph.schema.json, and dry-run task.mjs init to exercise the engine's validateGraph — rejecting unknown types, dangling deps, and missing output_schema.

3

Human Review and Edit

Present the validated draft for plan-mode review before running.

Surface the fan-out width, per-unit work, and gather step via the plan gate. The human may edit nodes, prompts, the unit list, or schemas before approving. Re-validate after any edit. Mode B skips this gate.

4

Run the Scheduling Loop

Drive the graph through the execute-plan scheduling loop.

init captures the GRAPH_ID, then ready / dispatch agent in the background / exec-node for fn, expand, and switch, honoring the concurrency window and the single-writer commit lock.

5

Gather Results

Reduce per-unit outputs with an all-resolved gather fn.

An fn reducer with require all-resolved gathers successes even when some children fail, so partial results always collect and one failure never sinks the run. Present the gathered result to the user.