@lloyal-labs/lloyal-agents 1.2.1 → 1.3.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.
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;AAAA,yCAA0C;AAQ1C;;;;;;;;GAQG;AACU,QAAA,GAAG,GAAG,IAAA,yBAAa,EAAiB,YAAY,CAAC,CAAC;AAE/D;;;;;;;GAOG;AACU,QAAA,KAAK,GAAG,IAAA,yBAAa,EAAc,cAAc,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACU,QAAA,MAAM,GAAG,IAAA,yBAAa,EAA4B,eAAe,CAAC,CAAC;AAEhF;;;;;;;GAOG;AACU,QAAA,KAAK,GAAG,IAAA,yBAAa,EAAc,cAAc,CAAC,CAAC;AAEhE;;;;;;;;GAQG;AACU,QAAA,WAAW,GAAG,IAAA,yBAAa,EAAU,oBAAoB,CAAC,CAAC;AAExE;;;;;;;;;GASG;AACU,QAAA,gBAAgB,GAAG,IAAA,yBAAa,EAAS,yBAAyB,CAAC,CAAC"}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;AAAA,yCAA0C;AAS1C;;;;;;;;GAQG;AACU,QAAA,GAAG,GAAG,IAAA,yBAAa,EAAiB,YAAY,CAAC,CAAC;AAE/D;;;;;;;GAOG;AACU,QAAA,KAAK,GAAG,IAAA,yBAAa,EAAc,cAAc,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACU,QAAA,MAAM,GAAG,IAAA,yBAAa,EAA4B,eAAe,CAAC,CAAC;AAEhF;;;;;;;GAOG;AACU,QAAA,KAAK,GAAG,IAAA,yBAAa,EAAc,cAAc,CAAC,CAAC;AAEhE;;;;;;;;GAQG;AACU,QAAA,WAAW,GAAG,IAAA,yBAAa,EAAU,oBAAoB,CAAC,CAAC;AAExE;;;;;;;;;GASG;AACU,QAAA,gBAAgB,GAAG,IAAA,yBAAa,EAAS,yBAAyB,CAAC,CAAC;AAEjF;;;;;;;;;;;;GAYG;AACU,QAAA,YAAY,GAAG,IAAA,yBAAa,EAAQ,qBAAqB,CAAC,CAAC"}
package/dist/diverge.js CHANGED
@@ -81,7 +81,7 @@ function* diverge(opts) {
81
81
  catch { /* already gone */ }
82
82
  }
83
83
  });
84
- branch.reseedSampler(2000 + i);
84
+ branch.reseedSampler((opts.seedBase ?? 2000) + i);
85
85
  live.push({ branch, output: '', done: false, tokenCount: 0, ppl: Infinity });
86
86
  }
87
87
  // Batched generation — produceSync/commit loop
