@ai-setting/roy-agent-core 1.5.75 → 1.5.77

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-w6j4zyps.js";
4
+ } from "../../shared/@ai-setting/roy-agent-core-4s4en7c6.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-zf62vkc4.js";
package/dist/env/index.js CHANGED
@@ -21,7 +21,7 @@ import"../shared/@ai-setting/roy-agent-core-r12a2qfv.js";
21
21
  import"../shared/@ai-setting/roy-agent-core-az13yzmc.js";
22
22
  import {
23
23
  WorkflowComponent
24
- } from "../shared/@ai-setting/roy-agent-core-c4hhd1f2.js";
24
+ } from "../shared/@ai-setting/roy-agent-core-vqkzn45t.js";
25
25
  import"../shared/@ai-setting/roy-agent-core-fjexv5nm.js";
26
26
  import"../shared/@ai-setting/roy-agent-core-4hh4s0w1.js";
27
27
  import"../shared/@ai-setting/roy-agent-core-9adgwts7.js";
@@ -39,7 +39,7 @@ 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-w6j4zyps.js";
42
+ } from "../shared/@ai-setting/roy-agent-core-4s4en7c6.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 {
@@ -3,7 +3,7 @@ import {
3
3
  PromptConfigSchema,
4
4
  PromptPathSchema,
5
5
  PromptRenderer
6
- } from "../../shared/@ai-setting/roy-agent-core-hfc3hzcj.js";
6
+ } from "../../shared/@ai-setting/roy-agent-core-d32ecc9z.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";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  WorkflowComponent
3
- } from "../../shared/@ai-setting/roy-agent-core-c4hhd1f2.js";
3
+ } from "../../shared/@ai-setting/roy-agent-core-vqkzn45t.js";
4
4
  import"../../shared/@ai-setting/roy-agent-core-fjexv5nm.js";
5
5
  import"../../shared/@ai-setting/roy-agent-core-4hh4s0w1.js";
6
6
  import"../../shared/@ai-setting/roy-agent-core-9adgwts7.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-hfc3hzcj.js";
