@ai-setting/roy-agent-core 1.5.55 → 1.5.57
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/config/index.js +9 -9
- package/dist/env/agent/index.js +12 -12
- package/dist/env/commands/index.js +9 -9
- package/dist/env/context/index.js +5 -5
- package/dist/env/debug/index.js +9 -9
- package/dist/env/event-source/index.js +11 -11
- package/dist/env/hook/index.js +7 -7
- package/dist/env/index.js +30 -30
- package/dist/env/llm/index.js +10 -10
- package/dist/env/log-trace/index.js +9 -9
- package/dist/env/mcp/index.js +10 -10
- package/dist/env/mcp/tool/index.js +3 -3
- package/dist/env/memory/index.js +10 -10
- package/dist/env/memory/plugin/index.js +3 -3
- package/dist/env/plugin/index.js +9 -9
- package/dist/env/prompt/index.js +9 -9
- package/dist/env/session/index.js +10 -10
- package/dist/env/skill/index.js +9 -9
- package/dist/env/task/delegate/index.js +8 -8
- package/dist/env/task/index.js +13 -13
- package/dist/env/task/plugins/index.js +6 -6
- package/dist/env/task/storage/index.js +3 -3
- package/dist/env/task/tools/index.js +5 -5
- package/dist/env/tool/built-in/index.js +2 -2
- package/dist/env/tool/index.js +10 -10
- package/dist/env/workflow/engine/index.js +11 -11
- package/dist/env/workflow/index.js +15 -15
- package/dist/env/workflow/nodes/index.js +4 -4
- package/dist/env/workflow/storage/index.js +4 -4
- package/dist/env/workflow/tools/index.js +2 -2
- package/dist/env/workflow/utils/index.js +4 -4
- package/dist/index.js +42 -42
- package/dist/shared/@ai-setting/{roy-agent-core-5t6cryce.js → roy-agent-core-07290s9n.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-9bmtxmp6.js → roy-agent-core-0jc06hhg.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-mab4mzg3.js → roy-agent-core-2h38rvyj.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-zmw5d68q.js → roy-agent-core-3czy06aq.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-nfa6fc3a.js → roy-agent-core-48jprgqk.js} +72 -234
- package/dist/shared/@ai-setting/{roy-agent-core-8n4bz6y3.js → roy-agent-core-496zzm5a.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-fwq0hs6e.js → roy-agent-core-58yjq16r.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-5k8watmp.js → roy-agent-core-5c2mfq1q.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-4ch3ghj6.js → roy-agent-core-65yjzwv5.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-9ffsvvcf.js → roy-agent-core-6b57g1zk.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-29867p67.js → roy-agent-core-6d5v531t.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-egsx6js7.js → roy-agent-core-6ph5va4n.js} +9 -8
- package/dist/shared/@ai-setting/{roy-agent-core-f336bk4g.js → roy-agent-core-6s3vec2y.js} +6 -6
- package/dist/shared/@ai-setting/{roy-agent-core-zwp3jp02.js → roy-agent-core-74cp3zp1.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-qmr365f5.js → roy-agent-core-7tp56w6n.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-kjdpe2ey.js → roy-agent-core-7wdjpbcr.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-58k274fg.js → roy-agent-core-7z9b1fm8.js} +1 -0
- package/dist/shared/@ai-setting/{roy-agent-core-bwrzwq5x.js → roy-agent-core-8pk6a00t.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-3jk7ngmx.js → roy-agent-core-8vkr264k.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-6vxg2gmr.js → roy-agent-core-9r8pew8y.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-ty33mnr7.js → roy-agent-core-am646wfz.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-rz57pqpa.js → roy-agent-core-ap59dpve.js} +5 -6
- package/dist/shared/@ai-setting/{roy-agent-core-t5kc8f7p.js → roy-agent-core-at22pe4k.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-hd9p5490.js → roy-agent-core-b8r4tfqq.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-z5sxe4p7.js → roy-agent-core-c6vet6xc.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-1bfmxx89.js → roy-agent-core-djtkntar.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-2xah3h0z.js → roy-agent-core-e1704378.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-ggvv4snf.js +20 -0
- package/dist/shared/@ai-setting/{roy-agent-core-9m9m6fe1.js → roy-agent-core-hkeegfq0.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-v002ynpa.js → roy-agent-core-hkfkhaas.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-q5qj0fes.js → roy-agent-core-k05v31rc.js} +6 -3
- package/dist/shared/@ai-setting/{roy-agent-core-2g5j2nw6.js → roy-agent-core-n19rm7tw.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-emk3q2nt.js → roy-agent-core-nx3c3ce2.js} +17 -13
- package/dist/shared/@ai-setting/{roy-agent-core-e68xspar.js → roy-agent-core-prdngx28.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-nt1q2g91.js → roy-agent-core-pwzkgtgr.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-vbyct0e7.js → roy-agent-core-q16bh5e9.js} +13 -11
- package/dist/shared/@ai-setting/{roy-agent-core-13vzexp2.js → roy-agent-core-qg4rma4c.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-cssnkkkg.js → roy-agent-core-rgckng3p.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-dpc9tz73.js → roy-agent-core-rmd82vf7.js} +12 -12
- package/dist/shared/@ai-setting/{roy-agent-core-cpf38des.js → roy-agent-core-sfqx98j6.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-10n2jh7p.js → roy-agent-core-shme7set.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-88d3k0p0.js → roy-agent-core-v8xa6vs8.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-e8eefm0k.js → roy-agent-core-w4f871e2.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-qakqwbbh.js → roy-agent-core-w6wagmhw.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-kwhv9dcd.js → roy-agent-core-x3gtyqax.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-c3ct1346.js → roy-agent-core-xhcgg11h.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-v7583cf9.js → roy-agent-core-y5d04fm3.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-t6zhkk09.js → roy-agent-core-zgtmazxg.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-0x3g6snw.js → roy-agent-core-zkwe508t.js} +7 -7
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-de0y1a5s.js +0 -20
|
@@ -6,11 +6,11 @@ import {
|
|
|
6
6
|
} from "./roy-agent-core-qxhq8ven.js";
|
|
7
7
|
import {
|
|
8
8
|
BaseComponent
|
|
9
|
-
} from "./roy-agent-core-
|
|
9
|
+
} from "./roy-agent-core-rgckng3p.js";
|
|
10
10
|
import {
|
|
11
11
|
createLogger,
|
|
12
12
|
init_logger
|
|
13
|
-
} from "./roy-agent-core-
|
|
13
|
+
} from "./roy-agent-core-shme7set.js";
|
|
14
14
|
|
|
15
15
|
// src/env/memory/types.ts
|
|
16
16
|
import { z } from "zod";
|
|
@@ -8,17 +8,17 @@ import {
|
|
|
8
8
|
} from "./roy-agent-core-fnv3ev18.js";
|
|
9
9
|
import {
|
|
10
10
|
adaptMcpTool
|
|
11
|
-
} from "./roy-agent-core-
|
|
11
|
+
} from "./roy-agent-core-djtkntar.js";
|
|
12
12
|
import {
|
|
13
13
|
toEnvKey
|
|
14
14
|
} from "./roy-agent-core-qxhq8ven.js";
|
|
15
15
|
import {
|
|
16
16
|
BaseComponent
|
|
17
|
-
} from "./roy-agent-core-
|
|
17
|
+
} from "./roy-agent-core-rgckng3p.js";
|
|
18
18
|
import {
|
|
19
19
|
createLogger,
|
|
20
20
|
init_logger
|
|
21
|
-
} from "./roy-agent-core-
|
|
21
|
+
} from "./roy-agent-core-shme7set.js";
|
|
22
22
|
|
|
23
23
|
// src/env/mcp/types.ts
|
|
24
24
|
import { z } from "zod";
|
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_SUBAGENT_PROMPT
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-nx3c3ce2.js";
|
|
4
4
|
import {
|
|
5
5
|
TaskHookPoints
|
|
6
6
|
} from "./roy-agent-core-92z6t4he.js";
|
|
7
7
|
import {
|
|
8
8
|
globalHookManager,
|
|
9
9
|
init_global_hook_manager
|
|
10
|
-
} from "./roy-agent-core-
|
|
10
|
+
} from "./roy-agent-core-7tp56w6n.js";
|
|
11
11
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
init_context
|
|
13
|
+
} from "./roy-agent-core-qg4rma4c.js";
|
|
14
|
+
import {
|
|
15
|
+
getCurrentTaskId
|
|
16
|
+
} from "./roy-agent-core-y5d04fm3.js";
|
|
15
17
|
import {
|
|
16
18
|
TracedAs,
|
|
17
19
|
init_decorator
|
|
18
|
-
} from "./roy-agent-core-
|
|
20
|
+
} from "./roy-agent-core-k05v31rc.js";
|
|
19
21
|
import {
|
|
20
22
|
createLogger,
|
|
21
23
|
init_logger
|
|
22
|
-
} from "./roy-agent-core-
|
|
24
|
+
} from "./roy-agent-core-shme7set.js";
|
|
23
25
|
import {
|
|
24
26
|
__legacyDecorateClassTS
|
|
25
27
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
26
28
|
|
|
27
29
|
// src/env/task/delegate/delegate-tool.ts
|
|
28
30
|
init_logger();
|
|
29
|
-
init_env_context();
|
|
30
31
|
init_decorator();
|
|
32
|
+
init_context();
|
|
31
33
|
import { z } from "zod";
|
|
32
34
|
|
|
33
35
|
// src/env/task/delegate/subagent-resolver.ts
|
|
@@ -205,10 +207,7 @@ var DelegateToolParameters = z.object({
|
|
|
205
207
|
description: z.string().describe("A short (3-5 words) description of the task"),
|
|
206
208
|
prompt: z.string().describe("The task for the agent to perform"),
|
|
207
209
|
subagent_type: z.string().describe("The type of specialized agent to use for this task").default("general"),
|
|
208
|
-
background: z.boolean().describe("Whether to run the task in background. If true, returns immediately and notifies when complete (default: false)").default(false),
|
|
209
210
|
timeout: z.number().describe("Task timeout in milliseconds. Default: 1800000 (30 minutes). If set, task will be terminated after timeout.").optional(),
|
|
210
|
-
cleanup: z.enum(["delete", "keep"]).describe("Whether to delete sub session after completion. 'delete' removes the session, 'keep' retains it (default: keep)").default("keep").optional(),
|
|
211
|
-
task_id: z.number().describe("Optional task ID to associate with this delegate task, for tracking in operation records").optional(),
|
|
212
211
|
reason: z.string().describe("Brief reason for calling this tool (max 30 chars, e.g., 'Delegate refactor task')").optional()
|
|
213
212
|
});
|
|
214
213
|
var DEFAULT_TIMEOUT = 1800000;
|
|
@@ -239,8 +238,8 @@ class BackgroundTaskManager {
|
|
|
239
238
|
}
|
|
240
239
|
}
|
|
241
240
|
async createTask(options) {
|
|
242
|
-
const { parentSessionId, description, prompt, subagentType, timeout
|
|
243
|
-
const taskIdGen = `
|
|
241
|
+
const { parentSessionId, description, prompt, subagentType, timeout } = options;
|
|
242
|
+
const taskIdGen = `process_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;
|
|
244
243
|
const sessionComponent = this.getSessionComponent();
|
|
245
244
|
if (!sessionComponent) {
|
|
246
245
|
throw new Error("SessionComponent not found");
|
|
@@ -254,9 +253,6 @@ class BackgroundTaskManager {
|
|
|
254
253
|
created_by: "subagent",
|
|
255
254
|
task_description: description
|
|
256
255
|
};
|
|
257
|
-
if (taskId) {
|
|
258
|
-
metadata.task_id = taskId;
|
|
259
|
-
}
|
|
260
256
|
const subSession = await sessionComponent.create({
|
|
261
257
|
title: `${description} (@${subagentType} subagent)`,
|
|
262
258
|
metadata
|
|
@@ -273,8 +269,7 @@ class BackgroundTaskManager {
|
|
|
273
269
|
subagentType,
|
|
274
270
|
status: "pending",
|
|
275
271
|
createdAt: Date.now(),
|
|
276
|
-
abortController
|
|
277
|
-
taskId
|
|
272
|
+
abortController
|
|
278
273
|
};
|
|
279
274
|
this.tasks.set(taskIdGen, task);
|
|
280
275
|
this.abortControllers.set(taskIdGen, abortController);
|
|
@@ -283,11 +278,10 @@ class BackgroundTaskManager {
|
|
|
283
278
|
subSessionId: subSession.id,
|
|
284
279
|
parentSessionId,
|
|
285
280
|
description,
|
|
286
|
-
subagentType
|
|
287
|
-
associatedTaskId: taskId
|
|
281
|
+
subagentType
|
|
288
282
|
};
|
|
289
283
|
this.publishBackgroundEvent(BackgroundTaskEventTypes.STARTED, startedPayload, parentSessionId);
|
|
290
|
-
this.executeTask(taskIdGen, prompt, timeout,
|
|
284
|
+
this.executeTask(taskIdGen, prompt, timeout, parentSessionId).catch((err) => {
|
|
291
285
|
logger.error(`[BackgroundTaskManager] executeTask unhandled rejection`, {
|
|
292
286
|
taskId: taskIdGen,
|
|
293
287
|
error: err instanceof Error ? err.message : String(err)
|
|
@@ -295,7 +289,7 @@ class BackgroundTaskManager {
|
|
|
295
289
|
});
|
|
296
290
|
return { taskId: taskIdGen, subSessionId: subSession.id };
|
|
297
291
|
}
|
|
298
|
-
async executeTask(taskId, prompt, timeout,
|
|
292
|
+
async executeTask(taskId, prompt, timeout, parentSessionId) {
|
|
299
293
|
const task = this.tasks.get(taskId);
|
|
300
294
|
if (!task) {
|
|
301
295
|
logger.warn(`[BackgroundTaskManager] executeTask: Task not found`, { taskId });
|
|
@@ -321,6 +315,13 @@ class BackgroundTaskManager {
|
|
|
321
315
|
task.completedAt = Date.now();
|
|
322
316
|
task.result = result;
|
|
323
317
|
const executionTimeMs = task.completedAt - task.startedAt;
|
|
318
|
+
task.associatedTaskId = getCurrentTaskId();
|
|
319
|
+
if (task.associatedTaskId === undefined && result) {
|
|
320
|
+
const match = result.match(/Task\s+#?(\d+)/i);
|
|
321
|
+
if (match) {
|
|
322
|
+
task.associatedTaskId = parseInt(match[1], 10);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
324
325
|
const completedPayload = {
|
|
325
326
|
backgroundTaskId: task.id,
|
|
326
327
|
subSessionId: task.subSessionId,
|
|
@@ -329,7 +330,7 @@ class BackgroundTaskManager {
|
|
|
329
330
|
result: task.result,
|
|
330
331
|
description: task.description,
|
|
331
332
|
executionTimeMs,
|
|
332
|
-
associatedTaskId: task.
|
|
333
|
+
associatedTaskId: task.associatedTaskId
|
|
333
334
|
};
|
|
334
335
|
this.publishBackgroundEvent(BackgroundTaskEventTypes.COMPLETED, completedPayload, parentSessionId || task.parentSessionId);
|
|
335
336
|
logger.info(`[BackgroundTaskManager] Task completed successfully`, {
|
|
@@ -340,6 +341,7 @@ class BackgroundTaskManager {
|
|
|
340
341
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
341
342
|
const isStoppedError = errorMessage.toLowerCase().includes("stopped") || errorMessage.toLowerCase().includes("aborted");
|
|
342
343
|
const executionTimeMs = task.startedAt ? Date.now() - task.startedAt : 0;
|
|
344
|
+
task.associatedTaskId = getCurrentTaskId();
|
|
343
345
|
if (isStoppedError) {
|
|
344
346
|
task.status = "stopped";
|
|
345
347
|
const stoppedPayload = {
|
|
@@ -350,7 +352,7 @@ class BackgroundTaskManager {
|
|
|
350
352
|
description: task.description,
|
|
351
353
|
error: errorMessage,
|
|
352
354
|
executionTimeMs,
|
|
353
|
-
associatedTaskId: task.
|
|
355
|
+
associatedTaskId: task.associatedTaskId
|
|
354
356
|
};
|
|
355
357
|
this.publishBackgroundEvent(BackgroundTaskEventTypes.STOPPED, stoppedPayload, parentSessionId || task.parentSessionId);
|
|
356
358
|
} else if (errorMessage.includes("timeout")) {
|
|
@@ -363,7 +365,7 @@ class BackgroundTaskManager {
|
|
|
363
365
|
description: task.description,
|
|
364
366
|
error: errorMessage,
|
|
365
367
|
executionTimeMs,
|
|
366
|
-
associatedTaskId: task.
|
|
368
|
+
associatedTaskId: task.associatedTaskId
|
|
367
369
|
};
|
|
368
370
|
this.publishBackgroundEvent(BackgroundTaskEventTypes.TIMEOUT, timeoutPayload, parentSessionId || task.parentSessionId);
|
|
369
371
|
} else {
|
|
@@ -373,10 +375,9 @@ class BackgroundTaskManager {
|
|
|
373
375
|
subSessionId: task.subSessionId,
|
|
374
376
|
parentSessionId: parentSessionId || task.parentSessionId,
|
|
375
377
|
status: "failed",
|
|
376
|
-
description: task.description,
|
|
377
378
|
error: errorMessage,
|
|
378
379
|
executionTimeMs,
|
|
379
|
-
associatedTaskId: task.
|
|
380
|
+
associatedTaskId: task.associatedTaskId
|
|
380
381
|
};
|
|
381
382
|
this.publishBackgroundEvent(BackgroundTaskEventTypes.FAILED, failedPayload, parentSessionId || task.parentSessionId);
|
|
382
383
|
}
|
|
@@ -453,7 +454,8 @@ ${prompt}
|
|
|
453
454
|
## 执行规范
|
|
454
455
|
- 使用可用工具完成任务
|
|
455
456
|
- 返回清晰的任务执行结果摘要
|
|
456
|
-
- 适时调用 task_operation_create
|
|
457
|
+
- 适时调用 task_operation_create 记录进展
|
|
458
|
+
- 如果你通过 task_create 创建了任务,请在最终响应中明确报告 task_id(例如:Task #627)`;
|
|
457
459
|
if (!agentComponent) {
|
|
458
460
|
throw new Error("AgentComponent not found");
|
|
459
461
|
}
|
|
@@ -471,15 +473,26 @@ ${prompt}
|
|
|
471
473
|
return new Promise((resolve, reject) => {
|
|
472
474
|
const timer = setTimeout(() => {
|
|
473
475
|
reject(new Error(`Task execution timeout after ${timeoutMs}ms`));
|
|
476
|
+
try {
|
|
477
|
+
agentComponent?.abort?.(subagentType);
|
|
478
|
+
} catch {}
|
|
474
479
|
}, timeoutMs);
|
|
475
480
|
signal?.addEventListener("abort", () => {
|
|
476
481
|
clearTimeout(timer);
|
|
482
|
+
try {
|
|
483
|
+
const env = this.env;
|
|
484
|
+
const agentComp = env?.getComponent?.("agent");
|
|
485
|
+
if (agentComp?.abort) {
|
|
486
|
+
agentComp.abort(subagentType);
|
|
487
|
+
}
|
|
488
|
+
} catch {}
|
|
477
489
|
reject(new Error("Task execution stopped"));
|
|
478
490
|
});
|
|
479
491
|
this.env.handle_query?.(delegateQuery, {
|
|
480
492
|
sessionId,
|
|
481
493
|
deniedTools: deniedTools.length > 0 ? deniedTools : undefined,
|
|
482
|
-
agentType: subagentType
|
|
494
|
+
agentType: subagentType,
|
|
495
|
+
abort: signal
|
|
483
496
|
})?.then((result) => {
|
|
484
497
|
clearTimeout(timer);
|
|
485
498
|
resolve(result);
|
|
@@ -512,7 +525,7 @@ ${prompt}
|
|
|
512
525
|
description: task.description,
|
|
513
526
|
error: "Task stopped by user",
|
|
514
527
|
executionTimeMs: task.startedAt ? task.completedAt - task.startedAt : 0,
|
|
515
|
-
associatedTaskId: task.
|
|
528
|
+
associatedTaskId: task.associatedTaskId
|
|
516
529
|
};
|
|
517
530
|
this.publishBackgroundEvent(BackgroundTaskEventTypes.STOPPED, stoppedPayload, task.parentSessionId);
|
|
518
531
|
return { success: true, task, message: "Task has been stopped" };
|
|
@@ -554,7 +567,8 @@ function getAgentRegistry(taskComponent) {
|
|
|
554
567
|
}
|
|
555
568
|
function createDelegateTool(taskComponent) {
|
|
556
569
|
const env = taskComponent.env;
|
|
557
|
-
const
|
|
570
|
+
const existingManager = taskComponent.backgroundTaskManager;
|
|
571
|
+
const backgroundTaskManager = existingManager ?? new BackgroundTaskManager(env);
|
|
558
572
|
const registry = getAgentRegistry(taskComponent);
|
|
559
573
|
taskComponent._backgroundTaskManager = backgroundTaskManager;
|
|
560
574
|
const tool = {
|
|
@@ -569,26 +583,35 @@ When using the delegate_task tool, you must specify a subagent_type parameter to
|
|
|
569
583
|
## When to use delegate_task:
|
|
570
584
|
- When you need to perform complex, multi-step tasks that require independent execution
|
|
571
585
|
- When you need to explore a codebase thoroughly (use "explore" subagent)
|
|
572
|
-
- When you need to run long-running tasks without blocking the main agent
|
|
586
|
+
- When you need to run long-running tasks without blocking the main agent
|
|
587
|
+
|
|
588
|
+
## How it works:
|
|
589
|
+
This tool **always runs in background mode**. It returns immediately with:
|
|
590
|
+
- **bgProcessId**: Internal background process ID (use with \`stop_task\` to cancel, different from Task #)
|
|
591
|
+
- **subSessionId**: Sub-agent session ID (use with \`session_get\` to see full execution log, always retained)
|
|
592
|
+
|
|
593
|
+
**After delegating, just WAIT for the notification.** The background process will automatically notify you when:
|
|
594
|
+
- ✅ **completed** — with \`bgprocess:\` + \`Task #\` (if it created a task) + result summary
|
|
595
|
+
- ⏱️ **timeout** — with \`bgprocess:\` + \`Task #\` (if available)
|
|
596
|
+
- ❌ **failed** — with \`bgprocess:\` + \`Task #\` + error details
|
|
597
|
+
- \uD83D\uDED1 **stopped** — with \`bgprocess:\` + \`Task #\`
|
|
598
|
+
|
|
599
|
+
The sub-agent runs independently and creates its own tasks via \`task_create\`.
|
|
600
|
+
No need to poll — just wait for the notification and use \`task_get\` with the Task # reported in it.
|
|
573
601
|
|
|
574
602
|
## Parameters:
|
|
575
603
|
- **description**: A short (3-5 words) description of the task
|
|
576
604
|
- **prompt**: The task for the agent to perform
|
|
577
605
|
- **subagent_type**: The type of specialized agent to use (e.g., "general", "explore")
|
|
578
|
-
- **
|
|
579
|
-
- **
|
|
580
|
-
- **task_id**: Optional task ID to associate with this delegate task
|
|
581
|
-
|
|
582
|
-
## Synchronous vs Background mode:
|
|
583
|
-
**Synchronous mode (default)**: Waits for subagent to complete and returns result directly
|
|
584
|
-
**Background mode (background=true)**: Returns immediately with "accepted" status, runs independently`,
|
|
606
|
+
- **timeout**: Task timeout in milliseconds (optional, default 30 minutes)
|
|
607
|
+
- **reason**: Brief reason for calling this tool (optional)`,
|
|
585
608
|
parameters: DelegateToolParameters,
|
|
586
609
|
execute: async (args, ctx) => {
|
|
587
610
|
const startTime = Date.now();
|
|
588
611
|
const params = DelegateToolParameters.parse(args);
|
|
589
|
-
const { description, prompt, subagent_type = "general",
|
|
612
|
+
const { description, prompt, subagent_type = "general", timeout, reason } = params;
|
|
590
613
|
const parentSessionId = ctx.session_id || "default";
|
|
591
|
-
logger.info(`[delegate_task] Called: description=${description}, subagent_type=${subagent_type}
|
|
614
|
+
logger.info(`[delegate_task] Called: description=${description}, subagent_type=${subagent_type}`);
|
|
592
615
|
const registry2 = getAgentRegistry(taskComponent);
|
|
593
616
|
if (!isKnownSubagentType(subagent_type, registry2)) {
|
|
594
617
|
return {
|
|
@@ -601,12 +624,9 @@ When using the delegate_task tool, you must specify a subagent_type parameter to
|
|
|
601
624
|
const tagService = taskComponent.getTagService();
|
|
602
625
|
let promptWithTaskInfo = prompt;
|
|
603
626
|
const delegateCtx = {
|
|
604
|
-
taskId: task_id,
|
|
605
627
|
prompt: promptWithTaskInfo,
|
|
606
628
|
subagentType: subagent_type,
|
|
607
|
-
background,
|
|
608
629
|
timeout,
|
|
609
|
-
cleanup,
|
|
610
630
|
reason,
|
|
611
631
|
tagService
|
|
612
632
|
};
|
|
@@ -619,212 +639,31 @@ When using the delegate_task tool, you must specify a subagent_type parameter to
|
|
|
619
639
|
};
|
|
620
640
|
await globalHookManager.execute(TaskHookPoints.DELEGATE_BEFORE, hookCtx, { sessionId: parentSessionId });
|
|
621
641
|
promptWithTaskInfo = delegateCtx.prompt;
|
|
622
|
-
|
|
623
|
-
return await handleBackgroundTask(taskComponent, backgroundTaskManager, parentSessionId, description, promptWithTaskInfo, delegateCtx.subagentType, delegateCtx.timeout, delegateCtx.cleanup, delegateCtx.taskId);
|
|
624
|
-
} else {
|
|
625
|
-
return await handleSyncTask(taskComponent, parentSessionId, description, promptWithTaskInfo, delegateCtx.subagentType, delegateCtx.timeout, delegateCtx.taskId);
|
|
626
|
-
}
|
|
642
|
+
return await handleBackgroundTask(backgroundTaskManager, parentSessionId, description, promptWithTaskInfo, delegateCtx.subagentType, delegateCtx.timeout);
|
|
627
643
|
}
|
|
628
644
|
};
|
|
629
645
|
return tool;
|
|
630
646
|
}
|
|
631
|
-
async function
|
|
647
|
+
async function handleBackgroundTask(backgroundTaskManager, parentSessionId, description, prompt, subagentType, timeout) {
|
|
632
648
|
const startTime = Date.now();
|
|
633
649
|
try {
|
|
634
|
-
const
|
|
635
|
-
if (!sessionComponent) {
|
|
636
|
-
return {
|
|
637
|
-
success: false,
|
|
638
|
-
output: "",
|
|
639
|
-
error: "SessionComponent not found",
|
|
640
|
-
metadata: { execution_time_ms: Date.now() - startTime }
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
const parentSession = await sessionComponent.get(parentSessionId);
|
|
644
|
-
if (!parentSession) {
|
|
645
|
-
return {
|
|
646
|
-
success: false,
|
|
647
|
-
output: "",
|
|
648
|
-
error: `Parent session not found: ${parentSessionId}`,
|
|
649
|
-
metadata: { execution_time_ms: Date.now() - startTime }
|
|
650
|
-
};
|
|
651
|
-
}
|
|
652
|
-
const metadata = {
|
|
653
|
-
subagent_type: subagentType,
|
|
654
|
-
created_by: "subagent",
|
|
655
|
-
task_description: description
|
|
656
|
-
};
|
|
657
|
-
if (taskId) {
|
|
658
|
-
metadata.task_id = taskId;
|
|
659
|
-
}
|
|
660
|
-
const subSession = await sessionComponent.create({
|
|
661
|
-
parentID: parentSessionId,
|
|
662
|
-
title: `${description} (@${subagentType} subagent)`,
|
|
663
|
-
metadata
|
|
664
|
-
});
|
|
665
|
-
if (!subSession) {
|
|
666
|
-
return {
|
|
667
|
-
success: false,
|
|
668
|
-
output: "",
|
|
669
|
-
error: "Failed to create sub-session",
|
|
670
|
-
metadata: { execution_time_ms: Date.now() - startTime }
|
|
671
|
-
};
|
|
672
|
-
}
|
|
673
|
-
const agentComponent = taskComponent.env?.getComponent?.("agent");
|
|
674
|
-
const registry = getAgentRegistry(taskComponent);
|
|
675
|
-
const resolved = await resolveSubAgentConfig(subagentType, { registry });
|
|
676
|
-
const subAgent = getSubAgentSpec(subagentType);
|
|
677
|
-
let basePrompt = resolved?.basePrompt || subAgent?.promptOverride || `You are a subagent. Complete this task: {task_description}`;
|
|
678
|
-
const deniedTools = resolved?.deniedTools || subAgent?.deniedTools || [];
|
|
679
|
-
const allowedTools = resolved?.allowedTools || subAgent?.allowedTools;
|
|
680
|
-
let fullPrompt = basePrompt.replace(/{task_description}/g, description || "N/A");
|
|
681
|
-
fullPrompt += `
|
|
682
|
-
|
|
683
|
-
---
|
|
684
|
-
|
|
685
|
-
# Session Info
|
|
686
|
-
- task_id: ${taskId || "N/A"}
|
|
687
|
-
- session_id: ${subSession.id}
|
|
688
|
-
|
|
689
|
-
---
|
|
690
|
-
|
|
691
|
-
## 用户指令
|
|
692
|
-
${prompt}
|
|
693
|
-
|
|
694
|
-
---
|
|
695
|
-
|
|
696
|
-
## 执行规范
|
|
697
|
-
- 使用可用工具完成任务
|
|
698
|
-
- 返回清晰的任务执行结果摘要
|
|
699
|
-
- 适时调用 task_operation_create 记录进展`;
|
|
700
|
-
if (!agentComponent) {
|
|
701
|
-
return {
|
|
702
|
-
success: false,
|
|
703
|
-
output: "",
|
|
704
|
-
error: "AgentComponent not found",
|
|
705
|
-
metadata: { execution_time_ms: Date.now() - startTime }
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
const subAgentForRegister = subAgent ? { ...subAgent, allowedTools } : allowedTools ? {
|
|
709
|
-
id: subagentType,
|
|
710
|
-
name: subagentType,
|
|
711
|
-
mode: "subagent",
|
|
712
|
-
description: resolved?.description || "Custom agent",
|
|
713
|
-
allowedTools,
|
|
714
|
-
deniedTools
|
|
715
|
-
} : undefined;
|
|
716
|
-
ensureSubAgentRegistered(agentComponent, subagentType, basePrompt, subAgentForRegister, deniedTools);
|
|
717
|
-
const isWorkflowAgent = registry?.get(subagentType)?.type === "workflow";
|
|
718
|
-
const delegateQuery = isWorkflowAgent ? prompt : fullPrompt;
|
|
719
|
-
const timeoutMs = timeout || DEFAULT_TIMEOUT;
|
|
720
|
-
let result;
|
|
721
|
-
try {
|
|
722
|
-
result = await Promise.race([
|
|
723
|
-
taskComponent.env?.handle_query?.(delegateQuery, {
|
|
724
|
-
sessionId: subSession.id,
|
|
725
|
-
deniedTools: deniedTools.length > 0 ? deniedTools : undefined,
|
|
726
|
-
agentType: subagentType
|
|
727
|
-
}),
|
|
728
|
-
new Promise((_, reject) => setTimeout(() => reject(new Error(`Task execution timeout after ${timeoutMs}ms`)), timeoutMs))
|
|
729
|
-
]);
|
|
730
|
-
} catch (error) {
|
|
731
|
-
result = error instanceof Error ? error.message : String(error);
|
|
732
|
-
}
|
|
733
|
-
await sessionComponent.addMessage(subSession.id, {
|
|
734
|
-
role: "assistant",
|
|
735
|
-
content: result
|
|
736
|
-
});
|
|
737
|
-
let taskNotification = "";
|
|
738
|
-
if (taskId) {
|
|
739
|
-
taskNotification = `
|
|
740
|
-
|
|
741
|
-
---
|
|
742
|
-
\uD83D\uDCCB [委托任务完成] 已委托子智能体完成 Task #${taskId} 的处理工作,请知悉。可通过 task_get #${taskId} 查看最新状态。`;
|
|
743
|
-
}
|
|
744
|
-
setCurrentTaskId(undefined);
|
|
745
|
-
logger.info(`[delegate_task.sync] Task completed, currentTaskId cleared from EnvContext${taskId ? ` (was: #${taskId})` : ""}`);
|
|
746
|
-
return {
|
|
747
|
-
success: true,
|
|
748
|
-
output: result + taskNotification + `
|
|
749
|
-
|
|
750
|
-
` + [
|
|
751
|
-
"<task_metadata>",
|
|
752
|
-
`session_id: ${subSession.id}`,
|
|
753
|
-
`subagent_type: ${subagentType}`,
|
|
754
|
-
"</task_metadata>"
|
|
755
|
-
].join(`
|
|
756
|
-
`),
|
|
757
|
-
metadata: {
|
|
758
|
-
execution_time_ms: Date.now() - startTime,
|
|
759
|
-
sessionId: subSession.id
|
|
760
|
-
}
|
|
761
|
-
};
|
|
762
|
-
} catch (error) {
|
|
763
|
-
setCurrentTaskId(undefined);
|
|
764
|
-
logger.info(`[delegate_task.sync] Error occurred, currentTaskId cleared from EnvContext${taskId ? ` (was: #${taskId})` : ""}`);
|
|
765
|
-
return {
|
|
766
|
-
success: false,
|
|
767
|
-
output: "",
|
|
768
|
-
error: error instanceof Error ? error.message : String(error),
|
|
769
|
-
metadata: { execution_time_ms: Date.now() - startTime }
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
async function handleBackgroundTask(taskComponent, backgroundTaskManager, parentSessionId, description, prompt, subagentType, timeout, cleanup, taskId) {
|
|
774
|
-
const startTime = Date.now();
|
|
775
|
-
try {
|
|
776
|
-
let associatedTaskId = taskId;
|
|
777
|
-
if (!associatedTaskId) {
|
|
778
|
-
const newTask = await taskComponent.createTask({
|
|
779
|
-
title: description,
|
|
780
|
-
description: `Background task delegated to ${subagentType} subagent`,
|
|
781
|
-
priority: "medium",
|
|
782
|
-
goals_and_expected_deliverables: prompt,
|
|
783
|
-
sessionId: parentSessionId,
|
|
784
|
-
project_path: "unknown",
|
|
785
|
-
context: "unknown"
|
|
786
|
-
});
|
|
787
|
-
associatedTaskId = newTask.id;
|
|
788
|
-
await taskComponent.createOperation({
|
|
789
|
-
taskId: associatedTaskId,
|
|
790
|
-
sessionId: parentSessionId,
|
|
791
|
-
actionType: "create",
|
|
792
|
-
actionTitle: `Delegated to ${subagentType} subagent`,
|
|
793
|
-
actionDescription: `Background task started: ${description}`
|
|
794
|
-
});
|
|
795
|
-
} else {
|
|
796
|
-
await taskComponent.updateTask(associatedTaskId, {
|
|
797
|
-
status: "active",
|
|
798
|
-
current_status: `Running ${subagentType} subagent`
|
|
799
|
-
});
|
|
800
|
-
await taskComponent.createOperation({
|
|
801
|
-
taskId: associatedTaskId,
|
|
802
|
-
sessionId: parentSessionId,
|
|
803
|
-
actionType: "progress",
|
|
804
|
-
actionTitle: `Started ${subagentType} subagent`,
|
|
805
|
-
actionDescription: `Background task: ${description}`
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
const { taskId: bgTaskId, subSessionId } = await backgroundTaskManager.createTask({
|
|
650
|
+
const { taskId: bgProcessId, subSessionId } = await backgroundTaskManager.createTask({
|
|
809
651
|
parentSessionId,
|
|
810
652
|
description,
|
|
811
653
|
prompt,
|
|
812
654
|
subagentType,
|
|
813
|
-
timeout
|
|
814
|
-
cleanup,
|
|
815
|
-
taskId: associatedTaskId
|
|
655
|
+
timeout
|
|
816
656
|
});
|
|
817
657
|
const output = [
|
|
818
658
|
`✅ Background task accepted`,
|
|
819
659
|
"",
|
|
820
|
-
`\uD83D\uDCCB
|
|
660
|
+
`\uD83D\uDCCB Process ID: ${bgProcessId}`,
|
|
821
661
|
`\uD83D\uDCDD Description: ${description}`,
|
|
822
662
|
`\uD83E\uDD16 Sub-agent: ${subagentType}`,
|
|
823
|
-
associatedTaskId ? `\uD83D\uDCCC Associated Task: #${associatedTaskId}` : "",
|
|
824
663
|
`⏱️ Timeout: ${(timeout || DEFAULT_TIMEOUT) / 1000}s`,
|
|
825
664
|
"",
|
|
826
|
-
`Use stop_task with task_id="${
|
|
827
|
-
].
|
|
665
|
+
`Use stop_task with task_id="${bgProcessId}" to cancel this task.`
|
|
666
|
+
].join(`
|
|
828
667
|
`);
|
|
829
668
|
return {
|
|
830
669
|
success: true,
|
|
@@ -834,8 +673,7 @@ async function handleBackgroundTask(taskComponent, backgroundTaskManager, parent
|
|
|
834
673
|
sessionId: subSessionId,
|
|
835
674
|
background: true,
|
|
836
675
|
status: "accepted",
|
|
837
|
-
|
|
838
|
-
bgTaskId
|
|
676
|
+
bgProcessId
|
|
839
677
|
}
|
|
840
678
|
};
|
|
841
679
|
} catch (error) {
|
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
BackgroundTaskManager,
|
|
6
6
|
createDelegateTool,
|
|
7
7
|
createStopTool
|
|
8
|
-
} from "./roy-agent-core-
|
|
8
|
+
} from "./roy-agent-core-48jprgqk.js";
|
|
9
9
|
import {
|
|
10
10
|
SQLiteTaskStore,
|
|
11
11
|
getDefaultTaskDbPath
|
|
12
|
-
} from "./roy-agent-core-
|
|
12
|
+
} from "./roy-agent-core-w4f871e2.js";
|
|
13
13
|
import {
|
|
14
14
|
completeTaskTool,
|
|
15
15
|
createTaskTool,
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
getTaskTool,
|
|
18
18
|
listTasksTool,
|
|
19
19
|
updateTaskTool
|
|
20
|
-
} from "./roy-agent-core-
|
|
20
|
+
} from "./roy-agent-core-e1704378.js";
|
|
21
21
|
import {
|
|
22
22
|
createOperationTool,
|
|
23
23
|
deleteOperationTool,
|
|
@@ -33,19 +33,19 @@ import {
|
|
|
33
33
|
} from "./roy-agent-core-qxhq8ven.js";
|
|
34
34
|
import {
|
|
35
35
|
BaseComponent
|
|
36
|
-
} from "./roy-agent-core-
|
|
36
|
+
} from "./roy-agent-core-rgckng3p.js";
|
|
37
37
|
import {
|
|
38
38
|
globalHookManager,
|
|
39
39
|
init_global_hook_manager
|
|
40
|
-
} from "./roy-agent-core-
|
|
40
|
+
} from "./roy-agent-core-7tp56w6n.js";
|
|
41
41
|
import {
|
|
42
42
|
TracedAs,
|
|
43
43
|
init_decorator
|
|
44
|
-
} from "./roy-agent-core-
|
|
44
|
+
} from "./roy-agent-core-k05v31rc.js";
|
|
45
45
|
import {
|
|
46
46
|
createLogger,
|
|
47
47
|
init_logger
|
|
48
|
-
} from "./roy-agent-core-
|
|
48
|
+
} from "./roy-agent-core-shme7set.js";
|
|
49
49
|
import {
|
|
50
50
|
__legacyDecorateClassTS
|
|
51
51
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
@@ -4,23 +4,23 @@ import {
|
|
|
4
4
|
} from "./roy-agent-core-ctdhjv68.js";
|
|
5
5
|
import {
|
|
6
6
|
BaseComponent
|
|
7
|
-
} from "./roy-agent-core-
|
|
7
|
+
} from "./roy-agent-core-rgckng3p.js";
|
|
8
8
|
import {
|
|
9
9
|
init_context
|
|
10
|
-
} from "./roy-agent-core-
|
|
10
|
+
} from "./roy-agent-core-qg4rma4c.js";
|
|
11
11
|
import {
|
|
12
12
|
getEnvContext,
|
|
13
13
|
init_env_context,
|
|
14
14
|
runWithEnvContextAsync
|
|
15
|
-
} from "./roy-agent-core-
|
|
15
|
+
} from "./roy-agent-core-y5d04fm3.js";
|
|
16
16
|
import {
|
|
17
17
|
TracedAs,
|
|
18
18
|
init_decorator
|
|
19
|
-
} from "./roy-agent-core-
|
|
19
|
+
} from "./roy-agent-core-k05v31rc.js";
|
|
20
20
|
import {
|
|
21
21
|
createLogger,
|
|
22
22
|
init_logger
|
|
23
|
-
} from "./roy-agent-core-
|
|
23
|
+
} from "./roy-agent-core-shme7set.js";
|
|
24
24
|
import {
|
|
25
25
|
__legacyDecorateClassTS
|
|
26
26
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
@@ -11,15 +11,15 @@ import {
|
|
|
11
11
|
import {
|
|
12
12
|
globalHookManager,
|
|
13
13
|
init_global_hook_manager
|
|
14
|
-
} from "./roy-agent-core-
|
|
14
|
+
} from "./roy-agent-core-7tp56w6n.js";
|
|
15
15
|
import {
|
|
16
16
|
init_decorator,
|
|
17
17
|
wrapFunction
|
|
18
|
-
} from "./roy-agent-core-
|
|
18
|
+
} from "./roy-agent-core-k05v31rc.js";
|
|
19
19
|
import {
|
|
20
20
|
createLogger,
|
|
21
21
|
init_logger
|
|
22
|
-
} from "./roy-agent-core-
|
|
22
|
+
} from "./roy-agent-core-shme7set.js";
|
|
23
23
|
import {
|
|
24
24
|
__esm
|
|
25
25
|
} from "./roy-agent-core-fs0mn2jk.js";
|