@blackbelt-technology/pi-flows

中文文档
0.10.0发布于 2026/11/04MITES Module构建来源已验证近 30 天下载 3069

Flow engine, dashboard, and orchestration extensions for pi

原始使用文档
文档目录16 节
  1. Overview
  2. Installation
  3. Anthropic OAuth (Claude subscription) models
  4. Quick Start
  5. Commands & Keybindings
  6. Core Concepts
  7. Writing Agents
  8. Writing Flows
  9. Step Types
  10. Input Wiring
  11. TUI Dashboard
  12. Integration with pi-agent-dashboard
  13. Built-in Agents
  14. Developer Docs
  15. Releasing
  16. License

pi-flows

CI

A pi-package that adds multi-agent workflow orchestration to pi. Design flows as YAML DAGs, run them with automatic parallel scheduling, and watch everything in a live TUI dashboard — while the main session stays fully interactive.


Overview

Flows are reusable workflow templates that coordinate multiple AI agents through structured inputs and outputs. Each agent runs in an isolated session with scoped tools and filesystem access.

Best practice usage:

  • Research → Plan → Implement → Verify cycles
  • Code review pipelines with verify/fix loops
  • Documentation generation with multi-domain research
  • Refactoring with interactive branching

Installation

pi install npm:pi-flows

Or from a local clone:

pi install /path/to/pi-flows

Anthropic OAuth (Claude subscription) models

pi-flows does no Anthropic-specific prompt or wire handling. Flow agents get pi's default system prompt plus the agent prompt, and tools keep their plain pi names. When a Claude subscription needs the system prompt adjusted, the pi-agent-dashboard handles it: it registers an agent extension through flow:register-agent-extension, and that extension rewrites the prompt section in before_agent_start. pi-flows no longer loads pi-anthropic-messages.

Quick Start

  1. Create an agent (.pi/flows/agents/reviewer.md):

    ---
    name: reviewer
    description: Reviews code for quality issues
    model: anthropic/claude-sonnet-4-5
    tools: read, grep, find
    inputs:
      - target_path
    ---
    Review the code for: ${{task}}
    Focus on: ${{input.target_path}}
    
  2. Create a flow (.pi/flows/flows/review/flow.yaml):

    name: review
    description: Research then review code
    task_required: true
    task_prompt: "What should I review?"
    
    steps:
      - id: research
        agent: project-context-reader
        task: Investigate the codebase for ${{task}}
    
      - id: review
        agent: reviewer
        blockedBy: [research]
        inputs:
          target_path: "${{result.research.summary}}"
        task: Review based on research findings
    
  3. Run it:

    /review Fix the auth middleware
    

Commands & Keybindings

CommandDescription
/flowsList and manage flows (run, delete)
/skill:manage-flowsLoad the flow/agent create-and-edit reference skill
/flows:deleteDelete a flow
alt+aToggle auto-routing (agents decide fork branches autonomously)
alt+xAbort running flow / dismiss flow summary
alt+oInspect agents (enter dashboard/summary navigate mode)
alt+tToggle thinking in the agent-detail overlay

Keybindings live in the alt+<letter> namespace to avoid colliding with pi's ctrl+<letter> defaults, and are rebindable via ~/.pi/agent/keybindings.json.

Flows also register as slash commands based on directory path: .pi/flows/flows/review/flow.yaml → /review. Each flow is a self-contained directory — its flow.yaml plus any co-located code-node handlers (<id>.ts).

