@dexto/agent-management 1.5.1 → 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.
Files changed (73) hide show
  1. package/dist/config/discover-prompts.cjs +14 -4
  2. package/dist/config/discover-prompts.d.ts +4 -4
  3. package/dist/config/discover-prompts.d.ts.map +1 -1
  4. package/dist/config/discover-prompts.js +14 -4
  5. package/dist/index.cjs +6 -1
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +2 -0
  9. package/dist/runtime/AgentPool.cjs +181 -0
  10. package/dist/runtime/AgentPool.d.ts +76 -0
  11. package/dist/runtime/AgentPool.d.ts.map +1 -0
  12. package/dist/runtime/AgentPool.js +160 -0
  13. package/dist/runtime/AgentRuntime.cjs +225 -0
  14. package/dist/runtime/AgentRuntime.d.ts +77 -0
  15. package/dist/runtime/AgentRuntime.d.ts.map +1 -0
  16. package/dist/runtime/AgentRuntime.js +201 -0
  17. package/dist/runtime/approval-delegation.cjs +97 -0
  18. package/dist/runtime/approval-delegation.d.ts +30 -0
  19. package/dist/runtime/approval-delegation.d.ts.map +1 -0
  20. package/dist/runtime/approval-delegation.js +73 -0
  21. package/dist/runtime/error-codes.cjs +40 -0
  22. package/dist/runtime/error-codes.d.ts +17 -0
  23. package/dist/runtime/error-codes.d.ts.map +1 -0
  24. package/dist/runtime/error-codes.js +16 -0
  25. package/dist/runtime/errors.cjs +135 -0
  26. package/dist/runtime/errors.d.ts +40 -0
  27. package/dist/runtime/errors.d.ts.map +1 -0
  28. package/dist/runtime/errors.js +111 -0
  29. package/dist/runtime/index.cjs +53 -0
  30. package/dist/runtime/index.d.ts +19 -0
  31. package/dist/runtime/index.d.ts.map +1 -0
  32. package/dist/runtime/index.js +26 -0
  33. package/dist/runtime/schemas.cjs +64 -0
  34. package/dist/runtime/schemas.d.ts +69 -0
  35. package/dist/runtime/schemas.d.ts.map +1 -0
  36. package/dist/runtime/schemas.js +35 -0
  37. package/dist/runtime/types.cjs +16 -0
  38. package/dist/runtime/types.d.ts +94 -0
  39. package/dist/runtime/types.d.ts.map +1 -0
  40. package/dist/runtime/types.js +0 -0
  41. package/dist/tool-provider/error-codes.cjs +35 -0
  42. package/dist/tool-provider/error-codes.d.ts +11 -0
  43. package/dist/tool-provider/error-codes.d.ts.map +1 -0
  44. package/dist/tool-provider/error-codes.js +11 -0
  45. package/dist/tool-provider/errors.cjs +81 -0
  46. package/dist/tool-provider/errors.d.ts +19 -0
  47. package/dist/tool-provider/errors.d.ts.map +1 -0
  48. package/dist/tool-provider/errors.js +57 -0
  49. package/dist/tool-provider/index.cjs +46 -0
  50. package/dist/tool-provider/index.d.ts +16 -0
  51. package/dist/tool-provider/index.d.ts.map +1 -0
  52. package/dist/tool-provider/index.js +16 -0
  53. package/dist/tool-provider/runtime-service.cjs +370 -0
  54. package/dist/tool-provider/runtime-service.d.ts +83 -0
  55. package/dist/tool-provider/runtime-service.d.ts.map +1 -0
  56. package/dist/tool-provider/runtime-service.js +346 -0
  57. package/dist/tool-provider/schemas.cjs +73 -0
  58. package/dist/tool-provider/schemas.d.ts +83 -0
  59. package/dist/tool-provider/schemas.d.ts.map +1 -0
  60. package/dist/tool-provider/schemas.js +48 -0
  61. package/dist/tool-provider/spawn-agent-tool.cjs +89 -0
  62. package/dist/tool-provider/spawn-agent-tool.d.ts +10 -0
  63. package/dist/tool-provider/spawn-agent-tool.d.ts.map +1 -0
  64. package/dist/tool-provider/spawn-agent-tool.js +65 -0
  65. package/dist/tool-provider/tool-provider.cjs +44 -0
  66. package/dist/tool-provider/tool-provider.d.ts +24 -0
  67. package/dist/tool-provider/tool-provider.d.ts.map +1 -0
  68. package/dist/tool-provider/tool-provider.js +20 -0
  69. package/dist/tool-provider/types.cjs +16 -0
  70. package/dist/tool-provider/types.d.ts +17 -0
  71. package/dist/tool-provider/types.d.ts.map +1 -0
  72. package/dist/tool-provider/types.js +0 -0
  73. package/package.json +2 -2
