@ai-setting/roy-agent-core 1.5.81 → 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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AgentComponent,
3
3
  AgentComponentConfigSchema
4
- } from "../../shared/@ai-setting/roy-agent-core-qbgd7bp6.js";
4
+ } from "../../shared/@ai-setting/roy-agent-core-015vw11k.js";
5
5
  import"../../shared/@ai-setting/roy-agent-core-r0m0at3x.js";
6
6
  import"../../shared/@ai-setting/roy-agent-core-e25xkv53.js";
7
7
  import"../../shared/@ai-setting/roy-agent-core-mbre4fxg.js";
@@ -4,7 +4,7 @@ import {
4
4
  builtInHandlers,
5
5
  getBuiltInHandler,
6
6
  larkCliHandler
7
- } from "../../shared/@ai-setting/roy-agent-core-j8q8119y.js";
7
+ } from "../../shared/@ai-setting/roy-agent-core-67yzhmg2.js";
8
8
  import {
9
9
  BUILT_IN_EVENT_SOURCE_TYPES,
10
10
  BUILT_IN_EVENT_SOURCE_TYPE_LIST,
@@ -15,7 +15,7 @@ import {
15
15
  validateEventSourceConfig
16
16
  } from "../../shared/@ai-setting/roy-agent-core-xb4hvk1m.js";
17
17
  import"../../shared/@ai-setting/roy-agent-core-v8xa6vs8.js";
18
- import"../../shared/@ai-setting/roy-agent-core-w83v54mj.js";
18
+ import"../../shared/@ai-setting/roy-agent-core-78yzt2bq.js";
19
19
  import"../../shared/@ai-setting/roy-agent-core-az13yzmc.js";
20
20
  import"../../shared/@ai-setting/roy-agent-core-92z6t4he.js";
21
21
  import"../../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
package/dist/env/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  BaseEnvironment
3
- } from "../shared/@ai-setting/roy-agent-core-t2q0rwt7.js";
3
+ } from "../shared/@ai-setting/roy-agent-core-68sef3es.js";
4
4
  import {
5
5
  EventSourceComponent,
6
6
  builtInHandlers,
7
7
  larkCliHandler
8
- } from "../shared/@ai-setting/roy-agent-core-j8q8119y.js";
8
+ } from "../shared/@ai-setting/roy-agent-core-67yzhmg2.js";
9
9
  import {
10
10
  EventSourceInitHooks,
11
11
  getDefaultConfigForType,
@@ -17,7 +17,7 @@ import"../shared/@ai-setting/roy-agent-core-v8xa6vs8.js";
17
17
  import {
18
18
  PluginComponent
19
19
  } from "../shared/@ai-setting/roy-agent-core-t1ef8hf2.js";
20
- import"../shared/@ai-setting/roy-agent-core-w83v54mj.js";
20
+ import"../shared/@ai-setting/roy-agent-core-78yzt2bq.js";
21
21
  import"../shared/@ai-setting/roy-agent-core-az13yzmc.js";
22
22
  import {
23
23
  WorkflowComponent
@@ -39,22 +39,22 @@ import"../shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
39
39
  import {
40
40
  AgentComponent,
41
41
  AgentComponentConfigSchema
42
- } from "../shared/@ai-setting/roy-agent-core-qbgd7bp6.js";
42
+ } from "../shared/@ai-setting/roy-agent-core-015vw11k.js";
43
43
  import"../shared/@ai-setting/roy-agent-core-r0m0at3x.js";
44
44
  import"../shared/@ai-setting/roy-agent-core-e25xkv53.js";
45
45
  import {
46
46
  TaskComponent
47
- } from "../shared/@ai-setting/roy-agent-core-p8jv13bm.js";
47
+ } from "../shared/@ai-setting/roy-agent-core-qjv8537d.js";
48
48
  import"../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
49
49
  import"../shared/@ai-setting/roy-agent-core-f6p7wwpd.js";
50
- import"../shared/@ai-setting/roy-agent-core-r9y8ct0w.js";
50
+ import"../shared/@ai-setting/roy-agent-core-pcdzfwdv.js";
51
51
  import"../shared/@ai-setting/roy-agent-core-mbre4fxg.js";
