@lloyal-labs/lloyal-agents 2.0.0 → 3.0.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/LICENSE +107 -0
- package/LICENSE-FAQ.md +256 -0
- package/README.md +31 -15
- package/dist/Agent.d.ts +15 -4
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +12 -2
- package/dist/Agent.js.map +1 -1
- package/dist/AgentPolicy.d.ts +92 -15
- package/dist/AgentPolicy.d.ts.map +1 -1
- package/dist/AgentPolicy.js +42 -14
- package/dist/AgentPolicy.js.map +1 -1
- package/dist/Tool.d.ts +45 -1
- package/dist/Tool.d.ts.map +1 -1
- package/dist/Tool.js +50 -2
- package/dist/Tool.js.map +1 -1
- package/dist/agent-pool.d.ts +4 -4
- package/dist/agent-pool.d.ts.map +1 -1
- package/dist/agent-pool.js +224 -53
- package/dist/agent-pool.js.map +1 -1
- package/dist/app-config.d.ts +50 -0
- package/dist/app-config.d.ts.map +1 -0
- package/dist/app-config.js +27 -0
- package/dist/app-config.js.map +1 -0
- package/dist/app-types.d.ts +309 -0
- package/dist/app-types.d.ts.map +1 -0
- package/dist/app-types.js +28 -0
- package/dist/app-types.js.map +1 -0
- package/dist/chunk.d.ts +118 -0
- package/dist/chunk.d.ts.map +1 -0
- package/dist/chunk.js +19 -0
- package/dist/chunk.js.map +1 -0
- package/dist/context.d.ts +76 -20
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +72 -20
- package/dist/context.js.map +1 -1
- package/dist/create-agent-pool.d.ts +18 -12
- package/dist/create-agent-pool.d.ts.map +1 -1
- package/dist/create-agent-pool.js +30 -29
- package/dist/create-agent-pool.js.map +1 -1
- package/dist/grant-store.d.ts +49 -0
- package/dist/grant-store.d.ts.map +1 -0
- package/dist/grant-store.js +33 -0
- package/dist/grant-store.js.map +1 -0
- package/dist/index.d.ts +10 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/orchestrators.d.ts +15 -8
- package/dist/orchestrators.d.ts.map +1 -1
- package/dist/orchestrators.js +10 -10
- package/dist/orchestrators.js.map +1 -1
- package/dist/replay.d.ts +19 -19
- package/dist/replay.d.ts.map +1 -1
- package/dist/replay.js +29 -29
- package/dist/replay.js.map +1 -1
- package/dist/source.d.ts +31 -1
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +32 -2
- package/dist/source.js.map +1 -1
- package/dist/spine.d.ts +100 -0
- package/dist/spine.d.ts.map +1 -0
- package/dist/{shared-root.js → spine.js} +57 -38
- package/dist/spine.js.map +1 -0
- package/dist/toolkit.d.ts +44 -17
- package/dist/toolkit.d.ts.map +1 -1
- package/dist/toolkit.js +24 -14
- package/dist/toolkit.js.map +1 -1
- package/dist/trace-types.d.ts +36 -4
- package/dist/trace-types.d.ts.map +1 -1
- package/dist/types.d.ts +46 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/use-agent.d.ts +10 -5
- package/dist/use-agent.d.ts.map +1 -1
- package/dist/use-agent.js +18 -15
- package/dist/use-agent.js.map +1 -1
- package/package.json +7 -5
- package/dist/shared-root.d.ts +0 -96
- package/dist/shared-root.d.ts.map +0 -1
- package/dist/shared-root.js.map +0 -1
package/dist/source.d.ts
CHANGED
|
@@ -69,7 +69,21 @@ export declare abstract class Source<TCtx = unknown, TChunk = unknown> {
|
|
|
69
69
|
abstract get tools(): Tool[];
|
|
70
70
|
/** Reranker instance, set during {@link bind}. Used by {@link createScorer}. */
|
|
71
71
|
protected _reranker: ScorerReranker | null;
|
|
72
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* Minimum entailment score for delegation to proceed.
|
|
74
|
+
*
|
|
75
|
+
* Reranker scores are logit-diffs (`logit(yes) − logit(no)`); a value
|
|
76
|
+
* `> 0` means the cross-encoder model prefers "yes" over "no" when
|
|
77
|
+
* asked whether the document matches the query. Default `0` ⇒ "the
|
|
78
|
+
* model agrees this passage is relevant"; subclasses may tighten
|
|
79
|
+
* (e.g. `2` for "confident yes") or loosen (negative, for noisy
|
|
80
|
+
* corpora where leaning-no hits are still worth investigating).
|
|
81
|
+
*
|
|
82
|
+
* The prior softmax-prob default was `0.25`, which corresponded to
|
|
83
|
+
* logit-diff `≈ −1.1`. The new default is stricter: only hits the
|
|
84
|
+
* model genuinely leans toward are surfaced. See TICK-002 calibration
|
|
85
|
+
* notes (`reasoning.run/scripts/inspect-rerank.mjs`) for the data.
|
|
86
|
+
*/
|
|
73
87
|
protected _entailmentFloor: number;
|
|
74
88
|
/**
|
|
75
89
|
* Create an immutable entailment scorer scoped to one invocation.
|
|
@@ -85,5 +99,21 @@ export declare abstract class Source<TCtx = unknown, TChunk = unknown> {
|
|
|
85
99
|
bind(_ctx: TCtx): Operation<void>;
|
|
86
100
|
/** Post-use chunks for reranking. Called after agents have used the tools. */
|
|
87
101
|
getChunks(): TChunk[];
|
|
102
|
+
/**
|
|
103
|
+
* App-level prompt data (e.g. a corpus TOC) for the HARNESS to place.
|
|
104
|
+
*
|
|
105
|
+
* Identical for every agent in a pool, so it belongs in shared KV —
|
|
106
|
+
* rendered ONCE, not duplicated per spawn (six 4.8k-token TOC-bearing
|
|
107
|
+
* suffixes overran a 32k context before this contract existed).
|
|
108
|
+
*
|
|
109
|
+
* Placement is a TRUST decision, which is why the framework does not
|
|
110
|
+
* place it automatically: this is free prose derived from source
|
|
111
|
+
* content, and the shared spine prefix is read by every agent in the
|
|
112
|
+
* pool. A harness may append it to its spine prompt for apps it trusts
|
|
113
|
+
* (first-party corpora); it must not blanket-append data from untrusted
|
|
114
|
+
* third-party apps — `renderSpine` itself stays prose-free for exactly
|
|
115
|
+
* this reason.
|
|
116
|
+
*/
|
|
117
|
+
promptData(): Record<string, unknown>;
|
|
88
118
|
}
|
|
89
119
|
//# sourceMappingURL=source.d.ts.map
|
package/dist/source.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/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AE,MAAM,GAAG,gBAAgB;IA0BrD,0FAA0F;IACzF,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;IAElC,8EAA8E;IAC9E,SAAS,IAAI,MAAM,EAAE;IAErB;;;;;;;;;;;;;;OAcG;IACH,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CACtC"}
|
package/dist/source.js
CHANGED
|
@@ -23,8 +23,22 @@ exports.NULL_SCORER = {
|
|
|
23
23
|
class Source {
|
|
24
24
|
/** Reranker instance, set during {@link bind}. Used by {@link createScorer}. */
|
|
25
25
|
_reranker = null;
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Minimum entailment score for delegation to proceed.
|
|
28
|
+
*
|
|
29
|
+
* Reranker scores are logit-diffs (`logit(yes) − logit(no)`); a value
|
|
30
|
+
* `> 0` means the cross-encoder model prefers "yes" over "no" when
|
|
31
|
+
* asked whether the document matches the query. Default `0` ⇒ "the
|
|
32
|
+
* model agrees this passage is relevant"; subclasses may tighten
|
|
33
|
+
* (e.g. `2` for "confident yes") or loosen (negative, for noisy
|
|
34
|
+
* corpora where leaning-no hits are still worth investigating).
|
|
35
|
+
*
|
|
36
|
+
* The prior softmax-prob default was `0.25`, which corresponded to
|
|
37
|
+
* logit-diff `≈ −1.1`. The new default is stricter: only hits the
|
|
38
|
+
* model genuinely leans toward are surfaced. See TICK-002 calibration
|
|
39
|
+
* notes (`reasoning.run/scripts/inspect-rerank.mjs`) for the data.
|
|
40
|
+
*/
|
|
41
|
+
_entailmentFloor = 0;
|
|
28
42
|
/**
|
|
29
43
|
* Create an immutable entailment scorer scoped to one invocation.
|
|
30
44
|
*
|
|
@@ -62,6 +76,22 @@ class Source {
|
|
|
62
76
|
*bind(_ctx) { }
|
|
63
77
|
/** Post-use chunks for reranking. Called after agents have used the tools. */
|
|
64
78
|
getChunks() { return []; }
|
|
79
|
+
/**
|
|
80
|
+
* App-level prompt data (e.g. a corpus TOC) for the HARNESS to place.
|
|
81
|
+
*
|
|
82
|
+
* Identical for every agent in a pool, so it belongs in shared KV —
|
|
83
|
+
* rendered ONCE, not duplicated per spawn (six 4.8k-token TOC-bearing
|
|
84
|
+
* suffixes overran a 32k context before this contract existed).
|
|
85
|
+
*
|
|
86
|
+
* Placement is a TRUST decision, which is why the framework does not
|
|
87
|
+
* place it automatically: this is free prose derived from source
|
|
88
|
+
* content, and the shared spine prefix is read by every agent in the
|
|
89
|
+
* pool. A harness may append it to its spine prompt for apps it trusts
|
|
90
|
+
* (first-party corpora); it must not blanket-append data from untrusted
|
|
91
|
+
* third-party apps — `renderSpine` itself stays prose-free for exactly
|
|
92
|
+
* this reason.
|
|
93
|
+
*/
|
|
94
|
+
promptData() { return {}; }
|
|
65
95
|
}
|
|
66
96
|
exports.Source = Source;
|
|
67
97
|
//# sourceMappingURL=source.js.map
|
package/dist/source.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.js","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":";;;AA2CA,sFAAsF;AACzE,QAAA,WAAW,GAAqB;IAC3C,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACzD,mBAAmB,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACxD,oBAAoB,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC/D,aAAa,EAAE,GAAG,EAAE,CAAC,IAAI;CAC1B,CAAC;AAYF;;;;;;;;;;;GAWG;AACH,MAAsB,MAAM;IAM1B,gFAAgF;IACtE,SAAS,GAA0B,IAAI,CAAC;IAClD
|
|
1
|
+
{"version":3,"file":"source.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EAAE,KAAK,CAAC,CAAC;gBACnE,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;gBACjE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACrE,CAAC;YACD,KAAK,CAAC,oBAAoB,CAAC,SAAiB,EAAE,KAAe;gBAC3D,OAAO,QAAQ,CAAC,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;YAC/C,CAAC;YACD,aAAa,CAAC,KAAa;gBACzB,OAAO,KAAK,IAAI,KAAK,CAAC;YACxB,CAAC;SACF,CAAC;IACJ,CAAC;IAED,0FAA0F;IAC1F,CAAC,IAAI,CAAC,IAAU,IAAoB,CAAC;IAErC,8EAA8E;IAC9E,SAAS,KAAe,OAAO,EAAE,CAAC,CAAC,CAAC;IAEpC;;;;;;;;;;;;;;OAcG;IACH,UAAU,KAA8B,OAAO,EAAE,CAAC,CAAC,CAAC;CACrD;AAlFD,wBAkFC"}
|
package/dist/spine.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { Operation } from "effection";
|
|
2
|
+
import { Branch } from "@lloyal-labs/sdk";
|
|
3
|
+
import type { Tool } from "./Tool";
|
|
4
|
+
import type { SamplingParams } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for {@link withSpine}
|
|
7
|
+
*
|
|
8
|
+
* @category Agents
|
|
9
|
+
*/
|
|
10
|
+
export interface SpineOptions {
|
|
11
|
+
/** Sampling parameters for the spine branch */
|
|
12
|
+
params?: SamplingParams;
|
|
13
|
+
/**
|
|
14
|
+
* Fork the spine from this branch instead of creating at position 0.
|
|
15
|
+
*
|
|
16
|
+
* When provided, the spine inherits the parent's full KV state —
|
|
17
|
+
* every tool call, tool result, and generated token the parent
|
|
18
|
+
* accumulated. Sub-agents forking from this spine attend over the
|
|
19
|
+
* parent's complete attention state (Continuous Context).
|
|
20
|
+
*
|
|
21
|
+
* When omitted, creates a fresh spine at position 0 (cold start).
|
|
22
|
+
*/
|
|
23
|
+
parent?: Branch;
|
|
24
|
+
/**
|
|
25
|
+
* When set, prefill the chat-format `[system + tools]` header onto the
|
|
26
|
+
* spine once at setup. Every agent forking from the spine inherits these
|
|
27
|
+
* tokens via `forkSync`'s metadata-only KV prefix-share — the role and
|
|
28
|
+
* tool schemas appear ONCE in physical KV regardless of how many agents
|
|
29
|
+
* the pool spawns.
|
|
30
|
+
*
|
|
31
|
+
* The resulting `FormatConfig` (parser/grammar/format/triggers) is set
|
|
32
|
+
* on the {@link SpineFmt} context so `setupAgent` can detect shared mode,
|
|
33
|
+
* skip its own system+tools formatting, and inherit the dispatch-side
|
|
34
|
+
* fmt from the spine.
|
|
35
|
+
*
|
|
36
|
+
* Use this for orchestrators where every agent shares the same role —
|
|
37
|
+
* chain-mode research pools, fanout-style same-role pools, etc. Mixed-
|
|
38
|
+
* role workflows (research → compare → synthesize) keep using per-spec
|
|
39
|
+
* `SpawnSpec.systemPrompt` and don't pass this option.
|
|
40
|
+
*/
|
|
41
|
+
systemPrompt?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Tools whose schemas embed into the chat-format header prefilled at setup.
|
|
44
|
+
* Their JSON schemas are decoded into the spine's KV ONCE; every agent
|
|
45
|
+
* forking from the spine inherits the schema tokens via fork prefix-share
|
|
46
|
+
* instead of re-emitting them in its own suffix.
|
|
47
|
+
*
|
|
48
|
+
* The same `Tool[]` is typically also passed to `agentPool` (where it
|
|
49
|
+
* becomes the dispatcher registry). Two roles, one input — schemas
|
|
50
|
+
* decoded once into the spine, instances registered for runtime
|
|
51
|
+
* `tool.execute()` dispatch.
|
|
52
|
+
*
|
|
53
|
+
* Only applied when `systemPrompt` is also set (shared mode); ignored
|
|
54
|
+
* otherwise.
|
|
55
|
+
*/
|
|
56
|
+
tools?: Tool[];
|
|
57
|
+
/**
|
|
58
|
+
* Whether to enable thinking-mode tokens (e.g. `<think>` blocks) when
|
|
59
|
+
* formatting the spine's chat-format header. Threaded through to the
|
|
60
|
+
* chat-format call AND stored on the `SpineFmt` FormatConfig so
|
|
61
|
+
* `setupAgent`'s shared-mode shortcut copies a parser/grammar/triggers
|
|
62
|
+
* configuration consistent with the per-agent suffix formatting.
|
|
63
|
+
*
|
|
64
|
+
* Should match the `enableThinking` value the caller passes to the agent
|
|
65
|
+
* pool — divergent values produce inconsistent grammar between the
|
|
66
|
+
* prefilled spine and per-agent suffixes.
|
|
67
|
+
*
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
enableThinking?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Scoped spine branch with guaranteed cleanup
|
|
74
|
+
*
|
|
75
|
+
* Creates (or forks) the pool's spine — the shared KV line that agents
|
|
76
|
+
* fork from and that `ctx.extendSpine` writes onto between tasks. The
|
|
77
|
+
* spine is pruned via try/finally when the body returns or throws,
|
|
78
|
+
* regardless of whether children still exist.
|
|
79
|
+
*
|
|
80
|
+
* Each agent's chat format (system + user + generation prompt) is rendered
|
|
81
|
+
* fresh inside `setupAgent`, so this spine carries no chat context itself —
|
|
82
|
+
* it exists as the pool's branching point and as the line that
|
|
83
|
+
* `ctx.extendSpine` writes onto between tasks.
|
|
84
|
+
*
|
|
85
|
+
* **Cold path** (no `parent`): creates a spine at position 0 with no prefill.
|
|
86
|
+
* Agents fork at position 0; their full chat context lives in their own suffix.
|
|
87
|
+
*
|
|
88
|
+
* **Warm path** (`parent` provided): forks from parent and prefills a turn
|
|
89
|
+
* separator so subsequent agent suffixes land on a clean turn boundary.
|
|
90
|
+
* Sub-agents inherit the parent's full KV state via the fork.
|
|
91
|
+
*
|
|
92
|
+
* @param opts - Sampling parameters and optional parent branch
|
|
93
|
+
* @param body - Operation that receives the spine branch and prefix length.
|
|
94
|
+
* Typically calls {@link useAgentPool} inside.
|
|
95
|
+
* @returns The body's return value
|
|
96
|
+
*
|
|
97
|
+
* @category Agents
|
|
98
|
+
*/
|
|
99
|
+
export declare function withSpine<T>(opts: SpineOptions, body: (spine: Branch, prefixLength: number) => Operation<T>): Operation<T>;
|
|
100
|
+
//# sourceMappingURL=spine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spine.d.ts","sourceRoot":"","sources":["../src/spine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAK1C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9C;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACf;;;;;;;;;;;;OAYG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAiB,SAAS,CAAC,CAAC,EAC1B,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,GAC1D,SAAS,CAAC,CAAC,CAAC,CAyId"}
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.withSpine = withSpine;
|
|
4
4
|
const effection_1 = require("effection");
|
|
5
5
|
const sdk_1 = require("@lloyal-labs/sdk");
|
|
6
6
|
const context_1 = require("./context");
|
|
7
7
|
const trace_scope_1 = require("./trace-scope");
|
|
8
|
+
const toolkit_1 = require("./toolkit");
|
|
8
9
|
/**
|
|
9
|
-
* Scoped
|
|
10
|
+
* Scoped spine branch with guaranteed cleanup
|
|
10
11
|
*
|
|
11
|
-
* Creates (or forks)
|
|
12
|
-
*
|
|
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,
|
|
13
15
|
* regardless of whether children still exist.
|
|
14
16
|
*
|
|
15
17
|
* Each agent's chat format (system + user + generation prompt) is rendered
|
|
16
|
-
* fresh inside `setupAgent`, so this
|
|
17
|
-
* it exists as the pool's branching point and as the
|
|
18
|
-
* `ctx.
|
|
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.
|
|
19
21
|
*
|
|
20
|
-
* **Cold path** (no `parent`): creates a
|
|
22
|
+
* **Cold path** (no `parent`): creates a spine at position 0 with no prefill.
|
|
21
23
|
* Agents fork at position 0; their full chat context lives in their own suffix.
|
|
22
24
|
*
|
|
23
25
|
* **Warm path** (`parent` provided): forks from parent and prefills a turn
|
|
@@ -25,13 +27,13 @@ const trace_scope_1 = require("./trace-scope");
|
|
|
25
27
|
* Sub-agents inherit the parent's full KV state via the fork.
|
|
26
28
|
*
|
|
27
29
|
* @param opts - Sampling parameters and optional parent branch
|
|
28
|
-
* @param body - Operation that receives the
|
|
30
|
+
* @param body - Operation that receives the spine branch and prefix length.
|
|
29
31
|
* Typically calls {@link useAgentPool} inside.
|
|
30
32
|
* @returns The body's return value
|
|
31
33
|
*
|
|
32
34
|
* @category Agents
|
|
33
35
|
*/
|
|
34
|
-
function*
|
|
36
|
+
function* withSpine(opts, body) {
|
|
35
37
|
const ctx = yield* context_1.Ctx.expect();
|
|
36
38
|
const tw = yield* context_1.Trace.expect();
|
|
37
39
|
// Read parent trace ID — connects nested pools to the outer DISPATCH that spawned them
|
|
@@ -44,21 +46,21 @@ function* withSharedRoot(opts, body) {
|
|
|
44
46
|
catch {
|
|
45
47
|
/* no parent — top level */
|
|
46
48
|
}
|
|
47
|
-
const scope = (0, trace_scope_1.traceScope)(tw, parentTraceId, "
|
|
49
|
+
const scope = (0, trace_scope_1.traceScope)(tw, parentTraceId, "withSpine", {
|
|
48
50
|
hasParent: !!opts.parent,
|
|
49
51
|
});
|
|
50
52
|
// Warm path: fork from parent branch (inherits full KV state), prefill a
|
|
51
53
|
// turn separator so the next agent's suffix lands on a clean boundary.
|
|
52
|
-
// Cold path: create fresh
|
|
54
|
+
// Cold path: create fresh spine at position 0 with no prefill — agents
|
|
53
55
|
// fork at 0 and carry their full chat context in their own suffix.
|
|
54
|
-
let
|
|
56
|
+
let spine;
|
|
55
57
|
let prefillTokens;
|
|
56
58
|
if (opts.parent) {
|
|
57
|
-
|
|
59
|
+
spine = opts.parent.forkSync();
|
|
58
60
|
prefillTokens = ctx.getTurnSeparator();
|
|
59
61
|
}
|
|
60
62
|
else {
|
|
61
|
-
|
|
63
|
+
spine = sdk_1.Branch.create(ctx, 0, opts.params ?? { temperature: 0.5 });
|
|
62
64
|
prefillTokens = [];
|
|
63
65
|
}
|
|
64
66
|
tw.write({
|
|
@@ -66,30 +68,30 @@ function* withSharedRoot(opts, body) {
|
|
|
66
68
|
parentTraceId: scope.traceId,
|
|
67
69
|
ts: performance.now(),
|
|
68
70
|
type: "branch:create",
|
|
69
|
-
branchHandle:
|
|
71
|
+
branchHandle: spine.handle,
|
|
70
72
|
parentHandle: opts.parent?.handle ?? null,
|
|
71
73
|
position: opts.parent ? opts.parent.position : 0,
|
|
72
|
-
role: "
|
|
74
|
+
role: "spine",
|
|
73
75
|
});
|
|
74
76
|
if (prefillTokens.length > 0) {
|
|
75
|
-
yield* (0, effection_1.call)(() =>
|
|
77
|
+
yield* (0, effection_1.call)(() => spine.prefill(prefillTokens));
|
|
76
78
|
tw.write({
|
|
77
79
|
traceId: tw.nextId(),
|
|
78
80
|
parentTraceId: scope.traceId,
|
|
79
81
|
ts: performance.now(),
|
|
80
82
|
type: "branch:prefill",
|
|
81
|
-
branchHandle:
|
|
83
|
+
branchHandle: spine.handle,
|
|
82
84
|
tokenCount: prefillTokens.length,
|
|
83
|
-
role: "
|
|
85
|
+
role: "spineHeader",
|
|
84
86
|
});
|
|
85
87
|
}
|
|
86
88
|
// Shared role+tools mode: format the chat header once and prefill onto
|
|
87
|
-
// the
|
|
89
|
+
// the spine. Agents forking from this spine inherit system+tools tokens
|
|
88
90
|
// via metadata-only prefix-share (no per-spawn re-prefill). The resulting
|
|
89
|
-
// FormatConfig is stashed on
|
|
91
|
+
// FormatConfig is stashed on SpineFmt so setupAgent can detect shared
|
|
90
92
|
// mode and copy parser/grammar/format/triggers without re-emitting the
|
|
91
93
|
// tool schemas in each agent's suffix.
|
|
92
|
-
let
|
|
94
|
+
let spineFmt = null;
|
|
93
95
|
if (opts.systemPrompt !== undefined) {
|
|
94
96
|
const enableThinking = opts.enableThinking ?? false;
|
|
95
97
|
const messages = JSON.stringify([{ role: "system", content: opts.systemPrompt }]);
|
|
@@ -100,23 +102,42 @@ function* withSharedRoot(opts, body) {
|
|
|
100
102
|
// trailing assistant generation prompt and corrupt the boundary.
|
|
101
103
|
addGenerationPrompt: false,
|
|
102
104
|
};
|
|
103
|
-
if (opts.
|
|
104
|
-
fmtOpts.tools = opts.toolsJson;
|
|
105
|
+
if (opts.tools && opts.tools.length > 0) {
|
|
106
|
+
fmtOpts.tools = (0, toolkit_1.createToolkit)(opts.tools).toolsJson;
|
|
107
|
+
}
|
|
105
108
|
const formatted = ctx.formatChatSync(messages, fmtOpts);
|
|
106
109
|
const headerTokens = ctx.tokenizeSync(formatted.prompt, false);
|
|
110
|
+
// Spine-seed emission for trace replay (`extractSpineSeed`). Captures
|
|
111
|
+
// the rendered chat prompt verbatim so a later `reconstructBranch`
|
|
112
|
+
// can rebuild this exact KV state in a fresh context. The token-count
|
|
113
|
+
// `branch:prefill` below is informational; the spine seed is the
|
|
114
|
+
// prompt text on this event.
|
|
115
|
+
tw.write({
|
|
116
|
+
traceId: tw.nextId(),
|
|
117
|
+
parentTraceId: scope.traceId,
|
|
118
|
+
ts: performance.now(),
|
|
119
|
+
type: "prompt:format",
|
|
120
|
+
promptText: formatted.prompt,
|
|
121
|
+
tokenCount: headerTokens.length,
|
|
122
|
+
messages,
|
|
123
|
+
tools: opts.tools && opts.tools.length > 0
|
|
124
|
+
? (0, toolkit_1.createToolkit)(opts.tools).toolsJson
|
|
125
|
+
: undefined,
|
|
126
|
+
role: "spine",
|
|
127
|
+
});
|
|
107
128
|
if (headerTokens.length > 0) {
|
|
108
|
-
yield* (0, effection_1.call)(() =>
|
|
129
|
+
yield* (0, effection_1.call)(() => spine.prefill(headerTokens));
|
|
109
130
|
tw.write({
|
|
110
131
|
traceId: tw.nextId(),
|
|
111
132
|
parentTraceId: scope.traceId,
|
|
112
133
|
ts: performance.now(),
|
|
113
134
|
type: "branch:prefill",
|
|
114
|
-
branchHandle:
|
|
135
|
+
branchHandle: spine.handle,
|
|
115
136
|
tokenCount: headerTokens.length,
|
|
116
|
-
role: "
|
|
137
|
+
role: "spineHeader",
|
|
117
138
|
});
|
|
118
139
|
}
|
|
119
|
-
|
|
140
|
+
spineFmt = {
|
|
120
141
|
format: formatted.format,
|
|
121
142
|
reasoningFormat: formatted.reasoningFormat,
|
|
122
143
|
generationPrompt: formatted.generationPrompt,
|
|
@@ -128,25 +149,23 @@ function* withSharedRoot(opts, body) {
|
|
|
128
149
|
};
|
|
129
150
|
}
|
|
130
151
|
try {
|
|
131
|
-
if (
|
|
132
|
-
yield* context_1.
|
|
133
|
-
|
|
134
|
-
yield* context_1.RootFmt.set(rootFmt);
|
|
135
|
-
return yield* body(root, prefillTokens.length);
|
|
152
|
+
if (spineFmt)
|
|
153
|
+
yield* context_1.SpineFmt.set(spineFmt);
|
|
154
|
+
return yield* body(spine, prefillTokens.length);
|
|
136
155
|
}
|
|
137
156
|
finally {
|
|
138
|
-
if (!
|
|
157
|
+
if (!spine.disposed) {
|
|
139
158
|
tw.write({
|
|
140
159
|
traceId: tw.nextId(),
|
|
141
160
|
parentTraceId: scope.traceId,
|
|
142
161
|
ts: performance.now(),
|
|
143
162
|
type: "branch:prune",
|
|
144
|
-
branchHandle:
|
|
163
|
+
branchHandle: spine.handle,
|
|
145
164
|
position: 0,
|
|
146
165
|
});
|
|
147
|
-
|
|
166
|
+
spine.pruneSubtreeSync();
|
|
148
167
|
}
|
|
149
168
|
scope.close();
|
|
150
169
|
}
|
|
151
170
|
}
|
|
152
|
-
//# sourceMappingURL=
|
|
171
|
+
//# sourceMappingURL=spine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spine.js","sourceRoot":"","sources":["../src/spine.ts"],"names":[],"mappings":";;AA0GA,8BA4IC;AAtPD,yCAAiC;AAEjC,0CAA0C;AAE1C,uCAA8D;AAC9D,+CAA2C;AAC3C,uCAA0C;AAyE1C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,QAAe,CAAC,CAAC,SAAS,CACxB,IAAkB,EAClB,IAA2D;IAE3D,MAAM,GAAG,GAAmB,KAAK,CAAC,CAAC,aAAG,CAAC,MAAM,EAAE,CAAC;IAChD,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,eAAK,CAAC,MAAM,EAAE,CAAC;IAEjC,uFAAuF;IACvF,IAAI,aAAa,GAAkB,IAAI,CAAC;IACxC,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,qBAAW,CAAC,GAAG,EAAE,CAAC;QACnC,IAAI,CAAC,IAAI,IAAI;YAAE,aAAa,GAAG,CAAC,CAAC;IACnC,CA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AAE,SAAS,CAAC,eAAe;YAC1C,cAAc;SACf,CAAC;IACJ,CAAC;IAED,IAAI,CAAC;QACH,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/toolkit.d.ts
CHANGED
|
@@ -1,38 +1,65 @@
|
|
|
1
1
|
import type { Tool } from './Tool';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* The compiled tool set an agent pool operates with: the assembled tool
|
|
4
|
+
* instances plus the two projections the runtime needs and the name of
|
|
5
|
+
* the designated terminal (if any).
|
|
4
6
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
+
* `createToolkit` is the single place a `Tool[]` (plus an optional
|
|
8
|
+
* terminal) is turned into the shapes the framework consumes. Nothing
|
|
9
|
+
* downstream consumes a `Toolkit` as a whole — the formatter reads
|
|
10
|
+
* `toolsJson`, the pool reads `toolMap` and `terminalName` — so this is
|
|
11
|
+
* internal plumbing, not a developer-facing concept. Harnesses pass
|
|
12
|
+
* `tools: Tool[]` + `terminal?: Tool` to `agentPool` / `useAgent`; the
|
|
13
|
+
* wrappers call `createToolkit` for them.
|
|
7
14
|
*
|
|
8
15
|
* @category Agents
|
|
9
16
|
*/
|
|
10
17
|
export interface Toolkit {
|
|
11
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* The assembled tool set — the supplied tools plus the designated
|
|
20
|
+
* terminal (if one was given and wasn't already present), deduped by
|
|
21
|
+
* name. `toolMap` and `toolsJson` are derived from exactly this list.
|
|
22
|
+
*/
|
|
23
|
+
tools: Tool[];
|
|
24
|
+
/** Name-to-instance map used by {@link useAgentPool} for tool dispatch. */
|
|
12
25
|
toolMap: Map<string, Tool>;
|
|
13
|
-
/** JSON-serialized tool schemas passed to `formatChat()` via task specs */
|
|
26
|
+
/** JSON-serialized tool schemas passed to `formatChat()` via task specs. */
|
|
14
27
|
toolsJson: string;
|
|
28
|
+
/**
|
|
29
|
+
* Name of the terminal tool, when one was designated via the
|
|
30
|
+
* `terminal` argument. The pool intercepts a call to this tool at the
|
|
31
|
+
* policy layer and extracts its `result` arg as the agent's return
|
|
32
|
+
* value (capture-only — the terminal's `execute()` is not run).
|
|
33
|
+
* Undefined when no terminal was designated (agent ends on
|
|
34
|
+
* free-text/stop).
|
|
35
|
+
*/
|
|
36
|
+
terminalName?: string;
|
|
15
37
|
}
|
|
16
38
|
/**
|
|
17
|
-
*
|
|
39
|
+
* Compile a `Tool[]` (and an optional terminal) into a {@link Toolkit}.
|
|
18
40
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
41
|
+
* The `terminal` is the tool that ends an agent's turn — `report`,
|
|
42
|
+
* `email`, `persistToDB`, whatever the harness designates. It's passed
|
|
43
|
+
* by **reference** (not by name), so there's no string to mistype and
|
|
44
|
+
* no "the terminal must also appear in the array" coupling: the terminal
|
|
45
|
+
* is merged into the assembled set here (deduped if already present), so
|
|
46
|
+
* its schema reaches the model and its instance is dispatchable, and its
|
|
47
|
+
* name is recorded as {@link Toolkit.terminalName}.
|
|
22
48
|
*
|
|
23
|
-
* @param tools -
|
|
24
|
-
*
|
|
49
|
+
* @param tools - The agent's non-terminal tools (app/source tools, or
|
|
50
|
+
* harness-constructed tools).
|
|
51
|
+
* @param terminal - Optional terminal tool. Omit for pools that end on
|
|
52
|
+
* free-text/stop.
|
|
25
53
|
*
|
|
26
54
|
* @example
|
|
27
55
|
* ```typescript
|
|
28
|
-
* const
|
|
29
|
-
* new SearchTool(chunks, reranker),
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* ]);
|
|
56
|
+
* const toolkit = createToolkit(
|
|
57
|
+
* [new SearchTool(chunks, reranker), new ReadFileTool(resources)],
|
|
58
|
+
* reportTool,
|
|
59
|
+
* );
|
|
33
60
|
* ```
|
|
34
61
|
*
|
|
35
62
|
* @category Agents
|
|
36
63
|
*/
|
|
37
|
-
export declare function createToolkit(tools: Tool[]): Toolkit;
|
|
64
|
+
export declare function createToolkit(tools: Tool[], terminal?: Tool): Toolkit;
|
|
38
65
|
//# sourceMappingURL=toolkit.d.ts.map
|
package/dist/toolkit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolkit.d.ts","sourceRoot":"","sources":["../src/toolkit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC
|
|
1
|
+
{"version":3,"file":"toolkit.d.ts","sourceRoot":"","sources":["../src/toolkit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,OAAO;IACtB;;;;OAIG;IACH,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,2EAA2E;IAC3E,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC3B,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,OAAO,CAWrE"}
|
package/dist/toolkit.js
CHANGED
|
@@ -2,30 +2,40 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createToolkit = createToolkit;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Compile a `Tool[]` (and an optional terminal) into a {@link Toolkit}.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* The `terminal` is the tool that ends an agent's turn — `report`,
|
|
8
|
+
* `email`, `persistToDB`, whatever the harness designates. It's passed
|
|
9
|
+
* by **reference** (not by name), so there's no string to mistype and
|
|
10
|
+
* no "the terminal must also appear in the array" coupling: the terminal
|
|
11
|
+
* is merged into the assembled set here (deduped if already present), so
|
|
12
|
+
* its schema reaches the model and its instance is dispatchable, and its
|
|
13
|
+
* name is recorded as {@link Toolkit.terminalName}.
|
|
10
14
|
*
|
|
11
|
-
* @param tools -
|
|
12
|
-
*
|
|
15
|
+
* @param tools - The agent's non-terminal tools (app/source tools, or
|
|
16
|
+
* harness-constructed tools).
|
|
17
|
+
* @param terminal - Optional terminal tool. Omit for pools that end on
|
|
18
|
+
* free-text/stop.
|
|
13
19
|
*
|
|
14
20
|
* @example
|
|
15
21
|
* ```typescript
|
|
16
|
-
* const
|
|
17
|
-
* new SearchTool(chunks, reranker),
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* ]);
|
|
22
|
+
* const toolkit = createToolkit(
|
|
23
|
+
* [new SearchTool(chunks, reranker), new ReadFileTool(resources)],
|
|
24
|
+
* reportTool,
|
|
25
|
+
* );
|
|
21
26
|
* ```
|
|
22
27
|
*
|
|
23
28
|
* @category Agents
|
|
24
29
|
*/
|
|
25
|
-
function createToolkit(tools) {
|
|
30
|
+
function createToolkit(tools, terminal) {
|
|
31
|
+
const merged = terminal && !tools.some(t => t.name === terminal.name)
|
|
32
|
+
? [...tools, terminal]
|
|
33
|
+
: tools;
|
|
26
34
|
return {
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
tools: merged,
|
|
36
|
+
toolMap: new Map(merged.map(t => [t.name, t])),
|
|
37
|
+
toolsJson: JSON.stringify(merged.map(t => t.schema)),
|
|
38
|
+
terminalName: terminal?.name,
|
|
29
39
|
};
|
|
30
40
|
}
|
|
31
41
|
//# sourceMappingURL=toolkit.js.map
|
package/dist/toolkit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolkit.js","sourceRoot":"","sources":["../src/toolkit.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"toolkit.js","sourceRoot":"","sources":["../src/toolkit.ts"],"names":[],"mappings":";;AAiEA,sCAWC;AArCD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,aAAa,CAAC,KAAa,EAAE,QAAe;IAC1D,MAAM,MAAM,GACV,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,CAAC;QACpD,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,QAAQ,CAAC;QACtB,CAAC,CAAC,KAAK,CAAC;IACZ,OAAO;QACL,KAAK,EAAE,MAAM;QACb,OAAO,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAC9C,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QACpD,YAAY,EAAE,QAAQ,EAAE,IAAI;KAC7B,CAAC;AACJ,CAAC"}
|