@aigne/core 1.72.0-beta.3 → 1.72.0-beta.5

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 (99) hide show
  1. package/CHANGELOG.md +27 -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/image-agent.d.ts +17 -1
  7. package/lib/cjs/agents/image-agent.js +16 -0
  8. package/lib/cjs/agents/image-model.d.ts +4 -4
  9. package/lib/cjs/agents/mcp-agent.d.ts +17 -0
  10. package/lib/cjs/agents/mcp-agent.js +18 -0
  11. package/lib/cjs/agents/team-agent.d.ts +55 -0
  12. package/lib/cjs/agents/team-agent.js +31 -0
  13. package/lib/cjs/agents/transform-agent.d.ts +12 -0
  14. package/lib/cjs/agents/transform-agent.js +13 -0
  15. package/lib/cjs/agents/video-model.d.ts +4 -4
  16. package/lib/cjs/loader/agent-yaml.d.ts +5 -67
  17. package/lib/cjs/loader/agent-yaml.js +4 -139
  18. package/lib/cjs/loader/agents.d.ts +4 -0
  19. package/lib/cjs/loader/agents.js +17 -0
  20. package/lib/cjs/loader/index.d.ts +18 -14
  21. package/lib/cjs/loader/index.js +20 -81
  22. package/lib/cjs/loader/schema.d.ts +21 -6
  23. package/lib/cjs/loader/schema.js +60 -1
  24. package/lib/cjs/prompt/prompt-builder.js +0 -1
  25. package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
  26. package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.js +63 -0
  27. package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
  28. package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +61 -0
  29. package/lib/cjs/prompt/skills/afs/delete.js +15 -3
  30. package/lib/cjs/prompt/skills/afs/edit.d.ts +6 -9
  31. package/lib/cjs/prompt/skills/afs/edit.js +85 -59
  32. package/lib/cjs/prompt/skills/afs/exec.js +17 -6
  33. package/lib/cjs/prompt/skills/afs/index.js +4 -1
  34. package/lib/cjs/prompt/skills/afs/list.js +26 -10
  35. package/lib/cjs/prompt/skills/afs/read.d.ts +6 -2
  36. package/lib/cjs/prompt/skills/afs/read.js +62 -15
  37. package/lib/cjs/prompt/skills/afs/rename.js +18 -4
  38. package/lib/cjs/prompt/skills/afs/search.js +21 -5
  39. package/lib/cjs/prompt/skills/afs/write.js +20 -6
  40. package/lib/cjs/prompt/template.d.ts +23 -23
  41. package/lib/dts/agents/agent.d.ts +31 -1
  42. package/lib/dts/agents/ai-agent.d.ts +7 -0
  43. package/lib/dts/agents/image-agent.d.ts +17 -1
  44. package/lib/dts/agents/image-model.d.ts +4 -4
  45. package/lib/dts/agents/mcp-agent.d.ts +17 -0
  46. package/lib/dts/agents/team-agent.d.ts +55 -0
  47. package/lib/dts/agents/transform-agent.d.ts +12 -0
  48. package/lib/dts/agents/video-model.d.ts +4 -4
  49. package/lib/dts/aigne/context.d.ts +2 -2
  50. package/lib/dts/loader/agent-yaml.d.ts +5 -67
  51. package/lib/dts/loader/agents.d.ts +4 -0
  52. package/lib/dts/loader/index.d.ts +18 -14
  53. package/lib/dts/loader/schema.d.ts +21 -6
  54. package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
  55. package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
  56. package/lib/dts/prompt/skills/afs/edit.d.ts +6 -9
  57. package/lib/dts/prompt/skills/afs/read.d.ts +6 -2
  58. package/lib/dts/prompt/template.d.ts +25 -25
  59. package/lib/esm/agents/agent.d.ts +31 -1
  60. package/lib/esm/agents/agent.js +13 -0
  61. package/lib/esm/agents/ai-agent.d.ts +7 -0
  62. package/lib/esm/agents/ai-agent.js +85 -3
  63. package/lib/esm/agents/image-agent.d.ts +17 -1
  64. package/lib/esm/agents/image-agent.js +16 -0
  65. package/lib/esm/agents/image-model.d.ts +4 -4
  66. package/lib/esm/agents/mcp-agent.d.ts +17 -0
  67. package/lib/esm/agents/mcp-agent.js +18 -0
  68. package/lib/esm/agents/team-agent.d.ts +55 -0
  69. package/lib/esm/agents/team-agent.js +31 -0
  70. package/lib/esm/agents/transform-agent.d.ts +12 -0
  71. package/lib/esm/agents/transform-agent.js +13 -0
  72. package/lib/esm/agents/video-model.d.ts +4 -4
  73. package/lib/esm/aigne/context.d.ts +2 -2
  74. package/lib/esm/loader/agent-yaml.d.ts +5 -67
  75. package/lib/esm/loader/agent-yaml.js +4 -138
  76. package/lib/esm/loader/agents.d.ts +4 -0
  77. package/lib/esm/loader/agents.js +14 -0
  78. package/lib/esm/loader/index.d.ts +18 -14
  79. package/lib/esm/loader/index.js +21 -81
  80. package/lib/esm/loader/schema.d.ts +21 -6
  81. package/lib/esm/loader/schema.js +57 -0
  82. package/lib/esm/prompt/prompt-builder.js +1 -2
  83. package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
  84. package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.js +59 -0
  85. package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
  86. package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +53 -0
  87. package/lib/esm/prompt/skills/afs/delete.js +15 -3
  88. package/lib/esm/prompt/skills/afs/edit.d.ts +6 -9
  89. package/lib/esm/prompt/skills/afs/edit.js +85 -59
  90. package/lib/esm/prompt/skills/afs/exec.js +17 -6
  91. package/lib/esm/prompt/skills/afs/index.js +4 -1
  92. package/lib/esm/prompt/skills/afs/list.js +26 -10
  93. package/lib/esm/prompt/skills/afs/read.d.ts +6 -2
  94. package/lib/esm/prompt/skills/afs/read.js +62 -15
  95. package/lib/esm/prompt/skills/afs/rename.js +18 -4
  96. package/lib/esm/prompt/skills/afs/search.js +21 -5
  97. package/lib/esm/prompt/skills/afs/write.js +20 -6
  98. package/lib/esm/prompt/template.d.ts +25 -25
  99. package/package.json +5 -4