52
52
  import {
53
53
  XDG_PATHS,
54
54
  getXDGPath,
55
55
  getXDGPaths
56
56
  } from "../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
57
- import"../shared/@ai-setting/roy-agent-core-df3ng0pz.js";
57
+ import"../shared/@ai-setting/roy-agent-core-7nh5h9fn.js";
58
58
  import"../shared/@ai-setting/roy-agent-core-t94ktchq.js";
59
59
  import"../shared/@ai-setting/roy-agent-core-92z6t4he.js";
60
60
  import {
@@ -3,7 +3,7 @@ import {
3
3
  PromptConfigSchema,
4
4
  PromptPathSchema,
5
5
  PromptRenderer
6
- } from "../../shared/@ai-setting/roy-agent-core-vgyj2rq9.js";
6
+ } from "../../shared/@ai-setting/roy-agent-core-vcvgq9hy.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";
@@ -5,7 +5,7 @@ import {
5
5
  TaskPriorityEnum,
6
6
  TaskStatusEnum,
7
7
  TaskTypeEnum
8
- } from "../../shared/@ai-setting/roy-agent-core-p8jv13bm.js";
8
+ } from "../../shared/@ai-setting/roy-agent-core-qjv8537d.js";
9
9
  import {
10
10
  TaskEntityEventTypes
11
11
  } from "../../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
@@ -13,10 +13,10 @@ import"../../shared/@ai-setting/roy-agent-core-f6p7wwpd.js";
13
13
  import {
14
14
  SQLiteTaskStore,
15
15
  getDefaultTaskDbPath
16
- } from "../../shared/@ai-setting/roy-agent-core-r9y8ct0w.js";
16
+ } from "../../shared/@ai-setting/roy-agent-core-pcdzfwdv.js";
17
17
  import"../../shared/@ai-setting/roy-agent-core-mbre4fxg.js";
18
18
  import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
19
- import"../../shared/@ai-setting/roy-agent-core-df3ng0pz.js";
19
+ import"../../shared/@ai-setting/roy-agent-core-7nh5h9fn.js";
20
20
  import"../../shared/@ai-setting/roy-agent-core-t94ktchq.js";
21
21
  import"../../shared/@ai-setting/roy-agent-core-92z6t4he.js";
22
22
  import"../../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
@@ -9,7 +9,7 @@ import {
9
9
  formatExtractorInput,
10
10
  formatExtractorInputFromDescription,
11
11
  parseExtractorOutput
12
- } from "../../../shared/@ai-setting/roy-agent-core-w83v54mj.js";
12
+ } from "../../../shared/@ai-setting/roy-agent-core-78yzt2bq.js";
13
13
  import"../../../shared/@ai-setting/roy-agent-core-az13yzmc.js";
14
14
  import"../../../shared/@ai-setting/roy-agent-core-92z6t4he.js";
15
15
  import"../../../shared/@ai-setting/roy-agent-core-qg4rma4c.js";
@@ -2,7 +2,7 @@ import {
2
2
  SQLiteTaskStore,
3
3
  getDefaultDataDir,
4
4
  getDefaultTaskDbPath
5
- } from "../../../shared/@ai-setting/roy-agent-core-r9y8ct0w.js";
5
+ } from "../../../shared/@ai-setting/roy-agent-core-pcdzfwdv.js";
6
6
  import"../../../shared/@ai-setting/roy-agent-core-shme7set.js";
7
7
  import"../../../shared/@ai-setting/roy-agent-core-7z9b1fm8.js";
8
8
  import"../../../shared/@ai-setting/roy-agent-core-c6592r3c.js";
@@ -8,7 +8,7 @@ import {
8
8
  listTasksTool,
9
9
  searchTasksTool,
10
10
  updateTaskTool
11
- } from "../../../shared/@ai-setting/roy-agent-core-df3ng0pz.js";
11
+ } from "../../../shared/@ai-setting/roy-agent-core-7nh5h9fn.js";
12
12
  import"../../../shared/@ai-setting/roy-agent-core-y5d04fm3.js";
13
13
  import"../../../shared/@ai-setting/roy-agent-core-k05v31rc.js";
