Multi-Agent Orchestration in TypeScript: Parallel & Sequential Subagent Patterns
Multi-Agent Orchestration in TypeScript: Parallel & Sequential Subagent Patterns: Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.
- Spawn N parallel subagents for concurrent repository analysis
- Sequential pipeline: pass outputs from one agent as inputs to the next
- Supervisor agent decomposes tasks; worker agents execute subtasks
- Aggregate structured results from multiple agents with typed outputs
Running Agents in Parallel
Use Promise.all to run multiple agent instances concurrently. Each instance maintains its own session, tool execution log, and context window:
import { createAgent } from 'smoke-monkey-harness';const modules = ['auth', 'payments', 'notifications', 'analytics'];// Spawn one agent per module — all run concurrentlyconst results = await Promise.all(modules.map((module) =>createAgent({provider: 'anthropic',model: 'claude-3-7-sonnet',workspacePath: `./src/${module}`,autoApprove: true,}).run(`Audit ${module} module for security vulnerabilities. Output JSON.`)));// Aggregate findingsconst allFindings = results.flatMap((r) => JSON.parse(r.output));console.log(`Found ${allFindings.length} total findings across ${modules.length} modules`);
The Supervisor-Worker Pattern
In this pattern, a supervisor agent analyzes the codebase and decomposes the task into subtasks. Worker agents then execute each subtask independently:
- Supervisor reads the repository structure and generates a task plan as JSON.
- Orchestrator parses the plan and spawns one worker agent per task.
- Workers execute their task autonomously in isolated workspace sub-paths.
- Supervisor is called again with all worker outputs to synthesize the final result.
This pattern scales to large codebases because no single context window needs to hold the entire codebase.
Use isolated workspace paths for workers
Give each worker agent a workspacePath scoped to its assigned module to prevent concurrent file write conflicts.
Frequently Asked Questions
Q:How many parallel agents can I run without hitting rate limits?
This depends on your LLM provider tier. For Anthropic Claude, the Tier 4 plan supports up to 4,000 requests per minute. Use Promise.allSettled with concurrency limiting (e.g., p-limit) for large-scale orchestration.
Q:Can agents communicate with each other directly?
Currently agents communicate via structured output files in the shared workspace. A supervisor agent can read the output files written by worker agents and use them as context for synthesis.
Related Alternatives & Comparisons
Build with Smoke Monkey Harness
Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.