pi-agent-flow 1.0.4 → 1.0.5
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/flow.ts +41 -8
- package/package.json +1 -1
package/flow.ts
CHANGED
|
@@ -104,6 +104,8 @@ function buildFlowArgs(
|
|
|
104
104
|
intent: string,
|
|
105
105
|
forkSessionPath: string | null,
|
|
106
106
|
tieredModels?: { lite?: string; flash?: string; full?: string },
|
|
107
|
+
parentDepth: number = 0,
|
|
108
|
+
maxDepth: number = 0,
|
|
107
109
|
): string[] {
|
|
108
110
|
const args: string[] = [
|
|
109
111
|
"--mode",
|
|
@@ -138,17 +140,46 @@ function buildFlowArgs(
|
|
|
138
140
|
// No --append-system-prompt: child inherits parent's system prompt for cache hits.
|
|
139
141
|
// Flow instructions go in the intent message instead.
|
|
140
142
|
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
143
|
+
const currentDepth = Math.max(0, Math.floor(parentDepth)) + 1;
|
|
144
|
+
const effectiveMaxDepth = Math.max(0, Math.floor(maxDepth));
|
|
145
|
+
const canDelegate = currentDepth < effectiveMaxDepth;
|
|
146
|
+
const availableTools = flow.tools?.join(", ") ?? "all";
|
|
147
|
+
|
|
148
|
+
// Phase 1: Context seal — sharp boundary declaring history sealed
|
|
149
|
+
const contextSeal =
|
|
150
|
+
`<context-seal>\n` +
|
|
151
|
+
`The conversation above is sealed — it is your session history for situational awareness only.\n` +
|
|
152
|
+
`Your task begins NOW. Do not respond to or continue anything from the history.\n` +
|
|
153
|
+
`</context-seal>`;
|
|
154
|
+
|
|
155
|
+
// Phase 2: Activation — role, tools, depth, delegation rules (dynamically generated)
|
|
156
|
+
const delegationRule = canDelegate
|
|
157
|
+
? `You may delegate to sub-flows (depth ${currentDepth}/${effectiveMaxDepth}).`
|
|
158
|
+
: `You may NOT delegate to sub-flows (depth limit reached).`;
|
|
159
|
+
|
|
160
|
+
const activation =
|
|
161
|
+
`\n\n<activation flow="${flow.name}" depth="${currentDepth}" tools="${availableTools}">\n` +
|
|
162
|
+
`You are a [${flow.name}] agent operating at depth ${currentDepth}.\n` +
|
|
163
|
+
`Available tools: ${availableTools}.\n` +
|
|
164
|
+
`${delegationRule}\n` +
|
|
165
|
+
`Do not attempt to use any tool outside the available set — it will fail.\n` +
|
|
166
|
+
`</activation>`;
|
|
167
|
+
|
|
168
|
+
// Phase 3: Directive — the flow's system prompt (renamed from <system-directive>)
|
|
169
|
+
const directive = flow.systemPrompt.trim()
|
|
170
|
+
? `\n\n<directive>\n${flow.systemPrompt.trim()}\n</directive>`
|
|
148
171
|
: "";
|
|
149
172
|
|
|
173
|
+
// Phase 4: Mission — the intent wrapped with execution contract
|
|
174
|
+
const mission =
|
|
175
|
+
`\n\n<mission>\n` +
|
|
176
|
+
`${intent}\n` +
|
|
177
|
+
`\nExecute this mission. Use only your available tools. If blocked, report why — do not guess.\n` +
|
|
178
|
+
`Follow the output format specified in your directive.\n` +
|
|
179
|
+
`</mission>`;
|
|
180
|
+
|
|
150
181
|
// -p must immediately precede the prompt so the CLI parser binds it correctly
|
|
151
|
-
args.push("-p", `${
|
|
182
|
+
args.push("-p", `${contextSeal}${activation}${directive}${mission}`);
|
|
152
183
|
return args;
|
|
153
184
|
}
|
|
154
185
|
|
|
@@ -269,6 +300,8 @@ export async function runFlow(opts: RunFlowOptions): Promise<SingleResult> {
|
|
|
269
300
|
intent,
|
|
270
301
|
forkSessionTmpPath,
|
|
271
302
|
opts.tieredModels,
|
|
303
|
+
parentDepth,
|
|
304
|
+
maxDepth,
|
|
272
305
|
);
|
|
273
306
|
let wasAborted = false;
|
|
274
307
|
|