14
14
  import"../../../shared/@ai-setting/roy-agent-core-shme7set.js";
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-vgyj2rq9.js";
6
+ } from "./shared/@ai-setting/roy-agent-core-vcvgq9hy.js";
7
7
  import {
8
8
  LLMComponent,
9
9
  LLMConfigSchema,
@@ -57,13 +57,13 @@ import {
57
57
  BaseEnvironment,
58
58
  generateDescendingId,
59
59
  generateId
60
- } from "./shared/@ai-setting/roy-agent-core-t2q0rwt7.js";
60
+ } from "./shared/@ai-setting/roy-agent-core-68sef3es.js";
61
61
  import {
62
62
  EventSourceComponent,
63
63
  builtInHandlers,
64
64
  getBuiltInHandler,
65
65
  larkCliHandler
66
- } from "./shared/@ai-setting/roy-agent-core-j8q8119y.js";
66
+ } from "./shared/@ai-setting/roy-agent-core-67yzhmg2.js";
67
67
  import {
68
68
  BUILT_IN_EVENT_SOURCE_TYPES,
69
69
  BUILT_IN_EVENT_SOURCE_TYPE_LIST,
@@ -83,7 +83,7 @@ import {
83
83
  import {
84
84
  TaskTagPlugin,
85
85
  createAutoTaskPlugin
86
- } from "./shared/@ai-setting/roy-agent-core-w83v54mj.js";
86
+ } from "./shared/@ai-setting/roy-agent-core-78yzt2bq.js";
87
87
  import {
88
88
  BasePlugin
89
89
  } from "./shared/@ai-setting/roy-agent-core-az13yzmc.js";
@@ -116,7 +116,7 @@ import"./shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
116
116
  import {
117
117
  AgentComponent,
118
118
  AgentComponentConfigSchema
119
- } from "./shared/@ai-setting/roy-agent-core-qbgd7bp6.js";
119
+ } from "./shared/@ai-setting/roy-agent-core-015vw11k.js";
120
120
  import {
121
121
  createInvokeConfig,
122
122
  invoke,
@@ -129,13 +129,13 @@ import {
129
129
  } from "./shared/@ai-setting/roy-agent-core-e25xkv53.js";
130
130
  import {
131
131
  TaskComponent
132
- } from "./shared/@ai-setting/roy-agent-core-p8jv13bm.js";
132
+ } from "./shared/@ai-setting/roy-agent-core-qjv8537d.js";
133
133
  import"./shared/@ai-setting/roy-agent-core-8gxth0eh.js";
134
134
  import"./shared/@ai-setting/roy-agent-core-f6p7wwpd.js";
135
135
  import {
136
136
  SQLiteTaskStore,
137
137
  getDefaultTaskDbPath
138
- } from "./shared/@ai-setting/roy-agent-core-r9y8ct0w.js";
138
+ } from "./shared/@ai-setting/roy-agent-core-pcdzfwdv.js";
139
139
  import {
140
140
  AgentRegistry
141
141
  } from "./shared/@ai-setting/roy-agent-core-mbre4fxg.js";
@@ -144,7 +144,7 @@ import {
144
144
  getXDGPath,
145
145
  getXDGPaths
146
146
  } from "./shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
147
- import"./shared/@ai-setting/roy-agent-core-df3ng0pz.js";
147
+ import"./shared/@ai-setting/roy-agent-core-7nh5h9fn.js";
148
148
  import"./shared/@ai-setting/roy-agent-core-t94ktchq.js";
