vekexasia/pi-extensible-workflows
GitHub: vekexasia/pi-extensible-workflows
为 Pi 平台提供确定性的多智能体工作流编排引擎,支持并行扇出、审批暂停和断点恢复。
Stars: 36 | Forks: 2
# pi-extensible-workflows

将多智能体任务转化为确定性的作业,支持并行扇出、暂停等待审批,并在恢复时无需重新运行已完成的工作。
[文档](https://vekexasia.github.io/pi-extensible-workflows/) | [开发者指南](https://vekexasia.github.io/pi-extensible-workflows/developers.html) | [智能体指南](https://vekexasia.github.io/pi-extensible-workflows/agents.html) | [扩展编写](https://vekexasia.github.io/pi-extensible-workflows/extensions.html) | [视频概述](https://youtu.be/qAiivspEHmU)
要求 Node.js 22.19 或更高版本。这是一个受信任的 Pi 扩展,具有与 Pi 相同的文件系统和进程访问权限。
## 安装
```
pi install npm:pi-extensible-workflows
```
有关源码安装和本地开发,请参阅[安装指南](https://vekexasia.github.io/pi-extensible-workflows/developers.html#installation)。
## 功能特性
默认路径是具名的内联工作流:编写一个 `script`,使用 `parallel(...)` 扇出独立的工作,等待键控结果,将其传递给一个汇总的 `agent(...)`,然后返回。内联启动需要非空的 `name`;注册函数启动会拒绝 `name`,并使用其注册的函数名作为运行名称。运行默认在后台执行;当必须在同一次工具调用中返回最终值时,请设置 `foreground: true`。如果前台工具调用在其结果被下一个事件循环回合接受之前分离,最终的成功或失败状态将被提升为一条后续消息。
```
const reviews = await parallel("review", {
correctness: () => agent("Review the current changes for correctness issues."),
security: () => agent("Review the current changes for security risks."),
tests: () => agent("Review the current changes for missing test coverage."),
});
return await agent(
prompt("Summarize and prioritize these findings:\n\n{reviews}", { reviews }),
);
```
**高级功能:** 当任务需要时,可以使用注册函数、`outputSchema`、预算、checkpoints、worktrees、重试/恢复、CLI 导出以及 `pipeline(...)`。这些功能在不会使基本内联路径复杂化的情况下保持可用。工作流 worktree 作用域始终使用显式的 `withWorktree(name, callback)` 形式。
主 Pi agent 会为每个任务动态编写这些脚本;扩展可以添加可重用的函数和变量,已完成的工作流可以在不重新运行已完成工作的情况下恢复。
在文档中了解更多关于角色、工作流契约和扩展 API 的信息:
- [工作流工具与调用 API](https://vekexasia.github.io/pi-extensible-workflows/developers.html#tool-api)
- [全局和项目设置](https://vekexasia.github.io/pi-extensible-workflows/developers.html#settings)
- [聚合运行预算](https://vekexasia.github.io/pi-extensible-workflows/developers.html#budgets)
- [工作流 DSL 和 worktrees](https://vekexasia.github.io/pi-extensible-workflows/developers.html#dsl)
- [扩展编写指南](https://vekexasia.github.io/pi-extensible-workflows/extensions.html)
- [复制粘贴扩展模板](https://github.com/vekexasia/pi-extensible-workflows/tree/main/examples/workflow-extension-template)
- [运行产物与生命周期事件](https://vekexasia.github.io/pi-extensible-workflows/developers.html#lifecycle)
- [运行检查与恢复](https://vekexasia.github.io/pi-extensible-workflows/developers.html#operations)
- [智能体模式与模型选择](https://vekexasia.github.io/pi-extensible-workflows/agents.html#patterns)
- [Checkpoints](https://vekexasia.github.io/pi-extensible-workflows/agents.html#checkpoints)
## 许可证
MIT
标签:AI代理, GNU通用公共许可证, MITM代理, Node.js, 任务调度, 多智能体编排, 工作流引擎, 自动化攻击