agents-relay 2.0.101 → 2.0.102
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/dist/planner-runtime.js +1 -1
- package/dist/planner.js +19 -12
- package/package.json +1 -1
package/dist/planner-runtime.js
CHANGED
|
@@ -80,7 +80,7 @@ async function finishPlanner(ports, jobId, planId, executionId, error, raw) {
|
|
|
80
80
|
return;
|
|
81
81
|
const attempt = fresh.attempt ?? 0;
|
|
82
82
|
const maxAttempts = fresh.maxAttempts ?? (fresh.manualPlanning ? 1 : 3);
|
|
83
|
-
retry = attempt < maxAttempts;
|
|
83
|
+
retry = attempt < maxAttempts && !message.startsWith('Planner JSON correction failed after one retry:');
|
|
84
84
|
fresh.status = retry ? 'PLANNING' : 'FAILED';
|
|
85
85
|
fresh.retryFeedback = message;
|
|
86
86
|
fresh.error = message;
|
package/dist/planner.js
CHANGED
|
@@ -502,17 +502,14 @@ export class AgentObjectivePlanner {
|
|
|
502
502
|
this.agentFile = agentFile;
|
|
503
503
|
}
|
|
504
504
|
async plan(context, signal) {
|
|
505
|
-
const resolvedPlanner = context.executionContext?.agents.find(agent => agent.name === 'planner')?.path;
|
|
506
505
|
const effectivePlanner = context.executionContext ? await resolveAgentMarkdown('planner', BUNDLED_AGENTS_ROOT, context.executionContext.project.path) : undefined;
|
|
507
506
|
const instructions = effectivePlanner?.content ?? await readFile(this.agentFile, 'utf8');
|
|
508
507
|
const contract = await readFile(DEFAULT_TASK_JOB_CONTRACT, 'utf8');
|
|
509
508
|
const resolvedContext = context.executionContext ? executionContextPrompt(context.executionContext) + '\n\n' : '';
|
|
510
509
|
const prompt = (effectivePlanner ? `[Effective planner contract SHA-256: ${effectivePlanner.hash}]\n\n` : '') + instructions.trim() + '\n\n## Shared Task / Job Contract\n\n' + contract.trim() + '\n\n' + resolvedContext + '## Durable planner input\n\n' + plannerInput(context);
|
|
511
|
-
|
|
512
|
-
const child = spawnOwnedProcess(this.command, ['exec', '--json', '--',
|
|
513
|
-
let stdoutBuffer = '';
|
|
514
|
-
let finalMessage = '';
|
|
515
|
-
let stderrTail = '';
|
|
510
|
+
const runAgent = (input) => new Promise((resolve, reject) => {
|
|
511
|
+
const child = spawnOwnedProcess(this.command, ['exec', '--json', '--', input], { invocation: 'planner.agent', signal, correlation: { jobId: context.job.id }, spawn: { cwd: context.executionContext?.project.path, stdio: ['ignore', 'pipe', 'pipe'] } });
|
|
512
|
+
let stdoutBuffer = '', finalMessage = '', stderrTail = '';
|
|
516
513
|
const consume = (line) => {
|
|
517
514
|
const message = parsePlannerAgentMessage(line);
|
|
518
515
|
if (message)
|
|
@@ -538,13 +535,23 @@ export class AgentObjectivePlanner {
|
|
|
538
535
|
reject(new Error('Planner agent returned no final message'));
|
|
539
536
|
return;
|
|
540
537
|
}
|
|
541
|
-
|
|
542
|
-
resolve(parsePlannerOutput(finalMessage));
|
|
543
|
-
}
|
|
544
|
-
catch (error) {
|
|
545
|
-
reject(error);
|
|
546
|
-
}
|
|
538
|
+
resolve(finalMessage);
|
|
547
539
|
});
|
|
548
540
|
});
|
|
541
|
+
const first = await runAgent(prompt);
|
|
542
|
+
try {
|
|
543
|
+
return parsePlannerOutput(first);
|
|
544
|
+
}
|
|
545
|
+
catch (error) {
|
|
546
|
+
if (signal.aborted)
|
|
547
|
+
throw error;
|
|
548
|
+
const correction = `${prompt}\n\n## Format correction (one retry only)\nYour previous final response was not valid Planner JSON. Error: ${error instanceof Error ? error.message : String(error)}\nPrevious response (possibly truncated):\n${first.slice(0, 12000)}\nReturn exactly one valid JSON object conforming to the Planner contract. No prose, no second JSON object.`;
|
|
549
|
+
try {
|
|
550
|
+
return parsePlannerOutput(await runAgent(correction));
|
|
551
|
+
}
|
|
552
|
+
catch (retryError) {
|
|
553
|
+
throw new Error(`Planner JSON correction failed after one retry: ${retryError instanceof Error ? retryError.message : String(retryError)}`);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
549
556
|
}
|
|
550
557
|
}
|