Motivation
The K9-AIF Squad executes agents sequentially — the right model for dependent steps. But many workflows contain independent work units that do not need to wait on each other: generating 20 scaffold files, extracting independent data slices, validating a transaction across multiple systems simultaneously.
Sequential execution in these cases is pure waste. The Sub-Agent Pattern introduces K9AgentSpawner — a parent agent that spawns lightweight ChildAgents in parallel, sequential, or tree mode, then merges their results. The Squad sees one agent. The spawning is entirely encapsulated.
Structure
- K9AgentSpawner sits in the Squad flow like any other agent
- When executed, it dynamically spawns ChildAgents at runtime
- ChildAgents are leaf nodes — they cannot spawn further agents
- Three execution modes: parallel (fork-join), sequential (pipeline), tree (hierarchical)
- ChildRegistry tracks all spawned children — no orphans on parent failure
- merge_results() is overridable — SBB defines the result policy