@ai-setting/roy-agent-core 1.5.62 → 1.5.64

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/env/index.js CHANGED
@@ -43,9 +43,9 @@ import"../shared/@ai-setting/roy-agent-core-ecaptews.js";
43
43
  import"../shared/@ai-setting/roy-agent-core-e25xkv53.js";
44
44
  import {
45
45
  TaskComponent
46
- } from "../shared/@ai-setting/roy-agent-core-wqzkxab9.js";
46
+ } from "../shared/@ai-setting/roy-agent-core-z2fxjh6k.js";
47
47
  import"../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
48
- import"../shared/@ai-setting/roy-agent-core-dkevkmas.js";
48
+ import"../shared/@ai-setting/roy-agent-core-eq52jra7.js";
49
49
  import"../shared/@ai-setting/roy-agent-core-cgq7btak.js";
50
50
  import"../shared/@ai-setting/roy-agent-core-nx3c3ce2.js";
51
51
  import {
@@ -3,7 +3,7 @@ import {
3
3
  PromptConfigSchema,
4
4
  PromptPathSchema,
5
5
  PromptRenderer
6
- } from "../../shared/@ai-setting/roy-agent-core-8am1xdvb.js";
6
+ } from "../../shared/@ai-setting/roy-agent-core-hfc3hzcj.js";
7
7
  import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
8
8
  import"../../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
9
9
  import"../../shared/@ai-setting/roy-agent-core-rgckng3p.js";
@@ -3,7 +3,7 @@ import {
3
3
  BackgroundTaskManager,
4
4
  createDelegateTool,
5
5
  createStopTool
6
- } from "../../../shared/@ai-setting/roy-agent-core-dkevkmas.js";
6
+ } from "../../../shared/@ai-setting/roy-agent-core-eq52jra7.js";
7
7
  import"../../../shared/@ai-setting/roy-agent-core-nx3c3ce2.js";
8
8
  import"../../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
9
9
  import"../../../shared/@ai-setting/roy-agent-core-92z6t4he.js";
@@ -5,11 +5,11 @@ import {
5
5
  TaskPriorityEnum,
6
6
  TaskStatusEnum,
7
7
  TaskTypeEnum
8
- } from "../../shared/@ai-setting/roy-agent-core-wqzkxab9.js";
8
+ } from "../../shared/@ai-setting/roy-agent-core-z2fxjh6k.js";
9
9
  import {
10
10
  TaskEntityEventTypes
11
11
  } from "../../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
12
- import"../../shared/@ai-setting/roy-agent-core-dkevkmas.js";
12
+ import"../../shared/@ai-setting/roy-agent-core-eq52jra7.js";
13
13
  import {
14
14
  SQLiteTaskStore,
15
15
  getDefaultTaskDbPath
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  PromptStore,
4
4
  getBuiltInPrompt,
5
5
  getBuiltInPromptNames
6
- } from "./shared/@ai-setting/roy-agent-core-8am1xdvb.js";
6
+ } from "./shared/@ai-setting/roy-agent-core-hfc3hzcj.js";
7
7
  import {
8
8
  LLMComponent,
9
9
  LLMConfigSchema,
@@ -128,9 +128,9 @@ import {
128
128
  } from "./shared/@ai-setting/roy-agent-core-e25xkv53.js";
129
129
  import {
130
130
  TaskComponent
131
- } from "./shared/@ai-setting/roy-agent-core-wqzkxab9.js";
131
+ } from "./shared/@ai-setting/roy-agent-core-z2fxjh6k.js";
132
132
  import"./shared/@ai-setting/roy-agent-core-8gxth0eh.js";
