@aigne/core 1.58.3 → 1.60.0
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 +21 -0
- package/lib/cjs/agents/agent.d.ts +9 -0
- package/lib/cjs/agents/agent.js +13 -3
- package/lib/cjs/agents/ai-agent.d.ts +0 -12
- package/lib/cjs/agents/ai-agent.js +4 -11
- package/lib/cjs/agents/chat-model.d.ts +9 -3
- package/lib/cjs/agents/chat-model.js +22 -3
- package/lib/cjs/agents/image-agent.d.ts +1 -3
- package/lib/cjs/agents/image-agent.js +3 -6
- package/lib/cjs/agents/image-model.d.ts +3 -3
- package/lib/cjs/agents/team-agent.js +6 -3
- package/lib/cjs/agents/user-agent.js +2 -1
- package/lib/cjs/aigne/context.js +2 -0
- package/lib/cjs/loader/agent-yaml.d.ts +5 -2
- package/lib/cjs/loader/agent-yaml.js +6 -1
- package/lib/cjs/loader/index.d.ts +23 -33
- package/lib/cjs/loader/index.js +12 -24
- package/lib/cjs/loader/schema.d.ts +29 -0
- package/lib/cjs/loader/schema.js +21 -1
- package/lib/dts/agents/agent.d.ts +9 -0
- package/lib/dts/agents/ai-agent.d.ts +0 -12
- package/lib/dts/agents/chat-model.d.ts +9 -3
- package/lib/dts/agents/image-agent.d.ts +1 -3
- package/lib/dts/agents/image-model.d.ts +3 -3
- package/lib/dts/loader/agent-yaml.d.ts +5 -2
- package/lib/dts/loader/index.d.ts +23 -33
- package/lib/dts/loader/schema.d.ts +29 -0
- package/lib/esm/agents/agent.d.ts +9 -0
- package/lib/esm/agents/agent.js +13 -3
- package/lib/esm/agents/ai-agent.d.ts +0 -12
- package/lib/esm/agents/ai-agent.js +4 -11
- package/lib/esm/agents/chat-model.d.ts +9 -3
- package/lib/esm/agents/chat-model.js +22 -3
- package/lib/esm/agents/image-agent.d.ts +1 -3
- package/lib/esm/agents/image-agent.js +3 -6
- package/lib/esm/agents/image-model.d.ts +3 -3
- package/lib/esm/agents/team-agent.js +6 -3
- package/lib/esm/agents/user-agent.js +2 -1
- package/lib/esm/aigne/context.js +2 -0
- package/lib/esm/loader/agent-yaml.d.ts +5 -2
- package/lib/esm/loader/agent-yaml.js +7 -2
- package/lib/esm/loader/index.d.ts +23 -33
- package/lib/esm/loader/index.js +14 -26
- package/lib/esm/loader/schema.d.ts +29 -0
- package/lib/esm/loader/schema.js +20 -0
- package/package.json +3 -3
package/lib/cjs/loader/index.js
CHANGED
|
@@ -27,7 +27,7 @@ async function load(path, options = {}) {
|
|
|
27
27
|
return {
|
|
28
28
|
...aigne,
|
|
29
29
|
rootDir,
|
|
30
|
-
model: typeof options.model === "function" ? await options.model(aigne.
|
|
30
|
+
model: typeof options.model === "function" ? await options.model(aigne.model) : options.model,
|
|
31
31
|
imageModel: typeof options.imageModel === "function"
|
|
32
32
|
? await options.imageModel(aigne.imageModel)
|
|
33
33
|
: options.imageModel,
|
|
@@ -92,9 +92,17 @@ async function parseAgent(path, agent, options, agentOptions) {
|
|
|
92
92
|
const memory = "memory" in agent && options?.memories?.length
|
|
93
93
|
? await loadMemory(options.memories, typeof agent.memory === "object" ? agent.memory.provider : undefined, typeof agent.memory === "object" ? agent.memory : {})
|
|
94
94
|
: undefined;
|
|
95
|
+
const model = agent.model && typeof options?.model === "function"
|
|
96
|
+
? await options.model(agent.model)
|
|
97
|
+
: undefined;
|
|
98
|
+
const imageModel = agent.imageModel && typeof options?.imageModel === "function"
|
|
99
|
+
? await options.imageModel(agent.imageModel)
|
|
100
|
+
: undefined;
|
|
95
101
|
const baseOptions = {
|
|
96
102
|
...agentOptions,
|
|
97
103
|
...agent,
|
|
104
|
+
model,
|
|
105
|
+
imageModel,
|
|
98
106
|
skills,
|
|
99
107
|
memory,
|
|
100
108
|
hooks: [
|
|
@@ -175,28 +183,8 @@ async function loadMemory(memories, provider, options) {
|
|
|
175
183
|
const aigneFileSchema = (0, schema_js_1.camelizeSchema)(zod_1.z.object({
|
|
176
184
|
name: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
177
185
|
description: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (!(0, type_utils_js_1.isRecord)(v))
|
|
181
|
-
return v;
|
|
182
|
-
return { ...v, model: v.model || `${v.provider || ""}:${v.name || ""}` };
|
|
183
|
-
}, (0, schema_js_1.optionalize)(zod_1.z.union([
|
|
184
|
-
zod_1.z.string(),
|
|
185
|
-
(0, schema_js_1.camelizeSchema)(zod_1.z.object({
|
|
186
|
-
model: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
187
|
-
temperature: (0, schema_js_1.optionalize)(zod_1.z.number().min(0).max(2)),
|
|
188
|
-
topP: (0, schema_js_1.optionalize)(zod_1.z.number().min(0)),
|
|
189
|
-
frequencyPenalty: (0, schema_js_1.optionalize)(zod_1.z.number().min(-2).max(2)),
|
|
190
|
-
presencePenalty: (0, schema_js_1.optionalize)(zod_1.z.number().min(-2).max(2)),
|
|
191
|
-
})),
|
|
192
|
-
])))
|
|
193
|
-
.transform((v) => (typeof v === "string" ? { model: v } : v)),
|
|
194
|
-
imageModel: (0, schema_js_1.optionalize)(zod_1.z.union([
|
|
195
|
-
zod_1.z.string(),
|
|
196
|
-
(0, schema_js_1.camelizeSchema)(zod_1.z.object({
|
|
197
|
-
model: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
198
|
-
})),
|
|
199
|
-
])).transform((v) => (typeof v === "string" ? { model: v } : v)),
|
|
186
|
+
model: (0, schema_js_1.optionalize)(schema_js_1.chatModelSchema),
|
|
187
|
+
imageModel: (0, schema_js_1.optionalize)(schema_js_1.imageModelSchema),
|
|
200
188
|
agents: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.string())),
|
|
201
189
|
skills: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.string())),
|
|
202
190
|
mcpServer: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
@@ -211,7 +199,7 @@ async function loadAIGNEFile(path) {
|
|
|
211
199
|
const file = await findAIGNEFile(path);
|
|
212
200
|
const raw = await (0, type_utils_js_1.tryOrThrow)(() => index_js_1.nodejs.fs.readFile(file, "utf8"), (error) => new Error(`Failed to load aigne.yaml from ${file}: ${error.message}`));
|
|
213
201
|
const json = (0, type_utils_js_1.tryOrThrow)(() => (0, yaml_1.parse)(raw), (error) => new Error(`Failed to parse aigne.yaml from ${file}: ${error.message}`));
|
|
214
|
-
const aigne = (0, type_utils_js_1.tryOrThrow)(() => aigneFileSchema.parse(json), (error) => new Error(`Failed to validate aigne.yaml from ${file}: ${error.message}`));
|
|
202
|
+
const aigne = (0, type_utils_js_1.tryOrThrow)(() => aigneFileSchema.parse({ ...json, model: json.model || json.chatModel || json.chat_model }), (error) => new Error(`Failed to validate aigne.yaml from ${file}: ${error.message}`));
|
|
215
203
|
return { aigne, rootDir: index_js_1.nodejs.path.dirname(file) };
|
|
216
204
|
}
|
|
217
205
|
async function findAIGNEFile(path) {
|
|
@@ -29,7 +29,36 @@ export declare const defaultInputSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.
|
|
|
29
29
|
}, {
|
|
30
30
|
$get: string;
|
|
31
31
|
}>, z.ZodUnknown]>>;
|
|
32
|
+
declare const chatModelObjectSchema: z.ZodObject<{
|
|
33
|
+
model: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
34
|
+
temperature: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
35
|
+
topP: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
36
|
+
frequencyPenalty: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
37
|
+
presencePenalty: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
39
|
+
model?: string | undefined;
|
|
40
|
+
temperature?: number | undefined;
|
|
41
|
+
topP?: number | undefined;
|
|
42
|
+
frequencyPenalty?: number | undefined;
|
|
43
|
+
presencePenalty?: number | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
model?: string | undefined;
|
|
46
|
+
temperature?: number | undefined;
|
|
47
|
+
topP?: number | undefined;
|
|
48
|
+
frequencyPenalty?: number | undefined;
|
|
49
|
+
presencePenalty?: number | undefined;
|
|
50
|
+
}>;
|
|
51
|
+
export declare const chatModelSchema: typeof chatModelObjectSchema;
|
|
52
|
+
declare const imageModelObjectSchema: z.ZodObject<{
|
|
53
|
+
model: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
54
|
+
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
model?: string | undefined;
|
|
56
|
+
}, {
|
|
57
|
+
model?: string | undefined;
|
|
58
|
+
}>;
|
|
59
|
+
export declare const imageModelSchema: typeof imageModelObjectSchema;
|
|
32
60
|
export declare function optionalize<T>(schema: ZodType<T>): ZodType<T | undefined>;
|
|
33
61
|
export declare function camelizeSchema<T extends ZodType>(schema: T, { shallow }?: {
|
|
34
62
|
shallow?: boolean;
|
|
35
63
|
}): T;
|
|
64
|
+
export {};
|
package/lib/cjs/loader/schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultInputSchema = exports.inputOutputSchema = void 0;
|
|
3
|
+
exports.imageModelSchema = exports.chatModelSchema = exports.defaultInputSchema = exports.inputOutputSchema = void 0;
|
|
4
4
|
exports.optionalize = optionalize;
|
|
5
5
|
exports.camelizeSchema = camelizeSchema;
|
|
6
6
|
const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
|
|
@@ -60,6 +60,26 @@ exports.defaultInputSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.union([
|
|
|
60
60
|
}),
|
|
61
61
|
zod_1.z.unknown(),
|
|
62
62
|
]));
|
|
63
|
+
const chatModelObjectSchema = camelizeSchema(zod_1.z.object({
|
|
64
|
+
model: optionalize(zod_1.z.string()),
|
|
65
|
+
temperature: optionalize(zod_1.z.number().min(0).max(2)),
|
|
66
|
+
topP: optionalize(zod_1.z.number().min(0)),
|
|
67
|
+
frequencyPenalty: optionalize(zod_1.z.number().min(-2).max(2)),
|
|
68
|
+
presencePenalty: optionalize(zod_1.z.number().min(-2).max(2)),
|
|
69
|
+
}));
|
|
70
|
+
exports.chatModelSchema = zod_1.z
|
|
71
|
+
.preprocess((v) => {
|
|
72
|
+
if (!(0, type_utils_js_1.isRecord)(v))
|
|
73
|
+
return v;
|
|
74
|
+
return { ...v, model: v.model || `${v.provider || ""}:${v.name || ""}` };
|
|
75
|
+
}, zod_1.z.union([zod_1.z.string(), chatModelObjectSchema]))
|
|
76
|
+
.transform((v) => typeof v === "string" ? { model: v } : v);
|
|
77
|
+
const imageModelObjectSchema = camelizeSchema(zod_1.z.object({
|
|
78
|
+
model: optionalize(zod_1.z.string()),
|
|
79
|
+
}));
|
|
80
|
+
exports.imageModelSchema = zod_1.z
|
|
81
|
+
.union([zod_1.z.string(), imageModelObjectSchema])
|
|
82
|
+
.transform((v) => typeof v === "string" ? { model: v } : v);
|
|
63
83
|
function optionalize(schema) {
|
|
64
84
|
return schema.nullish().transform((v) => v ?? undefined);
|
|
65
85
|
}
|
|
@@ -8,7 +8,9 @@ import type { Memory, MemoryAgent } from "../memory/memory.js";
|
|
|
8
8
|
import type { MemoryRecorderInput } from "../memory/recorder.js";
|
|
9
9
|
import type { MemoryRetrieverInput } from "../memory/retriever.js";
|
|
10
10
|
import { type Nullish, type PromiseOrValue, type XOr } from "../utils/type-utils.js";
|
|
11
|
+
import type { ChatModel } from "./chat-model.js";
|
|
11
12
|
import type { GuideRailAgent, GuideRailAgentOutput } from "./guide-rail-agent.js";
|
|
13
|
+
import type { ImageModel } from "./image-model.js";
|
|
12
14
|
import { type TransferAgentOutput } from "./types.js";
|
|
13
15
|
export * from "./types.js";
|
|
14
16
|
export declare const DEFAULT_INPUT_ACTION_GET = "$get";
|
|
@@ -73,6 +75,8 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
73
75
|
* for documentation and debugging
|
|
74
76
|
*/
|
|
75
77
|
description?: string;
|
|
78
|
+
model?: ChatModel;
|
|
79
|
+
imageModel?: ImageModel;
|
|
76
80
|
taskTitle?: string | ((input: I) => PromiseOrValue<string | undefined>);
|
|
77
81
|
taskRenderMode?: TaskRenderMode;
|
|
78
82
|
/**
|
|
@@ -142,6 +146,8 @@ export interface AgentInvokeOptions<U extends UserContext = UserContext> {
|
|
|
142
146
|
* agent system and maintain proper isolation and resource control.
|
|
143
147
|
*/
|
|
144
148
|
context: Context<U>;
|
|
149
|
+
model?: ChatModel;
|
|
150
|
+
imageModel?: ImageModel;
|
|
145
151
|
/**
|
|
146
152
|
* Whether to enable streaming response
|
|
147
153
|
*
|
|
@@ -269,6 +275,8 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
269
275
|
* each other's roles in a multi-agent system
|
|
270
276
|
*/
|
|
271
277
|
readonly description?: string;
|
|
278
|
+
model?: ChatModel;
|
|
279
|
+
imageModel?: ImageModel;
|
|
272
280
|
taskTitle?: string | ((input: Message) => PromiseOrValue<string | undefined>);
|
|
273
281
|
renderTaskTitle(input: I): Promise<string | undefined>;
|
|
274
282
|
taskRenderMode?: TaskRenderMode;
|
|
@@ -422,6 +430,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
422
430
|
private callHooks;
|
|
423
431
|
private mergeDefaultInput;
|
|
424
432
|
protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I & Message, options: AgentInvokeOptions): Promise<O>;
|
|
433
|
+
protected invokeChildAgent: Context["invoke"];
|
|
425
434
|
/**
|
|
426
435
|
* Process agent output
|
|
427
436
|
*
|
|
@@ -15,12 +15,6 @@ export declare const DEFAULT_FILE_OUTPUT_KEY = "files";
|
|
|
15
15
|
* @template O The output message type the agent returns
|
|
16
16
|
*/
|
|
17
17
|
export interface AIAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
18
|
-
/**
|
|
19
|
-
* The language model to use for this agent
|
|
20
|
-
*
|
|
21
|
-
* If not provided, the agent will use the model from the context
|
|
22
|
-
*/
|
|
23
|
-
model?: ChatModel;
|
|
24
18
|
/**
|
|
25
19
|
* Instructions to guide the AI model's behavior
|
|
26
20
|
*
|
|
@@ -200,12 +194,6 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
|
|
|
200
194
|
* @param options Configuration options for the AI agent
|
|
201
195
|
*/
|
|
202
196
|
constructor(options: AIAgentOptions<I, O>);
|
|
203
|
-
/**
|
|
204
|
-
* The language model used by this agent
|
|
205
|
-
*
|
|
206
|
-
* If not set on the agent, the model from the context will be used
|
|
207
|
-
*/
|
|
208
|
-
model?: ChatModel;
|
|
209
197
|
/**
|
|
210
198
|
* Instructions for the language model
|
|
211
199
|
*
|
|
@@ -3,6 +3,10 @@ import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
|
3
3
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type AgentResponse, type AgentResponseStream, type Message } from "./agent.js";
|
|
4
4
|
export declare class StructuredOutputError extends Error {
|
|
5
5
|
}
|
|
6
|
+
export interface ChatModelOptions extends Omit<AgentOptions<ChatModelInput, ChatModelOutput>, "model" | "inputSchema" | "outputSchema"> {
|
|
7
|
+
model?: string;
|
|
8
|
+
modelOptions?: Omit<ModelOptions, "model">;
|
|
9
|
+
}
|
|
6
10
|
/**
|
|
7
11
|
* ChatModel is an abstract base class for interacting with Large Language Models (LLMs).
|
|
8
12
|
*
|
|
@@ -27,8 +31,9 @@ export declare class StructuredOutputError extends Error {
|
|
|
27
31
|
* {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
|
|
28
32
|
*/
|
|
29
33
|
export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelOutput> {
|
|
34
|
+
options?: ChatModelOptions | undefined;
|
|
30
35
|
tag: string;
|
|
31
|
-
constructor(options?:
|
|
36
|
+
constructor(options?: ChatModelOptions | undefined);
|
|
32
37
|
get credential(): PromiseOrValue<{
|
|
33
38
|
url?: string;
|
|
34
39
|
apiKey?: string;
|
|
@@ -145,7 +150,7 @@ export interface ChatModelInput extends Message {
|
|
|
145
150
|
/**
|
|
146
151
|
* Model-specific configuration options
|
|
147
152
|
*/
|
|
148
|
-
modelOptions?:
|
|
153
|
+
modelOptions?: ModelOptions;
|
|
149
154
|
}
|
|
150
155
|
/**
|
|
151
156
|
* Message role types
|
|
@@ -578,7 +583,7 @@ export type Modality = "text" | "image" | "audio";
|
|
|
578
583
|
*
|
|
579
584
|
* Contains various parameters for controlling model behavior, such as model name, temperature, etc.
|
|
580
585
|
*/
|
|
581
|
-
export interface
|
|
586
|
+
export interface ModelOptions {
|
|
582
587
|
/**
|
|
583
588
|
* Model name or version
|
|
584
589
|
*/
|
|
@@ -604,6 +609,7 @@ export interface ChatModelOptions {
|
|
|
604
609
|
*/
|
|
605
610
|
parallelToolCalls?: boolean;
|
|
606
611
|
modalities?: Modality[];
|
|
612
|
+
preferFileInputType?: "file" | "url";
|
|
607
613
|
}
|
|
608
614
|
/**
|
|
609
615
|
* Output message format for ChatModel
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { type ZodObject, type ZodType } from "zod";
|
|
2
2
|
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
3
3
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "./agent.js";
|
|
4
|
-
import { type
|
|
4
|
+
import { type ImageModelOutput } from "./image-model.js";
|
|
5
5
|
export interface ImageAgentOptions<I extends Message = any, O extends ImageModelOutput = any> extends Omit<AgentOptions<I, O>, "outputSchema"> {
|
|
6
|
-
model?: ImageModel;
|
|
7
6
|
instructions: string | PromptBuilder;
|
|
8
7
|
modelOptions?: Record<string, any>;
|
|
9
8
|
}
|
|
@@ -14,7 +13,6 @@ export declare class ImageAgent<I extends Message = any, O extends ImageModelOut
|
|
|
14
13
|
tag: string;
|
|
15
14
|
static from<I extends Message = any, O extends ImageModelOutput = any>(options: ImageAgentOptions<I, O>): ImageAgent<I, O>;
|
|
16
15
|
constructor(options: ImageAgentOptions<I, O>);
|
|
17
|
-
model?: ImageModel;
|
|
18
16
|
instructions: PromptBuilder;
|
|
19
17
|
modelOptions?: Record<string, any>;
|
|
20
18
|
process(input: I, options: AgentInvokeOptions): Promise<O>;
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import type { PromiseOrValue } from "../utils/type-utils.js";
|
|
3
3
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type Message } from "./agent.js";
|
|
4
4
|
import { type ChatModelOutputUsage } from "./chat-model.js";
|
|
5
|
-
export interface ImageModelOptions<I extends ImageModelInput = ImageModelInput, O extends ImageModelOutput = ImageModelOutput> extends AgentOptions<I, O> {
|
|
5
|
+
export interface ImageModelOptions<I extends ImageModelInput = ImageModelInput, O extends ImageModelOutput = ImageModelOutput> extends Omit<AgentOptions<I, O>, "model"> {
|
|
6
6
|
}
|
|
7
7
|
export declare abstract class ImageModel<I extends ImageModelInput = ImageModelInput, O extends ImageModelOutput = ImageModelOutput> extends Agent<I, O> {
|
|
8
8
|
tag: string;
|
|
@@ -32,14 +32,14 @@ export declare const imageModelInputSchema: z.ZodObject<{
|
|
|
32
32
|
}, "strip", z.ZodTypeAny, {
|
|
33
33
|
prompt: string;
|
|
34
34
|
model?: string | undefined;
|
|
35
|
-
responseFormat?: "base64" | "url" | undefined;
|
|
36
35
|
image?: string | string[] | undefined;
|
|
36
|
+
responseFormat?: "base64" | "url" | undefined;
|
|
37
37
|
n?: number | undefined;
|
|
38
38
|
}, {
|
|
39
39
|
prompt: string;
|
|
40
40
|
model?: string | undefined;
|
|
41
|
-
responseFormat?: "base64" | "url" | undefined;
|
|
42
41
|
image?: string | string[] | undefined;
|
|
42
|
+
responseFormat?: "base64" | "url" | undefined;
|
|
43
43
|
n?: number | undefined;
|
|
44
44
|
}>;
|
|
45
45
|
export interface ImageModelOutput extends Message {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { type ZodType } from "zod";
|
|
1
|
+
import { type ZodType, z } from "zod";
|
|
2
2
|
import type { AgentHooks, FunctionAgentFn, TaskRenderMode } from "../agents/agent.js";
|
|
3
3
|
import { AIAgentToolChoice } from "../agents/ai-agent.js";
|
|
4
4
|
import { ProcessMode, type ReflectionMode } from "../agents/team-agent.js";
|
|
5
|
+
import { chatModelSchema, imageModelSchema } from "./schema.js";
|
|
5
6
|
export interface HooksSchema {
|
|
6
7
|
priority?: AgentHooks["priority"];
|
|
7
8
|
onStart?: NestAgentSchema;
|
|
@@ -20,6 +21,8 @@ export type NestAgentSchema = string | {
|
|
|
20
21
|
export interface BaseAgentSchema {
|
|
21
22
|
name?: string;
|
|
22
23
|
description?: string;
|
|
24
|
+
model?: z.infer<typeof chatModelSchema>;
|
|
25
|
+
imageModel?: z.infer<typeof imageModelSchema>;
|
|
23
26
|
taskTitle?: string;
|
|
24
27
|
taskRenderMode?: TaskRenderMode;
|
|
25
28
|
inputSchema?: ZodType<Record<string, any>>;
|
|
@@ -74,5 +77,5 @@ export interface FunctionAgentSchema extends BaseAgentSchema {
|
|
|
74
77
|
process: FunctionAgentFn;
|
|
75
78
|
}
|
|
76
79
|
export type AgentSchema = AIAgentSchema | ImageAgentSchema | MCPAgentSchema | TeamAgentSchema | TransformAgentSchema | FunctionAgentSchema;
|
|
77
|
-
export declare function parseAgentFile(path: string, data:
|
|
80
|
+
export declare function parseAgentFile(path: string, data: any): Promise<AgentSchema>;
|
|
78
81
|
export declare function loadAgentFromYamlFile(path: string): Promise<AgentSchema>;
|
|
@@ -9,7 +9,7 @@ export interface LoadOptions {
|
|
|
9
9
|
memories?: {
|
|
10
10
|
new (parameters?: MemoryAgentOptions): MemoryAgent;
|
|
11
11
|
}[];
|
|
12
|
-
model?: ChatModel | ((model?: z.infer<typeof aigneFileSchema>["
|
|
12
|
+
model?: ChatModel | ((model?: z.infer<typeof aigneFileSchema>["model"]) => PromiseOrValue<ChatModel | undefined>);
|
|
13
13
|
imageModel?: ImageModel | ((model?: z.infer<typeof aigneFileSchema>["imageModel"]) => PromiseOrValue<ImageModel | undefined>);
|
|
14
14
|
key?: string | number;
|
|
15
15
|
}
|
|
@@ -18,38 +18,22 @@ export declare function loadAgent(path: string, options?: LoadOptions, agentOpti
|
|
|
18
18
|
declare const aigneFileSchema: z.ZodObject<{
|
|
19
19
|
name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
20
20
|
description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
21
|
-
|
|
21
|
+
model: z.ZodType<{
|
|
22
22
|
model?: string | undefined;
|
|
23
23
|
temperature?: number | undefined;
|
|
24
24
|
topP?: number | undefined;
|
|
25
25
|
frequencyPenalty?: number | undefined;
|
|
26
26
|
presencePenalty?: number | undefined;
|
|
27
|
-
} | undefined, z.ZodTypeDef,
|
|
28
|
-
model?: string | undefined;
|
|
29
|
-
temperature?: number | undefined;
|
|
30
|
-
topP?: number | undefined;
|
|
31
|
-
frequencyPenalty?: number | undefined;
|
|
32
|
-
presencePenalty?: number | undefined;
|
|
33
|
-
} | undefined>, string | {
|
|
34
|
-
model?: string | undefined;
|
|
35
|
-
temperature?: number | undefined;
|
|
36
|
-
topP?: number | undefined;
|
|
37
|
-
frequencyPenalty?: number | undefined;
|
|
38
|
-
presencePenalty?: number | undefined;
|
|
39
|
-
} | undefined, unknown>, {
|
|
27
|
+
} | undefined, z.ZodTypeDef, {
|
|
40
28
|
model?: string | undefined;
|
|
41
29
|
temperature?: number | undefined;
|
|
42
30
|
topP?: number | undefined;
|
|
43
31
|
frequencyPenalty?: number | undefined;
|
|
44
32
|
presencePenalty?: number | undefined;
|
|
45
|
-
} | undefined
|
|
46
|
-
imageModel: z.
|
|
47
|
-
model?: string | undefined;
|
|
48
|
-
} | undefined, z.ZodTypeDef, string | {
|
|
49
|
-
model?: string | undefined;
|
|
50
|
-
} | undefined>, {
|
|
33
|
+
} | undefined>;
|
|
34
|
+
imageModel: z.ZodType<{
|
|
51
35
|
model?: string | undefined;
|
|
52
|
-
} | undefined,
|
|
36
|
+
} | undefined, z.ZodTypeDef, {
|
|
53
37
|
model?: string | undefined;
|
|
54
38
|
} | undefined>;
|
|
55
39
|
agents: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
@@ -67,20 +51,20 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
67
51
|
chat?: string | undefined;
|
|
68
52
|
} | undefined>;
|
|
69
53
|
}, "strip", z.ZodTypeAny, {
|
|
70
|
-
|
|
71
|
-
description?: string | undefined;
|
|
72
|
-
skills?: string[] | undefined;
|
|
73
|
-
imageModel?: {
|
|
74
|
-
model?: string | undefined;
|
|
75
|
-
} | undefined;
|
|
76
|
-
agents?: string[] | undefined;
|
|
77
|
-
chatModel?: {
|
|
54
|
+
model?: {
|
|
78
55
|
model?: string | undefined;
|
|
79
56
|
temperature?: number | undefined;
|
|
80
57
|
topP?: number | undefined;
|
|
81
58
|
frequencyPenalty?: number | undefined;
|
|
82
59
|
presencePenalty?: number | undefined;
|
|
83
60
|
} | undefined;
|
|
61
|
+
name?: string | undefined;
|
|
62
|
+
description?: string | undefined;
|
|
63
|
+
imageModel?: {
|
|
64
|
+
model?: string | undefined;
|
|
65
|
+
} | undefined;
|
|
66
|
+
skills?: string[] | undefined;
|
|
67
|
+
agents?: string[] | undefined;
|
|
84
68
|
mcpServer?: {
|
|
85
69
|
agents?: string[] | undefined;
|
|
86
70
|
} | undefined;
|
|
@@ -89,14 +73,20 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
89
73
|
chat?: string | undefined;
|
|
90
74
|
} | undefined;
|
|
91
75
|
}, {
|
|
76
|
+
model?: {
|
|
77
|
+
model?: string | undefined;
|
|
78
|
+
temperature?: number | undefined;
|
|
79
|
+
topP?: number | undefined;
|
|
80
|
+
frequencyPenalty?: number | undefined;
|
|
81
|
+
presencePenalty?: number | undefined;
|
|
82
|
+
} | undefined;
|
|
92
83
|
name?: string | undefined;
|
|
93
84
|
description?: string | undefined;
|
|
94
|
-
|
|
95
|
-
imageModel?: string | {
|
|
85
|
+
imageModel?: {
|
|
96
86
|
model?: string | undefined;
|
|
97
87
|
} | undefined;
|
|
88
|
+
skills?: string[] | undefined;
|
|
98
89
|
agents?: string[] | undefined;
|
|
99
|
-
chatModel?: unknown;
|
|
100
90
|
mcpServer?: {
|
|
101
91
|
agents?: string[] | undefined;
|
|
102
92
|
} | undefined;
|
|
@@ -29,7 +29,36 @@ export declare const defaultInputSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.
|
|
|
29
29
|
}, {
|
|
30
30
|
$get: string;
|
|
31
31
|
}>, z.ZodUnknown]>>;
|
|
32
|
+
declare const chatModelObjectSchema: z.ZodObject<{
|
|
33
|
+
model: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
34
|
+
temperature: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
35
|
+
topP: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
36
|
+
frequencyPenalty: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
37
|
+
presencePenalty: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
39
|
+
model?: string | undefined;
|
|
40
|
+
temperature?: number | undefined;
|
|
41
|
+
topP?: number | undefined;
|
|
42
|
+
frequencyPenalty?: number | undefined;
|
|
43
|
+
presencePenalty?: number | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
model?: string | undefined;
|
|
46
|
+
temperature?: number | undefined;
|
|
47
|
+
topP?: number | undefined;
|
|
48
|
+
frequencyPenalty?: number | undefined;
|
|
49
|
+
presencePenalty?: number | undefined;
|
|
50
|
+
}>;
|
|
51
|
+
export declare const chatModelSchema: typeof chatModelObjectSchema;
|
|
52
|
+
declare const imageModelObjectSchema: z.ZodObject<{
|
|
53
|
+
model: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
54
|
+
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
model?: string | undefined;
|
|
56
|
+
}, {
|
|
57
|
+
model?: string | undefined;
|
|
58
|
+
}>;
|
|
59
|
+
export declare const imageModelSchema: typeof imageModelObjectSchema;
|
|
32
60
|
export declare function optionalize<T>(schema: ZodType<T>): ZodType<T | undefined>;
|
|
33
61
|
export declare function camelizeSchema<T extends ZodType>(schema: T, { shallow }?: {
|
|
34
62
|
shallow?: boolean;
|
|
35
63
|
}): T;
|
|
64
|
+
export {};
|
|
@@ -8,7 +8,9 @@ import type { Memory, MemoryAgent } from "../memory/memory.js";
|
|
|
8
8
|
import type { MemoryRecorderInput } from "../memory/recorder.js";
|
|
9
9
|
import type { MemoryRetrieverInput } from "../memory/retriever.js";
|
|
10
10
|
import { type Nullish, type PromiseOrValue, type XOr } from "../utils/type-utils.js";
|
|
11
|
+
import type { ChatModel } from "./chat-model.js";
|
|
11
12
|
import type { GuideRailAgent, GuideRailAgentOutput } from "./guide-rail-agent.js";
|
|
13
|
+
import type { ImageModel } from "./image-model.js";
|
|
12
14
|
import { type TransferAgentOutput } from "./types.js";
|
|
13
15
|
export * from "./types.js";
|
|
14
16
|
export declare const DEFAULT_INPUT_ACTION_GET = "$get";
|
|
@@ -73,6 +75,8 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
73
75
|
* for documentation and debugging
|
|
74
76
|
*/
|
|
75
77
|
description?: string;
|
|
78
|
+
model?: ChatModel;
|
|
79
|
+
imageModel?: ImageModel;
|
|
76
80
|
taskTitle?: string | ((input: I) => PromiseOrValue<string | undefined>);
|
|
77
81
|
taskRenderMode?: TaskRenderMode;
|
|
78
82
|
/**
|
|
@@ -142,6 +146,8 @@ export interface AgentInvokeOptions<U extends UserContext = UserContext> {
|
|
|
142
146
|
* agent system and maintain proper isolation and resource control.
|
|
143
147
|
*/
|
|
144
148
|
context: Context<U>;
|
|
149
|
+
model?: ChatModel;
|
|
150
|
+
imageModel?: ImageModel;
|
|
145
151
|
/**
|
|
146
152
|
* Whether to enable streaming response
|
|
147
153
|
*
|
|
@@ -269,6 +275,8 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
269
275
|
* each other's roles in a multi-agent system
|
|
270
276
|
*/
|
|
271
277
|
readonly description?: string;
|
|
278
|
+
model?: ChatModel;
|
|
279
|
+
imageModel?: ImageModel;
|
|
272
280
|
taskTitle?: string | ((input: Message) => PromiseOrValue<string | undefined>);
|
|
273
281
|
renderTaskTitle(input: I): Promise<string | undefined>;
|
|
274
282
|
taskRenderMode?: TaskRenderMode;
|
|
@@ -422,6 +430,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
422
430
|
private callHooks;
|
|
423
431
|
private mergeDefaultInput;
|
|
424
432
|
protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I & Message, options: AgentInvokeOptions): Promise<O>;
|
|
433
|
+
protected invokeChildAgent: Context["invoke"];
|
|
425
434
|
/**
|
|
426
435
|
* Process agent output
|
|
427
436
|
*
|
package/lib/esm/agents/agent.js
CHANGED
|
@@ -80,6 +80,8 @@ export class Agent {
|
|
|
80
80
|
this.name = options.name || this.constructor.name;
|
|
81
81
|
this.alias = options.alias;
|
|
82
82
|
this.description = options.description;
|
|
83
|
+
this.model = options.model;
|
|
84
|
+
this.imageModel = options.imageModel;
|
|
83
85
|
this.taskTitle = options.taskTitle;
|
|
84
86
|
this.taskRenderMode = options.taskRenderMode;
|
|
85
87
|
if (inputSchema)
|
|
@@ -180,6 +182,8 @@ export class Agent {
|
|
|
180
182
|
* each other's roles in a multi-agent system
|
|
181
183
|
*/
|
|
182
184
|
description;
|
|
185
|
+
model;
|
|
186
|
+
imageModel;
|
|
183
187
|
taskTitle;
|
|
184
188
|
async renderTaskTitle(input) {
|
|
185
189
|
if (!this.taskTitle)
|
|
@@ -445,10 +449,9 @@ export class Agent {
|
|
|
445
449
|
return input;
|
|
446
450
|
}
|
|
447
451
|
async invokeSkill(skill, input, options) {
|
|
448
|
-
const { context } = options;
|
|
449
452
|
await this.callHooks("onSkillStart", { skill, input }, options);
|
|
450
453
|
try {
|
|
451
|
-
const output = await
|
|
454
|
+
const output = await this.invokeChildAgent(skill, input, { ...options, streaming: false });
|
|
452
455
|
await this.callHooks("onSkillEnd", { skill, input, output }, options);
|
|
453
456
|
return output;
|
|
454
457
|
}
|
|
@@ -457,6 +460,13 @@ export class Agent {
|
|
|
457
460
|
throw error;
|
|
458
461
|
}
|
|
459
462
|
}
|
|
463
|
+
invokeChildAgent = ((agent, input, options) => {
|
|
464
|
+
return options.context.invoke(agent, input, {
|
|
465
|
+
...options,
|
|
466
|
+
model: this.model || options.model,
|
|
467
|
+
imageModel: this.imageModel || options.imageModel,
|
|
468
|
+
});
|
|
469
|
+
});
|
|
460
470
|
/**
|
|
461
471
|
* Process agent output
|
|
462
472
|
*
|
|
@@ -551,7 +561,7 @@ export class Agent {
|
|
|
551
561
|
return { ...(await this.onGuideRailError(error)), $status: "GuideRailError" };
|
|
552
562
|
}
|
|
553
563
|
async runGuideRails(input, output, options) {
|
|
554
|
-
const result = await Promise.all((this.guideRails ?? []).map((i) =>
|
|
564
|
+
const result = await Promise.all((this.guideRails ?? []).map((i) => this.invokeChildAgent(i, { input, output }, { ...options, streaming: false })));
|
|
555
565
|
return result.find((i) => !!i.abort);
|
|
556
566
|
}
|
|
557
567
|
/**
|
|
@@ -15,12 +15,6 @@ export declare const DEFAULT_FILE_OUTPUT_KEY = "files";
|
|
|
15
15
|
* @template O The output message type the agent returns
|
|
16
16
|
*/
|
|
17
17
|
export interface AIAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
18
|
-
/**
|
|
19
|
-
* The language model to use for this agent
|
|
20
|
-
*
|
|
21
|
-
* If not provided, the agent will use the model from the context
|
|
22
|
-
*/
|
|
23
|
-
model?: ChatModel;
|
|
24
18
|
/**
|
|
25
19
|
* Instructions to guide the AI model's behavior
|
|
26
20
|
*
|
|
@@ -200,12 +194,6 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
|
|
|
200
194
|
* @param options Configuration options for the AI agent
|
|
201
195
|
*/
|
|
202
196
|
constructor(options: AIAgentOptions<I, O>);
|
|
203
|
-
/**
|
|
204
|
-
* The language model used by this agent
|
|
205
|
-
*
|
|
206
|
-
* If not set on the agent, the model from the context will be used
|
|
207
|
-
*/
|
|
208
|
-
model?: ChatModel;
|
|
209
197
|
/**
|
|
210
198
|
* Instructions for the language model
|
|
211
199
|
*
|
|
@@ -103,7 +103,6 @@ export class AIAgent extends Agent {
|
|
|
103
103
|
constructor(options) {
|
|
104
104
|
super(options);
|
|
105
105
|
checkArguments("AIAgent", aiAgentOptionsSchema, options);
|
|
106
|
-
this.model = options.model;
|
|
107
106
|
this.instructions =
|
|
108
107
|
typeof options.instructions === "string"
|
|
109
108
|
? PromptBuilder.from(options.instructions)
|
|
@@ -131,12 +130,6 @@ export class AIAgent extends Agent {
|
|
|
131
130
|
throw new Error("AIAgent requires either inputKey or instructions to be set");
|
|
132
131
|
}
|
|
133
132
|
}
|
|
134
|
-
/**
|
|
135
|
-
* The language model used by this agent
|
|
136
|
-
*
|
|
137
|
-
* If not set on the agent, the model from the context will be used
|
|
138
|
-
*/
|
|
139
|
-
model;
|
|
140
133
|
/**
|
|
141
134
|
* Instructions for the language model
|
|
142
135
|
*
|
|
@@ -234,7 +227,7 @@ export class AIAgent extends Agent {
|
|
|
234
227
|
* @protected
|
|
235
228
|
*/
|
|
236
229
|
async *process(input, options) {
|
|
237
|
-
const model = this.model
|
|
230
|
+
const model = this.model || options.model || options.context.model;
|
|
238
231
|
if (!model)
|
|
239
232
|
throw new Error("model is required to run AIAgent");
|
|
240
233
|
const { toolAgents, ...modelInput } = await this.instructions.build({
|
|
@@ -251,7 +244,7 @@ export class AIAgent extends Agent {
|
|
|
251
244
|
const outputKey = this.outputKey;
|
|
252
245
|
for (;;) {
|
|
253
246
|
const modelOutput = {};
|
|
254
|
-
let stream = await
|
|
247
|
+
let stream = await this.invokeChildAgent(model, { ...modelInput, messages: modelInput.messages.concat(toolCallMessages) }, { ...options, streaming: true });
|
|
255
248
|
if (this.structuredStreamMode) {
|
|
256
249
|
const { metadataStart, metadataEnd, parse } = this.customStructuredStreamInstructions || STRUCTURED_STREAM_INSTRUCTIONS;
|
|
257
250
|
stream = stream.pipeThrough(new ExtractMetadataTransform({ start: metadataStart, end: metadataEnd, parse }));
|
|
@@ -336,7 +329,7 @@ export class AIAgent extends Agent {
|
|
|
336
329
|
* @protected
|
|
337
330
|
*/
|
|
338
331
|
async *_processRouter(input, model, modelInput, options, toolsMap) {
|
|
339
|
-
const { toolCalls: [call] = [] } = await
|
|
332
|
+
const { toolCalls: [call] = [] } = await this.invokeChildAgent(model, modelInput, {
|
|
340
333
|
...options,
|
|
341
334
|
streaming: false,
|
|
342
335
|
});
|
|
@@ -346,7 +339,7 @@ export class AIAgent extends Agent {
|
|
|
346
339
|
const tool = toolsMap.get(call.function.name);
|
|
347
340
|
if (!tool)
|
|
348
341
|
throw new Error(`Tool not found: ${call.function.name}`);
|
|
349
|
-
const stream = await
|
|
342
|
+
const stream = await this.invokeChildAgent(tool, { ...call.function.arguments, ...input }, { ...options, streaming: true, sourceAgent: this });
|
|
350
343
|
return yield* stream;
|
|
351
344
|
}
|
|
352
345
|
}
|