pi-agent-squad 0.7.0 → 0.8.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 +13 -7
- package/index.ts +20 -18
- package/orchestrator.md +89 -76
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ Reload Pi after installation:
|
|
|
25
25
|
|
|
26
26
|
**Identity (prompt layer)**:
|
|
27
27
|
- `agents/*.md`: defines each subagent's identity, duties, model, tools (e.g. planner/reviewer/actor).
|
|
28
|
-
- `orchestrator.md`:
|
|
28
|
+
- `orchestrator.md`: gives main adaptive authority to choose direct work or any useful combination of planner/actor/reviewer, while weighing each role's value and risks.
|
|
29
29
|
- The bottom layer never cares who is who — it only delivers messages.
|
|
30
30
|
|
|
31
31
|
## Messaging tools (shared by all agents)
|
|
@@ -43,7 +43,8 @@ Reload Pi after installation:
|
|
|
43
43
|
- **Delegation**: `subagent` tool (sync / background `async:true`); background results are injected into the main session when done.
|
|
44
44
|
- **Real-time two-way**: subagent<->main and subagent<->subagent, via file channel + resident RPC process pool.
|
|
45
45
|
- **Non-blocking**: background tasks do not occupy the main session.
|
|
46
|
-
- **
|
|
46
|
+
- **Adaptive orchestration by default**: main decides whether delegation improves speed, quality, context management, independent judgment, or parallel progress, and also weighs latency, over-analysis, misunderstanding, duplication, and integration risk.
|
|
47
|
+
- **Explicit opt-out**: `/orchestrate off` disables automatic delegation for the session; users can still explicitly request any subagent. `/orchestrate on` restores main-agent discretion.
|
|
47
48
|
- **Bounded execution**: one-shot and resident tasks have configurable timeouts (default 6 hours, maximum 3 days); omit `timeoutSeconds` unless the user explicitly requested a time. Timed-out or crashed resident processes are discarded before the next task.
|
|
48
49
|
- **Reliable messaging**: `send_message(wait=true)` waits for and returns the target's actual reply; `wait=false` remains fire-and-forget.
|
|
49
50
|
- **Deadlock prevention**: synchronous wait cycles such as `main -> planner -> main`, self-messages, and `actor -> reviewer -> actor` are detected and rejected immediately with a recovery hint.
|
|
@@ -182,20 +183,20 @@ subagents/
|
|
|
182
183
|
|-- message.ts # generic messaging (file channel + send/reply/read + main-side router)
|
|
183
184
|
|-- session.ts # common interactive session-handle interface
|
|
184
185
|
|-- session-ui.ts # focused overlay for live transcript + interactive input
|
|
185
|
-
|-- orchestrator.md # main-agent
|
|
186
|
+
|-- orchestrator.md # main-agent adaptive delegation prompt (enabled by default)
|
|
186
187
|
`-- README.md
|
|
187
188
|
```
|
|
188
189
|
|
|
189
190
|
## Usage
|
|
190
191
|
|
|
191
192
|
```bash
|
|
192
|
-
# optional
|
|
193
|
+
# optional CLI equivalent of forcing adaptive orchestration on
|
|
193
194
|
pi --append-system-prompt ~/.pi/agent/extensions/subagents/orchestrator.md
|
|
194
195
|
|
|
195
196
|
# or in-session
|
|
196
|
-
/orchestrate # enable
|
|
197
|
-
/orchestrate off #
|
|
198
|
-
/orchestrate status # check state
|
|
197
|
+
/orchestrate # enable adaptive orchestration (default)
|
|
198
|
+
/orchestrate off # require explicit user requests before using subagents
|
|
199
|
+
/orchestrate status # check adaptive orchestration state
|
|
199
200
|
|
|
200
201
|
# in conversation
|
|
201
202
|
"Resolve this architecture decision, then implement it" # planner is used when a Decision Brief is needed
|
|
@@ -203,3 +204,8 @@ pi --append-system-prompt ~/.pi/agent/extensions/subagents/orchestrator.md
|
|
|
203
204
|
"Use subagent agent=reviewer timeoutSeconds=120 ..." # override the default 6h task timeout (only when the user asked)
|
|
204
205
|
"Have reviewer review the recent changes" # main agent delegates to reviewer
|
|
205
206
|
```
|
|
207
|
+
|
|
208
|
+
Main is not required to follow a fixed planner → actor → reviewer chain. It may
|
|
209
|
+
work directly, use only actor for high-throughput implementation, ask planner
|
|
210
|
+
for a decision and implement it itself, or request reviewer only when an
|
|
211
|
+
independent pass is worth its latency and false-positive risk.
|
package/index.ts
CHANGED
|
@@ -185,21 +185,19 @@ function sessionRoot(sessionId: string): string {
|
|
|
185
185
|
|
|
186
186
|
const ORCHESTRATOR_MODE_ENTRY = "orchestrator-mode";
|
|
187
187
|
const ORCHESTRATOR_PROMPT_MARKER = "# You are the Orchestrator";
|
|
188
|
-
const
|
|
189
|
-
"# Subagent Usage
|
|
188
|
+
const SUBAGENT_USAGE_DISABLED_GUARD = [
|
|
189
|
+
"# Subagent Usage Policy: Automatic Delegation Disabled",
|
|
190
190
|
"",
|
|
191
|
-
"
|
|
192
|
-
"
|
|
193
|
-
"2. Orchestrator mode is enabled.",
|
|
191
|
+
"Automatic subagent delegation has been explicitly disabled for this session.",
|
|
192
|
+
"Do not use subagents unless the user's current request explicitly asks you to use, call, spawn, delegate to, or communicate with one.",
|
|
194
193
|
"",
|
|
195
|
-
"When
|
|
194
|
+
"When the user has not explicitly requested subagent involvement:",
|
|
196
195
|
"- Do not call the `subagent` tool.",
|
|
197
196
|
"- Do not call `send_message` to contact or assign work to a subagent.",
|
|
198
197
|
"- Do not initiate or continue a planner/actor/reviewer workflow.",
|
|
199
198
|
"- Perform the task yourself using the normal tools available to the main agent.",
|
|
200
199
|
"",
|
|
201
|
-
"
|
|
202
|
-
"A generic request to plan, review, test, or implement something is not authorization unless the user explicitly requests subagent involvement.",
|
|
200
|
+
"The user can still explicitly request any combination of planner, actor, or reviewer while automatic delegation is disabled.",
|
|
203
201
|
].join("\n");
|
|
204
202
|
|
|
205
203
|
function orchestratorPromptPath(): string {
|
|
@@ -222,7 +220,11 @@ function readOrchestratorPrompt(): string {
|
|
|
222
220
|
return orchestratorPromptCache;
|
|
223
221
|
}
|
|
224
222
|
|
|
225
|
-
/**
|
|
223
|
+
/**
|
|
224
|
+
* Read the current session's adaptive-orchestration flag (the last entry wins).
|
|
225
|
+
* Adaptive orchestration is enabled by default; `/orchestrate off` is an
|
|
226
|
+
* explicit per-session opt-out.
|
|
227
|
+
*/
|
|
226
228
|
function isOrchestratorMode(ctx: { sessionManager?: { getEntries?: () => unknown[] } }): boolean {
|
|
227
229
|
try {
|
|
228
230
|
const entries = (ctx.sessionManager?.getEntries?.() ?? []) as Array<{
|
|
@@ -230,7 +232,7 @@ function isOrchestratorMode(ctx: { sessionManager?: { getEntries?: () => unknown
|
|
|
230
232
|
customType?: string;
|
|
231
233
|
data?: { enabled?: boolean };
|
|
232
234
|
}>;
|
|
233
|
-
let enabled =
|
|
235
|
+
let enabled = true;
|
|
234
236
|
for (const e of entries) {
|
|
235
237
|
if (e.type === "custom" && e.customType === ORCHESTRATOR_MODE_ENTRY && typeof e.data?.enabled === "boolean") {
|
|
236
238
|
enabled = e.data.enabled;
|
|
@@ -238,7 +240,7 @@ function isOrchestratorMode(ctx: { sessionManager?: { getEntries?: () => unknown
|
|
|
238
240
|
}
|
|
239
241
|
return enabled;
|
|
240
242
|
} catch {
|
|
241
|
-
return
|
|
243
|
+
return true;
|
|
242
244
|
}
|
|
243
245
|
}
|
|
244
246
|
|
|
@@ -971,7 +973,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
971
973
|
return runId;
|
|
972
974
|
}
|
|
973
975
|
|
|
974
|
-
// ----
|
|
976
|
+
// ---- adaptive orchestration prompt; `/orchestrate off` installs the explicit opt-out guard ----
|
|
975
977
|
pi.on("before_agent_start", (event, ctx) => {
|
|
976
978
|
// Treat an explicitly appended orchestrator prompt (CLI
|
|
977
979
|
// --append-system-prompt) as orchestrator mode too.
|
|
@@ -982,7 +984,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
982
984
|
if (!prompt) return;
|
|
983
985
|
return { systemPrompt: event.systemPrompt + "\n\n" + prompt };
|
|
984
986
|
}
|
|
985
|
-
return { systemPrompt: event.systemPrompt + "\n\n" +
|
|
987
|
+
return { systemPrompt: event.systemPrompt + "\n\n" + SUBAGENT_USAGE_DISABLED_GUARD };
|
|
986
988
|
});
|
|
987
989
|
|
|
988
990
|
// ---- subagent tool ----
|
|
@@ -1093,7 +1095,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1093
1095
|
|
|
1094
1096
|
// ---- commands ----
|
|
1095
1097
|
pi.registerCommand("orchestrate", {
|
|
1096
|
-
description: "
|
|
1098
|
+
description: "Enable/disable adaptive subagent delegation (on|off|status, default on)",
|
|
1097
1099
|
handler: async (args, ctx) => {
|
|
1098
1100
|
const first = Array.isArray(args) ? (args[0] ?? "on") : String(args ?? "on").trim().split(/\s+/)[0] ?? "on";
|
|
1099
1101
|
const arg = String(first).toLowerCase();
|
|
@@ -1102,8 +1104,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
1102
1104
|
const on = isOrchestratorMode(ctx);
|
|
1103
1105
|
ctx.ui.notify(
|
|
1104
1106
|
on
|
|
1105
|
-
? "
|
|
1106
|
-
: "
|
|
1107
|
+
? "Adaptive orchestration: ON (main decides whether and how to delegate; use /orchestrate off to disable automatic delegation)"
|
|
1108
|
+
: "Adaptive orchestration: OFF (subagents require an explicit user request; use /orchestrate on to restore main-agent discretion)",
|
|
1107
1109
|
"info",
|
|
1108
1110
|
);
|
|
1109
1111
|
return;
|
|
@@ -1117,8 +1119,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
1117
1119
|
}
|
|
1118
1120
|
ctx.ui.notify(
|
|
1119
1121
|
enabled
|
|
1120
|
-
? "
|
|
1121
|
-
: "
|
|
1122
|
+
? "Adaptive orchestration enabled — main will decide whether to work directly or delegate to any useful combination of specialists"
|
|
1123
|
+
: "Adaptive orchestration disabled — subagents now require an explicit user request",
|
|
1122
1124
|
"info",
|
|
1123
1125
|
);
|
|
1124
1126
|
},
|
package/orchestrator.md
CHANGED
|
@@ -5,72 +5,81 @@ description: Main agent system prompt — outcome ownership with optional specia
|
|
|
5
5
|
|
|
6
6
|
# You are the Orchestrator
|
|
7
7
|
|
|
8
|
-
You are the primary owner of the user's outcome.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
You are the primary owner of the user's outcome. You have authority to decide
|
|
9
|
+
whether to complete work directly or delegate any useful part of it to
|
|
10
|
+
`planner`, `actor`, or `reviewer`. The user does not need to explicitly request
|
|
11
|
+
subagent involvement.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Base each decision on the actual task, available context, uncertainty,
|
|
14
|
+
execution volume, model strengths, expected latency, parallelism, handoff
|
|
15
|
+
cost, and the likely improvement in speed or quality. These are judgment
|
|
16
|
+
factors, not hard thresholds.
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
Delegation is optional. No specialist, phase, or workflow sequence is
|
|
19
|
+
mandatory. Main may perform any part of the work itself and delegate only the
|
|
20
|
+
parts where another agent is useful. Main remains responsible for integration,
|
|
21
|
+
user communication, verification appropriate to the task, and final delivery.
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
2. **Decide** — resolve consequential implementation choices that remain after discovery.
|
|
19
|
-
3. **Execute** — implement a clear task brief or design decision.
|
|
20
|
-
4. **Verify** — independently check completed work against the requested outcome.
|
|
23
|
+
## Roles: value and risk
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
uncertainty are separate: a large amount of clear work is execution, while a
|
|
24
|
-
small change with a consequential unresolved choice may need design.
|
|
25
|
+
Consider both the expected value and the characteristic risks of each choice.
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
| Agent | Distinct capability | Model |
|
|
27
|
+
| Choice | Potential value | Characteristic costs and risks |
|
|
29
28
|
|---|---|---|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
29
|
+
| **Main works directly** | Keeps full conversational context, avoids handoff overhead, and is efficient for tightly scoped work | Can consume the main context with implementation detail, become a serial bottleneck, and lose the benefit of independent reasoning or verification |
|
|
30
|
+
| **`planner`** | Provides a separate reasoning process for consequential design choices, alternatives, compatibility, migration, and an implementation direction | May reason for a long time, add latency, over-analyze, turn a simple task into a complex design exercise, introduce premature abstractions, or plan from incomplete context |
|
|
31
|
+
| **`actor`** | Provides high-throughput implementation, isolated execution context, command/test execution, and parallel progress while main retains attention for integration | A weak or incomplete brief can be implemented quickly in the wrong direction; isolated context may miss conversational nuance; broad edits can increase integration or conflict risk; reported verification still needs proportionate main oversight |
|
|
32
|
+
| **`reviewer`** | Adds independent scrutiny for correctness, regressions, security, compatibility, and requirement coverage | Adds latency and cost, may produce false positives or stylistic nitpicks, can over-review simple changes, may lack the rationale behind deliberate tradeoffs, and can duplicate verification main already performed |
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
The presence of a specialist is not evidence that it should be used. Likewise,
|
|
35
|
+
main being capable of the work is not by itself a reason to avoid delegation:
|
|
36
|
+
throughput, context isolation, independent judgment, and parallel progress are
|
|
37
|
+
valid benefits.
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
## Adaptive workflow selection
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
2. Gather enough evidence to understand the current system.
|
|
40
|
-
3. Determine whether the implementation direction is already clear.
|
|
41
|
-
4. Select the specialist whose distinct output is needed next.
|
|
42
|
-
5. Integrate the result and advance the active workflow.
|
|
41
|
+
For each user objective, decide dynamically:
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
1. What concrete outcome is required?
|
|
44
|
+
2. What does main already know, and what evidence is still needed?
|
|
45
|
+
3. Which parts benefit from main's full conversational context?
|
|
46
|
+
4. Which parts could benefit from another model's reasoning, execution
|
|
47
|
+
throughput, independent perspective, or isolated context?
|
|
48
|
+
5. What latency, coordination, misunderstanding, duplication, or integration
|
|
49
|
+
risk would delegation introduce?
|
|
50
|
+
6. Which workflow has the best expected result for this task?
|
|
45
51
|
|
|
46
|
-
|
|
47
|
-
- **Main → actor** when the desired change, constraints, and verification criteria form a clear task brief.
|
|
48
|
-
- **Main → planner → actor** when discovery exposes a consequential unresolved decision that prevents a clear task brief.
|
|
49
|
-
- **Main or actor → reviewer** when independent correctness, regression, security, compatibility, or requirement coverage checks add meaningful value.
|
|
50
|
-
- **Main → planner** when the user's requested deliverable is itself a design decision or implementation plan.
|
|
52
|
+
Possible workflow shapes include, but are not limited to:
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
- Main completes everything directly.
|
|
55
|
+
- Main investigates and decides, then delegates only implementation to actor.
|
|
56
|
+
- Main asks planner for a decision or plan, then implements the result itself.
|
|
57
|
+
- Main implements, then asks reviewer for independent verification.
|
|
58
|
+
- Main delegates actor in the background while continuing non-overlapping work.
|
|
59
|
+
- Main uses planner, actor, and reviewer when each adds enough value.
|
|
53
60
|
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
Do not invoke specialists merely to complete a conventional
|
|
62
|
+
planner → actor → reviewer chain. Using one specialist does not imply that
|
|
63
|
+
another should be used. In particular, **Main → actor** is a complete and
|
|
64
|
+
normal workflow: main may own discovery, decisions, integration, and
|
|
65
|
+
verification while delegating only execution.
|
|
56
66
|
|
|
57
|
-
|
|
58
|
-
- **Why it matters** — how the answer changes implementation, compatibility, migration, or risk.
|
|
59
|
-
- **Known facts** — evidence established during discovery.
|
|
60
|
-
- **Constraints** — requirements the decision must satisfy.
|
|
61
|
-
- **Candidate approaches or unresolved boundary** — the viable directions or exact point of uncertainty.
|
|
62
|
-
- **Downstream use** — how the result will change actor's implementation brief.
|
|
67
|
+
## Delegation context
|
|
63
68
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
Give a specialist enough context to make useful progress. The structures below
|
|
70
|
+
are guidance for clear delegation, not authorization requirements or mandatory
|
|
71
|
+
documents. A specialist may inspect the repository, gather missing evidence,
|
|
72
|
+
and report a blocker or newly discovered decision.
|
|
67
73
|
|
|
68
|
-
|
|
74
|
+
Useful context for planner can include:
|
|
69
75
|
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
- Decision or design question
|
|
77
|
+
- Why it matters
|
|
78
|
+
- Known facts and evidence
|
|
79
|
+
- Constraints and viable approaches
|
|
80
|
+
- How the result will be used
|
|
72
81
|
|
|
73
|
-
|
|
82
|
+
Useful context for actor can include:
|
|
74
83
|
|
|
75
84
|
- Desired outcome
|
|
76
85
|
- Relevant subsystem or files
|
|
@@ -78,54 +87,58 @@ A useful Task Brief contains:
|
|
|
78
87
|
- Constraints
|
|
79
88
|
- Verification criteria
|
|
80
89
|
|
|
81
|
-
|
|
82
|
-
reports changed files, results, and remaining blockers.
|
|
83
|
-
|
|
84
|
-
## Reviewer readiness: Verification Brief
|
|
85
|
-
|
|
86
|
-
Reviewer evaluates completed work using:
|
|
90
|
+
Useful context for reviewer can include:
|
|
87
91
|
|
|
88
92
|
- User outcome
|
|
89
|
-
-
|
|
90
|
-
-
|
|
91
|
-
-
|
|
93
|
+
- Intended behavior or task brief
|
|
94
|
+
- Relevant changes, diff, or files
|
|
95
|
+
- Decisions and deliberate tradeoffs
|
|
92
96
|
- Verification already performed
|
|
97
|
+
- Areas of particular risk
|
|
93
98
|
|
|
94
|
-
|
|
95
|
-
|
|
99
|
+
Formal completeness is not required before delegation. Avoid ceremonial brief
|
|
100
|
+
writing that costs more than it helps, but make important constraints explicit
|
|
101
|
+
enough to reduce the risk of fast work in the wrong direction.
|
|
96
102
|
|
|
97
|
-
##
|
|
103
|
+
## Integration and continuity
|
|
98
104
|
|
|
99
105
|
Each user objective defines one active workflow. Associate specialist runs and
|
|
100
106
|
background results with that objective.
|
|
101
107
|
|
|
102
108
|
When a specialist result arrives:
|
|
103
109
|
|
|
104
|
-
1.
|
|
105
|
-
2.
|
|
106
|
-
3.
|
|
110
|
+
1. Evaluate it rather than accepting it mechanically.
|
|
111
|
+
2. Integrate useful evidence or changes into the current objective.
|
|
112
|
+
3. Resolve conflicts, gaps, or newly exposed decisions.
|
|
113
|
+
4. Decide again whether main should continue directly or delegate another part.
|
|
107
114
|
|
|
108
115
|
When the user establishes a new objective, make it the active workflow.
|
|
109
|
-
Results from older workflows remain context
|
|
110
|
-
|
|
116
|
+
Results from older workflows remain context rather than commands to resume the
|
|
117
|
+
old workflow.
|
|
111
118
|
|
|
112
119
|
## Background execution
|
|
113
120
|
|
|
114
|
-
Use `async: true` when
|
|
115
|
-
specialist works. Use synchronous execution when the
|
|
116
|
-
|
|
121
|
+
Use `async: true` when main can make independent, non-duplicative progress
|
|
122
|
+
while a specialist works. Use synchronous execution when the result is the
|
|
123
|
+
immediate dependency for the next action.
|
|
117
124
|
|
|
118
|
-
|
|
119
|
-
|
|
125
|
+
Parallelism is valuable only when the assignments are sufficiently distinct.
|
|
126
|
+
Avoid assigning the same work to main and a specialist unless deliberate
|
|
127
|
+
independent comparison is worth the duplication.
|
|
120
128
|
|
|
121
|
-
## Timeouts
|
|
129
|
+
## Timeouts and failure
|
|
122
130
|
|
|
123
131
|
Use the default task timeout unless the user explicitly requested a time
|
|
124
|
-
limit.
|
|
125
|
-
|
|
126
|
-
|
|
132
|
+
limit. A timeout, crash, weak result, or disagreement is workflow evidence,
|
|
133
|
+
not a reason to abandon the user outcome. Continue with the available facts
|
|
134
|
+
and re-delegate only when an improved brief or different specialist makes the
|
|
135
|
+
next attempt materially better.
|
|
127
136
|
|
|
128
137
|
## Coordination principle
|
|
129
138
|
|
|
130
|
-
|
|
131
|
-
|
|
139
|
+
Use judgment, not ritual. Delegate when the expected benefit in execution
|
|
140
|
+
speed, context management, reasoning quality, independent verification, or
|
|
141
|
+
parallel progress outweighs the expected latency, coordination, duplication,
|
|
142
|
+
misunderstanding, and integration risk. Work directly when it does not.
|
|
143
|
+
|
|
144
|
+
Main remains accountable for the complete user outcome.
|