@ai-setting/roy-agent-core 1.5.79 → 1.5.81

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 (30) 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 +13 -13
  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 +4 -4
  7. package/dist/env/task/plugins/index.js +1 -1
  8. package/dist/env/task/tools/index.js +1 -1
  9. package/dist/env/workflow/engine/index.js +3 -3
  10. package/dist/env/workflow/index.js +5 -5
  11. package/dist/env/workflow/nodes/index.js +1 -1
  12. package/dist/env/workflow/tools/index.js +26 -142
  13. package/dist/env/workflow/utils/index.js +1 -1
  14. package/dist/index.js +14 -14
  15. package/dist/shared/@ai-setting/{roy-agent-core-jazhr292.js → roy-agent-core-6b0r2e7j.js} +2 -2
  16. package/dist/shared/@ai-setting/roy-agent-core-a6j7g1qe.js +428 -0
  17. package/dist/shared/@ai-setting/{roy-agent-core-7t0jen73.js → roy-agent-core-df3ng0pz.js} +6 -2
  18. package/dist/shared/@ai-setting/{roy-agent-core-0tgnq4nz.js → roy-agent-core-f6p7wwpd.js} +64 -5
  19. package/dist/shared/@ai-setting/{roy-agent-core-99j4w3fx.js → roy-agent-core-gb9gbkc3.js} +2 -0
  20. package/dist/shared/@ai-setting/{roy-agent-core-ajx32wzj.js → roy-agent-core-j754zgb4.js} +13 -0
  21. package/dist/shared/@ai-setting/{roy-agent-core-7mw366pc.js → roy-agent-core-j8q8119y.js} +1 -1
  22. package/dist/shared/@ai-setting/{roy-agent-core-zf62vkc4.js → roy-agent-core-mbre4fxg.js} +32 -1
  23. package/dist/shared/@ai-setting/{roy-agent-core-11dnsfwp.js → roy-agent-core-p8jv13bm.js} +2 -2
  24. package/dist/shared/@ai-setting/{roy-agent-core-4ws3w7cx.js → roy-agent-core-qbgd7bp6.js} +5 -2
  25. package/dist/shared/@ai-setting/{roy-agent-core-8x1gmqcv.js → roy-agent-core-t2q0rwt7.js} +3 -2
  26. package/dist/shared/@ai-setting/{roy-agent-core-s83ararq.js → roy-agent-core-v3t28k5n.js} +35 -3
  27. package/dist/shared/@ai-setting/{roy-agent-core-d32ecc9z.js → roy-agent-core-vgyj2rq9.js} +103 -1
  28. package/dist/shared/@ai-setting/{roy-agent-core-n9tw52zb.js → roy-agent-core-w83v54mj.js} +11 -6
  29. package/package.json +1 -1
  30. package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +0 -36
@@ -7,7 +7,7 @@ import {
7
7
  } from "./roy-agent-core-e25xkv53.js";
8
8
  import {
9
9
  AgentRegistry
10
- } from "./roy-agent-core-zf62vkc4.js";
10
+ } from "./roy-agent-core-mbre4fxg.js";
11
11
  import {
12
12
  ContextError
13
13
  } from "./roy-agent-core-ctdhjv68.js";
@@ -299,6 +299,8 @@ class AgentComponent extends BaseComponent {
299
299
  });
300
300
  const loadedCount = await this.registry.load();
301
301
  logger.info(`[AgentComponent] Loaded ${loadedCount} agents from config directory`);
