@aigne/core 1.72.0-beta.2 → 1.72.0-beta.4

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 (105) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/lib/cjs/agents/agent.d.ts +31 -1
  3. package/lib/cjs/agents/agent.js +13 -0
  4. package/lib/cjs/agents/ai-agent.d.ts +7 -0
  5. package/lib/cjs/agents/ai-agent.js +85 -3
  6. package/lib/cjs/agents/chat-model.d.ts +153 -0
  7. package/lib/cjs/agents/chat-model.js +35 -1
  8. package/lib/cjs/agents/image-agent.d.ts +17 -1
  9. package/lib/cjs/agents/image-agent.js +16 -0
  10. package/lib/cjs/agents/image-model.d.ts +14 -4
  11. package/lib/cjs/agents/mcp-agent.d.ts +17 -0
  12. package/lib/cjs/agents/mcp-agent.js +18 -0
  13. package/lib/cjs/agents/team-agent.d.ts +55 -0
  14. package/lib/cjs/agents/team-agent.js +31 -0
  15. package/lib/cjs/agents/transform-agent.d.ts +12 -0
  16. package/lib/cjs/agents/transform-agent.js +13 -0
  17. package/lib/cjs/agents/video-model.d.ts +14 -4
  18. package/lib/cjs/aigne/usage.d.ts +4 -0
  19. package/lib/cjs/aigne/usage.js +6 -0
  20. package/lib/cjs/loader/agent-yaml.d.ts +5 -63
  21. package/lib/cjs/loader/agent-yaml.js +4 -129
  22. package/lib/cjs/loader/agents.d.ts +4 -0
  23. package/lib/cjs/loader/agents.js +17 -0
  24. package/lib/cjs/loader/index.d.ts +18 -14
  25. package/lib/cjs/loader/index.js +20 -81
  26. package/lib/cjs/loader/schema.d.ts +21 -6
  27. package/lib/cjs/loader/schema.js +60 -1
  28. package/lib/cjs/prompt/prompt-builder.js +0 -1
  29. package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
  30. package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.js +63 -0
  31. package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
  32. package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +61 -0
  33. package/lib/cjs/prompt/skills/afs/delete.js +15 -3
  34. package/lib/cjs/prompt/skills/afs/edit.js +30 -7
  35. package/lib/cjs/prompt/skills/afs/exec.js +17 -6
  36. package/lib/cjs/prompt/skills/afs/index.js +4 -1
  37. package/lib/cjs/prompt/skills/afs/list.js +26 -10
  38. package/lib/cjs/prompt/skills/afs/read.js +14 -3
  39. package/lib/cjs/prompt/skills/afs/rename.js +18 -4
  40. package/lib/cjs/prompt/skills/afs/search.js +21 -5
  41. package/lib/cjs/prompt/skills/afs/write.js +18 -4
  42. package/lib/cjs/prompt/template.d.ts +92 -17
  43. package/lib/cjs/prompt/template.js +46 -17
  44. package/lib/dts/agents/agent.d.ts +31 -1
  45. package/lib/dts/agents/ai-agent.d.ts +7 -0
  46. package/lib/dts/agents/chat-model.d.ts +153 -0
  47. package/lib/dts/agents/image-agent.d.ts +17 -1
  48. package/lib/dts/agents/image-model.d.ts +14 -4
  49. package/lib/dts/agents/mcp-agent.d.ts +17 -0
  50. package/lib/dts/agents/team-agent.d.ts +55 -0
  51. package/lib/dts/agents/transform-agent.d.ts +12 -0
  52. package/lib/dts/agents/video-model.d.ts +14 -4
  53. package/lib/dts/aigne/context.d.ts +2 -2
  54. package/lib/dts/aigne/usage.d.ts +4 -0
  55. package/lib/dts/loader/agent-yaml.d.ts +5 -63
  56. package/lib/dts/loader/agents.d.ts +4 -0
  57. package/lib/dts/loader/index.d.ts +18 -14
  58. package/lib/dts/loader/schema.d.ts +21 -6
  59. package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
  60. package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
  61. package/lib/dts/prompt/template.d.ts +92 -17
  62. package/lib/esm/agents/agent.d.ts +31 -1
  63. package/lib/esm/agents/agent.js +13 -0
  64. package/lib/esm/agents/ai-agent.d.ts +7 -0
  65. package/lib/esm/agents/ai-agent.js +85 -3
  66. package/lib/esm/agents/chat-model.d.ts +153 -0
  67. package/lib/esm/agents/chat-model.js +34 -0
  68. package/lib/esm/agents/image-agent.d.ts +17 -1
  69. package/lib/esm/agents/image-agent.js +16 -0
  70. package/lib/esm/agents/image-model.d.ts +14 -4
  71. package/lib/esm/agents/mcp-agent.d.ts +17 -0
  72. package/lib/esm/agents/mcp-agent.js +18 -0
  73. package/lib/esm/agents/team-agent.d.ts +55 -0
  74. package/lib/esm/agents/team-agent.js +31 -0
  75. package/lib/esm/agents/transform-agent.d.ts +12 -0
  76. package/lib/esm/agents/transform-agent.js +13 -0
  77. package/lib/esm/agents/video-model.d.ts +14 -4
  78. package/lib/esm/aigne/context.d.ts +2 -2
  79. package/lib/esm/aigne/usage.d.ts +4 -0
  80. package/lib/esm/aigne/usage.js +6 -0
  81. package/lib/esm/loader/agent-yaml.d.ts +5 -63
  82. package/lib/esm/loader/agent-yaml.js +4 -128
  83. package/lib/esm/loader/agents.d.ts +4 -0
  84. package/lib/esm/loader/agents.js +14 -0
  85. package/lib/esm/loader/index.d.ts +18 -14
  86. package/lib/esm/loader/index.js +21 -81
  87. package/lib/esm/loader/schema.d.ts +21 -6
  88. package/lib/esm/loader/schema.js +57 -0
  89. package/lib/esm/prompt/prompt-builder.js +1 -2
  90. package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
  91. package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.js +59 -0
  92. package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
  93. package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +53 -0
  94. package/lib/esm/prompt/skills/afs/delete.js +15 -3
  95. package/lib/esm/prompt/skills/afs/edit.js +30 -7
  96. package/lib/esm/prompt/skills/afs/exec.js +17 -6
  97. package/lib/esm/prompt/skills/afs/index.js +4 -1
  98. package/lib/esm/prompt/skills/afs/list.js +26 -10
  99. package/lib/esm/prompt/skills/afs/read.js +14 -3
  100. package/lib/esm/prompt/skills/afs/rename.js +18 -4
  101. package/lib/esm/prompt/skills/afs/search.js +21 -5
  102. package/lib/esm/prompt/skills/afs/write.js +18 -4
  103. package/lib/esm/prompt/template.d.ts +92 -17
  104. package/lib/esm/prompt/template.js +46 -17
  105. package/package.json +5 -4
