@ai-setting/roy-agent-core 1.5.80 → 1.5.83

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 (32) hide show
  1. package/dist/env/agent/index.js +2 -2
  2. package/dist/env/event-source/index.js +2 -2
  3. package/dist/env/index.js +14 -14
  4. package/dist/env/prompt/index.js +1 -1
  5. package/dist/env/task/delegate/index.js +2 -2
  6. package/dist/env/task/index.js +5 -5
  7. package/dist/env/task/plugins/index.js +1 -1
  8. package/dist/env/task/storage/index.js +1 -1
  9. package/dist/env/task/tools/index.js +1 -1
  10. package/dist/env/workflow/engine/index.js +3 -3
  11. package/dist/env/workflow/index.js +5 -5
  12. package/dist/env/workflow/nodes/index.js +1 -1
  13. package/dist/env/workflow/tools/index.js +26 -142
  14. package/dist/env/workflow/utils/index.js +1 -1
  15. package/dist/index.js +15 -15
  16. package/dist/shared/@ai-setting/{roy-agent-core-4ws3w7cx.js → roy-agent-core-015vw11k.js} +32 -3
  17. package/dist/shared/@ai-setting/{roy-agent-core-7mw366pc.js → roy-agent-core-67yzhmg2.js} +1 -1
  18. package/dist/shared/@ai-setting/{roy-agent-core-8x1gmqcv.js → roy-agent-core-68sef3es.js} +4 -6
  19. package/dist/shared/@ai-setting/{roy-agent-core-jazhr292.js → roy-agent-core-6b0r2e7j.js} +2 -2
  20. package/dist/shared/@ai-setting/{roy-agent-core-n9tw52zb.js → roy-agent-core-78yzt2bq.js} +40 -128
  21. package/dist/shared/@ai-setting/{roy-agent-core-7t0jen73.js → roy-agent-core-7nh5h9fn.js} +37 -4
  22. package/dist/shared/@ai-setting/roy-agent-core-a6j7g1qe.js +428 -0
  23. package/dist/shared/@ai-setting/{roy-agent-core-0tgnq4nz.js → roy-agent-core-f6p7wwpd.js} +64 -5
  24. package/dist/shared/@ai-setting/{roy-agent-core-99j4w3fx.js → roy-agent-core-gb9gbkc3.js} +2 -0
  25. package/dist/shared/@ai-setting/{roy-agent-core-ajx32wzj.js → roy-agent-core-j754zgb4.js} +13 -0
  26. package/dist/shared/@ai-setting/{roy-agent-core-zf62vkc4.js → roy-agent-core-mbre4fxg.js} +32 -1
  27. package/dist/shared/@ai-setting/{roy-agent-core-r9y8ct0w.js → roy-agent-core-pcdzfwdv.js} +4 -0
  28. package/dist/shared/@ai-setting/{roy-agent-core-11dnsfwp.js → roy-agent-core-qjv8537d.js} +3 -3
  29. package/dist/shared/@ai-setting/{roy-agent-core-s83ararq.js → roy-agent-core-v3t28k5n.js} +35 -3
  30. package/dist/shared/@ai-setting/{roy-agent-core-d32ecc9z.js → roy-agent-core-vcvgq9hy.js} +150 -1
  31. package/package.json +1 -1
  32. package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +0 -36
