@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.
- package/CHANGELOG.md +27 -0
- package/lib/cjs/agents/agent.d.ts +31 -1
- package/lib/cjs/agents/agent.js +13 -0
- package/lib/cjs/agents/ai-agent.d.ts +7 -0
- package/lib/cjs/agents/ai-agent.js +85 -3
- package/lib/cjs/agents/image-agent.d.ts +17 -1
- package/lib/cjs/agents/image-agent.js +16 -0
- package/lib/cjs/agents/image-model.d.ts +4 -4
- package/lib/cjs/agents/mcp-agent.d.ts +17 -0
- package/lib/cjs/agents/mcp-agent.js +18 -0
- package/lib/cjs/agents/team-agent.d.ts +55 -0
- package/lib/cjs/agents/team-agent.js +31 -0
- package/lib/cjs/agents/transform-agent.d.ts +12 -0
- package/lib/cjs/agents/transform-agent.js +13 -0
- package/lib/cjs/agents/video-model.d.ts +4 -4
- package/lib/cjs/loader/agent-yaml.d.ts +5 -67
- package/lib/cjs/loader/agent-yaml.js +4 -139
- package/lib/cjs/loader/agents.d.ts +4 -0
- package/lib/cjs/loader/agents.js +17 -0
- package/lib/cjs/loader/index.d.ts +18 -14
- package/lib/cjs/loader/index.js +20 -81
- package/lib/cjs/loader/schema.d.ts +21 -6
- package/lib/cjs/loader/schema.js +60 -1
- package/lib/cjs/prompt/prompt-builder.js +0 -1
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.js +63 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +61 -0
- package/lib/cjs/prompt/skills/afs/delete.js +15 -3
- package/lib/cjs/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/cjs/prompt/skills/afs/edit.js +85 -59
- package/lib/cjs/prompt/skills/afs/exec.js +17 -6
- package/lib/cjs/prompt/skills/afs/index.js +4 -1
- package/lib/cjs/prompt/skills/afs/list.js +26 -10
- package/lib/cjs/prompt/skills/afs/read.d.ts +6 -2
- package/lib/cjs/prompt/skills/afs/read.js +62 -15
- package/lib/cjs/prompt/skills/afs/rename.js +18 -4
- package/lib/cjs/prompt/skills/afs/search.js +21 -5
- package/lib/cjs/prompt/skills/afs/write.js +20 -6
- package/lib/cjs/prompt/template.d.ts +23 -23
- package/lib/dts/agents/agent.d.ts +31 -1
- package/lib/dts/agents/ai-agent.d.ts +7 -0
- package/lib/dts/agents/image-agent.d.ts +17 -1
- package/lib/dts/agents/image-model.d.ts +4 -4
- package/lib/dts/agents/mcp-agent.d.ts +17 -0
- package/lib/dts/agents/team-agent.d.ts +55 -0
- package/lib/dts/agents/transform-agent.d.ts +12 -0
- package/lib/dts/agents/video-model.d.ts +4 -4
- package/lib/dts/aigne/context.d.ts +2 -2
- package/lib/dts/loader/agent-yaml.d.ts +5 -67
- package/lib/dts/loader/agents.d.ts +4 -0
- package/lib/dts/loader/index.d.ts +18 -14
- package/lib/dts/loader/schema.d.ts +21 -6
- package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
- package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
- package/lib/dts/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/dts/prompt/skills/afs/read.d.ts +6 -2
- package/lib/dts/prompt/template.d.ts +25 -25
- package/lib/esm/agents/agent.d.ts +31 -1
- package/lib/esm/agents/agent.js +13 -0
- package/lib/esm/agents/ai-agent.d.ts +7 -0
- package/lib/esm/agents/ai-agent.js +85 -3
- package/lib/esm/agents/image-agent.d.ts +17 -1
- package/lib/esm/agents/image-agent.js +16 -0
- package/lib/esm/agents/image-model.d.ts +4 -4
- package/lib/esm/agents/mcp-agent.d.ts +17 -0
- package/lib/esm/agents/mcp-agent.js +18 -0
- package/lib/esm/agents/team-agent.d.ts +55 -0
- package/lib/esm/agents/team-agent.js +31 -0
- package/lib/esm/agents/transform-agent.d.ts +12 -0
- package/lib/esm/agents/transform-agent.js +13 -0
- package/lib/esm/agents/video-model.d.ts +4 -4
- package/lib/esm/aigne/context.d.ts +2 -2
- package/lib/esm/loader/agent-yaml.d.ts +5 -67
- package/lib/esm/loader/agent-yaml.js +4 -138
- package/lib/esm/loader/agents.d.ts +4 -0
- package/lib/esm/loader/agents.js +14 -0
- package/lib/esm/loader/index.d.ts +18 -14
- package/lib/esm/loader/index.js +21 -81
- package/lib/esm/loader/schema.d.ts +21 -6
- package/lib/esm/loader/schema.js +57 -0
- package/lib/esm/prompt/prompt-builder.js +1 -2
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.js +59 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +53 -0
- package/lib/esm/prompt/skills/afs/delete.js +15 -3
- package/lib/esm/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/esm/prompt/skills/afs/edit.js +85 -59
- package/lib/esm/prompt/skills/afs/exec.js +17 -6
- package/lib/esm/prompt/skills/afs/index.js +4 -1
- package/lib/esm/prompt/skills/afs/list.js +26 -10
- package/lib/esm/prompt/skills/afs/read.d.ts +6 -2
- package/lib/esm/prompt/skills/afs/read.js +62 -15
- package/lib/esm/prompt/skills/afs/rename.js +18 -4
- package/lib/esm/prompt/skills/afs/search.js +21 -5
- package/lib/esm/prompt/skills/afs/write.js +20 -6
- package/lib/esm/prompt/template.d.ts +25 -25
- package/package.json +5 -4
|
@@ -2,12 +2,8 @@ import { jsonSchemaToZod } from "@aigne/json-schema-to-zod";
|
|
|
2
2
|
import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
|
|
3
3
|
import { parse } from "yaml";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import { AIAgentToolChoice } from "../agents/ai-agent.js";
|
|
6
|
-
import { roleSchema } from "../agents/chat-model.js";
|
|
7
|
-
import { ProcessMode } from "../agents/team-agent.js";
|
|
8
5
|
import { tryOrThrow } from "../utils/type-utils.js";
|
|
9
|
-
import {
|
|
10
|
-
import { camelizeSchema, chatModelSchema, defaultInputSchema, imageModelSchema, inputOutputSchema, optionalize, preprocessSchema, } from "./schema.js";
|
|
6
|
+
import { camelizeSchema, chatModelSchema, defaultInputSchema, imageModelSchema, inputOutputSchema, optionalize, } from "./schema.js";
|
|
11
7
|
export async function parseAgentFile(path, data, options) {
|
|
12
8
|
const agentSchema = getAgentSchema({ filepath: path, options });
|
|
13
9
|
return agentSchema.parseAsync({
|
|
@@ -25,51 +21,7 @@ export async function loadAgentFromYamlFile(path, options) {
|
|
|
25
21
|
}, options), (error) => new Error(`Failed to validate agent definition from ${path}: ${error.message}`));
|
|
26
22
|
return agent;
|
|
27
23
|
}
|
|
28
|
-
const
|
|
29
|
-
z.object({
|
|
30
|
-
role: roleSchema.default("system"),
|
|
31
|
-
url: z.string(),
|
|
32
|
-
cacheControl: optionalize(z.object({
|
|
33
|
-
type: z.literal("ephemeral"),
|
|
34
|
-
ttl: optionalize(z.union([z.literal("5m"), z.literal("1h")])),
|
|
35
|
-
})),
|
|
36
|
-
}),
|
|
37
|
-
z.object({
|
|
38
|
-
role: roleSchema.default("system"),
|
|
39
|
-
content: z.string(),
|
|
40
|
-
cacheControl: optionalize(z.object({
|
|
41
|
-
type: z.literal("ephemeral"),
|
|
42
|
-
ttl: optionalize(z.union([z.literal("5m"), z.literal("1h")])),
|
|
43
|
-
})),
|
|
44
|
-
}),
|
|
45
|
-
]));
|
|
46
|
-
const parseInstructionItem = ({ filepath }) => async ({ role, cacheControl, ...v }) => {
|
|
47
|
-
if (role === "tool")
|
|
48
|
-
throw new Error(`'tool' role is not allowed in instruction item in agent file ${filepath}`);
|
|
49
|
-
if ("content" in v && typeof v.content === "string") {
|
|
50
|
-
return { role, content: v.content, path: filepath, cacheControl };
|
|
51
|
-
}
|
|
52
|
-
if ("url" in v && typeof v.url === "string") {
|
|
53
|
-
const url = nodejs.path.isAbsolute(v.url)
|
|
54
|
-
? v.url
|
|
55
|
-
: nodejs.path.join(nodejs.path.dirname(filepath), v.url);
|
|
56
|
-
return nodejs.fs
|
|
57
|
-
.readFile(url, "utf8")
|
|
58
|
-
.then((content) => ({ role, content, path: url, cacheControl }));
|
|
59
|
-
}
|
|
60
|
-
throw new Error(`Invalid instruction item in agent file ${filepath}. Expected 'content' or 'url' property`);
|
|
61
|
-
};
|
|
62
|
-
export const getInstructionsSchema = ({ filepath }) => z
|
|
63
|
-
.union([z.string(), instructionItemSchema, z.array(instructionItemSchema)])
|
|
64
|
-
.transform(async (v) => {
|
|
65
|
-
if (typeof v === "string")
|
|
66
|
-
return [{ role: "system", content: v, path: filepath }];
|
|
67
|
-
if (Array.isArray(v)) {
|
|
68
|
-
return Promise.all(v.map((item) => parseInstructionItem({ filepath })(item)));
|
|
69
|
-
}
|
|
70
|
-
return [await parseInstructionItem({ filepath })(v)];
|
|
71
|
-
});
|
|
72
|
-
export const getAgentSchema = ({ filepath, options, }) => {
|
|
24
|
+
export const getAgentSchema = ({ filepath }) => {
|
|
73
25
|
const agentSchema = z.lazy(() => {
|
|
74
26
|
const nestAgentSchema = z.lazy(() => z.union([
|
|
75
27
|
agentSchema,
|
|
@@ -105,6 +57,7 @@ export const getAgentSchema = ({ filepath, options, }) => {
|
|
|
105
57
|
}))),
|
|
106
58
|
});
|
|
107
59
|
const baseAgentSchema = z.object({
|
|
60
|
+
type: z.string(),
|
|
108
61
|
name: optionalize(z.string()),
|
|
109
62
|
alias: optionalize(z.array(z.string())),
|
|
110
63
|
description: optionalize(z.string()),
|
|
@@ -143,94 +96,7 @@ export const getAgentSchema = ({ filepath, options, }) => {
|
|
|
143
96
|
])),
|
|
144
97
|
shareAFS: optionalize(z.boolean()),
|
|
145
98
|
});
|
|
146
|
-
|
|
147
|
-
return camelizeSchema(preprocessSchema(async (json) => {
|
|
148
|
-
if (typeof json === "object" &&
|
|
149
|
-
json &&
|
|
150
|
-
"type" in json &&
|
|
151
|
-
typeof json.type === "string" &&
|
|
152
|
-
!["ai", "image", "mcp", "team", "transform", "function"].includes(json.type)) {
|
|
153
|
-
if (!options?.require)
|
|
154
|
-
throw new Error(`Module loader is not provided to load agent type module ${json.type} from ${filepath}`);
|
|
155
|
-
const Mod = await options.require(json.type, { parent: filepath });
|
|
156
|
-
if (typeof Mod?.default?.prototype?.constructor !== "function") {
|
|
157
|
-
throw new Error(`The agent type module ${json.type} does not export a default Agent class`);
|
|
158
|
-
}
|
|
159
|
-
Object.assign(json, { agentClass: Mod.default });
|
|
160
|
-
}
|
|
161
|
-
return json;
|
|
162
|
-
}, z.union([
|
|
163
|
-
z
|
|
164
|
-
.object({
|
|
165
|
-
type: z.string(),
|
|
166
|
-
agentClass: z.custom((v) => typeof v?.prototype?.constructor === "function"),
|
|
167
|
-
})
|
|
168
|
-
.extend(baseAgentSchema.shape)
|
|
169
|
-
.passthrough(),
|
|
170
|
-
z.discriminatedUnion("type", [
|
|
171
|
-
z
|
|
172
|
-
.object({
|
|
173
|
-
type: z.literal("ai"),
|
|
174
|
-
instructions: optionalize(instructionsSchema),
|
|
175
|
-
autoReorderSystemMessages: optionalize(z.boolean()),
|
|
176
|
-
autoMergeSystemMessages: optionalize(z.boolean()),
|
|
177
|
-
inputKey: optionalize(z.string()),
|
|
178
|
-
outputKey: optionalize(z.string()),
|
|
179
|
-
inputFileKey: optionalize(z.string()),
|
|
180
|
-
outputFileKey: optionalize(z.string()),
|
|
181
|
-
toolChoice: optionalize(z.nativeEnum(AIAgentToolChoice)),
|
|
182
|
-
toolCallsConcurrency: optionalize(z.number().int().min(0)),
|
|
183
|
-
keepTextInToolUses: optionalize(z.boolean()),
|
|
184
|
-
catchToolsError: optionalize(z.boolean()),
|
|
185
|
-
structuredStreamMode: optionalize(z.boolean()),
|
|
186
|
-
})
|
|
187
|
-
.extend(baseAgentSchema.shape),
|
|
188
|
-
z
|
|
189
|
-
.object({
|
|
190
|
-
type: z.literal("image"),
|
|
191
|
-
instructions: instructionsSchema,
|
|
192
|
-
inputFileKey: optionalize(z.string()),
|
|
193
|
-
})
|
|
194
|
-
.extend(baseAgentSchema.shape),
|
|
195
|
-
z
|
|
196
|
-
.object({
|
|
197
|
-
type: z.literal("mcp"),
|
|
198
|
-
url: optionalize(z.string()),
|
|
199
|
-
command: optionalize(z.string()),
|
|
200
|
-
args: optionalize(z.array(z.string())),
|
|
201
|
-
})
|
|
202
|
-
.extend(baseAgentSchema.shape),
|
|
203
|
-
z
|
|
204
|
-
.object({
|
|
205
|
-
type: z.literal("team"),
|
|
206
|
-
mode: optionalize(z.nativeEnum(ProcessMode)),
|
|
207
|
-
iterateOn: optionalize(z.string()),
|
|
208
|
-
concurrency: optionalize(z.number().int().min(1)),
|
|
209
|
-
iterateWithPreviousOutput: optionalize(z.boolean()),
|
|
210
|
-
includeAllStepsOutput: optionalize(z.boolean()),
|
|
211
|
-
reflection: camelizeSchema(optionalize(z.object({
|
|
212
|
-
reviewer: nestAgentSchema,
|
|
213
|
-
isApproved: z.string(),
|
|
214
|
-
maxIterations: optionalize(z.number().int().min(1)),
|
|
215
|
-
returnLastOnMaxIterations: optionalize(z.boolean()),
|
|
216
|
-
customErrorMessage: optionalize(z.string()),
|
|
217
|
-
}))),
|
|
218
|
-
})
|
|
219
|
-
.extend(baseAgentSchema.shape),
|
|
220
|
-
z
|
|
221
|
-
.object({
|
|
222
|
-
type: z.literal("transform"),
|
|
223
|
-
jsonata: z.string(),
|
|
224
|
-
})
|
|
225
|
-
.extend(baseAgentSchema.shape),
|
|
226
|
-
z
|
|
227
|
-
.object({
|
|
228
|
-
type: z.literal("function"),
|
|
229
|
-
process: z.preprocess((v) => (typeof v === "string" ? codeToFunctionAgentFn(v) : v), z.custom()),
|
|
230
|
-
})
|
|
231
|
-
.extend(baseAgentSchema.shape),
|
|
232
|
-
]),
|
|
233
|
-
])));
|
|
99
|
+
return camelizeSchema(baseAgentSchema.passthrough());
|
|
234
100
|
});
|
|
235
101
|
return agentSchema;
|
|
236
102
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FunctionAgent } from "../agents/agent.js";
|
|
2
|
+
import { AIAgent } from "../agents/ai-agent.js";
|
|
3
|
+
import { ImageAgent } from "../agents/image-agent.js";
|
|
4
|
+
import { MCPAgent } from "../agents/mcp-agent.js";
|
|
5
|
+
import { TeamAgent } from "../agents/team-agent.js";
|
|
6
|
+
import { TransformAgent } from "../agents/transform-agent.js";
|
|
7
|
+
export const builtinAgents = {
|
|
8
|
+
ai: AIAgent,
|
|
9
|
+
function: FunctionAgent,
|
|
10
|
+
image: ImageAgent,
|
|
11
|
+
mcp: MCPAgent,
|
|
12
|
+
team: TeamAgent,
|
|
13
|
+
transform: TransformAgent,
|
|
14
|
+
};
|
|
@@ -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 {
|
|
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
|
-
|
|
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" | "
|
|
75
|
+
thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
|
|
71
76
|
$get: string;
|
|
72
|
-
} | undefined, z.ZodTypeDef, number | "high" | "
|
|
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" | "
|
|
106
|
+
thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
|
|
102
107
|
$get: string;
|
|
103
|
-
} | undefined, z.ZodTypeDef, number | "high" | "
|
|
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" | "
|
|
167
|
+
thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
|
|
162
168
|
$get: string;
|
|
163
|
-
} | undefined, z.ZodTypeDef, number | "high" | "
|
|
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" | "
|
|
218
|
+
thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
|
|
213
219
|
$get: string;
|
|
214
|
-
} | undefined, z.ZodTypeDef, number | "high" | "
|
|
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 {};
|
package/lib/esm/loader/index.js
CHANGED
|
@@ -2,18 +2,12 @@ import { AFS } from "@aigne/afs";
|
|
|
2
2
|
import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
|
|
3
3
|
import { parse } from "yaml";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import { Agent
|
|
6
|
-
import { AIAgent } from "../agents/ai-agent.js";
|
|
7
|
-
import { ImageAgent } from "../agents/image-agent.js";
|
|
8
|
-
import { MCPAgent } from "../agents/mcp-agent.js";
|
|
9
|
-
import { TeamAgent } from "../agents/team-agent.js";
|
|
10
|
-
import { TransformAgent } from "../agents/transform-agent.js";
|
|
11
|
-
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
12
|
-
import { ChatMessagesTemplate, parseChatMessages } from "../prompt/template.js";
|
|
5
|
+
import { Agent } from "../agents/agent.js";
|
|
13
6
|
import { isAgent } from "../utils/agent-utils.js";
|
|
14
7
|
import { flat, isNil, isNonNullable, omitBy, tryOrThrow, } from "../utils/type-utils.js";
|
|
15
8
|
import { loadAgentFromJsFile } from "./agent-js.js";
|
|
16
9
|
import { loadAgentFromYamlFile, } from "./agent-yaml.js";
|
|
10
|
+
import { builtinAgents } from "./agents.js";
|
|
17
11
|
import { camelizeSchema, chatModelSchema, imageModelSchema, optionalize } from "./schema.js";
|
|
18
12
|
const AIGNE_FILE_NAME = ["aigne.yaml", "aigne.yml"];
|
|
19
13
|
export async function load(path, options = {}) {
|
|
@@ -154,7 +148,10 @@ export async function parseAgent(path, agent, options, agentOptions) {
|
|
|
154
148
|
const mod = options?.afs?.availableModules?.find((mod) => mod.module === moduleName || mod.alias?.includes(moduleName));
|
|
155
149
|
if (!mod)
|
|
156
150
|
throw new Error(`AFS module not found: ${typeof m === "string" ? m : m.module}`);
|
|
157
|
-
const module = await mod.
|
|
151
|
+
const module = await mod.load({
|
|
152
|
+
filepath: path,
|
|
153
|
+
parsed: typeof m === "string" ? {} : m.options,
|
|
154
|
+
});
|
|
158
155
|
afs.mount(module);
|
|
159
156
|
}
|
|
160
157
|
}
|
|
@@ -186,73 +183,24 @@ export async function parseAgent(path, agent, options, agentOptions) {
|
|
|
186
183
|
skills: [...(agentOptions?.skills || []), ...skills],
|
|
187
184
|
afs: afs || agentOptions?.afs,
|
|
188
185
|
};
|
|
189
|
-
let
|
|
190
|
-
if (
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
...baseOptions,
|
|
197
|
-
instructions,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
case "image": {
|
|
201
|
-
if (!instructions)
|
|
202
|
-
throw new Error(`Missing required instructions for image agent at path: ${path}`);
|
|
203
|
-
return ImageAgent.from({
|
|
204
|
-
...baseOptions,
|
|
205
|
-
instructions,
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
case "mcp": {
|
|
209
|
-
if (agent.url) {
|
|
210
|
-
return MCPAgent.from({
|
|
211
|
-
...baseOptions,
|
|
212
|
-
url: agent.url,
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
if (agent.command) {
|
|
216
|
-
return MCPAgent.from({
|
|
217
|
-
...baseOptions,
|
|
218
|
-
command: agent.command,
|
|
219
|
-
args: agent.args,
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
throw new Error(`Missing url or command in mcp agent: ${path}`);
|
|
223
|
-
}
|
|
224
|
-
case "team": {
|
|
225
|
-
return TeamAgent.from({
|
|
226
|
-
...baseOptions,
|
|
227
|
-
mode: agent.mode,
|
|
228
|
-
iterateOn: agent.iterateOn,
|
|
229
|
-
reflection: agent.reflection && {
|
|
230
|
-
...agent.reflection,
|
|
231
|
-
reviewer: await loadNestAgent(path, agent.reflection.reviewer, options),
|
|
232
|
-
},
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
case "transform": {
|
|
236
|
-
return TransformAgent.from({
|
|
237
|
-
...baseOptions,
|
|
238
|
-
jsonata: agent.jsonata,
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
case "function": {
|
|
242
|
-
return FunctionAgent.from({
|
|
243
|
-
...baseOptions,
|
|
244
|
-
process: agent.process,
|
|
245
|
-
});
|
|
186
|
+
let agentClass = builtinAgents[agent.type];
|
|
187
|
+
if (!agentClass) {
|
|
188
|
+
if (!options?.require)
|
|
189
|
+
throw new Error(`Module loader is not provided to load agent type module ${agent.type} from ${path}`);
|
|
190
|
+
const Mod = await options.require(agent.type, { parent: path });
|
|
191
|
+
if (typeof Mod?.default?.prototype?.constructor !== "function") {
|
|
192
|
+
throw new Error(`The agent type module ${agent.type} does not export a default Agent class`);
|
|
246
193
|
}
|
|
194
|
+
agentClass = Mod.default;
|
|
247
195
|
}
|
|
248
|
-
if (
|
|
249
|
-
|
|
250
|
-
filepath: path,
|
|
251
|
-
parsed: baseOptions,
|
|
252
|
-
options,
|
|
253
|
-
});
|
|
196
|
+
if (!agentClass) {
|
|
197
|
+
throw new Error(`Unsupported agent type: ${agent.type} from ${path}`);
|
|
254
198
|
}
|
|
255
|
-
|
|
199
|
+
return await agentClass.load({
|
|
200
|
+
filepath: path,
|
|
201
|
+
parsed: baseOptions,
|
|
202
|
+
options: { ...options, loadNestAgent },
|
|
203
|
+
});
|
|
256
204
|
}
|
|
257
205
|
async function loadMemory(memories, provider, options) {
|
|
258
206
|
const M = !provider
|
|
@@ -308,11 +256,3 @@ export async function findAIGNEFile(path) {
|
|
|
308
256
|
}
|
|
309
257
|
throw new Error(`aigne.yaml not found in ${path}. Please ensure you are in the correct directory or provide a valid path.`);
|
|
310
258
|
}
|
|
311
|
-
export function instructionsToPromptBuilder(instructions) {
|
|
312
|
-
return new PromptBuilder({
|
|
313
|
-
instructions: ChatMessagesTemplate.from(parseChatMessages(instructions.map((i) => ({
|
|
314
|
-
...i,
|
|
315
|
-
options: { workingDir: nodejs.path.dirname(i.path) },
|
|
316
|
-
})))),
|
|
317
|
-
});
|
|
318
|
-
}
|
|
@@ -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" | "
|
|
60
|
+
thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
|
|
59
61
|
$get: string;
|
|
60
|
-
} | undefined, z.ZodTypeDef, number | "high" | "
|
|
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" | "
|
|
91
|
+
thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
|
|
90
92
|
$get: string;
|
|
91
|
-
} | undefined, z.ZodTypeDef, number | "high" | "
|
|
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" | "
|
|
122
|
+
thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
|
|
121
123
|
$get: string;
|
|
122
|
-
} | undefined, z.ZodTypeDef, number | "high" | "
|
|
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 {};
|
package/lib/esm/loader/schema.js
CHANGED
|
@@ -2,6 +2,9 @@ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
|
|
|
2
2
|
import { parse } from "yaml";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { getterSchema } from "../agents/agent.js";
|
|
5
|
+
import { roleSchema } from "../agents/chat-model.js";
|
|
6
|
+
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
7
|
+
import { ChatMessagesTemplate, parseChatMessages } from "../prompt/template.js";
|
|
5
8
|
import { camelize } from "../utils/camelize.js";
|
|
6
9
|
import { isRecord } from "../utils/type-utils.js";
|
|
7
10
|
export const inputOutputSchema = ({ path }) => {
|
|
@@ -94,3 +97,57 @@ export function camelizeSchema(schema, { shallow = true } = {}) {
|
|
|
94
97
|
export function preprocessSchema(fn, schema) {
|
|
95
98
|
return z.preprocess(fn, schema);
|
|
96
99
|
}
|
|
100
|
+
const instructionItemSchema = camelizeSchema(z.union([
|
|
101
|
+
z.object({
|
|
102
|
+
role: roleSchema.default("system"),
|
|
103
|
+
url: z.string(),
|
|
104
|
+
cacheControl: optionalize(z.object({
|
|
105
|
+
type: z.literal("ephemeral"),
|
|
106
|
+
ttl: optionalize(z.union([z.literal("5m"), z.literal("1h")])),
|
|
107
|
+
})),
|
|
108
|
+
}),
|
|
109
|
+
z.object({
|
|
110
|
+
role: roleSchema.default("system"),
|
|
111
|
+
content: z.string(),
|
|
112
|
+
cacheControl: optionalize(z.object({
|
|
113
|
+
type: z.literal("ephemeral"),
|
|
114
|
+
ttl: optionalize(z.union([z.literal("5m"), z.literal("1h")])),
|
|
115
|
+
})),
|
|
116
|
+
}),
|
|
117
|
+
]));
|
|
118
|
+
const parseInstructionItem = ({ filepath }) => async ({ role, cacheControl, ...v }) => {
|
|
119
|
+
if (role === "tool")
|
|
120
|
+
throw new Error(`'tool' role is not allowed in instruction item in agent file ${filepath}`);
|
|
121
|
+
if ("content" in v && typeof v.content === "string") {
|
|
122
|
+
return { role, content: v.content, path: filepath, cacheControl };
|
|
123
|
+
}
|
|
124
|
+
if ("url" in v && typeof v.url === "string") {
|
|
125
|
+
const url = nodejs.path.isAbsolute(v.url)
|
|
126
|
+
? v.url
|
|
127
|
+
: nodejs.path.join(nodejs.path.dirname(filepath), v.url);
|
|
128
|
+
return nodejs.fs
|
|
129
|
+
.readFile(url, "utf8")
|
|
130
|
+
.then((content) => ({ role, content, path: url, cacheControl }));
|
|
131
|
+
}
|
|
132
|
+
throw new Error(`Invalid instruction item in agent file ${filepath}. Expected 'content' or 'url' property`);
|
|
133
|
+
};
|
|
134
|
+
export const getInstructionsSchema = ({ filepath }) => z
|
|
135
|
+
.union([z.string(), instructionItemSchema, z.array(instructionItemSchema)])
|
|
136
|
+
.transform(async (v) => {
|
|
137
|
+
if (typeof v === "string")
|
|
138
|
+
return [{ role: "system", content: v, path: filepath }];
|
|
139
|
+
if (Array.isArray(v)) {
|
|
140
|
+
return Promise.all(v.map((item) => parseInstructionItem({ filepath })(item)));
|
|
141
|
+
}
|
|
142
|
+
return [await parseInstructionItem({ filepath })(v)];
|
|
143
|
+
});
|
|
144
|
+
export function instructionsToPromptBuilder(instructions) {
|
|
145
|
+
return new PromptBuilder({
|
|
146
|
+
instructions: typeof instructions === "string"
|
|
147
|
+
? instructions
|
|
148
|
+
: ChatMessagesTemplate.from(parseChatMessages(instructions.map((i) => ({
|
|
149
|
+
...i,
|
|
150
|
+
options: { workingDir: nodejs.path.dirname(i.path) },
|
|
151
|
+
})))),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
@@ -10,7 +10,7 @@ import { optionalize } from "../loader/schema.js";
|
|
|
10
10
|
import { outputSchemaToResponseFormatSchema } from "../utils/json-schema.js";
|
|
11
11
|
import { checkArguments, flat, isNonNullable, isRecord, partition, unique, } from "../utils/type-utils.js";
|
|
12
12
|
import { createPromptBuilderContext } from "./context/index.js";
|
|
13
|
-
import { AFS_EXECUTABLE_TOOLS_PROMPT_TEMPLATE
|
|
13
|
+
import { AFS_EXECUTABLE_TOOLS_PROMPT_TEMPLATE } from "./prompts/afs-builtin-prompt.js";
|
|
14
14
|
import { MEMORY_MESSAGE_TEMPLATE } from "./prompts/memory-message-template.js";
|
|
15
15
|
import { STRUCTURED_STREAM_INSTRUCTIONS } from "./prompts/structured-stream-instructions.js";
|
|
16
16
|
import { getAFSSkills } from "./skills/afs/index.js";
|
|
@@ -116,7 +116,6 @@ export class PromptBuilder {
|
|
|
116
116
|
const afs = options.agent?.afs;
|
|
117
117
|
if (afs && options.agent?.historyConfig?.disabled !== true) {
|
|
118
118
|
const historyModule = (await afs.listModules()).find((m) => m.module instanceof AFSHistory);
|
|
119
|
-
messages.push(await SystemMessageTemplate.from(await getAFSSystemPrompt(afs)).format({}));
|
|
120
119
|
if (historyModule) {
|
|
121
120
|
const history = await afs.list(historyModule.path, {
|
|
122
121
|
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,59 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Agent } from "../../../../agents/agent.js";
|
|
3
|
+
const skillToolInputSchema = z.object({
|
|
4
|
+
skill: z.string().describe("The name of the skill agent to invoke."),
|
|
5
|
+
args: z.string().optional().describe("The arguments to pass to the skill."),
|
|
6
|
+
});
|
|
7
|
+
export class AgentSkill extends Agent {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super({
|
|
10
|
+
name: "Skill",
|
|
11
|
+
taskTitle: "Invoke {{skill}}: {{args}}",
|
|
12
|
+
...options,
|
|
13
|
+
description: `\
|
|
14
|
+
Execute a skill within the main conversation
|
|
15
|
+
|
|
16
|
+
<skills_instructions>
|
|
17
|
+
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.
|
|
18
|
+
|
|
19
|
+
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.
|
|
20
|
+
|
|
21
|
+
User: "run /commit" Assistant: [Calls Skill tool with skill: "commit"]
|
|
22
|
+
How to invoke:
|
|
23
|
+
|
|
24
|
+
Use this tool with the skill name and optional arguments
|
|
25
|
+
|
|
26
|
+
Important:
|
|
27
|
+
|
|
28
|
+
When a skill is relevant, you must invoke this tool IMMEDIATELY as your first action
|
|
29
|
+
NEVER just announce or mention a skill in your text response without actually calling this tool
|
|
30
|
+
This is a BLOCKING REQUIREMENT: invoke the relevant Skill tool BEFORE generating any other response about the task
|
|
31
|
+
Only use skills listed in <available_skills> below
|
|
32
|
+
Do not invoke a skill that is already running
|
|
33
|
+
Do not use this tool for built-in CLI commands (like /help, /clear, etc.)
|
|
34
|
+
</skills_instructions>
|
|
35
|
+
|
|
36
|
+
<available_skills>
|
|
37
|
+
${options.agentSkills.map((s) => `${s.name}: ${s.description}`).join("\n\n")}
|
|
38
|
+
</available_skills>
|
|
39
|
+
`,
|
|
40
|
+
inputSchema: skillToolInputSchema,
|
|
41
|
+
});
|
|
42
|
+
this.agentSkills = options.agentSkills;
|
|
43
|
+
}
|
|
44
|
+
agentSkills;
|
|
45
|
+
async process(input) {
|
|
46
|
+
const skill = this.agentSkills.find((s) => s.name === input.skill);
|
|
47
|
+
if (!skill)
|
|
48
|
+
throw new Error(`Skill not found: ${input.skill}`);
|
|
49
|
+
return {
|
|
50
|
+
result: `\
|
|
51
|
+
Base directory for this skill: ${skill.path}
|
|
52
|
+
|
|
53
|
+
${skill.content}
|
|
54
|
+
|
|
55
|
+
${input.args ? `ARGUMENTS: ${input.args ?? "None"}` : ""}
|
|
56
|
+
`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|