@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/shared-root.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withSharedRoot = withSharedRoot;
|
|
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
|
-
/**
|
|
9
|
-
* Scoped shared root branch with guaranteed cleanup
|
|
10
|
-
*
|
|
11
|
-
* Creates (or forks) a root branch, prefills the system prompt, and passes
|
|
12
|
-
* it to the body function. The root is pruned via try/finally when the body
|
|
13
|
-
* returns or throws, regardless of whether children still exist.
|
|
14
|
-
*
|
|
15
|
-
* **Cold path** (no `parent`): creates root at position 0, prefills system
|
|
16
|
-
* prompt. Use for top-level research where no prior context exists.
|
|
17
|
-
*
|
|
18
|
-
* **Warm path** (`parent` provided): forks from parent branch, prefills
|
|
19
|
-
* system prompt as a delta. Sub-agents inherit the parent's full KV state.
|
|
20
|
-
* Use for recursive tools (web_research, research) where sub-agents should
|
|
21
|
-
* attend over the calling agent's accumulated evidence.
|
|
22
|
-
*
|
|
23
|
-
* @param opts - System prompt, tools, sampling parameters, and optional parent branch
|
|
24
|
-
* @param body - Operation that receives the root branch and prefix length.
|
|
25
|
-
* Typically calls {@link runAgents} or {@link useAgentPool} inside.
|
|
26
|
-
* @returns The body's return value
|
|
27
|
-
*
|
|
28
|
-
* @category Agents
|
|
29
|
-
*/
|
|
30
|
-
function* withSharedRoot(opts, body) {
|
|
31
|
-
const ctx = yield* context_1.Ctx.expect();
|
|
32
|
-
const tw = yield* context_1.Trace.expect();
|
|
33
|
-
// Read parent trace ID — connects nested pools to the outer DISPATCH that spawned them
|
|
34
|
-
let parentTraceId = null;
|
|
35
|
-
try {
|
|
36
|
-
const p = yield* context_1.TraceParent.get();
|
|
37
|
-
if (p != null)
|
|
38
|
-
parentTraceId = p;
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
/* no parent — top level */
|
|
42
|
-
}
|
|
43
|
-
const scope = (0, trace_scope_1.traceScope)(tw, parentTraceId, "withSharedRoot", {
|
|
44
|
-
hasTools: !!opts.tools,
|
|
45
|
-
systemPromptLength: opts.systemPrompt.length,
|
|
46
|
-
hasParent: !!opts.parent,
|
|
47
|
-
});
|
|
48
|
-
const messages = [{ role: "system", content: opts.systemPrompt }];
|
|
49
|
-
const fmtOpts = {
|
|
50
|
-
addGenerationPrompt: false,
|
|
51
|
-
enableThinking: false,
|
|
52
|
-
};
|
|
53
|
-
if (opts.tools)
|
|
54
|
-
fmtOpts.tools = opts.tools;
|
|
55
|
-
const fmt = ctx.formatChatSync(JSON.stringify(messages), fmtOpts);
|
|
56
|
-
const sharedTokens = ctx.tokenizeSync(fmt.prompt);
|
|
57
|
-
tw.write({
|
|
58
|
-
traceId: tw.nextId(),
|
|
59
|
-
parentTraceId: scope.traceId,
|
|
60
|
-
ts: performance.now(),
|
|
61
|
-
type: "prompt:format",
|
|
62
|
-
promptText: fmt.prompt,
|
|
63
|
-
tokenCount: sharedTokens.length,
|
|
64
|
-
messages: JSON.stringify(messages),
|
|
65
|
-
tools: opts.tools,
|
|
66
|
-
grammar: fmt.grammar || undefined,
|
|
67
|
-
role: "sharedRoot",
|
|
68
|
-
});
|
|
69
|
-
// Warm path: fork from parent branch (inherits full KV state)
|
|
70
|
-
// Cold path: create fresh root at position 0
|
|
71
|
-
let root;
|
|
72
|
-
let prefillTokens;
|
|
73
|
-
if (opts.parent) {
|
|
74
|
-
root = opts.parent.forkSync();
|
|
75
|
-
// Warm path: parent already has system prompt + tools in KV.
|
|
76
|
-
// Only prefill turn separator — the prompt is inherited via fork.
|
|
77
|
-
// This saves ~760 tokens per recursive fork.
|
|
78
|
-
const sep = ctx.getTurnSeparator();
|
|
79
|
-
prefillTokens = sep;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
root = sdk_1.Branch.create(ctx, 0, opts.params ?? { temperature: 0.5 });
|
|
83
|
-
prefillTokens = sharedTokens;
|
|
84
|
-
}
|
|
85
|
-
tw.write({
|
|
86
|
-
traceId: tw.nextId(),
|
|
87
|
-
parentTraceId: scope.traceId,
|
|
88
|
-
ts: performance.now(),
|
|
89
|
-
type: "branch:create",
|
|
90
|
-
branchHandle: root.handle,
|
|
91
|
-
parentHandle: opts.parent?.handle ?? null,
|
|
92
|
-
position: opts.parent ? opts.parent.position : 0,
|
|
93
|
-
role: "sharedRoot",
|
|
94
|
-
});
|
|
95
|
-
yield* (0, effection_1.call)(() => root.prefill(prefillTokens));
|
|
96
|
-
tw.write({
|
|
97
|
-
traceId: tw.nextId(),
|
|
98
|
-
parentTraceId: scope.traceId,
|
|
99
|
-
ts: performance.now(),
|
|
100
|
-
type: "branch:prefill",
|
|
101
|
-
branchHandle: root.handle,
|
|
102
|
-
tokenCount: prefillTokens.length,
|
|
103
|
-
role: "sharedPrefix",
|
|
104
|
-
});
|
|
105
|
-
try {
|
|
106
|
-
if (opts.enableScratchpad)
|
|
107
|
-
yield* context_1.ScratchpadParent.set(root);
|
|
108
|
-
return yield* body(root, prefillTokens.length);
|
|
109
|
-
}
|
|
110
|
-
finally {
|
|
111
|
-
if (!root.disposed) {
|
|
112
|
-
tw.write({
|
|
113
|
-
traceId: tw.nextId(),
|
|
114
|
-
parentTraceId: scope.traceId,
|
|
115
|
-
ts: performance.now(),
|
|
116
|
-
type: "branch:prune",
|
|
117
|
-
branchHandle: root.handle,
|
|
118
|
-
position: 0,
|
|
119
|
-
});
|
|
120
|
-
root.pruneSubtreeSync();
|
|
121
|
-
}
|
|
122
|
-
scope.close();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
//# sourceMappingURL=shared-root.js.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