@rohaquinlop/pi-subagents 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -1
- package/agents/researcher.md +1 -0
- package/agents/scout.md +1 -0
- package/agents/worker.md +2 -0
- package/index.ts +750 -20
- package/lib/error-helpers.ts +66 -0
- package/lib/helpers.ts +32 -1
- package/lib/loop-detector.ts +40 -0
- package/lib/pipeline-helpers.ts +53 -0
- package/lib/types.ts +53 -0
- package/package.json +40 -40
- package/tools/safe-bash.ts +5 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @rohaquinlop/pi-subagents
|
|
2
2
|
|
|
3
|
-
A [pi](https://github.com/earendil-works/pi) extension that registers
|
|
3
|
+
A [pi](https://github.com/earendil-works/pi) extension that registers three agent orchestration tools — `subagent`, `pipeline`, and `loop` — with three built-in agents:
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -22,6 +22,8 @@ pi install @rohaquinlop/pi-subagents
|
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
|
+
### Subagent — Single Agent Dispatch
|
|
26
|
+
|
|
25
27
|
One tool call = one subagent:
|
|
26
28
|
```json
|
|
27
29
|
{ "agent": "scout", "task": "Find all auth-related files in src/" }
|
|
@@ -31,6 +33,49 @@ To fan out, emit multiple `subagent` tool calls in the same assistant turn — p
|
|
|
31
33
|
|
|
32
34
|
Each subagent runs as an isolated `pi` process with no inherited context — all context must be in the task description.
|
|
33
35
|
|
|
36
|
+
### Pipeline — Sequential Agent Chains
|
|
37
|
+
|
|
38
|
+
Chain 2–5 agents in sequence where each agent's output feeds as context into the next. Use `{previous}` in a step's task to inject the prior step's output.
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{ "tool": "pipeline", "args": { "steps": [
|
|
42
|
+
{ "agent": "scout", "task": "Find all auth-related code in src/" },
|
|
43
|
+
{ "agent": "worker", "task": "Based on these findings:\n{previous}\n\nImplement password reset flow." }
|
|
44
|
+
]}}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Each step runs a separate subagent process. The pipeline stops on the first error. Per-step and total usage (tokens, cost, duration) are shown in the TUI.
|
|
48
|
+
|
|
49
|
+
### Loop — Iterative Refinement
|
|
50
|
+
|
|
51
|
+
Run the same agent 2–5 times, passing all prior iteration outputs as context. Optionally use a `judge` agent to stop early when quality is sufficient.
|
|
52
|
+
|
|
53
|
+
**Basic (fixed iterations):**
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{ "tool": "loop", "args": {
|
|
57
|
+
"agent": "worker",
|
|
58
|
+
"task": "Write a comprehensive README for this project.",
|
|
59
|
+
"max_iterations": 3
|
|
60
|
+
}}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**With judge for dynamic stopping:**
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{ "tool": "loop", "args": {
|
|
67
|
+
"agent": "worker",
|
|
68
|
+
"task": "Write a comprehensive README for this project.",
|
|
69
|
+
"max_iterations": 5,
|
|
70
|
+
"judge": {
|
|
71
|
+
"agent": "reviewer",
|
|
72
|
+
"criteria": "Is this README complete, well-structured, and ready for publication? Answer YES or NO."
|
|
73
|
+
}
|
|
74
|
+
}}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The judge evaluates each iteration's output. When satisfied (YES), the loop stops early — no wasted iterations. Judge feedback is passed back to the runner agent for refinement.
|
|
78
|
+
|
|
34
79
|
## Config
|
|
35
80
|
|
|
36
81
|
Optional `config.json` next to `index.ts`:
|
|
@@ -81,6 +126,14 @@ Frontmatter fields:
|
|
|
81
126
|
|
|
82
127
|
The markdown body becomes the agent's system prompt.
|
|
83
128
|
|
|
129
|
+
Agents can optionally declare a `connector` field in their frontmatter — a prompt template that wraps their output before it's passed as `{previous}` to the next agent in a pipeline:
|
|
130
|
+
|
|
131
|
+
```yaml
|
|
132
|
+
connector: "## Key findings from codebase exploration:\n\n{output}"
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Connectors use single-line format with `\n` for line breaks. They can be overridden per-step via the optional `connector` field on pipeline steps.
|
|
136
|
+
|
|
84
137
|
### 2. Register agents via `globalThis.__pi_subagents`
|
|
85
138
|
|
|
86
139
|
Pi loads extensions via jiti, which creates separate module instances. Direct imports from the subagents extension will reference a different `agents` array than the one the `subagent` tool uses. Use the `globalThis` bridge instead:
|
|
@@ -190,3 +243,7 @@ Matching is case-insensitive.
|
|
|
190
243
|
└── tools/ # Extensions loaded into subagent processes
|
|
191
244
|
└── safe-bash.ts # bash with dangerous command blocking
|
|
192
245
|
```
|
|
246
|
+
|
|
247
|
+
## Acknowledgements
|
|
248
|
+
|
|
249
|
+
The pipeline and loop tools are conceptually inspired by [RecursiveMAS](https://arxiv.org/abs/2604.25917) — a research framework for scaling agent collaboration through iterative refinement and system-level orchestration.
|
package/agents/researcher.md
CHANGED
|
@@ -4,6 +4,7 @@ description: Web researcher — searches the web and synthesizes findings
|
|
|
4
4
|
tools: web_search, web_fetch
|
|
5
5
|
model: deepseek-v4-flash
|
|
6
6
|
thinking: medium
|
|
7
|
+
connector: "## Research findings:\n\n{output}"
|
|
7
8
|
---
|
|
8
9
|
|
|
9
10
|
You are a research specialist. Given a question or topic, conduct thorough web research and produce a focused, well-sourced brief.
|
package/agents/scout.md
CHANGED
|
@@ -4,6 +4,7 @@ description: Fast codebase recon — explores files, finds patterns, maps archit
|
|
|
4
4
|
tools: read, grep, find, ls
|
|
5
5
|
model: deepseek-v4-flash
|
|
6
6
|
thinking: medium
|
|
7
|
+
connector: "## Key findings from codebase exploration:\n\n{output}"
|
|
7
8
|
---
|
|
8
9
|
|
|
9
10
|
You are a scout agent. Quickly investigate a codebase and return structured findings.
|
package/agents/worker.md
CHANGED
|
@@ -5,6 +5,7 @@ tools: read, write, edit, safe_bash, web_search, web_fetch, subagent
|
|
|
5
5
|
subagent_agents: scout, researcher
|
|
6
6
|
model: deepseek-v4-flash
|
|
7
7
|
thinking: medium
|
|
8
|
+
connector: "## Implementation results:\n\n{output}"
|
|
8
9
|
---
|
|
9
10
|
|
|
10
11
|
You are a worker agent. You operate in an isolated context — you have no knowledge of any prior conversation.
|
|
@@ -15,6 +16,7 @@ Guidelines:
|
|
|
15
16
|
- Read files before editing to understand existing code
|
|
16
17
|
- Make targeted edits, not wholesale rewrites
|
|
17
18
|
- Use safe_bash for running commands (tests, builds, installs, etc.)
|
|
19
|
+
- `safe_bash` has a 5-minute default timeout (300s). For long-running commands (builds, tests, installs), pass a larger `timeout`, e.g. `timeout: 600` for 10 minutes.
|
|
18
20
|
- If something fails, diagnose and fix it
|
|
19
21
|
- Report what you did and what changed when done
|
|
20
22
|
|