@lloyal-labs/lloyal-agents 1.2.2 → 1.4.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/dist/Agent.d.ts +165 -0
- package/dist/Agent.d.ts.map +1 -0
- package/dist/Agent.js +160 -0
- package/dist/Agent.js.map +1 -0
- package/dist/AgentPolicy.d.ts +125 -0
- package/dist/AgentPolicy.d.ts.map +1 -0
- package/dist/AgentPolicy.js +109 -0
- package/dist/AgentPolicy.js.map +1 -0
- package/dist/agent-pool.d.ts.map +1 -1
- package/dist/agent-pool.js +184 -117
- package/dist/agent-pool.js.map +1 -1
- package/dist/context.d.ts +15 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +15 -1
- package/dist/context.js.map +1 -1
- package/dist/diverge.js +1 -1
- package/dist/diverge.js.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/prompt.d.ts +77 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +55 -0
- package/dist/prompt.js.map +1 -0
- package/dist/shared-root.d.ts +22 -25
- package/dist/shared-root.d.ts.map +1 -1
- package/dist/shared-root.js +32 -31
- package/dist/shared-root.js.map +1 -1
- package/dist/source.d.ts +11 -13
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +7 -9
- package/dist/source.js.map +1 -1
- package/dist/spawn-agents.d.ts +101 -0
- package/dist/spawn-agents.d.ts.map +1 -0
- package/dist/spawn-agents.js +160 -0
- package/dist/spawn-agents.js.map +1 -0
- package/dist/types.d.ts +31 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,101 @@
|
|
|
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, PressureThresholds } from './types';
|
|
6
|
+
import type { AgentPolicy } from './AgentPolicy';
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for the self-referential recursive tool.
|
|
9
|
+
*
|
|
10
|
+
* @category Agents
|
|
11
|
+
*/
|
|
12
|
+
export interface RecursiveOpts {
|
|
13
|
+
/** Tool name agents see in their toolkit. @default "delegate" */
|
|
14
|
+
name?: string;
|
|
15
|
+
/** Tool description shown in the agent's tool schema. */
|
|
16
|
+
description?: string;
|
|
17
|
+
/**
|
|
18
|
+
* JSON schema for the recursive tool's arguments.
|
|
19
|
+
* @default `{ type: 'object', properties: { tasks: { type: 'array', items: { type: 'string' } } }, required: ['tasks'] }`
|
|
20
|
+
*/
|
|
21
|
+
argsSchema?: JsonSchema;
|
|
22
|
+
/**
|
|
23
|
+
* Extract task strings from parsed tool arguments.
|
|
24
|
+
* @default `(args) => args.tasks as string[]`
|
|
25
|
+
*/
|
|
26
|
+
extractTasks?: (args: Record<string, unknown>) => string[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Options for {@link spawnAgents}.
|
|
30
|
+
*
|
|
31
|
+
* @category Agents
|
|
32
|
+
*/
|
|
33
|
+
export interface SpawnAgentsOpts {
|
|
34
|
+
/** Data access tools (from a Source or custom). */
|
|
35
|
+
tools: Tool[];
|
|
36
|
+
/** System prompt for spawned agents. */
|
|
37
|
+
systemPrompt: string;
|
|
38
|
+
/** One task per agent — content string for each. */
|
|
39
|
+
tasks: string[];
|
|
40
|
+
/** Terminal tool name + instance. Pool intercepts calls to this tool and extracts results. */
|
|
41
|
+
terminalTool?: {
|
|
42
|
+
name: string;
|
|
43
|
+
tool: Tool;
|
|
44
|
+
};
|
|
45
|
+
/** Max tool-use turns per agent before hard cut. @default 100 */
|
|
46
|
+
maxTurns?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Enable self-referential recursion. When truthy, a wrapper tool is
|
|
49
|
+
* added to the toolkit that calls `spawnAgents()` recursively with
|
|
50
|
+
* the same config. Agents can delegate sub-tasks at arbitrary depth,
|
|
51
|
+
* bounded by KV pressure.
|
|
52
|
+
*
|
|
53
|
+
* Pass `true` for defaults, or an object to configure the tool's
|
|
54
|
+
* name, description, args schema, and task extraction.
|
|
55
|
+
*/
|
|
56
|
+
recursive?: boolean | RecursiveOpts;
|
|
57
|
+
/** Scratchpad extraction for agents killed before reporting. */
|
|
58
|
+
reportPrompt?: {
|
|
59
|
+
system: string;
|
|
60
|
+
user: string;
|
|
61
|
+
minTokens?: number;
|
|
62
|
+
minToolCalls?: number;
|
|
63
|
+
};
|
|
64
|
+
/** Prune agent branches immediately on report, freeing KV mid-pool. */
|
|
65
|
+
pruneOnReport?: boolean;
|
|
66
|
+
/** KV pressure thresholds for the agent pool. */
|
|
67
|
+
pressure?: PressureThresholds;
|
|
68
|
+
/** Custom agent policy. @default DefaultAgentPolicy */
|
|
69
|
+
policy?: AgentPolicy;
|
|
70
|
+
/** Enable structured trace events. */
|
|
71
|
+
trace?: boolean;
|
|
72
|
+
/** Parent branch for warm path (Continuous Context). Sub-agents inherit full attention state. */
|
|
73
|
+
parent?: Branch;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Spawn parallel agents with tools, optionally self-referential.
|
|
77
|
+
*
|
|
78
|
+
* Creates a shared root, forks one agent per task, runs the four-phase
|
|
79
|
+
* tick loop, and returns results. When `recursive` is enabled, a
|
|
80
|
+
* delegate tool is added to the toolkit that calls `spawnAgents()`
|
|
81
|
+
* again — enabling agents to delegate sub-tasks at arbitrary depth.
|
|
82
|
+
*
|
|
83
|
+
* This is the general-purpose orchestration primitive. The harness
|
|
84
|
+
* controls the prompt, tools, recursion shape, and policy. Sources
|
|
85
|
+
* just provide data access tools.
|
|
86
|
+
*
|
|
87
|
+
* @example Research harness
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const result = yield* spawnAgents({
|
|
90
|
+
* tools: source.tools,
|
|
91
|
+
* systemPrompt: RESEARCH_PROMPT,
|
|
92
|
+
* tasks: questions,
|
|
93
|
+
* terminalTool: { name: 'report', tool: reportTool },
|
|
94
|
+
* recursive: { name: 'web_research', extractTasks: (a) => a.questions as string[] },
|
|
95
|
+
* });
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @category Agents
|
|
99
|
+
*/
|
|
100
|
+
export declare function spawnAgents(opts: SpawnAgentsOpts): Operation<AgentPoolResult>;
|
|
101
|
+
//# sourceMappingURL=spawn-agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn-agents.d.ts","sourceRoot":"","sources":["../src/spawn-agents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAe,MAAM,SAAS,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAUjD;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC;CAC5D;AAID;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,mDAAmD;IACnD,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,8FAA8F;IAC9F,YAAY,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC;IAC5C,iEAAiE;IACjE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IACpC,gEAAgE;IAChE,YAAY,CAAC,EAAE;QACb,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,uEAAuE;IACvE,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,uDAAuD;IACvD,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,sCAAsC;IACtC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,iGAAiG;IACjG,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAyGD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAiB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,SAAS,CAAC,eAAe,CAAC,CAiD9E"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.spawnAgents = spawnAgents;
|
|
4
|
+
const Tool_1 = require("./Tool");
|
|
5
|
+
const context_1 = require("./context");
|
|
6
|
+
const trace_scope_1 = require("./trace-scope");
|
|
7
|
+
const toolkit_1 = require("./toolkit");
|
|
8
|
+
const shared_root_1 = require("./shared-root");
|
|
9
|
+
const agent_pool_1 = require("./agent-pool");
|
|
10
|
+
// ── Recursive tool ───────────────────────────────────────────
|
|
11
|
+
const DEFAULT_ARGS_SCHEMA = {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
tasks: {
|
|
15
|
+
type: 'array',
|
|
16
|
+
items: { type: 'string' },
|
|
17
|
+
description: 'Sub-tasks to delegate to parallel agents',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
required: ['tasks'],
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Internal tool that calls spawnAgents() recursively.
|
|
24
|
+
* Created by spawnAgents() when `recursive` is enabled.
|
|
25
|
+
*/
|
|
26
|
+
class DelegateTool extends Tool_1.Tool {
|
|
27
|
+
name;
|
|
28
|
+
description;
|
|
29
|
+
parameters;
|
|
30
|
+
_spawnOpts;
|
|
31
|
+
_extractTasks;
|
|
32
|
+
_toolkit = null;
|
|
33
|
+
constructor(name, description, argsSchema, extractTasks, spawnOpts) {
|
|
34
|
+
super();
|
|
35
|
+
this.name = name;
|
|
36
|
+
this.description = description;
|
|
37
|
+
this.parameters = argsSchema;
|
|
38
|
+
this._extractTasks = extractTasks;
|
|
39
|
+
this._spawnOpts = spawnOpts;
|
|
40
|
+
}
|
|
41
|
+
/** Wire the circular toolkit reference. Called after createToolkit(). */
|
|
42
|
+
setToolkit(toolkit) {
|
|
43
|
+
this._toolkit = toolkit;
|
|
44
|
+
}
|
|
45
|
+
*execute(args, context) {
|
|
46
|
+
let tasks;
|
|
47
|
+
try {
|
|
48
|
+
tasks = this._extractTasks(args);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return { error: 'Failed to extract tasks from arguments.' };
|
|
52
|
+
}
|
|
53
|
+
if (!Array.isArray(tasks) || tasks.length === 0) {
|
|
54
|
+
return { error: 'Tasks must be a non-empty array of strings.' };
|
|
55
|
+
}
|
|
56
|
+
if (!this._toolkit) {
|
|
57
|
+
throw new Error(`${this.name}: toolkit not wired. Internal error.`);
|
|
58
|
+
}
|
|
59
|
+
const opts = this._spawnOpts;
|
|
60
|
+
const toolkit = this._toolkit;
|
|
61
|
+
const tw = yield* context_1.Trace.expect();
|
|
62
|
+
const scope = (0, trace_scope_1.traceScope)(tw, null, `delegate:${this.name}`, { taskCount: tasks.length });
|
|
63
|
+
const pool = yield* (0, shared_root_1.withSharedRoot)({ systemPrompt: opts.systemPrompt, tools: toolkit.toolsJson, parent: context?.branch }, function* (root) {
|
|
64
|
+
return yield* (0, agent_pool_1.useAgentPool)({
|
|
65
|
+
tasks: tasks.map((t) => ({
|
|
66
|
+
systemPrompt: opts.systemPrompt,
|
|
67
|
+
content: t,
|
|
68
|
+
tools: toolkit.toolsJson,
|
|
69
|
+
parent: root,
|
|
70
|
+
})),
|
|
71
|
+
tools: toolkit.toolMap,
|
|
72
|
+
terminalTool: opts.terminalTool?.name,
|
|
73
|
+
pruneOnReport: opts.pruneOnReport ?? true,
|
|
74
|
+
maxTurns: opts.maxTurns,
|
|
75
|
+
trace: opts.trace,
|
|
76
|
+
pressure: opts.pressure,
|
|
77
|
+
reportPrompt: opts.reportPrompt,
|
|
78
|
+
policy: opts.policy,
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
const result = {
|
|
82
|
+
results: pool.agents.map((a) => a.findings).filter(Boolean),
|
|
83
|
+
nestedResults: pool.agents.flatMap((a) => a.nestedResults ?? []),
|
|
84
|
+
agentCount: pool.agents.length,
|
|
85
|
+
totalTokens: pool.totalTokens,
|
|
86
|
+
totalToolCalls: pool.totalToolCalls,
|
|
87
|
+
};
|
|
88
|
+
scope.close();
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// ── spawnAgents ──────────────────────────────────────────────
|
|
93
|
+
/**
|
|
94
|
+
* Spawn parallel agents with tools, optionally self-referential.
|
|
95
|
+
*
|
|
96
|
+
* Creates a shared root, forks one agent per task, runs the four-phase
|
|
97
|
+
* tick loop, and returns results. When `recursive` is enabled, a
|
|
98
|
+
* delegate tool is added to the toolkit that calls `spawnAgents()`
|
|
99
|
+
* again — enabling agents to delegate sub-tasks at arbitrary depth.
|
|
100
|
+
*
|
|
101
|
+
* This is the general-purpose orchestration primitive. The harness
|
|
102
|
+
* controls the prompt, tools, recursion shape, and policy. Sources
|
|
103
|
+
* just provide data access tools.
|
|
104
|
+
*
|
|
105
|
+
* @example Research harness
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const result = yield* spawnAgents({
|
|
108
|
+
* tools: source.tools,
|
|
109
|
+
* systemPrompt: RESEARCH_PROMPT,
|
|
110
|
+
* tasks: questions,
|
|
111
|
+
* terminalTool: { name: 'report', tool: reportTool },
|
|
112
|
+
* recursive: { name: 'web_research', extractTasks: (a) => a.questions as string[] },
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @category Agents
|
|
117
|
+
*/
|
|
118
|
+
function* spawnAgents(opts) {
|
|
119
|
+
// Build the recursive delegate tool if enabled
|
|
120
|
+
let delegateTool;
|
|
121
|
+
if (opts.recursive) {
|
|
122
|
+
const rc = typeof opts.recursive === 'object' ? opts.recursive : {};
|
|
123
|
+
const name = rc.name ?? 'delegate';
|
|
124
|
+
const description = rc.description ?? `Delegate sub-tasks to parallel agents. Each task gets its own agent.`;
|
|
125
|
+
const argsSchema = rc.argsSchema ?? DEFAULT_ARGS_SCHEMA;
|
|
126
|
+
const extractTasks = rc.extractTasks ?? ((args) => args.tasks);
|
|
127
|
+
delegateTool = new DelegateTool(name, description, argsSchema, extractTasks, opts);
|
|
128
|
+
}
|
|
129
|
+
// Compose toolkit: data tools + terminal tool + optional delegate tool
|
|
130
|
+
const allTools = [
|
|
131
|
+
...opts.tools,
|
|
132
|
+
...(opts.terminalTool ? [opts.terminalTool.tool] : []),
|
|
133
|
+
...(delegateTool ? [delegateTool] : []),
|
|
134
|
+
];
|
|
135
|
+
const toolkit = (0, toolkit_1.createToolkit)(allTools);
|
|
136
|
+
// Wire circular reference: delegate tool needs the toolkit that contains it
|
|
137
|
+
if (delegateTool) {
|
|
138
|
+
delegateTool.setToolkit(toolkit);
|
|
139
|
+
}
|
|
140
|
+
// Run the pool
|
|
141
|
+
return yield* (0, shared_root_1.withSharedRoot)({ systemPrompt: opts.systemPrompt, tools: toolkit.toolsJson, parent: opts.parent }, function* (root) {
|
|
142
|
+
return yield* (0, agent_pool_1.useAgentPool)({
|
|
143
|
+
tasks: opts.tasks.map((t) => ({
|
|
144
|
+
systemPrompt: opts.systemPrompt,
|
|
145
|
+
content: t,
|
|
146
|
+
tools: toolkit.toolsJson,
|
|
147
|
+
parent: root,
|
|
148
|
+
})),
|
|
149
|
+
tools: toolkit.toolMap,
|
|
150
|
+
terminalTool: opts.terminalTool?.name,
|
|
151
|
+
pruneOnReport: opts.pruneOnReport,
|
|
152
|
+
maxTurns: opts.maxTurns,
|
|
153
|
+
trace: opts.trace,
|
|
154
|
+
pressure: opts.pressure,
|
|
155
|
+
reportPrompt: opts.reportPrompt,
|
|
156
|
+
policy: opts.policy,
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=spawn-agents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn-agents.js","sourceRoot":"","sources":["../src/spawn-agents.ts"],"names":[],"mappings":";;AAoNA,kCAiDC;AAnQD,iCAA8B;AAI9B,uCAAkC;AAClC,+CAA2C;AAC3C,uCAA0C;AAE1C,+CAA+C;AAC/C,6CAA4C;AAyE5C,gEAAgE;AAEhE,MAAM,mBAAmB,GAAe;IACtC,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,KAAK,EAAE;YACL,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACzB,WAAW,EAAE,0CAA0C;SACxD;KACF;IACD,QAAQ,EAAE,CAAC,OAAO,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,MAAM,YAAa,SAAQ,WAA6B;IAC7C,IAAI,CAAS;IACb,WAAW,CAAS;IACpB,UAAU,CAAa;IAExB,UAAU,CAAkB;IAC5B,aAAa,CAA8C;IAC3D,QAAQ,GAAmB,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C,QAAQ,CAAC,CAAC;IAExC,4EAA4E;IAC5E,IAAI,YAAY,EAAE,CAAC;QACjB,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAED,eAAe;IACf,OAAO,KAAK,CAAC,CAAC,IAAA,4BAAc,EAC1B,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,EAClF,QAAQ,CAAC,EAAE,IAAI;QACb,OAAO,KAAK,CAAC,CAAC,IAAA,yBAAY,EAAC;YACzB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC5B,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,OAAO,EAAE,CAAC;gBACV,KAAK,EAAE,OAAO,CAAC,SAAS;gBACxB,MAAM,EAAE,IAAI;aACb,CAAC,CAAC;YACH,KAAK,EAAE,OAAO,CAAC,OAAO;YACtB,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI;YACrC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAC;IACL,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Branch } from '@lloyal-labs/sdk';
|
|
2
|
+
import type { AgentPolicy } from './AgentPolicy';
|
|
2
3
|
/**
|
|
3
4
|
* JSON Schema definition for tool parameter validation
|
|
4
5
|
*
|
|
@@ -50,6 +51,13 @@ export interface ToolSchema {
|
|
|
50
51
|
export interface ToolContext {
|
|
51
52
|
/** Stable agent identifier — branch handle at creation time */
|
|
52
53
|
agentId: number;
|
|
54
|
+
/**
|
|
55
|
+
* The calling agent's branch — use for recursive tools that spawn
|
|
56
|
+
* sub-agents via {@link withSharedRoot} with `parent` option.
|
|
57
|
+
* Sub-agents forking from this branch inherit the agent's full
|
|
58
|
+
* KV state (Continuous Context).
|
|
59
|
+
*/
|
|
60
|
+
branch?: Branch;
|
|
53
61
|
/** Progress callback for long-running operations */
|
|
54
62
|
onProgress?: (p: {
|
|
55
63
|
filled: number;
|
|
@@ -199,6 +207,24 @@ export interface AgentPoolOptions {
|
|
|
199
207
|
* findings are pruned — hard-cut agents keep their branches for
|
|
200
208
|
* reportPass extraction. @default false */
|
|
201
209
|
pruneOnReport?: boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Report prompt for scratchpad extraction of agents that were killed
|
|
212
|
+
* without findings. When provided, the pool extracts findings inline
|
|
213
|
+
* (idle processing) instead of requiring the harness to call reportPass.
|
|
214
|
+
*
|
|
215
|
+
* Format: `{ system: string; user: string }` — system prompt describes
|
|
216
|
+
* the extraction task, user prompt triggers the report.
|
|
217
|
+
*/
|
|
218
|
+
reportPrompt?: {
|
|
219
|
+
system: string;
|
|
220
|
+
user: string;
|
|
221
|
+
/** Min tokens generated before scratchpad extraction is attempted. @default 100 */
|
|
222
|
+
minTokens?: number;
|
|
223
|
+
/** Min tool calls before scratchpad extraction is attempted. @default 2 */
|
|
224
|
+
minToolCalls?: number;
|
|
225
|
+
};
|
|
226
|
+
/** Custom agent policy. @default DefaultAgentPolicy with default opts */
|
|
227
|
+
policy?: AgentPolicy;
|
|
202
228
|
}
|
|
203
229
|
/**
|
|
204
230
|
* Result for a single completed agent
|
|
@@ -224,6 +250,8 @@ export interface AgentResult {
|
|
|
224
250
|
samplingPpl: number;
|
|
225
251
|
/** Per-token trace data (present only when {@link AgentPoolOptions.trace} is true) */
|
|
226
252
|
trace?: TraceToken[];
|
|
253
|
+
/** Findings collected from recursive tool results (inner sub-agent findings) */
|
|
254
|
+
nestedResults: readonly string[];
|
|
227
255
|
}
|
|
228
256
|
/**
|
|
229
257
|
* Aggregate result from a completed agent pool run
|
|
@@ -298,6 +326,8 @@ export interface DivergeOptions {
|
|
|
298
326
|
parent?: Branch;
|
|
299
327
|
/** Sampling parameters for all attempts */
|
|
300
328
|
params?: SamplingParams;
|
|
329
|
+
/** Base seed for sampler diversity across attempts. @default 2000 */
|
|
330
|
+
seedBase?: number;
|
|
301
331
|
}
|
|
302
332
|
/**
|
|
303
333
|
* Single attempt result from {@link diverge}
|
|
@@ -366,6 +396,7 @@ export type AgentEvent = {
|
|
|
366
396
|
agentId: number;
|
|
367
397
|
tool: string;
|
|
368
398
|
result: string;
|
|
399
|
+
contextAvailablePercent?: number;
|
|
369
400
|
} | {
|
|
370
401
|
type: 'agent:tool_progress';
|
|
371
402
|
agentId: number;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAIjD;;;;;;;GAOG;AACH,MAAM,WAAW,UAAU;IACzB,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,2DAA2D;IAC3D,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,U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AC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACxE;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,uBAAuB,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9G;IAAE,IAAI,EAAE,qBAAqB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC7F;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACvC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lloyal-labs/lloyal-agents",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@lloyal-labs/sdk": "*",
|
|
35
|
-
"effection": "^4.0.2"
|
|
35
|
+
"effection": "^4.0.2",
|
|
36
|
+
"eta": "^4.5.1"
|
|
36
37
|
},
|
|
37
38
|
"files": [
|
|
38
39
|
"dist/"
|