149
149
  import {
150
150
  TaskHookPoints
@@ -548,6 +548,27 @@ class AgentComponent extends BaseComponent {
548
548
  this.doomLoopCaches.set(runId, new Map);
549
549
  }
550
550
  await this.resolveSystemPrompt(agent, agentName);
551
+ if (agent.config.systemPrompt) {
552
+ const sp = agent.config.systemPrompt;
553
+ if (sp.includes("{{workspace_dir}}")) {
554
+ const workspaceDir = this.env?.getComponent?.("config")?.get?.("workspace_dir") || process.cwd();
555
+ agent.config.systemPrompt = agent.config.systemPrompt.replaceAll("{{workspace_dir}}", String(workspaceDir));
556
+ }
557
+ if (sp.includes("{{memory}}")) {
558
+ try {
559
+ const memoryComponent = this.env?.getComponent?.("memory");
560
+ if (memoryComponent && typeof memoryComponent.recallMemory === "function") {
561
+ const memoryContent = await memoryComponent.recallMemory();
562
+ agent.config.systemPrompt = agent.config.systemPrompt.replace("{{memory}}", memoryContent || "(No memory)");
563
+ } else {
564
+ agent.config.systemPrompt = agent.config.systemPrompt.replace("{{memory}}", "(Memory component not available)");
565
+ }
566
+ } catch (err) {
567
+ logger.warn(`[AgentComponent._run] Failed to replace {{memory}}: ${err}`);
568
+ agent.config.systemPrompt = agent.config.systemPrompt.replace("{{memory}}", "(Failed to load memory)");
569
+ }
570
+ }
571
+ }
551
572
  const effectiveContext = {
552
573
  ...context,
553
574
  agentType: agent.config.type,
@@ -637,6 +658,7 @@ class AgentComponent extends BaseComponent {
637
658
  result.iterations = iteration;
638
659
  logger.debug(`Iteration ${iteration} started`);
639
660
  this.doomLoopCaches.set(runId, new Map);
661
+ hookCtx.currentToolCall = undefined;
640
662
  hookCtx.maxIterations = agent.config.maxIterations;
641
663
  try {
642
664
  logger.debug(`[ReAct] Iteration ${iteration} buildMessages result: ${hookCtx.messages.length} messages`);
@@ -957,7 +979,11 @@ class AgentComponent extends BaseComponent {
957
979
  historyMessageCount,
958
980
  sessionId: effectiveContext.sessionId
959
981
  });
960
- await this.recordSessionMessages(effectiveContext.sessionId, newMessages);
982
+ if (effectiveContext.persistSession !== false) {
983
+ await this.recordSessionMessages(effectiveContext.sessionId, newMessages);
984
+ } else {
985
+ logger.debug(`Skipping session message recording (persistSession=false, sessionId=${effectiveContext.sessionId})`);
986
+ }
961
987
  return this.finalizeResult(result, hookCtx);
962
988
  });
963
989
  }
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TaskTagPlugin,
3
3
  createLarkCliTaskNotifyHook
4
- } from "./roy-agent-core-w83v54mj.js";
4
+ } from "./roy-agent-core-78yzt2bq.js";
5
5
  import {
6
6
  envKeyToConfigKey
7
7
  } from "./roy-agent-core-qxhq8ven.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createAutoTaskPlugin
3
- } from "./roy-agent-core-w83v54mj.js";
3
+ } from "./roy-agent-core-78yzt2bq.js";
4
4
  import {
5
5
  ContextError,
6
6
  ErrorCodes
@@ -195,15 +195,12 @@ class BaseEnvironment extends BaseComponent {
195
195
  });
196
196
  logger.info(`[handle_query] Created default receptionist agent with deniedTools: ${defaultDeniedTools.length} tools denied`);
197
197
  try {
198
- const llmRef = this.getComponent("llm");
199
- const toolRef = this.getComponent("tool");
200
198
  const autoTaskPlugin = createAutoTaskPlugin({
201
- threshold: 30,
202
- llmComponent: llmRef ?? undefined,
203
- toolComponent: toolRef ?? undefined
199
+ threshold: 20,
200
+ agentComponent
204
201
  });
205
202
  agentComponent.registerPlugin("default", autoTaskPlugin);
206
- logger.info("[handle_query] AutoTaskPlugin v3 registered on default agent (threshold=30)");
203
+ logger.info("[handle_query] AutoTaskPlugin v4.4 registered on default agent (threshold=20)");
207
204
  } catch (err) {
208
205
  logger.warn(`[handle_query] Failed to register AutoTaskPlugin: ${err}`);
209
206
  }
