@aigne/core 1.63.0-beta → 1.63.0-beta.10
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 +97 -0
- package/lib/cjs/agents/agent.d.ts +8 -1
- package/lib/cjs/agents/agent.js +14 -4
- package/lib/cjs/agents/ai-agent.d.ts +18 -1
- package/lib/cjs/agents/ai-agent.js +60 -17
- package/lib/cjs/agents/chat-model.js +1 -1
- package/lib/cjs/loader/agent-yaml.d.ts +14 -1
- package/lib/cjs/loader/agent-yaml.js +24 -0
- package/lib/cjs/loader/index.d.ts +7 -0
- package/lib/cjs/loader/index.js +22 -0
- package/lib/cjs/prompt/prompt-builder.d.ts +1 -0
- package/lib/cjs/prompt/prompt-builder.js +57 -16
- package/lib/cjs/prompt/prompts/afs-builtin-prompt.d.ts +2 -0
- package/lib/cjs/prompt/prompts/afs-builtin-prompt.js +23 -0
- package/lib/cjs/prompt/skills/afs.d.ts +3 -0
- package/lib/cjs/prompt/skills/afs.js +75 -0
- package/lib/cjs/utils/type-utils.d.ts +1 -0
- package/lib/cjs/utils/type-utils.js +14 -0
- package/lib/dts/agents/agent.d.ts +8 -1
- package/lib/dts/agents/ai-agent.d.ts +18 -1
- package/lib/dts/loader/agent-yaml.d.ts +14 -1
- package/lib/dts/loader/index.d.ts +7 -0
- package/lib/dts/prompt/prompt-builder.d.ts +1 -0
- package/lib/dts/prompt/prompts/afs-builtin-prompt.d.ts +2 -0
- package/lib/dts/prompt/skills/afs.d.ts +3 -0
- package/lib/dts/utils/type-utils.d.ts +1 -0
- package/lib/esm/agents/agent.d.ts +8 -1
- package/lib/esm/agents/agent.js +14 -4
- package/lib/esm/agents/ai-agent.d.ts +18 -1
- package/lib/esm/agents/ai-agent.js +57 -17
- package/lib/esm/agents/chat-model.js +1 -1
- package/lib/esm/loader/agent-yaml.d.ts +14 -1
- package/lib/esm/loader/agent-yaml.js +24 -0
- package/lib/esm/loader/index.d.ts +7 -0
- package/lib/esm/loader/index.js +22 -0
- package/lib/esm/prompt/prompt-builder.d.ts +1 -0
- package/lib/esm/prompt/prompt-builder.js +58 -17
- package/lib/esm/prompt/prompts/afs-builtin-prompt.d.ts +2 -0
- package/lib/esm/prompt/prompts/afs-builtin-prompt.js +20 -0
- package/lib/esm/prompt/skills/afs.d.ts +3 -0
- package/lib/esm/prompt/skills/afs.js +72 -0
- package/lib/esm/utils/type-utils.d.ts +1 -0
- package/lib/esm/utils/type-utils.js +13 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,102 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.63.0-beta.10](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.9...core-v1.63.0-beta.10) (2025-10-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Dependencies
|
|
7
|
+
|
|
8
|
+
* The following workspace dependencies were updated
|
|
9
|
+
* dependencies
|
|
10
|
+
* @aigne/observability-api bumped to 0.11.2-beta.5
|
|
11
|
+
|
|
12
|
+
## [1.63.0-beta.9](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.8...core-v1.63.0-beta.9) (2025-10-16)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* allow custom user messages and prevent duplicate user content ([#632](https://github.com/AIGNE-io/aigne-framework/issues/632)) ([6c883b2](https://github.com/AIGNE-io/aigne-framework/commit/6c883b2d57a65e9b46232cece91fc6aa1de03aba))
|
|
18
|
+
* **models:** auto retry when got emtpy response from gemini ([#636](https://github.com/AIGNE-io/aigne-framework/issues/636)) ([9367cef](https://github.com/AIGNE-io/aigne-framework/commit/9367cef49ea4c0c87b8a36b454deb2efaee6886f))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Dependencies
|
|
22
|
+
|
|
23
|
+
* The following workspace dependencies were updated
|
|
24
|
+
* dependencies
|
|
25
|
+
* @aigne/observability-api bumped to 0.11.2-beta.4
|
|
26
|
+
|
|
27
|
+
## [1.63.0-beta.8](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.7...core-v1.63.0-beta.8) (2025-10-16)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Dependencies
|
|
31
|
+
|
|
32
|
+
* The following workspace dependencies were updated
|
|
33
|
+
* dependencies
|
|
34
|
+
* @aigne/observability-api bumped to 0.11.2-beta.3
|
|
35
|
+
|
|
36
|
+
## [1.63.0-beta.7](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.6...core-v1.63.0-beta.7) (2025-10-15)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Bug Fixes
|
|
40
|
+
|
|
41
|
+
* add options for system message reordering and merging ([#624](https://github.com/AIGNE-io/aigne-framework/issues/624)) ([8ca466d](https://github.com/AIGNE-io/aigne-framework/commit/8ca466d49d1e4ed08bc90922f39c0d3ed60c4fd5))
|
|
42
|
+
|
|
43
|
+
## [1.63.0-beta.6](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.5...core-v1.63.0-beta.6) (2025-10-15)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### Dependencies
|
|
47
|
+
|
|
48
|
+
* The following workspace dependencies were updated
|
|
49
|
+
* dependencies
|
|
50
|
+
* @aigne/observability-api bumped to 0.11.2-beta.2
|
|
51
|
+
|
|
52
|
+
## [1.63.0-beta.5](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.4...core-v1.63.0-beta.5) (2025-10-13)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### Bug Fixes
|
|
56
|
+
|
|
57
|
+
* **core:** auto merge multiple system messages ([#619](https://github.com/AIGNE-io/aigne-framework/issues/619)) ([e9e62c0](https://github.com/AIGNE-io/aigne-framework/commit/e9e62c03c45f5a9b75d44a07588b2b179e262aad))
|
|
58
|
+
|
|
59
|
+
## [1.63.0-beta.4](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.3...core-v1.63.0-beta.4) (2025-10-12)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### Features
|
|
63
|
+
|
|
64
|
+
* **afs:** add configurable history injection to AFS system ([#611](https://github.com/AIGNE-io/aigne-framework/issues/611)) ([689b5d7](https://github.com/AIGNE-io/aigne-framework/commit/689b5d76d8cc82f548e8be74e63f18e7a6216c31))
|
|
65
|
+
|
|
66
|
+
## [1.63.0-beta.3](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.2...core-v1.63.0-beta.3) (2025-10-11)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
### Features
|
|
70
|
+
|
|
71
|
+
* **afs:** add module system fs for afs ([#594](https://github.com/AIGNE-io/aigne-framework/issues/594)) ([83c7b65](https://github.com/AIGNE-io/aigne-framework/commit/83c7b6555d21c606a5005eb05f6686882fb8ffa3))
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
### Dependencies
|
|
75
|
+
|
|
76
|
+
* The following workspace dependencies were updated
|
|
77
|
+
* dependencies
|
|
78
|
+
* @aigne/afs bumped to 1.1.0-beta
|
|
79
|
+
* @aigne/observability-api bumped to 0.11.2-beta.1
|
|
80
|
+
|
|
81
|
+
## [1.63.0-beta.2](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.1...core-v1.63.0-beta.2) (2025-10-09)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
### Bug Fixes
|
|
85
|
+
|
|
86
|
+
* input schema of AI agent should includes input key and input file key ([#600](https://github.com/AIGNE-io/aigne-framework/issues/600)) ([b4ca076](https://github.com/AIGNE-io/aigne-framework/commit/b4ca076d6b4a1a1ecb8d4ebb008abd0d7561aadd))
|
|
87
|
+
|
|
88
|
+
## [1.63.0-beta.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta...core-v1.63.0-beta.1) (2025-10-09)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
### Features
|
|
92
|
+
|
|
93
|
+
* **core:** add `toolCallsConcurrency` support for AI agent ([#598](https://github.com/AIGNE-io/aigne-framework/issues/598)) ([84df406](https://github.com/AIGNE-io/aigne-framework/commit/84df406bfa9e3bdf159509f4b9cf2301ec80b155))
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
### Bug Fixes
|
|
97
|
+
|
|
98
|
+
* **core:** add input_file_key support for agent yaml ([#597](https://github.com/AIGNE-io/aigne-framework/issues/597)) ([63414a3](https://github.com/AIGNE-io/aigne-framework/commit/63414a3d46c74c686e7f033c224ca6175bea8c3f))
|
|
99
|
+
|
|
3
100
|
## [1.63.0-beta](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.62.0...core-v1.63.0-beta) (2025-10-07)
|
|
4
101
|
|
|
5
102
|
|
|
@@ -20,7 +20,8 @@ export declare const DEFAULT_INPUT_ACTION_GET = "$get";
|
|
|
20
20
|
*/
|
|
21
21
|
export interface Message extends Record<string, unknown> {
|
|
22
22
|
$meta?: {
|
|
23
|
-
usage
|
|
23
|
+
usage?: ContextUsage;
|
|
24
|
+
[key: string]: unknown;
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
@@ -122,6 +123,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
122
123
|
*/
|
|
123
124
|
memory?: MemoryAgent | MemoryAgent[];
|
|
124
125
|
afs?: true | AFSOptions | AFS | ((afs: AFS) => AFS);
|
|
126
|
+
afsConfig?: AFSConfig;
|
|
125
127
|
asyncMemoryRecord?: boolean;
|
|
126
128
|
/**
|
|
127
129
|
* Maximum number of memory items to retrieve
|
|
@@ -130,6 +132,10 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
130
132
|
hooks?: AgentHooks<I, O> | AgentHooks<I, O>[];
|
|
131
133
|
retryOnError?: Agent<I, O>["retryOnError"] | boolean;
|
|
132
134
|
}
|
|
135
|
+
export interface AFSConfig {
|
|
136
|
+
injectHistory?: boolean;
|
|
137
|
+
historyWindowSize?: number;
|
|
138
|
+
}
|
|
133
139
|
export declare const agentOptionsSchema: ZodObject<{
|
|
134
140
|
[key in keyof AgentOptions]: ZodType<AgentOptions[key]>;
|
|
135
141
|
}>;
|
|
@@ -212,6 +218,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
212
218
|
*/
|
|
213
219
|
readonly memories: MemoryAgent[];
|
|
214
220
|
afs?: AFS;
|
|
221
|
+
afsConfig?: AFSConfig;
|
|
215
222
|
asyncMemoryRecord?: boolean;
|
|
216
223
|
tag?: string;
|
|
217
224
|
/**
|
package/lib/cjs/agents/agent.js
CHANGED
|
@@ -161,6 +161,7 @@ class Agent {
|
|
|
161
161
|
: options.afs instanceof afs_1.AFS
|
|
162
162
|
? options.afs
|
|
163
163
|
: new afs_1.AFS(options.afs);
|
|
164
|
+
this.afsConfig = options.afsConfig;
|
|
164
165
|
this.asyncMemoryRecord = options.asyncMemoryRecord;
|
|
165
166
|
this.maxRetrieveMemoryCount = options.maxRetrieveMemoryCount;
|
|
166
167
|
this.hooks = (0, type_utils_js_1.flat)(options.hooks);
|
|
@@ -179,6 +180,7 @@ class Agent {
|
|
|
179
180
|
*/
|
|
180
181
|
memories = [];
|
|
181
182
|
afs;
|
|
183
|
+
afsConfig;
|
|
182
184
|
asyncMemoryRecord;
|
|
183
185
|
tag;
|
|
184
186
|
/**
|
|
@@ -449,7 +451,10 @@ class Agent {
|
|
|
449
451
|
(0, stream_utils_js_1.mergeAgentResponseChunk)(output, chunk);
|
|
450
452
|
yield chunk;
|
|
451
453
|
}
|
|
452
|
-
|
|
454
|
+
let result = await this.processAgentOutput(input, output, options);
|
|
455
|
+
if (attempt > 0) {
|
|
456
|
+
result = { ...result, $meta: { ...result.$meta, retries: attempt } };
|
|
457
|
+
}
|
|
453
458
|
if (result && !(0, fast_deep_equal_1.default)(result, output)) {
|
|
454
459
|
yield { delta: { json: result } };
|
|
455
460
|
}
|
|
@@ -459,7 +464,8 @@ class Agent {
|
|
|
459
464
|
catch (error) {
|
|
460
465
|
if (this.retryOnError?.retries) {
|
|
461
466
|
const { retries, minTimeout = DEFAULT_RETRY_MIN_TIMEOUT, factor = DEFAULT_RETRY_FACTOR, randomize = false, shouldRetry, } = this.retryOnError;
|
|
462
|
-
if (attempt
|
|
467
|
+
if (attempt < retries && (!shouldRetry || (await shouldRetry(error)))) {
|
|
468
|
+
attempt++;
|
|
463
469
|
const timeout = minTimeout * factor ** (attempt - 1) * (randomize ? 1 + Math.random() : 1);
|
|
464
470
|
logger_js_1.logger.warn(`Agent ${this.name} attempt ${attempt} of ${retries} failed with error: ${error}. Retrying in ${timeout}ms...`);
|
|
465
471
|
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
@@ -467,8 +473,12 @@ class Agent {
|
|
|
467
473
|
}
|
|
468
474
|
}
|
|
469
475
|
const res = await this.processAgentError(input, error, options);
|
|
470
|
-
if (!res.retry)
|
|
471
|
-
|
|
476
|
+
if (!res.retry) {
|
|
477
|
+
const e = res.error ?? error;
|
|
478
|
+
if (attempt > 0)
|
|
479
|
+
e.message += ` (after ${attempt} retries)`;
|
|
480
|
+
throw e;
|
|
481
|
+
}
|
|
472
482
|
}
|
|
473
483
|
}
|
|
474
484
|
}
|
|
@@ -3,7 +3,7 @@ import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
|
3
3
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type AgentProcessResult, type Message } from "./agent.js";
|
|
4
4
|
import type { ChatModel, ChatModelInput } from "./chat-model.js";
|
|
5
5
|
import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
|
|
6
|
-
import type
|
|
6
|
+
import { type FileType } from "./model.js";
|
|
7
7
|
export declare const DEFAULT_OUTPUT_KEY = "message";
|
|
8
8
|
export declare const DEFAULT_OUTPUT_FILE_KEY = "files";
|
|
9
9
|
/**
|
|
@@ -23,6 +23,8 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
|
|
|
23
23
|
* more complex prompt templates
|
|
24
24
|
*/
|
|
25
25
|
instructions?: string | PromptBuilder;
|
|
26
|
+
autoReorderSystemMessages?: boolean;
|
|
27
|
+
autoMergeSystemMessages?: boolean;
|
|
26
28
|
/**
|
|
27
29
|
* Pick a message from input to use as the user's message
|
|
28
30
|
*/
|
|
@@ -42,6 +44,12 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
|
|
|
42
44
|
* @default AIAgentToolChoice.auto
|
|
43
45
|
*/
|
|
44
46
|
toolChoice?: AIAgentToolChoice | Agent;
|
|
47
|
+
/**
|
|
48
|
+
* Maximum number of tool calls to execute concurrently
|
|
49
|
+
*
|
|
50
|
+
* @default 1
|
|
51
|
+
*/
|
|
52
|
+
toolCallsConcurrency?: number;
|
|
45
53
|
/**
|
|
46
54
|
* Whether to preserve text generated during tool usage in the final output
|
|
47
55
|
*/
|
|
@@ -210,6 +218,8 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
|
|
|
210
218
|
* {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-prompt-builder}
|
|
211
219
|
*/
|
|
212
220
|
instructions: PromptBuilder;
|
|
221
|
+
autoReorderSystemMessages?: boolean;
|
|
222
|
+
autoMergeSystemMessages?: boolean;
|
|
213
223
|
/**
|
|
214
224
|
* Pick a message from input to use as the user's message
|
|
215
225
|
*/
|
|
@@ -237,6 +247,12 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
|
|
|
237
247
|
* {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-router}
|
|
238
248
|
*/
|
|
239
249
|
toolChoice?: AIAgentToolChoice | Agent;
|
|
250
|
+
/**
|
|
251
|
+
* Maximum number of tool calls to execute concurrently
|
|
252
|
+
*
|
|
253
|
+
* @default 1
|
|
254
|
+
*/
|
|
255
|
+
toolCallsConcurrency?: number;
|
|
240
256
|
/**
|
|
241
257
|
* Whether to preserve text generated during tool usage in the final output
|
|
242
258
|
*/
|
|
@@ -299,6 +315,7 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
|
|
|
299
315
|
metadataEnd: string;
|
|
300
316
|
parse: (raw: string) => object;
|
|
301
317
|
};
|
|
318
|
+
get inputSchema(): ZodType<I>;
|
|
302
319
|
/**
|
|
303
320
|
* Process an input message and generate a response
|
|
304
321
|
*
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.AIAgent = exports.aiAgentOptionsSchema = exports.aiAgentToolChoiceSchema = exports.AIAgentToolChoice = exports.DEFAULT_OUTPUT_FILE_KEY = exports.DEFAULT_OUTPUT_KEY = void 0;
|
|
7
|
+
const fastq_1 = __importDefault(require("fastq"));
|
|
4
8
|
const zod_1 = require("zod");
|
|
5
9
|
const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
|
|
6
10
|
const structured_stream_instructions_js_1 = require("../prompt/prompts/structured-stream-instructions.js");
|
|
@@ -8,6 +12,7 @@ const template_js_1 = require("../prompt/template.js");
|
|
|
8
12
|
const structured_stream_extractor_js_1 = require("../utils/structured-stream-extractor.js");
|
|
9
13
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
10
14
|
const agent_js_1 = require("./agent.js");
|
|
15
|
+
const model_js_1 = require("./model.js");
|
|
11
16
|
const types_js_1 = require("./types.js");
|
|
12
17
|
exports.DEFAULT_OUTPUT_KEY = "message";
|
|
13
18
|
exports.DEFAULT_OUTPUT_FILE_KEY = "files";
|
|
@@ -58,6 +63,7 @@ exports.aiAgentOptionsSchema = agent_js_1.agentOptionsSchema.extend({
|
|
|
58
63
|
inputKey: zod_1.z.string().optional(),
|
|
59
64
|
outputKey: zod_1.z.string().optional(),
|
|
60
65
|
toolChoice: exports.aiAgentToolChoiceSchema.optional(),
|
|
66
|
+
toolCallsConcurrency: zod_1.z.number().int().min(0).optional(),
|
|
61
67
|
keepTextInToolUses: zod_1.z.boolean().optional(),
|
|
62
68
|
memoryAgentsAsTools: zod_1.z.boolean().optional(),
|
|
63
69
|
memoryPromptTemplate: zod_1.z.string().optional(),
|
|
@@ -111,12 +117,15 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
111
117
|
typeof options.instructions === "string"
|
|
112
118
|
? prompt_builder_js_1.PromptBuilder.from(options.instructions)
|
|
113
119
|
: (options.instructions ?? new prompt_builder_js_1.PromptBuilder());
|
|
120
|
+
this.autoReorderSystemMessages = options.autoReorderSystemMessages ?? false;
|
|
121
|
+
this.autoMergeSystemMessages = options.autoMergeSystemMessages ?? false;
|
|
114
122
|
this.inputKey = options.inputKey;
|
|
115
123
|
this.inputFileKey = options.inputFileKey;
|
|
116
124
|
this.outputKey = options.outputKey || exports.DEFAULT_OUTPUT_KEY;
|
|
117
125
|
this.outputFileKey = options.outputFileKey || exports.DEFAULT_OUTPUT_FILE_KEY;
|
|
118
126
|
this.outputFileType = options.outputFileType;
|
|
119
127
|
this.toolChoice = options.toolChoice;
|
|
128
|
+
this.toolCallsConcurrency = options.toolCallsConcurrency || 1;
|
|
120
129
|
this.keepTextInToolUses = options.keepTextInToolUses;
|
|
121
130
|
this.memoryAgentsAsTools = options.memoryAgentsAsTools;
|
|
122
131
|
this.memoryPromptTemplate = options.memoryPromptTemplate;
|
|
@@ -146,6 +155,8 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
146
155
|
* {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-prompt-builder}
|
|
147
156
|
*/
|
|
148
157
|
instructions;
|
|
158
|
+
autoReorderSystemMessages;
|
|
159
|
+
autoMergeSystemMessages;
|
|
149
160
|
/**
|
|
150
161
|
* Pick a message from input to use as the user's message
|
|
151
162
|
*/
|
|
@@ -173,6 +184,12 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
173
184
|
* {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-router}
|
|
174
185
|
*/
|
|
175
186
|
toolChoice;
|
|
187
|
+
/**
|
|
188
|
+
* Maximum number of tool calls to execute concurrently
|
|
189
|
+
*
|
|
190
|
+
* @default 1
|
|
191
|
+
*/
|
|
192
|
+
toolCallsConcurrency;
|
|
176
193
|
/**
|
|
177
194
|
* Whether to preserve text generated during tool usage in the final output
|
|
178
195
|
*/
|
|
@@ -230,6 +247,20 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
230
247
|
* which outputs structured data in YAML format within <metadata> tags.
|
|
231
248
|
*/
|
|
232
249
|
customStructuredStreamInstructions;
|
|
250
|
+
get inputSchema() {
|
|
251
|
+
let schema = super.inputSchema;
|
|
252
|
+
if (this.inputKey) {
|
|
253
|
+
schema = schema.extend({
|
|
254
|
+
[this.inputKey]: zod_1.z.string().nullish(),
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
if (this.inputFileKey) {
|
|
258
|
+
schema = schema.extend({
|
|
259
|
+
[this.inputFileKey]: model_js_1.fileUnionContentsSchema.nullish(),
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
return schema;
|
|
263
|
+
}
|
|
233
264
|
/**
|
|
234
265
|
* Process an input message and generate a response
|
|
235
266
|
*
|
|
@@ -287,31 +318,43 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
287
318
|
yield { delta: { text: { [outputKey]: "\n" } } };
|
|
288
319
|
}
|
|
289
320
|
const executedToolCalls = [];
|
|
321
|
+
let error;
|
|
322
|
+
const queue = fastq_1.default.promise(async ({ tool, call }) => {
|
|
323
|
+
try {
|
|
324
|
+
// NOTE: should pass both arguments (model generated) and input (user provided) to the tool
|
|
325
|
+
const output = await this.invokeSkill(tool, { ...input, ...call.function.arguments }, options).catch((error) => {
|
|
326
|
+
if (!this.catchToolsError) {
|
|
327
|
+
return Promise.reject(error);
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
isError: true,
|
|
331
|
+
error: {
|
|
332
|
+
message: error.message,
|
|
333
|
+
},
|
|
334
|
+
};
|
|
335
|
+
});
|
|
336
|
+
executedToolCalls.push({ call, output });
|
|
337
|
+
}
|
|
338
|
+
catch (e) {
|
|
339
|
+
error = e;
|
|
340
|
+
queue.killAndDrain();
|
|
341
|
+
}
|
|
342
|
+
}, this.toolCallsConcurrency || 1);
|
|
290
343
|
// Execute tools
|
|
291
344
|
for (const call of toolCalls) {
|
|
292
345
|
const tool = toolsMap.get(call.function.name);
|
|
293
346
|
if (!tool)
|
|
294
347
|
throw new Error(`Tool not found: ${call.function.name}`);
|
|
295
|
-
|
|
296
|
-
const output = await this.invokeSkill(tool, { ...input, ...call.function.arguments }, options).catch((error) => {
|
|
297
|
-
if (!this.catchToolsError) {
|
|
298
|
-
return Promise.reject(error);
|
|
299
|
-
}
|
|
300
|
-
return {
|
|
301
|
-
isError: true,
|
|
302
|
-
error: {
|
|
303
|
-
message: error.message,
|
|
304
|
-
},
|
|
305
|
-
};
|
|
306
|
-
});
|
|
307
|
-
// NOTE: Return transfer output immediately
|
|
308
|
-
if ((0, types_js_1.isTransferAgentOutput)(output)) {
|
|
309
|
-
return output;
|
|
310
|
-
}
|
|
311
|
-
executedToolCalls.push({ call, output });
|
|
348
|
+
queue.push({ tool, call });
|
|
312
349
|
}
|
|
350
|
+
await queue.drained();
|
|
351
|
+
if (error)
|
|
352
|
+
throw error;
|
|
313
353
|
// Continue LLM function calling loop if any tools were executed
|
|
314
354
|
if (executedToolCalls.length) {
|
|
355
|
+
const transferOutput = executedToolCalls.find((i) => (0, types_js_1.isTransferAgentOutput)(i.output))?.output;
|
|
356
|
+
if (transferOutput)
|
|
357
|
+
return transferOutput;
|
|
315
358
|
toolCallMessages.push(await template_js_1.AgentMessageTemplate.from(undefined, executedToolCalls.map(({ call }) => call)).format(), ...(await Promise.all(executedToolCalls.map(({ call, output }) => template_js_1.ToolMessageTemplate.from(output, call.id).format()))));
|
|
316
359
|
continue;
|
|
317
360
|
}
|
|
@@ -42,7 +42,7 @@ const type_utils_js_1 = require("../utils/type-utils.js");
|
|
|
42
42
|
const agent_js_1 = require("./agent.js");
|
|
43
43
|
const model_js_1 = require("./model.js");
|
|
44
44
|
const CHAT_MODEL_DEFAULT_RETRY_OPTIONS = {
|
|
45
|
-
retries:
|
|
45
|
+
retries: 10,
|
|
46
46
|
shouldRetry: async (error) => error instanceof StructuredOutputError || (await Promise.resolve().then(() => __importStar(require("is-network-error")))).default(error),
|
|
47
47
|
};
|
|
48
48
|
class StructuredOutputError extends Error {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { AFSOptions } from "@aigne/afs";
|
|
1
2
|
import { type ZodType, z } from "zod";
|
|
2
|
-
import type { AgentHooks, FunctionAgentFn, TaskRenderMode } from "../agents/agent.js";
|
|
3
|
+
import type { AFSConfig, AgentHooks, FunctionAgentFn, TaskRenderMode } from "../agents/agent.js";
|
|
3
4
|
import { AIAgentToolChoice } from "../agents/ai-agent.js";
|
|
4
5
|
import { type Role } from "../agents/chat-model.js";
|
|
5
6
|
import { ProcessMode, type ReflectionMode } from "../agents/team-agent.js";
|
|
@@ -19,6 +20,10 @@ export type NestAgentSchema = string | {
|
|
|
19
20
|
defaultInput?: Record<string, any>;
|
|
20
21
|
hooks?: HooksSchema | HooksSchema[];
|
|
21
22
|
} | AgentSchema;
|
|
23
|
+
export type AFSModuleSchema = string | {
|
|
24
|
+
module: string;
|
|
25
|
+
options?: Record<string, any>;
|
|
26
|
+
};
|
|
22
27
|
export interface BaseAgentSchema {
|
|
23
28
|
name?: string;
|
|
24
29
|
description?: string;
|
|
@@ -36,6 +41,10 @@ export interface BaseAgentSchema {
|
|
|
36
41
|
provider: string;
|
|
37
42
|
subscribeTopic?: string[];
|
|
38
43
|
};
|
|
44
|
+
afs?: boolean | (Omit<AFSOptions, "modules"> & {
|
|
45
|
+
modules?: AFSModuleSchema[];
|
|
46
|
+
});
|
|
47
|
+
afsConfig?: AFSConfig;
|
|
39
48
|
}
|
|
40
49
|
export type Instructions = {
|
|
41
50
|
role: Exclude<Role, "tool">;
|
|
@@ -45,9 +54,13 @@ export type Instructions = {
|
|
|
45
54
|
export interface AIAgentSchema extends BaseAgentSchema {
|
|
46
55
|
type: "ai";
|
|
47
56
|
instructions?: Instructions;
|
|
57
|
+
autoReorderSystemMessages?: boolean;
|
|
58
|
+
autoMergeSystemMessages?: boolean;
|
|
48
59
|
inputKey?: string;
|
|
60
|
+
inputFileKey?: string;
|
|
49
61
|
outputKey?: string;
|
|
50
62
|
toolChoice?: AIAgentToolChoice;
|
|
63
|
+
toolCallsConcurrency?: number;
|
|
51
64
|
keepTextInToolUses?: boolean;
|
|
52
65
|
}
|
|
53
66
|
export interface ImageAgentSchema extends BaseAgentSchema {
|
|
@@ -53,6 +53,25 @@ async function parseAgentFile(path, data) {
|
|
|
53
53
|
subscribeTopic: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.string())),
|
|
54
54
|
})),
|
|
55
55
|
])),
|
|
56
|
+
afs: (0, schema_js_1.optionalize)(zod_1.z.union([
|
|
57
|
+
zod_1.z.boolean(),
|
|
58
|
+
(0, schema_js_1.camelizeSchema)(zod_1.z.object({
|
|
59
|
+
storage: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
60
|
+
url: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
61
|
+
})),
|
|
62
|
+
modules: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.union([
|
|
63
|
+
zod_1.z.string(),
|
|
64
|
+
zod_1.z.object({
|
|
65
|
+
module: zod_1.z.string(),
|
|
66
|
+
options: (0, schema_js_1.optionalize)(zod_1.z.record(zod_1.z.any())),
|
|
67
|
+
}),
|
|
68
|
+
]))),
|
|
69
|
+
})),
|
|
70
|
+
])),
|
|
71
|
+
afsConfig: (0, schema_js_1.optionalize)((0, schema_js_1.camelizeSchema)(zod_1.z.object({
|
|
72
|
+
injectHistory: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
73
|
+
historyWindowSize: (0, schema_js_1.optionalize)(zod_1.z.number().int().min(1)),
|
|
74
|
+
}))),
|
|
56
75
|
});
|
|
57
76
|
const instructionItemSchema = zod_1.z.union([
|
|
58
77
|
zod_1.z.object({
|
|
@@ -93,9 +112,14 @@ async function parseAgentFile(path, data) {
|
|
|
93
112
|
.object({
|
|
94
113
|
type: zod_1.z.literal("ai"),
|
|
95
114
|
instructions: (0, schema_js_1.optionalize)(instructionsSchema),
|
|
115
|
+
autoReorderSystemMessages: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
116
|
+
autoMergeSystemMessages: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
96
117
|
inputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
97
118
|
outputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
119
|
+
inputFileKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
120
|
+
outputFileKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
98
121
|
toolChoice: (0, schema_js_1.optionalize)(zod_1.z.nativeEnum(ai_agent_js_1.AIAgentToolChoice)),
|
|
122
|
+
toolCallsConcurrency: (0, schema_js_1.optionalize)(zod_1.z.number().int().min(0)),
|
|
99
123
|
keepTextInToolUses: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
100
124
|
structuredStreamMode: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
101
125
|
})
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AFSModule } from "@aigne/afs";
|
|
1
2
|
import { type ZodType, z } from "zod";
|
|
2
3
|
import { Agent, type AgentOptions } from "../agents/agent.js";
|
|
3
4
|
import type { ChatModel } from "../agents/chat-model.js";
|
|
@@ -11,6 +12,12 @@ export interface LoadOptions {
|
|
|
11
12
|
}[];
|
|
12
13
|
model?: ChatModel | ((model?: z.infer<typeof aigneFileSchema>["model"]) => PromiseOrValue<ChatModel | undefined>);
|
|
13
14
|
imageModel?: ImageModel | ((model?: z.infer<typeof aigneFileSchema>["imageModel"]) => PromiseOrValue<ImageModel | undefined>);
|
|
15
|
+
afs?: {
|
|
16
|
+
availableModules?: {
|
|
17
|
+
module: string;
|
|
18
|
+
create: (options?: Record<string, any>) => PromiseOrValue<AFSModule>;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
14
21
|
}
|
|
15
22
|
export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
|
|
16
23
|
export declare function loadAgent(path: string, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
package/lib/cjs/loader/index.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.load = load;
|
|
4
4
|
exports.loadAgent = loadAgent;
|
|
5
5
|
exports.loadAIGNEFile = loadAIGNEFile;
|
|
6
|
+
const afs_1 = require("@aigne/afs");
|
|
6
7
|
const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
|
|
7
8
|
const yaml_1 = require("yaml");
|
|
8
9
|
const zod_1 = require("zod");
|
|
@@ -112,6 +113,26 @@ async function parseAgent(path, agent, options, agentOptions) {
|
|
|
112
113
|
const memory = "memory" in agent && options?.memories?.length
|
|
113
114
|
? await loadMemory(options.memories, typeof agent.memory === "object" ? agent.memory.provider : undefined, typeof agent.memory === "object" ? agent.memory : {})
|
|
114
115
|
: undefined;
|
|
116
|
+
let afs;
|
|
117
|
+
if (typeof agent.afs === "boolean") {
|
|
118
|
+
if (agent.afs) {
|
|
119
|
+
afs = new afs_1.AFS();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else if (agent.afs) {
|
|
123
|
+
afs = new afs_1.AFS({
|
|
124
|
+
...agent.afs,
|
|
125
|
+
modules: agent.afs.modules &&
|
|
126
|
+
(await Promise.all(agent.afs.modules.map((m) => {
|
|
127
|
+
const mod = typeof m === "string"
|
|
128
|
+
? options?.afs?.availableModules?.find((mod) => mod.module === m)
|
|
129
|
+
: options?.afs?.availableModules?.find((mod) => mod.module === m.module);
|
|
130
|
+
if (!mod)
|
|
131
|
+
throw new Error(`AFS module not found: ${typeof m === "string" ? m : m.module}`);
|
|
132
|
+
return mod.create(typeof m === "string" ? {} : m.options);
|
|
133
|
+
}))),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
115
136
|
const model = agent.model && typeof options?.model === "function"
|
|
116
137
|
? await options.model(agent.model)
|
|
117
138
|
: undefined;
|
|
@@ -129,6 +150,7 @@ async function parseAgent(path, agent, options, agentOptions) {
|
|
|
129
150
|
...((await parseHooks(path, agent.hooks, options)) ?? []),
|
|
130
151
|
...[agentOptions?.hooks].flat().filter(type_utils_js_1.isNonNullable),
|
|
131
152
|
],
|
|
153
|
+
afs,
|
|
132
154
|
};
|
|
133
155
|
let instructions;
|
|
134
156
|
if ("instructions" in agent && agent.instructions) {
|