# Dynamic Workflow Engine — Design ## Architecture ``` User writes workflow JS file: .boocode/workflows/my-flow.js Workflow Runtime (apps/server) ├── isolated-vm sandbox (or node:vm) ├── API surface: agent(), parallel(), pipeline(), phase(), budget() ├── Tool bridge → BooCode's existing tool set ├── Workflow manager (concurrency, lifecycle) ├── Resumability cache (SHA-256 of agent spec) └── Catalog (built-in workflows: deep-research, review-code) Workflow execution: 1. User triggers workflow (slash command or Orchestrator panel) 2. File discovery finds .boocode/workflows/.js 3. Sandbox compiles and executes the script 4. agent() calls go through tool bridge → existing inference pipeline 5. parallel() spawns concurrent agent calls (max 3 default) 6. Results stream via existing WS frames 7. Completed agents cached by hash for resume API Surface (Claude Code compatible): agent(prompt, { label?, schema?, model?, capabilities?, max_tool_calls? }) parallel([() => agent(...), () => agent(...)]) pipeline(items, ...stages) phase(title) log(message) budget.total / budget.spent() / budget.remaining() args workflow(name, args?) — one level of nesting ``` ## Implementation Plan ### Phase 1: Core Runtime (this session) - Sandbox using Node's `vm` module (no extra deps) - `agent()` function that creates a task and waits for completion - Workflow file discovery - Basic workflow manager ### Phase 2: Advanced Primitives - `parallel()` with concurrency limits - `pipeline()` streaming - `budget()` token tracking - Workflow resumability cache ### Phase 3: UI + Polish - Integration with Orchestrator panel - Built-in workflow catalog - Workflow editor - Error recovery