Core Concepts

  • Agents — Markdown files with YAML frontmatter (config) and body (system prompt). Run in isolated sessions with scoped tools and file access.
  • Flows — YAML files defining a DAG of steps connected via blockedBy. The engine schedules independent steps in parallel, up to max_concurrent.
  • Template variables — ${{task}}, ${{result.step-id.summary}}, ${{input.name}} wire data between steps at dispatch time.
  • Models — model: is optional: a literal model, an optional @name alias (resolved by an installed model:resolve resolver such as pi-agent-dashboard), an ordered list, or nothing. Unresolvable aliases fall back to the session model.
  • Settings (.pi/settings.json, project overrides global) — flows.modelFallback: "session" (default) or "error"; flows.decisionAgent: agent used for decision steps without their own agent: (flow-level decision_agent: wins over it); flows.decider: default decider chain, e.g. ["system-one", "agent"] (see docs/flows.md).
  • Edit flow — Create and edit flows/agents conversationally in the main session using the flow_agents and flow_write tools. These tools are off by default; enable them per project (/flows:edit-mode on, or flows.editFlow: true in .pi/settings.json) or globally (~/.pi/agent/settings.json). The setting is re-read every turn and also controls whether the model sees the packaged manage-flows skill. pi-flows never writes into the repo unless you toggle edit mode explicitly. Load /skill:manage-flows for the format reference.

Writing Agents

Agents are .md files in .pi/flows/agents/ (project-local), ~/.pi/agent/flows/agents/ (user-level, all projects; flows go in ~/.pi/agent/flows/flows/; project overrides user) or a package's agents/ directory.

---
name: backend-dev
description: Implements backend changes
model: anthropic/claude-sonnet-4-5
thinking: high
tools: read, write, edit, grep, bash
inputs:
  - research_context
outputs:
  - verdict
access:
  read: ["src/**"]
  write: ["src/main/**"]
  bash:
    deny: ["rm -rf"]
card:
  label: "Backend Dev"
  metric: developer
---
You are a backend developer. Task: ${{task}}
Context: ${{input.research_context}}

Key fields: model (role tier), tools (allowlist — guard blocks everything else), inputs/outputs (typed data flow), access (filesystem sandbox), card (TUI dashboard rendering).

Writing Flows

Step Types

Every step declares an explicit type: (the parser does not infer it). There are five: agent, fork, agent-decision, code, code-decision.

Agent — dispatch a named agent with a task:

- id: impl
  type: agent
  agent: backend-dev
  blockedBy: [research]
  inputs:
    research_context: "${{result.research.summary}}"

Fork — present a choice to the user (or let an agent decide in auto-routing mode):

- id: choose
  type: fork
  question: "Which approach?"
  options: [Quick fix, Full refactor]
  branches:
    Quick fix: quick-step
    Full refactor: refactor-step
  agent: flow-decision    # used when alt+a (AUTO) is active

Agent Decision — an agent calls finish({ branch }) to route; a branch pointing at an earlier step is a loop (bounded by max_iterations):

- id: verify-loop
  type: agent-decision
  agent: flow-decision
  task: "Check iteration ${{loop.verify-loop.iteration}}/${{loop.verify-loop.max}}"
  branches:
    fix: fixer        # backward target → loops
    done: done        # forward target → exits
  max_iterations: 3   # required when a branch points backward

Code — run a deterministic TypeScript handler as a node (no LLM):

- id: validate
  type: code
  inputs:
    invoice: "${{result.extract.canonical}}"
  outputs:
    - name: valid
  blockedBy: [extract]

Code Decision — a code node that routes on a returned branch (≥2 branches):

- id: route
  type: code-decision
  inputs:
    valid: "${{result.validate.valid}}"
  branches:
    approve: finalize
    reject: notify

Input Wiring

Steps pass data through inputs + template variables:

- id: researcher
  agent: researcher
  task: Investigate ${{task}}

- id: developer
  agent: developer
  blockedBy: [researcher]
  inputs:
    context: "${{result.researcher.summary}}"
    spec_path: specs/api-spec.md    # pass a path; the agent reads it via its `read` tool

The agent's prompt references inputs as ${{input.context}}. Typed outputs declared in agent frontmatter (outputs:) are accessible as ${{result.step-id.outputName}} and are delivered to code-node handlers as their real JSON type when wired as a whole-value reference. File-backed data is passed as a path and read at runtime (give the consuming agent the read tool) — there is no file:// content injection.

