@aigne/core 1.59.0 → 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 +14 -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 +1 -1
- package/lib/cjs/agents/chat-model.js +1 -0
- 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 +1 -1
- 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 +1 -1
- package/lib/dts/agents/image-agent.d.ts +1 -3
- package/lib/dts/agents/image-model.d.ts +1 -1
- 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 +1 -1
- package/lib/esm/agents/chat-model.js +1 -0
- 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 +1 -1
- 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 +2 -2
|
@@ -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,7 +3,7 @@ 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>, "inputSchema" | "outputSchema"> {
|
|
6
|
+
export interface ChatModelOptions extends Omit<AgentOptions<ChatModelInput, ChatModelOutput>, "model" | "inputSchema" | "outputSchema"> {
|
|
7
7
|
model?: string;
|
|
8
8
|
modelOptions?: Omit<ModelOptions, "model">;
|
|
9
9
|
}
|
|
@@ -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;
|
|
@@ -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
|
}
|
|
@@ -3,7 +3,7 @@ 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>, "inputSchema" | "outputSchema"> {
|
|
6
|
+
export interface ChatModelOptions extends Omit<AgentOptions<ChatModelInput, ChatModelOutput>, "model" | "inputSchema" | "outputSchema"> {
|
|
7
7
|
model?: string;
|
|
8
8
|
modelOptions?: Omit<ModelOptions, "model">;
|
|
9
9
|
}
|
|
@@ -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>;
|
|
@@ -4,7 +4,6 @@ import { checkArguments } from "../utils/type-utils.js";
|
|
|
4
4
|
import { Agent, agentOptionsSchema, } from "./agent.js";
|
|
5
5
|
import { imageModelOutputSchema } from "./image-model.js";
|
|
6
6
|
export const imageAgentOptionsSchema = agentOptionsSchema.extend({
|
|
7
|
-
model: z.custom().optional(),
|
|
8
7
|
instructions: z.union([z.string(), z.custom()]),
|
|
9
8
|
modelOptions: z.record(z.any()).optional(),
|
|
10
9
|
});
|
|
@@ -16,21 +15,19 @@ export class ImageAgent extends Agent {
|
|
|
16
15
|
constructor(options) {
|
|
17
16
|
super({ ...options, outputSchema: imageModelOutputSchema });
|
|
18
17
|
checkArguments("ImageAgent", imageAgentOptionsSchema, options);
|
|
19
|
-
this.model = options.model;
|
|
20
18
|
this.instructions =
|
|
21
19
|
typeof options.instructions === "string"
|
|
22
20
|
? PromptBuilder.from(options.instructions)
|
|
23
21
|
: options.instructions;
|
|
24
22
|
this.modelOptions = options.modelOptions;
|
|
25
23
|
}
|
|
26
|
-
model;
|
|
27
24
|
instructions;
|
|
28
25
|
modelOptions;
|
|
29
26
|
async process(input, options) {
|
|
30
|
-
const
|
|
31
|
-
if (!
|
|
27
|
+
const imageModel = this.imageModel || options.imageModel || options.context.imageModel;
|
|
28
|
+
if (!imageModel)
|
|
32
29
|
throw new Error("image model is required to run ImageAgent");
|
|
33
30
|
const { prompt } = await this.instructions.buildImagePrompt({ input });
|
|
34
|
-
return (await
|
|
31
|
+
return (await this.invokeChildAgent(imageModel, { ...input, ...this.modelOptions, prompt }, { ...options, streaming: false }));
|
|
35
32
|
}
|
|
36
33
|
}
|
|
@@ -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;
|
|
@@ -171,7 +171,10 @@ export class TeamAgent extends Agent {
|
|
|
171
171
|
for (;;) {
|
|
172
172
|
const output = await agentProcessResultToObject(await this._processNonReflection(previousOutput, options));
|
|
173
173
|
Object.assign(previousOutput, output);
|
|
174
|
-
const reviewOutput = await
|
|
174
|
+
const reviewOutput = await this.invokeChildAgent(this.reflection.reviewer, previousOutput, {
|
|
175
|
+
...options,
|
|
176
|
+
streaming: false,
|
|
177
|
+
});
|
|
175
178
|
Object.assign(previousOutput, reviewOutput);
|
|
176
179
|
const { isApproved } = this.reflection;
|
|
177
180
|
const approved = typeof isApproved === "string" ? reviewOutput[isApproved] : await isApproved(reviewOutput);
|
|
@@ -246,7 +249,7 @@ export class TeamAgent extends Agent {
|
|
|
246
249
|
async *_processSequential(input, options) {
|
|
247
250
|
const output = {};
|
|
248
251
|
for (const agent of this.skills) {
|
|
249
|
-
const o = await
|
|
252
|
+
const o = await this.invokeChildAgent(agent, { ...input, ...output }, { ...options, streaming: true });
|
|
250
253
|
const isLast = agent === this.skills[this.skills.length - 1];
|
|
251
254
|
for await (const chunk of o) {
|
|
252
255
|
// Only yield the chunk if it is the last agent in the sequence
|
|
@@ -272,7 +275,7 @@ export class TeamAgent extends Agent {
|
|
|
272
275
|
* @private
|
|
273
276
|
*/
|
|
274
277
|
async *_processParallel(input, options) {
|
|
275
|
-
const streams = await Promise.all(this.skills.map((agent) =>
|
|
278
|
+
const streams = await Promise.all(this.skills.map((agent) => this.invokeChildAgent(agent, input, { ...options, streaming: true })));
|
|
276
279
|
const read = async (index, reader) => {
|
|
277
280
|
const promise = reader.read();
|
|
278
281
|
return promise.then((result) => ({ ...result, reader, index }));
|
|
@@ -32,7 +32,8 @@ export class UserAgent extends Agent {
|
|
|
32
32
|
return this._process(input, options);
|
|
33
33
|
}
|
|
34
34
|
if (this.activeAgent) {
|
|
35
|
-
const [output, agent] = await
|
|
35
|
+
const [output, agent] = await this.invokeChildAgent(this.activeAgent, input, {
|
|
36
|
+
...options,
|
|
36
37
|
returnActiveAgent: true,
|
|
37
38
|
streaming: true,
|
|
38
39
|
// Do not create a new context for the nested agent invocation,
|
package/lib/esm/aigne/context.js
CHANGED
|
@@ -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>;
|
|
@@ -5,7 +5,7 @@ import { z } from "zod";
|
|
|
5
5
|
import { AIAgentToolChoice } from "../agents/ai-agent.js";
|
|
6
6
|
import { ProcessMode } from "../agents/team-agent.js";
|
|
7
7
|
import { tryOrThrow } from "../utils/type-utils.js";
|
|
8
|
-
import { camelizeSchema, defaultInputSchema, inputOutputSchema, optionalize } from "./schema.js";
|
|
8
|
+
import { camelizeSchema, chatModelSchema, defaultInputSchema, imageModelSchema, inputOutputSchema, optionalize, } from "./schema.js";
|
|
9
9
|
export async function parseAgentFile(path, data) {
|
|
10
10
|
const agentSchema = z.lazy(() => {
|
|
11
11
|
const nestAgentSchema = z.lazy(() => z.union([
|
|
@@ -31,6 +31,8 @@ export async function parseAgentFile(path, data) {
|
|
|
31
31
|
name: optionalize(z.string()),
|
|
32
32
|
alias: optionalize(z.array(z.string())),
|
|
33
33
|
description: optionalize(z.string()),
|
|
34
|
+
model: optionalize(chatModelSchema),
|
|
35
|
+
imageModel: optionalize(imageModelSchema),
|
|
34
36
|
taskTitle: optionalize(z.string()),
|
|
35
37
|
taskRenderMode: optionalize(z.union([z.literal("hide"), z.literal("collapse")])),
|
|
36
38
|
inputSchema: optionalize(inputOutputSchema({ path })).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
@@ -114,7 +116,10 @@ export async function parseAgentFile(path, data) {
|
|
|
114
116
|
.extend(baseAgentSchema.shape),
|
|
115
117
|
]));
|
|
116
118
|
});
|
|
117
|
-
return agentSchema.parseAsync(
|
|
119
|
+
return agentSchema.parseAsync({
|
|
120
|
+
...data,
|
|
121
|
+
model: data.model || data.chatModel || data.chat_model,
|
|
122
|
+
});
|
|
118
123
|
}
|
|
119
124
|
export async function loadAgentFromYamlFile(path) {
|
|
120
125
|
const raw = await tryOrThrow(() => nodejs.fs.readFile(path, "utf8"), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
|