{"slug": "pi-dynamic-workflows", "title": "Pi Dynamic Workflows", "summary": "Pi Dynamic Workflows, a new extension for the Pi AI assistant, enables users to run complex, multi-step tasks by having the model write a JavaScript script that distributes work across isolated subagents and synthesizes results. The tool, inspired by Anthropic's Claude Code dynamic workflows, supports codebase audits, multi-perspective reviews, and large refactors, with live progress tracking and cancellation capabilities.", "body_md": "Claude-Code-style dynamic workflows for\n\n[Pi].\n\nA Pi extension that adds a `workflow`\n\ntool. Instead of one assistant doing everything sequentially, the model writes a small JavaScript script that fans out the work across many isolated subagents, then synthesizes the results.\n\nGreat for codebase audits, multi-perspective review, large refactors, and fan-out research.\n\nInspired by Anthropic's [dynamic workflows in Claude Code](https://claude.com/blog/introducing-dynamic-workflows-in-claude-code).\n\n```\npi install npm:pi-dynamic-workflows\n# or from a local checkout\npi install /path/to/pi-dynamic-workflows\n```\n\nThen in Pi:\n\n```\n/reload\n```\n\nThat's it. The extension registers a `workflow`\n\ntool and activates it on session start.\n\nJust ask Pi for a workflow in plain language:\n\n```\nRun a workflow to inspect this repository and summarize the main modules.\n```\n\nThe model will write a workflow script and call the `workflow`\n\ntool. Live progress shows up inline:\n\n```\n◆ Workflow: inspect_project (3/3 done)\n  ✓ Scan 1/1\n    #1 ✓ repo inventory\n  ✓ Analyze 2/2\n    #2 ✓ source modules\n    #3 ✓ final summary\n```\n\nPress `Esc`\n\nto cancel a running workflow. Active subagents are aborted and surfaced as skipped.\n\nA workflow is plain JavaScript. The first statement must export literal metadata. `name`\n\nand `description`\n\nare required; `phases`\n\nis optional documentation for an expected outline. The live progress view is driven by `phase(...)`\n\ncalls at runtime:\n\n``` js\nexport const meta = {\n  name: 'inspect_project',\n  description: 'Inspect a repository and summarize the main modules',\n  phases: [\n    { title: 'Scan' },\n    { title: 'Analyze' },\n  ],\n}\n\nphase('Scan')\nconst inventory = await agent('Inspect the repository structure.', {\n  label: 'repo inventory',\n})\n\nphase('Analyze')\nconst summary = await agent(\n  'Summarize the main modules from this inventory:\\n' + inventory,\n  { label: 'module summary' },\n)\n\nreturn { inventory, summary }\n```\n\nPhases are discovered as the script runs, so conditional and loop-created phases work naturally. If a branch is skipped, its phase does not show up as an empty progress row.\n\nReusable workflow files can opt into editor hints for workflow globals:\n\n```\n/// <reference types=\"pi-dynamic-workflows/workflow\" />\n```\n\nThis declares `agent`\n\n, `parallel`\n\n, `pipeline`\n\n, `phase`\n\n, `log`\n\n, `args`\n\n, `cwd`\n\n, and `budget`\n\nfor TypeScript-aware editors.\n\n| Global | Description |\n|---|---|\n`agent(prompt, opts)` |\nSpawn an isolated subagent. Returns its final text or, with `opts.schema` , a validated object. |\n`parallel(thunks)` |\nRun an array of `() => agent(...)` thunks concurrently. Results are returned in input order. |\n`pipeline(items, ...stages)` |\nRun each item through sequential stages while items fan out. Each stage receives `(prev, original, index)` . |\n`phase(title)` |\nMark the current phase. Used for grouping in the live progress view. |\n`log(message)` |\nAppend a workflow-level log line. |\n`args` |\nOptional JSON value passed in via the tool's `args` parameter. |\n`cwd` , `process.cwd()` |\nCurrent working directory for subagents. |\n`budget` |\n`{ total, spent(), remaining() }` token budget tracker. |\n\nWorkflow scripts are evaluated inside a Node `vm`\n\nsandbox. The following are intentionally unavailable:\n\n`Date.now()`\n\n,`new Date()`\n\n`Math.random()`\n\n`require`\n\n,`import`\n\n,`fs`\n\n, network APIs- spreads, computed keys, template interpolation, function calls inside\n`meta`\n\nThis keeps `meta`\n\nparseable, runs reproducible, and the surface area small.\n\nPass a JSON Schema via `opts.schema`\n\nand the subagent will return a validated object:\n\n``` js\nconst finding = await agent('Find security-sensitive files.', {\n  label: 'security scan',\n  schema: {\n    type: 'object',\n    properties: {\n      paths: { type: 'array', items: { type: 'string' } },\n      reason: { type: 'string' },\n    },\n    required: ['paths', 'reason'],\n  },\n})\n```\n\nUnder the hood this is a Pi `structured_output`\n\ntool with `terminate: true`\n\n, so the subagent ends on that call without an extra assistant turn.\n\n```\nuser prompt\n  → Pi model writes a workflow script\n  → workflow tool parses + runs script in a vm sandbox\n  → script calls agent(), parallel(), pipeline()\n  → each agent() spawns an in-memory Pi subagent session\n  → snapshots stream back as compact progress\n  → final structured result returned to the parent assistant\n```\n\nSubagents run in fresh in-memory Pi sessions with the standard coding tools, so they can read files, run shell commands, and call structured output exactly like a normal Pi turn.\n\n| File | Purpose |\n|---|---|\n`src/workflow.ts` |\nAST-validated parser and sandboxed workflow runtime. |\n`src/workflow-tool.ts` |\nThe Pi `workflow` tool, prompt guidelines, rendering, abort handling. |\n`src/agent.ts` |\n`WorkflowAgent` , an in-memory Pi subagent runner. |\n`src/structured-output.ts` |\nTerminating structured-output tool backed by TypeBox/JSON Schema. |\n`src/display.ts` |\nWorkflow snapshots and compact text renderers. |\n`extensions/workflow.ts` |\nThe Pi extension entrypoint. |\n\n```\nnpm install\nnpm test     # biome check + tsc + unit tests\nnpm run dev\n```\n\nParser unit tests live in `tests/workflow-parser.test.ts`\n\nand cover both accepted and rejected script shapes.\n\nThis is a prototype. It implements the core workflow primitive (script, subagents, parallel/pipeline, phases, abort, structured output) but does not yet implement persisted or resumable runs, or a `/workflows`\n\nmanager.\n\nMIT", "url": "https://wpnews.pro/news/pi-dynamic-workflows", "canonical_source": "https://github.com/Michaelliv/pi-dynamic-workflows", "published_at": "2026-06-03 03:43:53+00:00", "updated_at": "2026-06-03 04:21:11.660026+00:00", "lang": "en", "topics": ["ai-tools", "ai-agents", "ai-products", "large-language-models", "ai-infrastructure"], "entities": ["Pi", "Claude Code", "Anthropic", "pi-dynamic-workflows"], "alternates": {"html": "https://wpnews.pro/news/pi-dynamic-workflows", "markdown": "https://wpnews.pro/news/pi-dynamic-workflows.md", "text": "https://wpnews.pro/news/pi-dynamic-workflows.txt", "jsonld": "https://wpnews.pro/news/pi-dynamic-workflows.jsonld"}}