@@ -0,0 +1,346 @@
1
+ import { AgentRuntime } from "../runtime/AgentRuntime.js";
2
+ import { createDelegatingApprovalHandler } from "../runtime/approval-delegation.js";
3
+ import { loadAgentConfig } from "../config/loader.js";
4
+ import { getAgentRegistry } from "../registry/registry.js";
5
+ class RuntimeService {
6
+ runtime;
7
+ parentId;
8
+ parentAgent;
9
+ config;
10
+ logger;
11
+ constructor(parentAgent, config, logger) {
12
+ this.parentAgent = parentAgent;
13
+ this.config = config;
14
+ this.logger = logger;
15
+ this.parentId = parentAgent.config.agentId ?? `parent-${Date.now()}`;
16
+ this.runtime = new AgentRuntime({
17
+ config: {
18
+ maxAgents: config.maxConcurrentAgents,
19
+ defaultTaskTimeout: config.defaultTimeout
20
+ },
21
+ logger
22
+ });
23
+ this.logger.debug(
24
+ `RuntimeService initialized for parent '${this.parentId}' (maxAgents: ${config.maxConcurrentAgents})`
25
+ );
26
+ }
27
+ /**
28
+ * Get count of sub-agents belonging to this parent
29
+ */
30
+ getSubAgentCount() {
31
+ return this.runtime.listAgents({ group: this.parentId }).length;
32
+ }
33
+ /**
34
+ * Check if this parent can spawn another sub-agent
35
+ */
36
+ canSpawn() {
37
+ return this.getSubAgentCount() < this.config.maxConcurrentAgents;
38
+ }
39
+ /**
40
+ * Spawn a sub-agent and execute a task
41
+ *
42
+ * This is the main method for the spawn_agent tool.
43
+ * It creates a sub-agent, executes the task, and cleans up after completion.
44
+ * If the sub-agent's LLM config fails, automatically falls back to parent's LLM.
45
+ *
46
+ * @param input.task - Short task description (for logging/UI)
47
+ * @param input.instructions - Full prompt sent to sub-agent
48
+ * @param input.agentId - Optional agent ID from registry
49
+ * @param input.timeout - Optional task timeout in milliseconds
50
+ * @param input.toolCallId - Optional tool call ID for progress events
51
+ * @param input.sessionId - Optional session ID for progress events
52
+ */
53
+ async spawnAndExecute(input) {
54
+ if (!this.config.allowSpawning) {
55
+ return {
56
+ success: false,
57
+ error: "Agent spawning is disabled in configuration"
58
+ };
59
+ }
60
+ if (!this.canSpawn()) {
61
+ return {
62
+ success: false,
63
+ error: `Maximum sub-agents limit (${this.config.maxConcurrentAgents}) reached for this parent`
64
+ };
65
+ }
66
+ if (input.agentId && this.config.allowedAgents) {
67
+ if (!this.config.allowedAgents.includes(input.agentId)) {
68
+ return {
69
+ success: false,
70
+ error: `Agent '${input.agentId}' is not in the allowed agents list. Allowed: ${this.config.allowedAgents.join(", ")}`
71
+ };
72
+ }
73
+ }
74
+ const timeout = input.timeout ?? this.config.defaultTimeout;
75
+ let autoApprove = false;
76
+ if (input.agentId && this.config.autoApproveAgents) {
77
+ autoApprove = this.config.autoApproveAgents.includes(input.agentId);
78
+ }
79
+ const result = await this.trySpawnWithFallback(
80
+ input,
81
+ timeout,
82
+ autoApprove,
83
+ input.toolCallId,
84
+ input.sessionId
85
+ );
86
+ return result;
87
+ }
88
+ /**
89
+ * Set up progress event emission for a sub-agent.
90
+ * Subscribes to llm:tool-call events and emits service:event with progress data.
91
+ *
92
+ * @returns Cleanup function to unsubscribe from events
93
+ */
94
+ setupProgressTracking(subAgentHandle, input, toolCallId, sessionId) {
95
+ if (!toolCallId || !sessionId) {
96
+ this.logger.debug(
97
+ `[Progress] Skipping progress tracking - missing toolCallId (${toolCallId}) or sessionId (${sessionId})`
98
+ );
99
+ return () => {
100
+ };
101
+ }
102
+ this.logger.debug(
103
+ `[Progress] Setting up progress tracking for sub-agent ${subAgentHandle.agentId} (toolCallId: ${toolCallId}, sessionId: ${sessionId})`
104
+ );
105
+ let toolCount = 0;
106
+ const subAgentBus = subAgentHandle.agent.agentEventBus;
107
+ const parentBus = this.parentAgent.agentEventBus;
108
+ const toolCallHandler = (event) => {
109
+ toolCount++;
110
+ let displayToolName = event.toolName;
111
+ if (displayToolName.startsWith("internal--")) {
112
+ displayToolName = displayToolName.replace("internal--", "");
113
+ } else if (displayToolName.startsWith("custom--")) {
114
+ displayToolName = displayToolName.replace("custom--", "");
115
+ } else if (displayToolName.startsWith("mcp--")) {
116
+ const parts = displayToolName.split("--");
117
+ if (parts.length >= 3) {
118
+ displayToolName = parts.slice(2).join("--");
119
+ }
120
+ }
121
+ this.logger.debug(
122
+ `[Progress] Sub-agent tool call #${toolCount}: ${displayToolName} (toolCallId: ${toolCallId})`
123
+ );
124
+ parentBus.emit("service:event", {
125
+ service: "agent-spawner",
126
+ event: "progress",
127
+ toolCallId,
128
+ sessionId,
129
+ data: {
130
+ task: input.task,
131
+ agentId: input.agentId ?? "default",
132
+ toolsCalled: toolCount,
133
+ currentTool: displayToolName,
134
+ currentArgs: event.args
135
+ }
136
+ });
137
+ };
138
+ subAgentBus.on("llm:tool-call", toolCallHandler);
139
+ return () => {
140
+ subAgentBus.off("llm:tool-call", toolCallHandler);
141
+ };
142
+ }
143
+ /**
144
+ * Try to spawn agent, falling back to parent's LLM config if the sub-agent's config fails
145
+ */
146
+ async trySpawnWithFallback(input, timeout, autoApprove, toolCallId, sessionId) {
147
+ let spawnedAgentId;
148
+ let usedFallback = false;
149
+ let cleanupProgressTracking;
150
+ try {
151
+ const buildOptions = {};
152
+ if (input.agentId !== void 0) {
153
+ buildOptions.agentId = input.agentId;
154
+ }
155
+ if (autoApprove) {
156
+ buildOptions.autoApprove = autoApprove;
157
+ }
158
+ let subAgentConfig = await this.buildSubAgentConfig(buildOptions);
159
+ let handle;
160
+ try {
161
+ handle = await this.runtime.spawnAgent({
162
+ agentConfig: subAgentConfig,
163
+ ephemeral: true,
164
+ group: this.parentId,
165
+ metadata: {
166
+ parentId: this.parentId,
167
+ task: input.task,
168
+ autoApprove,
169
+ spawnedAt: (/* @__PURE__ */ new Date()).toISOString()
170
+ },
171
+ onBeforeStart: (agent) => {
172
+ if (!autoApprove) {
173
+ const delegatingHandler = createDelegatingApprovalHandler(
174
+ this.parentAgent.services.approvalManager,
175
+ agent.config.agentId ?? "unknown",
176
+ this.logger
177
+ );
178
+ agent.setApprovalHandler(delegatingHandler);
179
+ }
180
+ }
181
+ });
182
+ spawnedAgentId = handle.agentId;
183
+ } catch (spawnError) {
184
+ const errorMsg = spawnError instanceof Error ? spawnError.message : String(spawnError);
185
+ const isLlmError = errorMsg.includes("Model") || errorMsg.includes("model") || errorMsg.includes("API") || errorMsg.includes("apiKey") || errorMsg.includes("provider");
186
+ if (isLlmError && input.agentId) {
187
+ this.logger.warn(
188
+ `Sub-agent LLM config failed: ${errorMsg}. Falling back to parent's LLM config.`
189
+ );
190
+ usedFallback = true;
191
+ buildOptions.inheritLlm = true;
192
+ subAgentConfig = await this.buildSubAgentConfig(buildOptions);
193
+ handle = await this.runtime.spawnAgent({
194
+ agentConfig: subAgentConfig,
195
+ ephemeral: true,
196
+ group: this.parentId,
197
+ metadata: {
198
+ parentId: this.parentId,
199
+ task: input.task,
200
+ autoApprove,
201
+ usedLlmFallback: true,
202
+ spawnedAt: (/* @__PURE__ */ new Date()).toISOString()
203
+ },
204
+ onBeforeStart: (agent) => {
205
+ if (!autoApprove) {
206
+ const delegatingHandler = createDelegatingApprovalHandler(
207
+ this.parentAgent.services.approvalManager,
208
+ agent.config.agentId ?? "unknown",
209
+ this.logger
210
+ );
211
+ agent.setApprovalHandler(delegatingHandler);
212
+ }
213
+ }
214
+ });
215
+ spawnedAgentId = handle.agentId;
216
+ } else {
217
+ throw spawnError;
218
+ }
219
+ }
220
+ this.logger.info(
221
+ `Spawned sub-agent '${spawnedAgentId}' for task: ${input.task}${autoApprove ? " (auto-approve)" : ""}${usedFallback ? " (using parent LLM)" : ""}`
222
+ );
223
+ cleanupProgressTracking = this.setupProgressTracking(
224
+ handle,
225
+ input,
226
+ toolCallId,
227
+ sessionId
228
+ );
229
+ const result = await this.runtime.executeTask(
230
+ spawnedAgentId,
231
+ input.instructions,
232
+ timeout
233
+ );
234
+ const output = {
235
+ success: result.success
236
+ };
237
+ if (result.response !== void 0) {
238
+ output.response = result.response;
239
+ }
240
+ if (result.error !== void 0) {
241
+ output.error = result.error;
242
+ }
243
+ return output;
244
+ } catch (error) {
245
+ const errorMessage = error instanceof Error ? error.message : String(error);
246
+ this.logger.error(`Failed to spawn and execute: ${errorMessage}`);
247
+ return {
248
+ success: false,
249
+ error: errorMessage
250
+ };
251
+ } finally {
252
+ if (cleanupProgressTracking) {
253
+ cleanupProgressTracking();
254
+ }
255
+ if (spawnedAgentId) {
256
+ try {
257
+ await this.runtime.stopAgent(spawnedAgentId);
258
+ } catch {
259
+ }
260
+ }
261
+ }
262
+ }
263
+ /**
264
+ * Build sub-agent config based on registry agent ID or parent config
265
+ *
266
+ * @param options.agentId - Agent ID from registry
267
+ * @param options.inheritLlm - Use parent's LLM config instead of sub-agent's
268
+ * @param options.autoApprove - Auto-approve all tool calls
269
+ */
270
+ async buildSubAgentConfig(options) {
271
+ const { agentId, inheritLlm, autoApprove } = options;
272
+ const parentConfig = this.parentAgent.config;
273
+ const toolConfirmationMode = autoApprove ? "auto-approve" : "manual";
274
+ if (agentId) {
275
+ const registry = getAgentRegistry();
276
+ if (!registry.hasAgent(agentId)) {
277
+ this.logger.warn(`Agent '${agentId}' not found in registry. Using default config.`);
278
+ } else {
279
+ const configPath = await registry.resolveAgent(agentId);
280
+ this.logger.debug(`Loading agent config from registry: ${configPath}`);
281
+ const loadedConfig = await loadAgentConfig(configPath, this.logger);
282
+ let llmConfig = loadedConfig.llm;
283
+ if (inheritLlm) {
284
+ this.logger.debug("Using parent LLM config (inheritLlm=true)");
285
+ llmConfig = { ...parentConfig.llm };
286
+ }
287
+ return {
288
+ ...loadedConfig,
289
+ llm: llmConfig,
290
+ toolConfirmation: {
291
+ ...loadedConfig.toolConfirmation,
292
+ mode: toolConfirmationMode
293
+ },
294
+ // Suppress sub-agent console logs entirely using silent transport
295
+ logger: {
296
+ level: "error",
297
+ transports: [{ type: "silent" }]
298
+ }
299
+ };
300
+ }
301
+ }
302
+ const config = {
303
+ llm: { ...parentConfig.llm },
304
+ // Default system prompt for sub-agents
305
+ systemPrompt: "You are a helpful sub-agent. Complete the task given to you efficiently and concisely.",
306
+ toolConfirmation: {
307
+ mode: toolConfirmationMode
308
+ },
309
+ // Suppress sub-agent console logs entirely using silent transport
310
+ logger: {
311
+ level: "error",
312
+ transports: [{ type: "silent" }]
313
+ }
314
+ };
315
+ return config;
316
+ }
317
+ /**
318
+ * Get information about available agents for tool description.
319
+ * Returns agent metadata from registry, filtered by allowedAgents if configured.
320
+ */
321
+ getAvailableAgents() {
322
+ const registry = getAgentRegistry();
323
+ const allAgents = registry.getAvailableAgents();
324
+ if (this.config.allowedAgents && this.config.allowedAgents.length > 0) {
325
+ const result = [];
326
+ for (const id of this.config.allowedAgents) {
327
+ const agent = allAgents[id];
328
+ if (agent) {
329
+ result.push(agent);
330
+ }
331
+ }
332
+ return result;
333
+ }
334
+ return Object.values(allAgents);
335
+ }
336
+ /**
337
+ * Clean up all sub-agents (called when parent stops)
338
+ */
339
+ async cleanup() {
340
+ this.logger.debug(`Cleaning up RuntimeService for parent '${this.parentId}'`);
341
+ await this.runtime.stopAll({ group: this.parentId });
342
+ }
343
+ }
344
+ export {
345
+ RuntimeService
346
+ };
@@ -0,0 +1,73 @@
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 schemas_exports = {};
20
+ __export(schemas_exports, {
21
+ AgentSpawnerConfigSchema: () => AgentSpawnerConfigSchema,
22
+ SpawnAgentInputSchema: () => SpawnAgentInputSchema
23
+ });
24
+ module.exports = __toCommonJS(schemas_exports);
25
+ var import_zod = require("zod");
26
+ const AgentSpawnerConfigSchema = import_zod.z.object({
27
+ /** Type discriminator for the provider */
28
+ type: import_zod.z.literal("agent-spawner"),
29
+ /** Maximum concurrent sub-agents this parent can spawn (default: 5) */
30
+ maxConcurrentAgents: import_zod.z.number().int().positive().default(5).describe("Maximum concurrent sub-agents"),
31
+ /** Default timeout for task execution in milliseconds (default: 300000 = 5 min) */
32
+ defaultTimeout: import_zod.z.number().int().positive().default(3e5).describe("Default task timeout in milliseconds"),
33
+ /** Whether spawning is enabled (default: true) */
34
+ allowSpawning: import_zod.z.boolean().default(true).describe("Whether agent spawning is enabled"),
35
+ /**
36
+ * List of agent IDs from the registry that this parent can spawn.
37
+ * If not provided, any registry agent can be spawned.
38
+ *
39
+ * Example:
40
+ * ```yaml
41
+ * customTools:
42
+ * - type: agent-spawner
43
+ * allowedAgents: ["explore-agent", "research-agent"]
44
+ * ```
45
+ */
46
+ allowedAgents: import_zod.z.array(import_zod.z.string().min(1)).optional().describe("Agent IDs from registry that can be spawned (omit to allow all)"),
47
+ /**
48
+ * Agent IDs that should have their tools auto-approved.
49
+ * Use for agents with only read-only/safe tools (e.g., explore-agent).
50
+ *
51
+ * Example:
52
+ * ```yaml
53
+ * customTools:
54
+ * - type: agent-spawner
55
+ * allowedAgents: ["explore-agent"]
56
+ * autoApproveAgents: ["explore-agent"]
57
+ * ```
58
+ */
59
+ autoApproveAgents: import_zod.z.array(import_zod.z.string().min(1)).optional().describe("Agent IDs that should have tools auto-approved (read-only agents)")
60
+ }).strict().describe("Configuration for the agent spawner tool provider");
61
+ const SpawnAgentInputSchema = import_zod.z.object({
62
+ /** Short task description (shown in UI/logs) */
63
+ task: import_zod.z.string().min(1).describe("Short task description for UI/logs"),
64
+ /** Detailed instructions for the sub-agent */
65
+ instructions: import_zod.z.string().min(1).describe("Detailed instructions for the sub-agent to execute"),
66
+ /** Agent ID from registry (optional - uses default minimal agent if not provided) */
67
+ agentId: import_zod.z.string().min(1).optional().describe("Agent ID from registry")
68
+ }).strict();
69
+ // Annotate the CommonJS export names for ESM import in node:
70
+ 0 && (module.exports = {
71
+ AgentSpawnerConfigSchema,
72
+ SpawnAgentInputSchema
73
+ });
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Agent Spawner Tool Provider Schemas
3
+ *
4
+ * Zod schemas for the agent spawner tool provider configuration and inputs.
5
+ */
6
+ import { z } from 'zod';
7
+ /**
8
+ * Configuration schema for the agent spawner tool provider
9
+ */
10
+ export declare const AgentSpawnerConfigSchema: z.ZodObject<{
11
+ /** Type discriminator for the provider */
12
+ type: z.ZodLiteral<"agent-spawner">;
13
+ /** Maximum concurrent sub-agents this parent can spawn (default: 5) */
14
+ maxConcurrentAgents: z.ZodDefault<z.ZodNumber>;
15
+ /** Default timeout for task execution in milliseconds (default: 300000 = 5 min) */
16
+ defaultTimeout: z.ZodDefault<z.ZodNumber>;
17
+ /** Whether spawning is enabled (default: true) */
18
+ allowSpawning: z.ZodDefault<z.ZodBoolean>;
19
+ /**
20
+ * List of agent IDs from the registry that this parent can spawn.
21
+ * If not provided, any registry agent can be spawned.
22
+ *
23
+ * Example:
24
+ * ```yaml
25
+ * customTools:
26
+ * - type: agent-spawner
27
+ * allowedAgents: ["explore-agent", "research-agent"]
28
+ * ```
29
+ */
30
+ allowedAgents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
31
+ /**
32
+ * Agent IDs that should have their tools auto-approved.
33
+ * Use for agents with only read-only/safe tools (e.g., explore-agent).
34
+ *
35
+ * Example:
36
+ * ```yaml
37
+ * customTools:
38
+ * - type: agent-spawner
39
+ * allowedAgents: ["explore-agent"]
40
+ * autoApproveAgents: ["explore-agent"]
41
+ * ```
42
+ */
43
+ autoApproveAgents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
44
+ }, "strict", z.ZodTypeAny, {
45
+ type: "agent-spawner";
46
+ maxConcurrentAgents: number;
47
+ defaultTimeout: number;
48
+ allowSpawning: boolean;
49
+ allowedAgents?: string[] | undefined;
50
+ autoApproveAgents?: string[] | undefined;
51
+ }, {
52
+ type: "agent-spawner";
53
+ maxConcurrentAgents?: number | undefined;
54
+ defaultTimeout?: number | undefined;
55
+ allowSpawning?: boolean | undefined;
56
+ allowedAgents?: string[] | undefined;
57
+ autoApproveAgents?: string[] | undefined;
58
+ }>;
59
+ export type AgentSpawnerConfig = z.output<typeof AgentSpawnerConfigSchema>;
60
+ /**
61
+ * Input schema for spawn_agent tool
62
+ *
63
+ * Note: Timeout is configured at the provider level (defaultTimeout in config).
64
+ * We don't expose timeout as a tool parameter because lowering it just wastes runs.
65
+ */
66
+ export declare const SpawnAgentInputSchema: z.ZodObject<{
67
+ /** Short task description (shown in UI/logs) */
68
+ task: z.ZodString;
69
+ /** Detailed instructions for the sub-agent */
70
+ instructions: z.ZodString;
71
+ /** Agent ID from registry (optional - uses default minimal agent if not provided) */
72
+ agentId: z.ZodOptional<z.ZodString>;
73
+ }, "strict", z.ZodTypeAny, {
74
+ task: string;
75
+ instructions: string;
76
+ agentId?: string | undefined;
77
+ }, {
78
+ task: string;
79
+ instructions: string;
80
+ agentId?: string | undefined;
81
+ }>;
82
+ export type SpawnAgentInput = z.output<typeof SpawnAgentInputSchema>;
83
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/tool-provider/schemas.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;GAEG;AACH,eAAO,MAAM,wBAAwB;IAE7B,0CAA0C;;IAG1C,uEAAuE;;IAQvE,mFAAmF;;IAQnF,kDAAkD;;IAGlD;;;;;;;;;;OAUG;;IAMH;;;;;;;;;;;OAWG;;;;;;;;;;;;;;;;EAOuD,CAAC;AAEnE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAM3E;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB;IAE1B,gDAAgD;;IAGhD,8CAA8C;;IAM9C,qFAAqF;;;;;;;;;;EAGhF,CAAC;AAEd,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { z } from "zod";
2
+ const AgentSpawnerConfigSchema = z.object({
3
+ /** Type discriminator for the provider */
4
+ type: z.literal("agent-spawner"),
5
+ /** Maximum concurrent sub-agents this parent can spawn (default: 5) */
6
+ maxConcurrentAgents: z.number().int().positive().default(5).describe("Maximum concurrent sub-agents"),
7
+ /** Default timeout for task execution in milliseconds (default: 300000 = 5 min) */
8
+ defaultTimeout: z.number().int().positive().default(3e5).describe("Default task timeout in milliseconds"),
9
+ /** Whether spawning is enabled (default: true) */
10
+ allowSpawning: z.boolean().default(true).describe("Whether agent spawning is enabled"),
11
+ /**
12
+ * List of agent IDs from the registry that this parent can spawn.
13
+ * If not provided, any registry agent can be spawned.
14
+ *
15
+ * Example:
16
+ * ```yaml
17
+ * customTools:
18
+ * - type: agent-spawner
19
+ * allowedAgents: ["explore-agent", "research-agent"]
20
+ * ```
21
+ */
22
+ allowedAgents: z.array(z.string().min(1)).optional().describe("Agent IDs from registry that can be spawned (omit to allow all)"),
23
+ /**
24
+ * Agent IDs that should have their tools auto-approved.
25
+ * Use for agents with only read-only/safe tools (e.g., explore-agent).
26
+ *
27
+ * Example:
28
+ * ```yaml
29
+ * customTools:
30
+ * - type: agent-spawner
31
+ * allowedAgents: ["explore-agent"]
32
+ * autoApproveAgents: ["explore-agent"]
33
+ * ```
34
+ */
35
+ autoApproveAgents: z.array(z.string().min(1)).optional().describe("Agent IDs that should have tools auto-approved (read-only agents)")
36
+ }).strict().describe("Configuration for the agent spawner tool provider");
37
+ const SpawnAgentInputSchema = z.object({
38
+ /** Short task description (shown in UI/logs) */
39
+ task: z.string().min(1).describe("Short task description for UI/logs"),
40
+ /** Detailed instructions for the sub-agent */
41
+ instructions: z.string().min(1).describe("Detailed instructions for the sub-agent to execute"),
42
+ /** Agent ID from registry (optional - uses default minimal agent if not provided) */
43
+ agentId: z.string().min(1).optional().describe("Agent ID from registry")
44
+ }).strict();
45
+ export {
46
+ AgentSpawnerConfigSchema,
47
+ SpawnAgentInputSchema
48
+ };
@@ -0,0 +1,89 @@
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 spawn_agent_tool_exports = {};
20
+ __export(spawn_agent_tool_exports, {
21
+ createSpawnAgentTool: () => createSpawnAgentTool
22
+ });
23
+ module.exports = __toCommonJS(spawn_agent_tool_exports);
24
+ var import_schemas = require("./schemas.js");
25
+ function buildDescription(service) {
26
+ const availableAgents = service.getAvailableAgents();
27
+ if (availableAgents.length === 0) {
28
+ return `Spawn a sub-agent to handle a specific task. The sub-agent executes the task and returns the result.
29
+
30
+ No specialized agents are configured. The sub-agent will inherit your LLM with a minimal config.
31
+
32
+ ## Parameters
33
+ - **task**: Short description for UI/logs (e.g., "Search for authentication code")
34
+ - **instructions**: Detailed instructions for the sub-agent`;
35
+ }
36
+ const agentsList = availableAgents.map((agent) => {
37
+ const tags = agent.tags?.length ? ` [${agent.tags.slice(0, 3).join(", ")}]` : "";
38
+ return `### ${agent.id}
39
+ ${agent.description}${tags}`;
40
+ }).join("\n\n");
41
+ return `Spawn a specialized sub-agent to handle a task. The sub-agent executes independently and returns the result.
42
+
43
+ ## Available Agents
44
+
45
+ ${agentsList}
46
+
47
+ ## Parameters
48
+ - **task**: Short description for UI/logs (e.g., "Explore authentication flow")
49
+ - **instructions**: Detailed instructions sent to the sub-agent
50
+ - **agentId**: Agent ID from the list above (e.g., "${availableAgents[0]?.id ?? "explore-agent"}")
51
+
52
+ ## Notes
53
+ - Sub-agents have their own tools, LLM, and conversation context
54
+ - Read-only agents (like explore-agent) have auto-approved tool calls for speed
55
+ - If a sub-agent's LLM fails, it automatically falls back to your LLM`;
56
+ }
57
+ function createSpawnAgentTool(service) {
58
+ return {
59
+ id: "spawn_agent",
60
+ description: buildDescription(service),
61
+ inputSchema: import_schemas.SpawnAgentInputSchema,
62
+ execute: async (input, context) => {
63
+ const validatedInput = input;
64
+ const options = {
65
+ task: validatedInput.task,
66
+ instructions: validatedInput.instructions
67
+ };
68
+ if (validatedInput.agentId !== void 0) {
69
+ options.agentId = validatedInput.agentId;
70
+ }
71
+ if (context?.toolCallId !== void 0) {
72
+ options.toolCallId = context.toolCallId;
73
+ }
74
+ if (context?.sessionId !== void 0) {
75
+ options.sessionId = context.sessionId;
76
+ }
77
+ const result = await service.spawnAndExecute(options);
78
+ if (result.success) {
79
+ return result.response ?? "Task completed successfully.";
80
+ } else {
81
+ return `Error: ${result.error ?? "Unknown error"}`;
82
+ }
83
+ }
84
+ };
85
+ }
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ createSpawnAgentTool
89
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * spawn_agent Tool
3
+ *
4
+ * Spawns a sub-agent to handle a specific task.
5
+ * The sub-agent will execute the task and return the result.
6
+ */
7
+ import type { InternalTool } from '@dexto/core';
8
+ import type { RuntimeService } from './runtime-service.js';
9
+ export declare function createSpawnAgentTool(service: RuntimeService): InternalTool;
10
+ //# sourceMappingURL=spawn-agent-tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spawn-agent-tool.d.ts","sourceRoot":"","sources":["../../src/tool-provider/spawn-agent-tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAwB,MAAM,aAAa,CAAC;AAEtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AA4C3D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,cAAc,GAAG,YAAY,CA0C1E"}