133
- import"./shared/@ai-setting/roy-agent-core-dkevkmas.js";
133
+ import"./shared/@ai-setting/roy-agent-core-eq52jra7.js";
134
134
  import {
135
135
  SQLiteTaskStore,
136
136
  getDefaultTaskDbPath
@@ -208,7 +208,8 @@ var DelegateToolParameters = z.object({
208
208
  prompt: z.string().describe("The task for the agent to perform"),
209
209
  subagent_type: z.string().describe("The type of specialized agent to use for this task").default("general"),
210
210
  timeout: z.number().describe("Task timeout in milliseconds. Default: 1800000 (30 minutes). If set, task will be terminated after timeout.").optional(),
211
- reason: z.string().describe("Brief reason for calling this tool (max 30 chars, e.g., 'Delegate refactor task')").optional()
211
+ reason: z.string().describe("Brief reason for calling this tool (max 30 chars, e.g., 'Delegate refactor task')").optional(),
212
+ similar_task_ids: z.array(z.number()).max(3).describe("Similar task IDs (max 3) to reference for improving task execution. Search for similar tasks before calling this tool.")
212
213
  });
213
214
  var DEFAULT_TIMEOUT = 1800000;
214
215
  var PROGRESS_INTERVAL = 120000;
@@ -238,7 +239,7 @@ class BackgroundTaskManager {
238
239
  }
239
240
  }
