@lloyal-labs/lloyal-agents 1.7.0 → 2.1.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 +83 -99
- package/dist/Agent.d.ts +29 -3
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +24 -2
- package/dist/Agent.js.map +1 -1
- package/dist/AgentPolicy.d.ts +34 -17
- package/dist/AgentPolicy.d.ts.map +1 -1
- package/dist/AgentPolicy.js +87 -25
- package/dist/AgentPolicy.js.map +1 -1
- package/dist/Tool.d.ts +1 -1
- package/dist/Tool.js +1 -1
- package/dist/agent-pool.d.ts +18 -6
- package/dist/agent-pool.d.ts.map +1 -1
- package/dist/agent-pool.js +435 -168
- package/dist/agent-pool.js.map +1 -1
- package/dist/context.d.ts +22 -5
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +22 -5
- package/dist/context.js.map +1 -1
- package/dist/create-agent-pool.d.ts +39 -21
- package/dist/create-agent-pool.d.ts.map +1 -1
- package/dist/create-agent-pool.js +41 -17
- package/dist/create-agent-pool.js.map +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/dist/orchestrators.d.ts +161 -0
- package/dist/orchestrators.d.ts.map +1 -0
- package/dist/orchestrators.js +173 -0
- package/dist/orchestrators.js.map +1 -0
- package/dist/replay.d.ts +96 -0
- package/dist/replay.d.ts.map +1 -0
- package/dist/replay.js +108 -0
- package/dist/replay.js.map +1 -0
- package/dist/spine.d.ts +106 -0
- package/dist/spine.d.ts.map +1 -0
- package/dist/spine.js +155 -0
- package/dist/spine.js.map +1 -0
- package/dist/trace-types.d.ts +25 -5
- package/dist/trace-types.d.ts.map +1 -1
- package/dist/types.d.ts +50 -16
- package/dist/types.d.ts.map +1 -1
- package/dist/use-agent.d.ts +3 -3
- package/dist/use-agent.d.ts.map +1 -1
- package/dist/use-agent.js +16 -20
- package/dist/use-agent.js.map +1 -1
- package/package.json +5 -5
- package/dist/shared-root.d.ts +0 -58
- package/dist/shared-root.d.ts.map +0 -1
- package/dist/shared-root.js +0 -125
- package/dist/shared-root.js.map +0 -1
package/dist/AgentPolicy.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare const defaultToolGuards: ToolGuard[];
|
|
|
21
21
|
* Why the agent entered idle status.
|
|
22
22
|
* @category Agents
|
|
23
23
|
*/
|
|
24
|
-
export type IdleReason = '
|
|
24
|
+
export type IdleReason = 'returned' | 'pressure_critical' | 'pressure_softcut' | 'pressure_settle_reject' | 'settle_stall_break' | 'max_turns' | 'free_text_stop' | 'tool_error';
|
|
25
25
|
/**
|
|
26
26
|
* Action returned by policy.onProduced — tells the pool what to do.
|
|
27
27
|
* @category Agents
|
|
@@ -30,7 +30,7 @@ export type ProduceAction = {
|
|
|
30
30
|
type: 'tool_call';
|
|
31
31
|
tc: ParsedToolCall;
|
|
32
32
|
} | {
|
|
33
|
-
type: '
|
|
33
|
+
type: 'return';
|
|
34
34
|
result: string;
|
|
35
35
|
} | {
|
|
36
36
|
type: 'nudge';
|
|
@@ -39,7 +39,7 @@ export type ProduceAction = {
|
|
|
39
39
|
type: 'idle';
|
|
40
40
|
reason: IdleReason;
|
|
41
41
|
} | {
|
|
42
|
-
type: '
|
|
42
|
+
type: 'free_text_return';
|
|
43
43
|
content: string;
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
@@ -90,12 +90,20 @@ export interface AgentPolicy {
|
|
|
90
90
|
toolCalls: ParsedToolCall[];
|
|
91
91
|
}, pressure: ContextPressure, config: PolicyConfig): ProduceAction;
|
|
92
92
|
/**
|
|
93
|
-
* SETTLE
|
|
93
|
+
* SETTLE stall-break: consulted when deferred tool results have no
|
|
94
|
+
* active siblings to free KV — the last-resort moment where a policy
|
|
95
|
+
* decides whether to nudge the agent (replacing the oversized result
|
|
96
|
+
* with a compact error payload) or drop it and let recovery extract.
|
|
94
97
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
98
|
+
* In normal operation, SETTLE defers oversized items across ticks.
|
|
99
|
+
* Siblings completing (parallel) or the spine growing (chain) restores
|
|
100
|
+
* headroom on subsequent ticks — this hook fires only when all agents
|
|
101
|
+
* are `awaiting_tool`/idle and deferral can't resolve on its own.
|
|
102
|
+
*
|
|
103
|
+
* Return `{type: 'nudge'}` to replace the oversized item with a compact
|
|
104
|
+
* error payload (carries the budget in its message). Return
|
|
105
|
+
* `{type: 'idle', reason: 'pressure_settle_reject'}` to drop the agent.
|
|
106
|
+
* If the hook is absent, the pool falls back to `settle_stall_break`.
|
|
99
107
|
*/
|
|
100
108
|
onSettleReject(agent: Agent, resultTokens: number, pressure: ContextPressure, config: PolicyConfig): SettleAction;
|
|
101
109
|
/**
|
|
@@ -145,7 +153,7 @@ export interface AgentPolicy {
|
|
|
145
153
|
*
|
|
146
154
|
* Optional — defaults to skip when absent.
|
|
147
155
|
*/
|
|
148
|
-
onRecovery?(agent: Agent): RecoveryAction;
|
|
156
|
+
onRecovery?(agent: Agent, pressure: ContextPressure): RecoveryAction;
|
|
149
157
|
}
|
|
150
158
|
/**
|
|
151
159
|
* Pool-level configuration passed to policy methods.
|
|
@@ -153,7 +161,7 @@ export interface AgentPolicy {
|
|
|
153
161
|
*/
|
|
154
162
|
export interface PolicyConfig {
|
|
155
163
|
maxTurns: number;
|
|
156
|
-
|
|
164
|
+
terminalToolName?: string;
|
|
157
165
|
hasNonTerminalTools: boolean;
|
|
158
166
|
}
|
|
159
167
|
/**
|
|
@@ -170,8 +178,8 @@ export interface PolicyConfig {
|
|
|
170
178
|
* @category Agents
|
|
171
179
|
*/
|
|
172
180
|
export interface DefaultAgentPolicyOpts {
|
|
173
|
-
/** Min non-terminal tool calls before
|
|
174
|
-
|
|
181
|
+
/** Min non-terminal tool calls before a return is accepted without nudge. @default 2 */
|
|
182
|
+
minToolCallsBeforeReturn?: number;
|
|
175
183
|
/** Replace default tool guards entirely. */
|
|
176
184
|
guards?: ToolGuard[];
|
|
177
185
|
/** Append additional guards to the defaults. */
|
|
@@ -223,7 +231,7 @@ export interface DefaultAgentPolicyOpts {
|
|
|
223
231
|
/** Terminal tool name. When set, agents mid-generation of this tool are
|
|
224
232
|
* protected from shouldExit — the hard limit is deferred until the tool
|
|
225
233
|
* call completes naturally or KV pressure forces a kill. */
|
|
226
|
-
|
|
234
|
+
terminalToolName?: string;
|
|
227
235
|
}
|
|
228
236
|
export declare class DefaultAgentPolicy implements AgentPolicy {
|
|
229
237
|
private _minToolCalls;
|
|
@@ -233,9 +241,18 @@ export declare class DefaultAgentPolicy implements AgentPolicy {
|
|
|
233
241
|
private _forceExploit;
|
|
234
242
|
private _recovery;
|
|
235
243
|
private _budget;
|
|
236
|
-
private
|
|
244
|
+
private _terminalToolName;
|
|
237
245
|
private _startTime;
|
|
238
246
|
constructor(opts?: DefaultAgentPolicyOpts);
|
|
247
|
+
/**
|
|
248
|
+
* Elapsed wall time for *this agent* (since its first idle→active transition),
|
|
249
|
+
* falling back to the policy's own construction time when the agent hasn't
|
|
250
|
+
* started yet (defensive — shouldn't normally happen).
|
|
251
|
+
*
|
|
252
|
+
* Per-agent timing means orchestrators that spawn agents sequentially (e.g.
|
|
253
|
+
* `chain`) get the correct "how long has this task been running?" semantics
|
|
254
|
+
* without the time budget leaking across iterations.
|
|
255
|
+
*/
|
|
239
256
|
private _elapsed;
|
|
240
257
|
/** KV pressure thresholds for ContextPressure construction.
|
|
241
258
|
* Pool reads this once at setup. */
|
|
@@ -251,14 +268,14 @@ export declare class DefaultAgentPolicy implements AgentPolicy {
|
|
|
251
268
|
private _isOverBudget;
|
|
252
269
|
private _handleOverBudget;
|
|
253
270
|
private _checkGuards;
|
|
254
|
-
onSettleReject(agent: Agent, _resultTokens: number,
|
|
271
|
+
onSettleReject(agent: Agent, _resultTokens: number, pressure: ContextPressure, config: PolicyConfig): SettleAction;
|
|
255
272
|
/**
|
|
256
273
|
* UI-driven override. Harness calls this when the user wants agents
|
|
257
274
|
* to wrap up. Overrides pressure-based logic immediately.
|
|
258
275
|
*/
|
|
259
276
|
setExploitMode(force: boolean): void;
|
|
260
277
|
shouldExit(agent: Agent, pressure: ContextPressure): boolean;
|
|
261
|
-
shouldExplore(
|
|
278
|
+
shouldExplore(agent: Agent, pressure: ContextPressure): boolean;
|
|
262
279
|
/**
|
|
263
280
|
* Trailing stop: at most one agent nudged or killed per tick.
|
|
264
281
|
* The sacrificed agent's findings are extracted and its KV freed,
|
|
@@ -268,6 +285,6 @@ export declare class DefaultAgentPolicy implements AgentPolicy {
|
|
|
268
285
|
private _killedThisTick;
|
|
269
286
|
private _nudgedThisTick;
|
|
270
287
|
resetTick(): void;
|
|
271
|
-
onRecovery(agent: Agent): RecoveryAction;
|
|
288
|
+
onRecovery(agent: Agent, pressure: ContextPressure): RecoveryAction;
|
|
272
289
|
}
|
|
273
290
|
//# sourceMappingURL=AgentPolicy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentPolicy.d.ts","sourceRoot":"","sources":["../src/AgentPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"AgentPolicy.d.ts","sourceRoot":"","sources":["../src/AgentPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAA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AsB;IAczC;;;;;;;;OAQG;IACH,OAAO,CAAC,QAAQ;IAKhB;yCACqC;IACrC,IAAI,kBAAkB,IAAI,kBAAkB,CAO3C;IAED,UAAU,CACR,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,SAAS,EAAE,cAAc,EAAE,CAAA;KAAE,EAC/D,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,YAAY,GACnB,aAAa;IAqBhB,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,iBAAiB;IA2BzB,OAAO,CAAC,YAAY;IAYpB,cAAc,CACZ,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,YAAY,GACnB,YAAY;IAUf;;;OAGG;IACH,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAEpC,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,eAAe,GAAG,OAAO;IAiB5D,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,eAAe,GAAG,OAAO;IAY/D;;;;;OAKG;IACH,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,eAAe,CAAS;IAEhC,SAAS,IAAI,IAAI;IAKjB,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,eAAe,GAAG,cAAc;CAuBpE"}
|
package/dist/AgentPolicy.js
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DefaultAgentPolicy = exports.defaultToolGuards = void 0;
|
|
4
4
|
const agent_pool_1 = require("./agent-pool");
|
|
5
|
+
const prompt_1 = require("./prompt");
|
|
6
|
+
// Recovery-phase KV accounting constants. These size the hardLimit reserve
|
|
7
|
+
// allocation for recoverInline: the prefill cost of the recovery prompt +
|
|
8
|
+
// room for llama.cpp's batch workspace. Used to compute the budget
|
|
9
|
+
// communicated to the model in its recovery prompt.
|
|
10
|
+
const RECOVERY_PREFILL_OVERHEAD = 150;
|
|
11
|
+
const BATCH_BUFFER = 512;
|
|
12
|
+
/**
|
|
13
|
+
* Convert a token budget to a conservative word count for the model-facing
|
|
14
|
+
* prompt. Tokens are tokenizer-specific; words are universal and better
|
|
15
|
+
* reflected in training data. Applies a 0.7 words/token ratio (vs the
|
|
16
|
+
* typical ~0.75) to under-advertise the budget, rounds down to the nearest
|
|
17
|
+
* 10, and floors at 10 so the model always has a non-zero target.
|
|
18
|
+
*/
|
|
19
|
+
function tokenBudgetAsWords(budgetTokens) {
|
|
20
|
+
return Math.max(10, Math.floor(budgetTokens * 0.7 / 10) * 10);
|
|
21
|
+
}
|
|
5
22
|
/** Default guards for deduplication and recursion discipline */
|
|
6
23
|
function parseHistoryArgs(argsStr) {
|
|
7
24
|
try {
|
|
@@ -40,10 +57,10 @@ class DefaultAgentPolicy {
|
|
|
40
57
|
_forceExploit = false;
|
|
41
58
|
_recovery;
|
|
42
59
|
_budget;
|
|
43
|
-
|
|
60
|
+
_terminalToolName;
|
|
44
61
|
_startTime;
|
|
45
62
|
constructor(opts) {
|
|
46
|
-
this._minToolCalls = opts?.
|
|
63
|
+
this._minToolCalls = opts?.minToolCallsBeforeReturn ?? 2;
|
|
47
64
|
this._exploreContext = opts?.shouldExplore?.context ?? 0.4;
|
|
48
65
|
this._exploreTime = opts?.shouldExplore?.time ?? 0.5;
|
|
49
66
|
this._guards = opts?.guards ?? [
|
|
@@ -52,10 +69,22 @@ class DefaultAgentPolicy {
|
|
|
52
69
|
];
|
|
53
70
|
this._recovery = opts?.recovery ?? null;
|
|
54
71
|
this._budget = opts?.budget ?? null;
|
|
55
|
-
this.
|
|
72
|
+
this._terminalToolName = opts?.terminalToolName ?? null;
|
|
56
73
|
this._startTime = performance.now();
|
|
57
74
|
}
|
|
58
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Elapsed wall time for *this agent* (since its first idle→active transition),
|
|
77
|
+
* falling back to the policy's own construction time when the agent hasn't
|
|
78
|
+
* started yet (defensive — shouldn't normally happen).
|
|
79
|
+
*
|
|
80
|
+
* Per-agent timing means orchestrators that spawn agents sequentially (e.g.
|
|
81
|
+
* `chain`) get the correct "how long has this task been running?" semantics
|
|
82
|
+
* without the time budget leaking across iterations.
|
|
83
|
+
*/
|
|
84
|
+
_elapsed(agent) {
|
|
85
|
+
const started = agent?.startedAt ?? this._startTime;
|
|
86
|
+
return performance.now() - started;
|
|
87
|
+
}
|
|
59
88
|
/** KV pressure thresholds for ContextPressure construction.
|
|
60
89
|
* Pool reads this once at setup. */
|
|
61
90
|
get pressureThresholds() {
|
|
@@ -72,23 +101,31 @@ class DefaultAgentPolicy {
|
|
|
72
101
|
return this._handleNoToolCall(agent, parsed);
|
|
73
102
|
if (this._isTerminalTool(tc, config))
|
|
74
103
|
return this._handleTerminalTool(tc, agent, config, pressure);
|
|
75
|
-
|
|
76
|
-
|
|
104
|
+
// Guards before budget: when an agent is over budget AND emitting
|
|
105
|
+
// a tool call the guards already want to reject (duplicate query,
|
|
106
|
+
// duplicate fetch, delegation-before-research), the guard's specific
|
|
107
|
+
// message is more actionable than a generic "report now within N
|
|
108
|
+
// words" turn-limit nudge. Previously, `_isOverBudget` preempted the
|
|
109
|
+
// guard — stuck agents (same query repeated past maxTurns) saw only
|
|
110
|
+
// turn-limit nudges instead of the dedup message that named the
|
|
111
|
+
// actual problem (see trace-1776819196054 agent 65539).
|
|
77
112
|
const guardRejection = this._checkGuards(tc, agent);
|
|
78
113
|
if (guardRejection)
|
|
79
114
|
return guardRejection;
|
|
115
|
+
if (this._isOverBudget(agent, tc, pressure, config))
|
|
116
|
+
return this._handleOverBudget(agent, tc, pressure, config);
|
|
80
117
|
// Normal tool call
|
|
81
118
|
return { type: 'tool_call', tc };
|
|
82
119
|
}
|
|
83
120
|
// ── onProduced decision predicates ─────────────────────
|
|
84
121
|
_handleNoToolCall(agent, parsed) {
|
|
85
122
|
if (!agent.result && agent.toolCallCount > 0 && parsed.content) {
|
|
86
|
-
return { type: '
|
|
123
|
+
return { type: 'free_text_return', content: parsed.content };
|
|
87
124
|
}
|
|
88
125
|
return { type: 'idle', reason: 'free_text_stop' };
|
|
89
126
|
}
|
|
90
127
|
_isTerminalTool(tc, config) {
|
|
91
|
-
return !!(config.
|
|
128
|
+
return !!(config.terminalToolName && tc.name === config.terminalToolName);
|
|
92
129
|
}
|
|
93
130
|
_handleTerminalTool(tc, agent, config, pressure) {
|
|
94
131
|
const underPressure = this._isUnderPressure(agent, pressure, config);
|
|
@@ -102,28 +139,34 @@ class DefaultAgentPolicy {
|
|
|
102
139
|
catch {
|
|
103
140
|
result = tc.arguments;
|
|
104
141
|
}
|
|
105
|
-
return { type: '
|
|
142
|
+
return { type: 'return', result };
|
|
106
143
|
}
|
|
107
144
|
_isUnderPressure(agent, pressure, config) {
|
|
108
145
|
const timeSoft = this._budget?.time?.softLimit;
|
|
109
|
-
const timeNudge = timeSoft != null && this._elapsed() >= timeSoft;
|
|
146
|
+
const timeNudge = timeSoft != null && this._elapsed(agent) >= timeSoft;
|
|
110
147
|
return agent.turns >= config.maxTurns || pressure.headroom < 0 || timeNudge;
|
|
111
148
|
}
|
|
112
149
|
_isOverBudget(agent, tc, pressure, config) {
|
|
113
150
|
const underPressure = this._isUnderPressure(agent, pressure, config);
|
|
114
|
-
return underPressure && (!config.
|
|
151
|
+
return underPressure && (!config.terminalToolName || tc.name !== config.terminalToolName);
|
|
115
152
|
}
|
|
116
153
|
_handleOverBudget(agent, tc, pressure, config) {
|
|
117
154
|
const timeSoft = this._budget?.time?.softLimit;
|
|
118
|
-
const timeNudge = timeSoft != null && this._elapsed() >= timeSoft;
|
|
119
|
-
if (config.
|
|
155
|
+
const timeNudge = timeSoft != null && this._elapsed(agent) >= timeSoft;
|
|
156
|
+
if (config.terminalToolName && agent.toolCallCount > 0 && !pressure.critical) {
|
|
120
157
|
if (!this._nudgedThisTick) {
|
|
121
158
|
this._nudgedThisTick = true;
|
|
159
|
+
// Budget the model can emit before `pressure.critical` kills it.
|
|
160
|
+
// Overshoot → kill → recoverInline extracts from the hardLimit reserve.
|
|
161
|
+
// Expressed in words (not tokens) because tokenizers vary across
|
|
162
|
+
// models but words are universal. Under-advertised + rounded down
|
|
163
|
+
// so the model has slack on the ceiling.
|
|
164
|
+
const words = tokenBudgetAsWords(pressure.remaining - pressure.hardLimit);
|
|
122
165
|
const msg = timeNudge
|
|
123
|
-
?
|
|
166
|
+
? `Time limit reached — report your findings now within ${words} words.`
|
|
124
167
|
: agent.turns >= config.maxTurns
|
|
125
|
-
?
|
|
126
|
-
:
|
|
168
|
+
? `Turn limit reached — report your findings now within ${words} words.`
|
|
169
|
+
: `KV memory pressure — report your findings now within ${words} words.`;
|
|
127
170
|
return { type: 'nudge', message: msg };
|
|
128
171
|
}
|
|
129
172
|
return { type: 'tool_call', tc };
|
|
@@ -146,10 +189,11 @@ class DefaultAgentPolicy {
|
|
|
146
189
|
}
|
|
147
190
|
return null;
|
|
148
191
|
}
|
|
149
|
-
onSettleReject(agent, _resultTokens,
|
|
192
|
+
onSettleReject(agent, _resultTokens, pressure, config) {
|
|
150
193
|
// Nudge if possible — stateless, no escalation tracking
|
|
151
|
-
if (config.
|
|
152
|
-
|
|
194
|
+
if (config.terminalToolName && agent.toolCallCount > 0) {
|
|
195
|
+
const words = tokenBudgetAsWords(pressure.remaining - pressure.hardLimit);
|
|
196
|
+
return { type: 'nudge', message: `Tool result too large for remaining KV. Report your findings now within ${words} words.` };
|
|
153
197
|
}
|
|
154
198
|
// No terminal tool: kill
|
|
155
199
|
return { type: 'idle', reason: 'pressure_settle_reject' };
|
|
@@ -160,11 +204,15 @@ class DefaultAgentPolicy {
|
|
|
160
204
|
*/
|
|
161
205
|
setExploitMode(force) { this._forceExploit = force; }
|
|
162
206
|
shouldExit(agent, pressure) {
|
|
163
|
-
|
|
207
|
+
// Terminal-tool protection applies in the graceful zone only — once
|
|
208
|
+
// `pressure.critical` fires, the agent must yield so the pool can
|
|
209
|
+
// kill+recover before native OOM. Holding this protection through
|
|
210
|
+
// critical territory was the DOJ runaway cause (trace-1776782401659).
|
|
211
|
+
if (this._terminalToolName && agent.currentTool === this._terminalToolName && !pressure.critical)
|
|
164
212
|
return false;
|
|
165
213
|
if (!pressure.critical) {
|
|
166
214
|
const timeHard = this._budget?.time?.hardLimit;
|
|
167
|
-
if (timeHard != null && this._elapsed() >= timeHard)
|
|
215
|
+
if (timeHard != null && this._elapsed(agent) >= timeHard)
|
|
168
216
|
return true;
|
|
169
217
|
return false;
|
|
170
218
|
}
|
|
@@ -173,14 +221,14 @@ class DefaultAgentPolicy {
|
|
|
173
221
|
this._killedThisTick = true;
|
|
174
222
|
return true;
|
|
175
223
|
}
|
|
176
|
-
shouldExplore(
|
|
224
|
+
shouldExplore(agent, pressure) {
|
|
177
225
|
if (this._forceExploit)
|
|
178
226
|
return false;
|
|
179
227
|
const contextOk = pressure.percentAvailable / 100 > this._exploreContext;
|
|
180
228
|
const timeSoftLimit = this._budget?.time?.softLimit;
|
|
181
229
|
const timeOk = timeSoftLimit == null
|
|
182
230
|
? true
|
|
183
|
-
: this._elapsed() / timeSoftLimit < this._exploreTime;
|
|
231
|
+
: this._elapsed(agent) / timeSoftLimit < this._exploreTime;
|
|
184
232
|
return contextOk && timeOk;
|
|
185
233
|
}
|
|
186
234
|
/**
|
|
@@ -195,7 +243,7 @@ class DefaultAgentPolicy {
|
|
|
195
243
|
this._killedThisTick = false;
|
|
196
244
|
this._nudgedThisTick = false;
|
|
197
245
|
}
|
|
198
|
-
onRecovery(agent) {
|
|
246
|
+
onRecovery(agent, pressure) {
|
|
199
247
|
if (!this._recovery)
|
|
200
248
|
return { type: 'skip' };
|
|
201
249
|
const minTokens = this._recovery.minTokens ?? 100;
|
|
@@ -203,7 +251,21 @@ class DefaultAgentPolicy {
|
|
|
203
251
|
if (agent.tokenCount < minTokens || agent.toolCallCount < minToolCalls) {
|
|
204
252
|
return { type: 'skip' };
|
|
205
253
|
}
|
|
206
|
-
|
|
254
|
+
// Budget recovery's generation can consume: hardLimit reserve minus the
|
|
255
|
+
// prefill overhead and llama.cpp's batch workspace. Expressed as words
|
|
256
|
+
// (not tokens) and under-advertised so the model has slack — tokenizers
|
|
257
|
+
// vary across models but words are universal. Rendered into the prompt
|
|
258
|
+
// as `it.budget` so authors can reference it via `<%= it.budget %>`.
|
|
259
|
+
const budgetTokens = Math.max(50, pressure.remaining - RECOVERY_PREFILL_OVERHEAD - BATCH_BUFFER);
|
|
260
|
+
const budget = tokenBudgetAsWords(budgetTokens);
|
|
261
|
+
const tctx = { budget };
|
|
262
|
+
return {
|
|
263
|
+
type: 'extract',
|
|
264
|
+
prompt: {
|
|
265
|
+
system: (0, prompt_1.renderTemplate)(this._recovery.prompt.system, tctx),
|
|
266
|
+
user: (0, prompt_1.renderTemplate)(this._recovery.prompt.user, tctx),
|
|
267
|
+
},
|
|
268
|
+
};
|
|
207
269
|
}
|
|
208
270
|
}
|
|
209
271
|
exports.DefaultAgentPolicy = DefaultAgentPolicy;
|
package/dist/AgentPolicy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentPolicy.js","sourceRoot":"","sources":["../src/AgentPolicy.ts"],"names":[],"mappings":";;;AACA,6CAA+C;
|
|
1
|
+
{"version":3,"file":"AgentPolicy.js","sourceRoot":"","sources":["../src/AgentPolicy.ts"],"names":[],"mappings":";;;AACA,6CAA+C;AAG/C,qCAA0C;AAE1C,2EAA2E;AAC3E,0EAA0E;AAC1E,mEAAmE;AACnE,oDAAoD;AACpD,MAAM,yBAAyB,GAAG,GAAG,CAAC;AACtC,MAAM,YAAY,GAAG,GAAG,CAAC;AAEzB;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,YAA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AAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC;aACvD;SACF,CAAC;IACJ,CAAC;CACF;AA9OD,gDA8OC"}
|
package/dist/Tool.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type { JsonSchema, ToolSchema, ToolContext } from './types';
|
|
|
13
13
|
* {@link runAgents}.
|
|
14
14
|
*
|
|
15
15
|
* `execute()` returns an Effection `Operation`, enabling tools to
|
|
16
|
-
* spawn sub-agents via {@link
|
|
16
|
+
* spawn sub-agents via {@link agentPool} or {@link withSpine}.
|
|
17
17
|
* For async work, wrap in `call()`. For synchronous tools, return
|
|
18
18
|
* directly from the generator body.
|
|
19
19
|
*
|
package/dist/Tool.js
CHANGED
|
@@ -14,7 +14,7 @@ exports.Tool = void 0;
|
|
|
14
14
|
* {@link runAgents}.
|
|
15
15
|
*
|
|
16
16
|
* `execute()` returns an Effection `Operation`, enabling tools to
|
|
17
|
-
* spawn sub-agents via {@link
|
|
17
|
+
* spawn sub-agents via {@link agentPool} or {@link withSpine}.
|
|
18
18
|
* For async work, wrap in `call()`. For synchronous tools, return
|
|
19
19
|
* directly from the generator body.
|
|
20
20
|
*
|
package/dist/agent-pool.d.ts
CHANGED
|
@@ -44,8 +44,20 @@ import type { PressureThresholds, AgentPoolOptions, AgentPoolResult, AgentEvent
|
|
|
44
44
|
export declare class ContextPressure {
|
|
45
45
|
/** Default softLimit: 1024 tokens reserved for downstream work */
|
|
46
46
|
static readonly DEFAULT_SOFT_LIMIT = 1024;
|
|
47
|
-
/**
|
|
48
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Default hardLimit: 512 tokens — matches llama.cpp's default `n_batch`.
|
|
49
|
+
* The pool validates at startup that `hardLimit >= nBatch`; the default
|
|
50
|
+
* is sized to satisfy the invariant for the default llama.cpp context.
|
|
51
|
+
* Recovery fits within the `hardLimit` reserve.
|
|
52
|
+
*/
|
|
53
|
+
static readonly DEFAULT_HARD_LIMIT = 512;
|
|
54
|
+
/**
|
|
55
|
+
* Assumed `nBatch` when the native binding doesn't expose it.
|
|
56
|
+
* Pool startup validates `pressureThresholds.hardLimit >= this`.
|
|
57
|
+
* TODO: once `SessionContext.nBatch` is exposed (lloyal.node
|
|
58
|
+
* follow-up), read from ctx.nBatch instead.
|
|
59
|
+
*/
|
|
60
|
+
static readonly ASSUMED_N_BATCH = 512;
|
|
49
61
|
/** Total KV cache capacity (max positions). 0 when no context limit. */
|
|
50
62
|
readonly nCtx: number;
|
|
51
63
|
/** KV cells currently in use (monotonic within a pool run). */
|
|
@@ -104,17 +116,17 @@ export declare class ContextPressure {
|
|
|
104
116
|
* @param opts - Pool configuration: tasks, tools, sampling params, max turns
|
|
105
117
|
* @returns Agent pool result with per-agent findings and aggregate statistics
|
|
106
118
|
*
|
|
107
|
-
* @example
|
|
119
|
+
* @example Spine with agent pool
|
|
108
120
|
* ```typescript
|
|
109
|
-
* const pool = yield*
|
|
121
|
+
* const pool = yield* withSpine(
|
|
110
122
|
* { systemPrompt: RESEARCH_PROMPT, tools: toolsJson },
|
|
111
|
-
* function*(
|
|
123
|
+
* function*(spine) {
|
|
112
124
|
* return yield* useAgentPool({
|
|
113
125
|
* tasks: questions.map(q => ({
|
|
114
126
|
* systemPrompt: RESEARCH_PROMPT,
|
|
115
127
|
* content: q,
|
|
116
128
|
* tools: toolsJson,
|
|
117
|
-
* parent:
|
|
129
|
+
* parent: spine,
|
|
118
130
|
* })),
|
|
119
131
|
* tools: toolMap,
|
|
120
132
|
* maxTurns: 6,
|
package/dist/agent-pool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-pool.d.ts","sourceRoot":"","sources":["../src/agent-pool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzD,OAAO,EAA+G,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-pool.d.ts","sourceRoot":"","sources":["../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