@@ -393,67 +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
- const rawArgs = tc.function?.arguments ?? tc.arguments;
440
- const rawArgsStr = typeof rawArgs === "string" ? rawArgs : JSON.stringify(rawArgs ?? {});
441
- logger2.debug(`[AutoTaskPlugin] inspecting toolCall name=${tcName ?? "unknown"}, rawArgs=${rawArgsStr.slice(0, 80)} (session=${sid.slice(0, 12)}...)`);
442
- if (tcName !== "delegate_task")
443
- continue;
444
- try {
445
- const args = JSON.parse(typeof rawArgs === "string" ? rawArgs : JSON.stringify(rawArgs ?? {}));
446
- if (args.description && args.prompt) {
447
- return args;
448
- }
449
- logger2.warn(`[AutoTaskPlugin] delegate_task args missing required fields: ${JSON.stringify(args).slice(0, 100)}`);
450
- } catch {
451
- logger2.warn(`[AutoTaskPlugin] Failed to parse delegate_task args: ${String(rawArgs).slice(0, 100)}`);
452
- }
453
- }
454
- return null;
455
- }
456
- const tryInvokeForDelegate = wrapFunction(tryInvokeForDelegateImpl, "plugin.auto-task.invoke-llm", { recordParams: true, recordResult: true, log: true });
457
401
  async function executeImpl(ctx) {
458
402
  try {
459
403
  logger2.debug(`[AutoTaskPlugin] agentName=${ctx.agent.name} (expected=${agentName})`);
@@ -470,90 +414,53 @@ function createAutoTaskPlugin(config) {
470
414
  }
471
415
  lastProcessedTraceId = traceId;
472
416
  logger2.debug(`[AutoTaskPlugin] new query detected (traceId=${traceId.slice(0, 20)}...)`);
473
- if (!llmRef || !toolRef) {
474
- logger2.warn(`[AutoTaskPlugin] llmComponent or toolComponent not provided at creation (session=${sid.slice(0, 12)}...)`);
475
- return { continue: true };
476
- }
477
- const delegateToolInfo = getDelegateToolInfo();
478
- if (!delegateToolInfo) {
479
- 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)}...)`);
480
419
  return { continue: true };
481
420
  }
482
- const msgs = [];
483
- 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];
484
424
  if (m.role === "user") {
485
- msgs.push({
486
- role: "user",
487
- content: typeof m.content === "string" ? m.content : JSON.stringify(m.content)
488
- });
489
- } else if (m.role === "assistant") {
490
- const text = typeof m.content === "string" ? m.content : "";
491
- if (text.trim()) {
492
- msgs.push({ role: "assistant", content: text });
493
- }
425
+ userQuery = typeof m.content === "string" ? m.content : JSON.stringify(m.content);
426
+ break;
494
427
  }
495
428
  }
496
- msgs.push({
497
- role: "user",
498
- content: `Based on the conversation above, please call \`delegate_task\` to hand off the current work to a sub-agent.
499
-
500
- Parameters for delegate_task:
501
- - description: A short 3-8 word title describing this work
502
- - prompt: Detailed instructions for the sub-agent to continue the work
503
- - subagent_type: Use "${subagentType}"
504
- - 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 = `
505
435
 
506
- Call delegate_task now.`
507
- });
508
- const model = toolChoiceModel ?? ctx.context?.model ?? ctx.agent?.config?.model;
509
- logger2.info(`[AutoTaskPlugin] Invoking LLM (model=${model}) for delegate_task args at iteration ${ctx.iteration} (session=${sid.slice(0, 12)}...)`);
510
- let args = await tryInvokeForDelegate(msgs, delegateToolInfo, model, sid);
511
- if (!args) {
512
- logger2.info(`[AutoTaskPlugin] Retrying with alternative prompt (session=${sid.slice(0, 12)}...)`);
513
- const retryMsgs = [
514
- ...msgs,
515
- {
516
- role: "user",
517
- content: `Please call \`delegate_task\` now with description (short title), prompt (detailed instructions), subagent_type="${subagentType}", and similar_task_ids=[].`
518
- }
519
- ];
520
- args = await tryInvokeForDelegate(retryMsgs, delegateToolInfo, model, sid);
436
+ ---
437
+ ⏳ **${subagentType} 正在执行**: ${shortDesc}(等待结果...)`;
438
+ if (ctx.toolResult?.result?.output !== undefined) {
439
+ ctx.toolResult.result.output += beforeMsg;
521
440
  }
522
- if (!args) {
523
- logger2.warn(`[AutoTaskPlugin] Failed to get delegate_task args after retry (session=${sid.slice(0, 12)}...)`);
524
- 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)}`;
525
453
  }