TUI Dashboard

When flows run, a live dashboard appears with agent cards in a grid layout. Each card shows status, elapsed time, and domain-specific metrics (files modified, tests passed, etc.). Navigate with arrow keys, expand agent detail views, and see the full flow summary after completion.

Card types (card.metric): developer, researcher, tester, verifier, writer, default — or register custom renderers via flow:register-card.

Integration with pi-agent-dashboard

pi-flows is the engine. The browser dashboard rendering of flow events lives in pi-agent-dashboard as a separate workspace plugin (packages/flows-plugin/). The two repos are intentionally split: pi-flows emits flow:* events; the dashboard reacts to them.

See docs/dashboard-integration.md for the architecture diagram, the wire-protocol bridge, and how to add new flow events end-to-end.

Built-in Agents

AgentRoleDescription
flow-decisionRouterMakes branch/loop decisions for fork and loop steps
project-context-readerResearcherReads and summarizes project structure

Developer Docs

Detailed documentation in the docs/ folder:

Releasing

Releases are automated via .github/workflows/publish.yml. Two paths:

Workflow dispatch (recommended). Open the GitHub Actions UI, run the Release workflow, type the version (e.g. 0.2.2). The workflow bumps package.json, dates the matching ## [Unreleased] (or undated ## [X.Y.Z]) section in CHANGELOG.md to ## [vX.Y.Z] - <today>, commits, tags, pushes, then publishes to npm with provenance via npm Trusted Publishing, and drafts a GitHub Release with the CHANGELOG body.

Tag push. Locally bump the version + CHANGELOG yourself, commit, tag vX.Y.Z, and git push --follow-tags. The same publish + release jobs fire.

Before the first release run, ensure:

  1. The npm package @blackbelt-technology/pi-flows has a Trusted Publisher configured pointing at this repo + publish.yml + the npm-publish environment.
  2. A GitHub repository environment named npm-publish exists (Settings → Environments). Add a required-reviewer rule there if you want a manual gate before every publish.

Prep your CHANGELOG entry under ## [Unreleased] before triggering the workflow — the heading-dating step rewrites it in place.

See docs/releasing.md for the operator runbook.

License

MIT

版本与发布记录

@blackbelt-technology/pi-flows 共发布 20 个版本,首次发布于 2026/05/16;过去 12 个月发布了 20 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.10.0latest2026/11/044 天前
0.9.02026/11/035 天前
0.8.12026/10/309 天前
0.8.02026/10/0830 天前
0.7.12026/10/071 个月前
0.7.02026/10/071 个月前

关于 @blackbelt-technology/pi-flows 的常见问题

@blackbelt-technology/pi-flows 是什么?

Flow engine, dashboard, and orchestration extensions for pi

如何安装 @blackbelt-technology/pi-flows?

在项目目录运行 npm install @blackbelt-technology/pi-flows,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:typebox(^1.3.7)、@earendil-works/pi-ai(>=0.84.1 <2.0.0)、@earendil-works/pi-tui(>=0.84.1 <2.0.0)、@earendil-works/pi-coding-agent(>=0.84.1 <2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@blackbelt-technology/pi-flows 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/blackbelt-technology__pi-flows 是否存在。

@blackbelt-technology/pi-flows 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@blackbelt-technology/pi-flows 可以商用吗?

@blackbelt-technology/pi-flows 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@blackbelt-technology/pi-flows 的下载量有多少?

根据 npm 官方下载统计,@blackbelt-technology/pi-flows 在 2026/10/09 – 2026/11/07 这 30 天内被下载 3,069 次,日均约 102 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@blackbelt-technology/pi-flows 还在维护吗?

最新版本 0.10.0 发布于 2026/11/04(4 天前);至今共发布 20 个版本,其中过去 12 个月发布了 20 个;首次发布于 2026/05/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。