@@ -0,0 +1,4 @@
1
+ import type { AgentClass } from "../agents/types.ts";
2
+ export declare const builtinAgents: {
3
+ [type: string]: AgentClass;
4
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.builtinAgents = void 0;
4
+ const agent_js_1 = require("../agents/agent.js");
5
+ const ai_agent_js_1 = require("../agents/ai-agent.js");
6
+ const image_agent_js_1 = require("../agents/image-agent.js");
7
+ const mcp_agent_js_1 = require("../agents/mcp-agent.js");
8
+ const team_agent_js_1 = require("../agents/team-agent.js");
9
+ const transform_agent_js_1 = require("../agents/transform-agent.js");
10
+ exports.builtinAgents = {
11
+ ai: ai_agent_js_1.AIAgent,
12
+ function: agent_js_1.FunctionAgent,
13
+ image: image_agent_js_1.ImageAgent,
14
+ mcp: mcp_agent_js_1.MCPAgent,
15
+ team: team_agent_js_1.TeamAgent,
16
+ transform: transform_agent_js_1.TransformAgent,
17
+ };
@@ -5,9 +5,8 @@ import type { ChatModel } from "../agents/chat-model.js";
5
5
  import type { ImageModel } from "../agents/image-model.js";
6
6
  import type { AIGNEOptions } from "../aigne/aigne.js";
7
7
  import type { MemoryAgent, MemoryAgentOptions } from "../memory/memory.js";
8
- import { PromptBuilder } from "../prompt/prompt-builder.js";
9
8
  import { type PromiseOrValue } from "../utils/type-utils.js";
10
- import { type Instructions, loadAgentFromYamlFile, type NestAgentSchema } from "./agent-yaml.js";
9
+ import { loadAgentFromYamlFile, type NestAgentSchema } from "./agent-yaml.js";
11
10
  export interface LoadOptions {
12
11
  memories?: {
13
12
  new (parameters?: MemoryAgentOptions): MemoryAgent;
@@ -19,7 +18,10 @@ export interface LoadOptions {
19
18
  availableModules?: {
20
19
  module: string;
21
20
  alias?: string[];
22
- create: (options?: Record<string, any>) => PromiseOrValue<AFSModule>;
21
+ load: (options: {
22
+ filepath: string;
23
+ parsed?: object;
24
+ }) => PromiseOrValue<AFSModule>;
23
25
  }[];
24
26
  };
25
27
  aigne?: z.infer<typeof aigneFileSchema>;
@@ -27,6 +29,9 @@ export interface LoadOptions {
27
29
  parent?: string;
28
30
  }) => Promise<any>;
29
31
  }
32
+ export interface AgentLoadOptions extends LoadOptions {
33
+ loadNestAgent: (path: string, agent: NestAgentSchema, options: LoadOptions, agentOptions?: AgentOptions<any, any> & Record<string, unknown>) => Promise<Agent>;
34
+ }
30
35
  export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
31
36
  export declare function loadAgent(path: string, options: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
32
37
  export declare function loadNestAgent(path: string, agent: NestAgentSchema, options: LoadOptions, agentOptions?: AgentOptions<any, any> & Record<string, unknown>): Promise<Agent>;
@@ -67,9 +72,9 @@ declare const aigneFileSchema: z.ZodObject<{
67
72
  } | undefined, z.ZodTypeDef, number | {
68
73
  $get: string;
69
74
  } | undefined>;
70
- thinkingEffort: ZodType<number | "high" | "medium" | "low" | "minimal" | {
75
+ thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
71
76
  $get: string;
72
- } | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
77
+ } | undefined, z.ZodTypeDef, number | "high" | "low" | "medium" | "minimal" | {
73
78
  $get: string;
74
79
  } | undefined>;
75
80
  }, z.ZodTypeAny, "passthrough"> | undefined, z.ZodTypeDef, z.objectInputType<{
@@ -98,9 +103,9 @@ declare const aigneFileSchema: z.ZodObject<{
98
103
  } | undefined, z.ZodTypeDef, number | {
99
104
  $get: string;
100
105
  } | undefined>;
101
- thinkingEffort: ZodType<number | "high" | "medium" | "low" | "minimal" | {
106
+ thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
102
107
  $get: string;
103
- } | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
108
+ } | undefined, z.ZodTypeDef, number | "high" | "low" | "medium" | "minimal" | {
104
109
  $get: string;
105
110
  } | undefined>;
