@lloyal-labs/lloyal-agents 1.5.8 → 2.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/README.md +81 -97
- package/dist/Agent.d.ts +60 -1
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +87 -1
- package/dist/Agent.js.map +1 -1
- package/dist/AgentPolicy.d.ts +52 -16
- package/dist/AgentPolicy.d.ts.map +1 -1
- package/dist/AgentPolicy.js +114 -43
- package/dist/AgentPolicy.js.map +1 -1
- package/dist/agent-pool.d.ts +17 -5
- package/dist/agent-pool.d.ts.map +1 -1
- package/dist/agent-pool.js +707 -417
- package/dist/agent-pool.js.map +1 -1
- package/dist/combinators.d.ts +29 -0
- package/dist/combinators.d.ts.map +1 -0
- package/dist/combinators.js +37 -0
- package/dist/combinators.js.map +1 -0
- package/dist/context.d.ts +18 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +18 -1
- package/dist/context.js.map +1 -1
- package/dist/create-agent-pool.d.ts +96 -0
- package/dist/create-agent-pool.d.ts.map +1 -0
- package/dist/create-agent-pool.js +84 -0
- package/dist/create-agent-pool.js.map +1 -0
- package/dist/index.d.ts +10 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -8
- 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/shared-root.d.ts +56 -18
- package/dist/shared-root.d.ts.map +1 -1
- package/dist/shared-root.js +79 -52
- package/dist/shared-root.js.map +1 -1
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js.map +1 -1
- package/dist/trace-types.d.ts +23 -2
- package/dist/trace-types.d.ts.map +1 -1
- package/dist/trace-writer.d.ts +4 -1
- package/dist/trace-writer.d.ts.map +1 -1
- package/dist/trace-writer.js +6 -2
- package/dist/trace-writer.js.map +1 -1
- package/dist/types.d.ts +42 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/use-agent.d.ts +92 -0
- package/dist/use-agent.d.ts.map +1 -0
- package/dist/use-agent.js +127 -0
- package/dist/use-agent.js.map +1 -0
- package/package.json +5 -5
- package/dist/generate.d.ts +0 -77
- package/dist/generate.d.ts.map +0 -1
- package/dist/generate.js +0 -166
- package/dist/generate.js.map +0 -1
- package/dist/run-agents.d.ts +0 -39
- package/dist/run-agents.d.ts.map +0 -1
- package/dist/run-agents.js +0 -46
- package/dist/run-agents.js.map +0 -1
- package/dist/spawn-agents.d.ts +0 -104
- package/dist/spawn-agents.d.ts.map +0 -1
- package/dist/spawn-agents.js +0 -255
- package/dist/spawn-agents.js.map +0 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAgent = useAgent;
|
|
4
|
+
exports.agent = agent;
|
|
5
|
+
const effection_1 = require("effection");
|
|
6
|
+
const sdk_1 = require("@lloyal-labs/sdk");
|
|
7
|
+
const context_1 = require("./context");
|
|
8
|
+
const agent_pool_1 = require("./agent-pool");
|
|
9
|
+
const toolkit_1 = require("./toolkit");
|
|
10
|
+
const trace_scope_1 = require("./trace-scope");
|
|
11
|
+
const orchestrators_1 = require("./orchestrators");
|
|
12
|
+
/**
|
|
13
|
+
* Single-agent resource — delegates to {@link useAgentPool} N=1.
|
|
14
|
+
*
|
|
15
|
+
* One path. No conditional. Tools optional — `useAgentPool` with no tools
|
|
16
|
+
* degenerates cleanly (tick loop: produce → commit → stop, no dispatch).
|
|
17
|
+
*
|
|
18
|
+
* Provides a completed Agent with branches alive. The resource keeps the
|
|
19
|
+
* root and agent branch alive until the caller's scope exits — caller can
|
|
20
|
+
* fork from the Agent's branch for verification or follow-up.
|
|
21
|
+
*
|
|
22
|
+
* Root managed via `ensure()` (not `withSharedRoot`) because the resource
|
|
23
|
+
* lifetime requires the root alive until the caller's scope exits.
|
|
24
|
+
*
|
|
25
|
+
* Events stream passively to the broadcast Channel during the inline drain.
|
|
26
|
+
*
|
|
27
|
+
* @param opts - Agent configuration
|
|
28
|
+
* @returns Agent with result populated, branches alive
|
|
29
|
+
*
|
|
30
|
+
* @example Single agent with tools
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const agent = yield* useAgent({
|
|
33
|
+
* systemPrompt: "You are a research assistant.",
|
|
34
|
+
* task: "Find information about X",
|
|
35
|
+
* tools: [searchTool, reportTool],
|
|
36
|
+
* terminalTool: 'report',
|
|
37
|
+
* });
|
|
38
|
+
* // agent.result — findings
|
|
39
|
+
* // agent.branch — alive, can fork from
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @category Agents
|
|
43
|
+
*/
|
|
44
|
+
function useAgent(opts) {
|
|
45
|
+
return (0, effection_1.resource)(function* (provide) {
|
|
46
|
+
const ctx = yield* context_1.Ctx.expect();
|
|
47
|
+
const broadcast = yield* context_1.Events.expect();
|
|
48
|
+
const tw = yield* context_1.Trace.expect();
|
|
49
|
+
const toolkit = (0, toolkit_1.createToolkit)(opts.tools ?? []);
|
|
50
|
+
const warmParent = opts.parent ?? opts.session?.trunk ?? undefined;
|
|
51
|
+
const scope = (0, trace_scope_1.traceScope)(tw, null, 'useAgent', {
|
|
52
|
+
hasTools: !!(opts.tools?.length),
|
|
53
|
+
hasParent: !!warmParent,
|
|
54
|
+
});
|
|
55
|
+
// Create root — ensure() for resource lifetime (not withSharedRoot'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.
|
|
59
|
+
const root = warmParent
|
|
60
|
+
? warmParent.forkSync()
|
|
61
|
+
: sdk_1.Branch.create(ctx, 0, opts.params ?? { temperature: 0.5 });
|
|
62
|
+
yield* (0, effection_1.ensure)(() => { if (!root.disposed)
|
|
63
|
+
root.pruneSubtreeSync(); });
|
|
64
|
+
const prefillTokens = warmParent ? ctx.getTurnSeparator() : [];
|
|
65
|
+
if (prefillTokens.length > 0) {
|
|
66
|
+
yield* (0, effection_1.call)(() => root.prefill(prefillTokens));
|
|
67
|
+
}
|
|
68
|
+
// Eager grammar from schema — set on root before fork.
|
|
69
|
+
// Fork inherits grammar state. formatChatSync returns no grammar for
|
|
70
|
+
// no-tools case, so applyLazyGrammar is a no-op and the inherited
|
|
71
|
+
// eager grammar persists on the forked agent branch.
|
|
72
|
+
if (opts.schema) {
|
|
73
|
+
const grammar = yield* (0, effection_1.call)(() => ctx.jsonSchemaToGrammar(JSON.stringify(opts.schema)));
|
|
74
|
+
root.setGrammar(grammar);
|
|
75
|
+
}
|
|
76
|
+
// Delegate to useAgentPool N=1 via a trivial parallel orchestrator
|
|
77
|
+
const hasTools = !!(opts.tools?.length);
|
|
78
|
+
const sub = yield* (0, agent_pool_1.useAgentPool)({
|
|
79
|
+
root,
|
|
80
|
+
orchestrate: (0, orchestrators_1.parallel)([{ content: opts.task, systemPrompt: opts.systemPrompt }]),
|
|
81
|
+
toolsJson: hasTools ? toolkit.toolsJson : '',
|
|
82
|
+
tools: toolkit.toolMap,
|
|
83
|
+
terminalTool: opts.terminalTool,
|
|
84
|
+
maxTurns: opts.maxTurns,
|
|
85
|
+
policy: opts.policy,
|
|
86
|
+
trace: opts.trace,
|
|
87
|
+
});
|
|
88
|
+
// Drain Subscription inline — forward to broadcast
|
|
89
|
+
let next = yield* sub.next();
|
|
90
|
+
while (!next.done) {
|
|
91
|
+
yield* broadcast.send(next.value);
|
|
92
|
+
next = yield* sub.next();
|
|
93
|
+
}
|
|
94
|
+
const pool = next.value;
|
|
95
|
+
scope.close();
|
|
96
|
+
yield* provide(pool.agents[0].agent);
|
|
97
|
+
// Resource stays alive — branch alive for caller to fork from
|
|
98
|
+
// ensure() prunes root on scope exit
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Single-agent scoped operation — wraps {@link useAgent} in `scoped()`.
|
|
103
|
+
*
|
|
104
|
+
* Returns completed Agent with result populated. Branches pruned on scope exit.
|
|
105
|
+
* This is the harness-level API for single-agent steps (plan, eval, bridge).
|
|
106
|
+
*
|
|
107
|
+
* @param opts - Agent configuration (same as {@link UseAgentOpts})
|
|
108
|
+
* @returns Completed Agent with `.result`, `.rawOutput`, `.tokenCount`
|
|
109
|
+
*
|
|
110
|
+
* @example Plan step
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const a = yield* agent({
|
|
113
|
+
* systemPrompt: PLAN.system,
|
|
114
|
+
* task: query,
|
|
115
|
+
* schema: planSchema,
|
|
116
|
+
* });
|
|
117
|
+
* const plan = JSON.parse(a.rawOutput);
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @category Agents
|
|
121
|
+
*/
|
|
122
|
+
function* agent(opts) {
|
|
123
|
+
return yield* (0, effection_1.scoped)(function* () {
|
|
124
|
+
return yield* useAgent(opts);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=use-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,G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GAAG,IAAI,CAAC,KAAK,CAAC;QAExB,KAAK,CAAC,KAAK,EAAE,CAAC;QAEd,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACrC,8DAA8D;QAC9D,qCAAqC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,QAAe,CAAC,CAAC,KAAK,CAAC,IAAkB;IACvC,OAAO,KAAK,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": "
|
|
3
|
+
"version": "2.0.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": "^
|
|
34
|
+
"@lloyal-labs/sdk": "^2.0.0",
|
|
35
35
|
"effection": "^4.0.2",
|
|
36
36
|
"eta": "^4.5.1"
|
|
37
37
|
},
|
package/dist/generate.d.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { Operation } from 'effection';
|
|
2
|
-
import { Branch } from '@lloyal-labs/sdk';
|
|
3
|
-
import type { GenerateOptions, GenerateResult } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* Prepare a branch for generation — create/fork, set grammar, prefill prompt
|
|
6
|
-
*
|
|
7
|
-
* Returns the prepared Branch ready for token production. The caller owns the
|
|
8
|
-
* branch and decides how to consume it:
|
|
9
|
-
*
|
|
10
|
-
* - **Manual loop** — call `produceSync()` / `commit()` for per-token control,
|
|
11
|
-
* streaming UI updates, or integration into a batched tick loop
|
|
12
|
-
* - **Async iterator** — `for await (const { text } of branch)` for convenience
|
|
13
|
-
* - **Pass to `generate()`** — which calls `prepare()` internally
|
|
14
|
-
*
|
|
15
|
-
* The caller is responsible for pruning the branch when done.
|
|
16
|
-
*
|
|
17
|
-
* When `parent` is provided, forks from it and prefills the prompt as a delta
|
|
18
|
-
* (with turn separator). Otherwise creates a fresh root branch.
|
|
19
|
-
*
|
|
20
|
-
* @param opts - Generation options (prompt, grammar, params, parent)
|
|
21
|
-
* @returns Prepared Branch with prompt prefilled, ready for produce/commit
|
|
22
|
-
*
|
|
23
|
-
* @example Stream tokens to UI
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const branch = yield* prepare({ prompt, grammar });
|
|
26
|
-
* try {
|
|
27
|
-
* let output = '';
|
|
28
|
-
* while (true) {
|
|
29
|
-
* const { token, text, isStop } = branch.produceSync();
|
|
30
|
-
* if (isStop) break;
|
|
31
|
-
* yield* call(() => branch.commit(token));
|
|
32
|
-
* output += text;
|
|
33
|
-
* updateUI(text); // per-token streaming
|
|
34
|
-
* }
|
|
35
|
-
* } finally {
|
|
36
|
-
* if (!branch.disposed) branch.pruneSync();
|
|
37
|
-
* }
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @example Batch multiple prepared branches
|
|
41
|
-
* ```typescript
|
|
42
|
-
* const branches = [];
|
|
43
|
-
* for (const task of tasks) {
|
|
44
|
-
* branches.push(yield* prepare({ prompt: task.prompt, grammar, parent: root }));
|
|
45
|
-
* }
|
|
46
|
-
* // Caller batches via BranchStore.commit() for continuous tree batching
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @category Agents
|
|
50
|
-
*/
|
|
51
|
-
export declare function prepare(opts: GenerateOptions): Operation<Branch>;
|
|
52
|
-
/**
|
|
53
|
-
* Single-branch grammar-constrained generation as an Effection operation
|
|
54
|
-
*
|
|
55
|
-
* Convenience wrapper over {@link prepare} — creates/forks a branch, prefills
|
|
56
|
-
* the prompt, generates to EOG, parses the output, and prunes the branch.
|
|
57
|
-
*
|
|
58
|
-
* For per-token streaming or batched generation, use {@link prepare} directly
|
|
59
|
-
* and run your own produce/commit loop.
|
|
60
|
-
*
|
|
61
|
-
* @param opts - Generation options (prompt, grammar, params, parse, parent)
|
|
62
|
-
* @returns Generated text, token count, and optionally parsed result
|
|
63
|
-
*
|
|
64
|
-
* @example Grammar-constrained JSON generation
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const plan = yield* generate({
|
|
67
|
-
* prompt: planPrompt,
|
|
68
|
-
* grammar: planGrammar,
|
|
69
|
-
* params: { temperature: 0.3 },
|
|
70
|
-
* parse: output => JSON.parse(output),
|
|
71
|
-
* });
|
|
72
|
-
* ```
|
|
73
|
-
*
|
|
74
|
-
* @category Agents
|
|
75
|
-
*/
|
|
76
|
-
export declare function generate<T = unknown>(opts: GenerateOptions): Operation<GenerateResult<T>>;
|
|
77
|
-
//# sourceMappingURL=generate.d.ts.map
|
package/dist/generate.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAiB,OAAO,CAAC,IAAI,EAAE,eAAe,GAAG,SAAS,CAAC,MAAM,CAAC,CAiDjE;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAiB,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,eAAe,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CA2C1F"}
|
package/dist/generate.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prepare = prepare;
|
|
4
|
-
exports.generate = generate;
|
|
5
|
-
const effection_1 = require("effection");
|
|
6
|
-
const sdk_1 = require("@lloyal-labs/sdk");
|
|
7
|
-
const context_1 = require("./context");
|
|
8
|
-
const trace_scope_1 = require("./trace-scope");
|
|
9
|
-
/**
|
|
10
|
-
* Prepare a branch for generation — create/fork, set grammar, prefill prompt
|
|
11
|
-
*
|
|
12
|
-
* Returns the prepared Branch ready for token production. The caller owns the
|
|
13
|
-
* branch and decides how to consume it:
|
|
14
|
-
*
|
|
15
|
-
* - **Manual loop** — call `produceSync()` / `commit()` for per-token control,
|
|
16
|
-
* streaming UI updates, or integration into a batched tick loop
|
|
17
|
-
* - **Async iterator** — `for await (const { text } of branch)` for convenience
|
|
18
|
-
* - **Pass to `generate()`** — which calls `prepare()` internally
|
|
19
|
-
*
|
|
20
|
-
* The caller is responsible for pruning the branch when done.
|
|
21
|
-
*
|
|
22
|
-
* When `parent` is provided, forks from it and prefills the prompt as a delta
|
|
23
|
-
* (with turn separator). Otherwise creates a fresh root branch.
|
|
24
|
-
*
|
|
25
|
-
* @param opts - Generation options (prompt, grammar, params, parent)
|
|
26
|
-
* @returns Prepared Branch with prompt prefilled, ready for produce/commit
|
|
27
|
-
*
|
|
28
|
-
* @example Stream tokens to UI
|
|
29
|
-
* ```typescript
|
|
30
|
-
* const branch = yield* prepare({ prompt, grammar });
|
|
31
|
-
* try {
|
|
32
|
-
* let output = '';
|
|
33
|
-
* while (true) {
|
|
34
|
-
* const { token, text, isStop } = branch.produceSync();
|
|
35
|
-
* if (isStop) break;
|
|
36
|
-
* yield* call(() => branch.commit(token));
|
|
37
|
-
* output += text;
|
|
38
|
-
* updateUI(text); // per-token streaming
|
|
39
|
-
* }
|
|
40
|
-
* } finally {
|
|
41
|
-
* if (!branch.disposed) branch.pruneSync();
|
|
42
|
-
* }
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* @example Batch multiple prepared branches
|
|
46
|
-
* ```typescript
|
|
47
|
-
* const branches = [];
|
|
48
|
-
* for (const task of tasks) {
|
|
49
|
-
* branches.push(yield* prepare({ prompt: task.prompt, grammar, parent: root }));
|
|
50
|
-
* }
|
|
51
|
-
* // Caller batches via BranchStore.commit() for continuous tree batching
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* @category Agents
|
|
55
|
-
*/
|
|
56
|
-
function* prepare(opts) {
|
|
57
|
-
const ctx = yield* context_1.Ctx.expect();
|
|
58
|
-
const tw = yield* context_1.Trace.expect();
|
|
59
|
-
const samplerParams = opts.params ?? {};
|
|
60
|
-
const hasParent = !!opts.parent;
|
|
61
|
-
const scope = (0, trace_scope_1.traceScope)(tw, null, 'prepare', { role: hasParent ? 'scratchpad' : 'root', hasGrammar: !!opts.grammar });
|
|
62
|
-
let branch;
|
|
63
|
-
if (opts.parent) {
|
|
64
|
-
branch = yield* (0, effection_1.call)(() => opts.parent.fork());
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
branch = sdk_1.Branch.create(ctx, 0, samplerParams, undefined, opts.grammar);
|
|
68
|
-
}
|
|
69
|
-
tw.write({
|
|
70
|
-
traceId: tw.nextId(), parentTraceId: scope.traceId, ts: performance.now(),
|
|
71
|
-
type: 'branch:create', branchHandle: branch.handle,
|
|
72
|
-
parentHandle: opts.parent?.handle ?? null,
|
|
73
|
-
position: 0, role: hasParent ? 'scratchpad' : 'root',
|
|
74
|
-
});
|
|
75
|
-
let prefillCount;
|
|
76
|
-
if (opts.parent) {
|
|
77
|
-
if (opts.grammar)
|
|
78
|
-
branch.setGrammar(opts.grammar);
|
|
79
|
-
const sep = ctx.getTurnSeparator();
|
|
80
|
-
const delta = yield* (0, effection_1.call)(() => ctx.tokenize(opts.prompt, false));
|
|
81
|
-
const tokens = [...sep, ...delta];
|
|
82
|
-
prefillCount = tokens.length;
|
|
83
|
-
yield* (0, effection_1.call)(() => branch.prefill(tokens));
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
const tokens = ctx.tokenizeSync(opts.prompt);
|
|
87
|
-
prefillCount = tokens.length;
|
|
88
|
-
yield* (0, effection_1.call)(() => branch.prefill(tokens));
|
|
89
|
-
}
|
|
90
|
-
tw.write({
|
|
91
|
-
traceId: tw.nextId(), parentTraceId: scope.traceId, ts: performance.now(),
|
|
92
|
-
type: 'prompt:format', promptText: opts.prompt, tokenCount: prefillCount,
|
|
93
|
-
messages: '', role: 'generate', grammar: opts.grammar,
|
|
94
|
-
});
|
|
95
|
-
tw.write({
|
|
96
|
-
traceId: tw.nextId(), parentTraceId: scope.traceId, ts: performance.now(),
|
|
97
|
-
type: 'branch:prefill', branchHandle: branch.handle, tokenCount: prefillCount,
|
|
98
|
-
role: hasParent ? 'scratchpad' : 'sharedPrefix',
|
|
99
|
-
});
|
|
100
|
-
scope.close();
|
|
101
|
-
return branch;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Single-branch grammar-constrained generation as an Effection operation
|
|
105
|
-
*
|
|
106
|
-
* Convenience wrapper over {@link prepare} — creates/forks a branch, prefills
|
|
107
|
-
* the prompt, generates to EOG, parses the output, and prunes the branch.
|
|
108
|
-
*
|
|
109
|
-
* For per-token streaming or batched generation, use {@link prepare} directly
|
|
110
|
-
* and run your own produce/commit loop.
|
|
111
|
-
*
|
|
112
|
-
* @param opts - Generation options (prompt, grammar, params, parse, parent)
|
|
113
|
-
* @returns Generated text, token count, and optionally parsed result
|
|
114
|
-
*
|
|
115
|
-
* @example Grammar-constrained JSON generation
|
|
116
|
-
* ```typescript
|
|
117
|
-
* const plan = yield* generate({
|
|
118
|
-
* prompt: planPrompt,
|
|
119
|
-
* grammar: planGrammar,
|
|
120
|
-
* params: { temperature: 0.3 },
|
|
121
|
-
* parse: output => JSON.parse(output),
|
|
122
|
-
* });
|
|
123
|
-
* ```
|
|
124
|
-
*
|
|
125
|
-
* @category Agents
|
|
126
|
-
*/
|
|
127
|
-
function* generate(opts) {
|
|
128
|
-
const tw = yield* context_1.Trace.expect();
|
|
129
|
-
const scope = (0, trace_scope_1.traceScope)(tw, null, 'generate', { hasGrammar: !!opts.grammar, hasParent: !!opts.parent });
|
|
130
|
-
const branch = yield* prepare(opts);
|
|
131
|
-
tw.write({
|
|
132
|
-
traceId: tw.nextId(), parentTraceId: scope.traceId, ts: performance.now(),
|
|
133
|
-
type: 'generate:start', branchHandle: branch.handle,
|
|
134
|
-
hasGrammar: !!opts.grammar, hasParent: !!opts.parent,
|
|
135
|
-
role: opts.parent ? 'scratchpad' : 'root',
|
|
136
|
-
});
|
|
137
|
-
try {
|
|
138
|
-
const { output, tokenCount } = yield* (0, effection_1.call)(async () => {
|
|
139
|
-
let output = '';
|
|
140
|
-
let tokenCount = 0;
|
|
141
|
-
for await (const { text } of branch) {
|
|
142
|
-
output += text;
|
|
143
|
-
tokenCount++;
|
|
144
|
-
}
|
|
145
|
-
return { output, tokenCount };
|
|
146
|
-
});
|
|
147
|
-
const parsed = opts.parse ? opts.parse(output) : undefined;
|
|
148
|
-
tw.write({
|
|
149
|
-
traceId: tw.nextId(), parentTraceId: scope.traceId, ts: performance.now(),
|
|
150
|
-
type: 'generate:end', branchHandle: branch.handle, tokenCount, output,
|
|
151
|
-
parsed: parsed !== undefined ? parsed : undefined,
|
|
152
|
-
});
|
|
153
|
-
return { output, tokenCount, parsed };
|
|
154
|
-
}
|
|
155
|
-
finally {
|
|
156
|
-
if (!branch.disposed) {
|
|
157
|
-
tw.write({
|
|
158
|
-
traceId: tw.nextId(), parentTraceId: scope.traceId, ts: performance.now(),
|
|
159
|
-
type: 'branch:prune', branchHandle: branch.handle, position: 0,
|
|
160
|
-
});
|
|
161
|
-
branch.pruneSync();
|
|
162
|
-
}
|
|
163
|
-
scope.close();
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
//# sourceMappingURL=generate.js.map
|
package/dist/generate.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":";;AAsDA,0BAiDC;AA0BD,4BA2CC;AA5KD,yCAAiC;AAEjC,0CAA0C;AAC1C,uCAAuC;AACvC,+CAA2C;AAG3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,QAAe,CAAC,CAAC,OAAO,CAAC,IAAqB;IAC5C,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,aAAG,CAAC,MAAM,EAAE,CAAC;IAChC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,eAAK,CAAC,MAAM,EAAE,CAAC;IACjC,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;IACxC,MAAM,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;IAEhC,MAAM,KAAK,GAAG,IAAA,wBAAU,EAAC,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,IAAI,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M,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAM,CAAC,CAAC,CAAC,SAAS,CAAC;QAEhE,EAAE,CAAC,KAAK,CAAC;YACP,OAAO,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,WAAW,CAAC,GAAG,EAAE;YACzE,IAAI,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM;YACrE,MAAM,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;SAClD,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IACxC,CAAC;YAAS,CAAC;QACT,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YACrB,EAAE,CAAC,KAAK,CAAC;gBACP,OAAO,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,WAAW,CAAC,GAAG,EAAE;gBACzE,IAAI,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;aAC/D,CAAC,CAAC;YACH,MAAM,CAAC,SAAS,EAAE,CAAC;QACrB,CAAC;QACD,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;AACH,CAAC"}
|
package/dist/run-agents.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Operation } from 'effection';
|
|
2
|
-
import type { AgentPoolOptions, AgentPoolResult } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Run an agent pool with automatic branch cleanup on return
|
|
5
|
-
*
|
|
6
|
-
* Wraps {@link useAgentPool} in `scoped()` — agent branches are pruned
|
|
7
|
-
* when the scope exits, before this operation returns. Use this when you
|
|
8
|
-
* don't need to fork from agent branches after the pool completes.
|
|
9
|
-
*
|
|
10
|
-
* For multi-level tree topology (forking from agent branches for
|
|
11
|
-
* verification or follow-up), use {@link useAgentPool} directly within
|
|
12
|
-
* your own scope management.
|
|
13
|
-
*
|
|
14
|
-
* @param opts - Pool configuration: tasks, tools, sampling params, max turns
|
|
15
|
-
* @returns Agent pool result (branches already pruned)
|
|
16
|
-
*
|
|
17
|
-
* @example Research agents with shared root
|
|
18
|
-
* ```typescript
|
|
19
|
-
* const pool = yield* withSharedRoot(
|
|
20
|
-
* { systemPrompt: RESEARCH_PROMPT, tools: toolsJson },
|
|
21
|
-
* function*(root, prefixLen) {
|
|
22
|
-
* return yield* runAgents({
|
|
23
|
-
* tasks: questions.map(q => ({
|
|
24
|
-
* systemPrompt: RESEARCH_PROMPT,
|
|
25
|
-
* content: q,
|
|
26
|
-
* tools: toolsJson,
|
|
27
|
-
* parent: root,
|
|
28
|
-
* })),
|
|
29
|
-
* tools: toolMap,
|
|
30
|
-
* maxTurns: 6,
|
|
31
|
-
* });
|
|
32
|
-
* },
|
|
33
|
-
* );
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @category Agents
|
|
37
|
-
*/
|
|
38
|
-
export declare function runAgents(opts: AgentPoolOptions): Operation<AgentPoolResult>;
|
|
39
|
-
//# sourceMappingURL=run-agents.d.ts.map
|
package/dist/run-agents.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"run-agents.d.ts","sourceRoot":"","sources":["../src/run-agents.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAiB,SAAS,CAAC,IAAI,EAAE,gBAAgB,GAAG,SAAS,CAAC,eAAe,CAAC,CAI7E"}
|
package/dist/run-agents.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runAgents = runAgents;
|
|
4
|
-
const effection_1 = require("effection");
|
|
5
|
-
const agent_pool_1 = require("./agent-pool");
|
|
6
|
-
/**
|
|
7
|
-
* Run an agent pool with automatic branch cleanup on return
|
|
8
|
-
*
|
|
9
|
-
* Wraps {@link useAgentPool} in `scoped()` — agent branches are pruned
|
|
10
|
-
* when the scope exits, before this operation returns. Use this when you
|
|
11
|
-
* don't need to fork from agent branches after the pool completes.
|
|
12
|
-
*
|
|
13
|
-
* For multi-level tree topology (forking from agent branches for
|
|
14
|
-
* verification or follow-up), use {@link useAgentPool} directly within
|
|
15
|
-
* your own scope management.
|
|
16
|
-
*
|
|
17
|
-
* @param opts - Pool configuration: tasks, tools, sampling params, max turns
|
|
18
|
-
* @returns Agent pool result (branches already pruned)
|
|
19
|
-
*
|
|
20
|
-
* @example Research agents with shared root
|
|
21
|
-
* ```typescript
|
|
22
|
-
* const pool = yield* withSharedRoot(
|
|
23
|
-
* { systemPrompt: RESEARCH_PROMPT, tools: toolsJson },
|
|
24
|
-
* function*(root, prefixLen) {
|
|
25
|
-
* return yield* runAgents({
|
|
26
|
-
* tasks: questions.map(q => ({
|
|
27
|
-
* systemPrompt: RESEARCH_PROMPT,
|
|
28
|
-
* content: q,
|
|
29
|
-
* tools: toolsJson,
|
|
30
|
-
* parent: root,
|
|
31
|
-
* })),
|
|
32
|
-
* tools: toolMap,
|
|
33
|
-
* maxTurns: 6,
|
|
34
|
-
* });
|
|
35
|
-
* },
|
|
36
|
-
* );
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @category Agents
|
|
40
|
-
*/
|
|
41
|
-
function* runAgents(opts) {
|
|
42
|
-
return yield* (0, effection_1.scoped)(function* () {
|
|
43
|
-
return yield* (0, agent_pool_1.useAgentPool)({ pruneOnReport: true, ...opts });
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=run-agents.js.map
|
package/dist/run-agents.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"run-agents.js","sourceRoot":"","sources":["../src/run-agents.ts"],"names":[],"mappings":";;AAwCA,8BAIC;AA5CD,yCAAmC;AAEnC,6CAA4C;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,QAAe,CAAC,CAAC,SAAS,CAAC,IAAsB;IAC/C,OAAO,KAAK,CAAC,CAAC,IAAA,kBAAM,EAAC,QAAQ,CAAC;QAC5B,OAAO,KAAK,CAAC,CAAC,IAAA,yBAAY,EAAC,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/spawn-agents.d.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import type { Operation } from 'effection';
|
|
2
|
-
import type { Branch } from '@lloyal-labs/sdk';
|
|
3
|
-
import { Tool } from './Tool';
|
|
4
|
-
import type { JsonSchema } from './types';
|
|
5
|
-
import type { AgentPoolResult } from './types';
|
|
6
|
-
import type { AgentPolicy } from './AgentPolicy';
|
|
7
|
-
import type { EntailmentScorer } from './source';
|
|
8
|
-
/**
|
|
9
|
-
* Configuration for the self-referential recursive tool.
|
|
10
|
-
*
|
|
11
|
-
* @category Agents
|
|
12
|
-
*/
|
|
13
|
-
export interface RecursiveOpts {
|
|
14
|
-
/** Tool name agents see in their toolkit. @default "delegate" */
|
|
15
|
-
name?: string;
|
|
16
|
-
/** Tool description shown in the agent's tool schema. */
|
|
17
|
-
description?: string;
|
|
18
|
-
/**
|
|
19
|
-
* JSON schema for the recursive tool's arguments.
|
|
20
|
-
* @default `{ type: 'object', properties: { tasks: { type: 'array', items: { type: 'string' } } }, required: ['tasks'] }`
|
|
21
|
-
*/
|
|
22
|
-
argsSchema?: JsonSchema;
|
|
23
|
-
/**
|
|
24
|
-
* Extract task strings from parsed tool arguments.
|
|
25
|
-
* @default `(args) => args.tasks as string[]`
|
|
26
|
-
*/
|
|
27
|
-
extractTasks?: (args: Record<string, unknown>) => string[];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Options for {@link spawnAgents}.
|
|
31
|
-
*
|
|
32
|
-
* @category Agents
|
|
33
|
-
*/
|
|
34
|
-
export interface SpawnAgentsOpts {
|
|
35
|
-
/** Data access tools (from a Source or custom). */
|
|
36
|
-
tools: Tool[];
|
|
37
|
-
/** System prompt for spawned agents. */
|
|
38
|
-
systemPrompt: string;
|
|
39
|
-
/** One task per agent — content string for each. */
|
|
40
|
-
tasks: string[];
|
|
41
|
-
/** Terminal tool name + instance. Pool intercepts calls to this tool and extracts results. */
|
|
42
|
-
terminalTool?: {
|
|
43
|
-
name: string;
|
|
44
|
-
tool: Tool;
|
|
45
|
-
};
|
|
46
|
-
/** Max tool-use turns per agent before hard cut. @default 100 */
|
|
47
|
-
maxTurns?: number;
|
|
48
|
-
/**
|
|
49
|
-
* Enable self-referential recursion. When truthy, a wrapper tool is
|
|
50
|
-
* added to the toolkit that calls `spawnAgents()` recursively with
|
|
51
|
-
* the same config. Agents can delegate sub-tasks at arbitrary depth,
|
|
52
|
-
* bounded by KV pressure.
|
|
53
|
-
*
|
|
54
|
-
* Pass `true` for defaults, or an object to configure the tool's
|
|
55
|
-
* name, description, args schema, and task extraction.
|
|
56
|
-
*/
|
|
57
|
-
recursive?: boolean | RecursiveOpts;
|
|
58
|
-
/** Prune agent branches immediately on report, freeing KV mid-pool. */
|
|
59
|
-
pruneOnReport?: boolean;
|
|
60
|
-
/** Custom agent policy. @default DefaultAgentPolicy */
|
|
61
|
-
policy?: AgentPolicy;
|
|
62
|
-
/** Enable structured trace events. */
|
|
63
|
-
trace?: boolean;
|
|
64
|
-
/** Parent branch for warm path (Continuous Context). Sub-agents inherit full attention state. */
|
|
65
|
-
parent?: Branch;
|
|
66
|
-
/** Entailment scorer for semantic coherence across recursive depths.
|
|
67
|
-
* Created via {@link Source.createScorer}. Propagated to all inner pools. */
|
|
68
|
-
scorer?: EntailmentScorer;
|
|
69
|
-
/** Similarity threshold for echo detection. If all proposed sub-questions
|
|
70
|
-
* score above this against the agent's own task, the delegation is rejected
|
|
71
|
-
* as a paraphrase rather than a decomposition. @default 0.8 */
|
|
72
|
-
echoThreshold?: number;
|
|
73
|
-
/** When true, also check proposed questions against ancestor tasks via
|
|
74
|
-
* walkAncestors(). Disabled by default to avoid false positives on
|
|
75
|
-
* genuine narrowing. Enable after observing local echo check behaviour. */
|
|
76
|
-
checkAncestorEcho?: boolean;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Spawn parallel agents with tools, optionally self-referential.
|
|
80
|
-
*
|
|
81
|
-
* Creates a shared root, forks one agent per task, runs the four-phase
|
|
82
|
-
* tick loop, and returns results. When `recursive` is enabled, a
|
|
83
|
-
* delegate tool is added to the toolkit that calls `spawnAgents()`
|
|
84
|
-
* again — enabling agents to delegate sub-tasks at arbitrary depth.
|
|
85
|
-
*
|
|
86
|
-
* This is the general-purpose orchestration primitive. The harness
|
|
87
|
-
* controls the prompt, tools, recursion shape, and policy. Sources
|
|
88
|
-
* just provide data access tools.
|
|
89
|
-
*
|
|
90
|
-
* @example Research harness
|
|
91
|
-
* ```typescript
|
|
92
|
-
* const result = yield* spawnAgents({
|
|
93
|
-
* tools: source.tools,
|
|
94
|
-
* systemPrompt: RESEARCH_PROMPT,
|
|
95
|
-
* tasks: questions,
|
|
96
|
-
* terminalTool: { name: 'report', tool: reportTool },
|
|
97
|
-
* recursive: { name: 'web_research', extractTasks: (a) => a.questions as string[] },
|
|
98
|
-
* });
|
|
99
|
-
* ```
|
|
100
|
-
*
|
|
101
|
-
* @category Agents
|
|
102
|
-
*/
|
|
103
|
-
export declare function spawnAgents(opts: SpawnAgentsOpts): Operation<AgentPoolResult>;
|
|
104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