302
+ this.registry.registerWorkflowAgent();
303
+ logger.info("[AgentComponent] Registered built-in workflow-agent");
302
304
  for (const agentDef of this.registry.list()) {
303
305
  if (!this.agents.has(agentDef.name)) {
304
306
  const systemPrompt = await this.registry.getSystemPrompt(agentDef.name);
@@ -550,6 +552,7 @@ class AgentComponent extends BaseComponent {
550
552
  ...context,
551
553
  agentType: agent.config.type,
552
554
  model: context?.model ?? agent.config.model,
555
+ traceId: context?.metadata?.traceId ?? context?.traceId,
553
556
  abort: abortController.signal
554
557
  };
555
558
  const result = {
@@ -1107,7 +1110,7 @@ ${additionInfo}`
1107
1110
  context: toolContext
1108
1111
  };
1109
1112
  let result;
1110
- const isLongRunningTool = toolName === "delegate_task" || toolName === "stop_task" || toolName === "bash";
1113
+ const isLongRunningTool = toolName === "delegate_task" || toolName === "stop_task" || toolName === "bash" || toolName === "workflow_run" || toolName === "run-workflow";
1111
1114
  const isExtraTool = this.toolComponent?.getTool ? !this.toolComponent.getTool(toolName) : false;
1112
1115
  if (isExtraTool) {
1113
1116
  logger.debug(`[executeTool] Tool "${toolName}" is an extraTool, executing directly`);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createAutoTaskPlugin
3
- } from "./roy-agent-core-n9tw52zb.js";
3
+ } from "./roy-agent-core-w83v54mj.js";
4
4
  import {
5
5
  ContextError,
6
6
  ErrorCodes
@@ -198,11 +198,12 @@ class BaseEnvironment extends BaseComponent {
198
198
  const llmRef = this.getComponent("llm");
199
199
  const toolRef = this.getComponent("tool");
200
200
  const autoTaskPlugin = createAutoTaskPlugin({
201
+ threshold: 30,
201
202
  llmComponent: llmRef ?? undefined,
202
203
  toolComponent: toolRef ?? undefined
203
204
  });
204
205
  agentComponent.registerPlugin("default", autoTaskPlugin);
205
- logger.info("[handle_query] AutoTaskPlugin v3 registered on default agent");
206
+ logger.info("[handle_query] AutoTaskPlugin v3 registered on default agent (threshold=30)");
206
207
  } catch (err) {
207
208
  logger.warn(`[handle_query] Failed to register AutoTaskPlugin: ${err}`);
208
209
  }
@@ -6,13 +6,18 @@ import {
6
6
  WorkflowEngine,
7
7
  exports_engine,
8
8
  init_engine
9
- } from "./roy-agent-core-jazhr292.js";
9
+ } from "./roy-agent-core-6b0r2e7j.js";
10
10
  import {
11
11
  WorkflowService
12
12
  } from "./roy-agent-core-4t40mkpv.js";
13
13
  import {
14
- askUserTool
15
- } from "./roy-agent-core-0vbdz0x7.js";
14
+ askUserTool,
15
+ createRunWorkflowTool,
16
+ createWorkflowGetTool,
17
+ createWorkflowListTool,
18
+ createWorkflowRunStatusTool,
19
+ createWorkflowRunStopTool
20
+ } from "./roy-agent-core-a6j7g1qe.js";
16
21
  import {
17
22
  BaseComponent
18
23
  } from "./roy-agent-core-rgckng3p.js";
@@ -173,6 +178,7 @@ class WorkflowComponent extends BaseComponent {
173
178
  await super.start();
174
179
  await this.initSqliteService();
175
180
  await this.registerAskUserTool();
181
+ await this.registerWorkflowTools();
176
182
  }
177
183
  async registerAskUserTool() {
178
184
  try {
@@ -194,6 +200,32 @@ class WorkflowComponent extends BaseComponent {
194
200
  componentLogger.warn("Failed to register ask_user tool:", error);
195
201
  }
196
202
  }
203
+ async registerWorkflowTools() {
204
+ if (!this.workflowService) {
205
+ componentLogger.warn("WorkflowService not initialized, cannot register workflow tools");
206
+ return;
207
+ }
208
+ try {
209
+ const toolComponent = this.toolComponent || this._workflowEnv?.getComponent("tool");
210
+ if (!toolComponent) {
211
+ componentLogger.warn("ToolComponent not available, cannot register workflow tools");
212
+ return;
213
+ }
214
+ const tools = [
215
+ createWorkflowGetTool(this.workflowService),
216
+ createWorkflowListTool(this.workflowService),
217
+ createRunWorkflowTool(this.workflowService),
218
+ createWorkflowRunStatusTool(this.workflowService),
219
+ createWorkflowRunStopTool(this.workflowService)
220
+ ];
221
+ for (const tool of tools) {
222
+ toolComponent.register(tool);
223
+ componentLogger.info(`[WorkflowComponent] Registered workflow tool: ${tool.name}`);
224
+ }
225
+ } catch (error) {
226
+ componentLogger.warn("Failed to register workflow tools:", error);
227
+ }
228
+ }
197
229
  async initSqliteService() {
198
230
  try {
199
231
  const { getDatabase, initializeTables } = await import("./roy-agent-core-74cp3zp1.js");
@@ -828,7 +828,109 @@ When reusing an existing task, you MUST follow these rules:
828
828
 
829
829
  # 输出要求
830
830
  直接调用 record_memory 工具,写入新的全局记忆。
831
- 输出格式为 Markdown,保持结构清晰。`
831
+ 输出格式为 Markdown,保持结构清晰。`,
832
+ "workflow-agent": `# Workflow 调度中介(Workflow Dispatch Mediator)
833
+
834
+ ## 你的身份
835
+
836
+ 你是 Roy 系统的 workflow 调度中介(entry-agent)。当 \`delegate_task\` 收到一个 workflow 类型的子智能体请求时,你被自动调用,负责将请求转交给合适的 workflow 执行。
837
+
838
+ - **类型**: primary(不是 subagent,不是 workflow,避免无限递归)
839
+ - **职责**: 仅做 workflow 调度,不做其他任何工作
840
+ - **边界**: 不要执行除 workflow 调度以外的任何任务
841
+
842
+ ## 工作目录
843
+
844
+ **workspace_dir**: {{workspace_dir}}
845
+
846
+ ## 可用工具
847
+
848
+ 你只有以下 5 个 workflow 相关工具可用:
849
+
850
+ 1. **\`workflow_list\`** — 列出所有已注册的 workflow
851
+ - 参数:tag(可选),search(可选),limit,offset
852
+ - 返回值:workflow 列表(名称、版本、描述、标签)
853
+
854
+ 2. **\`workflow_get\`** — 获取 workflow 定义详情
855
+ - 参数:\`name\`(workflow 名称)或 \`run_id\`(run ID)
856
+ - 返回值:workflow 定义(名称、版本、描述、入参 inputs schema、节点列表),或 run 的状态
857
+
858
+ 3. **\`workflow_run\`** — 运行 workflow
859
+ - 参数:\`workflow_name\`(必填),\`input\`(可选 JSON),\`sync\`(是否等待完成,默认 true),\`timeout\`(可选)
860
+ - 返回值:run_id, status, output, error, duration_ms
861
+
862
+ 4. **\`workflow_run_status\`** — 查询 run 状态
863
+ - 参数:\`run_id\`(必填)
864
+ - 返回值:run_id, status, output, error
865
+
866
+ 5. **\`workflow_run_stop\`** — 停止 run
867
+ - 参数:\`run_id\`(必填),\`reason\`(可选)
868
+ - 返回值:success 状态
869
+
870
+ ## 核心使命
871
+
872
+ 当被调用时,你会收到:
873
+
874
+ 1. **workflow 名称** — 来自 \`subagent_type\`(例如 \`strict-task-agent\` 对应 workflow \`strict-task-agent\`)
875
+ 2. **用户原始 prompt** — 上游 agent 传给 delegate_task 的请求内容
876
+ 3. **任务上下文** — session_id、trace_id 等元数据
877
+
878
+ 你的工作流程:
879
+
880
+ ### 步骤 1: 查询 workflow 详情
881
+
882
+ 调用 \`workflow_get\` 工具,传入 workflow 名称,读取其入参 schema。
883
+
884
+ ### 步骤 2: 提取用户输入
885
+
886
+ 从用户原始 prompt 中,**仅**提取符合 schema 的字段,组装为 JSON。
887
+ 如果 schema 要求必填字段但用户 prompt 中没有,**不要猜测**——直接 \`workflow_run\` 让 workflow 自己处理默认值或报错。
888
+
889
+ ### 步骤 3: 触发 workflow run
890
+
891
+ 调用 \`workflow_run\` 工具,传入 workflow 名称和 input JSON。
892
+
893
+ ### 步骤 4: 查询状态(如需)
894
+
895
+ 调用 \`workflow_run_status\` 查询执行结果。
896
+
897
+ ### 步骤 5: 返回结果
898
+
899
+ 把 workflow run 的输出原样返回给上游 caller。
900
+
901
+ ## 工作流程示例
902
+
903
+ \`\`\`
904
+ # 步骤 1: 查看 workflow 入参
905
+ workflow_get(name="strict-task-agent")
906
+ # → 返回 inputs 中包含 task_description (required), priority (optional)
907
+
908
+ # 步骤 2: 从 prompt 提取 input
909
+ # prompt: "修复登录bug,优先级高"
910
+ # → {"task_description": "修复登录bug", "priority": "high"}
911
+
912
+ # 步骤 3: 执行 workflow
913
+ workflow_run(workflow_name="strict-task-agent", input={"task_description": "修复登录bug", "priority": "high"})
914
+ # → 返回 run_id, status, output
915
+ \`\`\`
916
+
917
+ ## 严格约束
918
+
919
+ - ✅ **只**通过 \`workflow_run\` 工具执行 workflow
920
+ - ✅ 先调用 \`workflow_get\` 获取 schema,再调用 \`workflow_run\`
921
+ - ❌ 不要直接读 workflow YAML 文件并尝试自己解释
922
+ - ❌ 不要执行 workflow 调度以外的任何工作(写代码、查文件、做调研、改 bug 都不做)
923
+ - ❌ 不要修改 workflow 定义
924
+ - ❌ 不要使用 \`delegate_task\` 再次委托——你已经是最末端的执行者
925
+ - ❌ 不要使用 \`bash\` 或其他非 workflow 工具——你的工具列表只有 5 个 workflow 工具
926
+
927
+ ## 为什么需要这个中介
928
+
929
+ > 历史背景:在本次重构之前,\`delegate_task("strict-task-agent")\` 会被当作普通 subagent 直接执行,导致 subagent session 被创建但 workflow 引擎从未启动,session 内容是默认 subagent prompt 而不是 workflow run。本中介模式修复了这个 bug——所有 workflow 类型 subagent 的 delegate_task 都先经过本 agent,再走标准 \`workflow_run\` 路径。
930
+ >
931
+ > 设计文档:.roy/design/2026-06-29-workflow-subagent-entry-agent-design.md
932
+
933
+ 记住:你是 workflow 的"调度员",不是 workflow 本身。`
832
934
  };
833
935
  function getBuiltInPromptNames() {
834
936
  return Object.keys(builtInPrompts);
@@ -436,9 +436,11 @@ function createAutoTaskPlugin(config) {
436
436
  }
437
437
  for (const tc of toolCalls) {
438
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)}...)`);
439
442
  if (tcName !== "delegate_task")
440
443
  continue;
441
- const rawArgs = tc.function?.arguments ?? tc.arguments;
442
444
  try {
443
445
  const args = JSON.parse(typeof rawArgs === "string" ? rawArgs : JSON.stringify(rawArgs ?? {}));
444
446
  if (args.description && args.prompt) {
@@ -508,11 +510,14 @@ Call delegate_task now.`
508
510
  let args = await tryInvokeForDelegate(msgs, delegateToolInfo, model, sid);
509
511
  if (!args) {
510
512
  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);
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);
516
521
  }