106
111
  }, z.ZodTypeAny, "passthrough"> | undefined>;
@@ -132,6 +137,7 @@ declare const aigneFileSchema: z.ZodObject<{
132
137
  chat?: string | undefined;
133
138
  } | undefined>;
134
139
  }, "strip", z.ZodTypeAny, {
140
+ name?: string | undefined;
135
141
  model?: z.objectInputType<{
136
142
  model: ZodType<string | {
137
143
  $get: string;
@@ -158,13 +164,12 @@ declare const aigneFileSchema: z.ZodObject<{
158
164
  } | undefined, z.ZodTypeDef, number | {
159
165
  $get: string;
160
166
  } | undefined>;
161
- thinkingEffort: ZodType<number | "high" | "medium" | "low" | "minimal" | {
167
+ thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
162
168
  $get: string;
163
- } | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
169
+ } | undefined, z.ZodTypeDef, number | "high" | "low" | "medium" | "minimal" | {
164
170
  $get: string;
165
171
  } | undefined>;
166
172
  }, z.ZodTypeAny, "passthrough"> | undefined;
167
- name?: string | undefined;
168
173
  description?: string | undefined;
169
174
  imageModel?: z.objectInputType<{
170
175
  model: ZodType<string | {
@@ -183,6 +188,7 @@ declare const aigneFileSchema: z.ZodObject<{
183
188
  chat?: string | undefined;
184
189
  } | undefined;
185
190
  }, {
191
+ name?: string | undefined;
186
192
  model?: z.objectInputType<{
187
193
  model: ZodType<string | {
188
194
  $get: string;
@@ -209,13 +215,12 @@ declare const aigneFileSchema: z.ZodObject<{
209
215
  } | undefined, z.ZodTypeDef, number | {
210
216
  $get: string;
211
217
  } | undefined>;
212
- thinkingEffort: ZodType<number | "high" | "medium" | "low" | "minimal" | {
218
+ thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
213
219
  $get: string;
214
- } | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
220
+ } | undefined, z.ZodTypeDef, number | "high" | "low" | "medium" | "minimal" | {
215
221
  $get: string;
216
222
  } | undefined>;
217
223
  }, z.ZodTypeAny, "passthrough"> | undefined;
218
- name?: string | undefined;
219
224
  description?: string | undefined;
220
225
  imageModel?: z.objectInputType<{
221
226
  model: ZodType<string | {
@@ -239,5 +244,4 @@ export declare function loadAIGNEFile(path: string): Promise<{
239
244
  rootDir: string;
240
245
  }>;
241
246
  export declare function findAIGNEFile(path: string): Promise<string>;
242
- export declare function instructionsToPromptBuilder(instructions: Instructions): PromptBuilder;
243
247
  export {};
@@ -6,23 +6,16 @@ exports.loadNestAgent = loadNestAgent;
6
6
  exports.parseAgent = parseAgent;
7
7
  exports.loadAIGNEFile = loadAIGNEFile;
8
8
  exports.findAIGNEFile = findAIGNEFile;
9
- exports.instructionsToPromptBuilder = instructionsToPromptBuilder;
10
9
  const afs_1 = require("@aigne/afs");
11
10
  const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
12
11
  const yaml_1 = require("yaml");
13
12
  const zod_1 = require("zod");
14
13
  const agent_js_1 = require("../agents/agent.js");
15
- const ai_agent_js_1 = require("../agents/ai-agent.js");
16
- const image_agent_js_1 = require("../agents/image-agent.js");
17
- const mcp_agent_js_1 = require("../agents/mcp-agent.js");
18
- const team_agent_js_1 = require("../agents/team-agent.js");
19
- const transform_agent_js_1 = require("../agents/transform-agent.js");
20
- const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
21
- const template_js_1 = require("../prompt/template.js");
22
14
  const agent_utils_js_1 = require("../utils/agent-utils.js");
23
15
  const type_utils_js_1 = require("../utils/type-utils.js");
24
16
  const agent_js_js_1 = require("./agent-js.js");
25
17
  const agent_yaml_js_1 = require("./agent-yaml.js");
18
+ const agents_js_1 = require("./agents.js");
26
19
  const schema_js_1 = require("./schema.js");
27
20
  const AIGNE_FILE_NAME = ["aigne.yaml", "aigne.yml"];
28
21
  async function load(path, options = {}) {
@@ -163,7 +156,10 @@ async function parseAgent(path, agent, options, agentOptions) {
163
156
  const mod = options?.afs?.availableModules?.find((mod) => mod.module === moduleName || mod.alias?.includes(moduleName));
164
157
  if (!mod)
165
158
  throw new Error(`AFS module not found: ${typeof m === "string" ? m : m.module}`);
166
- const module = await mod.create(typeof m === "string" ? {} : m.options);
159
+ const module = await mod.load({
160
+ filepath: path,
161
+ parsed: typeof m === "string" ? {} : m.options,
162
+ });
167
163
  afs.mount(module);
168
164
  }
169
165
  }
@@ -195,73 +191,24 @@ async function parseAgent(path, agent, options, agentOptions) {
195
191
  skills: [...(agentOptions?.skills || []), ...skills],
196
192
  afs: afs || agentOptions?.afs,
197
193
  };
198
- let instructions;
199
- if ("instructions" in agent && agent.instructions && ["ai", "image"].includes(agent.type)) {
200
- instructions = instructionsToPromptBuilder(agent.instructions);
201
- }
202
- switch (agent.type) {
203
- case "ai": {
204
- return ai_agent_js_1.AIAgent.from({
205
- ...baseOptions,
206
- instructions,
207
- });
208
- }
209
- case "image": {
210
- if (!instructions)
211
- throw new Error(`Missing required instructions for image agent at path: ${path}`);
212
- return image_agent_js_1.ImageAgent.from({
213
- ...baseOptions,
214
- instructions,
215
- });
216
- }
217
- case "mcp": {
218
- if (agent.url) {
219
- return mcp_agent_js_1.MCPAgent.from({
220
- ...baseOptions,
221
- url: agent.url,
222
- });
223
- }
224
- if (agent.command) {
225
- return mcp_agent_js_1.MCPAgent.from({
226
- ...baseOptions,
227
- command: agent.command,
228
- args: agent.args,
229
- });
230
- }
231
- throw new Error(`Missing url or command in mcp agent: ${path}`);
232
- }
233
- case "team": {
234
- return team_agent_js_1.TeamAgent.from({
235
- ...baseOptions,
236
- mode: agent.mode,
237
- iterateOn: agent.iterateOn,
238
- reflection: agent.reflection && {
239
- ...agent.reflection,
240
- reviewer: await loadNestAgent(path, agent.reflection.reviewer, options),
241
- },
242
- });
243
- }
244
- case "transform": {
245
- return transform_agent_js_1.TransformAgent.from({
246
- ...baseOptions,
247
- jsonata: agent.jsonata,
248
- });
249
- }
250
- case "function": {
251
- return agent_js_1.FunctionAgent.from({
252
- ...baseOptions,
253
- process: agent.process,
254
- });
194
+ let agentClass = agents_js_1.builtinAgents[agent.type];
195
+ if (!agentClass) {
196
+ if (!options?.require)
197
+ throw new Error(`Module loader is not provided to load agent type module ${agent.type} from ${path}`);
198
+ const Mod = await options.require(agent.type, { parent: path });
199
+ if (typeof Mod?.default?.prototype?.constructor !== "function") {
200
+ throw new Error(`The agent type module ${agent.type} does not export a default Agent class`);
255
201
  }
202
+ agentClass = Mod.default;
256
203
  }
257
- if ("agentClass" in agent && agent.agentClass) {
258
- return await agent.agentClass.load({
259
- filepath: path,
260
- parsed: baseOptions,
261
- options,
262
- });
204
+ if (!agentClass) {
205
+ throw new Error(`Unsupported agent type: ${agent.type} from ${path}`);
263
206
  }
264
- throw new Error(`Unsupported agent type: ${"type" in agent ? agent.type : "unknown"} at path: ${path}`);
207
+ return await agentClass.load({
208
+ filepath: path,
209
+ parsed: baseOptions,
210
+ options: { ...options, loadNestAgent },
211
+ });
265
212
  }
266
213
  async function loadMemory(memories, provider, options) {
267
214
  const M = !provider
@@ -317,11 +264,3 @@ async function findAIGNEFile(path) {
317
264
  }
318
265
  throw new Error(`aigne.yaml not found in ${path}. Please ensure you are in the correct directory or provide a valid path.`);
319
266
  }
320
- function instructionsToPromptBuilder(instructions) {
321
- return new prompt_builder_js_1.PromptBuilder({
322
- instructions: template_js_1.ChatMessagesTemplate.from((0, template_js_1.parseChatMessages)(instructions.map((i) => ({
323
- ...i,
324
- options: { workingDir: index_js_1.nodejs.path.dirname(i.path) },
325
- })))),
326
- });
327
- }
@@ -1,4 +1,6 @@
1
1
  import { type ZodType, z } from "zod";
2
+ import { type Role } from "../agents/chat-model.js";
3
+ import { PromptBuilder } from "../prompt/prompt-builder.js";
2
4
  export declare const inputOutputSchema: ({ path }: {
3
5
  path: string;
4
6
  }) => z.ZodUnion<[ZodType<any, z.ZodTypeDef, any>, z.ZodEffects<z.ZodObject<{
@@ -55,9 +57,9 @@ declare const chatModelObjectSchema: z.ZodObject<{
55
57
  } | undefined, z.ZodTypeDef, number | {
56
58
  $get: string;
57
59
  } | undefined>;
58
- thinkingEffort: ZodType<number | "high" | "medium" | "low" | "minimal" | {
60
+ thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
59
61
  $get: string;
60
- } | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
62
+ } | undefined, z.ZodTypeDef, number | "high" | "low" | "medium" | "minimal" | {
61
63
  $get: string;
62
64
  } | undefined>;
63
65
  }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
@@ -86,9 +88,9 @@ declare const chatModelObjectSchema: z.ZodObject<{
86
88
  } | undefined, z.ZodTypeDef, number | {
87
89
  $get: string;
88
90
  } | undefined>;
89
- thinkingEffort: ZodType<number | "high" | "medium" | "low" | "minimal" | {
91
+ thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
90
92
  $get: string;
91
- } | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
93
+ } | undefined, z.ZodTypeDef, number | "high" | "low" | "medium" | "minimal" | {
92
94
  $get: string;
93
95
  } | undefined>;
94
96
  }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
@@ -117,9 +119,9 @@ declare const chatModelObjectSchema: z.ZodObject<{
117
119
  } | undefined, z.ZodTypeDef, number | {
118
120
  $get: string;
119
121
  } | undefined>;
120
- thinkingEffort: ZodType<number | "high" | "medium" | "low" | "minimal" | {
122
+ thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
121
123
  $get: string;
122
- } | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
124
+ } | undefined, z.ZodTypeDef, number | "high" | "low" | "medium" | "minimal" | {
123
125
  $get: string;
124
126
  } | undefined>;
125
127
  }, z.ZodTypeAny, "passthrough">>;
@@ -149,4 +151,17 @@ export declare function camelizeSchema<T extends ZodType>(schema: T, { shallow }
149
151
  shallow?: boolean;
150
152
  }): T;
151
153
  export declare function preprocessSchema<T extends ZodType>(fn: (data: unknown) => unknown, schema: T): T;
154
+ export type Instructions = {
155
+ role: Exclude<Role, "tool">;
156
+ content: string;
157
+ path: string;
158
+ cacheControl?: {
159
+ type: "ephemeral";
160
+ ttl?: "5m" | "1h";
161
+ };
162
+ }[];
163
+ export declare const getInstructionsSchema: ({ filepath }: {
164
+ filepath: string;
165
+ }) => ZodType<Instructions>;
166
+ export declare function instructionsToPromptBuilder(instructions: Instructions | string): PromptBuilder;
152
167
  export {};
@@ -1,13 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.imageModelSchema = exports.chatModelSchema = exports.defaultInputSchema = exports.inputOutputSchema = void 0;
3
+ exports.getInstructionsSchema = exports.imageModelSchema = exports.chatModelSchema = exports.defaultInputSchema = exports.inputOutputSchema = void 0;
4
4
  exports.optionalize = optionalize;
5
5
  exports.camelizeSchema = camelizeSchema;
6
6
  exports.preprocessSchema = preprocessSchema;
7
+ exports.instructionsToPromptBuilder = instructionsToPromptBuilder;
7
8
  const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
8
9
  const yaml_1 = require("yaml");
9
10
  const zod_1 = require("zod");
10
11
  const agent_js_1 = require("../agents/agent.js");
12
+ const chat_model_js_1 = require("../agents/chat-model.js");
13
+ const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
14
+ const template_js_1 = require("../prompt/template.js");
11
15
  const camelize_js_1 = require("../utils/camelize.js");
12
16
  const type_utils_js_1 = require("../utils/type-utils.js");
13
17
  const inputOutputSchema = ({ path }) => {
@@ -101,3 +105,58 @@ function camelizeSchema(schema, { shallow = true } = {}) {
101
105
  function preprocessSchema(fn, schema) {
102
106
  return zod_1.z.preprocess(fn, schema);
103
107
  }
108
+ const instructionItemSchema = camelizeSchema(zod_1.z.union([
109
+ zod_1.z.object({
110
+ role: chat_model_js_1.roleSchema.default("system"),
111
+ url: zod_1.z.string(),
112
+ cacheControl: optionalize(zod_1.z.object({
113
+ type: zod_1.z.literal("ephemeral"),
114
+ ttl: optionalize(zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")])),
115
+ })),
116
+ }),
117
+ zod_1.z.object({
118
+ role: chat_model_js_1.roleSchema.default("system"),
119
+ content: zod_1.z.string(),
120
+ cacheControl: optionalize(zod_1.z.object({
121
+ type: zod_1.z.literal("ephemeral"),
122
+ ttl: optionalize(zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")])),
123
+ })),
124
+ }),
125
+ ]));
126
+ const parseInstructionItem = ({ filepath }) => async ({ role, cacheControl, ...v }) => {
127
+ if (role === "tool")
128
+ throw new Error(`'tool' role is not allowed in instruction item in agent file ${filepath}`);
129
+ if ("content" in v && typeof v.content === "string") {
130
+ return { role, content: v.content, path: filepath, cacheControl };
131
+ }
132
+ if ("url" in v && typeof v.url === "string") {
133
+ const url = index_js_1.nodejs.path.isAbsolute(v.url)
134
+ ? v.url
135
+ : index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(filepath), v.url);
136
+ return index_js_1.nodejs.fs
137
+ .readFile(url, "utf8")
138
+ .then((content) => ({ role, content, path: url, cacheControl }));
139
+ }
140
+ throw new Error(`Invalid instruction item in agent file ${filepath}. Expected 'content' or 'url' property`);
141
+ };
142
+ const getInstructionsSchema = ({ filepath }) => zod_1.z
143
+ .union([zod_1.z.string(), instructionItemSchema, zod_1.z.array(instructionItemSchema)])
144
+ .transform(async (v) => {
145
+ if (typeof v === "string")
146
+ return [{ role: "system", content: v, path: filepath }];
147
+ if (Array.isArray(v)) {
148
+ return Promise.all(v.map((item) => parseInstructionItem({ filepath })(item)));
149
+ }
150
+ return [await parseInstructionItem({ filepath })(v)];
151
+ });
152
+ exports.getInstructionsSchema = getInstructionsSchema;
153
+ function instructionsToPromptBuilder(instructions) {
154
+ return new prompt_builder_js_1.PromptBuilder({
155
+ instructions: typeof instructions === "string"
156
+ ? instructions
157
+ : template_js_1.ChatMessagesTemplate.from((0, template_js_1.parseChatMessages)(instructions.map((i) => ({
158
+ ...i,
159
+ options: { workingDir: index_js_1.nodejs.path.dirname(i.path) },
160
+ })))),
161
+ });
162
+ }
@@ -119,7 +119,6 @@ class PromptBuilder {
119
119
  const afs = options.agent?.afs;
120
120
  if (afs && options.agent?.historyConfig?.disabled !== true) {
121
121
  const historyModule = (await afs.listModules()).find((m) => m.module instanceof afs_history_1.AFSHistory);
122
- messages.push(await template_js_1.SystemMessageTemplate.from(await (0, afs_builtin_prompt_js_1.getAFSSystemPrompt)(afs)).format({}));
123
122
  if (historyModule) {
124
123
  const history = await afs.list(historyModule.path, {
125
124
  limit: options.agent?.maxRetrieveMemoryCount || 10,
@@ -0,0 +1,17 @@
1
+ import { Agent, type AgentOptions, type Message } from "../../../../agents/agent.js";
2
+ import type { Skill } from "./skill-loader.js";
3
+ export interface SkillToolInput extends Message {
4
+ skill: string;
5
+ args?: string;
6
+ }
7
+ export interface SkillToolOutput extends Message {
8
+ result: string;
9
+ }
10
+ export interface SkillToolOptions extends AgentOptions<SkillToolInput, SkillToolOutput> {
11
+ agentSkills: Skill[];
12
+ }
13
+ export declare class AgentSkill extends Agent<SkillToolInput, SkillToolOutput> {
14
+ constructor(options: SkillToolOptions);
15
+ private agentSkills;
16
+ process(input: SkillToolInput): Promise<SkillToolOutput>;
17
+ }
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AgentSkill = void 0;
4
+ const zod_1 = require("zod");
5
+ const agent_js_1 = require("../../../../agents/agent.js");
6
+ const skillToolInputSchema = zod_1.z.object({
7
+ skill: zod_1.z.string().describe("The name of the skill agent to invoke."),
8
+ args: zod_1.z.string().optional().describe("The arguments to pass to the skill."),
9
+ });
10
+ class AgentSkill extends agent_js_1.Agent {
11
+ constructor(options) {
12
+ super({
13
+ name: "Skill",
14
+ taskTitle: "Invoke {{skill}}: {{args}}",
15
+ ...options,
16
+ description: `\
17
+ Execute a skill within the main conversation
18
+
19
+ <skills_instructions>
20
+ When users ask you to perform tasks, check if any of the available skills below can help complete the task more effectively. Skills provide specialized capabilities and domain knowledge.
21
+
22
+ When users ask you to run a "slash command" or reference "/" (e.g., "/commit", "/review-pr"), they are referring to a skill. Use this tool to invoke the corresponding skill.
23
+
24
+ User: "run /commit" Assistant: [Calls Skill tool with skill: "commit"]
25
+ How to invoke:
26
+
27
+ Use this tool with the skill name and optional arguments
28
+
29
+ Important:
30
+
31
+ When a skill is relevant, you must invoke this tool IMMEDIATELY as your first action
32
+ NEVER just announce or mention a skill in your text response without actually calling this tool
33
+ This is a BLOCKING REQUIREMENT: invoke the relevant Skill tool BEFORE generating any other response about the task
34
+ Only use skills listed in <available_skills> below
35
+ Do not invoke a skill that is already running
36
+ Do not use this tool for built-in CLI commands (like /help, /clear, etc.)
37
+ </skills_instructions>
38
+
39
+ <available_skills>
40
+ ${options.agentSkills.map((s) => `${s.name}: ${s.description}`).join("\n\n")}
41
+ </available_skills>
42
+ `,
43
+ inputSchema: skillToolInputSchema,
44
+ });
45
+ this.agentSkills = options.agentSkills;
46
+ }
47
+ agentSkills;
48
+ async process(input) {
49
+ const skill = this.agentSkills.find((s) => s.name === input.skill);
50
+ if (!skill)
51
+ throw new Error(`Skill not found: ${input.skill}`);
52
+ return {
53
+ result: `\
54
+ Base directory for this skill: ${skill.path}
55
+
56
+ ${skill.content}
57
+
58
+ ${input.args ? `ARGUMENTS: ${input.args ?? "None"}` : ""}
59
+ `,
60
+ };
61
+ }
62
+ }
63
+ exports.AgentSkill = AgentSkill;
@@ -0,0 +1,13 @@
1
+ import type { AFS } from "@aigne/afs";
2
+ import { AgentSkill } from "./agent-skill.js";
3
+ export interface Skill {
4
+ path: string;
5
+ name: string;
6
+ description: string;
7
+ content: string;
8
+ }
9
+ export declare function loadSkill(path: string): Promise<Skill>;
10
+ export declare function loadSkills(paths: string[]): Promise<Skill[]>;
11
+ export declare function loadAgentSkillFromAFS({ afs, }: {
12
+ afs: AFS;
13
+ }): Promise<AgentSkill | undefined>;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadSkill = loadSkill;
7
+ exports.loadSkills = loadSkills;
8
+ exports.loadAgentSkillFromAFS = loadAgentSkillFromAFS;
9
+ const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
10
+ const front_matter_1 = __importDefault(require("front-matter"));
11
+ const agent_skill_js_1 = require("./agent-skill.js");
12
+ function parseSkill(content, path) {
13
+ const meta = (0, front_matter_1.default)(content);
14
+ return {
15
+ path,
16
+ name: meta.attributes.name,
17
+ description: meta.attributes.description,
18
+ content: meta.body,
19
+ };
20
+ }
21
+ async function loadSkill(path) {
22
+ const entry = index_js_1.nodejs.path.join(path, "SKILL.md");
23
+ const skill = await index_js_1.nodejs.fs.readFile(entry, "utf-8");
24
+ return parseSkill(skill, path);
25
+ }
26
+ async function loadSkills(paths) {
27
+ const skills = [];
28
+ for (const path of paths) {
29
+ const skill = await loadSkill(path);
30
+ skills.push(skill);
31
+ }
32
+ return skills;
33
+ }
34
+ async function loadAgentSkillFromAFS({ afs, }) {
35
+ const modules = await afs.listModules();
36
+ const filtered = modules.filter(({ module: m }) => "options" in m &&
37
+ typeof m.options === "object" &&
38
+ m.options &&
39
+ "agentSkills" in m.options &&
40
+ m.options.agentSkills === true);
41
+ if (!filtered.length)
42
+ return;
43
+ const skills = [];
44
+ for (const module of filtered) {
45
+ const data = (await afs.list(module.path, {
46
+ pattern: "**/SKILL.md",
47
+ })).data;
48
+ for (const entry of data) {
49
+ const { data: file } = await afs.read(entry.path);
50
+ if (typeof file?.content !== "string")
51
+ continue;
52
+ const skill = parseSkill(file.content, index_js_1.nodejs.path.dirname(entry.path));
53
+ skills.push(skill);
54
+ }
55
+ }
56
+ if (!skills.length)
57
+ return;
58
+ return new agent_skill_js_1.AgentSkill({
59
+ agentSkills: skills,
60
+ });
61
+ }
@@ -7,15 +7,27 @@ class AFSDeleteAgent extends base_js_1.AFSSkillBase {
7
7
  constructor(options) {
8
8
  super({
9
9
  name: "afs_delete",
10
- description: "Permanently delete files or directories. Use when removing unwanted files or cleaning up temporary data.",
10
+ description: `Permanently delete files or directories from the Agentic File System (AFS)
11
+ - Removes files or directories at the specified AFS path
12
+ - Supports recursive deletion for directories with contents
13
+ - Use with caution as deletion is permanent
14
+
15
+ Usage:
16
+ - The path must be an absolute AFS path starting with "/" (e.g., "/docs/old-file.md", "/temp")
17
+ - This is NOT a local system file path - it operates within the AFS virtual file system
18
+ - To delete a directory, you MUST set recursive=true
19
+ - Deleting a non-empty directory without recursive=true will fail
20
+ - This operation cannot be undone`,
11
21
  ...options,
12
22
  inputSchema: zod_1.z.object({
13
- path: zod_1.z.string().describe("Absolute file or directory path to delete"),
23
+ path: zod_1.z
24
+ .string()
25
+ .describe("Absolute AFS path to delete (e.g., '/docs/old-file.md', '/temp'). Must start with '/'"),
14
26
  recursive: zod_1.z
15
27
  .boolean()
16
28
  .optional()
17
29
  .default(false)
18
- .describe("Allow directory deletion (default: false, required for directories)"),
30
+ .describe("MUST be set to true to delete directories. Default: false (files only)"),
19
31
  }),
20
32
  outputSchema: zod_1.z.object({
21
33
  status: zod_1.z.string(),
@@ -7,19 +7,42 @@ class AFSEditAgent extends base_js_1.AFSSkillBase {
7
7
  constructor(options) {
8
8
  super({
9
9
  name: "afs_edit",
10
- description: "Apply precise line-based patches to modify file content. Use when making targeted changes without rewriting the entire file.",
10
+ description: `Apply precise line-based patches to modify files in the Agentic File System (AFS)
11
+ - Performs targeted edits using line numbers without rewriting the entire file
12
+ - Supports both replacing and deleting line ranges
13
+ - Multiple patches can be applied in a single operation
14
+
15
+ Usage:
16
+ - The path must be an absolute AFS path starting with "/" (e.g., "/docs/readme.md")
17
+ - This is NOT a local system file path - it operates within the AFS virtual file system
18
+ - IMPORTANT: You MUST use afs_read with withLineNumbers=true before editing to get accurate line numbers
19
+ - Line numbers are 0-based: first line is 0, second line is 1, etc.
20
+ - The range [start_line, end_line) is exclusive on end_line`,
11
21
  ...options,
12
22
  inputSchema: zod_1.z.object({
13
- path: zod_1.z.string().describe("Absolute file path to edit"),
23
+ path: zod_1.z
24
+ .string()
25
+ .describe("Absolute AFS path to the file to edit (e.g., '/docs/readme.md'). Must start with '/'"),
14
26
  patches: zod_1.z
15
27
  .array(zod_1.z.object({
16
- start_line: zod_1.z.number().int().describe("Start line number (0-based, inclusive)"),
17
- end_line: zod_1.z.number().int().describe("End line number (0-based, exclusive)"),
18
- replace: zod_1.z.string().optional().describe("New content to replace the line range"),
19
- delete: zod_1.z.boolean().describe("Delete mode: true to delete lines, false to replace"),
28
+ start_line: zod_1.z
29
+ .number()
30
+ .int()
31
+ .describe("Start line number (0-based, inclusive). First line is 0"),
32
+ end_line: zod_1.z
33
+ .number()
34
+ .int()
35
+ .describe("End line number (0-based, exclusive). To edit line 5 only, use start_line=5, end_line=6"),
36
+ replace: zod_1.z
37
+ .string()
38
+ .optional()
39
+ .describe("New content to insert. Omit when delete=true"),
40
+ delete: zod_1.z
41
+ .boolean()
42
+ .describe("Set to true to delete the line range. Set to false to replace with 'replace' content"),
20
43
  }))
21
44
  .min(1)
22
- .describe("List of patches to apply sequentially"),
45
+ .describe("Array of patches to apply. Each patch specifies a line range and the operation (delete or replace)"),
23
46
  }),
24
47
  outputSchema: zod_1.z.object({
25
48
  status: zod_1.z.string(),