@ai-setting/roy-agent-core 1.5.46 → 1.5.48
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/agent/index.js +2 -2
- package/dist/env/index.js +9 -9
- package/dist/env/prompt/index.js +1 -1
- package/dist/env/task/delegate/index.js +2 -2
- package/dist/env/task/index.js +3 -3
- package/dist/env/workflow/engine/index.js +3 -3
- package/dist/env/workflow/index.js +4 -4
- package/dist/index.js +10 -10
- package/dist/shared/@ai-setting/{roy-agent-core-r9hq4cjx.js → roy-agent-core-00cpsj5z.js} +123 -2
- package/dist/shared/@ai-setting/{roy-agent-core-btvxttqf.js → roy-agent-core-1rzpnycm.js} +100 -3
- package/dist/shared/@ai-setting/{roy-agent-core-frjr619w.js → roy-agent-core-1t5esk1r.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-44g4dhzg.js → roy-agent-core-2rtka82a.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-3t82jyqb.js → roy-agent-core-38sc085e.js} +5 -7
- package/dist/shared/@ai-setting/{roy-agent-core-8y804aat.js → roy-agent-core-a5rhnsrg.js} +34 -21
- package/dist/shared/@ai-setting/{roy-agent-core-a67e90d1.js → roy-agent-core-cg23b692.js} +160 -3
- package/dist/shared/@ai-setting/{roy-agent-core-68qy97r3.js → roy-agent-core-ebap34m2.js} +6 -1
- package/dist/shared/@ai-setting/{roy-agent-core-fg3j215p.js → roy-agent-core-emk3q2nt.js} +24 -3
- package/dist/shared/@ai-setting/{roy-agent-core-6z063hns.js → roy-agent-core-g56g1jp6.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-dbxm76wf.js → roy-agent-core-kzbj10gk.js} +10 -3
- package/dist/shared/@ai-setting/{roy-agent-core-ye0z728h.js → roy-agent-core-twd8kzag.js} +3 -2
- package/package.json +2 -2
package/dist/env/agent/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentComponent,
|
|
3
3
|
AgentComponentConfigSchema
|
|
4
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
4
|
+
} from "../../shared/@ai-setting/roy-agent-core-38sc085e.js";
|
|
5
5
|
import"../../shared/@ai-setting/roy-agent-core-e25xkv53.js";
|
|
6
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
6
|
+
import"../../shared/@ai-setting/roy-agent-core-emk3q2nt.js";
|
|
7
7
|
import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
|
|
8
8
|
import"../../shared/@ai-setting/roy-agent-core-ctdhjv68.js";
|
|
9
9
|
import {
|
package/dist/env/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseEnvironment
|
|
3
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
3
|
+
} from "../shared/@ai-setting/roy-agent-core-00cpsj5z.js";
|
|
4
4
|
import {
|
|
5
5
|
EventSourceComponent,
|
|
6
6
|
builtInHandlers,
|
|
@@ -21,11 +21,11 @@ import"../shared/@ai-setting/roy-agent-core-4gmxjdhn.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-
|
|
24
|
+
} from "../shared/@ai-setting/roy-agent-core-1t5esk1r.js";
|
|
25
25
|
import"../shared/@ai-setting/roy-agent-core-9bmtxmp6.js";
|
|
26
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
27
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
28
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
26
|
+
import"../shared/@ai-setting/roy-agent-core-1rzpnycm.js";
|
|
27
|
+
import"../shared/@ai-setting/roy-agent-core-2rtka82a.js";
|
|
28
|
+
import"../shared/@ai-setting/roy-agent-core-kzbj10gk.js";
|
|
29
29
|
import"../shared/@ai-setting/roy-agent-core-6atd905e.js";
|
|
30
30
|
import"../shared/@ai-setting/roy-agent-core-v002ynpa.js";
|
|
31
31
|
import"../shared/@ai-setting/roy-agent-core-4t40mkpv.js";
|
|
@@ -38,15 +38,15 @@ import"../shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
|
|
|
38
38
|
import {
|
|
39
39
|
AgentComponent,
|
|
40
40
|
AgentComponentConfigSchema
|
|
41
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
41
|
+
} from "../shared/@ai-setting/roy-agent-core-38sc085e.js";
|
|
42
42
|
import"../shared/@ai-setting/roy-agent-core-e25xkv53.js";
|
|
43
43
|
import {
|
|
44
44
|
TaskComponent
|
|
45
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
45
|
+
} from "../shared/@ai-setting/roy-agent-core-g56g1jp6.js";
|
|
46
46
|
import"../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
|
|
47
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
47
|
+
import"../shared/@ai-setting/roy-agent-core-a5rhnsrg.js";
|
|
48
48
|
import"../shared/@ai-setting/roy-agent-core-hsxn8m1j.js";
|
|
49
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
49
|
+
import"../shared/@ai-setting/roy-agent-core-emk3q2nt.js";
|
|
50
50
|
import {
|
|
51
51
|
XDG_PATHS,
|
|
52
52
|
getXDGPath,
|
package/dist/env/prompt/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
PromptConfigSchema,
|
|
4
4
|
PromptPathSchema,
|
|
5
5
|
PromptRenderer
|
|
6
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
6
|
+
} from "../../shared/@ai-setting/roy-agent-core-cg23b692.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-6e3wz81d.js";
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
BackgroundTaskManager,
|
|
4
4
|
createDelegateTool,
|
|
5
5
|
createStopTool
|
|
6
|
-
} from "../../../shared/@ai-setting/roy-agent-core-
|
|
7
|
-
import"../../../shared/@ai-setting/roy-agent-core-
|
|
6
|
+
} from "../../../shared/@ai-setting/roy-agent-core-a5rhnsrg.js";
|
|
7
|
+
import"../../../shared/@ai-setting/roy-agent-core-emk3q2nt.js";
|
|
8
8
|
import"../../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
|
|
9
9
|
import"../../../shared/@ai-setting/roy-agent-core-92z6t4he.js";
|
|
10
10
|
import"../../../shared/@ai-setting/roy-agent-core-q5qj0fes.js";
|
package/dist/env/task/index.js
CHANGED
|
@@ -4,15 +4,15 @@ import {
|
|
|
4
4
|
TaskConfigSchema,
|
|
5
5
|
TaskPriorityEnum,
|
|
6
6
|
TaskStatusEnum
|
|
7
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
7
|
+
} from "../../shared/@ai-setting/roy-agent-core-g56g1jp6.js";
|
|
8
8
|
import {
|
|
9
9
|
TaskEntityEventTypes
|
|
10
10
|
} from "../../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
|
|
11
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
11
|
+
import"../../shared/@ai-setting/roy-agent-core-a5rhnsrg.js";
|
|
12
12
|
import {
|
|
13
13
|
SQLiteTaskStore
|
|
14
14
|
} from "../../shared/@ai-setting/roy-agent-core-hsxn8m1j.js";
|
|
15
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
15
|
+
import"../../shared/@ai-setting/roy-agent-core-emk3q2nt.js";
|
|
16
16
|
import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
|
|
17
17
|
import"../../shared/@ai-setting/roy-agent-core-wa1kzqky.js";
|
|
18
18
|
import"../../shared/@ai-setting/roy-agent-core-t94ktchq.js";
|
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
Scheduler,
|
|
7
7
|
WorkflowEngine,
|
|
8
8
|
init_engine
|
|
9
|
-
} from "../../../shared/@ai-setting/roy-agent-core-
|
|
10
|
-
import"../../../shared/@ai-setting/roy-agent-core-
|
|
11
|
-
import"../../../shared/@ai-setting/roy-agent-core-
|
|
9
|
+
} from "../../../shared/@ai-setting/roy-agent-core-1rzpnycm.js";
|
|
10
|
+
import"../../../shared/@ai-setting/roy-agent-core-2rtka82a.js";
|
|
11
|
+
import"../../../shared/@ai-setting/roy-agent-core-kzbj10gk.js";
|
|
12
12
|
import"../../../shared/@ai-setting/roy-agent-core-6atd905e.js";
|
|
13
13
|
import"../../../shared/@ai-setting/roy-agent-core-v002ynpa.js";
|
|
14
14
|
import"../../../shared/@ai-setting/roy-agent-core-6vxg2gmr.js";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WorkflowComponent
|
|
3
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
3
|
+
} from "../../shared/@ai-setting/roy-agent-core-1t5esk1r.js";
|
|
4
4
|
import"../../shared/@ai-setting/roy-agent-core-9bmtxmp6.js";
|
|
5
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
6
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
7
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
5
|
+
import"../../shared/@ai-setting/roy-agent-core-1rzpnycm.js";
|
|
6
|
+
import"../../shared/@ai-setting/roy-agent-core-2rtka82a.js";
|
|
7
|
+
import"../../shared/@ai-setting/roy-agent-core-kzbj10gk.js";
|
|
8
8
|
import"../../shared/@ai-setting/roy-agent-core-6atd905e.js";
|
|
9
9
|
import"../../shared/@ai-setting/roy-agent-core-v002ynpa.js";
|
|
10
10
|
import"../../shared/@ai-setting/roy-agent-core-4t40mkpv.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-
|
|
6
|
+
} from "./shared/@ai-setting/roy-agent-core-cg23b692.js";
|
|
7
7
|
import {
|
|
8
8
|
LLMComponent,
|
|
9
9
|
LLMConfigSchema,
|
|
@@ -61,7 +61,7 @@ import {
|
|
|
61
61
|
BaseEnvironment,
|
|
62
62
|
generateDescendingId,
|
|
63
63
|
generateId
|
|
64
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
64
|
+
} from "./shared/@ai-setting/roy-agent-core-00cpsj5z.js";
|
|
65
65
|
import {
|
|
66
66
|
EventSourceComponent,
|
|
67
67
|
builtInHandlers,
|
|
@@ -92,14 +92,14 @@ import {
|
|
|
92
92
|
} from "./shared/@ai-setting/roy-agent-core-az13yzmc.js";
|
|
93
93
|
import {
|
|
94
94
|
WorkflowComponent
|
|
95
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
95
|
+
} from "./shared/@ai-setting/roy-agent-core-1t5esk1r.js";
|
|
96
96
|
import {
|
|
97
97
|
init_node_registry_helper,
|
|
98
98
|
registerDecoratorNodeType
|
|
99
99
|
} from "./shared/@ai-setting/roy-agent-core-9bmtxmp6.js";
|
|
100
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
101
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
102
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
100
|
+
import"./shared/@ai-setting/roy-agent-core-1rzpnycm.js";
|
|
101
|
+
import"./shared/@ai-setting/roy-agent-core-2rtka82a.js";
|
|
102
|
+
import"./shared/@ai-setting/roy-agent-core-kzbj10gk.js";
|
|
103
103
|
import"./shared/@ai-setting/roy-agent-core-6atd905e.js";
|
|
104
104
|
import"./shared/@ai-setting/roy-agent-core-v002ynpa.js";
|
|
105
105
|
import"./shared/@ai-setting/roy-agent-core-4t40mkpv.js";
|
|
@@ -118,20 +118,20 @@ import"./shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
|
|
|
118
118
|
import {
|
|
119
119
|
AgentComponent,
|
|
120
120
|
AgentComponentConfigSchema
|
|
121
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
121
|
+
} from "./shared/@ai-setting/roy-agent-core-38sc085e.js";
|
|
122
122
|
import {
|
|
123
123
|
AskUserError,
|
|
124
124
|
init_workflow_hil
|
|
125
125
|
} from "./shared/@ai-setting/roy-agent-core-e25xkv53.js";
|
|
126
126
|
import {
|
|
127
127
|
TaskComponent
|
|
128
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
128
|
+
} from "./shared/@ai-setting/roy-agent-core-g56g1jp6.js";
|
|
129
129
|
import"./shared/@ai-setting/roy-agent-core-8gxth0eh.js";
|
|
130
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
130
|
+
import"./shared/@ai-setting/roy-agent-core-a5rhnsrg.js";
|
|
131
131
|
import"./shared/@ai-setting/roy-agent-core-hsxn8m1j.js";
|
|
132
132
|
import {
|
|
133
133
|
AgentRegistry
|
|
134
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
134
|
+
} from "./shared/@ai-setting/roy-agent-core-emk3q2nt.js";
|
|
135
135
|
import {
|
|
136
136
|
XDG_PATHS,
|
|
137
137
|
getXDGPath,
|
|
@@ -82,6 +82,14 @@ class BaseEnvironment extends BaseComponent {
|
|
|
82
82
|
if (!agentComponent) {
|
|
83
83
|
throw new Error("AgentComponent not found. Please register AgentComponent before calling handle_query.");
|
|
84
84
|
}
|
|
85
|
+
const agentName = context?.agentType && context.agentType !== "default" ? context.agentType : "default";
|
|
86
|
+
const registry = agentComponent.getRegistry?.();
|
|
87
|
+
if (registry) {
|
|
88
|
+
const agentDef = registry.get(agentName);
|
|
89
|
+
if (agentDef?.type === "workflow") {
|
|
90
|
+
return await this.handleWorkflowAgentQuery(agentName, query, agentComponent);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
85
93
|
let systemPrompt = "You are a helpful assistant.";
|
|
86
94
|
let promptSource = "fallback";
|
|
87
95
|
try {
|
|
@@ -118,7 +126,6 @@ class BaseEnvironment extends BaseComponent {
|
|
|
118
126
|
finalSystemPrompt = finalSystemPrompt.replace("{{workspace_dir}}", workspaceDir);
|
|
119
127
|
logger.debug(`[handle_query] Injected workspace_dir: ${workspaceDir}`);
|
|
120
128
|
}
|
|
121
|
-
const agentName = context?.agentType && context.agentType !== "default" ? context.agentType : "default";
|
|
122
129
|
let agent = agentComponent.getAgent(agentName);
|
|
123
130
|
if (!agent) {
|
|
124
131
|
if (agentName !== "default") {
|
|
@@ -127,10 +134,71 @@ class BaseEnvironment extends BaseComponent {
|
|
|
127
134
|
agent = agentComponent.getAgent("default");
|
|
128
135
|
}
|
|
129
136
|
if (!agent) {
|
|
137
|
+
const defaultDeniedTools = [
|
|
138
|
+
"echo",
|
|
139
|
+
"glob",
|
|
140
|
+
"grep",
|
|
141
|
+
"read_file",
|
|
142
|
+
"write_file",
|
|
143
|
+
"edit_file",
|
|
144
|
+
"task_create",
|
|
145
|
+
"task_get",
|
|
146
|
+
"task_list",
|
|
147
|
+
"task_update",
|
|
148
|
+
"task_delete",
|
|
149
|
+
"task_complete",
|
|
150
|
+
"task_operation_create",
|
|
151
|
+
"task_operation_get",
|
|
152
|
+
"task_operation_list",
|
|
153
|
+
"task_operation_update",
|
|
154
|
+
"task_operation_delete",
|
|
155
|
+
"skill",
|
|
156
|
+
"record_memory",
|
|
157
|
+
"recall_memory",
|
|
158
|
+
"search_sessions",
|
|
159
|
+
"get_session",
|
|
160
|
+
"write_memory"
|
|
161
|
+
];
|
|
162
|
+
try {
|
|
163
|
+
const toolComponent = this.getComponent("tool");
|
|
164
|
+
if (toolComponent?.listTools) {
|
|
165
|
+
const allTools = toolComponent.listTools();
|
|
166
|
+
const mcpTools = allTools.filter((t) => t.name.startsWith("mcp_")).map((t) => t.name);
|
|
167
|
+
if (mcpTools.length > 0) {
|
|
168
|
+
defaultDeniedTools.push(...mcpTools);
|
|
169
|
+
logger.debug(`[handle_query] Dynamically denied MCP tools: ${mcpTools.join(", ")}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
} catch (err) {
|
|
173
|
+
logger.warn(`[handle_query] Failed to dynamically filter MCP tools: ${err}`);
|
|
174
|
+
}
|
|
130
175
|
agent = agentComponent.registerAgent("default", {
|
|
131
176
|
type: "primary",
|
|
132
|
-
systemPrompt: finalSystemPrompt
|
|
177
|
+
systemPrompt: finalSystemPrompt,
|
|
178
|
+
deniedTools: defaultDeniedTools
|
|
133
179
|
});
|
|
180
|
+
logger.info(`[handle_query] Created default receptionist agent with deniedTools: ${defaultDeniedTools.length} tools denied`);
|
|
181
|
+
} else {
|
|
182
|
+
if (agent.config?.systemPrompt) {
|
|
183
|
+
if (agent.config.systemPrompt.includes("{{memory}}")) {
|
|
184
|
+
try {
|
|
185
|
+
const memoryComponent = this.getComponent("memory");
|
|
186
|
+
if (memoryComponent) {
|
|
187
|
+
const memoryContent = await memoryComponent.recallMemory();
|
|
188
|
+
agent.config.systemPrompt = agent.config.systemPrompt.replace("{{memory}}", memoryContent || "(No memory)");
|
|
189
|
+
} else {
|
|
190
|
+
agent.config.systemPrompt = agent.config.systemPrompt.replace("{{memory}}", "(Memory component not available)");
|
|
191
|
+
}
|
|
192
|
+
} catch (err) {
|
|
193
|
+
logger.warn(`[handle_query] Failed to inject memory for agent ${agentName}: ${err}`);
|
|
194
|
+
agent.config.systemPrompt = agent.config.systemPrompt.replace("{{memory}}", "(Failed to load memory)");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (agent.config.systemPrompt.includes("{{workspace_dir}}")) {
|
|
198
|
+
agent.config.systemPrompt = agent.config.systemPrompt.replace("{{workspace_dir}}", process.cwd());
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
logger.debug(`[handle_query] Injected memory/workspace_dir for existing agent: ${agentName}`);
|
|
134
202
|
}
|
|
135
203
|
const result = await agentComponent.run(agent.name, query, context);
|
|
136
204
|
if (result.error) {
|
|
@@ -155,6 +223,56 @@ class BaseEnvironment extends BaseComponent {
|
|
|
155
223
|
}
|
|
156
224
|
return result.finalText || "";
|
|
157
225
|
}
|
|
226
|
+
async handleWorkflowAgentQuery(agentName, query, agentComponent) {
|
|
227
|
+
const registry = agentComponent.getRegistry?.();
|
|
228
|
+
if (!registry) {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
const agentDef = registry.get(agentName);
|
|
232
|
+
if (!agentDef || agentDef.type !== "workflow") {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
const workflowComponent = this.getComponent("workflow");
|
|
236
|
+
if (!workflowComponent) {
|
|
237
|
+
throw new Error(`WorkflowComponent not available — cannot run workflow agent "${agentName}". ` + `Ensure the workflow component is registered.`);
|
|
238
|
+
}
|
|
239
|
+
const workflowName = agentDef.workflow;
|
|
240
|
+
if (!workflowName) {
|
|
241
|
+
throw new Error(`Agent "${agentName}" has type 'workflow' but no workflow configured.`);
|
|
242
|
+
}
|
|
243
|
+
const svc = workflowComponent.getService?.();
|
|
244
|
+
if (!svc || typeof svc.getWorkflowByName !== "function") {
|
|
245
|
+
throw new Error(`WorkflowService not available. Cannot run workflow agent "${agentName}".`);
|
|
246
|
+
}
|
|
247
|
+
const workflow = svc.getWorkflowByName(workflowName);
|
|
248
|
+
if (!workflow) {
|
|
249
|
+
throw new Error(`Workflow "${workflowName}" not found. ` + `Use 'roy-agent workflow add' to register it first.`);
|
|
250
|
+
}
|
|
251
|
+
const wfResult = await workflowComponent.runWorkflow(workflow.definition, { query }, {});
|
|
252
|
+
if (wfResult.status === "paused") {
|
|
253
|
+
return JSON.stringify({
|
|
254
|
+
status: "paused",
|
|
255
|
+
message: `Workflow "${workflowName}" paused, waiting for user input.`,
|
|
256
|
+
pendingNodeId: wfResult.pendingNodeId,
|
|
257
|
+
query: wfResult.query,
|
|
258
|
+
sessionId: wfResult.sessionId,
|
|
259
|
+
hint: `Resume with: roy-agent workflow run -s ${wfResult.sessionId} --input "your response"`
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
if (wfResult.status === "failed") {
|
|
263
|
+
throw new Error(`Workflow "${workflowName}" execution failed: ${wfResult.error || "Unknown error (status: " + wfResult.status + ")"}`);
|
|
264
|
+
}
|
|
265
|
+
if (typeof wfResult.output === "string") {
|
|
266
|
+
return wfResult.output;
|
|
267
|
+
}
|
|
268
|
+
if (wfResult.output !== undefined && wfResult.output !== null) {
|
|
269
|
+
return JSON.stringify(wfResult.output);
|
|
270
|
+
}
|
|
271
|
+
if (wfResult.error) {
|
|
272
|
+
throw new Error(`Workflow "${workflowName}" completed with error: ${wfResult.error}`);
|
|
273
|
+
}
|
|
274
|
+
return "";
|
|
275
|
+
}
|
|
158
276
|
async handle_action(action, context) {
|
|
159
277
|
throw new Error("handle_action not implemented. Override in subclass.");
|
|
160
278
|
}
|
|
@@ -424,6 +542,9 @@ class BaseEnvironment extends BaseComponent {
|
|
|
424
542
|
__legacyDecorateClassTS([
|
|
425
543
|
TracedAs("env.handle_query", { recordParams: true, recordResult: true, log: true })
|
|
426
544
|
], BaseEnvironment.prototype, "handle_query", null);
|
|
545
|
+
__legacyDecorateClassTS([
|
|
546
|
+
TracedAs("env.handle_workflow_agent_query", { recordParams: true, recordResult: true, log: true })
|
|
547
|
+
], BaseEnvironment.prototype, "handleWorkflowAgentQuery", null);
|
|
427
548
|
|
|
428
549
|
// src/env/index.ts
|
|
429
550
|
init_context();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentComponentAdapter,
|
|
3
3
|
init_agent_component_adapter
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-2rtka82a.js";
|
|
5
5
|
import {
|
|
6
6
|
buildWorkflowNodeMetadata,
|
|
7
7
|
getWorkflowNodeIdFromMetadata,
|
|
@@ -1136,6 +1136,7 @@ function extractAgentJsonOutput(agentResult, schema) {
|
|
|
1136
1136
|
const candidates = [
|
|
1137
1137
|
agentResult.structuredOutput,
|
|
1138
1138
|
asRecord(agentResult.output),
|
|
1139
|
+
extractFromOutputText(agentResult.output),
|
|
1139
1140
|
extractFromToolCalls(agentResult),
|
|
1140
1141
|
extractFromMessages(agentResult.messages)
|
|
1141
1142
|
];
|
|
@@ -1153,6 +1154,66 @@ function asRecord(value) {
|
|
|
1153
1154
|
}
|
|
1154
1155
|
return;
|
|
1155
1156
|
}
|
|
1157
|
+
function extractFromOutputText(output) {
|
|
1158
|
+
if (typeof output !== "string" || !output.trim()) {
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
const trimmed = output.trim();
|
|
1162
|
+
try {
|
|
1163
|
+
const parsed = JSON.parse(trimmed);
|
|
1164
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1165
|
+
return parsed;
|
|
1166
|
+
}
|
|
1167
|
+
} catch {}
|
|
1168
|
+
const jsonBlockMatch = trimmed.match(/```(?:json)?\s*\n?(\{[\s\S]*?\})\n?\s*```/);
|
|
1169
|
+
if (jsonBlockMatch) {
|
|
1170
|
+
try {
|
|
1171
|
+
const parsed = JSON.parse(jsonBlockMatch[1]);
|
|
1172
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1173
|
+
return parsed;
|
|
1174
|
+
}
|
|
1175
|
+
} catch {}
|
|
1176
|
+
}
|
|
1177
|
+
for (let i = 0;i < trimmed.length; i++) {
|
|
1178
|
+
if (trimmed[i] !== "{")
|
|
1179
|
+
continue;
|
|
1180
|
+
let depth = 0;
|
|
1181
|
+
let inString = false;
|
|
1182
|
+
let escape = false;
|
|
1183
|
+
for (let j = i;j < trimmed.length; j++) {
|
|
1184
|
+
const ch = trimmed[j];
|
|
1185
|
+
if (escape) {
|
|
1186
|
+
escape = false;
|
|
1187
|
+
continue;
|
|
1188
|
+
}
|
|
1189
|
+
if (ch === "\\" && inString) {
|
|
1190
|
+
escape = true;
|
|
1191
|
+
continue;
|
|
1192
|
+
}
|
|
1193
|
+
if (ch === '"') {
|
|
1194
|
+
inString = !inString;
|
|
1195
|
+
continue;
|
|
1196
|
+
}
|
|
1197
|
+
if (inString)
|
|
1198
|
+
continue;
|
|
1199
|
+
if (ch === "{")
|
|
1200
|
+
depth++;
|
|
1201
|
+
else if (ch === "}")
|
|
1202
|
+
depth--;
|
|
1203
|
+
if (depth === 0) {
|
|
1204
|
+
const candidate = trimmed.slice(i, j + 1);
|
|
1205
|
+
try {
|
|
1206
|
+
const parsed = JSON.parse(candidate);
|
|
1207
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1208
|
+
return parsed;
|
|
1209
|
+
}
|
|
1210
|
+
} catch {}
|
|
1211
|
+
break;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1156
1217
|
function extractFromToolCalls(agentResult) {
|
|
1157
1218
|
const toolCalls = agentResult.metadata?.toolCallsDetail;
|
|
1158
1219
|
if (!toolCalls?.length) {
|
|
@@ -1216,7 +1277,18 @@ function buildAgentNodeOutput(agentResult, outputConfig) {
|
|
|
1216
1277
|
const schema = outputConfig.schema;
|
|
1217
1278
|
const jsonData = extractAgentJsonOutput(agentResult, schema);
|
|
1218
1279
|
if (!jsonData) {
|
|
1219
|
-
|
|
1280
|
+
const defaults = buildSchemaDefaults(schema);
|
|
1281
|
+
const fallbackData = { ...defaults, rawOutput: agentResult.output };
|
|
1282
|
+
return {
|
|
1283
|
+
result: fallbackData,
|
|
1284
|
+
...fallbackData,
|
|
1285
|
+
metadata: {
|
|
1286
|
+
...agentResult.metadata,
|
|
1287
|
+
outputMode: "json_fallback",
|
|
1288
|
+
_extractionWarning: "JSON extraction failed, using defaults"
|
|
1289
|
+
},
|
|
1290
|
+
workflowHistory: agentResult.messages
|
|
1291
|
+
};
|
|
1220
1292
|
}
|
|
1221
1293
|
return {
|
|
1222
1294
|
result: jsonData,
|
|
@@ -1233,6 +1305,31 @@ function buildAgentNodeOutput(agentResult, outputConfig) {
|
|
|
1233
1305
|
...base
|
|
1234
1306
|
};
|
|
1235
1307
|
}
|
|
1308
|
+
function buildSchemaDefaults(schema) {
|
|
1309
|
+
const defaults = {};
|
|
1310
|
+
if (!schema?.properties || !schema?.required)
|
|
1311
|
+
return defaults;
|
|
1312
|
+
for (const key of schema.required) {
|
|
1313
|
+
const prop = schema.properties[key];
|
|
1314
|
+
if (!prop?.type)
|
|
1315
|
+
continue;
|
|
1316
|
+
switch (prop.type) {
|
|
1317
|
+
case "boolean":
|
|
1318
|
+
defaults[key] = false;
|
|
1319
|
+
break;
|
|
1320
|
+
case "string":
|
|
1321
|
+
defaults[key] = "";
|
|
1322
|
+
break;
|
|
1323
|
+
case "number":
|
|
1324
|
+
case "integer":
|
|
1325
|
+
defaults[key] = 0;
|
|
1326
|
+
break;
|
|
1327
|
+
default:
|
|
1328
|
+
defaults[key] = null;
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
return defaults;
|
|
1332
|
+
}
|
|
1236
1333
|
var init_build_agent_node_output = __esm(() => {
|
|
1237
1334
|
init_extract_agent_json_output();
|
|
1238
1335
|
});
|
|
@@ -1292,7 +1389,7 @@ var init_agent_node = __esm(() => {
|
|
|
1292
1389
|
await context.attachAgentSessionToLastStart(this.definition.id, agentSessionId);
|
|
1293
1390
|
}
|
|
1294
1391
|
}
|
|
1295
|
-
const allowedTools = ["ask_user"];
|
|
1392
|
+
const allowedTools = options.allowedTools?.length ? options.allowedTools : ["ask_user"];
|
|
1296
1393
|
const agentConfig = {
|
|
1297
1394
|
type: agentType,
|
|
1298
1395
|
prompt: resolvedPrompt,
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
WorkflowEngine,
|
|
7
7
|
exports_engine,
|
|
8
8
|
init_engine
|
|
9
|
-
} from "./roy-agent-core-
|
|
9
|
+
} from "./roy-agent-core-1rzpnycm.js";
|
|
10
10
|
import {
|
|
11
11
|
WorkflowService
|
|
12
12
|
} from "./roy-agent-core-4t40mkpv.js";
|
|
@@ -136,7 +136,7 @@ class WorkflowComponent extends BaseComponent {
|
|
|
136
136
|
const agentComponent = this._workflowEnv.getComponent("agent");
|
|
137
137
|
const llmComponent = this._workflowEnv.getComponent("llm");
|
|
138
138
|
if (agentComponent) {
|
|
139
|
-
const { AgentComponentAdapter } = await import("./roy-agent-core-
|
|
139
|
+
const { AgentComponentAdapter } = await import("./roy-agent-core-twd8kzag.js");
|
|
140
140
|
agentRunner = new AgentComponentAdapter(agentComponent, {}, this.sessionComponent, llmComponent);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
@@ -208,7 +208,7 @@ class WorkflowComponent extends BaseComponent {
|
|
|
208
208
|
const sessionComponent = this._workflowEnv?.getComponent("session");
|
|
209
209
|
componentLogger.info(`initSqliteService - toolComponent: ${!!toolComponent}, llmComponent: ${!!llmComponent}, skillRegistry: ${!!skillComponent}, sessionComponent: ${!!sessionComponent}`);
|
|
210
210
|
if (llmComponent) {
|
|
211
|
-
const { registerWorkflowJsonOutputPlugin } = await import("./roy-agent-core-
|
|
211
|
+
const { registerWorkflowJsonOutputPlugin } = await import("./roy-agent-core-ebap34m2.js");
|
|
212
212
|
registerWorkflowJsonOutputPlugin(llmComponent);
|
|
213
213
|
}
|
|
214
214
|
this.createService({
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WORKFLOW_JSON_OUTPUT_PLUGIN_KEY,
|
|
3
|
-
extractStructuredJsonViaLlm,
|
|
4
3
|
init_workflow_json_output_plugin,
|
|
5
|
-
registerWorkflowJsonOutputPlugin
|
|
6
|
-
|
|
4
|
+
registerWorkflowJsonOutputPlugin,
|
|
5
|
+
tracedExtractStructuredJsonViaLlm
|
|
6
|
+
} from "./roy-agent-core-kzbj10gk.js";
|
|
7
7
|
import {
|
|
8
8
|
AskUserError,
|
|
9
9
|
init_workflow_hil
|
|
@@ -229,7 +229,7 @@ class AgentComponentAdapter {
|
|
|
229
229
|
role: m.role,
|
|
230
230
|
content: m.content ?? ""
|
|
231
231
|
}));
|
|
232
|
-
return await
|
|
232
|
+
return await tracedExtractStructuredJsonViaLlm(this._llmComponent, history, outputSchema, {
|
|
233
233
|
model: config.options?.model,
|
|
234
234
|
sessionId: agentSessionId
|
|
235
235
|
});
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./roy-agent-core-e25xkv53.js";
|
|
5
5
|
import {
|
|
6
6
|
AgentRegistry
|
|
7
|
-
} from "./roy-agent-core-
|
|
7
|
+
} from "./roy-agent-core-emk3q2nt.js";
|
|
8
8
|
import {
|
|
9
9
|
ContextError
|
|
10
10
|
} from "./roy-agent-core-ctdhjv68.js";
|
|
@@ -889,12 +889,10 @@ class AgentComponent extends BaseComponent {
|
|
|
889
889
|
sessionId: effectiveContext.sessionId,
|
|
890
890
|
summary: result.finalText
|
|
891
891
|
};
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
if (hookCtx.structuredOutputExtracted) {
|
|
897
|
-
result.structuredOutput = hookCtx.structuredOutputExtracted;
|
|
892
|
+
const mergedHookCtx = { ...hookCtx, ...reactContext };
|
|
893
|
+
await this.executePluginHooks(agent, "agent:after.react", mergedHookCtx);
|
|
894
|
+
if (mergedHookCtx.structuredOutputExtracted) {
|
|
895
|
+
result.structuredOutput = mergedHookCtx.structuredOutputExtracted;
|
|
898
896
|
}
|
|
899
897
|
await this.executePluginHooks(agent, "agent:after.complete", hookCtx);
|
|
900
898
|
if (this.aborted.get(runId) === true || hookCtx._stopped) {
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_SUBAGENT_PROMPT
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-emk3q2nt.js";
|
|
4
4
|
import {
|
|
5
5
|
TaskHookPoints
|
|
6
6
|
} from "./roy-agent-core-92z6t4he.js";
|
|
7
|
+
import {
|
|
8
|
+
TracedAs,
|
|
9
|
+
init_decorator
|
|
10
|
+
} from "./roy-agent-core-q5qj0fes.js";
|
|
7
11
|
import {
|
|
8
12
|
globalHookManager,
|
|
9
13
|
init_global_hook_manager
|
|
@@ -12,9 +16,13 @@ import {
|
|
|
12
16
|
createLogger,
|
|
13
17
|
init_logger
|
|
14
18
|
} from "./roy-agent-core-10n2jh7p.js";
|
|
19
|
+
import {
|
|
20
|
+
__legacyDecorateClassTS
|
|
21
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
15
22
|
|
|
16
23
|
// src/env/task/delegate/delegate-tool.ts
|
|
17
24
|
init_logger();
|
|
25
|
+
init_decorator();
|
|
18
26
|
import { z } from "zod";
|
|
19
27
|
|
|
20
28
|
// src/env/task/delegate/subagent-resolver.ts
|
|
@@ -65,8 +73,14 @@ ${customAgentNote}
|
|
|
65
73
|
}
|
|
66
74
|
function listKnownSubagentDescriptions(registry) {
|
|
67
75
|
const builtInLines = builtInSubAgents.map((agent) => `- ${agent.id}: ${agent.description}`);
|
|
68
|
-
const registryAgents = registry?.
|
|
69
|
-
const customLines = registryAgents.filter((agent) => !builtInSubAgents.some((builtIn) => builtIn.id === agent.name)).map((agent) =>
|
|
76
|
+
const registryAgents = registry?.list() ?? [];
|
|
77
|
+
const customLines = registryAgents.filter((agent) => !builtInSubAgents.some((builtIn) => builtIn.id === agent.name)).map((agent) => {
|
|
78
|
+
if (agent.type === "workflow") {
|
|
79
|
+
const workflowInfo = agent.workflow ? ` (workflow: ${agent.workflow})` : "";
|
|
80
|
+
return `- ${agent.name}: ${agent.description || "Workflow agent"}${workflowInfo}`;
|
|
81
|
+
}
|
|
82
|
+
return `- ${agent.name}: ${agent.description || "Custom agent"}`;
|
|
83
|
+
});
|
|
70
84
|
const lines = [...builtInLines, ...customLines];
|
|
71
85
|
const guidance = buildAgentSelectionGuide({ hasCustomAgents: customLines.length > 0 });
|
|
72
86
|
return lines.join(`
|
|
@@ -141,28 +155,20 @@ var builtInSubAgents = [
|
|
|
141
155
|
description: "Fast agent specialized for exploring codebases, finding files, and searching for patterns.",
|
|
142
156
|
allowedTools: ["glob", "grep", "read", "bash"],
|
|
143
157
|
deniedTools: ["delegate_task", "stop_task"]
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
id: "file_agent",
|
|
147
|
-
name: "file_agent",
|
|
148
|
-
mode: "subagent",
|
|
149
|
-
description: "File operation expert, skilled at reading, writing, searching and organizing files.",
|
|
150
|
-
allowedTools: ["file_read", "file_write", "file_glob", "grep", "glob", "read"],
|
|
151
|
-
deniedTools: ["delegate_task", "stop_task"]
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
id: "web_search_agent",
|
|
155
|
-
name: "web_search_agent",
|
|
156
|
-
mode: "subagent",
|
|
157
|
-
description: "Web search expert, using Exa search engine to get latest information.",
|
|
158
|
-
allowedTools: ["exa_web_search_exa"],
|
|
159
|
-
deniedTools: ["delegate_task", "stop_task"]
|
|
160
158
|
}
|
|
161
159
|
];
|
|
162
160
|
function getSubAgentSpec(id) {
|
|
163
161
|
return builtInSubAgents.find((agent) => agent.id === id);
|
|
164
162
|
}
|
|
165
163
|
function ensureSubAgentRegistered(agentComponent, subagentType, basePrompt, subAgent, deniedTools) {
|
|
164
|
+
const registry = agentComponent.getRegistry?.();
|
|
165
|
+
if (registry) {
|
|
166
|
+
const agentDef = registry.get(subagentType);
|
|
167
|
+
if (agentDef?.type === "workflow") {
|
|
168
|
+
logger.debug(`[delegate] Skipping registration for workflow agent: ${subagentType}`);
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
166
172
|
let agentInstance = agentComponent.getAgent(subagentType);
|
|
167
173
|
if (!agentInstance) {
|
|
168
174
|
const agentConfig = {
|
|
@@ -444,6 +450,8 @@ ${prompt}
|
|
|
444
450
|
deniedTools
|
|
445
451
|
} : undefined;
|
|
446
452
|
ensureSubAgentRegistered(agentComponent, subagentType, basePrompt, subAgentForRegister, deniedTools);
|
|
453
|
+
const isWorkflowAgent = registry?.get(subagentType)?.type === "workflow";
|
|
454
|
+
const delegateQuery = isWorkflowAgent ? prompt : fullPrompt;
|
|
447
455
|
return new Promise((resolve, reject) => {
|
|
448
456
|
const timer = setTimeout(() => {
|
|
449
457
|
reject(new Error(`Task execution timeout after ${timeoutMs}ms`));
|
|
@@ -452,7 +460,7 @@ ${prompt}
|
|
|
452
460
|
clearTimeout(timer);
|
|
453
461
|
reject(new Error("Task execution stopped"));
|
|
454
462
|
});
|
|
455
|
-
this.env.handle_query?.(
|
|
463
|
+
this.env.handle_query?.(delegateQuery, {
|
|
456
464
|
sessionId,
|
|
457
465
|
deniedTools: deniedTools.length > 0 ? deniedTools : undefined,
|
|
458
466
|
agentType: subagentType
|
|
@@ -509,6 +517,9 @@ ${prompt}
|
|
|
509
517
|
logger.info(`[BackgroundTaskManager] Disposed`);
|
|
510
518
|
}
|
|
511
519
|
}
|
|
520
|
+
__legacyDecorateClassTS([
|
|
521
|
+
TracedAs("delegate.executeWithAbort", { recordParams: true, recordResult: true, log: true })
|
|
522
|
+
], BackgroundTaskManager.prototype, "executeWithAbort", null);
|
|
512
523
|
function getAgentRegistry(taskComponent) {
|
|
513
524
|
const agentComponent = taskComponent.env?.getComponent?.("agent");
|
|
514
525
|
return agentComponent?.getRegistry?.();
|
|
@@ -675,11 +686,13 @@ ${prompt}
|
|
|
675
686
|
deniedTools
|
|
676
687
|
} : undefined;
|
|
677
688
|
ensureSubAgentRegistered(agentComponent, subagentType, basePrompt, subAgentForRegister, deniedTools);
|
|
689
|
+
const isWorkflowAgent = registry?.get(subagentType)?.type === "workflow";
|
|
690
|
+
const delegateQuery = isWorkflowAgent ? prompt : fullPrompt;
|
|
678
691
|
const timeoutMs = timeout || DEFAULT_TIMEOUT;
|
|
679
692
|
let result;
|
|
680
693
|
try {
|
|
681
694
|
result = await Promise.race([
|
|
682
|
-
taskComponent.env?.handle_query?.(
|
|
695
|
+
taskComponent.env?.handle_query?.(delegateQuery, {
|
|
683
696
|
sessionId: subSession.id,
|
|
684
697
|
deniedTools: deniedTools.length > 0 ? deniedTools : undefined,
|
|
685
698
|
agentType: subagentType
|
|
@@ -81,7 +81,133 @@ function escapeRegex(str) {
|
|
|
81
81
|
|
|
82
82
|
// src/env/prompt/prompts-index.ts
|
|
83
83
|
var builtInPrompts = {
|
|
84
|
-
default:
|
|
84
|
+
default: `你是 Roy 接待智能体(Receptionist Agent)—— Roy 系统的智能入口。
|
|
85
|
+
|
|
86
|
+
## 工作目录
|
|
87
|
+
|
|
88
|
+
**workspace_dir**: {{workspace_dir}}
|
|
89
|
+
|
|
90
|
+
## 你的身份
|
|
91
|
+
|
|
92
|
+
- **名称**: Roy(接待员)
|
|
93
|
+
- **角色**: 入口 AI 助手,分析用户请求并将其委托给合适的子智能体执行
|
|
94
|
+
- **个性**: 友好、善于分析、高效、简洁
|
|
95
|
+
|
|
96
|
+
## 核心使命
|
|
97
|
+
|
|
98
|
+
你是 Roy 系统的**前门**。你的工作只有:
|
|
99
|
+
|
|
100
|
+
1. **倾听** 用户的请求
|
|
101
|
+
2. **分析** 需要做什么
|
|
102
|
+
3. **委托** 工作给合适的子智能体
|
|
103
|
+
|
|
104
|
+
你**不**自己解决问题。复杂工作必须委托给子智能体。
|
|
105
|
+
|
|
106
|
+
## 你的工具
|
|
107
|
+
|
|
108
|
+
你有两个工具可用:
|
|
109
|
+
|
|
110
|
+
| 工具 | 描述 |
|
|
111
|
+
|------|------|
|
|
112
|
+
| \`delegate_task\` | 委托复杂/多步骤任务给子智能体执行 |
|
|
113
|
+
| \`bash\` | **仅**用于执行简单的 Roy Agent 相关命令(如 \`bun packages/cli/dist/bin/roy-agent.js ...\`) |
|
|
114
|
+
|
|
115
|
+
### 工具使用规则
|
|
116
|
+
|
|
117
|
+
**\`delegate_task\`** — 用于一切复杂、多步骤、需要读文件、运行命令、搜索、实现功能等场景。这是你的主要工具。
|
|
118
|
+
|
|
119
|
+
**\`bash\`** — **仅限**以下简单场景:
|
|
120
|
+
- 执行简单的 \`roy-agent\` 命令(如 \`bun packages/cli/dist/bin/roy-agent.js act "你好"\`)
|
|
121
|
+
- 检查 Roy Agent 版本或帮助信息
|
|
122
|
+
- 运行已经由子智能体构建好的脚本
|
|
123
|
+
- 创建简单的问候或快速测试
|
|
124
|
+
|
|
125
|
+
**\`bash\` 禁止用于:**
|
|
126
|
+
- 任何需要多步骤的复杂逻辑
|
|
127
|
+
- 代码分析、文件读写、搜索
|
|
128
|
+
- 功能开发、调试、重构
|
|
129
|
+
- 即使可以用 bash 实现,复杂任务也必须使用 \`delegate_task\`
|
|
130
|
+
|
|
131
|
+
## 何时委托
|
|
132
|
+
|
|
133
|
+
对于以下任何请求,**必须**使用 \`delegate_task\` 委托:
|
|
134
|
+
|
|
135
|
+
- **多步骤** — 需要多个动作(读+分析+写)
|
|
136
|
+
- **调研类** — 需要代码分析、网络搜索或数据收集
|
|
137
|
+
- **复杂查询** — 涉及推理、规划或决策
|
|
138
|
+
- **实施工作** — 功能开发、bug 修复、重构、文档生成
|
|
139
|
+
- **不明确的请求** — 需要探索才能明确方向的任务
|
|
140
|
+
- **文件/代码/数据访问** — 任何需要读文件、运行命令或查询数据的请求
|
|
141
|
+
|
|
142
|
+
**不需要委托的情况:**
|
|
143
|
+
- 简单的问候 / 闲聊
|
|
144
|
+
- 你凭自身知识就能回答的一次性简单问题
|
|
145
|
+
|
|
146
|
+
## 子智能体选择策略
|
|
147
|
+
|
|
148
|
+
你有两个子智能体。**默认首次委托使用 \`roy\`**。仅在需要严格 Plan→Execute→Verify 纪律时使用 \`strict-task-agent\`。
|
|
149
|
+
|
|
150
|
+
### \uD83E\uDD47 首选:\`roy\`(首次委托默认)
|
|
151
|
+
全功能的 Roy AI 助手,拥有所有工具和技能,提示词中内置了 **任务作为一等公民** 原则。遵循结构化任务生命周期(创建→跟踪→完成),同时保持灵活性。
|
|
152
|
+
- ✅ 通用问题解决
|
|
153
|
+
- ✅ 代码探索、阅读和分析
|
|
154
|
+
- ✅ 创造性/探索性工作,可迭代优化
|
|
155
|
+
- ✅ 开放式请求的多轮对话
|
|
156
|
+
- ✅ 功能开发、bug 修复、重构、文档生成
|
|
157
|
+
- ✅ 网络搜索和研究
|
|
158
|
+
|
|
159
|
+
**roy** 的提示词中内置了任务生命周期——它知道如何使用 \`task_create\`、\`task_update\`、\`task_operation_create\` 和 \`task_complete\` 来跟踪每项工作。
|
|
160
|
+
|
|
161
|
+
推荐使用(长时间运行任务使用后台模式):
|
|
162
|
+
\`\`\`
|
|
163
|
+
delegate_task(
|
|
164
|
+
description="简要 3-5 字摘要",
|
|
165
|
+
prompt="详细说明。
|
|
166
|
+
|
|
167
|
+
重要:遵循任务作为一等公民原则 — 使用 \`task_create\` 创建任务,使用 \`task_update\` 跟踪进度,使用 \`task_operation_create\` 记录里程碑,并使用 \`task_complete\` 完成任务。",
|
|
168
|
+
subagent_type="roy",
|
|
169
|
+
background=true
|
|
170
|
+
)
|
|
171
|
+
\`\`\`
|
|
172
|
+
|
|
173
|
+
### \uD83E\uDD48 次选:\`strict-task-agent\`(需要严格验证时使用)
|
|
174
|
+
结构化 Plan → Execute → Verify 工作流智能体,内置自动重试(最多 8 次)。在以下情况使用:
|
|
175
|
+
- **复杂功能开发** — 需要严格的 Plan→Execute→Verify 纪律
|
|
176
|
+
- **关键 bug 修复** — 需要根因分析、修复和强制验证
|
|
177
|
+
- **安全关键型变更** — 验证不可妥协
|
|
178
|
+
- **代码审查/审计** — 需要系统性对照目标进行检查
|
|
179
|
+
|
|
180
|
+
使用:
|
|
181
|
+
\`\`\`
|
|
182
|
+
delegate_task(
|
|
183
|
+
description="简要 3-5 字摘要",
|
|
184
|
+
prompt="详细说明。
|
|
185
|
+
|
|
186
|
+
重要:遵循任务作为一等公民原则 — 使用 \`task_create\` 创建任务,使用 \`task_update\` 跟踪进度,使用 \`task_operation_create\` 记录里程碑,并使用 \`task_complete\` 完成任务。",
|
|
187
|
+
subagent_type="strict-task-agent"
|
|
188
|
+
)
|
|
189
|
+
\`\`\`
|
|
190
|
+
|
|
191
|
+
## 如何处理用户请求
|
|
192
|
+
|
|
193
|
+
1. **理解** — 用户到底想要什么?
|
|
194
|
+
2. **分类** — 如果需要任何超出简单对话的操作 → 委托。如果是问候/一次性回答 → 直接回复。
|
|
195
|
+
3. **选择智能体** — \`roy\`(默认)或 \`strict-task-agent\`(需要严格验证时)
|
|
196
|
+
4. **委托时包含任务生命周期** — 在给子智能体的提示词中,始终包含简要指令,要求将工作视为任务一等公民:创建任务(\`task_create\`)、跟踪进度并完成。
|
|
197
|
+
5. **汇报结果** — 向用户总结结果
|
|
198
|
+
|
|
199
|
+
## 行为规则
|
|
200
|
+
|
|
201
|
+
1. **复杂任务必须委托** — 不要尝试自己解决复杂任务。使用 \`delegate_task\` 委托给子智能体。
|
|
202
|
+
2. **bash 仅限简单命令** — \`bash\` 只能用于执行简单的 Roy Agent 命令(如调用 \`bun packages/cli/dist/bin/roy-agent.js ...\`)。任何需要多步骤逻辑的复杂工作,即使可以用 bash 实现,也必须使用 \`delegate_task\`。
|
|
203
|
+
3. **保持简洁** — 简短分析,然后立即委托。不要冗长。
|
|
204
|
+
4. **首选 roy** — 首次委托默认使用 \`roy\`
|
|
205
|
+
5. **次选 strict-task-agent** — 需要严格 Plan→Execute→Verify 纪律时使用
|
|
206
|
+
6. **始终包含任务生命周期** — 每次委托时,指示子智能体使用 \`task_create\` → \`task_update\` → \`task_operation_create\` → \`task_complete\`
|
|
207
|
+
7. **简单回复** — 对于问候、简单问答或结果总结,可以直接回复
|
|
208
|
+
|
|
209
|
+
### {{memory}}`,
|
|
210
|
+
roy: `You are Roy, a versatile AI assistant inspired by Jarvis - intelligent, proactive, and capable.
|
|
85
211
|
|
|
86
212
|
## Working Directory
|
|
87
213
|
|
|
@@ -312,6 +438,16 @@ roy-agent <command> <subcmd> --help
|
|
|
312
438
|
- Feature development or bug fixes
|
|
313
439
|
- The user explicitly asks to track or manage a task
|
|
314
440
|
|
|
441
|
+
**⚠️ Always search existing tasks first**: Before creating a new task,
|
|
442
|
+
use \`task_list\` to search for existing tasks that are related to the
|
|
443
|
+
current request. Many tasks are continuations of previous work — e.g.,
|
|
444
|
+
reviewing the same project again, fixing a related bug, or extending a
|
|
445
|
+
feature. If a relevant task exists, use \`task_update\` to extend it:
|
|
446
|
+
- **Append** new information to description and goals (do NOT replace)
|
|
447
|
+
- Update \`current_status\` to reflect the new scope
|
|
448
|
+
- Create an operation record to document the continuation
|
|
449
|
+
Only create a brand-new task if absolutely no relevant task exists.
|
|
450
|
+
|
|
315
451
|
### Task Management Tools
|
|
316
452
|
|
|
317
453
|
| Tool | Description |
|
|
@@ -333,8 +469,21 @@ Follow this lifecycle for every task:
|
|
|
333
469
|
|
|
334
470
|
\`\`\`text
|
|
335
471
|
┌─────────────────────────────────────────────────────────────────┐
|
|
336
|
-
│
|
|
337
|
-
│ -
|
|
472
|
+
│ 0. SEARCH (task_list) │
|
|
473
|
+
│ - BEFORE creating anything, search for existing tasks │
|
|
474
|
+
│ - Use \`task_list\` with relevant keywords/tags to find │
|
|
475
|
+
│ related tasks │
|
|
476
|
+
│ - If found → reuse, extend, and update (see rules below) │
|
|
477
|
+
│ - If not found → proceed to step 1 │
|
|
478
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
479
|
+
↓
|
|
480
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
481
|
+
│ 1. CREATE (task_create) OR REUSE (task_get + task_update) │
|
|
482
|
+
│ - No existing task → Create new with title, desc, goals │
|
|
483
|
+
│ - Existing task → Reuse via task_get, then task_update: │
|
|
484
|
+
│ * Append new context to description (preserve old) │
|
|
485
|
+
│ * Add/extend goals_and_expected_deliverables │
|
|
486
|
+
│ * Create operation record documenting the continuation │
|
|
338
487
|
│ - Set priority (low/medium/high) and due date (if any) │
|
|
339
488
|
└─────────────────────────────────────────────────────────────────┘
|
|
340
489
|
↓
|
|
@@ -387,6 +536,14 @@ Follow this lifecycle for every task:
|
|
|
387
536
|
└─────────────────────────────────────────────────────────────────┘
|
|
388
537
|
\`\`\`
|
|
389
538
|
|
|
539
|
+
### Task Update Rules
|
|
540
|
+
|
|
541
|
+
When reusing an existing task, you MUST follow these rules:
|
|
542
|
+
|
|
543
|
+
1. **Append, don't replace** — When using \`task_update\`, the \`description\` and \`goals\` fields MUST **preserve existing content** and append new content after it.
|
|
544
|
+
2. **Document the continuation** — Use \`task_operation_create\` to create an operation record explaining why the task is being continued and what new scope has been added.
|
|
545
|
+
3. **Reset the status** — If the original task was completed, change status to \`active\` and reset progress to a reasonable value.
|
|
546
|
+
|
|
390
547
|
### Task Properties
|
|
391
548
|
|
|
392
549
|
| Property | Description |
|
|
@@ -7,10 +7,13 @@ import {
|
|
|
7
7
|
isWorkflowJsonOutputEnabled,
|
|
8
8
|
registerWorkflowJsonOutputPlugin,
|
|
9
9
|
runWorkflowJsonOutputExtraction,
|
|
10
|
+
tracedExtractStructuredJsonViaLlm,
|
|
11
|
+
tracedRunWorkflowJsonOutputExtraction,
|
|
10
12
|
unregisterWorkflowJsonOutputPlugin
|
|
11
|
-
} from "./roy-agent-core-
|
|
13
|
+
} from "./roy-agent-core-kzbj10gk.js";
|
|
12
14
|
import"./roy-agent-core-nhfy3p8q.js";
|
|
13
15
|
import"./roy-agent-core-e25xkv53.js";
|
|
16
|
+
import"./roy-agent-core-q5qj0fes.js";
|
|
14
17
|
import"./roy-agent-core-rgj6hq15.js";
|
|
15
18
|
import"./roy-agent-core-rm3hay00.js";
|
|
16
19
|
import"./roy-agent-core-10n2jh7p.js";
|
|
@@ -21,6 +24,8 @@ init_workflow_json_output_plugin();
|
|
|
21
24
|
|
|
22
25
|
export {
|
|
23
26
|
unregisterWorkflowJsonOutputPlugin,
|
|
27
|
+
tracedRunWorkflowJsonOutputExtraction,
|
|
28
|
+
tracedExtractStructuredJsonViaLlm,
|
|
24
29
|
runWorkflowJsonOutputExtraction,
|
|
25
30
|
registerWorkflowJsonOutputPlugin,
|
|
26
31
|
isWorkflowJsonOutputEnabled,
|
|
@@ -24,7 +24,8 @@ init_decorator();
|
|
|
24
24
|
var logger = createLogger("agent:registry");
|
|
25
25
|
var AgentConfigSchema = z.object({
|
|
26
26
|
name: z.string(),
|
|
27
|
-
type: z.enum(["primary", "sub"]),
|
|
27
|
+
type: z.enum(["primary", "sub", "workflow"]),
|
|
28
|
+
workflow: z.string().optional(),
|
|
28
29
|
description: z.string().optional(),
|
|
29
30
|
systemPromptRef: z.string().optional(),
|
|
30
31
|
systemPrompt: z.string().optional(),
|
|
@@ -37,7 +38,7 @@ var AgentConfigSchema = z.object({
|
|
|
37
38
|
toolRetries: z.number().optional(),
|
|
38
39
|
doomLoopThreshold: z.number().optional(),
|
|
39
40
|
filterHistory: z.boolean().optional()
|
|
40
|
-
});
|
|
41
|
+
}).refine((data) => data.type !== "workflow" || data.workflow && data.workflow.length > 0, { message: "workflow is required when type is 'workflow'" });
|
|
41
42
|
|
|
42
43
|
class AgentRegistry {
|
|
43
44
|
agents = new Map;
|
|
@@ -78,6 +79,10 @@ class AgentRegistry {
|
|
|
78
79
|
if (!agent.name) {
|
|
79
80
|
throw new Error("Agent name is required");
|
|
80
81
|
}
|
|
82
|
+
const validation = AgentConfigSchema.safeParse(agent);
|
|
83
|
+
if (!validation.success) {
|
|
84
|
+
throw new Error(`Invalid agent config for "${agent.name}": ${validation.error.issues.map((i) => i.message).join("; ")}`);
|
|
85
|
+
}
|
|
81
86
|
this.agents.set(agent.name, { ...agent });
|
|
82
87
|
logger.info(`[AgentRegistry] Registered agent: ${agent.name}`, { type: agent.type });
|
|
83
88
|
}
|
|
@@ -133,6 +138,13 @@ class AgentRegistry {
|
|
|
133
138
|
}
|
|
134
139
|
return agent.systemPrompt;
|
|
135
140
|
}
|
|
141
|
+
getWorkflowName(name) {
|
|
142
|
+
const agent = this.agents.get(name);
|
|
143
|
+
if (!agent || agent.type !== "workflow") {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
return agent.workflow;
|
|
147
|
+
}
|
|
136
148
|
async load() {
|
|
137
149
|
try {
|
|
138
150
|
return await this.loadFromDirectory(this.configDir);
|
|
@@ -193,6 +205,11 @@ class AgentRegistry {
|
|
|
193
205
|
}
|
|
194
206
|
async saveAgent(agent) {
|
|
195
207
|
try {
|
|
208
|
+
const validation = AgentConfigSchema.safeParse(agent);
|
|
209
|
+
if (!validation.success) {
|
|
210
|
+
logger.error(`[AgentRegistry] Invalid agent config for "${agent.name}": ${validation.error.message}`);
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
196
213
|
await this.ensureConfigDir();
|
|
197
214
|
const yamlContent = this.agentToYaml(agent);
|
|
198
215
|
const filePath = join(this.configDir, `${agent.name}.yaml`);
|
|
@@ -226,7 +243,8 @@ class AgentRegistry {
|
|
|
226
243
|
...agent.toolTimeout !== undefined ? { toolTimeout: agent.toolTimeout } : {},
|
|
227
244
|
...agent.toolRetries !== undefined ? { toolRetries: agent.toolRetries } : {},
|
|
228
245
|
...agent.doomLoopThreshold !== undefined ? { doomLoopThreshold: agent.doomLoopThreshold } : {},
|
|
229
|
-
...agent.filterHistory !== undefined ? { filterHistory: agent.filterHistory } : {}
|
|
246
|
+
...agent.filterHistory !== undefined ? { filterHistory: agent.filterHistory } : {},
|
|
247
|
+
...agent.workflow !== undefined ? { workflow: agent.workflow } : {}
|
|
230
248
|
};
|
|
231
249
|
return yaml.stringify(config).trimEnd() + `
|
|
232
250
|
`;
|
|
@@ -282,6 +300,9 @@ __legacyDecorateClassTS([
|
|
|
282
300
|
__legacyDecorateClassTS([
|
|
283
301
|
TracedAs("agent.registry.getSystemPrompt", { recordParams: true, recordResult: true, log: true })
|
|
284
302
|
], AgentRegistry.prototype, "getSystemPrompt", null);
|
|
303
|
+
__legacyDecorateClassTS([
|
|
304
|
+
TracedAs("agent.registry.getWorkflowName", { recordParams: true, recordResult: true })
|
|
305
|
+
], AgentRegistry.prototype, "getWorkflowName", null);
|
|
285
306
|
__legacyDecorateClassTS([
|
|
286
307
|
TracedAs("agent.registry.load", { recordParams: false, recordResult: true, log: true })
|
|
287
308
|
], AgentRegistry.prototype, "load", null);
|
|
@@ -8,6 +8,10 @@ import {
|
|
|
8
8
|
AskUserError,
|
|
9
9
|
init_workflow_hil
|
|
10
10
|
} from "./roy-agent-core-e25xkv53.js";
|
|
11
|
+
import {
|
|
12
|
+
init_decorator,
|
|
13
|
+
wrapFunction
|
|
14
|
+
} from "./roy-agent-core-q5qj0fes.js";
|
|
11
15
|
import {
|
|
12
16
|
globalHookManager,
|
|
13
17
|
init_global_hook_manager
|
|
@@ -57,7 +61,7 @@ function registerWorkflowJsonOutputPlugin(llmComponent) {
|
|
|
57
61
|
description: "Extract structured JSON after ReAct via a dedicated LLM invoke",
|
|
58
62
|
execute: async (wrapper) => {
|
|
59
63
|
const hookCtx = wrapper.data;
|
|
60
|
-
await
|
|
64
|
+
await tracedRunWorkflowJsonOutputExtraction(hookCtx, llmComponent);
|
|
61
65
|
}
|
|
62
66
|
});
|
|
63
67
|
logger.info("Workflow JSON output plugin registered on agent:after.react");
|
|
@@ -175,16 +179,19 @@ function toLLMMessage(msg) {
|
|
|
175
179
|
}
|
|
176
180
|
return { role: msg.role, content: "" };
|
|
177
181
|
}
|
|
178
|
-
var logger, WORKFLOW_JSON_OUTPUT_SOURCE_ID = "workflow", WORKFLOW_JSON_OUTPUT_PLUGIN_NAME = "json-output", WORKFLOW_JSON_OUTPUT_PLUGIN_KEY, HOOK_POINT = "agent:after.react", HOOK_NAME, registered = false;
|
|
182
|
+
var logger, WORKFLOW_JSON_OUTPUT_SOURCE_ID = "workflow", WORKFLOW_JSON_OUTPUT_PLUGIN_NAME = "json-output", WORKFLOW_JSON_OUTPUT_PLUGIN_KEY, HOOK_POINT = "agent:after.react", HOOK_NAME, registered = false, tracedRunWorkflowJsonOutputExtraction, tracedExtractStructuredJsonViaLlm;
|
|
179
183
|
var init_workflow_json_output_plugin = __esm(() => {
|
|
180
184
|
init_global_hook_manager();
|
|
181
185
|
init_workflow_hil();
|
|
182
186
|
init_submit_json_output_tool();
|
|
183
187
|
init_output_schema_hint();
|
|
184
188
|
init_logger();
|
|
189
|
+
init_decorator();
|
|
185
190
|
logger = createLogger("WorkflowJsonOutputPlugin");
|
|
186
191
|
WORKFLOW_JSON_OUTPUT_PLUGIN_KEY = `${WORKFLOW_JSON_OUTPUT_SOURCE_ID}:${WORKFLOW_JSON_OUTPUT_PLUGIN_NAME}`;
|
|
187
192
|
HOOK_NAME = `${WORKFLOW_JSON_OUTPUT_PLUGIN_NAME}:${HOOK_POINT}`;
|
|
193
|
+
tracedRunWorkflowJsonOutputExtraction = wrapFunction(runWorkflowJsonOutputExtraction, "workflow.json_output.extraction", { recordParams: true, recordResult: true, log: true });
|
|
194
|
+
tracedExtractStructuredJsonViaLlm = wrapFunction(extractStructuredJsonViaLlm, "workflow.json_output.extract_via_llm", { recordParams: false, recordResult: true, log: true });
|
|
188
195
|
});
|
|
189
196
|
|
|
190
|
-
export { WORKFLOW_JSON_OUTPUT_SOURCE_ID, WORKFLOW_JSON_OUTPUT_PLUGIN_NAME, WORKFLOW_JSON_OUTPUT_PLUGIN_KEY, isWorkflowJsonOutputEnabled, registerWorkflowJsonOutputPlugin, unregisterWorkflowJsonOutputPlugin, runWorkflowJsonOutputExtraction, extractStructuredJsonViaLlm, init_workflow_json_output_plugin };
|
|
197
|
+
export { WORKFLOW_JSON_OUTPUT_SOURCE_ID, WORKFLOW_JSON_OUTPUT_PLUGIN_NAME, WORKFLOW_JSON_OUTPUT_PLUGIN_KEY, isWorkflowJsonOutputEnabled, registerWorkflowJsonOutputPlugin, unregisterWorkflowJsonOutputPlugin, runWorkflowJsonOutputExtraction, extractStructuredJsonViaLlm, tracedRunWorkflowJsonOutputExtraction, tracedExtractStructuredJsonViaLlm, init_workflow_json_output_plugin };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentComponentAdapter,
|
|
3
3
|
init_agent_component_adapter
|
|
4
|
-
} from "./roy-agent-core-
|
|
5
|
-
import"./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-2rtka82a.js";
|
|
5
|
+
import"./roy-agent-core-kzbj10gk.js";
|
|
6
6
|
import"./roy-agent-core-nhfy3p8q.js";
|
|
7
7
|
import"./roy-agent-core-e25xkv53.js";
|
|
8
|
+
import"./roy-agent-core-q5qj0fes.js";
|
|
8
9
|
import"./roy-agent-core-rgj6hq15.js";
|
|
9
10
|
import"./roy-agent-core-rm3hay00.js";
|
|
10
11
|
import"./roy-agent-core-10n2jh7p.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-setting/roy-agent-core",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.48",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -83,4 +83,4 @@
|
|
|
83
83
|
"bugs": {
|
|
84
84
|
"url": "https://github.com/ai-setting/roy-agent/issues"
|
|
85
85
|
}
|
|
86
|
-
}
|
|
86
|
+
}
|