Higher-Order Skills
Skills that compose and orchestrate other skills—like higher-order functions, but for agent workflows.
What are Higher-Order Skills?
A higher-order skill doesn't just perform a task—it orchestrates other skills to accomplish complex, multi-step objectives. Just as higher-order functions take functions as arguments and return functions, higher-order skills take skills as dependencies and coordinate their execution.
These skills typically:
- Link to multiple skills for delegation
- Define iteration or branching logic to coordinate execution
- Manage state across multiple sub-skill invocations
- Synthesize results from delegated work
Patterns
Map-Reduce
Fan out work to multiple agents, collect results, and synthesize a final output:
FOR $item IN $collection
DELEGATE /process item/ TO ~/agent/processor
Collect $result into $results
END
Synthesize $results into final output This pattern excels when work can be parallelized and results need aggregation.
Iteration with Hypothesis Testing
Loop until a condition is met, refining approach based on observations:
WHILE NOT /success/ AND $iteration < $maxIterations DO
Form hypothesis
Run experiment
Observe results
IF /progress/ THEN
Refine
ELSE
Pivot
END
END This pattern is ideal for problems requiring exploration and adaptation.
Pipeline
Sequential skill chaining where output flows from one stage to the next:
USE ~/skill/analyze TO /analyze input/
USE ~/skill/transform TO /transform results/
USE ~/skill/validate TO /validate output/ Use this when each step transforms data for the next stage.
Example: The Scientist
The scientific-method.mdz skill demonstrates a sophisticated higher-order
pattern for hypothesis-driven iteration. It orchestrates sub-agents to run
experiments and refine solutions based on observations.
Structure
---
name: scientific-method
description: When orchestrating hypothesis-driven iteration
--- State Persistence with Work Packages
The scientist uses ~/skill/work-packages to persist state across iterations:
- A master work package tracks overall progress and findings
- Each experiment gets its own work package at a computed path
- Results are recorded for later synthesis
$workPackagePath = $n => `/work package directory//wp-experiment-$n.md` The WHILE Loop
The core iteration continues until diminishing returns or max iterations:
WHILE NOT diminishing returns AND $iteration < $maxIterations DO
Design experiment and set success criteria
DELEGATE run experiment TO ~/agent/experimenter WITH #experiment-prompt
Extract $observations and update master work package
IF $result = "progress" THEN
Commit changes, update hypothesis
ELSE
Revert if regression, revise hypothesis
END
END Result Accumulation
The skill supports two strategies via $strategy:
- accumulate: Commit successful changes and build on them
- independent: Run experiments independently, synthesize at the end
The final conclusion synthesizes all findings, documenting what worked and what didn't.
Structure of a Higher-Order Skill
A typical higher-order skill follows this structure:
---
name: orchestrator-skill
description: When coordinating multiple skills
---
## Types
$State: context maintained across iterations
$Result: output from delegated work
## Input
$collection: items to process
$maxIterations: $Number = 5
## Context
$results: $Result[] = []
$iteration = 0
## Workflow
FOR $item IN $collection
DELEGATE process item TO ~/agent/worker
Collect result
END
USE ~/skill/synthesize TO combine results Key Techniques
- Link to dependencies: Reference all orchestrated skills and agents
- Define iteration variables: Track state in the Context section
- Use work packages: Persist state for complex, multi-step workflows
- Create sub-agent prompts: Define reusable prompt sections for delegation
- Handle failure modes: Include branching logic for different outcomes
See Also
- Composition — Links and delegation
- Control Flow — WHILE, FOR, IF/THEN/ELSE, END
- Examples — Full implementations including scientific-method