Sequential agent-chain extension for Pi Coding Agent.
This package is not a standalone app. It is a Pi extension that:
- Loads chain definitions from
.pi/agents/agent-chain.yaml - Discovers agent definitions from markdown files with frontmatter
- Registers the
run_chaintool - Adds
/chainand/chain-listcommands - Supports final output delivery to chat, a follow-up turn, or a file
pi-chains gives you a repeatable way to split a job across multiple focused agents.
Each chain runs step by step. Agent steps execute in order, and the next step receives
the original user task plus structured outputs from earlier agents as context.
This is useful when you want workflows like:
- research -> implementation
- analyze -> plan -> write
- review -> patch -> summarize
- generate content -> write result to a file
The extension entrypoint is extensions/index.ts, which re-exports the registration
logic from chains.ts.
run_chain
Parameters:
{
"chain": "chain-name",
"task": "What the chain should do"
}/chain <name> <task...>/chain-list
Install from Github:
pi install https://github.com/eleqtrizit/pi-chainsInstall from this directory:
pi install ./Remove it:
pi remove ./Run it directly without installing:
pi --extension "$(pwd)/extensions/index.ts"You need two things:
- Agent definition files
- A chain definition file
** NOTE THE TOOL RESTRICTIONS CURRENTLY DO NOT WORK - NOT SURE IF WILL IMPLEMENT **
Agents are discovered from these directories:
.pi/agents/~/.pi/agent/agents/
Each agent is a markdown file with frontmatter plus a prompt body.
Example: .pi/agents/researcher.md
---
name: researcher
description: Finds facts and constraints for a task
tools: read,grep,ls
---
You are a research specialist.
Collect the relevant facts, constraints, and unknowns.
Be concise and structured.Example: .pi/agents/writer.md
---
name: writer
description: Turns prior chain output into a final deliverable
tools: read,write,edit,ls
---
You write clear final artifacts based on the prior chain context.
Produce the requested deliverable directly.
Do not repeat analysis unless it is needed in the final output.Frontmatter fields used by the extension:
name: agent name used by the chaindescription: short label for chain contexttools: tool allowlist passed to the spawned Pi agent
The markdown body becomes the system prompt appended to that agent run.
Create .pi/agents/agent-chain.yaml.
Each top-level key is a chain name. A chain has:
descriptionsteps
Each step is either:
- An agent step:
agent+prompt - An output step:
outputplus optional output settings
Supported output modes:
chatHistory: insert final content into chat historytriggerTurn: insert final content and trigger a follow-up turnfile: write final content to a file
Output-step options:
display: whether the sent message should be shown in chatfile_name: required whenoutput: fileprepend: text added before the final contentappend: text added after the final content
draft-readme:
description: Research a repo and draft a README
steps:
- agent: researcher
prompt: |
Inspect the repo and extract the purpose, key workflows, and setup steps.
Return a concise outline for a README.
- agent: writer
prompt: |
Turn the prior chain context into a polished README.md draft.
Use markdown headings and practical examples.
- output: chatHistory
display: trueRun it:
/chain draft-readme Create a README for this repository
Or via the tool:
{
"chain": "draft-readme",
"task": "Create a README for this repository"
}spec-to-file:
description: Convert a request into a saved markdown spec
steps:
- agent: researcher
prompt: |
Analyze the request and produce the technical requirements.
- agent: writer
prompt: |
Write a concise implementation spec in markdown.
- output: file
file_name: docs/generated-spec.md
prepend: |
<!-- generated by pi-chains -->
append: |
<!-- end generated file -->Run it:
/chain spec-to-file Write a spec for adding SSO to the dashboard
Use triggerTurn when the chain should feed another turn automatically.
plan-then-act:
description: Produce a plan and immediately hand it back into Pi
steps:
- agent: researcher
prompt: |
Break the task into an execution plan with risks and assumptions.
- output: triggerTurn
display: true
prepend: |
Continue from this generated plan:For the first agent, the task is the user task you pass to the chain.
For later agents, the extension builds a structured context block that includes:
- The original user input
- Earlier agent names and descriptions
- Earlier agent outputs
That means later agents can work from the full prior chain context instead of only the last step's raw output.
- Create a few focused agent files.
- Define one or more chains in
.pi/agents/agent-chain.yaml. - Start Pi with this extension installed, or launch it with
--extension. - Run
/chain-listto confirm the chains were loaded. - Run
/chain <name> <task...>or callrun_chain.
Install dependencies:
npm installType-check:
npx tsc --noEmitRun tests:
npm test