@lloyal-labs/lloyal-agents 1.5.6 → 1.7.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 +34 -1
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +65 -1
- package/dist/Agent.js.map +1 -1
- package/dist/AgentPolicy.d.ts +51 -8
- package/dist/AgentPolicy.d.ts.map +1 -1
- package/dist/AgentPolicy.js +105 -63
- package/dist/AgentPolicy.js.map +1 -1
- package/dist/Tool.d.ts +5 -7
- package/dist/Tool.d.ts.map +1 -1
- package/dist/Tool.js +5 -7
- package/dist/Tool.js.map +1 -1
- package/dist/agent-pool.d.ts +9 -3
- package/dist/agent-pool.d.ts.map +1 -1
- package/dist/agent-pool.js +446 -407
- 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/create-agent-pool.d.ts +78 -0
- package/dist/create-agent-pool.d.ts.map +1 -0
- package/dist/create-agent-pool.js +60 -0
- package/dist/create-agent-pool.js.map +1 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.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 +4 -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 +9 -0
- 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 +131 -0
- package/dist/use-agent.js.map +1 -0
- package/package.json +2 -2
- 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
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
|
-
//# sourceMappingURL=spawn-agents.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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;AAE3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,KAA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AM,CAAC;IACvB;;gFAE4E;IAC5E,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AA8MD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAiB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,SAAS,CAAC,eAAe,CAAC,CAgD9E"}
|
package/dist/spawn-agents.js
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.spawnAgents = spawnAgents;
|
|
4
|
-
const effection_1 = require("effection");
|
|
5
|
-
const Tool_1 = require("./Tool");
|
|
6
|
-
const context_1 = require("./context");
|
|
7
|
-
const trace_scope_1 = require("./trace-scope");
|
|
8
|
-
const toolkit_1 = require("./toolkit");
|
|
9
|
-
const shared_root_1 = require("./shared-root");
|
|
10
|
-
const agent_pool_1 = require("./agent-pool");
|
|
11
|
-
// ── Recursive tool ───────────────────────────────────────────
|
|
12
|
-
const DEFAULT_ARGS_SCHEMA = {
|
|
13
|
-
type: 'object',
|
|
14
|
-
properties: {
|
|
15
|
-
tasks: {
|
|
16
|
-
type: 'array',
|
|
17
|
-
items: { type: 'string' },
|
|
18
|
-
description: 'Sub-tasks to delegate to parallel agents',
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
required: ['tasks'],
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Internal tool that calls spawnAgents() recursively.
|
|
25
|
-
* Created by spawnAgents() when `recursive` is enabled.
|
|
26
|
-
*/
|
|
27
|
-
class DelegateTool extends Tool_1.Tool {
|
|
28
|
-
name;
|
|
29
|
-
description;
|
|
30
|
-
parameters;
|
|
31
|
-
_spawnOpts;
|
|
32
|
-
_extractTasks;
|
|
33
|
-
_toolkit = null;
|
|
34
|
-
constructor(name, description, argsSchema, extractTasks, spawnOpts) {
|
|
35
|
-
super();
|
|
36
|
-
this.name = name;
|
|
37
|
-
this.description = description;
|
|
38
|
-
this.parameters = argsSchema;
|
|
39
|
-
this._extractTasks = extractTasks;
|
|
40
|
-
this._spawnOpts = spawnOpts;
|
|
41
|
-
}
|
|
42
|
-
/** Wire the circular toolkit reference. Called after createToolkit(). */
|
|
43
|
-
setToolkit(toolkit) {
|
|
44
|
-
this._toolkit = toolkit;
|
|
45
|
-
}
|
|
46
|
-
*execute(args, context) {
|
|
47
|
-
let tasks;
|
|
48
|
-
try {
|
|
49
|
-
tasks = this._extractTasks(args);
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
return { error: 'Failed to extract tasks from arguments.' };
|
|
53
|
-
}
|
|
54
|
-
if (!Array.isArray(tasks) || tasks.length === 0) {
|
|
55
|
-
return { error: 'Tasks must be a non-empty array of strings.' };
|
|
56
|
-
}
|
|
57
|
-
if (!this._toolkit) {
|
|
58
|
-
throw new Error(`${this.name}: toolkit not wired. Internal error.`);
|
|
59
|
-
}
|
|
60
|
-
const tw = yield* context_1.Trace.expect();
|
|
61
|
-
// Entailment gate: filter drifted/echoed tasks before spawning
|
|
62
|
-
const scorer = context?.scorer;
|
|
63
|
-
let filtered;
|
|
64
|
-
if (scorer) {
|
|
65
|
-
const allTasks = [...tasks];
|
|
66
|
-
const scores = yield* (0, effection_1.call)(() => scorer.scoreEntailmentBatch(tasks));
|
|
67
|
-
const surviving = [];
|
|
68
|
-
const rejected = [];
|
|
69
|
-
for (let i = 0; i < tasks.length; i++) {
|
|
70
|
-
if (scorer.shouldProceed(scores[i])) {
|
|
71
|
-
surviving.push(tasks[i]);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
rejected.push({ task: tasks[i], score: scores[i] });
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (rejected.length > 0)
|
|
78
|
-
filtered = rejected;
|
|
79
|
-
// Read calling agent for diagnostic — same read the echo guard will do
|
|
80
|
-
let _diagAgent;
|
|
81
|
-
try {
|
|
82
|
-
_diagAgent = yield* context_1.CallingAgent.get();
|
|
83
|
-
}
|
|
84
|
-
catch { /* top-level */ }
|
|
85
|
-
tw.write({
|
|
86
|
-
traceId: tw.nextId(), parentTraceId: null, ts: performance.now(),
|
|
87
|
-
type: 'entailment:delegate',
|
|
88
|
-
tool: this.name,
|
|
89
|
-
callingAgentId: _diagAgent?.id,
|
|
90
|
-
callingAgentTaskLength: _diagAgent?.task?.length,
|
|
91
|
-
callingAgentTask: _diagAgent?.task?.slice(0, 200),
|
|
92
|
-
tasks: allTasks.map((text, i) => ({
|
|
93
|
-
text: text.slice(0, 200),
|
|
94
|
-
score: scores[i],
|
|
95
|
-
kept: scorer.shouldProceed(scores[i]),
|
|
96
|
-
})),
|
|
97
|
-
});
|
|
98
|
-
if (surviving.length === 0) {
|
|
99
|
-
return { filtered, error: 'All proposed tasks drifted from the original query.' };
|
|
100
|
-
}
|
|
101
|
-
tasks = surviving;
|
|
102
|
-
// Echo guard: reject if all surviving questions are paraphrases of the agent's task
|
|
103
|
-
const echoThreshold = this._spawnOpts.echoThreshold ?? 0.8;
|
|
104
|
-
let callingAgent;
|
|
105
|
-
try {
|
|
106
|
-
callingAgent = yield* context_1.CallingAgent.get();
|
|
107
|
-
}
|
|
108
|
-
catch { /* top-level */ }
|
|
109
|
-
if (callingAgent?.task) {
|
|
110
|
-
const echoScores = yield* (0, effection_1.call)(() => scorer.scoreSimilarityBatch(callingAgent.task, tasks));
|
|
111
|
-
const minEchoScore = Math.min(...echoScores);
|
|
112
|
-
const echoRejected = minEchoScore > echoThreshold;
|
|
113
|
-
tw.write({
|
|
114
|
-
traceId: tw.nextId(), parentTraceId: null, ts: performance.now(),
|
|
115
|
-
type: 'entailment:delegate:echo',
|
|
116
|
-
tool: this.name,
|
|
117
|
-
agentTask: callingAgent.task.slice(0, 200),
|
|
118
|
-
tasks: tasks.map((text, i) => ({ text: text.slice(0, 200), echoScore: echoScores[i] })),
|
|
119
|
-
threshold: echoThreshold,
|
|
120
|
-
rejected: echoRejected,
|
|
121
|
-
});
|
|
122
|
-
if (echoRejected) {
|
|
123
|
-
return {
|
|
124
|
-
filtered,
|
|
125
|
-
echoRejected: true,
|
|
126
|
-
error: 'Your sub-questions are too similar to your own task. You have already searched and read content on this topic. Call report() with what you found, including what you checked but could not find.',
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
// Optional: check ancestor tasks
|
|
130
|
-
if (this._spawnOpts.checkAncestorEcho) {
|
|
131
|
-
const ancestorTasks = callingAgent.walkAncestors(a => a.task ? [a.task] : [])
|
|
132
|
-
.filter(t => t !== callingAgent.task);
|
|
133
|
-
for (const ancestorTask of ancestorTasks) {
|
|
134
|
-
const ancestorScores = yield* (0, effection_1.call)(() => scorer.scoreSimilarityBatch(ancestorTask, tasks));
|
|
135
|
-
if (Math.min(...ancestorScores) > echoThreshold) {
|
|
136
|
-
tw.write({
|
|
137
|
-
traceId: tw.nextId(), parentTraceId: null, ts: performance.now(),
|
|
138
|
-
type: 'entailment:delegate:echo',
|
|
139
|
-
tool: this.name,
|
|
140
|
-
agentTask: ancestorTask.slice(0, 200),
|
|
141
|
-
tasks: tasks.map((text, i) => ({ text: text.slice(0, 200), echoScore: ancestorScores[i] })),
|
|
142
|
-
threshold: echoThreshold,
|
|
143
|
-
rejected: true,
|
|
144
|
-
});
|
|
145
|
-
return {
|
|
146
|
-
filtered,
|
|
147
|
-
echoRejected: true,
|
|
148
|
-
error: 'Your sub-questions echo an ancestor task. Report what you found instead of re-delegating.',
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
const opts = this._spawnOpts;
|
|
156
|
-
const toolkit = this._toolkit;
|
|
157
|
-
const scope = (0, trace_scope_1.traceScope)(tw, null, `delegate:${this.name}`, { taskCount: tasks.length, filtered: filtered?.length ?? 0 });
|
|
158
|
-
// Scorer propagation: same immutable scorer reaches all descendant pools
|
|
159
|
-
const pool = yield* (0, shared_root_1.withSharedRoot)({ systemPrompt: opts.systemPrompt, tools: toolkit.toolsJson, parent: context?.branch }, function* (root) {
|
|
160
|
-
return yield* (0, agent_pool_1.useAgentPool)({
|
|
161
|
-
tasks: tasks.map((t) => ({
|
|
162
|
-
systemPrompt: opts.systemPrompt,
|
|
163
|
-
content: t,
|
|
164
|
-
tools: toolkit.toolsJson,
|
|
165
|
-
parent: root,
|
|
166
|
-
})),
|
|
167
|
-
tools: toolkit.toolMap,
|
|
168
|
-
terminalTool: opts.terminalTool?.name,
|
|
169
|
-
pruneOnReport: opts.pruneOnReport ?? true,
|
|
170
|
-
maxTurns: opts.maxTurns,
|
|
171
|
-
trace: opts.trace,
|
|
172
|
-
policy: opts.policy,
|
|
173
|
-
scorer: context?.scorer,
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
const result = {
|
|
177
|
-
results: pool.agents.map((a) => a.result).filter(Boolean),
|
|
178
|
-
nestedResults: pool.agents.flatMap((a) => a.nestedResults ?? []),
|
|
179
|
-
agentCount: pool.agents.length,
|
|
180
|
-
totalTokens: pool.totalTokens,
|
|
181
|
-
totalToolCalls: pool.totalToolCalls,
|
|
182
|
-
...(filtered ? { filtered } : {}),
|
|
183
|
-
};
|
|
184
|
-
scope.close();
|
|
185
|
-
return result;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
// ── spawnAgents ──────────────────────────────────────────────
|
|
189
|
-
/**
|
|
190
|
-
* Spawn parallel agents with tools, optionally self-referential.
|
|
191
|
-
*
|
|
192
|
-
* Creates a shared root, forks one agent per task, runs the four-phase
|
|
193
|
-
* tick loop, and returns results. When `recursive` is enabled, a
|
|
194
|
-
* delegate tool is added to the toolkit that calls `spawnAgents()`
|
|
195
|
-
* again — enabling agents to delegate sub-tasks at arbitrary depth.
|
|
196
|
-
*
|
|
197
|
-
* This is the general-purpose orchestration primitive. The harness
|
|
198
|
-
* controls the prompt, tools, recursion shape, and policy. Sources
|
|
199
|
-
* just provide data access tools.
|
|
200
|
-
*
|
|
201
|
-
* @example Research harness
|
|
202
|
-
* ```typescript
|
|
203
|
-
* const result = yield* spawnAgents({
|
|
204
|
-
* tools: source.tools,
|
|
205
|
-
* systemPrompt: RESEARCH_PROMPT,
|
|
206
|
-
* tasks: questions,
|
|
207
|
-
* terminalTool: { name: 'report', tool: reportTool },
|
|
208
|
-
* recursive: { name: 'web_research', extractTasks: (a) => a.questions as string[] },
|
|
209
|
-
* });
|
|
210
|
-
* ```
|
|
211
|
-
*
|
|
212
|
-
* @category Agents
|
|
213
|
-
*/
|
|
214
|
-
function* spawnAgents(opts) {
|
|
215
|
-
// Build the recursive delegate tool if enabled
|
|
216
|
-
let delegateTool;
|
|
217
|
-
if (opts.recursive) {
|
|
218
|
-
const rc = typeof opts.recursive === 'object' ? opts.recursive : {};
|
|
219
|
-
const name = rc.name ?? 'delegate';
|
|
220
|
-
const description = rc.description ?? `Delegate sub-tasks to parallel agents. Each task gets its own agent.`;
|
|
221
|
-
const argsSchema = rc.argsSchema ?? DEFAULT_ARGS_SCHEMA;
|
|
222
|
-
const extractTasks = rc.extractTasks ?? ((args) => args.tasks);
|
|
223
|
-
delegateTool = new DelegateTool(name, description, argsSchema, extractTasks, opts);
|
|
224
|
-
}
|
|
225
|
-
// Compose toolkit: data tools + terminal tool + optional delegate tool
|
|
226
|
-
const allTools = [
|
|
227
|
-
...opts.tools,
|
|
228
|
-
...(opts.terminalTool ? [opts.terminalTool.tool] : []),
|
|
229
|
-
...(delegateTool ? [delegateTool] : []),
|
|
230
|
-
];
|
|
231
|
-
const toolkit = (0, toolkit_1.createToolkit)(allTools);
|
|
232
|
-
// Wire circular reference: delegate tool needs the toolkit that contains it
|
|
233
|
-
if (delegateTool) {
|
|
234
|
-
delegateTool.setToolkit(toolkit);
|
|
235
|
-
}
|
|
236
|
-
// Run the pool
|
|
237
|
-
return yield* (0, shared_root_1.withSharedRoot)({ systemPrompt: opts.systemPrompt, tools: toolkit.toolsJson, parent: opts.parent }, function* (root) {
|
|
238
|
-
return yield* (0, agent_pool_1.useAgentPool)({
|
|
239
|
-
tasks: opts.tasks.map((t) => ({
|
|
240
|
-
systemPrompt: opts.systemPrompt,
|
|
241
|
-
content: t,
|
|
242
|
-
tools: toolkit.toolsJson,
|
|
243
|
-
parent: root,
|
|
244
|
-
})),
|
|
245
|
-
tools: toolkit.toolMap,
|
|
246
|
-
terminalTool: opts.terminalTool?.name,
|
|
247
|
-
pruneOnReport: opts.pruneOnReport,
|
|
248
|
-
maxTurns: opts.maxTurns,
|
|
249
|
-
trace: opts.trace,
|
|
250
|
-
policy: opts.policy,
|
|
251
|
-
scorer: opts.scorer,
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
//# sourceMappingURL=spawn-agents.js.map
|
package/dist/spawn-agents.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spawn-agents.js","sourceRoot":"","sources":["../src/spawn-agents.ts"],"names":[],"mappings":";;AA8TA,kCAgDC;AA7WD,yCAAiC;AAEjC,iCAA8B;AAM9B,uCAAgD;AAChD,+CAA2C;AAC3C,uCAA0C;AAE1C,+CAA+C;AAC/C,6CAA4C;AA2E5C,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,IAAI,CAAC;IAExC,YACE,IAAY,EACZ,WAAmB,EACnB,UAAsB,EACtB,YAAyD,EACzD,SAA0B;QAE1B,KAAK,EAAE,CAAC;QACR,IAAI,CAA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