@aigne/core 1.71.0-beta → 1.71.0-beta.2
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 +14 -0
- package/lib/cjs/agents/agent.d.ts +6 -0
- package/lib/cjs/agents/agent.js +4 -1
- package/lib/cjs/loader/index.d.ts +2 -1
- package/lib/cjs/loader/index.js +1 -0
- package/lib/cjs/prompt/filters/index.js +11 -9
- package/lib/cjs/prompt/prompt-builder.d.ts +4 -0
- package/lib/cjs/prompt/prompt-builder.js +55 -1
- package/lib/cjs/prompt/prompts/afs-builtin-prompt.d.ts +1 -0
- package/lib/cjs/prompt/prompts/afs-builtin-prompt.js +7 -4
- package/lib/dts/agents/agent.d.ts +6 -0
- package/lib/dts/loader/index.d.ts +2 -1
- package/lib/dts/prompt/prompt-builder.d.ts +4 -0
- package/lib/dts/prompt/prompts/afs-builtin-prompt.d.ts +1 -0
- package/lib/esm/agents/agent.d.ts +6 -0
- package/lib/esm/agents/agent.js +4 -1
- package/lib/esm/loader/index.d.ts +2 -1
- package/lib/esm/loader/index.js +1 -1
- package/lib/esm/prompt/filters/index.js +11 -9
- package/lib/esm/prompt/prompt-builder.d.ts +4 -0
- package/lib/esm/prompt/prompt-builder.js +57 -3
- package/lib/esm/prompt/prompts/afs-builtin-prompt.d.ts +1 -0
- package/lib/esm/prompt/prompts/afs-builtin-prompt.js +6 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.71.0-beta.2](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.71.0-beta.1...core-v1.71.0-beta.2) (2025-12-09)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **orchestrator:** enhance prompts with detailed guidance ([#811](https://github.com/AIGNE-io/aigne-framework/issues/811)) ([5656f38](https://github.com/AIGNE-io/aigne-framework/commit/5656f38c09e458e18b90e962a5e85c96755be2e4))
|
|
9
|
+
|
|
10
|
+
## [1.71.0-beta.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.71.0-beta...core-v1.71.0-beta.1) (2025-12-08)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* correct run example & doc improvements ([#707](https://github.com/AIGNE-io/aigne-framework/issues/707)) ([f98fc5d](https://github.com/AIGNE-io/aigne-framework/commit/f98fc5df28fd6ce6134128c2f0e5395c1554b740))
|
|
16
|
+
|
|
3
17
|
## [1.71.0-beta](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.70.1...core-v1.71.0-beta) (2025-12-07)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -118,6 +118,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
118
118
|
* agentSucceed, or agentFailed
|
|
119
119
|
*/
|
|
120
120
|
disableEvents?: boolean;
|
|
121
|
+
historyConfig?: Agent["historyConfig"];
|
|
121
122
|
/**
|
|
122
123
|
* One or more memory agents this agent can use
|
|
123
124
|
*/
|
|
@@ -346,6 +347,11 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
346
347
|
* agentSucceed, or agentFailed
|
|
347
348
|
*/
|
|
348
349
|
private disableEvents?;
|
|
350
|
+
historyConfig?: {
|
|
351
|
+
disabled?: boolean;
|
|
352
|
+
maxTokens?: number;
|
|
353
|
+
maxItems?: number;
|
|
354
|
+
};
|
|
349
355
|
private subscriptions;
|
|
350
356
|
/**
|
|
351
357
|
* Attach agent to context:
|
package/lib/cjs/agents/agent.js
CHANGED
|
@@ -151,6 +151,7 @@ class Agent {
|
|
|
151
151
|
if (options.skills?.length)
|
|
152
152
|
this.skills.push(...options.skills.map(functionToAgent));
|
|
153
153
|
this.disableEvents = options.disableEvents;
|
|
154
|
+
this.historyConfig = options.historyConfig;
|
|
154
155
|
if (Array.isArray(options.memory)) {
|
|
155
156
|
this.memories.push(...options.memory);
|
|
156
157
|
}
|
|
@@ -324,6 +325,7 @@ class Agent {
|
|
|
324
325
|
* agentSucceed, or agentFailed
|
|
325
326
|
*/
|
|
326
327
|
disableEvents;
|
|
328
|
+
historyConfig;
|
|
327
329
|
subscriptions = [];
|
|
328
330
|
/**
|
|
329
331
|
* Attach agent to context:
|
|
@@ -567,7 +569,8 @@ class Agent {
|
|
|
567
569
|
const o = await this.callHooks(["onSuccess", "onEnd"], { input, output: finalOutput }, options);
|
|
568
570
|
if (o?.output)
|
|
569
571
|
finalOutput = o.output;
|
|
570
|
-
this.
|
|
572
|
+
if (this.historyConfig?.disabled !== true)
|
|
573
|
+
this.afs?.emit("agentSucceed", { input, output: finalOutput });
|
|
571
574
|
if (!this.disableEvents)
|
|
572
575
|
context.emit("agentSucceed", { agent: this, output: finalOutput });
|
|
573
576
|
return finalOutput;
|
|
@@ -29,7 +29,7 @@ export interface LoadOptions {
|
|
|
29
29
|
}
|
|
30
30
|
export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
|
|
31
31
|
export declare function loadAgent(path: string, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
32
|
-
export declare function loadNestAgent(path: string, agent: NestAgentSchema, options?: LoadOptions, agentOptions?: AgentOptions & Record<string, unknown>): Promise<Agent>;
|
|
32
|
+
export declare function loadNestAgent(path: string, agent: NestAgentSchema, options?: LoadOptions, agentOptions?: AgentOptions<any, any> & Record<string, unknown>): Promise<Agent>;
|
|
33
33
|
export declare function parseAgent(path: string, agent: Awaited<ReturnType<typeof loadAgentFromYamlFile>>, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
34
34
|
type CliAgent = string | {
|
|
35
35
|
url?: string;
|
|
@@ -238,5 +238,6 @@ export declare function loadAIGNEFile(path: string): Promise<{
|
|
|
238
238
|
aigne: z.infer<typeof aigneFileSchema>;
|
|
239
239
|
rootDir: string;
|
|
240
240
|
}>;
|
|
241
|
+
export declare function findAIGNEFile(path: string): Promise<string>;
|
|
241
242
|
export declare function instructionsToPromptBuilder(instructions: Instructions): PromptBuilder;
|
|
242
243
|
export {};
|
package/lib/cjs/loader/index.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.loadAgent = loadAgent;
|
|
|
5
5
|
exports.loadNestAgent = loadNestAgent;
|
|
6
6
|
exports.parseAgent = parseAgent;
|
|
7
7
|
exports.loadAIGNEFile = loadAIGNEFile;
|
|
8
|
+
exports.findAIGNEFile = findAIGNEFile;
|
|
8
9
|
exports.instructionsToPromptBuilder = instructionsToPromptBuilder;
|
|
9
10
|
const afs_1 = require("@aigne/afs");
|
|
10
11
|
const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
|
|
@@ -37,13 +37,15 @@ exports.setupFilters = setupFilters;
|
|
|
37
37
|
const tson = __importStar(require("@zenoaihq/tson"));
|
|
38
38
|
const yaml_1 = require("yaml");
|
|
39
39
|
function setupFilters(env) {
|
|
40
|
-
env.addFilter("yaml.stringify", (obj) => {
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
env.addFilter("json.stringify", (obj, ...args) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
env.addFilter("yaml.stringify", async (obj, cb) => {
|
|
41
|
+
cb(null, (0, yaml_1.stringify)(await obj));
|
|
42
|
+
}, true);
|
|
43
|
+
env.addFilter("json.stringify", async (obj, ...args) => {
|
|
44
|
+
const jsonArgs = args.slice(0, -1);
|
|
45
|
+
const cb = args[args.length - 1];
|
|
46
|
+
cb(null, JSON.stringify(await obj, ...jsonArgs));
|
|
47
|
+
}, true);
|
|
48
|
+
env.addFilter("tson.stringify", async (obj, cb) => {
|
|
49
|
+
cb(null, tson.dumps(await obj));
|
|
50
|
+
}, true);
|
|
49
51
|
}
|
|
@@ -37,6 +37,10 @@ export declare class PromptBuilder {
|
|
|
37
37
|
}>;
|
|
38
38
|
private getTemplateVariables;
|
|
39
39
|
private buildMessages;
|
|
40
|
+
getHistories(options: PromptBuildOptions): Promise<{
|
|
41
|
+
role: "user" | "agent";
|
|
42
|
+
content: unknown;
|
|
43
|
+
}[]>;
|
|
40
44
|
private refineMessages;
|
|
41
45
|
private convertMemoriesToMessages;
|
|
42
46
|
private buildResponseFormat;
|
|
@@ -95,10 +95,36 @@ class PromptBuilder {
|
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
getTemplateVariables(options) {
|
|
98
|
+
const self = this;
|
|
98
99
|
return {
|
|
99
100
|
userContext: options.context?.userContext,
|
|
100
101
|
...options.context?.userContext,
|
|
101
102
|
...options.input,
|
|
103
|
+
$afs: {
|
|
104
|
+
get enabled() {
|
|
105
|
+
return !!options.agent?.afs;
|
|
106
|
+
},
|
|
107
|
+
description: afs_builtin_prompt_js_1.AFS_DESCRIPTION_PROMPT_TEMPLATE,
|
|
108
|
+
get modules() {
|
|
109
|
+
return options.agent?.afs
|
|
110
|
+
?.listModules()
|
|
111
|
+
.then((list) => list.map((i) => (0, type_utils_js_1.pick)(i, ["name", "path", "description"])));
|
|
112
|
+
},
|
|
113
|
+
get histories() {
|
|
114
|
+
return self.getHistories(options);
|
|
115
|
+
},
|
|
116
|
+
get skills() {
|
|
117
|
+
const afs = options.agent?.afs;
|
|
118
|
+
if (!afs)
|
|
119
|
+
return [];
|
|
120
|
+
return (0, afs_js_1.getAFSSkills)(afs).then((skills) => skills.map((s) => (0, type_utils_js_1.pick)(s, ["name", "description"])));
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
$agent: {
|
|
124
|
+
get skills() {
|
|
125
|
+
return options.agent?.skills.map((s) => (0, type_utils_js_1.pick)(s, ["name", "description"]));
|
|
126
|
+
},
|
|
127
|
+
},
|
|
102
128
|
};
|
|
103
129
|
}
|
|
104
130
|
async buildMessages(options) {
|
|
@@ -120,7 +146,7 @@ class PromptBuilder {
|
|
|
120
146
|
memories.push(...options.context.memories);
|
|
121
147
|
}
|
|
122
148
|
const afs = options.agent?.afs;
|
|
123
|
-
if (afs) {
|
|
149
|
+
if (afs && options.agent?.historyConfig?.disabled !== true) {
|
|
124
150
|
const historyModule = (await afs.listModules()).find((m) => m.module instanceof afs_history_1.AFSHistory);
|
|
125
151
|
messages.push(await template_js_1.SystemMessageTemplate.from(await (0, afs_builtin_prompt_js_1.getAFSSystemPrompt)(afs)).format({}));
|
|
126
152
|
if (historyModule) {
|
|
@@ -198,6 +224,34 @@ class PromptBuilder {
|
|
|
198
224
|
messages.push(...otherCustomMessages);
|
|
199
225
|
return this.refineMessages(options, messages);
|
|
200
226
|
}
|
|
227
|
+
async getHistories(options) {
|
|
228
|
+
const { agent } = options;
|
|
229
|
+
const afs = agent?.afs;
|
|
230
|
+
if (!afs)
|
|
231
|
+
return [];
|
|
232
|
+
const historyModule = (await afs.listModules()).find((m) => m.module instanceof afs_history_1.AFSHistory);
|
|
233
|
+
if (!historyModule)
|
|
234
|
+
return [];
|
|
235
|
+
const { list: history } = await afs.list(historyModule.path, {
|
|
236
|
+
limit: agent.historyConfig?.maxItems || 10,
|
|
237
|
+
orderBy: [["createdAt", "desc"]],
|
|
238
|
+
});
|
|
239
|
+
return history
|
|
240
|
+
.reverse()
|
|
241
|
+
.map((i) => {
|
|
242
|
+
if (!i.content)
|
|
243
|
+
return;
|
|
244
|
+
const { input, output } = i.content;
|
|
245
|
+
if (!input || !output)
|
|
246
|
+
return;
|
|
247
|
+
return [
|
|
248
|
+
{ role: "user", content: input },
|
|
249
|
+
{ role: "agent", content: output },
|
|
250
|
+
];
|
|
251
|
+
})
|
|
252
|
+
.filter(type_utils_js_1.isNonNullable)
|
|
253
|
+
.flat();
|
|
254
|
+
}
|
|
201
255
|
refineMessages(options, messages) {
|
|
202
256
|
const { autoReorderSystemMessages, autoMergeSystemMessages } = options.agent ?? {};
|
|
203
257
|
if (!autoReorderSystemMessages && !autoMergeSystemMessages)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { AFS } from "@aigne/afs";
|
|
2
2
|
export declare function getAFSSystemPrompt(afs: AFS): Promise<string>;
|
|
3
3
|
export declare const AFS_EXECUTABLE_TOOLS_PROMPT_TEMPLATE = "<afs_executable_tools>\nHere are the executable tools available in the AFS you can use:\n\n{{ tools | yaml.stringify }}\n</afs_executable_tools>\n";
|
|
4
|
+
export declare const AFS_DESCRIPTION_PROMPT_TEMPLATE = "AFS (Agentic File System) provides tools to interact with a virtual file system,\nallowing you to list, search, read, and write files, or execute a useful tool from the available modules.\nYou can use these tools to manage and retrieve files as needed.\n";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AFS_EXECUTABLE_TOOLS_PROMPT_TEMPLATE = void 0;
|
|
3
|
+
exports.AFS_DESCRIPTION_PROMPT_TEMPLATE = exports.AFS_EXECUTABLE_TOOLS_PROMPT_TEMPLATE = void 0;
|
|
4
4
|
exports.getAFSSystemPrompt = getAFSSystemPrompt;
|
|
5
5
|
const yaml_1 = require("yaml");
|
|
6
6
|
const type_utils_js_1 = require("../../utils/type-utils.js");
|
|
@@ -8,9 +8,7 @@ async function getAFSSystemPrompt(afs) {
|
|
|
8
8
|
return `\
|
|
9
9
|
|
|
10
10
|
<afs_usage>
|
|
11
|
-
|
|
12
|
-
allowing you to list, search, read, and write files, or execute a useful tool from the available modules.
|
|
13
|
-
Use these tools to manage and retrieve files as needed.
|
|
11
|
+
${exports.AFS_DESCRIPTION_PROMPT_TEMPLATE}
|
|
14
12
|
|
|
15
13
|
Provided modules:
|
|
16
14
|
${(0, yaml_1.stringify)((await afs.listModules()).map((i) => (0, type_utils_js_1.pick)(i, ["name", "path", "description"])))}
|
|
@@ -31,3 +29,8 @@ Here are the executable tools available in the AFS you can use:
|
|
|
31
29
|
{{ tools | yaml.stringify }}
|
|
32
30
|
</afs_executable_tools>
|
|
33
31
|
`;
|
|
32
|
+
exports.AFS_DESCRIPTION_PROMPT_TEMPLATE = `\
|
|
33
|
+
AFS (Agentic File System) provides tools to interact with a virtual file system,
|
|
34
|
+
allowing you to list, search, read, and write files, or execute a useful tool from the available modules.
|
|
35
|
+
You can use these tools to manage and retrieve files as needed.
|
|
36
|
+
`;
|
|
@@ -118,6 +118,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
118
118
|
* agentSucceed, or agentFailed
|
|
119
119
|
*/
|
|
120
120
|
disableEvents?: boolean;
|
|
121
|
+
historyConfig?: Agent["historyConfig"];
|
|
121
122
|
/**
|
|
122
123
|
* One or more memory agents this agent can use
|
|
123
124
|
*/
|
|
@@ -346,6 +347,11 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
346
347
|
* agentSucceed, or agentFailed
|
|
347
348
|
*/
|
|
348
349
|
private disableEvents?;
|
|
350
|
+
historyConfig?: {
|
|
351
|
+
disabled?: boolean;
|
|
352
|
+
maxTokens?: number;
|
|
353
|
+
maxItems?: number;
|
|
354
|
+
};
|
|
349
355
|
private subscriptions;
|
|
350
356
|
/**
|
|
351
357
|
* Attach agent to context:
|
|
@@ -29,7 +29,7 @@ export interface LoadOptions {
|
|
|
29
29
|
}
|
|
30
30
|
export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
|
|
31
31
|
export declare function loadAgent(path: string, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
32
|
-
export declare function loadNestAgent(path: string, agent: NestAgentSchema, options?: LoadOptions, agentOptions?: AgentOptions & Record<string, unknown>): Promise<Agent>;
|
|
32
|
+
export declare function loadNestAgent(path: string, agent: NestAgentSchema, options?: LoadOptions, agentOptions?: AgentOptions<any, any> & Record<string, unknown>): Promise<Agent>;
|
|
33
33
|
export declare function parseAgent(path: string, agent: Awaited<ReturnType<typeof loadAgentFromYamlFile>>, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
34
34
|
type CliAgent = string | {
|
|
35
35
|
url?: string;
|
|
@@ -238,5 +238,6 @@ export declare function loadAIGNEFile(path: string): Promise<{
|
|
|
238
238
|
aigne: z.infer<typeof aigneFileSchema>;
|
|
239
239
|
rootDir: string;
|
|
240
240
|
}>;
|
|
241
|
+
export declare function findAIGNEFile(path: string): Promise<string>;
|
|
241
242
|
export declare function instructionsToPromptBuilder(instructions: Instructions): PromptBuilder;
|
|
242
243
|
export {};
|
|
@@ -37,6 +37,10 @@ export declare class PromptBuilder {
|
|
|
37
37
|
}>;
|
|
38
38
|
private getTemplateVariables;
|
|
39
39
|
private buildMessages;
|
|
40
|
+
getHistories(options: PromptBuildOptions): Promise<{
|
|
41
|
+
role: "user" | "agent";
|
|
42
|
+
content: unknown;
|
|
43
|
+
}[]>;
|
|
40
44
|
private refineMessages;
|
|
41
45
|
private convertMemoriesToMessages;
|
|
42
46
|
private buildResponseFormat;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { AFS } from "@aigne/afs";
|
|
2
2
|
export declare function getAFSSystemPrompt(afs: AFS): Promise<string>;
|
|
3
3
|
export declare const AFS_EXECUTABLE_TOOLS_PROMPT_TEMPLATE = "<afs_executable_tools>\nHere are the executable tools available in the AFS you can use:\n\n{{ tools | yaml.stringify }}\n</afs_executable_tools>\n";
|
|
4
|
+
export declare const AFS_DESCRIPTION_PROMPT_TEMPLATE = "AFS (Agentic File System) provides tools to interact with a virtual file system,\nallowing you to list, search, read, and write files, or execute a useful tool from the available modules.\nYou can use these tools to manage and retrieve files as needed.\n";
|
|
@@ -118,6 +118,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
118
118
|
* agentSucceed, or agentFailed
|
|
119
119
|
*/
|
|
120
120
|
disableEvents?: boolean;
|
|
121
|
+
historyConfig?: Agent["historyConfig"];
|
|
121
122
|
/**
|
|
122
123
|
* One or more memory agents this agent can use
|
|
123
124
|
*/
|
|
@@ -346,6 +347,11 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
346
347
|
* agentSucceed, or agentFailed
|
|
347
348
|
*/
|
|
348
349
|
private disableEvents?;
|
|
350
|
+
historyConfig?: {
|
|
351
|
+
disabled?: boolean;
|
|
352
|
+
maxTokens?: number;
|
|
353
|
+
maxItems?: number;
|
|
354
|
+
};
|
|
349
355
|
private subscriptions;
|
|
350
356
|
/**
|
|
351
357
|
* Attach agent to context:
|
package/lib/esm/agents/agent.js
CHANGED
|
@@ -103,6 +103,7 @@ export class Agent {
|
|
|
103
103
|
if (options.skills?.length)
|
|
104
104
|
this.skills.push(...options.skills.map(functionToAgent));
|
|
105
105
|
this.disableEvents = options.disableEvents;
|
|
106
|
+
this.historyConfig = options.historyConfig;
|
|
106
107
|
if (Array.isArray(options.memory)) {
|
|
107
108
|
this.memories.push(...options.memory);
|
|
108
109
|
}
|
|
@@ -276,6 +277,7 @@ export class Agent {
|
|
|
276
277
|
* agentSucceed, or agentFailed
|
|
277
278
|
*/
|
|
278
279
|
disableEvents;
|
|
280
|
+
historyConfig;
|
|
279
281
|
subscriptions = [];
|
|
280
282
|
/**
|
|
281
283
|
* Attach agent to context:
|
|
@@ -519,7 +521,8 @@ export class Agent {
|
|
|
519
521
|
const o = await this.callHooks(["onSuccess", "onEnd"], { input, output: finalOutput }, options);
|
|
520
522
|
if (o?.output)
|
|
521
523
|
finalOutput = o.output;
|
|
522
|
-
this.
|
|
524
|
+
if (this.historyConfig?.disabled !== true)
|
|
525
|
+
this.afs?.emit("agentSucceed", { input, output: finalOutput });
|
|
523
526
|
if (!this.disableEvents)
|
|
524
527
|
context.emit("agentSucceed", { agent: this, output: finalOutput });
|
|
525
528
|
return finalOutput;
|
|
@@ -29,7 +29,7 @@ export interface LoadOptions {
|
|
|
29
29
|
}
|
|
30
30
|
export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
|
|
31
31
|
export declare function loadAgent(path: string, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
32
|
-
export declare function loadNestAgent(path: string, agent: NestAgentSchema, options?: LoadOptions, agentOptions?: AgentOptions & Record<string, unknown>): Promise<Agent>;
|
|
32
|
+
export declare function loadNestAgent(path: string, agent: NestAgentSchema, options?: LoadOptions, agentOptions?: AgentOptions<any, any> & Record<string, unknown>): Promise<Agent>;
|
|
33
33
|
export declare function parseAgent(path: string, agent: Awaited<ReturnType<typeof loadAgentFromYamlFile>>, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
34
34
|
type CliAgent = string | {
|
|
35
35
|
url?: string;
|
|
@@ -238,5 +238,6 @@ export declare function loadAIGNEFile(path: string): Promise<{
|
|
|
238
238
|
aigne: z.infer<typeof aigneFileSchema>;
|
|
239
239
|
rootDir: string;
|
|
240
240
|
}>;
|
|
241
|
+
export declare function findAIGNEFile(path: string): Promise<string>;
|
|
241
242
|
export declare function instructionsToPromptBuilder(instructions: Instructions): PromptBuilder;
|
|
242
243
|
export {};
|
package/lib/esm/loader/index.js
CHANGED
|
@@ -269,7 +269,7 @@ export async function loadAIGNEFile(path) {
|
|
|
269
269
|
const aigne = tryOrThrow(() => aigneFileSchema.parse({ ...json, model: json.model || json.chatModel || json.chat_model }), (error) => new Error(`Failed to validate aigne.yaml from ${file}: ${error.message}`));
|
|
270
270
|
return { aigne, rootDir: nodejs.path.dirname(file) };
|
|
271
271
|
}
|
|
272
|
-
async function findAIGNEFile(path) {
|
|
272
|
+
export async function findAIGNEFile(path) {
|
|
273
273
|
const possibleFiles = AIGNE_FILE_NAME.includes(nodejs.path.basename(path))
|
|
274
274
|
? [path]
|
|
275
275
|
: AIGNE_FILE_NAME.map((name) => nodejs.path.join(path, name));
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import * as tson from "@zenoaihq/tson";
|
|
2
2
|
import { stringify } from "yaml";
|
|
3
3
|
export function setupFilters(env) {
|
|
4
|
-
env.addFilter("yaml.stringify", (obj) => {
|
|
5
|
-
|
|
6
|
-
});
|
|
7
|
-
env.addFilter("json.stringify", (obj, ...args) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
env.addFilter("yaml.stringify", async (obj, cb) => {
|
|
5
|
+
cb(null, stringify(await obj));
|
|
6
|
+
}, true);
|
|
7
|
+
env.addFilter("json.stringify", async (obj, ...args) => {
|
|
8
|
+
const jsonArgs = args.slice(0, -1);
|
|
9
|
+
const cb = args[args.length - 1];
|
|
10
|
+
cb(null, JSON.stringify(await obj, ...jsonArgs));
|
|
11
|
+
}, true);
|
|
12
|
+
env.addFilter("tson.stringify", async (obj, cb) => {
|
|
13
|
+
cb(null, tson.dumps(await obj));
|
|
14
|
+
}, true);
|
|
13
15
|
}
|
|
@@ -37,6 +37,10 @@ export declare class PromptBuilder {
|
|
|
37
37
|
}>;
|
|
38
38
|
private getTemplateVariables;
|
|
39
39
|
private buildMessages;
|
|
40
|
+
getHistories(options: PromptBuildOptions): Promise<{
|
|
41
|
+
role: "user" | "agent";
|
|
42
|
+
content: unknown;
|
|
43
|
+
}[]>;
|
|
40
44
|
private refineMessages;
|
|
41
45
|
private convertMemoriesToMessages;
|
|
42
46
|
private buildResponseFormat;
|
|
@@ -8,8 +8,8 @@ import { DEFAULT_OUTPUT_FILE_KEY, DEFAULT_OUTPUT_KEY } from "../agents/ai-agent.
|
|
|
8
8
|
import { fileUnionContentsSchema } from "../agents/model.js";
|
|
9
9
|
import { optionalize } from "../loader/schema.js";
|
|
10
10
|
import { outputSchemaToResponseFormatSchema } from "../utils/json-schema.js";
|
|
11
|
-
import { checkArguments, flat, isNonNullable, isRecord, partition, unique, } from "../utils/type-utils.js";
|
|
12
|
-
import { AFS_EXECUTABLE_TOOLS_PROMPT_TEMPLATE, getAFSSystemPrompt, } from "./prompts/afs-builtin-prompt.js";
|
|
11
|
+
import { checkArguments, flat, isNonNullable, isRecord, partition, pick, unique, } from "../utils/type-utils.js";
|
|
12
|
+
import { AFS_DESCRIPTION_PROMPT_TEMPLATE, AFS_EXECUTABLE_TOOLS_PROMPT_TEMPLATE, getAFSSystemPrompt, } from "./prompts/afs-builtin-prompt.js";
|
|
13
13
|
import { MEMORY_MESSAGE_TEMPLATE } from "./prompts/memory-message-template.js";
|
|
14
14
|
import { STRUCTURED_STREAM_INSTRUCTIONS } from "./prompts/structured-stream-instructions.js";
|
|
15
15
|
import { getAFSSkills } from "./skills/afs.js";
|
|
@@ -92,10 +92,36 @@ export class PromptBuilder {
|
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
getTemplateVariables(options) {
|
|
95
|
+
const self = this;
|
|
95
96
|
return {
|
|
96
97
|
userContext: options.context?.userContext,
|
|
97
98
|
...options.context?.userContext,
|
|
98
99
|
...options.input,
|
|
100
|
+
$afs: {
|
|
101
|
+
get enabled() {
|
|
102
|
+
return !!options.agent?.afs;
|
|
103
|
+
},
|
|
104
|
+
description: AFS_DESCRIPTION_PROMPT_TEMPLATE,
|
|
105
|
+
get modules() {
|
|
106
|
+
return options.agent?.afs
|
|
107
|
+
?.listModules()
|
|
108
|
+
.then((list) => list.map((i) => pick(i, ["name", "path", "description"])));
|
|
109
|
+
},
|
|
110
|
+
get histories() {
|
|
111
|
+
return self.getHistories(options);
|
|
112
|
+
},
|
|
113
|
+
get skills() {
|
|
114
|
+
const afs = options.agent?.afs;
|
|
115
|
+
if (!afs)
|
|
116
|
+
return [];
|
|
117
|
+
return getAFSSkills(afs).then((skills) => skills.map((s) => pick(s, ["name", "description"])));
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
$agent: {
|
|
121
|
+
get skills() {
|
|
122
|
+
return options.agent?.skills.map((s) => pick(s, ["name", "description"]));
|
|
123
|
+
},
|
|
124
|
+
},
|
|
99
125
|
};
|
|
100
126
|
}
|
|
101
127
|
async buildMessages(options) {
|
|
@@ -117,7 +143,7 @@ export class PromptBuilder {
|
|
|
117
143
|
memories.push(...options.context.memories);
|
|
118
144
|
}
|
|
119
145
|
const afs = options.agent?.afs;
|
|
120
|
-
if (afs) {
|
|
146
|
+
if (afs && options.agent?.historyConfig?.disabled !== true) {
|
|
121
147
|
const historyModule = (await afs.listModules()).find((m) => m.module instanceof AFSHistory);
|
|
122
148
|
messages.push(await SystemMessageTemplate.from(await getAFSSystemPrompt(afs)).format({}));
|
|
123
149
|
if (historyModule) {
|
|
@@ -195,6 +221,34 @@ export class PromptBuilder {
|
|
|
195
221
|
messages.push(...otherCustomMessages);
|
|
196
222
|
return this.refineMessages(options, messages);
|
|
197
223
|
}
|
|
224
|
+
async getHistories(options) {
|
|
225
|
+
const { agent } = options;
|
|
226
|
+
const afs = agent?.afs;
|
|
227
|
+
if (!afs)
|
|
228
|
+
return [];
|
|
229
|
+
const historyModule = (await afs.listModules()).find((m) => m.module instanceof AFSHistory);
|
|
230
|
+
if (!historyModule)
|
|
231
|
+
return [];
|
|
232
|
+
const { list: history } = await afs.list(historyModule.path, {
|
|
233
|
+
limit: agent.historyConfig?.maxItems || 10,
|
|
234
|
+
orderBy: [["createdAt", "desc"]],
|
|
235
|
+
});
|
|
236
|
+
return history
|
|
237
|
+
.reverse()
|
|
238
|
+
.map((i) => {
|
|
239
|
+
if (!i.content)
|
|
240
|
+
return;
|
|
241
|
+
const { input, output } = i.content;
|
|
242
|
+
if (!input || !output)
|
|
243
|
+
return;
|
|
244
|
+
return [
|
|
245
|
+
{ role: "user", content: input },
|
|
246
|
+
{ role: "agent", content: output },
|
|
247
|
+
];
|
|
248
|
+
})
|
|
249
|
+
.filter(isNonNullable)
|
|
250
|
+
.flat();
|
|
251
|
+
}
|
|
198
252
|
refineMessages(options, messages) {
|
|
199
253
|
const { autoReorderSystemMessages, autoMergeSystemMessages } = options.agent ?? {};
|
|
200
254
|
if (!autoReorderSystemMessages && !autoMergeSystemMessages)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { AFS } from "@aigne/afs";
|
|
2
2
|
export declare function getAFSSystemPrompt(afs: AFS): Promise<string>;
|
|
3
3
|
export declare const AFS_EXECUTABLE_TOOLS_PROMPT_TEMPLATE = "<afs_executable_tools>\nHere are the executable tools available in the AFS you can use:\n\n{{ tools | yaml.stringify }}\n</afs_executable_tools>\n";
|
|
4
|
+
export declare const AFS_DESCRIPTION_PROMPT_TEMPLATE = "AFS (Agentic File System) provides tools to interact with a virtual file system,\nallowing you to list, search, read, and write files, or execute a useful tool from the available modules.\nYou can use these tools to manage and retrieve files as needed.\n";
|
|
@@ -4,9 +4,7 @@ export async function getAFSSystemPrompt(afs) {
|
|
|
4
4
|
return `\
|
|
5
5
|
|
|
6
6
|
<afs_usage>
|
|
7
|
-
|
|
8
|
-
allowing you to list, search, read, and write files, or execute a useful tool from the available modules.
|
|
9
|
-
Use these tools to manage and retrieve files as needed.
|
|
7
|
+
${AFS_DESCRIPTION_PROMPT_TEMPLATE}
|
|
10
8
|
|
|
11
9
|
Provided modules:
|
|
12
10
|
${stringify((await afs.listModules()).map((i) => pick(i, ["name", "path", "description"])))}
|
|
@@ -27,3 +25,8 @@ Here are the executable tools available in the AFS you can use:
|
|
|
27
25
|
{{ tools | yaml.stringify }}
|
|
28
26
|
</afs_executable_tools>
|
|
29
27
|
`;
|
|
28
|
+
export const AFS_DESCRIPTION_PROMPT_TEMPLATE = `\
|
|
29
|
+
AFS (Agentic File System) provides tools to interact with a virtual file system,
|
|
30
|
+
allowing you to list, search, read, and write files, or execute a useful tool from the available modules.
|
|
31
|
+
You can use these tools to manage and retrieve files as needed.
|
|
32
|
+
`;
|