@vintcessun: 原来 LLM 还能自己写工作脚本,把任务拆给一群子代理并行干。 单个助手顺序思考,遇到代码库审计、大型重构这种活,要么慢,要么思路串。 pi-dynamic-workflows 让模型直接生成一段 JS 脚本,用 agent()、para…
摘要
介绍 pi-dynamic-workflows,一个让 LLM 通过生成 JavaScript 脚本动态编排多个子代理并行执行任务的工具,适用于代码审计、大型重构等场景。
查看缓存全文
缓存时间: 2026/05/31 07:03
原来 LLM 还能自己写工作脚本,把任务拆给一群子代理并行干。 单个助手顺序思考,遇到代码库审计、大型重构这种活,要么慢,要么思路串。 pi-dynamic-workflows 让模型直接生成一段 JS 脚本,用 agent()、parallel() 做任务编排,沙箱里跑完再汇总——进度还实时显示。 本质是把“一个人干活”变成“一个人写调度脚本,小弟们并行执行”。
Michaelliv/pi-dynamic-workflows
Source: https://github.com/Michaelliv/pi-dynamic-workflows
pi-dynamic-workflows
Claude-Code-style dynamic workflows for Pi.
A Pi extension that adds a workflow tool. 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.
Great for codebase audits, multi-perspective review, large refactors, and fan-out research.
Inspired by Anthropic’s dynamic workflows in Claude Code.
Install
pi install npm:pi-dynamic-workflows
# or from a local checkout
pi install /path/to/pi-dynamic-workflows
Then in Pi:
/reload
That’s it. The extension registers a workflow tool and activates it on session start.
Usage
Just ask Pi for a workflow in plain language:
Run a workflow to inspect this repository and summarize the main modules.
The model will write a workflow script and call the workflow tool. Live progress shows up inline:
◆ Workflow: inspect_project (3/3 done)
✓ Scan 1/1
#1 ✓ repo inventory
✓ Analyze 2/2
#2 ✓ source modules
#3 ✓ final summary
Press Esc to cancel a running workflow. Active subagents are aborted and surfaced as skipped.
Workflow script shape
A workflow is plain JavaScript. The first statement must export literal metadata. name and description are required; phases is optional documentation for an expected outline. The live progress view is driven by phase(...) calls at runtime:
export const meta = {
name: 'inspect_project',
description: 'Inspect a repository and summarize the main modules',
phases: [
{ title: 'Scan' },
{ title: 'Analyze' },
],
}
phase('Scan')
const inventory = await agent('Inspect the repository structure.', {
label: 'repo inventory',
})
phase('Analyze')
const summary = await agent(
'Summarize the main modules from this inventory:\n' + inventory,
{ label: 'module summary' },
)
return { inventory, summary }
Phases 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.
Editor IntelliSense
Reusable workflow files can opt into editor hints for workflow globals:
/// <reference types="pi-dynamic-workflows/workflow" />
This declares agent, parallel, pipeline, phase, log, args, cwd, and budget for TypeScript-aware editors.
Available globals
| Global | Description |
|---|---|
agent(prompt, opts) | Spawn an isolated subagent. Returns its final text or, with opts.schema, a validated object. |
parallel(thunks) | Run an array of () => agent(...) thunks concurrently. Results are returned in input order. |
pipeline(items, ...stages) | Run each item through sequential stages while items fan out. Each stage receives (prev, original, index). |
phase(title) | Mark the current phase. Used for grouping in the live progress view. |
log(message) | Append a workflow-level log line. |
args | Optional JSON value passed in via the tool’s args parameter. |
cwd, process.cwd() | Current working directory for subagents. |
budget | { total, spent(), remaining() } token budget tracker. |
Determinism rules
Workflow scripts are evaluated inside a Node vm sandbox. The following are intentionally unavailable:
Date.now(),new Date()Math.random()require,import,fs, network APIs- spreads, computed keys, template interpolation, function calls inside
meta
This keeps meta parseable, runs reproducible, and the surface area small.
Structured subagent output
Pass a JSON Schema via opts.schema and the subagent will return a validated object:
const finding = await agent('Find security-sensitive files.', {
label: 'security scan',
schema: {
type: 'object',
properties: {
paths: { type: 'array', items: { type: 'string' } },
reason: { type: 'string' },
},
required: ['paths', 'reason'],
},
})
Under the hood this is a Pi structured_output tool with terminate: true, so the subagent ends on that call without an extra assistant turn.
How it works
user prompt
→ Pi model writes a workflow script
→ workflow tool parses + runs script in a vm sandbox
→ script calls agent(), parallel(), pipeline()
→ each agent() spawns an in-memory Pi subagent session
→ snapshots stream back as compact progress
→ final structured result returned to the parent assistant
Subagents 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.
Library modules
| File | Purpose |
|---|---|
src/workflow.ts | AST-validated parser and sandboxed workflow runtime. |
src/workflow-tool.ts | The Pi workflow tool, prompt guidelines, rendering, abort handling. |
src/agent.ts | WorkflowAgent, an in-memory Pi subagent runner. |
src/structured-output.ts | Terminating structured-output tool backed by TypeBox/JSON Schema. |
src/display.ts | Workflow snapshots and compact text renderers. |
extensions/workflow.ts | The Pi extension entrypoint. |
Development
npm install
npm test # biome check + tsc + unit tests
npm run dev
Parser unit tests live in tests/workflow-parser.test.ts and cover both accepted and rejected script shapes.
Status
This 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 manager.
License
MIT
相似文章
@wsl8297: 在 GitHub 上发现一个递归式多 Agent 框架:ROMA(Recursive Open Meta-Agent),它通过层次化的递归结构来解决复杂问题,把任务拆解成可并行处理的组件,让 Agent 能处理更复杂的推理任务。 GitH…
ROMA 是一个基于 DSPy 构建的递归式多 Agent 框架,旨在通过层次化递归结构解决复杂推理任务,支持任务拆解、并行处理及多种 LLM 提供商。
@geekbb: pi-workflow 是一个为 Pi 设计的工作流编排工具,让 Pi 能执行多步骤、可复用的工作流,而不是只有单轮对话。用自然语言就能触发,不用每次手写提示词。 四种工作流直接用: - deep-research 做深度研究 - dee…
pi-workflow 是一个为 Pi AI 助手设计的工作流编排工具,使其能够执行多步骤、可重复的工作流,包括深度研究、代码审查、规格检查和影响评估。它通过 JSON 阶段图定义工作流,支持多种执行模式。
@Xudong07452910: 最好的 AI Coding 工作流,可能是让 AI 把自己的不稳定性慢慢沉淀成系统。 文章作者用 Fable 开发面向 LLM 时代的源码管理系统,体验很真实:模型很聪明,能读大量代码、提 issue、修问题,但也会犯很低级的错,比如两次…
A blog post discusses the need to complement brilliant but clumsy LLMs with deterministic tools and formal workflows, using the author's experience developing the Beagle SCM with Fable as an example.
@elliotchen100: 表面上是 Claude Code 能自己生成 workflow,往深一层看,是 agent 产品的控制面在变化。 过去我们把复杂任务塞进一个长 context,期待模型自己记住目标、拆步骤、判断完成;现在这些东西开始外化成可执行的 har…
文章指出,Claude Code能自动生成workflow的背后,反映了AI agent产品的控制面正在从依赖长上下文记忆目标、拆解步骤,转向外化为可执行的harness,包括任务结构、权限边界、验证机制和停止条件等。
@mylifcc: 重磅实验:让 LLM 当「优化代理」自动调度循环! 刚读完这篇刚接受 PACT 2025 的论文:《Agentic Auto-Scheduling: An Experimental Study of LLM-Guided Loop Opt…
介绍一篇被PACT 2025接受的论文,提出了ComPilot框架,利用现成LLM作为优化代理,无需微调即可自动优化复杂循环嵌套,几何平均加速达3.54倍,超越SOTA Pluto。