@0perator/operator 0.1.356 → 0.1.357
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/config/scaffold.js +2 -1
- package/dist/engine/agent.js +29 -2
- package/dist/engine/loop-guard.js +25 -0
- package/package.json +1 -1
package/dist/config/scaffold.js
CHANGED
|
@@ -54,12 +54,13 @@ function settingsExample(version) {
|
|
|
54
54
|
telemetry: { enabled: true },
|
|
55
55
|
autonomy: { maxRounds: 200, maxTurnWallClockSec: 900 },
|
|
56
56
|
loopGuard: {
|
|
57
|
-
_about: "Stops a model that repeats itself. Defaults shown; omit the block to keep them. enabled:false turns it off. hardStop unset = notices only when you are in the session, ends the turn for headless runs; true/false forces it. warnAfter = occurrence that adds a note to the tool result; hardStopAfter = occurrence that ends the turn. caps are per turn (0 disables). repetition:false disables the repeated-output check.",
|
|
57
|
+
_about: "Stops a model that repeats itself. Defaults shown; omit the block to keep them. enabled:false turns it off. hardStop unset = notices only when you are in the session, ends the turn for headless runs; true/false forces it. warnAfter = occurrence that adds a note to the tool result; hardStopAfter = occurrence that ends the turn. caps are per turn (0 disables). repetition:false disables the repeated-output check. finishDirective:false ends the turn the moment recovery runs out; by default one final directive names the stall and forces a pivot instead.",
|
|
58
58
|
enabled: true,
|
|
59
59
|
warnAfter: { identicalCall: 3, exactFailure: 2, sameToolFailure: 3, noProgress: 2 },
|
|
60
60
|
hardStopAfter: { identicalCall: 5, exactFailure: 5, sameToolFailure: 8, noProgress: 5 },
|
|
61
61
|
caps: { webSearches: 50, subagents: 50 },
|
|
62
62
|
repetition: true,
|
|
63
|
+
finishDirective: true,
|
|
63
64
|
},
|
|
64
65
|
}, null, 2) + "\n";
|
|
65
66
|
}
|
package/dist/engine/agent.js
CHANGED
|
@@ -925,6 +925,15 @@ export async function runTurn(userInput, conversation, opts) {
|
|
|
925
925
|
const attempt = recovery.spend();
|
|
926
926
|
if (attempt === undefined) {
|
|
927
927
|
const d = guard?.halt ?? deadRoundStop(calls, Math.max(0, ...round.repeats.map((c) => callCounts.get(callSignature(c.name, c.args)) ?? 0)));
|
|
928
|
+
if (guardCfg.finishDirective) {
|
|
929
|
+
const dir = recovery.directive(d);
|
|
930
|
+
if (dir) {
|
|
931
|
+
guard?.resume();
|
|
932
|
+
guard?.forgetResults();
|
|
933
|
+
engineUser(dir);
|
|
934
|
+
return true;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
928
937
|
return stopTurn(loopStopNote({ ...d, message: d.message + (recovery.attempts ? `; ${recovery.attempts} recovery attempts used` : "") }), rounds + 1);
|
|
929
938
|
}
|
|
930
939
|
guard?.resume(); // this batch's halt (a hard limit, a re-worded completed action) is what the recovery answers
|
|
@@ -1677,8 +1686,17 @@ export async function runTurn(userInput, conversation, opts) {
|
|
|
1677
1686
|
loopNudge("stale_reread", staleRereadNudge(reread));
|
|
1678
1687
|
if (guard?.halt) {
|
|
1679
1688
|
const note = recovery.next(guard.halt);
|
|
1680
|
-
if (!note)
|
|
1689
|
+
if (!note) {
|
|
1690
|
+
if (guardCfg.finishDirective) {
|
|
1691
|
+
const dir = recovery.directive(guard.halt);
|
|
1692
|
+
if (dir) {
|
|
1693
|
+
guard.resume();
|
|
1694
|
+
engineUser(dir);
|
|
1695
|
+
continue;
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1681
1698
|
return stopTurn(loopStopNote({ ...guard.halt, message: guard.halt.message + (recovery.attempts ? `; ${recovery.attempts} recovery attempts used` : "") }), rounds + 1);
|
|
1699
|
+
}
|
|
1682
1700
|
guard.resume();
|
|
1683
1701
|
engineUser(note);
|
|
1684
1702
|
continue;
|
|
@@ -1783,8 +1801,17 @@ export async function runTurn(userInput, conversation, opts) {
|
|
|
1783
1801
|
loopNudge("stale_reread", staleRereadNudge(reread));
|
|
1784
1802
|
if (guard?.halt) {
|
|
1785
1803
|
const note = recovery.next(guard.halt);
|
|
1786
|
-
if (!note)
|
|
1804
|
+
if (!note) {
|
|
1805
|
+
if (guardCfg.finishDirective) {
|
|
1806
|
+
const dir = recovery.directive(guard.halt);
|
|
1807
|
+
if (dir) {
|
|
1808
|
+
guard.resume();
|
|
1809
|
+
engineUser(dir);
|
|
1810
|
+
continue;
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1787
1813
|
return stopTurn(loopStopNote({ ...guard.halt, message: guard.halt.message + (recovery.attempts ? `; ${recovery.attempts} recovery attempts used` : "") }), rounds + 1);
|
|
1814
|
+
}
|
|
1788
1815
|
guard.resume();
|
|
1789
1816
|
engineUser(note);
|
|
1790
1817
|
continue;
|
|
@@ -26,6 +26,7 @@ export function resolveLoopGuardConfig(raw, ctx) {
|
|
|
26
26
|
hardStop: typeof s.hardStop === "boolean" ? s.hardStop : ctx.unattended,
|
|
27
27
|
repetition: s.repetition !== false,
|
|
28
28
|
recoveryAttempts: Math.min(5, intAtLeast(s.recovery?.maxAttempts, 2, 0)),
|
|
29
|
+
finishDirective: s.finishDirective !== false,
|
|
29
30
|
stopOnNoWrite: s.stopOnNoWrite === true,
|
|
30
31
|
warnIdentical: intAtLeast(s.warnAfter?.identicalCall, d.warnIdentical, 2),
|
|
31
32
|
warnExactFailure: intAtLeast(s.warnAfter?.exactFailure, d.warnExactFailure, 1),
|
|
@@ -543,11 +544,14 @@ export function loopStopNote(d) {
|
|
|
543
544
|
export class LoopRecovery {
|
|
544
545
|
maxAttempts;
|
|
545
546
|
used = 0;
|
|
547
|
+
directiveSpent = false;
|
|
546
548
|
constructor(maxAttempts) {
|
|
547
549
|
this.maxAttempts = maxAttempts;
|
|
548
550
|
}
|
|
549
551
|
get attempts() { return this.used; }
|
|
550
552
|
get max() { return this.maxAttempts; }
|
|
553
|
+
/** The finish directive has been sent once (or is disabled): after it a stall is terminal again. */
|
|
554
|
+
get exhausted() { return this.used >= this.maxAttempts && this.directiveSpent; }
|
|
551
555
|
/** One attempt for a dead round (agent.ts recoverDeadRound), from the same budget; undefined once it is spent. That
|
|
552
556
|
* recovery puts the repeated calls' results in front of the model, so unlike next() a re-worded repeat of a COMPLETED
|
|
553
557
|
* action is recoverable there. */
|
|
@@ -566,6 +570,27 @@ export class LoopRecovery {
|
|
|
566
570
|
`repeat a side effect whose outcome is uncertain, invent missing information, or claim unverified success. ` +
|
|
567
571
|
`Continue within the existing time, token, round and resource limits.`;
|
|
568
572
|
}
|
|
573
|
+
/** The turn's LAST recovery: the budget is spent and the guard is about to end the turn. Instead of ending it, name
|
|
574
|
+
* the pattern back to the model in its own terms and force a pivot — the model has the objective and the evidence,
|
|
575
|
+
* the guard only has the repetition. One-shot: `directiveSpent` makes the next stall terminal, so this can never
|
|
576
|
+
* become an unbounded loop. Caps and a re-worded repeat of a COMPLETED action stay terminal (nothing to pivot to). */
|
|
577
|
+
directive(d) {
|
|
578
|
+
if (this.directiveSpent || this.maxAttempts <= 0)
|
|
579
|
+
return undefined;
|
|
580
|
+
if (d.code === "web_search_cap" || d.code === "subagent_cap" || d.code === "completed_action")
|
|
581
|
+
return undefined;
|
|
582
|
+
this.directiveSpent = true;
|
|
583
|
+
return `Loop guard — finish directive (the turn is NOT ending; this is the last note about this stall): ` +
|
|
584
|
+
`the pattern is ${d.message}. You have tried this route ${this.maxAttempts + 1}+ times and it is not moving. ` +
|
|
585
|
+
`Do NOT repeat the blocked action, do NOT re-gather the same context, and do NOT hand the decision back to the owner. ` +
|
|
586
|
+
`In ONE line, say what you assumed would work and what actually happened — then immediately pick the strongest of: ` +
|
|
587
|
+
`(a) a step of the task that does NOT depend on the blocked route, and do it now; ` +
|
|
588
|
+
`(b) a genuinely different mechanism for the same goal (another tool, another file, another command, another ` +
|
|
589
|
+
`endpoint, or offline evidence you already have); ` +
|
|
590
|
+
`(c) if the blocked route is load-bearing for the whole task, deliver the best partial you can and state the exact ` +
|
|
591
|
+
`blocker plus the one thing needed to clear it. ` +
|
|
592
|
+
`Finish something this turn. Never bypass a permission denial, invent missing information, or claim unverified success.`;
|
|
593
|
+
}
|
|
569
594
|
}
|
|
570
595
|
export const noEditNudge = (n) => `You've run ${n} rounds of tools without changing a file. If you've found the root cause, ` +
|
|
571
596
|
`make the change now and verify it. If you're still gathering context that's fine — but if you're ` +
|