240
241
  async createTask(options) {
241
- const { parentSessionId, description, prompt, subagentType, timeout } = options;
242
+ const { parentSessionId, description, prompt, subagentType, timeout, similarTaskIds } = options;
242
243
  const taskIdGen = `process_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;
243
244
  const sessionComponent = this.getSessionComponent();
244
245
  if (!sessionComponent) {
@@ -269,7 +270,8 @@ class BackgroundTaskManager {
269
270
  subagentType,
270
271
  status: "pending",
271
272
  createdAt: Date.now(),
272
- abortController
273
+ abortController,
274
+ similarTaskIds
273
275
  };
274
276
  this.tasks.set(taskIdGen, task);
275
277
  this.abortControllers.set(taskIdGen, abortController);
@@ -306,7 +308,7 @@ class BackgroundTaskManager {
306
308
  if (!subSession) {
307
309
  throw new Error(`Sub session not found: ${task.subSessionId}`);
308
310
  }
309
- const result = await this.executeWithAbort(subSession, prompt, timeoutMs, abortController?.signal);
311
+ const result = await this.executeWithAbort(subSession, prompt, timeoutMs, abortController?.signal, task.similarTaskIds);
310
312
  if (abortController?.signal.aborted) {
311
313
  logger.info(`[BackgroundTaskManager] Task was aborted`, { taskId });
312
314
  return;
@@ -427,7 +429,7 @@ class BackgroundTaskManager {
427
429
  this.progressTimers.delete(taskId);
428
430
  }
429
431
  }
430
- async executeWithAbort(subSession, prompt, timeoutMs, signal) {
432
+ async executeWithAbort(subSession, prompt, timeoutMs, signal, similarTaskIds) {
431
433
  const metadata = subSession.info?.metadata || {};
432
434
  const taskId = metadata.task_id;
433
435
  const taskDescription = metadata.task_description || "";
@@ -461,6 +463,67 @@ ${prompt}
461
463
  - 返回清晰的任务执行结果摘要
462
464
  - 适时调用 task_operation_create 记录进展
463
465
  - 如果你通过 task_create 创建了任务,请在最终响应中明确报告 task_id(例如:Task #627)`;
466
+ if (similarTaskIds && similarTaskIds.length > 0) {
467
+ try {
468
+ const taskComponent = this.env?.getComponent?.("task");
469
+ if (taskComponent) {
470
+ const similarTasksSections = [];
471
+ for (const similarId of similarTaskIds) {
472
+ try {
473
+ const similarTask = await taskComponent.getTask(similarId);
474
+ if (!similarTask) {
475
+ logger.warn(`[delegate] Similar task #${similarId} not found, skipping`);
476
+ continue;
477
+ }
478
+ const operations = await taskComponent.listOperations({ taskId: similarId, limit: 10 });
479
+ let section = `### Task #${similarTask.id}: ${similarTask.title}
480
+ `;
481
+ section += `- Status: ${similarTask.status}
482
+ `;
483
+ if (similarTask.description) {
484
+ section += `- Description: ${similarTask.description}
485
+ `;
486
+ }
487
+ if (similarTask.goals_and_expected_deliverables) {
488
+ section += `- Goals: ${similarTask.goals_and_expected_deliverables}
489
+ `;
490
+ }
491
+ if (operations && operations.length > 0) {
492
+ section += `- Recent Operations:
493
+ `;
494
+ for (const op of operations) {
495
+ section += ` - [${op.actionType}] ${op.actionTitle}: ${op.actionDescription || ""}
496
+ `;
497
+ }
498
+ }
499
+ similarTasksSections.push(section);
500
+ } catch (err) {
501
+ logger.warn(`[delegate] Failed to fetch similar task #${similarId}`, { error: err instanceof Error ? err.message : String(err) });
502
+ }
503
+ }
504
+ if (similarTasksSections.length > 0) {
505
+ fullPrompt += `
506
+
507
+ ---
508
+
509
+ ## Similar Tasks Reference
510
+
511
+ The following similar tasks and their operation records can serve as reference:
512
+
513
+ `;
514
+ fullPrompt += similarTasksSections.join(`
515
+ `);
516
+ fullPrompt += `
517
+
518
+ ---
519
+
520
+ Use these as guidance to improve task execution efficiency.`;
521
+ }
522
+ }
523
+ } catch (err) {
524
+ logger.warn(`[delegate] Failed to inject similar tasks reference`, { error: err instanceof Error ? err.message : String(err) });
525
+ }
526
+ }
464
527
  if (!agentComponent) {
465
528
  throw new Error("AgentComponent not found");
466
529
  }
@@ -609,12 +672,13 @@ No need to poll — just wait for the notification and use \`task_get\` with the
609
672
  - **prompt**: The task for the agent to perform
610
673
  - **subagent_type**: The type of specialized agent to use (e.g., "general", "explore")
611
674
  - **timeout**: Task timeout in milliseconds (optional, default 30 minutes)
612
- - **reason**: Brief reason for calling this tool (optional)`,
675
+ - **reason**: Brief reason for calling this tool (optional)
676
+ - **similar_task_ids**: Similar task IDs (max 3) to reference for improving sub-agent execution efficiency. Search for similar tasks using \`task_search\` or \`task_list\` before calling this tool.`,
613
677
  parameters: DelegateToolParameters,
614
678
  execute: async (args, ctx) => {
615
679
  const startTime = Date.now();
616
680
  const params = DelegateToolParameters.parse(args);
617
- const { description, prompt, subagent_type = "general", timeout, reason } = params;
681
+ const { description, prompt, subagent_type = "general", timeout, reason, similar_task_ids } = params;
618
682
  const parentSessionId = ctx.session_id || "default";
619
683
  logger.info(`[delegate_task] Called: description=${description}, subagent_type=${subagent_type}`);
620
684
  const registry2 = getAgentRegistry(taskComponent);
@@ -644,12 +708,12 @@ No need to poll — just wait for the notification and use \`task_get\` with the
644
708
  };
645
709
  await globalHookManager.execute(TaskHookPoints.DELEGATE_BEFORE, delegateCtx, { sessionId: parentSessionId });
646
710
  promptWithTaskInfo = delegateCtx.prompt;
647
- return await handleBackgroundTask(backgroundTaskManager, parentSessionId, description, promptWithTaskInfo, delegateCtx.subagentType, delegateCtx.timeout);
711
+ return await handleBackgroundTask(backgroundTaskManager, parentSessionId, description, promptWithTaskInfo, delegateCtx.subagentType, delegateCtx.timeout, similar_task_ids);
648
712
  }
649
713
  };
650
714
  return tool;
651
715
  }
652
- async function handleBackgroundTask(backgroundTaskManager, parentSessionId, description, prompt, subagentType, timeout) {
716
+ async function handleBackgroundTask(backgroundTaskManager, parentSessionId, description, prompt, subagentType, timeout, similarTaskIds) {
653
717
  const startTime = Date.now();
654
718
  try {
655
719
  const { taskId: bgProcessId, subSessionId } = await backgroundTaskManager.createTask({
@@ -657,7 +721,8 @@ async function handleBackgroundTask(backgroundTaskManager, parentSessionId, desc
657
721
  description,
658
722
  prompt,
659
723
  subagentType,
660
- timeout
724
+ timeout,
725
+ similarTaskIds
661
726
  });
662
727
  const output = [
663
728
  `✅ Background task accepted`,
@@ -130,6 +130,8 @@ var builtInPrompts = {
130
130
 
131
131
  **\`delegate_task\`** — 这是你的**主要执行工具**。用于一切复杂、多步骤、需要读文件、运行命令、代码分析、搜索、实现功能等场景。**当不确定用哪个时,选 \`delegate_task\`。**
132
132
 
133
+ > **similar_task_ids 是必填参数**:每次调用 \`delegate_task\` 前,必须先使用 \`task_search\` 搜索与当前任务相似的历史任务,将找到的相似任务 ID 填入 \`similar_task_ids\` 参数(最多 3 个)。如果没有找到相似任务,传入空数组 \`similar_task_ids=[]\`。
134
+
133
135
  **\`bash\`** — **仅限**以下**一次性简单操作**:
134
136
  - 调用一行 \`roy-agent\` 命令(如 \`bun packages/cli/dist/bin/roy-agent.js tasks list\`)
135
137
  - 执行一个简单的 shell 命令(如 \`ls\`、\`echo hello\`)
@@ -184,7 +186,8 @@ delegate_task(
184
186
  prompt="详细说明。
185
187
 
186
188
  重要:遵循任务作为一等公民原则 — 使用 \`task_create\` 创建任务,使用 \`task_update\` 跟踪进度,使用 \`task_operation_create\` 记录里程碑,并使用 \`task_complete\` 完成任务。",
187
- subagent_type="roy"
189
+ subagent_type="roy",
190
+ similar_task_ids=[] // 必填:先使用 task_search 搜索相似任务,将找到的 ID 填入此处(最多 3 个)
188
191
  )
189
192
  \`\`\`
190
193
 
@@ -206,7 +209,8 @@ delegate_task(
206
209
  prompt="详细说明。
207
210
 
208
211
  重要:遵循任务作为一等公民原则 — 使用 \`task_create\` 创建任务,使用 \`task_update\` 跟踪进度,使用 \`task_operation_create\` 记录里程碑,并使用 \`task_complete\` 完成任务。",
209
- subagent_type="strict-task-agent"
212
+ subagent_type="strict-task-agent",
213
+ similar_task_ids=[] // 必填:先使用 task_search 搜索相似任务,将找到的 ID 填入此处(最多 3 个)
210
214
  )
211
215
  \`\`\`
212
216
 
@@ -215,7 +219,7 @@ delegate_task(
215
219
  1. **理解** — 用户到底想要什么?
216
220
  2. **分类** — 如果需要任何超出简单对话的操作 → 委托。如果是问候/一次性回答 → 直接回复。
217
221
  3. **选择智能体** — \`roy\`(默认)或 \`strict-task-agent\`(需要严格验证时)
218
- 4. **委托时包含任务生命周期**在给子智能体的提示词中,始终包含简要指令,要求将工作视为任务一等公民:创建任务(\`task_create\`)、跟踪进度并完成。
222
+ 4. **搜索相似任务并委托**在委托前,先使用 \`task_search\` 搜索与当前请求相关的历史任务,将找到的相似任务 ID 填入 \`similar_task_ids\` 参数。在给子智能体的提示词中,始终包含简要指令,要求将工作视为任务一等公民:创建任务(\`task_create\`)、跟踪进度并完成。
219
223
  5. **汇报结果** — 向用户总结结果
220
224
 
221
225
  ## 行为规则
@@ -5,7 +5,7 @@ import {
5
5
  BackgroundTaskManager,
6
6
  createDelegateTool,
7
7
  createStopTool
8
- } from "./roy-agent-core-dkevkmas.js";
8
+ } from "./roy-agent-core-eq52jra7.js";
9
9
  import {
10
10
  SQLiteTaskStore,
11
11
  getDefaultTaskDbPath
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.5.62",
3
+ "version": "1.5.64",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",