526
- logger2.info(`[AutoTaskPlugin] LLM generated delegate_task args: description="${String(args.description).slice(0, 50)}", subagent_type=${args.subagent_type}`);
527
- const execResult = await toolRef.execute({
528
- name: "delegate_task",
529
- args: {
530
- description: args.description,
531
- prompt: args.prompt,
532
- subagent_type: args.subagent_type || subagentType,
533
- similar_task_ids: args.similar_task_ids || []
534
- },
535
- context: {
536
- session_id: sid,
537
- agent: ctx.agent.name
538
- },
539
- skipHooks: true
540
- });
541
- if (execResult.success && ctx.toolResult?.result?.output !== undefined) {
542
- const bgProcessId = execResult.result?.bgProcessId ?? "unknown";
454
+ if (taskAgentFinalText && ctx.toolResult?.result?.output !== undefined) {
543
455
  const injection = `
544
456
 
545
457
  ---
546
- \uD83D\uDE80 **Task Delegated**: 已通过 delegate_task 委托给子 agent(${subagentType})在后台运行。
547
-
548
- ⏳ 请等待后台任务运行结果通知,无需额外操作。
549
-
550
- \uD83D\uDCCB 后台进程 ID: \`${bgProcessId}\`
458
+ ${taskAgentFinalText}
551
459
  ---`;
552
460
  ctx.toolResult.result.output += injection;
553
- logger2.info(`[AutoTaskPlugin] delegate_task called (bgProcessId=${bgProcessId}, session=${sid.slice(0, 12)}...)`);
554
- } else {
555
- const errMsg = execResult?.output || execResult?.error || "unknown error";
556
- 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`);
557
464
  }
558
465
  return { continue: true };
559
466
  } catch (err) {
@@ -561,15 +468,15 @@ Call delegate_task now.`
561
468
  return { continue: true };
562
469
  }
563
470
  }
