@dexto/agent-management 1.5.2 → 1.5.3
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/index.cjs +6 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/runtime/AgentPool.cjs +181 -0
- package/dist/runtime/AgentPool.d.ts +76 -0
- package/dist/runtime/AgentPool.d.ts.map +1 -0
- package/dist/runtime/AgentPool.js +160 -0
- package/dist/runtime/AgentRuntime.cjs +225 -0
- package/dist/runtime/AgentRuntime.d.ts +77 -0
- package/dist/runtime/AgentRuntime.d.ts.map +1 -0
- package/dist/runtime/AgentRuntime.js +201 -0
- package/dist/runtime/approval-delegation.cjs +97 -0
- package/dist/runtime/approval-delegation.d.ts +30 -0
- package/dist/runtime/approval-delegation.d.ts.map +1 -0
- package/dist/runtime/approval-delegation.js +73 -0
- package/dist/runtime/error-codes.cjs +40 -0
- package/dist/runtime/error-codes.d.ts +17 -0
- package/dist/runtime/error-codes.d.ts.map +1 -0
- package/dist/runtime/error-codes.js +16 -0
- package/dist/runtime/errors.cjs +135 -0
- package/dist/runtime/errors.d.ts +40 -0
- package/dist/runtime/errors.d.ts.map +1 -0
- package/dist/runtime/errors.js +111 -0
- package/dist/runtime/index.cjs +53 -0
- package/dist/runtime/index.d.ts +19 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +26 -0
- package/dist/runtime/schemas.cjs +64 -0
- package/dist/runtime/schemas.d.ts +69 -0
- package/dist/runtime/schemas.d.ts.map +1 -0
- package/dist/runtime/schemas.js +35 -0
- package/dist/runtime/types.cjs +16 -0
- package/dist/runtime/types.d.ts +94 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +0 -0
- package/dist/tool-provider/error-codes.cjs +35 -0
- package/dist/tool-provider/error-codes.d.ts +11 -0
- package/dist/tool-provider/error-codes.d.ts.map +1 -0
- package/dist/tool-provider/error-codes.js +11 -0
- package/dist/tool-provider/errors.cjs +81 -0
- package/dist/tool-provider/errors.d.ts +19 -0
- package/dist/tool-provider/errors.d.ts.map +1 -0
- package/dist/tool-provider/errors.js +57 -0
- package/dist/tool-provider/index.cjs +46 -0
- package/dist/tool-provider/index.d.ts +16 -0
- package/dist/tool-provider/index.d.ts.map +1 -0
- package/dist/tool-provider/index.js +16 -0
- package/dist/tool-provider/runtime-service.cjs +370 -0
- package/dist/tool-provider/runtime-service.d.ts +83 -0
- package/dist/tool-provider/runtime-service.d.ts.map +1 -0
- package/dist/tool-provider/runtime-service.js +346 -0
- package/dist/tool-provider/schemas.cjs +73 -0
- package/dist/tool-provider/schemas.d.ts +83 -0
- package/dist/tool-provider/schemas.d.ts.map +1 -0
- package/dist/tool-provider/schemas.js +48 -0
- package/dist/tool-provider/spawn-agent-tool.cjs +89 -0
- package/dist/tool-provider/spawn-agent-tool.d.ts +10 -0
- package/dist/tool-provider/spawn-agent-tool.d.ts.map +1 -0
- package/dist/tool-provider/spawn-agent-tool.js +65 -0
- package/dist/tool-provider/tool-provider.cjs +44 -0
- package/dist/tool-provider/tool-provider.d.ts +24 -0
- package/dist/tool-provider/tool-provider.d.ts.map +1 -0
- package/dist/tool-provider/tool-provider.js +20 -0
- package/dist/tool-provider/types.cjs +16 -0
- package/dist/tool-provider/types.d.ts +17 -0
- package/dist/tool-provider/types.d.ts.map +1 -0
- package/dist/tool-provider/types.js +0 -0
- package/package.json +2 -2
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var runtime_service_exports = {};
|
|
20
|
+
__export(runtime_service_exports, {
|
|
21
|
+
RuntimeService: () => RuntimeService
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(runtime_service_exports);
|
|
24
|
+
var import_AgentRuntime = require("../runtime/AgentRuntime.js");
|
|
25
|
+
var import_approval_delegation = require("../runtime/approval-delegation.js");
|
|
26
|
+
var import_loader = require("../config/loader.js");
|
|
27
|
+
var import_registry = require("../registry/registry.js");
|
|
28
|
+
class RuntimeService {
|
|
29
|
+
runtime;
|
|
30
|
+
parentId;
|
|
31
|
+
parentAgent;
|
|
32
|
+
config;
|
|
33
|
+
logger;
|
|
34
|
+
constructor(parentAgent, config, logger) {
|
|
35
|
+
this.parentAgent = parentAgent;
|
|
36
|
+
this.config = config;
|
|
37
|
+
this.logger = logger;
|
|
38
|
+
this.parentId = parentAgent.config.agentId ?? `parent-${Date.now()}`;
|
|
39
|
+
this.runtime = new import_AgentRuntime.AgentRuntime({
|
|
40
|
+
config: {
|
|
41
|
+
maxAgents: config.maxConcurrentAgents,
|
|
42
|
+
defaultTaskTimeout: config.defaultTimeout
|
|
43
|
+
},
|
|
44
|
+
logger
|
|
45
|
+
});
|
|
46
|
+
this.logger.debug(
|
|
47
|
+
`RuntimeService initialized for parent '${this.parentId}' (maxAgents: ${config.maxConcurrentAgents})`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get count of sub-agents belonging to this parent
|
|
52
|
+
*/
|
|
53
|
+
getSubAgentCount() {
|
|
54
|
+
return this.runtime.listAgents({ group: this.parentId }).length;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Check if this parent can spawn another sub-agent
|
|
58
|
+
*/
|
|
59
|
+
canSpawn() {
|
|
60
|
+
return this.getSubAgentCount() < this.config.maxConcurrentAgents;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Spawn a sub-agent and execute a task
|
|
64
|
+
*
|
|
65
|
+
* This is the main method for the spawn_agent tool.
|
|
66
|
+
* It creates a sub-agent, executes the task, and cleans up after completion.
|
|
67
|
+
* If the sub-agent's LLM config fails, automatically falls back to parent's LLM.
|
|
68
|
+
*
|
|
69
|
+
* @param input.task - Short task description (for logging/UI)
|
|
70
|
+
* @param input.instructions - Full prompt sent to sub-agent
|
|
71
|
+
* @param input.agentId - Optional agent ID from registry
|
|
72
|
+
* @param input.timeout - Optional task timeout in milliseconds
|
|
73
|
+
* @param input.toolCallId - Optional tool call ID for progress events
|
|
74
|
+
* @param input.sessionId - Optional session ID for progress events
|
|
75
|
+
*/
|
|
76
|
+
async spawnAndExecute(input) {
|
|
77
|
+
if (!this.config.allowSpawning) {
|
|
78
|
+
return {
|
|
79
|
+
success: false,
|
|
80
|
+
error: "Agent spawning is disabled in configuration"
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (!this.canSpawn()) {
|
|
84
|
+
return {
|
|
85
|
+
success: false,
|
|
86
|
+
error: `Maximum sub-agents limit (${this.config.maxConcurrentAgents}) reached for this parent`
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (input.agentId && this.config.allowedAgents) {
|
|
90
|
+
if (!this.config.allowedAgents.includes(input.agentId)) {
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
error: `Agent '${input.agentId}' is not in the allowed agents list. Allowed: ${this.config.allowedAgents.join(", ")}`
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const timeout = input.timeout ?? this.config.defaultTimeout;
|
|
98
|
+
let autoApprove = false;
|
|
99
|
+
if (input.agentId && this.config.autoApproveAgents) {
|
|
100
|
+
autoApprove = this.config.autoApproveAgents.includes(input.agentId);
|
|
101
|
+
}
|
|
102
|
+
const result = await this.trySpawnWithFallback(
|
|
103
|
+
input,
|
|
104
|
+
timeout,
|
|
105
|
+
autoApprove,
|
|
106
|
+
input.toolCallId,
|
|
107
|
+
input.sessionId
|
|
108
|
+
);
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Set up progress event emission for a sub-agent.
|
|
113
|
+
* Subscribes to llm:tool-call events and emits service:event with progress data.
|
|
114
|
+
*
|
|
115
|
+
* @returns Cleanup function to unsubscribe from events
|
|
116
|
+
*/
|
|
117
|
+
setupProgressTracking(subAgentHandle, input, toolCallId, sessionId) {
|
|
118
|
+
if (!toolCallId || !sessionId) {
|
|
119
|
+
this.logger.debug(
|
|
120
|
+
`[Progress] Skipping progress tracking - missing toolCallId (${toolCallId}) or sessionId (${sessionId})`
|
|
121
|
+
);
|
|
122
|
+
return () => {
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
this.logger.debug(
|
|
126
|
+
`[Progress] Setting up progress tracking for sub-agent ${subAgentHandle.agentId} (toolCallId: ${toolCallId}, sessionId: ${sessionId})`
|
|
127
|
+
);
|
|
128
|
+
let toolCount = 0;
|
|
129
|
+
const subAgentBus = subAgentHandle.agent.agentEventBus;
|
|
130
|
+
const parentBus = this.parentAgent.agentEventBus;
|
|
131
|
+
const toolCallHandler = (event) => {
|
|
132
|
+
toolCount++;
|
|
133
|
+
let displayToolName = event.toolName;
|
|
134
|
+
if (displayToolName.startsWith("internal--")) {
|
|
135
|
+
displayToolName = displayToolName.replace("internal--", "");
|
|
136
|
+
} else if (displayToolName.startsWith("custom--")) {
|
|
137
|
+
displayToolName = displayToolName.replace("custom--", "");
|
|
138
|
+
} else if (displayToolName.startsWith("mcp--")) {
|
|
139
|
+
const parts = displayToolName.split("--");
|
|
140
|
+
if (parts.length >= 3) {
|
|
141
|
+
displayToolName = parts.slice(2).join("--");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
this.logger.debug(
|
|
145
|
+
`[Progress] Sub-agent tool call #${toolCount}: ${displayToolName} (toolCallId: ${toolCallId})`
|
|
146
|
+
);
|
|
147
|
+
parentBus.emit("service:event", {
|
|
148
|
+
service: "agent-spawner",
|
|
149
|
+
event: "progress",
|
|
150
|
+
toolCallId,
|
|
151
|
+
sessionId,
|
|
152
|
+
data: {
|
|
153
|
+
task: input.task,
|
|
154
|
+
agentId: input.agentId ?? "default",
|
|
155
|
+
toolsCalled: toolCount,
|
|
156
|
+
currentTool: displayToolName,
|
|
157
|
+
currentArgs: event.args
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
subAgentBus.on("llm:tool-call", toolCallHandler);
|
|
162
|
+
return () => {
|
|
163
|
+
subAgentBus.off("llm:tool-call", toolCallHandler);
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Try to spawn agent, falling back to parent's LLM config if the sub-agent's config fails
|
|
168
|
+
*/
|
|
169
|
+
async trySpawnWithFallback(input, timeout, autoApprove, toolCallId, sessionId) {
|
|
170
|
+
let spawnedAgentId;
|
|
171
|
+
let usedFallback = false;
|
|
172
|
+
let cleanupProgressTracking;
|
|
173
|
+
try {
|
|
174
|
+
const buildOptions = {};
|
|
175
|
+
if (input.agentId !== void 0) {
|
|
176
|
+
buildOptions.agentId = input.agentId;
|
|
177
|
+
}
|
|
178
|
+
if (autoApprove) {
|
|
179
|
+
buildOptions.autoApprove = autoApprove;
|
|
180
|
+
}
|
|
181
|
+
let subAgentConfig = await this.buildSubAgentConfig(buildOptions);
|
|
182
|
+
let handle;
|
|
183
|
+
try {
|
|
184
|
+
handle = await this.runtime.spawnAgent({
|
|
185
|
+
agentConfig: subAgentConfig,
|
|
186
|
+
ephemeral: true,
|
|
187
|
+
group: this.parentId,
|
|
188
|
+
metadata: {
|
|
189
|
+
parentId: this.parentId,
|
|
190
|
+
task: input.task,
|
|
191
|
+
autoApprove,
|
|
192
|
+
spawnedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
193
|
+
},
|
|
194
|
+
onBeforeStart: (agent) => {
|
|
195
|
+
if (!autoApprove) {
|
|
196
|
+
const delegatingHandler = (0, import_approval_delegation.createDelegatingApprovalHandler)(
|
|
197
|
+
this.parentAgent.services.approvalManager,
|
|
198
|
+
agent.config.agentId ?? "unknown",
|
|
199
|
+
this.logger
|
|
200
|
+
);
|
|
201
|
+
agent.setApprovalHandler(delegatingHandler);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
spawnedAgentId = handle.agentId;
|
|
206
|
+
} catch (spawnError) {
|
|
207
|
+
const errorMsg = spawnError instanceof Error ? spawnError.message : String(spawnError);
|
|
208
|
+
const isLlmError = errorMsg.includes("Model") || errorMsg.includes("model") || errorMsg.includes("API") || errorMsg.includes("apiKey") || errorMsg.includes("provider");
|
|
209
|
+
if (isLlmError && input.agentId) {
|
|
210
|
+
this.logger.warn(
|
|
211
|
+
`Sub-agent LLM config failed: ${errorMsg}. Falling back to parent's LLM config.`
|
|
212
|
+
);
|
|
213
|
+
usedFallback = true;
|
|
214
|
+
buildOptions.inheritLlm = true;
|
|
215
|
+
subAgentConfig = await this.buildSubAgentConfig(buildOptions);
|
|
216
|
+
handle = await this.runtime.spawnAgent({
|
|
217
|
+
agentConfig: subAgentConfig,
|
|
218
|
+
ephemeral: true,
|
|
219
|
+
group: this.parentId,
|
|
220
|
+
metadata: {
|
|
221
|
+
parentId: this.parentId,
|
|
222
|
+
task: input.task,
|
|
223
|
+
autoApprove,
|
|
224
|
+
usedLlmFallback: true,
|
|
225
|
+
spawnedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
226
|
+
},
|
|
227
|
+
onBeforeStart: (agent) => {
|
|
228
|
+
if (!autoApprove) {
|
|
229
|
+
const delegatingHandler = (0, import_approval_delegation.createDelegatingApprovalHandler)(
|
|
230
|
+
this.parentAgent.services.approvalManager,
|
|
231
|
+
agent.config.agentId ?? "unknown",
|
|
232
|
+
this.logger
|
|
233
|
+
);
|
|
234
|
+
agent.setApprovalHandler(delegatingHandler);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
spawnedAgentId = handle.agentId;
|
|
239
|
+
} else {
|
|
240
|
+
throw spawnError;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
this.logger.info(
|
|
244
|
+
`Spawned sub-agent '${spawnedAgentId}' for task: ${input.task}${autoApprove ? " (auto-approve)" : ""}${usedFallback ? " (using parent LLM)" : ""}`
|
|
245
|
+
);
|
|
246
|
+
cleanupProgressTracking = this.setupProgressTracking(
|
|
247
|
+
handle,
|
|
248
|
+
input,
|
|
249
|
+
toolCallId,
|
|
250
|
+
sessionId
|
|
251
|
+
);
|
|
252
|
+
const result = await this.runtime.executeTask(
|
|
253
|
+
spawnedAgentId,
|
|
254
|
+
input.instructions,
|
|
255
|
+
timeout
|
|
256
|
+
);
|
|
257
|
+
const output = {
|
|
258
|
+
success: result.success
|
|
259
|
+
};
|
|
260
|
+
if (result.response !== void 0) {
|
|
261
|
+
output.response = result.response;
|
|
262
|
+
}
|
|
263
|
+
if (result.error !== void 0) {
|
|
264
|
+
output.error = result.error;
|
|
265
|
+
}
|
|
266
|
+
return output;
|
|
267
|
+
} catch (error) {
|
|
268
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
269
|
+
this.logger.error(`Failed to spawn and execute: ${errorMessage}`);
|
|
270
|
+
return {
|
|
271
|
+
success: false,
|
|
272
|
+
error: errorMessage
|
|
273
|
+
};
|
|
274
|
+
} finally {
|
|
275
|
+
if (cleanupProgressTracking) {
|
|
276
|
+
cleanupProgressTracking();
|
|
277
|
+
}
|
|
278
|
+
if (spawnedAgentId) {
|
|
279
|
+
try {
|
|
280
|
+
await this.runtime.stopAgent(spawnedAgentId);
|
|
281
|
+
} catch {
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Build sub-agent config based on registry agent ID or parent config
|
|
288
|
+
*
|
|
289
|
+
* @param options.agentId - Agent ID from registry
|
|
290
|
+
* @param options.inheritLlm - Use parent's LLM config instead of sub-agent's
|
|
291
|
+
* @param options.autoApprove - Auto-approve all tool calls
|
|
292
|
+
*/
|
|
293
|
+
async buildSubAgentConfig(options) {
|
|
294
|
+
const { agentId, inheritLlm, autoApprove } = options;
|
|
295
|
+
const parentConfig = this.parentAgent.config;
|
|
296
|
+
const toolConfirmationMode = autoApprove ? "auto-approve" : "manual";
|
|
297
|
+
if (agentId) {
|
|
298
|
+
const registry = (0, import_registry.getAgentRegistry)();
|
|
299
|
+
if (!registry.hasAgent(agentId)) {
|
|
300
|
+
this.logger.warn(`Agent '${agentId}' not found in registry. Using default config.`);
|
|
301
|
+
} else {
|
|
302
|
+
const configPath = await registry.resolveAgent(agentId);
|
|
303
|
+
this.logger.debug(`Loading agent config from registry: ${configPath}`);
|
|
304
|
+
const loadedConfig = await (0, import_loader.loadAgentConfig)(configPath, this.logger);
|
|
305
|
+
let llmConfig = loadedConfig.llm;
|
|
306
|
+
if (inheritLlm) {
|
|
307
|
+
this.logger.debug("Using parent LLM config (inheritLlm=true)");
|
|
308
|
+
llmConfig = { ...parentConfig.llm };
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
...loadedConfig,
|
|
312
|
+
llm: llmConfig,
|
|
313
|
+
toolConfirmation: {
|
|
314
|
+
...loadedConfig.toolConfirmation,
|
|
315
|
+
mode: toolConfirmationMode
|
|
316
|
+
},
|
|
317
|
+
// Suppress sub-agent console logs entirely using silent transport
|
|
318
|
+
logger: {
|
|
319
|
+
level: "error",
|
|
320
|
+
transports: [{ type: "silent" }]
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const config = {
|
|
326
|
+
llm: { ...parentConfig.llm },
|
|
327
|
+
// Default system prompt for sub-agents
|
|
328
|
+
systemPrompt: "You are a helpful sub-agent. Complete the task given to you efficiently and concisely.",
|
|
329
|
+
toolConfirmation: {
|
|
330
|
+
mode: toolConfirmationMode
|
|
331
|
+
},
|
|
332
|
+
// Suppress sub-agent console logs entirely using silent transport
|
|
333
|
+
logger: {
|
|
334
|
+
level: "error",
|
|
335
|
+
transports: [{ type: "silent" }]
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
return config;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Get information about available agents for tool description.
|
|
342
|
+
* Returns agent metadata from registry, filtered by allowedAgents if configured.
|
|
343
|
+
*/
|
|
344
|
+
getAvailableAgents() {
|
|
345
|
+
const registry = (0, import_registry.getAgentRegistry)();
|
|
346
|
+
const allAgents = registry.getAvailableAgents();
|
|
347
|
+
if (this.config.allowedAgents && this.config.allowedAgents.length > 0) {
|
|
348
|
+
const result = [];
|
|
349
|
+
for (const id of this.config.allowedAgents) {
|
|
350
|
+
const agent = allAgents[id];
|
|
351
|
+
if (agent) {
|
|
352
|
+
result.push(agent);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return result;
|
|
356
|
+
}
|
|
357
|
+
return Object.values(allAgents);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Clean up all sub-agents (called when parent stops)
|
|
361
|
+
*/
|
|
362
|
+
async cleanup() {
|
|
363
|
+
this.logger.debug(`Cleaning up RuntimeService for parent '${this.parentId}'`);
|
|
364
|
+
await this.runtime.stopAll({ group: this.parentId });
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
368
|
+
0 && (module.exports = {
|
|
369
|
+
RuntimeService
|
|
370
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RuntimeService - Bridge between tools and AgentRuntime
|
|
3
|
+
*
|
|
4
|
+
* Manages the relationship between a parent agent and its sub-agents,
|
|
5
|
+
* providing methods that tools can call to spawn and execute tasks.
|
|
6
|
+
*
|
|
7
|
+
* This service adds parent-child semantics on top of the general-purpose AgentRuntime:
|
|
8
|
+
* - Uses `group` to associate spawned agents with the parent
|
|
9
|
+
* - Wires up approval delegation so sub-agent tool requests go to parent
|
|
10
|
+
* - Enforces per-parent agent limits
|
|
11
|
+
* - Always cleans up agents after task completion (synchronous model)
|
|
12
|
+
*/
|
|
13
|
+
import type { DextoAgent, IDextoLogger } from '@dexto/core';
|
|
14
|
+
import type { AgentRegistryEntry } from '../registry/types.js';
|
|
15
|
+
import type { AgentSpawnerConfig } from './schemas.js';
|
|
16
|
+
import type { SpawnAgentOutput } from './types.js';
|
|
17
|
+
export declare class RuntimeService {
|
|
18
|
+
private runtime;
|
|
19
|
+
private parentId;
|
|
20
|
+
private parentAgent;
|
|
21
|
+
private config;
|
|
22
|
+
private logger;
|
|
23
|
+
constructor(parentAgent: DextoAgent, config: AgentSpawnerConfig, logger: IDextoLogger);
|
|
24
|
+
/**
|
|
25
|
+
* Get count of sub-agents belonging to this parent
|
|
26
|
+
*/
|
|
27
|
+
private getSubAgentCount;
|
|
28
|
+
/**
|
|
29
|
+
* Check if this parent can spawn another sub-agent
|
|
30
|
+
*/
|
|
31
|
+
private canSpawn;
|
|
32
|
+
/**
|
|
33
|
+
* Spawn a sub-agent and execute a task
|
|
34
|
+
*
|
|
35
|
+
* This is the main method for the spawn_agent tool.
|
|
36
|
+
* It creates a sub-agent, executes the task, and cleans up after completion.
|
|
37
|
+
* If the sub-agent's LLM config fails, automatically falls back to parent's LLM.
|
|
38
|
+
*
|
|
39
|
+
* @param input.task - Short task description (for logging/UI)
|
|
40
|
+
* @param input.instructions - Full prompt sent to sub-agent
|
|
41
|
+
* @param input.agentId - Optional agent ID from registry
|
|
42
|
+
* @param input.timeout - Optional task timeout in milliseconds
|
|
43
|
+
* @param input.toolCallId - Optional tool call ID for progress events
|
|
44
|
+
* @param input.sessionId - Optional session ID for progress events
|
|
45
|
+
*/
|
|
46
|
+
spawnAndExecute(input: {
|
|
47
|
+
task: string;
|
|
48
|
+
instructions: string;
|
|
49
|
+
agentId?: string;
|
|
50
|
+
timeout?: number;
|
|
51
|
+
toolCallId?: string;
|
|
52
|
+
sessionId?: string;
|
|
53
|
+
}): Promise<SpawnAgentOutput>;
|
|
54
|
+
/**
|
|
55
|
+
* Set up progress event emission for a sub-agent.
|
|
56
|
+
* Subscribes to llm:tool-call events and emits service:event with progress data.
|
|
57
|
+
*
|
|
58
|
+
* @returns Cleanup function to unsubscribe from events
|
|
59
|
+
*/
|
|
60
|
+
private setupProgressTracking;
|
|
61
|
+
/**
|
|
62
|
+
* Try to spawn agent, falling back to parent's LLM config if the sub-agent's config fails
|
|
63
|
+
*/
|
|
64
|
+
private trySpawnWithFallback;
|
|
65
|
+
/**
|
|
66
|
+
* Build sub-agent config based on registry agent ID or parent config
|
|
67
|
+
*
|
|
68
|
+
* @param options.agentId - Agent ID from registry
|
|
69
|
+
* @param options.inheritLlm - Use parent's LLM config instead of sub-agent's
|
|
70
|
+
* @param options.autoApprove - Auto-approve all tool calls
|
|
71
|
+
*/
|
|
72
|
+
private buildSubAgentConfig;
|
|
73
|
+
/**
|
|
74
|
+
* Get information about available agents for tool description.
|
|
75
|
+
* Returns agent metadata from registry, filtered by allowedAgents if configured.
|
|
76
|
+
*/
|
|
77
|
+
getAvailableAgents(): AgentRegistryEntry[];
|
|
78
|
+
/**
|
|
79
|
+
* Clean up all sub-agents (called when parent stops)
|
|
80
|
+
*/
|
|
81
|
+
cleanup(): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=runtime-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-service.d.ts","sourceRoot":"","sources":["../../src/tool-provider/runtime-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAe,MAAM,aAAa,CAAC;AAKzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,qBAAa,cAAc;IACvB,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,MAAM,CAAe;gBAEjB,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,YAAY;IAuBrF;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAIxB;;OAEG;IACH,OAAO,CAAC,QAAQ;IAIhB;;;;;;;;;;;;;OAaG;IACG,eAAe,CAAC,KAAK,EAAE;QACzB,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA8C7B;;;;;OAKG;IACH,OAAO,CAAC,qBAAqB;IAqE7B;;OAEG;YACW,oBAAoB;IAgKlC;;;;;;OAMG;YACW,mBAAmB;IAuEjC;;;OAGG;IACH,kBAAkB,IAAI,kBAAkB,EAAE;IAoB1C;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAIjC"}
|