@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/spine.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withSpine = withSpine;
|
|
4
|
+
const effection_1 = require("effection");
|
|
5
|
+
const sdk_1 = require("@lloyal-labs/sdk");
|
|
6
|
+
const context_1 = require("./context");
|
|
7
|
+
const trace_scope_1 = require("./trace-scope");
|
|
8
|
+
const toolkit_1 = require("./toolkit");
|
|
9
|
+
/**
|
|
10
|
+
* Scoped spine branch with guaranteed cleanup
|
|
11
|
+
*
|
|
12
|
+
* Creates (or forks) the pool's spine — the shared KV line that agents
|
|
13
|
+
* fork from and that `ctx.extendSpine` writes onto between tasks. The
|
|
14
|
+
* spine is pruned via try/finally when the body returns or throws,
|
|
15
|
+
* regardless of whether children still exist.
|
|
16
|
+
*
|
|
17
|
+
* Each agent's chat format (system + user + generation prompt) is rendered
|
|
18
|
+
* fresh inside `setupAgent`, so this spine carries no chat context itself —
|
|
19
|
+
* it exists as the pool's branching point and as the line that
|
|
20
|
+
* `ctx.extendSpine` writes onto between tasks.
|
|
21
|
+
*
|
|
22
|
+
* **Cold path** (no `parent`): creates a spine at position 0 with no prefill.
|
|
23
|
+
* Agents fork at position 0; their full chat context lives in their own suffix.
|
|
24
|
+
*
|
|
25
|
+
* **Warm path** (`parent` provided): forks from parent and prefills a turn
|
|
26
|
+
* separator so subsequent agent suffixes land on a clean turn boundary.
|
|
27
|
+
* Sub-agents inherit the parent's full KV state via the fork.
|
|
28
|
+
*
|
|
29
|
+
* @param opts - Sampling parameters and optional parent branch
|
|
30
|
+
* @param body - Operation that receives the spine branch and prefix length.
|
|
31
|
+
* Typically calls {@link useAgentPool} inside.
|
|
32
|
+
* @returns The body's return value
|
|
33
|
+
*
|
|
34
|
+
* @category Agents
|
|
35
|
+
*/
|
|
36
|
+
function* withSpine(opts, body) {
|
|
37
|
+
const ctx = yield* context_1.Ctx.expect();
|
|
38
|
+
const tw = yield* context_1.Trace.expect();
|
|
39
|
+
// Read parent trace ID — connects nested pools to the outer DISPATCH that spawned them
|
|
40
|
+
let parentTraceId = null;
|
|
41
|
+
try {
|
|
42
|
+
const p = yield* context_1.TraceParent.get();
|
|
43
|
+
if (p != null)
|
|
44
|
+
parentTraceId = p;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
/* no parent — top level */
|
|
48
|
+
}
|
|
49
|
+
const scope = (0, trace_scope_1.traceScope)(tw, parentTraceId, "withSpine", {
|
|
50
|
+
hasParent: !!opts.parent,
|
|
51
|
+
});
|
|
52
|
+
// Warm path: fork from parent branch (inherits full KV state), prefill a
|
|
53
|
+
// turn separator so the next agent's suffix lands on a clean boundary.
|
|
54
|
+
// Cold path: create fresh spine at position 0 with no prefill — agents
|
|
55
|
+
// fork at 0 and carry their full chat context in their own suffix.
|
|
56
|
+
let spine;
|
|
57
|
+
let prefillTokens;
|
|
58
|
+
if (opts.parent) {
|
|
59
|
+
spine = opts.parent.forkSync();
|
|
60
|
+
prefillTokens = ctx.getTurnSeparator();
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
spine = sdk_1.Branch.create(ctx, 0, opts.params ?? { temperature: 0.5 });
|
|
64
|
+
prefillTokens = [];
|
|
65
|
+
}
|
|
66
|
+
tw.write({
|
|
67
|
+
traceId: tw.nextId(),
|
|
68
|
+
parentTraceId: scope.traceId,
|
|
69
|
+
ts: performance.now(),
|
|
70
|
+
type: "branch:create",
|
|
71
|
+
branchHandle: spine.handle,
|
|
72
|
+
parentHandle: opts.parent?.handle ?? null,
|
|
73
|
+
position: opts.parent ? opts.parent.position : 0,
|
|
74
|
+
role: "spine",
|
|
75
|
+
});
|
|
76
|
+
if (prefillTokens.length > 0) {
|
|
77
|
+
yield* (0, effection_1.call)(() => spine.prefill(prefillTokens));
|
|
78
|
+
tw.write({
|
|
79
|
+
traceId: tw.nextId(),
|
|
80
|
+
parentTraceId: scope.traceId,
|
|
81
|
+
ts: performance.now(),
|
|
82
|
+
type: "branch:prefill",
|
|
83
|
+
branchHandle: spine.handle,
|
|
84
|
+
tokenCount: prefillTokens.length,
|
|
85
|
+
role: "spineHeader",
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
// Shared role+tools mode: format the chat header once and prefill onto
|
|
89
|
+
// the spine. Agents forking from this spine inherit system+tools tokens
|
|
90
|
+
// via metadata-only prefix-share (no per-spawn re-prefill). The resulting
|
|
91
|
+
// FormatConfig is stashed on SpineFmt so setupAgent can detect shared
|
|
92
|
+
// mode and copy parser/grammar/format/triggers without re-emitting the
|
|
93
|
+
// tool schemas in each agent's suffix.
|
|
94
|
+
let spineFmt = null;
|
|
95
|
+
if (opts.systemPrompt !== undefined) {
|
|
96
|
+
const enableThinking = opts.enableThinking ?? false;
|
|
97
|
+
const messages = JSON.stringify([{ role: "system", content: opts.systemPrompt }]);
|
|
98
|
+
const fmtOpts = {
|
|
99
|
+
enableThinking,
|
|
100
|
+
// Header ends at <|im_end|>; agents append <|im_start|>user…assistant
|
|
101
|
+
// markers as their suffix. Without this, the template would emit a
|
|
102
|
+
// trailing assistant generation prompt and corrupt the boundary.
|
|
103
|
+
addGenerationPrompt: false,
|
|
104
|
+
};
|
|
105
|
+
if (opts.tools && opts.tools.length > 0) {
|
|
106
|
+
fmtOpts.tools = (0, toolkit_1.createToolkit)(opts.tools).toolsJson;
|
|
107
|
+
}
|
|
108
|
+
const formatted = ctx.formatChatSync(messages, fmtOpts);
|
|
109
|
+
const headerTokens = ctx.tokenizeSync(formatted.prompt, false);
|
|
110
|
+
if (headerTokens.length > 0) {
|
|
111
|
+
yield* (0, effection_1.call)(() => spine.prefill(headerTokens));
|
|
112
|
+
tw.write({
|
|
113
|
+
traceId: tw.nextId(),
|
|
114
|
+
parentTraceId: scope.traceId,
|
|
115
|
+
ts: performance.now(),
|
|
116
|
+
type: "branch:prefill",
|
|
117
|
+
branchHandle: spine.handle,
|
|
118
|
+
tokenCount: headerTokens.length,
|
|
119
|
+
role: "spineHeader",
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
spineFmt = {
|
|
123
|
+
format: formatted.format,
|
|
124
|
+
reasoningFormat: formatted.reasoningFormat,
|
|
125
|
+
generationPrompt: formatted.generationPrompt,
|
|
126
|
+
parser: formatted.parser,
|
|
127
|
+
grammar: formatted.grammar,
|
|
128
|
+
grammarLazy: formatted.grammarLazy,
|
|
129
|
+
grammarTriggers: formatted.grammarTriggers,
|
|
130
|
+
enableThinking,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
if (opts.enableScratchpad)
|
|
135
|
+
yield* context_1.ScratchpadParent.set(spine);
|
|
136
|
+
if (spineFmt)
|
|
137
|
+
yield* context_1.SpineFmt.set(spineFmt);
|
|
138
|
+
return yield* body(spine, prefillTokens.length);
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
if (!spine.disposed) {
|
|
142
|
+
tw.write({
|
|
143
|
+
traceId: tw.nextId(),
|
|
144
|
+
parentTraceId: scope.traceId,
|
|
145
|
+
ts: performance.now(),
|
|
146
|
+
type: "branch:prune",
|
|
147
|
+
branchHandle: spine.handle,
|
|
148
|
+
position: 0,
|
|
149
|
+
});
|
|
150
|
+
spine.pruneSubtreeSync();
|
|
151
|
+
}
|
|
152
|
+
scope.close();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=spine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spine.js","sourceRoot":"","sources":["../src/spine.ts"],"names":[],"mappings":";;AAgHA,8BA2HC;AA3OD,yCAAiC;AAEjC,0CAA0C;AAE1C,uCAAgF;AAChF,+CAA2C;AAC3C,uCAA0C;AA+E1C;;;;;;;;;;;;;;;;;;;;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C,0BAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC9D,IAAI,QAAQ;YAAE,KAAK,CAAC,CAAC,kBAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC5C,OAAO,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;YAAS,CAAC;QACT,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACpB,EAAE,CAAC,KAAK,CAAC;gBACP,OAAO,EAAE,EAAE,CAAC,MAAM,EAAE;gBACpB,aAAa,EAAE,KAAK,CAAC,OAAO;gBAC5B,EAAE,EAAE,WAAW,CAAC,GAAG,EAAE;gBACrB,IAAI,EAAE,cAAc;gBACpB,YAAY,EAAE,KAAK,CAAC,MAAM;gBAC1B,QAAQ,EAAE,CAAC;aACZ,CAAC,CAAC;YACH,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC3B,CAAC;QACD,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;AACH,CAAC"}
|
package/dist/trace-types.d.ts
CHANGED
|
@@ -45,18 +45,18 @@ export type TraceEvent = (TraceEventBase & {
|
|
|
45
45
|
messages: string;
|
|
46
46
|
tools?: string;
|
|
47
47
|
grammar?: string;
|
|
48
|
-
role: '
|
|
48
|
+
role: 'spine' | 'agentSuffix' | 'generate' | 'diverge' | 'toolResultDelta';
|
|
49
49
|
}) | (TraceEventBase & {
|
|
50
50
|
type: 'branch:create';
|
|
51
51
|
branchHandle: number;
|
|
52
52
|
parentHandle: number | null;
|
|
53
53
|
position: number;
|
|
54
|
-
role: 'root' | '
|
|
54
|
+
role: 'root' | 'spine' | 'agentFork' | 'scratchpad' | 'divergeAttempt';
|
|
55
55
|
}) | (TraceEventBase & {
|
|
56
56
|
type: 'branch:prefill';
|
|
57
57
|
branchHandle: number;
|
|
58
58
|
tokenCount: number;
|
|
59
|
-
role: '
|
|
59
|
+
role: 'spineHeader' | 'agentSuffix' | 'toolResult' | 'warmDelta' | 'scratchpad' | 'probe' | 'recovery';
|
|
60
60
|
probeText?: string;
|
|
61
61
|
}) | (TraceEventBase & {
|
|
62
62
|
type: 'branch:prune';
|
|
@@ -108,12 +108,26 @@ export type TraceEvent = (TraceEventBase & {
|
|
|
108
108
|
}) | (TraceEventBase & {
|
|
109
109
|
type: 'pool:agentDrop';
|
|
110
110
|
agentId: number;
|
|
111
|
-
reason: 'pressure_init' | 'pressure_critical' | 'pressure_softcut' | 'pressure_settle_reject' | 'time_exceeded' | 'policy_exit' | 'maxTurns' | 'stop_token';
|
|
111
|
+
reason: 'pressure_init' | 'pressure_critical' | 'pressure_softcut' | 'pressure_settle_reject' | 'settle_stall_break' | 'time_exceeded' | 'policy_exit' | 'maxTurns' | 'tool_error' | 'stop_token';
|
|
112
112
|
}) | (TraceEventBase & {
|
|
113
113
|
type: 'pool:agentNudge';
|
|
114
114
|
agentId: number;
|
|
115
|
-
reason: 'pressure_softcut' | 'pressure_settle_reject' | 'time_nudge' | 'nudge';
|
|
115
|
+
reason: 'pressure_softcut' | 'pressure_settle_reject' | 'settle_reject' | 'time_nudge' | 'nudge';
|
|
116
116
|
message?: string;
|
|
117
|
+
}) | (TraceEventBase & {
|
|
118
|
+
type: 'pool:recoveryProduce';
|
|
119
|
+
agentId: number;
|
|
120
|
+
tokenCount: number;
|
|
121
|
+
outputLength: number;
|
|
122
|
+
}) | (TraceEventBase & {
|
|
123
|
+
type: 'pool:recoveryReturn';
|
|
124
|
+
agentId: number;
|
|
125
|
+
resultLength: number;
|
|
126
|
+
}) | (TraceEventBase & {
|
|
127
|
+
type: 'pool:recoveryFailed';
|
|
128
|
+
agentId: number;
|
|
129
|
+
reason: string;
|
|
130
|
+
outputExcerpt: string;
|
|
117
131
|
}) | (TraceEventBase & {
|
|
118
132
|
type: 'agent:turn';
|
|
119
133
|
agentId: number;
|
|
@@ -124,6 +138,12 @@ export type TraceEvent = (TraceEventBase & {
|
|
|
124
138
|
name: string;
|
|
125
139
|
arguments: string;
|
|
126
140
|
}>;
|
|
141
|
+
}) | (TraceEventBase & {
|
|
142
|
+
type: 'spine:extend';
|
|
143
|
+
userContent: string;
|
|
144
|
+
assistantContent: string;
|
|
145
|
+
deltaTokens: number;
|
|
146
|
+
positionAfter: number;
|
|
127
147
|
}) | (TraceEventBase & {
|
|
128
148
|
type: 'tool:dispatch';
|
|
129
149
|
agentId: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace-types.d.ts","sourceRoot":"","sources":["../src/trace-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,sCAAsC;AACtC,UAAU,cAAc;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9B,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,UAAU,GAEpB,CAAE,cAAc,GAAG;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,KACrF,cAAc,GAAG;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,KAG1E,cAAc,GAAG;IACf,IAAI,EAAE,eAAe,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"trace-types.d.ts","sourceRoot":"","sources":["../src/trace-types.ts"],"names":[],"m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CAAA;KAAE,CAAC,CAAC;CACnF,CAAA,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Operation } from 'effection';
|
|
1
2
|
import type { Branch } from '@lloyal-labs/sdk';
|
|
2
3
|
import type { AgentPolicy } from './AgentPolicy';
|
|
3
4
|
import type { EntailmentScorer } from './source';
|
|
@@ -55,7 +56,7 @@ export interface ToolContext {
|
|
|
55
56
|
agentId: number;
|
|
56
57
|
/**
|
|
57
58
|
* The calling agent's branch — use for recursive tools that spawn
|
|
58
|
-
* sub-agents via {@link
|
|
59
|
+
* sub-agents via {@link withSpine} with `parent` option.
|
|
59
60
|
* Sub-agents forking from this branch inherit the agent's full
|
|
60
61
|
* KV state (Continuous Context).
|
|
61
62
|
*/
|
|
@@ -186,9 +187,11 @@ export interface PressureThresholds {
|
|
|
186
187
|
softLimit?: number;
|
|
187
188
|
/**
|
|
188
189
|
* Crash-prevention floor (tokens). When remaining drops below this,
|
|
189
|
-
* agents are killed
|
|
190
|
-
* `
|
|
191
|
-
*
|
|
190
|
+
* `pressure.critical` is true and agents are killed before the next
|
|
191
|
+
* decode. Must be >= the context's `nBatch` — otherwise native decode
|
|
192
|
+
* can't allocate the next batch when the kill fires, and recovery's
|
|
193
|
+
* prefill will OOM. The pool validates this at startup.
|
|
194
|
+
* Default: 512 (matches llama.cpp's default `n_batch`).
|
|
192
195
|
*/
|
|
193
196
|
hardLimit?: number;
|
|
194
197
|
}
|
|
@@ -198,8 +201,19 @@ export interface PressureThresholds {
|
|
|
198
201
|
* @category Agents
|
|
199
202
|
*/
|
|
200
203
|
export interface AgentPoolOptions {
|
|
201
|
-
/**
|
|
202
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Spine branch. Orchestrator-spawned agents fork from this by default.
|
|
206
|
+
* Produced by {@link withSpine} in the {@link agentPool} wrapper.
|
|
207
|
+
*/
|
|
208
|
+
spine: Branch;
|
|
209
|
+
/**
|
|
210
|
+
* Orchestrator callback — declares the execution pattern (parallel, chain,
|
|
211
|
+
* fanout, dag, or a custom shape). Drives task spawning, waiting, and
|
|
212
|
+
* spine extension through the provided {@link PoolContext}.
|
|
213
|
+
*/
|
|
214
|
+
orchestrate: (ctx: import('./orchestrators').PoolContext) => Operation<void>;
|
|
215
|
+
/** JSON-serialized tool schemas for chat formatting. Derived from tool map. */
|
|
216
|
+
toolsJson: string;
|
|
203
217
|
/**
|
|
204
218
|
* Tool registry mapping tool names to {@link Tool} instances.
|
|
205
219
|
*
|
|
@@ -219,21 +233,37 @@ export interface AgentPoolOptions {
|
|
|
219
233
|
/** Maximum tool-call turns per agent before forced termination */
|
|
220
234
|
maxTurns?: number;
|
|
221
235
|
/** Tool name that signals agent completion. When the model calls this tool,
|
|
222
|
-
*
|
|
223
|
-
* The tool
|
|
224
|
-
*
|
|
225
|
-
|
|
236
|
+
* the result is extracted from its arguments and the agent is marked done.
|
|
237
|
+
* The tool's execute() code-path is not reached — the framework intercepts
|
|
238
|
+
* the call at the policy layer and treats it as the agent's return. If
|
|
239
|
+
* omitted, agents complete only via stop token, free-text return, or
|
|
240
|
+
* hard-cut. */
|
|
241
|
+
terminalToolName?: string;
|
|
226
242
|
/** Enable per-token entropy/surprisal on `agent:produce` events */
|
|
227
243
|
trace?: boolean;
|
|
228
|
-
/** Prune agent branches immediately when they
|
|
229
|
-
* Frees KV for remaining agents mid-pool. Only agents
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
|
|
244
|
+
/** Prune agent branches immediately when they voluntarily return via the
|
|
245
|
+
* terminal tool. Frees KV for remaining agents mid-pool. Only agents
|
|
246
|
+
* that voluntarily returned are pruned — hard-cut agents keep their
|
|
247
|
+
* branches for scratchpad recovery. @default false */
|
|
248
|
+
pruneOnReturn?: boolean;
|
|
233
249
|
/** Custom agent policy. Configure recovery (scratchpad extraction),
|
|
234
250
|
* time limits, explore/exploit threshold, and tool guards via
|
|
235
251
|
* {@link DefaultAgentPolicyOpts}. @default DefaultAgentPolicy with default opts */
|
|
236
252
|
policy?: AgentPolicy;
|
|
253
|
+
/**
|
|
254
|
+
* Whether the chat template delimits `<think>` blocks for this pool's
|
|
255
|
+
* agents. Captured once at pool creation, stored on each agent's
|
|
256
|
+
* `fmt.enableThinking`, and threaded through every `buildToolResultDelta`
|
|
257
|
+
* call so the parser's `generation_prompt` stays consistent with the
|
|
258
|
+
* actual KV state. Setting `true` gives the template's generation prompt
|
|
259
|
+
* the `<think>\n` prefix that thinking-capable models (Qwen3 family)
|
|
260
|
+
* expect — thoughts are correctly delimited and `parseChatOutput`
|
|
261
|
+
* extracts them into `reasoning_content`. Setting `false` omits think
|
|
262
|
+
* tokens; if the model emits them anyway (as Qwen3.5 does) they leak
|
|
263
|
+
* into visible content.
|
|
264
|
+
* @default false
|
|
265
|
+
*/
|
|
266
|
+
enableThinking?: boolean;
|
|
237
267
|
/** Entailment scorer for semantic coherence across recursive depths.
|
|
238
268
|
* Passed to every tool via {@link ToolContext.scorer}. */
|
|
239
269
|
scorer?: EntailmentScorer;
|
|
@@ -418,7 +448,11 @@ export type AgentEvent = {
|
|
|
418
448
|
filled: number;
|
|
419
449
|
total: number;
|
|
420
450
|
} | {
|
|
421
|
-
type: 'agent:
|
|
451
|
+
type: 'agent:return';
|
|
452
|
+
agentId: number;
|
|
453
|
+
result: string;
|
|
454
|
+
} | {
|
|
455
|
+
type: 'agent:recovered';
|
|
422
456
|
agentId: number;
|
|
423
457
|
result: string;
|
|
424
458
|
} | {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,KAAK,EAAE,gBA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IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
package/dist/use-agent.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface UseAgentOpts {
|
|
|
18
18
|
/** Tools available to the agent. Optional — pool degenerates cleanly without tools. */
|
|
19
19
|
tools?: Tool[];
|
|
20
20
|
/** Terminal tool name — tool must be in the tools array. */
|
|
21
|
-
|
|
21
|
+
terminalToolName?: string;
|
|
22
22
|
/** Max tool-use turns before hard cut. @default 100 */
|
|
23
23
|
maxTurns?: number;
|
|
24
24
|
/** JSON Schema for eager grammar constraint (deferred: Zod support). */
|
|
@@ -44,7 +44,7 @@ export interface UseAgentOpts {
|
|
|
44
44
|
* root and agent branch alive until the caller's scope exits — caller can
|
|
45
45
|
* fork from the Agent's branch for verification or follow-up.
|
|
46
46
|
*
|
|
47
|
-
* Root managed via `ensure()` (not `
|
|
47
|
+
* Root managed via `ensure()` (not `withSpine`) because the resource
|
|
48
48
|
* lifetime requires the root alive until the caller's scope exits.
|
|
49
49
|
*
|
|
50
50
|
* Events stream passively to the broadcast Channel during the inline drain.
|
|
@@ -58,7 +58,7 @@ export interface UseAgentOpts {
|
|
|
58
58
|
* systemPrompt: "You are a research assistant.",
|
|
59
59
|
* task: "Find information about X",
|
|
60
60
|
* tools: [searchTool, reportTool],
|
|
61
|
-
*
|
|
61
|
+
* terminalToolName: 'report',
|
|
62
62
|
* });
|
|
63
63
|
* // agent.result — findings
|
|
64
64
|
* // agent.branch — alive, can fork from
|
package/dist/use-agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-agent.d.ts","sourceRoot":"","sources":["../src/use-agent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,KAAK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CAAC,IAAI,EAAE,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC,CA+D7D;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAiB,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC,CAI3D"}
|
package/dist/use-agent.js
CHANGED
|
@@ -8,6 +8,7 @@ const context_1 = require("./context");
|
|
|
8
8
|
const agent_pool_1 = require("./agent-pool");
|
|
9
9
|
const toolkit_1 = require("./toolkit");
|
|
10
10
|
const trace_scope_1 = require("./trace-scope");
|
|
11
|
+
const orchestrators_1 = require("./orchestrators");
|
|
11
12
|
/**
|
|
12
13
|
* Single-agent resource — delegates to {@link useAgentPool} N=1.
|
|
13
14
|
*
|
|
@@ -18,7 +19,7 @@ const trace_scope_1 = require("./trace-scope");
|
|
|
18
19
|
* root and agent branch alive until the caller's scope exits — caller can
|
|
19
20
|
* fork from the Agent's branch for verification or follow-up.
|
|
20
21
|
*
|
|
21
|
-
* Root managed via `ensure()` (not `
|
|
22
|
+
* Root managed via `ensure()` (not `withSpine`) because the resource
|
|
22
23
|
* lifetime requires the root alive until the caller's scope exits.
|
|
23
24
|
*
|
|
24
25
|
* Events stream passively to the broadcast Channel during the inline drain.
|
|
@@ -32,7 +33,7 @@ const trace_scope_1 = require("./trace-scope");
|
|
|
32
33
|
* systemPrompt: "You are a research assistant.",
|
|
33
34
|
* task: "Find information about X",
|
|
34
35
|
* tools: [searchTool, reportTool],
|
|
35
|
-
*
|
|
36
|
+
* terminalToolName: 'report',
|
|
36
37
|
* });
|
|
37
38
|
* // agent.result — findings
|
|
38
39
|
* // agent.branch — alive, can fork from
|
|
@@ -51,21 +52,19 @@ function useAgent(opts) {
|
|
|
51
52
|
hasTools: !!(opts.tools?.length),
|
|
52
53
|
hasParent: !!warmParent,
|
|
53
54
|
});
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
fmtOpts.tools = toolkit.toolsJson;
|
|
59
|
-
const fmt = ctx.formatChatSync(JSON.stringify(messages), fmtOpts);
|
|
60
|
-
const sharedTokens = ctx.tokenizeSync(fmt.prompt);
|
|
61
|
-
// Create root — ensure() for resource lifetime (not withSharedRoot's try/finally)
|
|
55
|
+
// Create root — ensure() for resource lifetime (not withSpine's try/finally).
|
|
56
|
+
// The root carries no chat context; the agent's suffix (formatted fresh in
|
|
57
|
+
// setupAgent) is the agent's full chat. Warm path prefills a turn separator
|
|
58
|
+
// so the suffix lands on a clean turn boundary.
|
|
62
59
|
const root = warmParent
|
|
63
60
|
? warmParent.forkSync()
|
|
64
61
|
: sdk_1.Branch.create(ctx, 0, opts.params ?? { temperature: 0.5 });
|
|
65
62
|
yield* (0, effection_1.ensure)(() => { if (!root.disposed)
|
|
66
63
|
root.pruneSubtreeSync(); });
|
|
67
|
-
const prefillTokens = warmParent ? ctx.getTurnSeparator() :
|
|
68
|
-
|
|
64
|
+
const prefillTokens = warmParent ? ctx.getTurnSeparator() : [];
|
|
65
|
+
if (prefillTokens.length > 0) {
|
|
66
|
+
yield* (0, effection_1.call)(() => root.prefill(prefillTokens));
|
|
67
|
+
}
|
|
69
68
|
// Eager grammar from schema — set on root before fork.
|
|
70
69
|
// Fork inherits grammar state. formatChatSync returns no grammar for
|
|
71
70
|
// no-tools case, so applyLazyGrammar is a no-op and the inherited
|
|
@@ -74,17 +73,14 @@ function useAgent(opts) {
|
|
|
74
73
|
const grammar = yield* (0, effection_1.call)(() => ctx.jsonSchemaToGrammar(JSON.stringify(opts.schema)));
|
|
75
74
|
root.setGrammar(grammar);
|
|
76
75
|
}
|
|
77
|
-
// Delegate to useAgentPool N=1
|
|
76
|
+
// Delegate to useAgentPool N=1 via a trivial parallel orchestrator
|
|
78
77
|
const hasTools = !!(opts.tools?.length);
|
|
79
78
|
const sub = yield* (0, agent_pool_1.useAgentPool)({
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
tools: hasTools ? toolkit.toolsJson : undefined,
|
|
84
|
-
parent: root,
|
|
85
|
-
}],
|
|
79
|
+
spine: root,
|
|
80
|
+
orchestrate: (0, orchestrators_1.parallel)([{ content: opts.task, systemPrompt: opts.systemPrompt }]),
|
|
81
|
+
toolsJson: hasTools ? toolkit.toolsJson : '',
|
|
86
82
|
tools: toolkit.toolMap,
|
|
87
|
-
|
|
83
|
+
terminalToolName: opts.terminalToolName,
|
|
88
84
|
maxTurns: opts.maxTurns,
|
|
89
85
|
policy: opts.policy,
|
|
90
86
|
trace: opts.trace,
|
package/dist/use-agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-agent.js","sourceRoot":"","sources":["../src/use-agent.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"use-agent.js","sourceRoot":"","sources":["../src/use-agent.ts"],"names":[],"mappings":";;AA4EA,4BA+DC;AAuBD,sBAIC;AAtKD,yCAA2D;AAE3D,0CAA0C;AAG1C,uCAA+C;AAC/C,6CAA4C;AAC5C,uCAA0C;AAC1C,+CAA2C;AAC3C,mDAA2C;AAmC3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,SAAgB,QAAQ,CAAC,IAAkB;IACzC,OAAO,IAAA,oBAAQ,EAAC,QAAQ,CAAC,EAAC,OAAO;QAC/B,MAAM,GAAG,GAAmB,KAAK,CAAC,CAAC,aAAG,CAAC,MAAM,EAAE,CAAC;QAChD,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,gBAAM,CAAC,MAAM,EAAE,CAAC;QACzC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,eAAK,CAAC,MAAM,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,IAAA,uBAAa,EAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;QAChD,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,IAAI,SAAS,CAAC;QAEnE,MAAM,KAAK,GAAG,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AAK,CAAC,CAAC,IAAA,kBAAM,EAAC,QAAQ,CAAC;QAC5B,OAAO,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lloyal-labs/lloyal-agents",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Multi-agent inference inside the decode loop — structured concurrency over shared KV state",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/lloyal-ai/
|
|
12
|
+
"url": "git+https://github.com/lloyal-ai/hdk.git",
|
|
13
13
|
"directory": "packages/agents"
|
|
14
14
|
},
|
|
15
|
-
"homepage": "https://github.com/lloyal-ai/
|
|
15
|
+
"homepage": "https://github.com/lloyal-ai/hdk/tree/main/packages/agents#readme",
|
|
16
16
|
"bugs": {
|
|
17
|
-
"url": "https://github.com/lloyal-ai/
|
|
17
|
+
"url": "https://github.com/lloyal-ai/hdk/issues"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|
|
20
20
|
"llm",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"build": "tsc -b"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@lloyal-labs/sdk": "^1.
|
|
34
|
+
"@lloyal-labs/sdk": "^2.1.0",
|
|
35
35
|
"effection": "^4.0.2",
|
|
36
36
|
"eta": "^4.5.1"
|
|
37
37
|
},
|
package/dist/shared-root.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { Operation } from "effection";
|
|
2
|
-
import { Branch } from "@lloyal-labs/sdk";
|
|
3
|
-
import type { SamplingParams } from "./types";
|
|
4
|
-
/**
|
|
5
|
-
* Configuration for {@link withSharedRoot}
|
|
6
|
-
*
|
|
7
|
-
* @category Agents
|
|
8
|
-
*/
|
|
9
|
-
export interface SharedRootOptions {
|
|
10
|
-
/** System prompt to tokenize and prefill into the shared root */
|
|
11
|
-
systemPrompt: string;
|
|
12
|
-
/** JSON-serialized tool schemas for tool-aware prompt formatting */
|
|
13
|
-
tools?: string;
|
|
14
|
-
/** Sampling parameters for the root branch */
|
|
15
|
-
params?: SamplingParams;
|
|
16
|
-
/**
|
|
17
|
-
* Set ScratchpadParent context so tools can fork from the shared root
|
|
18
|
-
* for scratchpad extraction (fork-attend-extract-prune pattern).
|
|
19
|
-
* @default false
|
|
20
|
-
*/
|
|
21
|
-
enableScratchpad?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Fork root from this branch instead of creating at position 0.
|
|
24
|
-
*
|
|
25
|
-
* When provided, the root inherits the parent's full KV state —
|
|
26
|
-
* every tool call, tool result, and generated token the parent
|
|
27
|
-
* accumulated. The system prompt is prefilled as a delta on top.
|
|
28
|
-
* Sub-agents forking from this root attend over the parent's
|
|
29
|
-
* complete attention state (Continuous Context).
|
|
30
|
-
*
|
|
31
|
-
* When omitted, creates a fresh root at position 0 (cold start).
|
|
32
|
-
*/
|
|
33
|
-
parent?: Branch;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Scoped shared root branch with guaranteed cleanup
|
|
37
|
-
*
|
|
38
|
-
* Creates (or forks) a root branch, prefills the system prompt, and passes
|
|
39
|
-
* it to the body function. The root is pruned via try/finally when the body
|
|
40
|
-
* returns or throws, regardless of whether children still exist.
|
|
41
|
-
*
|
|
42
|
-
* **Cold path** (no `parent`): creates root at position 0, prefills system
|
|
43
|
-
* prompt. Use for top-level research where no prior context exists.
|
|
44
|
-
*
|
|
45
|
-
* **Warm path** (`parent` provided): forks from parent branch, prefills
|
|
46
|
-
* system prompt as a delta. Sub-agents inherit the parent's full KV state.
|
|
47
|
-
* Use for recursive tools (web_research, research) where sub-agents should
|
|
48
|
-
* attend over the calling agent's accumulated evidence.
|
|
49
|
-
*
|
|
50
|
-
* @param opts - System prompt, tools, sampling parameters, and optional parent branch
|
|
51
|
-
* @param body - Operation that receives the root branch and prefix length.
|
|
52
|
-
* Typically calls {@link runAgents} or {@link useAgentPool} inside.
|
|
53
|
-
* @returns The body's return value
|
|
54
|
-
*
|
|
55
|
-
* @category Agents
|
|
56
|
-
*/
|
|
57
|
-
export declare function withSharedRoot<T>(opts: SharedRootOptions, body: (root: Branch, sharedPrefixLength: number) => Operation<T>): Operation<T>;
|
|
58
|
-
//# sourceMappingURL=shared-root.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shared-root.d.ts","sourceRoot":"","sources":["../src/shared-root.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAI1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,iEAAiE;IACjE,YAAY,EAAE,MAAM,CAAC;IACrB,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAiB,cAAc,CAAC,CAAC,EAC/B,IAAI,EAAE,iBAAiB,EACvB,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,GAC/D,SAAS,CAAC,CAAC,CAAC,CAkGd"}
|