564
- const execute = wrapFunction(executeImpl, "plugin.auto-task.tool-call-hook", {
471
+ const execute = wrapFunction(executeImpl, "plugin.auto-task.launch-agent", {
565
472
  recordParams: false,
566
473
  recordResult: true,
567
474
  log: true
568
475
  });
569
476
  return {
570
477
  name: "AutoTaskPlugin",
571
- version: "3.0.0",
572
- description: "ReAct iteration 达到阈值时通过 LLM 生成 delegate_task 入参并直接调用",
478
+ version: "4.5.0",
479
+ description: "ReAct iteration 达到阈值时 await task-agent 执行并提取 delegate_task 结果注入 tool result",
573
480
  hooks: [
574
481
  { point: "agent:after.tool", priority: 50 }
575
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")
@@ -446,6 +447,22 @@ function batchDeleteTaskTool(taskComponent) {
446
447
  init_env_context();
447
448
  init_logger();
448
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
+ }
449
466
  function updateTaskTool(taskComponent) {
450
467
  return {
451
468
  name: "task_update",
@@ -455,6 +472,17 @@ function updateTaskTool(taskComponent) {
455
472
  const params = UpdateTaskToolSchema.parse(args);
456
473
  const sessionId = ctx.session_id || "unknown";
457
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
+ }
458
486
  const task = await taskComponent.updateTask(params.task_id, {
459
487
  title: params.title,
460
488
  description: params.description,
@@ -467,7 +495,8 @@ function updateTaskTool(taskComponent) {
467
495
  due_date: params.due_date,
468
496
  tags: params.tags,
469
497
  project_path: params.project_path,
470
- context: params.context
498
+ context: params.context,
499
+ parent_task_id: params.parent_task_id
471
500
  });
472
501
  if (!task) {
473
502
  return {
@@ -287,6 +287,10 @@ class SQLiteTaskStore {
287
287
  updates.push("context = ?");
288
288
  values.push(options.context);
289
289
  }
290
+ if (options.parent_task_id !== undefined) {
291
+ updates.push("parent_task_id = ?");
292
+ values.push(options.parent_task_id);
293
+ }
290
294
  if (updates.length === 0)
291
295
  return task;
292
296
  updates.push("updated_at = ?");
@@ -9,7 +9,7 @@ import {
9
9
  import {
10
10
  SQLiteTaskStore,
11
11
  getDefaultTaskDbPath
12
- } from "./roy-agent-core-r9y8ct0w.js";
12
+ } from "./roy-agent-core-pcdzfwdv.js";
13
13
  import {
14
14
  batchArchiveTaskTool,
15
15
  batchDeleteTaskTool,
@@ -20,7 +20,7 @@ import {
20
20
  listTasksTool,
21
21
  searchTasksTool,
22
22
  updateTaskTool
23
- } from "./roy-agent-core-df3ng0pz.js";
23
+ } from "./roy-agent-core-7nh5h9fn.js";
24
24
  import {
25
25
  createOperationTool,
26
26
  deleteOperationTool,
@@ -930,7 +930,54 @@ workflow_run(workflow_name="strict-task-agent", input={"task_description": "修
930
930
  >
931
931
  > 设计文档:.roy/design/2026-06-29-workflow-subagent-entry-agent-design.md
932
932
 
933
- 记住:你是 workflow 的"调度员",不是 workflow 本身。`
933
+ 记住:你是 workflow 的"调度员",不是 workflow 本身。`,
934
+ "task-agent": `# Task Agent — 任务优先智能体
935
+
936
+ ## 你的身份
937
+ 当主 agent(default)在 ReAct 循环中达到迭代阈值时,你被调用。你的职责:
938
+ 1. 分析对话历史,理解用户需求
939
+ 2. task_create 创建任务
940
+ 3. task_search 搜索相似任务
941
+ 4. delegate_task 委托给 roy
942
+
943
+ ## 工作目录
944
+
945
+ **workspace_dir**: {{workspace_dir}}
946
+
947
+ ## 可用工具(全部 task 工具 + delegate_task + bash)
948
+
949
+ ### 任务查询工具
950
+ - task_search(keywords=[...]) — 搜索相关任务(返回任务 ID 列表,用于 similar_task_ids)
951
+ - task_get(task_id=123) — 查看任务详情
952
+ - task_list(status="active") — 列出任务
953
+ - task_operation_list(task_id=123) — 查看操作记录
954
+
955
+ ### 任务生命周期工具
956
+ - task_create(title=..., description=..., progress=0, status="active") — 创建新任务
957
+ - task_update(task_id=..., ...) — 更新任务状态
958
+ - task_operation_create(task_id=..., ...) — 记录操作记录
959
+ - task_complete(task_id=...) — 完成任务
960
+
961
+ ### 执行工具
962
+ - delegate_task(description=..., prompt=..., subagent_type="roy", similar_task_ids=[...]) — 委托给子 agent
963
+ - bash(command=...) — 执行 shell 命令
964
+
965
+ ## 工作流程(严格执行)
966
+ 1. **分析对话** → 理解用户到底需要做什么
967
+ 2. **task_create** → 创建任务(title 简短 3-8 字,description 详细,progress=0, status="active")
968
+ 3. **task_operation_create** → 记录"任务已创建,开始搜索相似任务"里程碑
969
+ 4. **task_search** → 搜索相似任务获取 similar_task_ids
970
+ 5. **task_get** → 获取相似任务详情(可选,最多 3 个)
971
+ 6. **delegate_task** → 委托给 roy:
972
+ - description: 简短标题(3-8 字)
973
+ - prompt: 详细的委托指令,包含用户原始需求
974
+ - subagent_type: "roy"
975
+ - similar_task_ids: 真实搜索到的 ID 列表(最多 3 个)
976
+
977
+ ## 重要规则
978
+ - delegate_task 是后台模式,调用后立即返回 bgProcessId
979
+ - 调用 delegate_task 后立即停止,不要再做其他操作
980
+ - 通过 task_operation_create 记录里程碑`
934
981
  };
935
982
  function getBuiltInPromptNames() {
936
983
  return Object.keys(builtInPrompts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.5.81",
3
+ "version": "1.5.83",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",