517
522
  if (!args) {
518
523
  logger2.warn(`[AutoTaskPlugin] Failed to get delegate_task args after retry (session=${sid.slice(0, 12)}...)`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.5.79",
3
+ "version": "1.5.81",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",
@@ -1,36 +0,0 @@
1
- import {
2
- AskUserError,
3
- init_workflow_hil
4
- } from "./roy-agent-core-e25xkv53.js";
5
-
6
- // src/env/workflow/tools/ask-user-tool.ts
7
- init_workflow_hil();
8
- import { z } from "zod";
9
- var AskUserInputSchema = z.object({
10
- query: z.string().describe("The question or request to ask the user"),
11
- options: z.array(z.string()).optional().describe("Optional choices for the user"),
12
- required_confirm: z.boolean().optional().describe("If true, user must explicitly confirm")
13
- });
14
- var askUserTool = {
15
- name: "ask_user",
16
- description: "Ask user for input or confirmation. Use this tool when you need user input or validation to continue the workflow.",
17
- parameters: AskUserInputSchema,
18
- async execute(args, context) {
19
- const runId = context.metadata?.runId || "unknown";
20
- const sessionId = context.metadata?.sessionId || `workflow_${runId}`;
21
- const nodeId = context.metadata?.nodeId || "unknown";
22
- let fullQuery = args.query;
23
- if (args.options && args.options.length > 0) {
24
- fullQuery = `${args.query} (选项: ${args.options.join(", ")})`;
25
- }
26
- throw new AskUserError(runId, sessionId, nodeId, "agent", fullQuery);
27
- },
28
- metadata: {
29
- category: "workflow",
30
- tags: ["human-in-loop", "user-input"],
31
- version: "1.0.0"
32
- }
33
- };
34
- var askUserToolInstance = askUserTool;
35
-
36
- export { AskUserInputSchema, askUserTool, askUserToolInstance };