@@ -94,6 +94,7 @@ export declare const videoModelInputSchema: z.ZodObject<{
94
94
  prompt: string;
95
95
  model?: string | undefined;
96
96
  modelOptions?: Record<string, unknown> | undefined;
97
+ outputFileType?: "local" | "url" | "file" | undefined;
97
98
  image?: {
98
99
  type: "url";
99
100
  url: string;
@@ -110,13 +111,13 @@ export declare const videoModelInputSchema: z.ZodObject<{
110
111
  filename?: string | undefined;
111
112
  mimeType?: string | undefined;
112
113
  } | undefined;
113
- outputFileType?: "local" | "file" | "url" | undefined;
114
114
  size?: string | undefined;
115
115
  seconds?: string | undefined;
116
116
  }, {
117
117
  prompt: string;
118
118
  model?: string | undefined;
119
119
  modelOptions?: Record<string, unknown> | undefined;
120
+ outputFileType?: "local" | "url" | "file" | undefined;
120
121
  image?: {
121
122
  type: "url";
122
123
  url: string;
@@ -133,7 +134,6 @@ export declare const videoModelInputSchema: z.ZodObject<{
133
134
  filename?: string | undefined;
134
135
  mimeType?: string | undefined;
135
136
  } | undefined;
136
- outputFileType?: "local" | "file" | "url" | undefined;
137
137
  size?: string | undefined;
138
138
  seconds?: string | undefined;
139
139
  }>;
@@ -240,7 +240,6 @@ export declare const videoModelOutputSchema: z.ZodObject<{
240
240
  filename?: string | undefined;
241
241
  mimeType?: string | undefined;
242
242
  })[];
243
- model?: string | undefined;
244
243
  usage?: {
245
244
  inputTokens: number;
246
245
  outputTokens: number;
@@ -249,6 +248,7 @@ export declare const videoModelOutputSchema: z.ZodObject<{
249
248
  cacheReadInputTokens?: number | undefined;
250
249
  creditPrefix?: "$" | "€" | "¥" | undefined;
251
250
  } | undefined;
251
+ model?: string | undefined;
252
252
  seconds?: number | undefined;
253
253
  }, {
254
254
  videos: ({
@@ -267,7 +267,6 @@ export declare const videoModelOutputSchema: z.ZodObject<{
267
267
  filename?: string | undefined;
268
268
  mimeType?: string | undefined;
269
269
  })[];
270
- model?: string | undefined;
271
270
  usage?: {
272
271
  inputTokens: number;
273
272
  outputTokens: number;
@@ -276,5 +275,6 @@ export declare const videoModelOutputSchema: z.ZodObject<{
276
275
  cacheReadInputTokens?: number | undefined;
277
276
  creditPrefix?: "$" | "€" | "¥" | undefined;
278
277
  } | undefined;
278
+ model?: string | undefined;
279
279
  seconds?: number | undefined;
280
280
  }>;
@@ -1,9 +1,6 @@
1
1
  import type { AFSOptions } from "@aigne/afs";
2
2
  import { type ZodType, z } from "zod";
3
- import type { AgentClass, AgentHooks, FunctionAgentFn, TaskRenderMode } from "../agents/agent.js";
4
- import { AIAgentToolChoice } from "../agents/ai-agent.js";
5
- import { type Role } from "../agents/chat-model.js";
6
- import { ProcessMode, type ReflectionMode } from "../agents/team-agent.js";
3
+ import type { AgentHooks, TaskRenderMode } from "../agents/agent.js";
7
4
  import type { LoadOptions } from "./index.js";
8
5
  import { chatModelSchema, imageModelSchema } from "./schema.js";
9
6
  export interface HooksSchema {
@@ -45,7 +42,8 @@ export interface AFSContextSchema {
45
42
  presets?: Record<string, AFSContextPresetSchema>;
46
43
  };
47
44
  }
48
- export interface BaseAgentSchema {
45
+ export interface AgentSchema {
46
+ type: string;
49
47
  name?: string;
50
48
  description?: string;
51
49
  model?: z.infer<typeof chatModelSchema>;
@@ -67,71 +65,11 @@ export interface BaseAgentSchema {
67
65
  context?: AFSContextSchema;
68
66
  });
69
67
  shareAFS?: boolean;
68
+ [key: string]: unknown;
70
69
  }
71
- export type Instructions = {
72
- role: Exclude<Role, "tool">;
73
- content: string;
74
- path: string;
75
- cacheControl?: {
76
- type: "ephemeral";
77
- ttl?: "5m" | "1h";
78
- };
79
- }[];
80
- export interface AIAgentSchema extends BaseAgentSchema {
81
- type: "ai";
82
- instructions?: Instructions;
83
- autoReorderSystemMessages?: boolean;
84
- autoMergeSystemMessages?: boolean;
85
- inputKey?: string;
86
- inputFileKey?: string;
87
- outputKey?: string;
88
- outputFileKey?: string;
89
- toolChoice?: AIAgentToolChoice;
90
- toolCallsConcurrency?: number;
91
- keepTextInToolUses?: boolean;
92
- }
93
- export interface ImageAgentSchema extends BaseAgentSchema {
94
- type: "image";
95
- instructions: Instructions;
96
- inputFileKey?: string;
97
- }
98
- export interface MCPAgentSchema extends BaseAgentSchema {
99
- type: "mcp";
100
- url?: string;
101
- command?: string;
102
- args?: string[];
103
- }
104
- export interface TeamAgentSchema extends BaseAgentSchema {
105
- type: "team";
106
- mode?: ProcessMode;
107
- iterateOn?: string;
108
- concurrency?: number;
109
- iterateWithPreviousOutput?: boolean;
110
- includeAllStepsOutput?: boolean;
111
- reflection?: Omit<ReflectionMode, "reviewer"> & {
112
- reviewer: NestAgentSchema;
113
- };
114
- }
115
- export interface TransformAgentSchema extends BaseAgentSchema {
116
- type: "transform";
117
- jsonata: string;
118
- }
119
- export interface FunctionAgentSchema extends BaseAgentSchema {
120
- type: "function";
121
- process: FunctionAgentFn;
122
- }
123
- export interface ThirdAgentSchema extends BaseAgentSchema {
124
- agentClass?: AgentClass;
125
- type: "";
126
- [key: string]: any;
127
- }
128
- export type AgentSchema = AIAgentSchema | ImageAgentSchema | MCPAgentSchema | TeamAgentSchema | TransformAgentSchema | FunctionAgentSchema | ThirdAgentSchema;
129
70
  export declare function parseAgentFile(path: string, data: any, options: LoadOptions): Promise<AgentSchema>;
130
71
  export declare function loadAgentFromYamlFile(path: string, options: LoadOptions): Promise<AgentSchema>;
131
- export declare const getInstructionsSchema: ({ filepath }: {
132
- filepath: string;
133
- }) => ZodType<Instructions>;
134
- export declare const getAgentSchema: ({ filepath, options, }: {
72
+ export declare const getAgentSchema: ({ filepath }: {
135
73
  filepath: string;
136
74
  options?: LoadOptions;
137
75
  }) => ZodType<AgentSchema, z.ZodTypeDef, AgentSchema>;
@@ -1,17 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNestAgentSchema = exports.getAgentSchema = exports.getInstructionsSchema = void 0;
3
+ exports.getNestAgentSchema = exports.getAgentSchema = void 0;
4
4
  exports.parseAgentFile = parseAgentFile;
5
5
  exports.loadAgentFromYamlFile = loadAgentFromYamlFile;
6
6
  const json_schema_to_zod_1 = require("@aigne/json-schema-to-zod");
7
7
  const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
8
8
  const yaml_1 = require("yaml");
9
9
  const zod_1 = require("zod");
10
- const ai_agent_js_1 = require("../agents/ai-agent.js");
11
- const chat_model_js_1 = require("../agents/chat-model.js");
12
- const team_agent_js_1 = require("../agents/team-agent.js");
13
10
  const type_utils_js_1 = require("../utils/type-utils.js");
14
- const function_agent_js_1 = require("./function-agent.js");
15
11
  const schema_js_1 = require("./schema.js");
16
12
  async function parseAgentFile(path, data, options) {
17
13
  const agentSchema = (0, exports.getAgentSchema)({ filepath: path, options });
@@ -30,52 +26,7 @@ async function loadAgentFromYamlFile(path, options) {
30
26
  }, options), (error) => new Error(`Failed to validate agent definition from ${path}: ${error.message}`));
31
27
  return agent;
32
28
  }
33
- const instructionItemSchema = (0, schema_js_1.camelizeSchema)(zod_1.z.union([
34
- zod_1.z.object({
35
- role: chat_model_js_1.roleSchema.default("system"),
36
- url: zod_1.z.string(),
37
- cacheControl: (0, schema_js_1.optionalize)(zod_1.z.object({
38
- type: zod_1.z.literal("ephemeral"),
39
- ttl: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")])),
40
- })),
41
- }),
42
- zod_1.z.object({
43
- role: chat_model_js_1.roleSchema.default("system"),
44
- content: zod_1.z.string(),
45
- cacheControl: (0, schema_js_1.optionalize)(zod_1.z.object({
46
- type: zod_1.z.literal("ephemeral"),
47
- ttl: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")])),
48
- })),
49
- }),
50
- ]));
51
- const parseInstructionItem = ({ filepath }) => async ({ role, cacheControl, ...v }) => {
52
- if (role === "tool")
53
- throw new Error(`'tool' role is not allowed in instruction item in agent file ${filepath}`);
54
- if ("content" in v && typeof v.content === "string") {
55
- return { role, content: v.content, path: filepath, cacheControl };
56
- }
57
- if ("url" in v && typeof v.url === "string") {
58
- const url = index_js_1.nodejs.path.isAbsolute(v.url)
59
- ? v.url
60
- : index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(filepath), v.url);
61
- return index_js_1.nodejs.fs
62
- .readFile(url, "utf8")
63
- .then((content) => ({ role, content, path: url, cacheControl }));
64
- }
65
- throw new Error(`Invalid instruction item in agent file ${filepath}. Expected 'content' or 'url' property`);
66
- };
67
- const getInstructionsSchema = ({ filepath }) => zod_1.z
68
- .union([zod_1.z.string(), instructionItemSchema, zod_1.z.array(instructionItemSchema)])
69
- .transform(async (v) => {
70
- if (typeof v === "string")
71
- return [{ role: "system", content: v, path: filepath }];
72
- if (Array.isArray(v)) {
73
- return Promise.all(v.map((item) => parseInstructionItem({ filepath })(item)));
74
- }
75
- return [await parseInstructionItem({ filepath })(v)];
76
- });
77
- exports.getInstructionsSchema = getInstructionsSchema;
78
- const getAgentSchema = ({ filepath, options, }) => {
29
+ const getAgentSchema = ({ filepath }) => {
79
30
  const agentSchema = zod_1.z.lazy(() => {
80
31
  const nestAgentSchema = zod_1.z.lazy(() => zod_1.z.union([
81
32
  agentSchema,
@@ -111,6 +62,7 @@ const getAgentSchema = ({ filepath, options, }) => {
111
62
  }))),
112
63
  });
113
64
  const baseAgentSchema = zod_1.z.object({
65
+ type: zod_1.z.string(),
114
66
  name: (0, schema_js_1.optionalize)(zod_1.z.string()),
115
67
  alias: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.string())),
116
68
  description: (0, schema_js_1.optionalize)(zod_1.z.string()),
@@ -149,94 +101,7 @@ const getAgentSchema = ({ filepath, options, }) => {
149
101
  ])),
150
102
  shareAFS: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
151
103
  });
