|
| 1 | +# @claude-code-best/workflow-engine |
| 2 | + |
| 3 | +Deterministic JS script orchestration engine for multi-agent workflows. The core layer has zero runtime dependencies and talks to the outside world exclusively through **port adapters** — you bring your own agent backend, journal store, and progress sink. |
| 4 | + |
| 5 | +## Why |
| 6 | + |
| 7 | +When you orchestrate multiple LLM agents, you want the orchestration itself to be **deterministic, replayable, and testable**. This engine runs a plain JS script (compiled by Bun's transpiler) with primitives like `agent()`, `phase()`, `parallel()` and `pipeline()`. The non-deterministic parts (the LLM, the file system, the clock) are isolated behind ports, so the same script produces the same journal on every replay. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +```bash |
| 12 | +bun add @claude-code-best/workflow-engine |
| 13 | +# or |
| 14 | +npm install @claude-code-best/workflow-engine |
| 15 | +``` |
| 16 | + |
| 17 | +Runtime peer requirements: `ajv` and `zod` are pulled in automatically as dependencies. |
| 18 | + |
| 19 | +## Minimal example |
| 20 | + |
| 21 | +```ts |
| 22 | +import { |
| 23 | + createFileJournalStore, |
| 24 | + createHostHandle, |
| 25 | + runWorkflow, |
| 26 | + type WorkflowPorts, |
| 27 | +} from '@claude-code-best/workflow-engine' |
| 28 | + |
| 29 | +const script = ` |
| 30 | +export const meta = { name: 'hello', description: 'minimal demo' } |
| 31 | +phase('Greet') |
| 32 | +const reply = await agent({ prompt: 'Say hi in one short sentence.' }) |
| 33 | +emit('result', { reply }) |
| 34 | +` |
| 35 | + |
| 36 | +const ports: WorkflowPorts = { |
| 37 | + // Provide your own agent runner + journal + progress emitter. |
| 38 | + // See examples/smoke.ts for a complete Anthropic SDK wiring. |
| 39 | +} as WorkflowPorts |
| 40 | + |
| 41 | +const handle = createHostHandle() |
| 42 | +await runWorkflow({ |
| 43 | + script, |
| 44 | + ports, |
| 45 | + workflowDir: '.wfe/runs/hello', |
| 46 | + hostHandle: handle, |
| 47 | +}) |
| 48 | +``` |
| 49 | + |
| 50 | +For a fully wired end-to-end example with the Anthropic SDK, see [`examples/smoke.ts`](./examples/smoke.ts). |
| 51 | + |
| 52 | +## Core primitives |
| 53 | + |
| 54 | +- `agent(params)` — call the configured AgentRunner; supports structured-output via JSON Schema. |
| 55 | +- `phase(name)` — declare a logical phase (display + progress grouping). |
| 56 | +- `parallel([...])` — barrier-style fan-out with bounded concurrency. |
| 57 | +- `pipeline(stream, fn)` — streaming pipeline with per-item hooks. |
| 58 | +- `emit(type, payload)` — emit a progress event to the host. |
| 59 | +- `log.*` / hooks / budgets — see the TypeScript definitions for the full surface. |
| 60 | + |
| 61 | +## Building from source |
| 62 | + |
| 63 | +```bash |
| 64 | +bun install # from the repo root |
| 65 | +bun run build # outputs dist/index.js + dist/**/*.d.ts |
| 66 | +bun test # 178 tests |
| 67 | +``` |
| 68 | + |
| 69 | +## License |
| 70 | + |
| 71 | +MIT © claude-code-best |
0 commit comments