@@ -1 +1 @@
1
- {"version":3,"file":"diverge.js","sourceRoot":"","sources":["../src/diverge.ts"],"names":[],"mappings":";;AA0CA,0BAsGC;AAhJD,yCAAyC;AAEzC,0CAA0C;AAC1C,uCAAuC;AACvC,6CAA+C;AAG/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,QAAe,CAAC,CAAC,OAAO,CAAC,IAAoB;IAC3C,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,aAAG,CAAC,MAAM,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,eAAK,CAAC,MAAM,EAAE,CAAC;IAEpC,mEAAmE;IACnE,IAAI,IAAY,CAAC;IACjB,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,YAAoB,CAAC;IAEzB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;QACnB,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC;IAC/B,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1F,MAAM,MAAM,GAAG,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7C,IAAI,GAAG,YAAM,CAAC,M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} from './types';
3
4
  /**
4
- * Single-branch grammar-constrained generation as an Effection operation
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
5
14
  *
6
- * Creates a fresh branch (or forks from `opts.parent`), prefills the prompt,
7
- * generates to EOG, and prunes the branch. Uses {@link Branch}'s async
8
- * iterator — single-branch generation doesn't need batched commit.
15
+ * The caller is responsible for pruning the branch when done.
9
16
  *
10
- * When `parent` is provided, the prompt is prefilled as a delta (with turn
11
- * separator) on a fork of the parent. This is the attention scratchpad
12
- * pattern: the fork sees the parent's context, attends to the prompt
13
- * content, generates a result, and is pruned — zero net KV cost.
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.
14
19
  *
15
- * The branch is always cleaned up via try/finally, even on error or
16
- * scope cancellation.
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.
17
60
  *
18
61
  * @param opts - Generation options (prompt, grammar, params, parse, parent)
19
62
  * @returns Generated text, token count, and optionally parsed result
@@ -28,17 +71,6 @@ import type { GenerateOptions, GenerateResult } from './types';
28
71
  * });
29
72
  * ```
30
73
  *
31
- * @example Attention scratchpad — fork, attend, extract, prune
32
- * ```typescript
33
- * const extracted = yield* generate({
34
- * prompt: contentToAttend,
35
- * grammar: extractionGrammar,
36
- * parse: output => JSON.parse(output),
37
- * parent: agentBranch,
38
- * });
39
- * // Fork is pruned — parent's KV unchanged
40
- * ```
41
- *
42
74
  * @category Agents
43
75
  */
44
76
  export declare function generate<T = unknown>(opts: GenerateOptions): Operation<GenerateResult<T>>;
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAI3C,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAiB,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,eAAe,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAoF1F"}
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 CHANGED
@@ -1,58 +1,64 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepare = prepare;
3
4
  exports.generate = generate;
4
5
  const effection_1 = require("effection");
5
6
  const sdk_1 = require("@lloyal-labs/sdk");
6
7
  const context_1 = require("./context");
7
8
  const trace_scope_1 = require("./trace-scope");
8
9
  /**
9
- * Single-branch grammar-constrained generation as an Effection operation
10
+ * Prepare a branch for generation create/fork, set grammar, prefill prompt
10
11
  *
11
- * Creates a fresh branch (or forks from `opts.parent`), prefills the prompt,
12
- * generates to EOG, and prunes the branch. Uses {@link Branch}'s async
13
- * iterator — single-branch generation doesn't need batched commit.
12
+ * Returns the prepared Branch ready for token production. The caller owns the
13
+ * branch and decides how to consume it:
14
14
  *
15
- * When `parent` is provided, the prompt is prefilled as a delta (with turn
16
- * separator) on a fork of the parent. This is the attention scratchpad
17
- * pattern: the fork sees the parent's context, attends to the prompt
18
- * content, generates a result, and is pruned zero net KV cost.
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
19
  *
20
- * The branch is always cleaned up via try/finally, even on error or
21
- * scope cancellation.
20
+ * The caller is responsible for pruning the branch when done.
22
21
  *
23
- * @param opts - Generation options (prompt, grammar, params, parse, parent)
24
- * @returns Generated text, token count, and optionally parsed result
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.
25
24
  *
26
- * @example Grammar-constrained JSON generation
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
27
29
  * ```typescript
28
- * const plan = yield* generate({
29
- * prompt: planPrompt,
30
- * grammar: planGrammar,
31
- * params: { temperature: 0.3 },
32
- * parse: output => JSON.parse(output),
33
- * });
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
+ * }
34
43
  * ```
35
44
  *
36
- * @example Attention scratchpad fork, attend, extract, prune
45
+ * @example Batch multiple prepared branches
37
46
  * ```typescript
38
- * const extracted = yield* generate({
39
- * prompt: contentToAttend,
40
- * grammar: extractionGrammar,
41
- * parse: output => JSON.parse(output),
42
- * parent: agentBranch,
43
- * });
44
- * // Fork is pruned — parent's KV unchanged
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
45
52
  * ```
46
53
  *
47
54
  * @category Agents
48
55
  */
49
- function* generate(opts) {
56
+ function* prepare(opts) {
50
57
  const ctx = yield* context_1.Ctx.expect();
51
58
  const tw = yield* context_1.Trace.expect();
52
59
  const samplerParams = opts.params ?? {};
53
60
  const hasParent = !!opts.parent;
54
- const role = hasParent ? 'scratchpad' : 'root';
55
- const scope = (0, trace_scope_1.traceScope)(tw, null, 'generate', { role, hasGrammar: !!opts.grammar });
61
+ const scope = (0, trace_scope_1.traceScope)(tw, null, 'prepare', { role: hasParent ? 'scratchpad' : 'root', hasGrammar: !!opts.grammar });
56
62
  let branch;
57
63
  if (opts.parent) {
58
64
  branch = yield* (0, effection_1.call)(() => opts.parent.fork());
@@ -66,38 +72,69 @@ function* generate(opts) {
66
72
  parentHandle: opts.parent?.handle ?? null,
67
73
  position: 0, role: hasParent ? 'scratchpad' : 'root',
68
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
+ });
69
137
  try {
70
- let prefillCount;
71
- if (opts.parent) {
72
- if (opts.grammar)
73
- branch.setGrammar(opts.grammar);
74
- const sep = ctx.getTurnSeparator();
75
- const delta = yield* (0, effection_1.call)(() => ctx.tokenize(opts.prompt, false));
76
- const tokens = [...sep, ...delta];
77
- prefillCount = tokens.length;
78
- yield* (0, effection_1.call)(() => branch.prefill(tokens));
79
- }
80
- else {
81
- const tokens = ctx.tokenizeSync(opts.prompt);
82
- prefillCount = tokens.length;
83
- yield* (0, effection_1.call)(() => branch.prefill(tokens));
84
- }
85
- tw.write({
86
- traceId: tw.nextId(), parentTraceId: scope.traceId, ts: performance.now(),
87
- type: 'prompt:format', promptText: opts.prompt, tokenCount: prefillCount,
88
- messages: '', role: 'generate', grammar: opts.grammar,
89
- });
90
- tw.write({
91
- traceId: tw.nextId(), parentTraceId: scope.traceId, ts: performance.now(),
92
- type: 'branch:prefill', branchHandle: branch.handle, tokenCount: prefillCount,
93
- role: hasParent ? 'scratchpad' : 'sharedPrefix',
94
- });
95
- tw.write({
96
- traceId: tw.nextId(), parentTraceId: scope.traceId, ts: performance.now(),
97
- type: 'generate:start', branchHandle: branch.handle,
98
- hasGrammar: !!opts.grammar, hasParent, role,
99
- });
100
- // Consume async iterator inside call() — generators can't use for-await
101
138
  const { output, tokenCount } = yield* (0, effection_1.call)(async () => {
102
139
  let output = '';
103
140
  let tokenCount = 0;
@@ -1 +1 @@
1
- {"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":";;AAgDA,4BAoFC;AApID,yCAAiC;AAEjC,0CAA0C;AAC1C,uCAAuC;AACvC,+CAA2C;AAG3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,QAAe,CAAC,CAAC,QAAQ,CAAc,IAAqB;IAC1D,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;IAChC,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC;IAE/C,MAAM,KAAK,GAAG,IAAA,wBAAU,EAAC,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAErF,IAAI,MAAc,CAAC;IACnB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,MAAM,GAAG,KAAK,CAAC,CAAC,IAAA,gBAAI,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAClD,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,YAAM,CAAC,MAAM,CAAC,GAAG,EAAE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AAE,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/index.d.ts CHANGED
@@ -1,8 +1,14 @@
1
1
  export { Ctx, Store, Events, Trace, TraceParent, ScratchpadParent } from './context';
2
2
  export { Tool } from './Tool';
3
+ export { Agent } from './Agent';
4
+ export type { AgentStatus, FindingsSource, FormatConfig, ToolHistoryEntry } from './Agent';
5
+ export { DefaultAgentPolicy } from './AgentPolicy';
6
+ export type { AgentPolicy, ProduceAction, SettleAction, IdleReason, PolicyConfig, ToolGuard, DefaultAgentPolicyOpts } from './AgentPolicy';
7
+ export { defaultToolGuards } from './AgentPolicy';
8
+ export { CallingAgent } from './context';
3
9
  export { Source } from './source';
4
10
  export { buildUserDelta, buildToolResultDelta } from '@lloyal-labs/sdk';
5
- export { generate } from './generate';
11
+ export { prepare, generate } from './generate';
6
12
  export { diverge } from './diverge';
7
13
  export { useAgentPool, ContextPressure } from './agent-pool';
8
14
  export { runAgents } from './run-agents';
@@ -11,6 +17,8 @@ export { initAgents } from './init';
11
17
  export { withSharedRoot } from './shared-root';
12
18
  export { NullTraceWriter, JsonlTraceWriter } from './trace-writer';
13
19
  export { traceScope } from './trace-scope';
20
+ export { composePrompt, renderPrompt, renderTemplate } from './prompt';
21
+ export type { PromptState, PromptSection, PromptStep } from './prompt';
14
22
  export type { Toolkit } from './toolkit';
15
23
  export type { TraceWriter } from './trace-writer';
16
24
  export type { TraceEvent, TraceId } from './trace-types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names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,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACvE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEvE,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACzD,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC1C,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,YAAY,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,eAAe,EACf,cAAc,EACd,cAAc,EACd,cAAc,EACd,aAAa,EACb,UAAU,GACX,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.traceScope = exports.JsonlTraceWriter = exports.NullTraceWriter = exports.withSharedRoot = exports.initAgents = exports.createToolkit = exports.runAgents = exports.ContextPressure = exports.useAgentPool = exports.diverge = exports.generate = exports.buildToolResultDelta = exports.buildUserDelta = exports.Source = exports.Tool = exports.ScratchpadParent = exports.TraceParent = exports.Trace = exports.Events = exports.Store = exports.Ctx = void 0;
3
+ exports.renderTemplate = exports.renderPrompt = exports.composePrompt = exports.traceScope = exports.JsonlTraceWriter = exports.NullTraceWriter = exports.withSharedRoot = exports.initAgents = exports.createToolkit = exports.runAgents = exports.ContextPressure = exports.useAgentPool = exports.diverge = exports.generate = exports.prepare = exports.buildToolResultDelta = exports.buildUserDelta = exports.Source = exports.CallingAgent = exports.defaultToolGuards = exports.DefaultAgentPolicy = exports.Agent = exports.Tool = exports.ScratchpadParent = exports.TraceParent = exports.Trace = exports.Events = exports.Store = exports.Ctx = void 0;
4
4
  var context_1 = require("./context");
5
5
  Object.defineProperty(exports, "Ctx", { enumerable: true, get: function () { return context_1.Ctx; } });
6
6
  Object.defineProperty(exports, "Store", { enumerable: true, get: function () { return context_1.Store; } });
@@ -10,12 +10,21 @@ Object.defineProperty(exports, "TraceParent", { enumerable: true, get: function
10
10
  Object.defineProperty(exports, "ScratchpadParent", { enumerable: true, get: function () { return context_1.ScratchpadParent; } });
11
11
  var Tool_1 = require("./Tool");
12
12
  Object.defineProperty(exports, "Tool", { enumerable: true, get: function () { return Tool_1.Tool; } });
13
+ var Agent_1 = require("./Agent");
14
+ Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return Agent_1.Agent; } });
15
+ var AgentPolicy_1 = require("./AgentPolicy");
16
+ Object.defineProperty(exports, "DefaultAgentPolicy", { enumerable: true, get: function () { return AgentPolicy_1.DefaultAgentPolicy; } });
17
+ var AgentPolicy_2 = require("./AgentPolicy");
18
+ Object.defineProperty(exports, "defaultToolGuards", { enumerable: true, get: function () { return AgentPolicy_2.defaultToolGuards; } });
19
+ var context_2 = require("./context");
20
+ Object.defineProperty(exports, "CallingAgent", { enumerable: true, get: function () { return context_2.CallingAgent; } });
13
21
  var source_1 = require("./source");
14
22
  Object.defineProperty(exports, "Source", { enumerable: true, get: function () { return source_1.Source; } });
15
23
  var sdk_1 = require("@lloyal-labs/sdk");
16
24
  Object.defineProperty(exports, "buildUserDelta", { enumerable: true, get: function () { return sdk_1.buildUserDelta; } });
17
25
  Object.defineProperty(exports, "buildToolResultDelta", { enumerable: true, get: function () { return sdk_1.buildToolResultDelta; } });
18
26
  var generate_1 = require("./generate");
27
+ Object.defineProperty(exports, "prepare", { enumerable: true, get: function () { return generate_1.prepare; } });
19
28
  Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return generate_1.generate; } });
20
29
  var diverge_1 = require("./diverge");
21
30
  Object.defineProperty(exports, "diverge", { enumerable: true, get: function () { return diverge_1.diverge; } });
@@ -35,4 +44,8 @@ Object.defineProperty(exports, "NullTraceWriter", { enumerable: true, get: funct
35
44
  Object.defineProperty(exports, "JsonlTraceWriter", { enumerable: true, get: function () { return trace_writer_1.JsonlTraceWriter; } });
36
45
  var trace_scope_1 = require("./trace-scope");
37
46
  Object.defineProperty(exports, "traceScope", { enumerable: true, get: function () { return trace_scope_1.traceScope; } });
47
+ var prompt_1 = require("./prompt");
48
+ Object.defineProperty(exports, "composePrompt", { enumerable: true, get: function () { return prompt_1.composePrompt; } });
49
+ Object.defineProperty(exports, "renderPrompt", { enumerable: true, get: function () { return prompt_1.renderPrompt; } });
50
+ Object.defineProperty(exports, "renderTemplate", { enumerable: true, get: function () { return prompt_1.renderTemplate; } });
38
51
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAqF;AAA5E,8FAAA,GAAG,OAAA;AAAE,gGAAA,KAAK,OAAA;AAAE,iGAAA,MAAM,OAAA;AAAE,gGAAA,KAAK,OAAA;AAAE,sGAAA,WAAW,OAAA;AAAE,2GAAA,gBAAgB,OAAA;AACjE,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,wCAAwE;AAA/D,qGAAA,cAAc,OAAA;AAAE,2GAAA,oBAAoB,OAAA;AAC7C,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,2CAA6D;AAApD,0GAAA,YAAY,OAAA;AAAE,6GAAA,eAAe,OAAA;AACtC,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,qCAA0C;AAAjC,wGAAA,aAAa,OAAA;AACtB,+BAAoC;AAA3B,kGAAA,UAAU,OAAA;AACnB,6CAA+C;AAAtC,6GAAA,cAAc,OAAA;AACvB,+CAAmE;AAA1D,+GAAA,eAAe,OAAA;AAAE,gHAAA,gBAAgB,OAAA;AAC1C,6CAA2C;AAAlC,yGAAA,UAAU,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAqF;AAA5E,8FAAA,GAAG,OAAA;AAAE,gGAAA,KAAK,OAAA;AAAE,iGAAA,MAAM,OAAA;AAAE,gGAAA,KAAK,OAAA;AAAE,sGAAA,WAAW,OAAA;AAAE,2GAAA,gBAAgB,OAAA;AACjE,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AAEd,6CAAmD;AAA1C,iHAAA,kBAAkB,OAAA;AAE3B,6CAAkD;AAAzC,gHAAA,iBAAiB,OAAA;AAC1B,qCAAyC;AAAhC,uGAAA,YAAY,OAAA;AACrB,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,wCAAwE;AAA/D,qGAAA,cAAc,OAAA;AAAE,2GAAA,oBAAoB,OAAA;AAC7C,uCAA+C;AAAtC,mGAAA,OAAO,OAAA;AAAE,oGAAA,QAAQ,OAAA;AAC1B,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,2CAA6D;AAApD,0GAAA,YAAY,OAAA;AAAE,6GAAA,eAAe,OAAA;AACtC,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,qCAA0C;AAAjC,wGAAA,aAAa,OAAA;AACtB,+BAAoC;AAA3B,kGAAA,UAAU,OAAA;AACnB,6CAA+C;AAAtC,6GAAA,cAAc,OAAA;AACvB,+CAAmE;AAA1D,+GAAA,eAAe,OAAA;AAAE,gHAAA,gBAAgB,OAAA;AAC1C,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,mCAAuE;AAA9D,uGAAA,aAAa,OAAA;AAAE,sGAAA,YAAY,OAAA;AAAE,wGAAA,cAAc,OAAA"}
@@ -0,0 +1,77 @@
1
+ import type { Tool } from './Tool';
2
+ /**
3
+ * A named content section in a composed prompt.
4
+ *
5
+ * @category Agents
6
+ */
7
+ export interface PromptSection {
8
+ heading: string;
9
+ content: string;
10
+ }
11
+ /**
12
+ * Accumulated prompt state built by composing {@link PromptStep}s.
13
+ *
14
+ * - `clauses` — system prompt fragments (joined with double newline)
15
+ * - `sections` — user content sections (each rendered as `heading:\n\ncontent`)
16
+ * - `tools` — tools available to the agent (fed to {@link createToolkit})
17
+ *
18
+ * @category Agents
19
+ */
20
+ export interface PromptState {
21
+ clauses: string[];
22
+ sections: PromptSection[];
23
+ tools: Tool[];
24
+ }
25
+ /**
26
+ * A pure function that transforms prompt state. Return the state
27
+ * unchanged to skip, or return a new state with additional clauses,
28
+ * sections, or tools. Steps are composed left-to-right via
29
+ * {@link composePrompt}.
30
+ *
31
+ * @category Agents
32
+ */
33
+ export type PromptStep = (state: PromptState) => PromptState;
34
+ /**
35
+ * Reduce an array of {@link PromptStep}s over a base {@link PromptState}.
36
+ *
37
+ * Each step can conditionally add system clauses, user content sections,
38
+ * or tools based on inference state. Steps that return the state unchanged
39
+ * are no-ops.
40
+ *
41
+ * @category Agents
42
+ */
43
+ export declare const composePrompt: (base: PromptState, steps: PromptStep[]) => PromptState;
44
+ /**
45
+ * Render a {@link PromptState} into system and user content strings
46
+ * suitable for `formatChatSync()`.
47
+ *
48
+ * @category Agents
49
+ */
50
+ export declare const renderPrompt: (state: PromptState, query: string) => {
51
+ system: string;
52
+ content: string;
53
+ };
54
+ /**
55
+ * Render a template string with Eta. Templates use standard Eta/EJS
56
+ * syntax: `<%= it.var %>` for interpolation, `<% if (it.x) { %>` for
57
+ * conditionals, `<% it.arr.forEach(...) %>` for loops.
58
+ *
59
+ * Auto-escaping is disabled — templates produce prompt text, not HTML.
60
+ *
61
+ * @param template - Eta template string
62
+ * @param data - Variables available as `it.*` in the template
63
+ * @returns Rendered string
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const result = renderTemplate(
68
+ * 'Hello <%= it.name %><% if (it.age) { %>, age <%= it.age %><% } %>',
69
+ * { name: 'Alice', age: 30 },
70
+ * );
71
+ * // => "Hello Alice, age 30"
72
+ * ```
73
+ *
74
+ * @category Agents
75
+ */
76
+ export declare const renderTemplate: (template: string, data: Record<string, unknown>) => string;
77
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAInC;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,WAAW,KAAK,WAAW,CAAC;AAE7D;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,GACxB,MAAM,WAAW,EACjB,OAAO,UAAU,EAAE,KAClB,WAAmD,CAAC;AAEvD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GACvB,OAAO,WAAW,EAClB,OAAO,MAAM,KACZ;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAMlC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,cAAc,GACzB,UAAU,MAAM,EAChB,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,MAA0C,CAAC"}
package/dist/prompt.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderTemplate = exports.renderPrompt = exports.composePrompt = void 0;
4
+ const eta_1 = require("eta");
5
+ const eta = new eta_1.Eta({ autoEscape: false });
6
+ /**
7
+ * Reduce an array of {@link PromptStep}s over a base {@link PromptState}.
8
+ *
9
+ * Each step can conditionally add system clauses, user content sections,
10
+ * or tools based on inference state. Steps that return the state unchanged
11
+ * are no-ops.
12
+ *
13
+ * @category Agents
14
+ */
15
+ const composePrompt = (base, steps) => steps.reduce((s, fn) => fn(s), base);
16
+ exports.composePrompt = composePrompt;
17
+ /**
18
+ * Render a {@link PromptState} into system and user content strings
19
+ * suitable for `formatChatSync()`.
20
+ *
21
+ * @category Agents
22
+ */
23
+ const renderPrompt = (state, query) => ({
24
+ system: state.clauses.join('\n\n'),
25
+ content: [
26
+ ...state.sections.map((s) => `${s.heading}:\n\n${s.content}`),
27
+ query,
28
+ ].join('\n\n---\n\n'),
29
+ });
30
+ exports.renderPrompt = renderPrompt;
31
+ /**
32
+ * Render a template string with Eta. Templates use standard Eta/EJS
33
+ * syntax: `<%= it.var %>` for interpolation, `<% if (it.x) { %>` for
34
+ * conditionals, `<% it.arr.forEach(...) %>` for loops.
35
+ *
36
+ * Auto-escaping is disabled — templates produce prompt text, not HTML.
37
+ *
38
+ * @param template - Eta template string
39
+ * @param data - Variables available as `it.*` in the template
40
+ * @returns Rendered string
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const result = renderTemplate(
45
+ * 'Hello <%= it.name %><% if (it.age) { %>, age <%= it.age %><% } %>',
46
+ * { name: 'Alice', age: 30 },
47
+ * );
48
+ * // => "Hello Alice, age 30"
49
+ * ```
50
+ *
51
+ * @category Agents
52
+ */
53
+ const renderTemplate = (template, data) => eta.renderString(template, data);
54
+ exports.renderTemplate = renderTemplate;
55
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":";;;AAAA,6BAA0B;AAG1B,MAAM,GAAG,GAAG,IAAI,SAAG,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;AAqC3C;;;;;;;;GAQG;AACI,MAAM,aAAa,GAAG,CAC3B,IAAiB,EACjB,KAAmB,EACN,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AAH1C,QAAA,aAAa,iBAG6B;AAEvD;;;;;GAKG;AACI,MAAM,YAAY,GAAG,CAC1B,KAAkB,EAClB,KAAa,EACwB,EAAE,CAAC,CAAC;IACzC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;IAClC,OAAO,EAAE;QACP,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;QAC7D,KAAK;KACN,CAAC,IAAI,CAAC,aAAa,CAAC;CACtB,CAAC,CAAC;AATU,QAAA,YAAY,gBAStB;AAEH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACI,MAAM,cAAc,GAAG,CAC5B,QAAgB,EAChB,IAA6B,EACrB,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAHjC,QAAA,cAAc,kBAGmB"}
@@ -40,7 +40,7 @@ const agent_pool_1 = require("./agent-pool");
40
40
  */
41
41
  function* runAgents(opts) {
42
42
  return yield* (0, effection_1.scoped)(function* () {
43
- return yield* (0, agent_pool_1.useAgentPool)(opts);
43
+ return yield* (0, agent_pool_1.useAgentPool)({ pruneOnReport: true, ...opts });
44
44
  });
45
45
  }
46
46
  //# sourceMappingURL=run-agents.js.map
@@ -1 +1 @@
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,IAAI,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC"}
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"}