152
- const instructionsSchema = (0, exports.getInstructionsSchema)({ filepath: filepath });
153
- return (0, schema_js_1.camelizeSchema)((0, schema_js_1.preprocessSchema)(async (json) => {
154
- if (typeof json === "object" &&
155
- json &&
156
- "type" in json &&
157
- typeof json.type === "string" &&
158
- !["ai", "image", "mcp", "team", "transform", "function"].includes(json.type)) {
159
- if (!options?.require)
160
- throw new Error(`Module loader is not provided to load agent type module ${json.type} from ${filepath}`);
161
- const Mod = await options.require(json.type, { parent: filepath });
162
- if (typeof Mod?.default?.prototype?.constructor !== "function") {
163
- throw new Error(`The agent type module ${json.type} does not export a default Agent class`);
164
- }
165
- Object.assign(json, { agentClass: Mod.default });
166
- }
167
- return json;
168
- }, zod_1.z.union([
169
- zod_1.z
170
- .object({
171
- type: zod_1.z.string(),
172
- agentClass: zod_1.z.custom((v) => typeof v?.prototype?.constructor === "function"),
173
- })
174
- .extend(baseAgentSchema.shape)
175
- .passthrough(),
176
- zod_1.z.discriminatedUnion("type", [
177
- zod_1.z
178
- .object({
179
- type: zod_1.z.literal("ai"),
180
- instructions: (0, schema_js_1.optionalize)(instructionsSchema),
181
- autoReorderSystemMessages: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
182
- autoMergeSystemMessages: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
183
- inputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
184
- outputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
185
- inputFileKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
186
- outputFileKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
187
- toolChoice: (0, schema_js_1.optionalize)(zod_1.z.nativeEnum(ai_agent_js_1.AIAgentToolChoice)),
188
- toolCallsConcurrency: (0, schema_js_1.optionalize)(zod_1.z.number().int().min(0)),
189
- keepTextInToolUses: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
190
- catchToolsError: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
191
- structuredStreamMode: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
192
- })
193
- .extend(baseAgentSchema.shape),
194
- zod_1.z
195
- .object({
196
- type: zod_1.z.literal("image"),
197
- instructions: instructionsSchema,
198
- inputFileKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
199
- })
200
- .extend(baseAgentSchema.shape),
201
- zod_1.z
202
- .object({
203
- type: zod_1.z.literal("mcp"),
204
- url: (0, schema_js_1.optionalize)(zod_1.z.string()),
205
- command: (0, schema_js_1.optionalize)(zod_1.z.string()),
206
- args: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.string())),
207
- })
208
- .extend(baseAgentSchema.shape),
209
- zod_1.z
210
- .object({
211
- type: zod_1.z.literal("team"),
212
- mode: (0, schema_js_1.optionalize)(zod_1.z.nativeEnum(team_agent_js_1.ProcessMode)),
213
- iterateOn: (0, schema_js_1.optionalize)(zod_1.z.string()),
214
- concurrency: (0, schema_js_1.optionalize)(zod_1.z.number().int().min(1)),
215
- iterateWithPreviousOutput: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
216
- includeAllStepsOutput: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
217
- reflection: (0, schema_js_1.camelizeSchema)((0, schema_js_1.optionalize)(zod_1.z.object({
218
- reviewer: nestAgentSchema,
219
- isApproved: zod_1.z.string(),
220
- maxIterations: (0, schema_js_1.optionalize)(zod_1.z.number().int().min(1)),
221
- returnLastOnMaxIterations: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
222
- customErrorMessage: (0, schema_js_1.optionalize)(zod_1.z.string()),
223
- }))),
224
- })
225
- .extend(baseAgentSchema.shape),
226
- zod_1.z
227
- .object({
228
- type: zod_1.z.literal("transform"),
229
- jsonata: zod_1.z.string(),
230
- })
231
- .extend(baseAgentSchema.shape),
232
- zod_1.z
233
- .object({
234
- type: zod_1.z.literal("function"),
235
- process: zod_1.z.preprocess((v) => (typeof v === "string" ? (0, function_agent_js_1.codeToFunctionAgentFn)(v) : v), zod_1.z.custom()),
236
- })
237
- .extend(baseAgentSchema.shape),
238
- ]),
239
- ])));
104
+ return (0, schema_js_1.camelizeSchema)(baseAgentSchema.passthrough());
240
105
  });
241
106
  return agentSchema;
242
107
  };
@@ -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 {};