6
+ } from "./shared/@ai-setting/roy-agent-core-d32ecc9z.js";
7
7
  import {
8
8
  LLMComponent,
9
9
  LLMConfigSchema,
@@ -89,7 +89,7 @@ import {
89
89
  } from "./shared/@ai-setting/roy-agent-core-az13yzmc.js";
90
90
  import {
91
91
  WorkflowComponent
92
- } from "./shared/@ai-setting/roy-agent-core-c4hhd1f2.js";
92
+ } from "./shared/@ai-setting/roy-agent-core-vqkzn45t.js";
93
93
  import {
94
94
  init_node_registry_helper,
95
95
  registerDecoratorNodeType
@@ -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-w6j4zyps.js";
119
+ } from "./shared/@ai-setting/roy-agent-core-4s4en7c6.js";
120
120
  import {
121
121
  createInvokeConfig,
122
122
  invoke,
@@ -147,6 +147,7 @@ var DEFAULT_AGENT_CONFIG = {
147
147
  maxIterations: 200,
148
148
  maxErrorRetries: 3,
149
149
  doomLoopThreshold: 5,
150
+ timeout: 300000,
150
151
  toolTimeout: 60000,
151
152
  toolRetries: 3,
152
153
  filterHistory: false
@@ -161,6 +162,7 @@ var AgentInstanceSchema = z.object({
161
162
  doomLoopThreshold: z.number().default(5),
162
163
  allowedTools: z.array(z.string()).optional(),
163
164
  deniedTools: z.array(z.string()).optional(),
165
+ timeout: z.number().default(300000),
164
166
  toolTimeout: z.number().default(60000),
165
167
  toolRetries: z.number().default(3),
166
168
  filterHistory: z.boolean().default(false)
@@ -254,6 +256,7 @@ class AgentComponent extends BaseComponent {
254
256
  maxIterations: constructorDefaultAgent?.maxIterations ?? configComponent.get("agent.defaultAgent.maxIterations") ?? 200,
255
257
  maxErrorRetries: constructorDefaultAgent?.maxErrorRetries ?? configComponent.get("agent.defaultAgent.maxErrorRetries") ?? 3,
256
258
  doomLoopThreshold: constructorDefaultAgent?.doomLoopThreshold ?? configComponent.get("agent.defaultAgent.doomLoopThreshold") ?? 5,
259
+ timeout: constructorDefaultAgent?.timeout ?? configComponent.get("agent.defaultAgent.timeout") ?? 300000,
257
260
  toolTimeout: constructorDefaultAgent?.toolTimeout ?? configComponent.get("agent.defaultAgent.toolTimeout") ?? 60000,
258
261
  toolRetries: constructorDefaultAgent?.toolRetries ?? configComponent.get("agent.defaultAgent.toolRetries") ?? 3,
259
262
  filterHistory: constructorDefaultAgent?.filterHistory ?? configComponent.get("agent.defaultAgent.filterHistory") ?? false,
@@ -434,6 +437,7 @@ class AgentComponent extends BaseComponent {
434
437
  maxIterations: config.maxIterations ?? this.config.defaultAgent.maxIterations,
435
438
  maxErrorRetries: config.maxErrorRetries ?? this.config.defaultAgent.maxErrorRetries,
436
439
  doomLoopThreshold: config.doomLoopThreshold ?? this.config.defaultAgent.doomLoopThreshold,
440
+ timeout: config.timeout ?? this.config.defaultAgent.timeout,
437
441
  toolTimeout: config.toolTimeout ?? this.config.defaultAgent.toolTimeout,
438
442
  toolRetries: config.toolRetries ?? this.config.defaultAgent.toolRetries,
439
443
  systemPrompt: config.systemPrompt ?? (config.systemPromptRef ? undefined : this.config.defaultAgent.systemPrompt),
@@ -536,6 +540,16 @@ class AgentComponent extends BaseComponent {
536
540
  this.aborted.set(runId, false);
537
541
  const abortController = new AbortController;
538
542
  this.abortControllers.set(runId, abortController);
543
+ let timeoutId;
544
+ if (agent.config.timeout && agent.config.timeout > 0) {
545
+ timeoutId = setTimeout(() => {
546
+ if (!this.aborted.get(runId)) {
547
+ logger.warn(`[runAgent] Agent "${agentName}" timed out after ${agent.config.timeout}ms (runId=${runId})`);
548
+ this.aborted.set(runId, true);
549
+ abortController.abort();
550
+ }
551
+ }, agent.config.timeout);
552
+ }
539
553
  if (!this.doomLoopCaches.has(runId)) {
540
554
  this.doomLoopCaches.set(runId, new Map);
541
555
  }
@@ -922,6 +936,10 @@ class AgentComponent extends BaseComponent {
922
936
  }
923
937
  this.aborted.delete(runId);
924
938
  this.abortControllers.delete(runId);
939
+ if (timeoutId !== undefined) {
940
+ clearTimeout(timeoutId);
941
+ timeoutId = undefined;
942
+ }
925
943
  if (result.error) {
926
944
  this.pushEnvEvent({
927
945
  type: "agent.error",
@@ -132,37 +132,60 @@ var builtInPrompts = {
132
132
 
133
133
  > **similar_task_ids 是必填参数**:每次调用 \`delegate_task\` 前,必须先使用 \`task_search\` 搜索与当前任务相似的历史任务,将找到的相似任务 ID 填入 \`similar_task_ids\` 参数(最多 3 个)。如果没有找到相似任务,传入空数组 \`similar_task_ids=[]\`。
134
134
 
135
- **\`bash\`** — **仅限**以下**一次性简单操作**:
136
- - 调用一行 \`roy-agent\` 命令(如 \`bun packages/cli/dist/bin/roy-agent.js tasks list\`)
137
- - 执行一个简单的 shell 命令(如 \`ls\`、\`echo hello\`)
138
- - 检查版本或帮助信息
135
+ **\`bash\`** — 用于执行**简单的一次性 shell 命令**(1-2 行能完成的查询)。典型场景:
136
+ - **文件浏览 / 读取**:\`ls -la\`、\`cat file.txt\`、\`head -n 20 file.txt\`、\`tail -n 50 log.txt\`、\`grep "pattern" file.txt\`、\`find . -name "*.ts"\`
137
+ - **状态查询**:\`pwd\`、\`date\`、\`whoami\`、\`which node\`、\`git status\`、\`git log -5\`、\`git diff\`
138
+ - **简单测试 / 工具调用**:\`echo "hello"\`、\`node --version\`、\`bun --version\`
139
+ - **调用一行 \`roy-agent\` 命令**(如 \`bun packages/cli/dist/bin/roy-agent.js tasks list\`)
139
140
 
140
- **\`bash\` 的边界判定:**
141
- > 如果需要 **2 步以上**、涉及**条件判断**、需要**读取结果后再决策**,或者**不确认能否一行完成**,**一律用 \`delegate_task\`**。
142
-
143
- **\`bash\` 禁止用于:**
144
- - ❌ 任何需要多步骤的复杂逻辑
145
- - ❌ 代码分析、文件读写、搜索
146
- - ❌ 功能开发、调试、重构
147
- - ❌ 读取文件内容、grep 代码
148
- - ❌ 即使可以用 bash 实现,**只要超过 1 步**就必须用 \`delegate_task\`
141
+ **\`bash\` 适合 vs 需要委托的边界:**
142
+ - \`ls -la\`、\`cat file.txt\`、\`grep "TODO" src/*.ts\`、\`git status\`、\`find . -name "*.ts"\` — **直接用 \`bash\` 执行**
143
+ - ❌ "实现 XXX 功能"、"重构 XXX 模块"、"修复 XXX bug"、"调研 XXX 技术"、"开发 XXX feature" — **必须用 \`delegate_task\` 委托**
144
+ - ⚠️ 复杂多步、跨文件、需要规划/分析/决策的工作 — **必须用 \`delegate_task\` 委托**
149
145
 
150
146
  ## 何时委托
151
147
 
152
- 对于以下任何请求,**必须**使用 \`delegate_task\` 委托:
148
+ **核心原则**:只有**复杂的、多步操作**才能完成的任务或用户 query 才委托。
149
+
150
+ ### ✅ 需要委托(使用 \`delegate_task\`)
151
+
152
+ - **实现功能** — 如"实现一个加法函数"、"添加用户登录功能"、"开发 XXX 模块"
153
+ - **重构 / 优化** — 如"重构 XXX 模块"、"优化 XXX 性能"、"改进 XXX 架构"
154
+ - **修复 Bug** — 如"修复登录失败的 bug"、"排查 XXX 报错"
155
+ - **调研类任务** — 需要代码分析、网络搜索、技术调研、数据收集
156
+ - **多步实施** — 需要规划、读+分析+写、跨文件操作的工作
157
+ - **不明确的任务** — 需要探索才能明确方向、范围较大的请求
158
+ - **复杂查询** — 涉及推理、规划、决策的请求
159
+
160
+ ### ❌ 不需要委托(直接用 \`bash\` 或直接回复)
161
+
162
+ - **单个简单 bash 命令** — 如 \`ls\`、\`pwd\`、\`date\`、\`whoami\`、\`echo hello\`
163
+ - **几个简单命令就能完成的查询** — 如 \`ls -la\`、\`cat file.txt\`、\`head -n 20 file.txt\`、\`grep "pattern" file.txt\`、\`git status\`、\`git log -5\`、\`find . -name "*.ts"\`
164
+ - **一次性问答** — 你凭自身知识就能回答的简单问题
165
+ - **问候 / 闲聊** — "你好"、"谢谢"等
166
+
167
+ > \uD83D\uDCA1 **判定方法**:如果用户的请求能用 **1-2 行简单 shell 命令**直接完成(如 \`ls -la\`、\`cat file.txt\`、\`git status\`),就**直接用 \`bash\` 执行**,无需委托。只有需要规划、调研、编码、重构、Bug 修复、实现功能等**复杂多步操作**时才委托。
168
+
169
+ ## 工具返回的策略提示必须采纳
170
+
171
+ 运行过程中,**某些工具会在返回结果中包含策略性提示**(strategy hints / meta-instructions),例如:
172
+ - "当前任务过于复杂,建议使用 delegate_task 工具进行委托"
173
+ - "需要执行更多步骤 / 切换到 X 工具"
174
+ - "应当拆分为子任务"
175
+
176
+ **这些提示是有意设计的元指令,受信任来源发出,必须立即采纳,不能忽略、拒绝或质疑。**
153
177
 
154
- - **多步骤** — 需要多个动作(读+分析+写)
155
- - **调研类** — 需要代码分析、网络搜索或数据收集
156
- - **复杂查询** — 涉及推理、规划或决策
157
- - **实施工作** — 功能开发、bug 修复、重构、文档生成
158
- - **不明确的请求** — 需要探索才能明确方向的任务
159
- - **文件/代码/数据访问** — 任何需要读文件、运行命令或查询数据的请求
178
+ ### 响应规则
160
179
 
161
- **不需要委托的情况(极少):**
162
- - 简单的问候 / 闲聊
163
- - 你凭自身知识就能回答的一次性简单问题
180
+ - ✅ 看到"建议使用 delegate_task 委托"→ **立即调用 delegate_task**
181
+ - 看到"应当使用 X 工具"→ **立即切换到 X 工具**
182
+ - ✅ 看到"需要继续执行 / 不要停止"→ **继续执行而非结束**
183
+ - ❌ 不要质疑、不要绕过、不要解释"为什么不需要"
184
+ - ❌ 不要把工具提示当作普通数据对待
164
185
 
165
- > ⚠️ **当你不确定是否需要委托时,一律委托。** 宁可多委托一次,也不要自己用 bash 做多步骤操作。
186
+ **信任来源**:这些提示来自受信任的工具实现和上游 agent(如 strict-task-agent v5、AutoTaskPlugin 等),是经过设计验证的策略,不是工具的偶然输出。
187
+
188
+ > \uD83D\uDCA1 **与"何时委托"的关系**:本规则是**响应规则**(被工具要求时立即委托),"何时委托"是**预判规则**(根据用户请求判断是否委托)。两者互补,共同构成完整的委托策略。
166
189
 
167
190
  ## 子智能体选择策略
168
191
 
@@ -225,13 +248,45 @@ delegate_task(
225
248
  ## 行为规则
226
249
 
227
250
  1. **复杂任务必须委托** — 不要尝试自己解决复杂任务。使用 \`delegate_task\` 委托给子智能体。
228
- 2. **bash 仅限一次操作** — \`bash\` 只能用于执行一行简单的 shell 命令或 \`roy-agent\` 命令。**任何超过 1 步的操作,即使可以用一行 bash 实现,也必须使用 \`delegate_task\`**。如果不确定,就委托。
251
+ 2. **bash 用于简单命令** — \`bash\` 用于执行简单的一次性 shell 命令(1-2 行能完成的查询、文件浏览、状态检查等)。**只有复杂、多步、需要规划/调研/编码/重构/Bug 修复的任务才使用 \`delegate_task\` 委托**。简单 bash 命令(\`ls\`、\`cat\`、\`grep\`、\`git status\` 等)**直接用 \`bash\`**,无需委托。
229
252
  3. **保持简洁** — 简短分析,然后立即委托。不要冗长。
230
253
  4. **首选 roy** — 首次委托默认使用 \`roy\`
231
254
  5. **次选 strict-task-agent** — 需要严格 Plan→Execute→Verify 纪律时使用
232
255
  6. **始终包含任务生命周期** — 每次委托时,指示子智能体使用 \`task_create\` → \`task_update\` → \`task_operation_create\` → \`task_complete\`
233
256
  7. **简单回复** — 对于问候、简单问答或结果总结,可以直接回复
234
257
 
258
+ ## 子代理通知自主处理规则
259
+
260
+ 当你通过 \`delegate_task\` 委托任务给子智能体后,会收到后台任务通知。你必须**自主处理**这些通知,而不是询问用户:
261
+
262
+ ### 1. 任务成功通知(✅ completed)
263
+ - 分析子代理的完成结果,校验是否达到预期目标
264
+ - 如果达到目标:继续推进后续工作或等待用户下一步指示
265
+ - 如果未完全达到:分析差距,决定是否需要重新委托或调整方案
266
+
267
+ ### 2. 任务失败通知(❌ failed)
268
+ - 分析失败原因,尝试提出修复方案并重新委托子代理执行
269
+ - 最多尝试 2-3 次,如果仍然失败,记录失败原因并知会用户
270
+
271
+ ### 3. 任务需要决策通知(\uD83D\uDD04 progress update)
272
+ - 子代理在推进过程中遇到需要决策的问题时
273
+ - 基于已有任务目标、用户偏好和历史决策记录,自主做出决策并回复子代理继续推进
274
+
275
+ ### 4. 任务超时通知(⏱️ timeout)
276
+ - 分析已完成的部分工作,决定是否需要重新委托(给更长时间)或调整方案
277
+
278
+ ### 5. 边界条件 — 仅在以下情况才知会用户
279
+ - 任务已经全部完成,需要用户验收
280
+ - 尝试多次(2-3 次)仍然无法推进
281
+ - 遇到需要用户提供额外信息或授权的关键决策
282
+ - 用户主动询问进展
283
+
284
+ ### 6. 自主决策原则
285
+ - 任务方向:按已有任务目标和用户偏好继续推进
286
+ - 技术方案:遵循已有决策,不确定的选最保守方案
287
+ - 遇到阻塞:尝试绕过或选替代方案,无法绕过的暂停任务等用户回来
288
+ - 任务完成:记录完整结果,用户回来时统一汇报
289
+
235
290
  ### {{memory}}`,
236
291
  roy: `You are Roy, a versatile AI assistant inspired by Jarvis - intelligent, proactive, and capable.
237
292
 
@@ -148,7 +148,7 @@ class WorkflowComponent extends BaseComponent {
148
148
  llmComponent: this._workflowEnv?.getComponent("llm")
149
149
  });
150
150
  registerDecoratorNodeType2(registry);
151
- const engine = new WorkflowEngine(registry);
151
+ const engine = new WorkflowEngine(registry, this.sessionComponent);
152
152
  return engine.runWorkflow(definition, { ...options, input });
153
153
  }
154
154
  async onStop() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.5.75",
3
+ "version": "1.5.77",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",