@@ -11,7 +11,7 @@ import {
11
11
  import {
12
12
  TemplateResolver,
13
13
  init_template_resolver
14
- } from "./roy-agent-core-99j4w3fx.js";
14
+ } from "./roy-agent-core-gb9gbkc3.js";
15
15
  import {
16
16
  SkillNode,
17
17
  ToolNode,
@@ -19,7 +19,7 @@ import {
19
19
  init_skill_node,
20
20
  init_tool_node,
21
21
  init_workflow_node
22
- } from "./roy-agent-core-ajx32wzj.js";
22
+ } from "./roy-agent-core-j754zgb4.js";
23
23
  import {
24
24
  WorkflowError,
25
25
  createWorkflowEvent,
@@ -393,65 +393,11 @@ init_logger();
393
393
  init_decorator();
394
394
  var logger2 = createLogger("AutoTaskPlugin");
395
395
  function createAutoTaskPlugin(config) {
396
- const threshold = config?.threshold ?? 30;
396
+ const threshold = config?.threshold ?? 20;
397
397
  const agentName = config?.agentName ?? "default";
398
- const llmRef = config?.llmComponent ?? null;
399
- const toolRef = config?.toolComponent ?? null;
400
- const toolChoiceModel = config?.model;
401
- const subagentType = config?.subagentType ?? "roy";
398
+ const agentComponent = config?.agentComponent ?? null;
399
+ const subagentType = config?.subagentType ?? "task-agent";
402
400
  let lastProcessedTraceId = "";
403
- let cachedDelegateToolInfo = undefined;
404
- function getDelegateToolInfoImpl() {
405
- if (cachedDelegateToolInfo !== undefined)
406
- return cachedDelegateToolInfo;
407
- if (!toolRef || typeof toolRef.getTool !== "function") {
408
- cachedDelegateToolInfo = null;
409
- return null;
410
- }
411
- const tool = toolRef.getTool("delegate_task");
412
- if (!tool) {
413
- cachedDelegateToolInfo = null;
414
- return null;
415
- }
416
- cachedDelegateToolInfo = {
417
- name: tool.name,
418
- description: tool.description || "",
419
- parameters: tool.parameters ?? {}
420
- };
421
- return cachedDelegateToolInfo;
422
- }
423
- const getDelegateToolInfo = wrapFunction(getDelegateToolInfoImpl, "plugin.auto-task.get-tool-info", { recordParams: false, recordResult: true, log: true });
424
- async function tryInvokeForDelegateImpl(msgs, delegateToolInfo, model, sid) {
425
- const result = await llmRef.invoke({
426
- messages: msgs,
427
- tools: [delegateToolInfo],
428
- model,
429
- context: { sessionId: sid },
430
- skipThresholdCheck: true
431
- });
432
- const toolCalls = result?.output?.toolCalls;
433
- if (!toolCalls || toolCalls.length === 0) {
434
- logger2.warn(`[AutoTaskPlugin] LLM returned no toolCalls (session=${sid.slice(0, 12)}...)`);
435
- return null;
436
- }
437
- for (const tc of toolCalls) {
438
- const tcName = tc.function?.name ?? tc.name;
439
- if (tcName !== "delegate_task")
440
- continue;
441
- const rawArgs = tc.function?.arguments ?? tc.arguments;
442
- try {
443
- const args = JSON.parse(typeof rawArgs === "string" ? rawArgs : JSON.stringify(rawArgs ?? {}));
444
- if (args.description && args.prompt) {
445
- return args;
446
- }
447
- logger2.warn(`[AutoTaskPlugin] delegate_task args missing required fields: ${JSON.stringify(args).slice(0, 100)}`);
448
- } catch {
449
- logger2.warn(`[AutoTaskPlugin] Failed to parse delegate_task args: ${String(rawArgs).slice(0, 100)}`);
450
- }
451
- }
452
- return null;
453
- }
454
- const tryInvokeForDelegate = wrapFunction(tryInvokeForDelegateImpl, "plugin.auto-task.invoke-llm", { recordParams: true, recordResult: true, log: true });
455
401
  async function executeImpl(ctx) {
456
402
  try {
457
403
  logger2.debug(`[AutoTaskPlugin] agentName=${ctx.agent.name} (expected=${agentName})`);
@@ -468,87 +414,53 @@ function createAutoTaskPlugin(config) {
468
414
  }
469
415
  lastProcessedTraceId = traceId;
470
416
  logger2.debug(`[AutoTaskPlugin] new query detected (traceId=${traceId.slice(0, 20)}...)`);
471
- if (!llmRef || !toolRef) {
472
- logger2.warn(`[AutoTaskPlugin] llmComponent or toolComponent not provided at creation (session=${sid.slice(0, 12)}...)`);
473
- return { continue: true };
474
- }
475
- const delegateToolInfo = getDelegateToolInfo();
476
- if (!delegateToolInfo) {
477
- logger2.warn(`[AutoTaskPlugin] delegate_task tool not found in toolComponent (session=${sid.slice(0, 12)}...)`);
417
+ if (!agentComponent || typeof agentComponent.run !== "function") {
418
+ logger2.warn(`[AutoTaskPlugin] agentComponent not provided or invalid (session=${sid.slice(0, 12)}...)`);
478
419
  return { continue: true };
479
420
  }
480
- const msgs = [];
481
- for (const m of ctx.messages) {
421
+ let userQuery = "";
422
+ for (let i = ctx.messages.length - 1;i >= 0; i--) {
423
+ const m = ctx.messages[i];
482
424
  if (m.role === "user") {
483
- msgs.push({
484
- role: "user",
485
- content: typeof m.content === "string" ? m.content : JSON.stringify(m.content)
486
- });
487
- } else if (m.role === "assistant") {
488
- const text = typeof m.content === "string" ? m.content : "";
489
- if (text.trim()) {
490
- msgs.push({ role: "assistant", content: text });
491
- }
425
+ userQuery = typeof m.content === "string" ? m.content : JSON.stringify(m.content);
426
+ break;
492
427
  }
493
428
  }
494
- msgs.push({
495
- role: "user",
496
- content: `Based on the conversation above, please call \`delegate_task\` to hand off the current work to a sub-agent.
497
-
498
- Parameters for delegate_task:
499
- - description: A short 3-8 word title describing this work
500
- - prompt: Detailed instructions for the sub-agent to continue the work
501
- - subagent_type: Use "${subagentType}"
502
- - similar_task_ids: []
429
+ if (!userQuery) {
430
+ userQuery = "分析项目结构并执行相关任务";
431
+ }
432
+ logger2.info(`[AutoTaskPlugin] Calling agentComponent.run("${subagentType}") at iteration ${ctx.iteration} (session=${sid.slice(0, 12)}..., persistSession=false)`);
433
+ const shortDesc = typeof userQuery === "string" ? userQuery.slice(0, 50) : "分析需求";
434
+ const beforeMsg = `
503
435
 
504
- Call delegate_task now.`
505
- });
506
- const model = toolChoiceModel ?? ctx.context?.model ?? ctx.agent?.config?.model;
507
- logger2.info(`[AutoTaskPlugin] Invoking LLM (model=${model}) for delegate_task args at iteration ${ctx.iteration} (session=${sid.slice(0, 12)}...)`);
508
- let args = await tryInvokeForDelegate(msgs, delegateToolInfo, model, sid);
509
- if (!args) {
510
- logger2.info(`[AutoTaskPlugin] Retrying with alternative prompt (session=${sid.slice(0, 12)}...)`);
511
- msgs.push({
512
- role: "user",
513
- content: `Please call \`delegate_task\` now with description (short title), prompt (detailed instructions), subagent_type="${subagentType}", and similar_task_ids=[].`
514
- });
515
- args = await tryInvokeForDelegate(msgs, delegateToolInfo, model, sid);
436
+ ---
437
+ ⏳ **${subagentType} 正在执行**: ${shortDesc}(等待结果...)`;
438
+ if (ctx.toolResult?.result?.output !== undefined) {
439
+ ctx.toolResult.result.output += beforeMsg;
516
440
  }
517
- if (!args) {
518
- logger2.warn(`[AutoTaskPlugin] Failed to get delegate_task args after retry (session=${sid.slice(0, 12)}...)`);
519
- return { continue: true };
441
+ let taskAgentFinalText = "";
442
+ try {
443
+ const taskAgentResult = await agentComponent.run(subagentType, userQuery, {
444
+ sessionId: sid,
445
+ traceId,
446
+ persistSession: false
447
+ });
448
+ taskAgentFinalText = taskAgentResult?.finalText || "";
449
+ logger2.info(`[AutoTaskPlugin] task-agent completed (session=${sid.slice(0, 12)}..., finalTextLength=${taskAgentFinalText.length})`);
450
+ } catch (err) {
451
+ logger2.error(`[AutoTaskPlugin] task-agent failed: ${err instanceof Error ? err.message : String(err)}`);
452
+ taskAgentFinalText = `❌ **${subagentType} 执行失败**: ${err instanceof Error ? err.message : String(err)}`;
520
453
  }
521
- logger2.info(`[AutoTaskPlugin] LLM generated delegate_task args: description="${String(args.description).slice(0, 50)}", subagent_type=${args.subagent_type}`);
522
- const execResult = await toolRef.execute({
523
- name: "delegate_task",
524
- args: {
525
- description: args.description,
526
- prompt: args.prompt,
527
- subagent_type: args.subagent_type || subagentType,
528
- similar_task_ids: args.similar_task_ids || []
529
- },
530
- context: {
531
- session_id: sid,
532
- agent: ctx.agent.name
533
- },
534
- skipHooks: true
535
- });
536
- if (execResult.success && ctx.toolResult?.result?.output !== undefined) {
537
- const bgProcessId = execResult.result?.bgProcessId ?? "unknown";
454
+ if (taskAgentFinalText && ctx.toolResult?.result?.output !== undefined) {
538
455
  const injection = `
539
456
 
540
457
  ---
541
- \uD83D\uDE80 **Task Delegated**: 已通过 delegate_task 委托给子 agent(${subagentType})在后台运行。
542
-
543
- ⏳ 请等待后台任务运行结果通知,无需额外操作。
544
-
545
- \uD83D\uDCCB 后台进程 ID: \`${bgProcessId}\`
458
+ ${taskAgentFinalText}
546
459
  ---`;
547
460
  ctx.toolResult.result.output += injection;
548
- logger2.info(`[AutoTaskPlugin] delegate_task called (bgProcessId=${bgProcessId}, session=${sid.slice(0, 12)}...)`);
549
- } else {
550
- const errMsg = execResult?.output || execResult?.error || "unknown error";
551
- logger2.warn(`[AutoTaskPlugin] delegate_task execution failed: success=${execResult?.success}, error=${String(errMsg).slice(0, 200)}`);
461
+ logger2.info(`[AutoTaskPlugin] task-agent finalText injected (session=${sid.slice(0, 12)}...)`);
462
+ } else if (!ctx.toolResult?.result?.output) {
463
+ logger2.warn(`[AutoTaskPlugin] toolResult unavailable for injection`);
552
464
  }
553
465
  return { continue: true };
554
466
  } catch (err) {
@@ -556,15 +468,15 @@ Call delegate_task now.`
556
468
  return { continue: true };
557
469
  }
558
470
  }
559
- const execute = wrapFunction(executeImpl, "plugin.auto-task.tool-call-hook", {
471
+ const execute = wrapFunction(executeImpl, "plugin.auto-task.launch-agent", {
560
472
  recordParams: false,
561
473
  recordResult: true,
562
474
  log: true
563
475
  });
564
476
  return {
565
477
  name: "AutoTaskPlugin",
566
- version: "3.0.0",
567
- description: "ReAct iteration 达到阈值时通过 LLM 生成 delegate_task 入参并直接调用",
478
+ version: "4.5.0",
479
+ description: "ReAct iteration 达到阈值时 await task-agent 执行并提取 delegate_task 结果注入 tool result",
568
480
  hooks: [
569
481
  { point: "agent:after.tool", priority: 50 }
570
482
  ],
@@ -66,7 +66,8 @@ var UpdateTaskToolSchema = z.object({
66
66
  due_date: z.string().optional(),
67
67
  tags: z.array(z.string()).optional(),
68
68
  project_path: z.string().optional().describe("Project path, identifies which project this task belongs to"),
69
- context: z.string().optional().describe("Task context information for storing additional context")
69
+ context: z.string().optional().describe("Task context information for storing additional context"),
70
+ parent_task_id: z.union([z.number(), z.null()]).optional().describe("Parent task ID (set to null to make it a root task)")
70
71
  });
71
72
  var DeleteTaskToolSchema = z.object({
72
73
  task_id: z.number().describe("Task ID")
@@ -143,8 +144,12 @@ function createTaskTool(taskComponent) {
143
144
  then create the child task with that parent_task_id.
144
145
 
145
146
  **Example:**
146
- - First: task_list(depth=0) → find root task #619 "roy-agent"
147
- - Then: task_create(title="New feature", parent_task_id=619, ...)
147
+ - First: task_list(depth=0) → find an appropriate root task for your project
148
+ (e.g. one whose title matches your project name). Use the returned root task's
149
+ id as \`parent_task_id\` — do NOT hardcode a specific id; the root task id varies
150
+ across deployments and resets.
151
+ - Then: task_create(title="New feature", parent_task_id=<root_task_id>, ...)
152
+ where \`<root_task_id>\` is the id returned by task_list, NOT a hardcoded number.
148
153
  `,
149
154
  parameters: CreateTaskToolSchema,
150
155
  execute: async (args, ctx) => {
@@ -442,6 +447,22 @@ function batchDeleteTaskTool(taskComponent) {
442
447
  init_env_context();
443
448
  init_logger();
444
449
  var logger2 = createLogger("tool:update-task");
450
+ async function detectCycle(taskComponent, taskId, newParentId) {
451
+ const visited = new Set;
452
+ let currentId = newParentId;
453
+ while (currentId !== null && currentId !== undefined) {
454
+ if (currentId === taskId)
455
+ return true;
456
+ if (visited.has(currentId))
457
+ break;
458
+ visited.add(currentId);
459
+ const currentTask = await taskComponent.getTask(currentId);
460
+ if (!currentTask)
461
+ break;
462
+ currentId = currentTask.parent_task_id;
463
+ }
464
+ return false;
465
+ }
445
466
  function updateTaskTool(taskComponent) {
446
467
  return {
447
468
  name: "task_update",
@@ -451,6 +472,17 @@ function updateTaskTool(taskComponent) {
451
472
  const params = UpdateTaskToolSchema.parse(args);
452
473
  const sessionId = ctx.session_id || "unknown";
453
474
  try {
475
+ if (params.parent_task_id !== undefined && params.parent_task_id !== null) {
476
+ const hasCycle = await detectCycle(taskComponent, params.task_id, params.parent_task_id);
477
+ if (hasCycle) {
478
+ return {
479
+ success: false,
480
+ output: "",
481
+ error: `Circular reference detected: setting parent_task_id to ${params.parent_task_id} for task #${params.task_id} would create a cycle`,
482
+ metadata: { execution_time_ms: 0 }
483
+ };
484
+ }
485
+ }
454
486
  const task = await taskComponent.updateTask(params.task_id, {
455
487
  title: params.title,
456
488
  description: params.description,
@@ -463,7 +495,8 @@ function updateTaskTool(taskComponent) {
463
495
  due_date: params.due_date,
464
496
  tags: params.tags,
465
497
  project_path: params.project_path,
466
- context: params.context
498
+ context: params.context,
499
+ parent_task_id: params.parent_task_id
467
500
  });
468
501
  if (!task) {
469
502
  return {