@dexto/agent-management 1.5.8 → 1.6.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/AgentFactory.cjs +5 -9
- package/dist/AgentFactory.d.ts +6 -5
- package/dist/AgentFactory.d.ts.map +1 -1
- package/dist/AgentFactory.js +5 -9
- package/dist/AgentManager.cjs +2 -2
- package/dist/AgentManager.d.ts +1 -1
- package/dist/AgentManager.d.ts.map +1 -1
- package/dist/AgentManager.js +4 -4
- package/dist/agent-creation.cjs +95 -0
- package/dist/agent-creation.d.ts +15 -0
- package/dist/agent-creation.d.ts.map +1 -0
- package/dist/agent-creation.js +78 -0
- package/dist/config/config-enrichment.cjs +0 -11
- package/dist/config/config-enrichment.d.ts +1 -1
- package/dist/config/config-enrichment.d.ts.map +1 -1
- package/dist/config/config-enrichment.js +0 -11
- package/dist/config/config-manager.cjs +4 -4
- package/dist/config/config-manager.d.ts +1 -1
- package/dist/config/config-manager.d.ts.map +1 -1
- package/dist/config/config-manager.js +3 -1
- package/dist/config/loader.d.ts +3 -3
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/images/image-store.cjs +256 -0
- package/dist/images/image-store.d.ts +70 -0
- package/dist/images/image-store.d.ts.map +1 -0
- package/dist/images/image-store.js +210 -0
- package/dist/index.cjs +32 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -1
- package/dist/plugins/discover-plugins.cjs +15 -31
- package/dist/plugins/discover-plugins.d.ts.map +1 -1
- package/dist/plugins/discover-plugins.js +15 -31
- package/dist/plugins/index.cjs +0 -2
- package/dist/plugins/index.d.ts +5 -6
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +0 -2
- package/dist/plugins/list-plugins.cjs +3 -1
- package/dist/plugins/list-plugins.d.ts.map +1 -1
- package/dist/plugins/list-plugins.js +3 -1
- package/dist/plugins/load-plugin.cjs +0 -13
- package/dist/plugins/load-plugin.d.ts +3 -5
- package/dist/plugins/load-plugin.d.ts.map +1 -1
- package/dist/plugins/load-plugin.js +0 -13
- package/dist/plugins/schemas.cjs +1 -11
- package/dist/plugins/schemas.d.ts +14 -69
- package/dist/plugins/schemas.d.ts.map +1 -1
- package/dist/plugins/schemas.js +1 -10
- package/dist/plugins/types.d.ts +2 -20
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/plugins/validate-plugin.cjs +7 -37
- package/dist/plugins/validate-plugin.d.ts +6 -24
- package/dist/plugins/validate-plugin.d.ts.map +1 -1
- package/dist/plugins/validate-plugin.js +8 -38
- package/dist/registry/registry.d.ts +4 -44
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/runtime/AgentPool.d.ts +2 -2
- package/dist/runtime/AgentPool.d.ts.map +1 -1
- package/dist/runtime/AgentRuntime.cjs +20 -15
- package/dist/runtime/AgentRuntime.d.ts +2 -2
- package/dist/runtime/AgentRuntime.d.ts.map +1 -1
- package/dist/runtime/AgentRuntime.js +20 -15
- package/dist/runtime/approval-delegation.d.ts +2 -2
- package/dist/runtime/approval-delegation.d.ts.map +1 -1
- package/dist/runtime/schemas.d.ts +1 -1
- package/dist/runtime/types.d.ts +2 -1
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/{tool-provider → tool-factories/agent-spawner}/error-codes.d.ts +1 -1
- package/dist/tool-factories/agent-spawner/error-codes.d.ts.map +1 -0
- package/dist/{tool-provider → tool-factories/agent-spawner}/errors.d.ts +1 -1
- package/dist/tool-factories/agent-spawner/errors.d.ts.map +1 -0
- package/dist/tool-factories/agent-spawner/factory.cjs +290 -0
- package/dist/tool-factories/agent-spawner/factory.d.ts +4 -0
- package/dist/tool-factories/agent-spawner/factory.d.ts.map +1 -0
- package/dist/tool-factories/agent-spawner/factory.js +279 -0
- package/dist/{tool-provider → tool-factories/agent-spawner}/index.cjs +9 -9
- package/dist/{tool-provider → tool-factories/agent-spawner}/index.d.ts +3 -3
- package/dist/tool-factories/agent-spawner/index.d.ts.map +1 -0
- package/dist/{tool-provider → tool-factories/agent-spawner}/index.js +4 -4
- package/dist/tool-factories/agent-spawner/llm-resolution.d.ts.map +1 -0
- package/dist/{tool-provider/runtime-service.cjs → tool-factories/agent-spawner/runtime.cjs} +33 -71
- package/dist/{tool-provider/runtime-service.d.ts → tool-factories/agent-spawner/runtime.d.ts} +6 -6
- package/dist/tool-factories/agent-spawner/runtime.d.ts.map +1 -0
- package/dist/{tool-provider/runtime-service.js → tool-factories/agent-spawner/runtime.js} +29 -67
- package/dist/{tool-provider → tool-factories/agent-spawner}/schemas.cjs +2 -2
- package/dist/{tool-provider → tool-factories/agent-spawner}/schemas.d.ts +4 -4
- package/dist/tool-factories/agent-spawner/schemas.d.ts.map +1 -0
- package/dist/{tool-provider → tool-factories/agent-spawner}/schemas.js +2 -2
- package/dist/{tool-provider → tool-factories/agent-spawner}/spawn-agent-tool.cjs +8 -7
- package/dist/tool-factories/agent-spawner/spawn-agent-tool.d.ts +11 -0
- package/dist/tool-factories/agent-spawner/spawn-agent-tool.d.ts.map +1 -0
- package/dist/{tool-provider → tool-factories/agent-spawner}/spawn-agent-tool.js +8 -7
- package/dist/tool-factories/agent-spawner/types.d.ts.map +1 -0
- package/dist/writer.d.ts +2 -1
- package/dist/writer.d.ts.map +1 -1
- package/package.json +6 -4
- package/dist/tool-provider/error-codes.d.ts.map +0 -1
- package/dist/tool-provider/errors.d.ts.map +0 -1
- package/dist/tool-provider/index.d.ts.map +0 -1
- package/dist/tool-provider/llm-resolution.d.ts.map +0 -1
- package/dist/tool-provider/runtime-service.d.ts.map +0 -1
- package/dist/tool-provider/schemas.d.ts.map +0 -1
- package/dist/tool-provider/spawn-agent-tool.d.ts +0 -10
- package/dist/tool-provider/spawn-agent-tool.d.ts.map +0 -1
- package/dist/tool-provider/tool-provider.cjs +0 -197
- package/dist/tool-provider/tool-provider.d.ts +0 -30
- package/dist/tool-provider/tool-provider.d.ts.map +0 -1
- package/dist/tool-provider/tool-provider.js +0 -180
- package/dist/tool-provider/types.d.ts.map +0 -1
- /package/dist/{tool-provider → tool-factories/agent-spawner}/error-codes.cjs +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/error-codes.js +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/errors.cjs +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/errors.js +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/llm-resolution.cjs +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/llm-resolution.d.ts +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/llm-resolution.js +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/types.cjs +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/types.d.ts +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/types.js +0 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { ToolError } from "@dexto/core";
|
|
2
|
+
import {
|
|
3
|
+
ConditionEngine,
|
|
4
|
+
SignalBus,
|
|
5
|
+
TaskRegistry,
|
|
6
|
+
createCheckTaskTool,
|
|
7
|
+
createListTasksTool,
|
|
8
|
+
createWaitForTool,
|
|
9
|
+
WaitForInputSchema,
|
|
10
|
+
CheckTaskInputSchema,
|
|
11
|
+
ListTasksInputSchema
|
|
12
|
+
} from "@dexto/orchestration";
|
|
13
|
+
import {
|
|
14
|
+
AgentSpawnerConfigSchema,
|
|
15
|
+
SpawnAgentInputSchema
|
|
16
|
+
} from "./schemas.js";
|
|
17
|
+
import { AgentSpawnerRuntime } from "./runtime.js";
|
|
18
|
+
import { createSpawnAgentTool } from "./spawn-agent-tool.js";
|
|
19
|
+
function requireAgentContext(context) {
|
|
20
|
+
if (!context.agent) {
|
|
21
|
+
throw ToolError.configInvalid("agent-spawner tools require ToolExecutionContext.agent");
|
|
22
|
+
}
|
|
23
|
+
if (!context.services) {
|
|
24
|
+
throw ToolError.configInvalid("agent-spawner tools require ToolExecutionContext.services");
|
|
25
|
+
}
|
|
26
|
+
return { agent: context.agent, logger: context.logger, toolServices: context.services };
|
|
27
|
+
}
|
|
28
|
+
const agentSpawnerToolsFactory = {
|
|
29
|
+
configSchema: AgentSpawnerConfigSchema,
|
|
30
|
+
metadata: {
|
|
31
|
+
displayName: "Agent Spawner",
|
|
32
|
+
description: "Spawn sub-agents for task delegation",
|
|
33
|
+
category: "agents"
|
|
34
|
+
},
|
|
35
|
+
create: (config) => {
|
|
36
|
+
let state;
|
|
37
|
+
const attachTaskForker = (options) => {
|
|
38
|
+
const { toolServices, taskForker, logger } = options;
|
|
39
|
+
if (toolServices.taskForker !== taskForker) {
|
|
40
|
+
toolServices.taskForker = taskForker;
|
|
41
|
+
logger.debug(
|
|
42
|
+
"AgentSpawnerRuntime attached as taskForker for context:fork skill support"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const ensureToolsInitialized = (context) => {
|
|
47
|
+
const { agent, logger, toolServices } = requireAgentContext(context);
|
|
48
|
+
if (state && state.agent === agent && !state.abortController.signal.aborted) {
|
|
49
|
+
attachTaskForker({ toolServices, taskForker: state.runtime, logger });
|
|
50
|
+
return state.tools;
|
|
51
|
+
}
|
|
52
|
+
if (state && !state.abortController.signal.aborted) {
|
|
53
|
+
state.abortController.abort();
|
|
54
|
+
}
|
|
55
|
+
if (state) {
|
|
56
|
+
state.runtime.cleanup().catch(() => void 0);
|
|
57
|
+
}
|
|
58
|
+
state = void 0;
|
|
59
|
+
const signalBus = new SignalBus();
|
|
60
|
+
const taskRegistry = new TaskRegistry(signalBus);
|
|
61
|
+
const conditionEngine = new ConditionEngine(taskRegistry, signalBus, logger);
|
|
62
|
+
const spawnerRuntime = new AgentSpawnerRuntime(agent, config, logger);
|
|
63
|
+
attachTaskForker({ toolServices, taskForker: spawnerRuntime, logger });
|
|
64
|
+
const taskSessions = /* @__PURE__ */ new Map();
|
|
65
|
+
const emitTasksUpdate = (sessionId) => {
|
|
66
|
+
const tasks = taskRegistry.list({
|
|
67
|
+
status: ["running", "completed", "failed", "cancelled"]
|
|
68
|
+
});
|
|
69
|
+
const scopedTasks = sessionId ? tasks.filter((task) => taskSessions.get(task.taskId) === sessionId) : tasks;
|
|
70
|
+
const runningCount = scopedTasks.filter((task) => task.status === "running").length;
|
|
71
|
+
agent.emit("service:event", {
|
|
72
|
+
service: "orchestration",
|
|
73
|
+
event: "tasks-updated",
|
|
74
|
+
sessionId: sessionId ?? "",
|
|
75
|
+
data: {
|
|
76
|
+
runningCount,
|
|
77
|
+
tasks: scopedTasks.map((task) => ({
|
|
78
|
+
taskId: task.taskId,
|
|
79
|
+
status: task.status,
|
|
80
|
+
...task.description !== void 0 && {
|
|
81
|
+
description: task.description
|
|
82
|
+
}
|
|
83
|
+
}))
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
const triggerBackgroundCompletion = (taskId, sessionId) => {
|
|
88
|
+
if (!sessionId) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
agent.emit("tool:background-completed", {
|
|
92
|
+
toolCallId: taskId,
|
|
93
|
+
sessionId
|
|
94
|
+
});
|
|
95
|
+
const taskInfo = taskRegistry.getInfo(taskId);
|
|
96
|
+
const resultText = (() => {
|
|
97
|
+
if (taskInfo?.status === "failed") {
|
|
98
|
+
return taskInfo.error ?? "Unknown error.";
|
|
99
|
+
}
|
|
100
|
+
if (taskInfo?.result !== void 0) {
|
|
101
|
+
if (typeof taskInfo.result === "string") {
|
|
102
|
+
return taskInfo.result;
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
return JSON.stringify(taskInfo.result, null, 2);
|
|
106
|
+
} catch {
|
|
107
|
+
return String(taskInfo.result ?? "<unserializable result>");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return "No result available.";
|
|
111
|
+
})();
|
|
112
|
+
const sanitizeCdata = (value) => value.replace(/\]\]>/g, "]]]]><![CDATA[>");
|
|
113
|
+
const safeDescription = taskInfo?.description ? sanitizeCdata(taskInfo.description) : null;
|
|
114
|
+
const safeResultText = sanitizeCdata(resultText);
|
|
115
|
+
const descriptionTag = safeDescription ? ` <description><![CDATA[${safeDescription}]]></description>
|
|
116
|
+
` : "";
|
|
117
|
+
const statusTag = taskInfo?.status ? ` <status>${taskInfo.status}</status>
|
|
118
|
+
` : "";
|
|
119
|
+
const content = [
|
|
120
|
+
{
|
|
121
|
+
type: "text",
|
|
122
|
+
text: `<background-task-completion>
|
|
123
|
+
<origin>task</origin>
|
|
124
|
+
<note>The following response was reported by the background task (not user input).</note>
|
|
125
|
+
<taskId>${taskId}</taskId>
|
|
126
|
+
` + statusTag + descriptionTag + ` <result><![CDATA[${safeResultText}]]></result>
|
|
127
|
+
</background-task-completion>`
|
|
128
|
+
}
|
|
129
|
+
];
|
|
130
|
+
agent.isSessionBusy(sessionId).then((isBusy) => {
|
|
131
|
+
if (isBusy) {
|
|
132
|
+
agent.queueMessage(sessionId, {
|
|
133
|
+
content,
|
|
134
|
+
kind: "background"
|
|
135
|
+
}).catch(() => void 0);
|
|
136
|
+
} else {
|
|
137
|
+
agent.emit("run:invoke", {
|
|
138
|
+
sessionId,
|
|
139
|
+
content,
|
|
140
|
+
source: "external",
|
|
141
|
+
metadata: { taskId }
|
|
142
|
+
});
|
|
143
|
+
agent.generate(content, sessionId).catch(() => void 0);
|
|
144
|
+
}
|
|
145
|
+
}).catch(() => {
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
const handleBackground = (event) => {
|
|
149
|
+
const taskId = event.toolCallId;
|
|
150
|
+
if (taskRegistry.has(taskId)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (event.sessionId) {
|
|
154
|
+
taskSessions.set(taskId, event.sessionId);
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
taskRegistry.register(
|
|
158
|
+
{
|
|
159
|
+
type: "generic",
|
|
160
|
+
taskId,
|
|
161
|
+
description: event.description ?? `Tool ${event.toolName}`,
|
|
162
|
+
promise: event.promise
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
...event.timeoutMs !== void 0 && { timeout: event.timeoutMs },
|
|
166
|
+
...event.notifyOnComplete !== void 0 && {
|
|
167
|
+
notify: event.notifyOnComplete
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
taskSessions.delete(taskId);
|
|
173
|
+
event.promise.catch(() => void 0);
|
|
174
|
+
logger.warn(
|
|
175
|
+
`Failed to register background task ${taskId}: ${error instanceof Error ? error.message : String(error)}`,
|
|
176
|
+
{ color: "yellow" }
|
|
177
|
+
);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
emitTasksUpdate(event.sessionId);
|
|
181
|
+
event.promise.finally(() => {
|
|
182
|
+
taskSessions.delete(taskId);
|
|
183
|
+
emitTasksUpdate(event.sessionId);
|
|
184
|
+
triggerBackgroundCompletion(taskId, event.sessionId);
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
const abortController = new AbortController();
|
|
188
|
+
agent.on("tool:background", handleBackground, {
|
|
189
|
+
signal: abortController.signal
|
|
190
|
+
});
|
|
191
|
+
agent.on(
|
|
192
|
+
"agent:stopped",
|
|
193
|
+
() => {
|
|
194
|
+
spawnerRuntime.cleanup().catch(() => void 0);
|
|
195
|
+
abortController.abort();
|
|
196
|
+
},
|
|
197
|
+
{ signal: abortController.signal }
|
|
198
|
+
);
|
|
199
|
+
const spawnAgentTool = createSpawnAgentTool(spawnerRuntime);
|
|
200
|
+
const waitForTool = createWaitForTool(conditionEngine);
|
|
201
|
+
const checkTaskTool = createCheckTaskTool(taskRegistry);
|
|
202
|
+
const listTasksTool = createListTasksTool(taskRegistry);
|
|
203
|
+
const tools = {
|
|
204
|
+
spawnAgent: spawnAgentTool,
|
|
205
|
+
waitFor: waitForTool,
|
|
206
|
+
checkTask: checkTaskTool,
|
|
207
|
+
listTasks: listTasksTool
|
|
208
|
+
};
|
|
209
|
+
state = {
|
|
210
|
+
agent,
|
|
211
|
+
abortController,
|
|
212
|
+
runtime: spawnerRuntime,
|
|
213
|
+
tools
|
|
214
|
+
};
|
|
215
|
+
return tools;
|
|
216
|
+
};
|
|
217
|
+
return [
|
|
218
|
+
{
|
|
219
|
+
id: "spawn_agent",
|
|
220
|
+
displayName: "Agent",
|
|
221
|
+
description: "Spawn a sub-agent to handle a task and return its result.",
|
|
222
|
+
inputSchema: SpawnAgentInputSchema,
|
|
223
|
+
execute: (input, context) => ensureToolsInitialized(context).spawnAgent.execute(input, context),
|
|
224
|
+
generatePreview: async (input, context) => {
|
|
225
|
+
const tool = ensureToolsInitialized(context).spawnAgent;
|
|
226
|
+
if (!tool.generatePreview) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
return await tool.generatePreview(input, context);
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
id: "wait_for",
|
|
234
|
+
displayName: "Wait",
|
|
235
|
+
description: "Wait for background task(s) to complete.",
|
|
236
|
+
inputSchema: WaitForInputSchema,
|
|
237
|
+
execute: (input, context) => ensureToolsInitialized(context).waitFor.execute(input, context),
|
|
238
|
+
generatePreview: async (input, context) => {
|
|
239
|
+
const tool = ensureToolsInitialized(context).waitFor;
|
|
240
|
+
if (!tool.generatePreview) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
return await tool.generatePreview(input, context);
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
id: "check_task",
|
|
248
|
+
displayName: "Check Task",
|
|
249
|
+
description: "Check the status of a background task.",
|
|
250
|
+
inputSchema: CheckTaskInputSchema,
|
|
251
|
+
execute: (input, context) => ensureToolsInitialized(context).checkTask.execute(input, context),
|
|
252
|
+
generatePreview: async (input, context) => {
|
|
253
|
+
const tool = ensureToolsInitialized(context).checkTask;
|
|
254
|
+
if (!tool.generatePreview) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
return await tool.generatePreview(input, context);
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
id: "list_tasks",
|
|
262
|
+
displayName: "List Tasks",
|
|
263
|
+
description: "List background tasks and their statuses.",
|
|
264
|
+
inputSchema: ListTasksInputSchema,
|
|
265
|
+
execute: (input, context) => ensureToolsInitialized(context).listTasks.execute(input, context),
|
|
266
|
+
generatePreview: async (input, context) => {
|
|
267
|
+
const tool = ensureToolsInitialized(context).listTasks;
|
|
268
|
+
if (!tool.generatePreview) {
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
return await tool.generatePreview(input, context);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
];
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
export {
|
|
278
|
+
agentSpawnerToolsFactory
|
|
279
|
+
};
|
|
@@ -16,20 +16,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var agent_spawner_exports = {};
|
|
20
|
+
__export(agent_spawner_exports, {
|
|
21
21
|
AgentSpawnerConfigSchema: () => import_schemas.AgentSpawnerConfigSchema,
|
|
22
22
|
AgentSpawnerError: () => import_errors.AgentSpawnerError,
|
|
23
23
|
AgentSpawnerErrorCode: () => import_error_codes.AgentSpawnerErrorCode,
|
|
24
|
-
|
|
24
|
+
AgentSpawnerRuntime: () => import_runtime.AgentSpawnerRuntime,
|
|
25
25
|
SpawnAgentInputSchema: () => import_schemas2.SpawnAgentInputSchema,
|
|
26
|
-
|
|
26
|
+
agentSpawnerToolsFactory: () => import_factory.agentSpawnerToolsFactory,
|
|
27
27
|
createSpawnAgentTool: () => import_spawn_agent_tool.createSpawnAgentTool
|
|
28
28
|
});
|
|
29
|
-
module.exports = __toCommonJS(
|
|
30
|
-
var
|
|
29
|
+
module.exports = __toCommonJS(agent_spawner_exports);
|
|
30
|
+
var import_factory = require("./factory.js");
|
|
31
31
|
var import_schemas = require("./schemas.js");
|
|
32
|
-
var
|
|
32
|
+
var import_runtime = require("./runtime.js");
|
|
33
33
|
var import_spawn_agent_tool = require("./spawn-agent-tool.js");
|
|
34
34
|
var import_schemas2 = require("./schemas.js");
|
|
35
35
|
var import_errors = require("./errors.js");
|
|
@@ -39,8 +39,8 @@ var import_error_codes = require("./error-codes.js");
|
|
|
39
39
|
AgentSpawnerConfigSchema,
|
|
40
40
|
AgentSpawnerError,
|
|
41
41
|
AgentSpawnerErrorCode,
|
|
42
|
-
|
|
42
|
+
AgentSpawnerRuntime,
|
|
43
43
|
SpawnAgentInputSchema,
|
|
44
|
-
|
|
44
|
+
agentSpawnerToolsFactory,
|
|
45
45
|
createSpawnAgentTool
|
|
46
46
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Agent Spawner
|
|
2
|
+
* Agent Spawner Tools Factory
|
|
3
3
|
*
|
|
4
4
|
* Enables agents to spawn sub-agents for task delegation.
|
|
5
5
|
*/
|
|
6
|
-
export {
|
|
6
|
+
export { agentSpawnerToolsFactory } from './factory.js';
|
|
7
7
|
export { AgentSpawnerConfigSchema } from './schemas.js';
|
|
8
8
|
export type { AgentSpawnerConfig } from './schemas.js';
|
|
9
|
-
export {
|
|
9
|
+
export { AgentSpawnerRuntime } from './runtime.js';
|
|
10
10
|
export { createSpawnAgentTool } from './spawn-agent-tool.js';
|
|
11
11
|
export { SpawnAgentInputSchema } from './schemas.js';
|
|
12
12
|
export type { SpawnAgentInput } from './schemas.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tool-factories/agent-spawner/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAGxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAG7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGpD,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { agentSpawnerToolsFactory } from "./factory.js";
|
|
2
2
|
import { AgentSpawnerConfigSchema } from "./schemas.js";
|
|
3
|
-
import {
|
|
3
|
+
import { AgentSpawnerRuntime } from "./runtime.js";
|
|
4
4
|
import { createSpawnAgentTool } from "./spawn-agent-tool.js";
|
|
5
5
|
import { SpawnAgentInputSchema } from "./schemas.js";
|
|
6
6
|
import { AgentSpawnerError } from "./errors.js";
|
|
@@ -9,8 +9,8 @@ export {
|
|
|
9
9
|
AgentSpawnerConfigSchema,
|
|
10
10
|
AgentSpawnerError,
|
|
11
11
|
AgentSpawnerErrorCode,
|
|
12
|
-
|
|
12
|
+
AgentSpawnerRuntime,
|
|
13
13
|
SpawnAgentInputSchema,
|
|
14
|
-
|
|
14
|
+
agentSpawnerToolsFactory,
|
|
15
15
|
createSpawnAgentTool
|
|
16
16
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-resolution.d.ts","sourceRoot":"","sources":["../../../src/tool-factories/agent-spawner/llm-resolution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG7C;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAClC,4CAA4C;IAC5C,GAAG,EAAE,SAAS,CAAC;IACf,wCAAwC;IACxC,UAAU,EACJ,mBAAmB,GACnB,eAAe,GACf,iBAAiB,CAAC;IACxB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,yBAAyB;IACtC,gDAAgD;IAChD,WAAW,EAAE,SAAS,CAAC;IACvB,6EAA6E;IAC7E,SAAS,EAAE,SAAS,CAAC;IACrB,wCAAwC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,qBAAqB,CAmE5F"}
|
|
@@ -26,21 +26,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
|
|
29
|
+
var runtime_exports = {};
|
|
30
|
+
__export(runtime_exports, {
|
|
31
|
+
AgentSpawnerRuntime: () => AgentSpawnerRuntime
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
33
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
34
34
|
var import_core = require("@dexto/core");
|
|
35
|
-
var import_AgentRuntime = require("
|
|
36
|
-
var import_approval_delegation = require("
|
|
37
|
-
var import_loader = require("
|
|
38
|
-
var import_registry = require("
|
|
39
|
-
var import_types = require("
|
|
40
|
-
var import_path = require("
|
|
35
|
+
var import_AgentRuntime = require("../../runtime/AgentRuntime.js");
|
|
36
|
+
var import_approval_delegation = require("../../runtime/approval-delegation.js");
|
|
37
|
+
var import_loader = require("../../config/loader.js");
|
|
38
|
+
var import_registry = require("../../registry/registry.js");
|
|
39
|
+
var import_types = require("../../registry/types.js");
|
|
40
|
+
var import_path = require("../../utils/path.js");
|
|
41
41
|
var path = __toESM(require("path"), 1);
|
|
42
42
|
var import_llm_resolution = require("./llm-resolution.js");
|
|
43
|
-
class
|
|
43
|
+
class AgentSpawnerRuntime {
|
|
44
44
|
runtime;
|
|
45
45
|
parentId;
|
|
46
46
|
parentAgent;
|
|
@@ -90,7 +90,7 @@ class RuntimeService {
|
|
|
90
90
|
logger
|
|
91
91
|
});
|
|
92
92
|
this.logger.debug(
|
|
93
|
-
`
|
|
93
|
+
`AgentSpawnerRuntime initialized for parent '${this.parentId}' (maxAgents: ${config.maxConcurrentAgents})`
|
|
94
94
|
);
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
@@ -164,23 +164,7 @@ class RuntimeService {
|
|
|
164
164
|
* @param options.sessionId - Optional session ID for progress events
|
|
165
165
|
*/
|
|
166
166
|
async fork(options) {
|
|
167
|
-
|
|
168
|
-
task: options.task,
|
|
169
|
-
instructions: options.instructions
|
|
170
|
-
};
|
|
171
|
-
if (options.agentId) {
|
|
172
|
-
spawnOptions.agentId = options.agentId;
|
|
173
|
-
}
|
|
174
|
-
if (options.autoApprove !== void 0) {
|
|
175
|
-
spawnOptions.autoApprove = options.autoApprove;
|
|
176
|
-
}
|
|
177
|
-
if (options.toolCallId) {
|
|
178
|
-
spawnOptions.toolCallId = options.toolCallId;
|
|
179
|
-
}
|
|
180
|
-
if (options.sessionId) {
|
|
181
|
-
spawnOptions.sessionId = options.sessionId;
|
|
182
|
-
}
|
|
183
|
-
return this.spawnAndExecute(spawnOptions);
|
|
167
|
+
return this.spawnAndExecute(options);
|
|
184
168
|
}
|
|
185
169
|
/**
|
|
186
170
|
* Set up progress event emission for a sub-agent.
|
|
@@ -202,10 +186,8 @@ class RuntimeService {
|
|
|
202
186
|
let toolCount = 0;
|
|
203
187
|
const tokenUsage = { input: 0, output: 0, total: 0 };
|
|
204
188
|
let currentTool = "";
|
|
205
|
-
const subAgentBus = subAgentHandle.agent.agentEventBus;
|
|
206
|
-
const parentBus = this.parentAgent.agentEventBus;
|
|
207
189
|
const emitProgress = (tool, args) => {
|
|
208
|
-
|
|
190
|
+
this.parentAgent.emit("service:event", {
|
|
209
191
|
service: "agent-spawner",
|
|
210
192
|
event: "progress",
|
|
211
193
|
toolCallId,
|
|
@@ -223,15 +205,10 @@ class RuntimeService {
|
|
|
223
205
|
const toolCallHandler = (event) => {
|
|
224
206
|
toolCount++;
|
|
225
207
|
let displayToolName = event.toolName;
|
|
226
|
-
if (displayToolName.startsWith("
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
displayToolName =
|
|
230
|
-
} else if (displayToolName.startsWith("mcp--")) {
|
|
231
|
-
const parts = displayToolName.split("--");
|
|
232
|
-
if (parts.length >= 3) {
|
|
233
|
-
displayToolName = parts.slice(2).join("--");
|
|
234
|
-
}
|
|
208
|
+
if (displayToolName.startsWith("mcp--")) {
|
|
209
|
+
const trimmed = displayToolName.substring("mcp--".length);
|
|
210
|
+
const parts = trimmed.split("--");
|
|
211
|
+
displayToolName = parts.length >= 2 ? parts.slice(1).join("--") : trimmed;
|
|
235
212
|
}
|
|
236
213
|
currentTool = displayToolName;
|
|
237
214
|
this.logger.debug(
|
|
@@ -250,11 +227,11 @@ class RuntimeService {
|
|
|
250
227
|
emitProgress(currentTool || "processing");
|
|
251
228
|
}
|
|
252
229
|
};
|
|
253
|
-
|
|
254
|
-
|
|
230
|
+
subAgentHandle.agent.on("llm:tool-call", toolCallHandler);
|
|
231
|
+
subAgentHandle.agent.on("llm:response", responseHandler);
|
|
255
232
|
return () => {
|
|
256
|
-
|
|
257
|
-
|
|
233
|
+
subAgentHandle.agent.off("llm:tool-call", toolCallHandler);
|
|
234
|
+
subAgentHandle.agent.off("llm:response", responseHandler);
|
|
258
235
|
};
|
|
259
236
|
}
|
|
260
237
|
/**
|
|
@@ -467,12 +444,12 @@ class RuntimeService {
|
|
|
467
444
|
*/
|
|
468
445
|
async buildSubAgentConfig(options, sessionId) {
|
|
469
446
|
const { agentId, inheritLlm, autoApprove } = options;
|
|
470
|
-
const
|
|
447
|
+
const parentSettings = this.parentAgent.config;
|
|
471
448
|
const currentParentLLM = this.parentAgent.getCurrentLLMConfig(sessionId);
|
|
472
449
|
this.logger.debug(
|
|
473
|
-
`[
|
|
450
|
+
`[AgentSpawnerRuntime] Building sub-agent config with LLM: ${currentParentLLM.provider}/${currentParentLLM.model}` + (sessionId ? ` (sessionId: ${sessionId})` : " (no sessionId)")
|
|
474
451
|
);
|
|
475
|
-
const
|
|
452
|
+
const permissionsMode = autoApprove ? "auto-approve" : "manual";
|
|
476
453
|
if (agentId) {
|
|
477
454
|
let configPath = null;
|
|
478
455
|
try {
|
|
@@ -510,17 +487,13 @@ class RuntimeService {
|
|
|
510
487
|
this.logger.debug(`Sub-agent LLM resolution: ${resolution.reason}`);
|
|
511
488
|
llmConfig = resolution.llm;
|
|
512
489
|
}
|
|
513
|
-
const filteredCustomTools = loadedConfig.customTools ? loadedConfig.customTools.filter(
|
|
514
|
-
(tool) => typeof tool === "object" && tool !== null && "type" in tool && tool.type !== "agent-spawner"
|
|
515
|
-
) : void 0;
|
|
516
490
|
return {
|
|
517
491
|
...loadedConfig,
|
|
518
492
|
llm: llmConfig,
|
|
519
|
-
|
|
520
|
-
...loadedConfig.
|
|
521
|
-
mode:
|
|
493
|
+
permissions: {
|
|
494
|
+
...loadedConfig.permissions,
|
|
495
|
+
mode: permissionsMode
|
|
522
496
|
},
|
|
523
|
-
customTools: filteredCustomTools,
|
|
524
497
|
// Suppress sub-agent console logs entirely using silent transport
|
|
525
498
|
logger: {
|
|
526
499
|
level: "error",
|
|
@@ -536,22 +509,11 @@ class RuntimeService {
|
|
|
536
509
|
llm: { ...currentParentLLM },
|
|
537
510
|
// Default system prompt for sub-agents
|
|
538
511
|
systemPrompt: "You are a helpful sub-agent. Complete the task given to you efficiently and concisely.",
|
|
539
|
-
|
|
540
|
-
mode:
|
|
512
|
+
permissions: {
|
|
513
|
+
mode: permissionsMode
|
|
541
514
|
},
|
|
542
515
|
// Inherit MCP servers from parent so subagent has tool access
|
|
543
|
-
mcpServers:
|
|
544
|
-
// Inherit internal tools from parent, excluding tools that don't work in subagent context
|
|
545
|
-
// - ask_user: Subagents can't interact with the user directly
|
|
546
|
-
// - invoke_skill: Avoid nested skill invocations for simplicity
|
|
547
|
-
internalTools: parentConfig.internalTools ? parentConfig.internalTools.filter(
|
|
548
|
-
(tool) => tool !== "ask_user" && tool !== "invoke_skill"
|
|
549
|
-
) : [],
|
|
550
|
-
// Inherit custom tools from parent, excluding agent-spawner to prevent nested spawning (depth=1 limit)
|
|
551
|
-
// - agent-spawner: Sub-agents should not spawn their own sub-agents
|
|
552
|
-
customTools: parentConfig.customTools ? parentConfig.customTools.filter(
|
|
553
|
-
(tool) => typeof tool === "object" && tool !== null && "type" in tool && tool.type !== "agent-spawner"
|
|
554
|
-
) : [],
|
|
516
|
+
mcpServers: parentSettings.mcpServers ? { ...parentSettings.mcpServers } : {},
|
|
555
517
|
// Suppress sub-agent console logs entirely using silent transport
|
|
556
518
|
logger: {
|
|
557
519
|
level: "error",
|
|
@@ -592,11 +554,11 @@ class RuntimeService {
|
|
|
592
554
|
* Clean up all sub-agents (called when parent stops)
|
|
593
555
|
*/
|
|
594
556
|
async cleanup() {
|
|
595
|
-
this.logger.debug(`Cleaning up
|
|
557
|
+
this.logger.debug(`Cleaning up AgentSpawnerRuntime for parent '${this.parentId}'`);
|
|
596
558
|
await this.runtime.stopAll({ group: this.parentId });
|
|
597
559
|
}
|
|
598
560
|
}
|
|
599
561
|
// Annotate the CommonJS export names for ESM import in node:
|
|
600
562
|
0 && (module.exports = {
|
|
601
|
-
|
|
563
|
+
AgentSpawnerRuntime
|
|
602
564
|
});
|
package/dist/{tool-provider/runtime-service.d.ts → tool-factories/agent-spawner/runtime.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* AgentSpawnerRuntime - Bridge between tools and AgentRuntime
|
|
3
3
|
*
|
|
4
4
|
* Manages the relationship between a parent agent and its sub-agents,
|
|
5
5
|
* providing methods that tools can call to spawn and execute tasks.
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
* - Enforces per-parent agent limits
|
|
11
11
|
* - Always cleans up agents after task completion (synchronous model)
|
|
12
12
|
*/
|
|
13
|
-
import type { DextoAgent,
|
|
14
|
-
import type { AgentRegistryEntry } from '
|
|
13
|
+
import type { DextoAgent, Logger, TaskForker } from '@dexto/core';
|
|
14
|
+
import type { AgentRegistryEntry } from '../../registry/types.js';
|
|
15
15
|
import type { AgentSpawnerConfig } from './schemas.js';
|
|
16
16
|
import type { SpawnAgentOutput } from './types.js';
|
|
17
|
-
export declare class
|
|
17
|
+
export declare class AgentSpawnerRuntime implements TaskForker {
|
|
18
18
|
private runtime;
|
|
19
19
|
private parentId;
|
|
20
20
|
private parentAgent;
|
|
@@ -22,7 +22,7 @@ export declare class RuntimeService implements TaskForker {
|
|
|
22
22
|
private logger;
|
|
23
23
|
private resolveBundledAgentConfig;
|
|
24
24
|
private createFallbackRegistryEntry;
|
|
25
|
-
constructor(parentAgent: DextoAgent, config: AgentSpawnerConfig, logger:
|
|
25
|
+
constructor(parentAgent: DextoAgent, config: AgentSpawnerConfig, logger: Logger);
|
|
26
26
|
/**
|
|
27
27
|
* Get count of sub-agents belonging to this parent
|
|
28
28
|
*/
|
|
@@ -112,4 +112,4 @@ export declare class RuntimeService implements TaskForker {
|
|
|
112
112
|
*/
|
|
113
113
|
cleanup(): Promise<void>;
|
|
114
114
|
}
|
|
115
|
-
//# sourceMappingURL=runtime
|
|
115
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/tool-factories/agent-spawner/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMlE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAIlE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnD,qBAAa,mBAAoB,YAAW,UAAU;IAClD,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO,CAAC,yBAAyB;IAyBjC,OAAO,CAAC,2BAA2B;gBAYvB,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM;IAuB/E;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAIxB;;OAEG;IACH,OAAO,CAAC,QAAQ;IAIhB;;;;;;;;;;;;;;OAcG;IACG,eAAe,CAAC,KAAK,EAAE;QACzB,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA8C7B;;;;;;;;;;OAUG;IACG,IAAI,CAAC,OAAO,EAAE;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAIpE;;;;;OAKG;IACH,OAAO,CAAC,qBAAqB;IAwG7B;;OAEG;IACH,OAAO,CAAC,UAAU;IAsBlB;;OAEG;YACW,oBAAoB;IAyPlC;;;;;;;OAOG;YACW,mBAAmB;IAmHjC;;;OAGG;IACH,kBAAkB,IAAI,kBAAkB,EAAE;IA6B1C;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAIjC"}
|