@aigne/core 1.72.0-beta.2 → 1.72.0-beta.23
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 +261 -0
- package/lib/cjs/agents/agent.d.ts +42 -11
- package/lib/cjs/agents/agent.js +34 -8
- package/lib/cjs/agents/ai-agent.d.ts +63 -4
- package/lib/cjs/agents/ai-agent.js +154 -20
- package/lib/cjs/agents/chat-model.d.ts +157 -0
- package/lib/cjs/agents/chat-model.js +71 -6
- package/lib/cjs/agents/image-agent.d.ts +17 -1
- package/lib/cjs/agents/image-agent.js +16 -0
- package/lib/cjs/agents/image-model.d.ts +12 -2
- package/lib/cjs/agents/image-model.js +1 -1
- package/lib/cjs/agents/mcp-agent.d.ts +17 -0
- package/lib/cjs/agents/mcp-agent.js +18 -0
- package/lib/cjs/agents/model.d.ts +3 -3
- package/lib/cjs/agents/model.js +2 -2
- package/lib/cjs/agents/team-agent.d.ts +55 -0
- package/lib/cjs/agents/team-agent.js +31 -0
- package/lib/cjs/agents/transform-agent.d.ts +12 -0
- package/lib/cjs/agents/transform-agent.js +13 -0
- package/lib/cjs/agents/video-model.d.ts +10 -0
- package/lib/cjs/agents/video-model.js +1 -1
- package/lib/cjs/aigne/context.js +1 -3
- package/lib/cjs/aigne/usage.d.ts +4 -0
- package/lib/cjs/aigne/usage.js +6 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/loader/agent-yaml.d.ts +5 -63
- package/lib/cjs/loader/agent-yaml.js +4 -129
- package/lib/cjs/loader/agents.d.ts +4 -0
- package/lib/cjs/loader/agents.js +17 -0
- package/lib/cjs/loader/index.d.ts +16 -12
- package/lib/cjs/loader/index.js +20 -81
- package/lib/cjs/loader/schema.d.ts +21 -6
- package/lib/cjs/loader/schema.js +60 -1
- package/lib/cjs/memory/recorder.d.ts +4 -4
- package/lib/cjs/memory/retriever.d.ts +4 -4
- package/lib/cjs/prompt/agent-session.d.ts +163 -0
- package/lib/cjs/prompt/agent-session.js +1008 -0
- package/lib/cjs/prompt/compact/compactor.d.ts +7 -0
- package/lib/cjs/prompt/compact/compactor.js +52 -0
- package/lib/cjs/prompt/compact/session-memory-extractor.d.ts +7 -0
- package/lib/cjs/prompt/compact/session-memory-extractor.js +143 -0
- package/lib/cjs/prompt/compact/types.d.ts +336 -0
- package/lib/cjs/prompt/compact/types.js +53 -0
- package/lib/cjs/prompt/compact/user-memory-extractor.d.ts +7 -0
- package/lib/cjs/prompt/compact/user-memory-extractor.js +124 -0
- package/lib/cjs/prompt/context/afs/history.d.ts +5 -1
- package/lib/cjs/prompt/context/afs/history.js +3 -2
- package/lib/cjs/prompt/context/afs/index.js +8 -1
- package/lib/cjs/prompt/prompt-builder.d.ts +11 -9
- package/lib/cjs/prompt/prompt-builder.js +79 -120
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +19 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.js +69 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.d.ts +12 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +50 -0
- package/lib/cjs/prompt/skills/afs/delete.js +15 -3
- package/lib/cjs/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/cjs/prompt/skills/afs/edit.js +85 -59
- package/lib/cjs/prompt/skills/afs/exec.js +17 -6
- package/lib/cjs/prompt/skills/afs/index.js +4 -1
- package/lib/cjs/prompt/skills/afs/list.d.ts +2 -0
- package/lib/cjs/prompt/skills/afs/list.js +35 -11
- package/lib/cjs/prompt/skills/afs/read.d.ts +9 -3
- package/lib/cjs/prompt/skills/afs/read.js +67 -15
- package/lib/cjs/prompt/skills/afs/rename.js +18 -4
- package/lib/cjs/prompt/skills/afs/search.js +21 -5
- package/lib/cjs/prompt/skills/afs/write.js +20 -6
- package/lib/cjs/prompt/template.d.ts +84 -9
- package/lib/cjs/prompt/template.js +46 -17
- package/lib/cjs/utils/mcp-utils.js +1 -1
- package/lib/cjs/utils/token-estimator.js +1 -1
- package/lib/dts/agents/agent.d.ts +42 -11
- package/lib/dts/agents/ai-agent.d.ts +63 -4
- package/lib/dts/agents/chat-model.d.ts +157 -0
- package/lib/dts/agents/image-agent.d.ts +17 -1
- package/lib/dts/agents/image-model.d.ts +12 -2
- package/lib/dts/agents/mcp-agent.d.ts +17 -0
- package/lib/dts/agents/model.d.ts +3 -3
- package/lib/dts/agents/team-agent.d.ts +55 -0
- package/lib/dts/agents/transform-agent.d.ts +12 -0
- package/lib/dts/agents/video-model.d.ts +10 -0
- package/lib/dts/aigne/context.d.ts +2 -2
- package/lib/dts/aigne/usage.d.ts +4 -0
- package/lib/dts/index.d.ts +1 -0
- package/lib/dts/loader/agent-yaml.d.ts +5 -63
- package/lib/dts/loader/agents.d.ts +4 -0
- package/lib/dts/loader/index.d.ts +16 -12
- package/lib/dts/loader/schema.d.ts +21 -6
- package/lib/dts/memory/recorder.d.ts +4 -4
- package/lib/dts/memory/retriever.d.ts +4 -4
- package/lib/dts/prompt/agent-session.d.ts +163 -0
- package/lib/dts/prompt/compact/compactor.d.ts +7 -0
- package/lib/dts/prompt/compact/session-memory-extractor.d.ts +7 -0
- package/lib/dts/prompt/compact/types.d.ts +336 -0
- package/lib/dts/prompt/compact/user-memory-extractor.d.ts +7 -0
- package/lib/dts/prompt/context/afs/history.d.ts +5 -1
- package/lib/dts/prompt/prompt-builder.d.ts +11 -9
- package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +19 -0
- package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +12 -0
- package/lib/dts/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/dts/prompt/skills/afs/list.d.ts +2 -0
- package/lib/dts/prompt/skills/afs/read.d.ts +9 -3
- package/lib/dts/prompt/template.d.ts +84 -9
- package/lib/esm/agents/agent.d.ts +42 -11
- package/lib/esm/agents/agent.js +34 -8
- package/lib/esm/agents/ai-agent.d.ts +63 -4
- package/lib/esm/agents/ai-agent.js +154 -20
- package/lib/esm/agents/chat-model.d.ts +157 -0
- package/lib/esm/agents/chat-model.js +70 -5
- package/lib/esm/agents/image-agent.d.ts +17 -1
- package/lib/esm/agents/image-agent.js +16 -0
- package/lib/esm/agents/image-model.d.ts +12 -2
- package/lib/esm/agents/image-model.js +1 -1
- package/lib/esm/agents/mcp-agent.d.ts +17 -0
- package/lib/esm/agents/mcp-agent.js +18 -0
- package/lib/esm/agents/model.d.ts +3 -3
- package/lib/esm/agents/model.js +2 -2
- package/lib/esm/agents/team-agent.d.ts +55 -0
- package/lib/esm/agents/team-agent.js +31 -0
- package/lib/esm/agents/transform-agent.d.ts +12 -0
- package/lib/esm/agents/transform-agent.js +13 -0
- package/lib/esm/agents/video-model.d.ts +10 -0
- package/lib/esm/agents/video-model.js +1 -1
- package/lib/esm/aigne/context.d.ts +2 -2
- package/lib/esm/aigne/context.js +2 -4
- package/lib/esm/aigne/usage.d.ts +4 -0
- package/lib/esm/aigne/usage.js +6 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/loader/agent-yaml.d.ts +5 -63
- package/lib/esm/loader/agent-yaml.js +4 -128
- package/lib/esm/loader/agents.d.ts +4 -0
- package/lib/esm/loader/agents.js +14 -0
- package/lib/esm/loader/index.d.ts +16 -12
- package/lib/esm/loader/index.js +21 -81
- package/lib/esm/loader/schema.d.ts +21 -6
- package/lib/esm/loader/schema.js +57 -0
- package/lib/esm/memory/recorder.d.ts +4 -4
- package/lib/esm/memory/retriever.d.ts +4 -4
- package/lib/esm/prompt/agent-session.d.ts +163 -0
- package/lib/esm/prompt/agent-session.js +968 -0
- package/lib/esm/prompt/compact/compactor.d.ts +7 -0
- package/lib/esm/prompt/compact/compactor.js +48 -0
- package/lib/esm/prompt/compact/session-memory-extractor.d.ts +7 -0
- package/lib/esm/prompt/compact/session-memory-extractor.js +139 -0
- package/lib/esm/prompt/compact/types.d.ts +336 -0
- package/lib/esm/prompt/compact/types.js +50 -0
- package/lib/esm/prompt/compact/user-memory-extractor.d.ts +7 -0
- package/lib/esm/prompt/compact/user-memory-extractor.js +120 -0
- package/lib/esm/prompt/context/afs/history.d.ts +5 -1
- package/lib/esm/prompt/context/afs/history.js +3 -2
- package/lib/esm/prompt/context/afs/index.js +8 -1
- package/lib/esm/prompt/prompt-builder.d.ts +11 -9
- package/lib/esm/prompt/prompt-builder.js +80 -121
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +19 -0
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.js +65 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.d.ts +12 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +43 -0
- package/lib/esm/prompt/skills/afs/delete.js +15 -3
- package/lib/esm/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/esm/prompt/skills/afs/edit.js +85 -59
- package/lib/esm/prompt/skills/afs/exec.js +17 -6
- package/lib/esm/prompt/skills/afs/index.js +4 -1
- package/lib/esm/prompt/skills/afs/list.d.ts +2 -0
- package/lib/esm/prompt/skills/afs/list.js +35 -11
- package/lib/esm/prompt/skills/afs/read.d.ts +9 -3
- package/lib/esm/prompt/skills/afs/read.js +67 -15
- package/lib/esm/prompt/skills/afs/rename.js +18 -4
- package/lib/esm/prompt/skills/afs/search.js +21 -5
- package/lib/esm/prompt/skills/afs/write.js +20 -6
- package/lib/esm/prompt/template.d.ts +84 -9
- package/lib/esm/prompt/template.js +46 -17
- package/lib/esm/utils/mcp-utils.js +1 -1
- package/lib/esm/utils/token-estimator.js +1 -1
- package/package.json +7 -6
|
@@ -27,35 +27,38 @@ export declare class ChatMessageTemplate {
|
|
|
27
27
|
content?: ChatModelInputMessage["content"];
|
|
28
28
|
name?: string | undefined;
|
|
29
29
|
options?: FormatOptions | undefined;
|
|
30
|
-
|
|
30
|
+
cacheControl?: ChatModelInputMessage["cacheControl"];
|
|
31
|
+
constructor(role: "system" | "user" | "agent" | "tool", content?: ChatModelInputMessage["content"], name?: string | undefined, options?: FormatOptions | undefined, cacheControl?: ChatModelInputMessage["cacheControl"]);
|
|
31
32
|
format(variables?: Record<string, unknown>, options?: FormatOptions): Promise<ChatModelInputMessage>;
|
|
32
33
|
}
|
|
33
34
|
export declare class SystemMessageTemplate extends ChatMessageTemplate {
|
|
34
|
-
static from(content: string, name?: string, options?: FormatOptions): SystemMessageTemplate;
|
|
35
|
+
static from(content: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): SystemMessageTemplate;
|
|
35
36
|
}
|
|
36
37
|
export declare class UserMessageTemplate extends ChatMessageTemplate {
|
|
37
|
-
static from(template: ChatModelInputMessageContent, name?: string, options?: FormatOptions): UserMessageTemplate;
|
|
38
|
+
static from(template: ChatModelInputMessageContent, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): UserMessageTemplate;
|
|
38
39
|
}
|
|
39
40
|
export declare class AgentMessageTemplate extends ChatMessageTemplate {
|
|
40
41
|
toolCalls?: ChatModelOutputToolCall[] | undefined;
|
|
41
|
-
static from(template?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[], name?: string, options?: FormatOptions): AgentMessageTemplate;
|
|
42
|
-
constructor(content?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[] | undefined, name?: string, options?: FormatOptions);
|
|
42
|
+
static from(template?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[], name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): AgentMessageTemplate;
|
|
43
|
+
constructor(content?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[] | undefined, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]);
|
|
43
44
|
format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
|
|
44
|
-
role: "agent" | "
|
|
45
|
+
role: "agent" | "user" | "system" | "tool";
|
|
45
46
|
name: string | undefined;
|
|
46
47
|
content: ChatModelInputMessageContent | undefined;
|
|
47
48
|
toolCalls: ChatModelOutputToolCall[] | undefined;
|
|
49
|
+
cacheControl: import("../index.js").CacheControl | undefined;
|
|
48
50
|
}>;
|
|
49
51
|
}
|
|
50
52
|
export declare class ToolMessageTemplate extends ChatMessageTemplate {
|
|
51
53
|
toolCallId: string;
|
|
52
|
-
static from(content: object | string, toolCallId: string, name?: string, options?: FormatOptions): ToolMessageTemplate;
|
|
53
|
-
constructor(content: object | string, toolCallId: string, name?: string, options?: FormatOptions);
|
|
54
|
+
static from(content: object | string, toolCallId: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): ToolMessageTemplate;
|
|
55
|
+
constructor(content: object | string, toolCallId: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]);
|
|
54
56
|
format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
|
|
55
|
-
role: "agent" | "
|
|
57
|
+
role: "agent" | "user" | "system" | "tool";
|
|
56
58
|
name: string | undefined;
|
|
57
59
|
content: ChatModelInputMessageContent | undefined;
|
|
58
60
|
toolCallId: string;
|
|
61
|
+
cacheControl: import("../index.js").CacheControl | undefined;
|
|
59
62
|
}>;
|
|
60
63
|
}
|
|
61
64
|
export declare class ChatMessagesTemplate {
|
|
@@ -69,26 +72,62 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
69
72
|
role: z.ZodLiteral<"system">;
|
|
70
73
|
content: z.ZodString;
|
|
71
74
|
name: z.ZodOptional<z.ZodString>;
|
|
75
|
+
cacheControl: z.ZodOptional<z.ZodObject<{
|
|
76
|
+
type: z.ZodLiteral<"ephemeral">;
|
|
77
|
+
ttl: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
|
|
78
|
+
}, "strip", z.ZodTypeAny, {
|
|
79
|
+
type: "ephemeral";
|
|
80
|
+
ttl?: "5m" | "1h" | undefined;
|
|
81
|
+
}, {
|
|
82
|
+
type: "ephemeral";
|
|
83
|
+
ttl?: "5m" | "1h" | undefined;
|
|
84
|
+
}>>;
|
|
72
85
|
}, "strip", z.ZodTypeAny, {
|
|
73
86
|
role: "system";
|
|
74
87
|
content: string;
|
|
75
88
|
name?: string | undefined;
|
|
89
|
+
cacheControl?: {
|
|
90
|
+
type: "ephemeral";
|
|
91
|
+
ttl?: "5m" | "1h" | undefined;
|
|
92
|
+
} | undefined;
|
|
76
93
|
}, {
|
|
77
94
|
role: "system";
|
|
78
95
|
content: string;
|
|
79
96
|
name?: string | undefined;
|
|
97
|
+
cacheControl?: {
|
|
98
|
+
type: "ephemeral";
|
|
99
|
+
ttl?: "5m" | "1h" | undefined;
|
|
100
|
+
} | undefined;
|
|
80
101
|
}>, z.ZodObject<{
|
|
81
102
|
role: z.ZodLiteral<"user">;
|
|
82
103
|
content: z.ZodString;
|
|
83
104
|
name: z.ZodOptional<z.ZodString>;
|
|
105
|
+
cacheControl: z.ZodOptional<z.ZodObject<{
|
|
106
|
+
type: z.ZodLiteral<"ephemeral">;
|
|
107
|
+
ttl: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
|
|
108
|
+
}, "strip", z.ZodTypeAny, {
|
|
109
|
+
type: "ephemeral";
|
|
110
|
+
ttl?: "5m" | "1h" | undefined;
|
|
111
|
+
}, {
|
|
112
|
+
type: "ephemeral";
|
|
113
|
+
ttl?: "5m" | "1h" | undefined;
|
|
114
|
+
}>>;
|
|
84
115
|
}, "strip", z.ZodTypeAny, {
|
|
85
116
|
role: "user";
|
|
86
117
|
content: string;
|
|
87
118
|
name?: string | undefined;
|
|
119
|
+
cacheControl?: {
|
|
120
|
+
type: "ephemeral";
|
|
121
|
+
ttl?: "5m" | "1h" | undefined;
|
|
122
|
+
} | undefined;
|
|
88
123
|
}, {
|
|
89
124
|
role: "user";
|
|
90
125
|
content: string;
|
|
91
126
|
name?: string | undefined;
|
|
127
|
+
cacheControl?: {
|
|
128
|
+
type: "ephemeral";
|
|
129
|
+
ttl?: "5m" | "1h" | undefined;
|
|
130
|
+
} | undefined;
|
|
92
131
|
}>, z.ZodObject<{
|
|
93
132
|
role: z.ZodLiteral<"agent">;
|
|
94
133
|
content: z.ZodOptional<z.ZodString>;
|
|
@@ -121,10 +160,24 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
121
160
|
id: string;
|
|
122
161
|
}>, "many">>;
|
|
123
162
|
name: z.ZodOptional<z.ZodString>;
|
|
163
|
+
cacheControl: z.ZodOptional<z.ZodObject<{
|
|
164
|
+
type: z.ZodLiteral<"ephemeral">;
|
|
165
|
+
ttl: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
|
|
166
|
+
}, "strip", z.ZodTypeAny, {
|
|
167
|
+
type: "ephemeral";
|
|
168
|
+
ttl?: "5m" | "1h" | undefined;
|
|
169
|
+
}, {
|
|
170
|
+
type: "ephemeral";
|
|
171
|
+
ttl?: "5m" | "1h" | undefined;
|
|
172
|
+
}>>;
|
|
124
173
|
}, "strip", z.ZodTypeAny, {
|
|
125
174
|
role: "agent";
|
|
126
175
|
name?: string | undefined;
|
|
127
176
|
content?: string | undefined;
|
|
177
|
+
cacheControl?: {
|
|
178
|
+
type: "ephemeral";
|
|
179
|
+
ttl?: "5m" | "1h" | undefined;
|
|
180
|
+
} | undefined;
|
|
128
181
|
toolCalls?: {
|
|
129
182
|
function: {
|
|
130
183
|
name: string;
|
|
@@ -137,6 +190,10 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
137
190
|
role: "agent";
|
|
138
191
|
name?: string | undefined;
|
|
139
192
|
content?: string | undefined;
|
|
193
|
+
cacheControl?: {
|
|
194
|
+
type: "ephemeral";
|
|
195
|
+
ttl?: "5m" | "1h" | undefined;
|
|
196
|
+
} | undefined;
|
|
140
197
|
toolCalls?: {
|
|
141
198
|
function: {
|
|
142
199
|
name: string;
|
|
@@ -150,16 +207,34 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
150
207
|
content: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>, string, string | Record<string, unknown>>;
|
|
151
208
|
toolCallId: z.ZodString;
|
|
152
209
|
name: z.ZodOptional<z.ZodString>;
|
|
210
|
+
cacheControl: z.ZodOptional<z.ZodObject<{
|
|
211
|
+
type: z.ZodLiteral<"ephemeral">;
|
|
212
|
+
ttl: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
|
|
213
|
+
}, "strip", z.ZodTypeAny, {
|
|
214
|
+
type: "ephemeral";
|
|
215
|
+
ttl?: "5m" | "1h" | undefined;
|
|
216
|
+
}, {
|
|
217
|
+
type: "ephemeral";
|
|
218
|
+
ttl?: "5m" | "1h" | undefined;
|
|
219
|
+
}>>;
|
|
153
220
|
}, "strip", z.ZodTypeAny, {
|
|
154
221
|
role: "tool";
|
|
155
222
|
content: string;
|
|
156
223
|
toolCallId: string;
|
|
157
224
|
name?: string | undefined;
|
|
225
|
+
cacheControl?: {
|
|
226
|
+
type: "ephemeral";
|
|
227
|
+
ttl?: "5m" | "1h" | undefined;
|
|
228
|
+
} | undefined;
|
|
158
229
|
}, {
|
|
159
230
|
role: "tool";
|
|
160
231
|
content: string | Record<string, unknown>;
|
|
161
232
|
toolCallId: string;
|
|
162
233
|
name?: string | undefined;
|
|
234
|
+
cacheControl?: {
|
|
235
|
+
type: "ephemeral";
|
|
236
|
+
ttl?: "5m" | "1h" | undefined;
|
|
237
|
+
} | undefined;
|
|
163
238
|
}>]>;
|
|
164
239
|
export declare function safeParseChatMessages(messages: unknown): ChatMessageTemplate[] | undefined;
|
|
165
240
|
export declare function parseChatMessages(messages: (z.infer<typeof chatMessageSchema> & {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AFS, type AFSExecOptions, type AFSExecResult, type AFSListOptions, type AFSListResult, type AFSModule, type AFSOptions, type AFSReadResult, type AFSSearchOptions } from "@aigne/afs";
|
|
2
2
|
import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
|
|
3
3
|
import type * as prompts from "@inquirer/prompts";
|
|
4
|
-
import { type ZodObject, type ZodType } from "zod";
|
|
4
|
+
import { type ZodObject, type ZodType, z } from "zod";
|
|
5
5
|
import type { AgentEvent, Context, UserContext } from "../aigne/context.js";
|
|
6
6
|
import type { MessagePayload } from "../aigne/message-queue.js";
|
|
7
7
|
import type { ContextUsage } from "../aigne/usage.js";
|
|
@@ -9,7 +9,7 @@ import type { Memory, MemoryAgent } from "../memory/memory.js";
|
|
|
9
9
|
import type { MemoryRecorderInput } from "../memory/recorder.js";
|
|
10
10
|
import type { MemoryRetrieverInput } from "../memory/retriever.js";
|
|
11
11
|
import { type Nullish, type PromiseOrValue, type XOr } from "../utils/type-utils.js";
|
|
12
|
-
import type { ChatModel } from "./chat-model.js";
|
|
12
|
+
import type { ChatModel, ChatModelInputMessage } from "./chat-model.js";
|
|
13
13
|
import type { GuideRailAgent, GuideRailAgentOutput } from "./guide-rail-agent.js";
|
|
14
14
|
import type { ImageModel } from "./image-model.js";
|
|
15
15
|
import { type GetterSchema, type TransferAgentOutput } from "./types.js";
|
|
@@ -118,7 +118,6 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
118
118
|
* agentSucceed, or agentFailed
|
|
119
119
|
*/
|
|
120
120
|
disableEvents?: boolean;
|
|
121
|
-
historyConfig?: Agent["historyConfig"];
|
|
122
121
|
/**
|
|
123
122
|
* One or more memory agents this agent can use
|
|
124
123
|
*/
|
|
@@ -173,6 +172,10 @@ export interface AgentInvokeOptions<U extends UserContext = UserContext> {
|
|
|
173
172
|
* This property only exists in the CLI context by command `aigne run`
|
|
174
173
|
*/
|
|
175
174
|
prompts?: typeof prompts;
|
|
175
|
+
/**
|
|
176
|
+
* The caller agent that invoked this agent
|
|
177
|
+
*/
|
|
178
|
+
caller?: Agent;
|
|
176
179
|
}
|
|
177
180
|
/**
|
|
178
181
|
* Agent is the base class for all agents.
|
|
@@ -211,15 +214,15 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
211
214
|
parsed: object;
|
|
212
215
|
}): Promise<Agent<I, O>>;
|
|
213
216
|
constructor(options?: AgentOptions<I, O>);
|
|
217
|
+
afs?: AFS;
|
|
218
|
+
tag?: string;
|
|
214
219
|
/**
|
|
215
220
|
* List of memories this agent can use
|
|
216
221
|
*
|
|
217
222
|
* @deprecated use afs instead
|
|
218
223
|
*/
|
|
219
224
|
readonly memories: MemoryAgent[];
|
|
220
|
-
afs?: AFS;
|
|
221
225
|
asyncMemoryRecord?: boolean;
|
|
222
|
-
tag?: string;
|
|
223
226
|
/**
|
|
224
227
|
* Maximum number of memory items to retrieve
|
|
225
228
|
*/
|
|
@@ -349,11 +352,6 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
349
352
|
* agentSucceed, or agentFailed
|
|
350
353
|
*/
|
|
351
354
|
private disableEvents?;
|
|
352
|
-
historyConfig?: {
|
|
353
|
-
disabled?: boolean;
|
|
354
|
-
maxTokens?: number;
|
|
355
|
-
maxItems?: number;
|
|
356
|
-
};
|
|
357
355
|
private subscriptions;
|
|
358
356
|
/**
|
|
359
357
|
* Attach agent to context:
|
|
@@ -455,7 +453,9 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
455
453
|
* @param options Invocation options
|
|
456
454
|
* @returns Final processed output
|
|
457
455
|
*/
|
|
458
|
-
protected processAgentOutput(input: I, output: Exclude<AgentResponse<O>, AgentResponseStream<O>>, options: AgentInvokeOptions
|
|
456
|
+
protected processAgentOutput(input: I, output: Exclude<AgentResponse<O>, AgentResponseStream<O>>, { messages, ...options }: AgentInvokeOptions & {
|
|
457
|
+
messages?: ChatModelInputMessage[];
|
|
458
|
+
}): Promise<O>;
|
|
459
459
|
/**
|
|
460
460
|
* Process errors that occur during agent execution
|
|
461
461
|
*
|
|
@@ -517,6 +517,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
517
517
|
*/
|
|
518
518
|
protected postprocess(input: I, output: O, options: AgentInvokeOptions): Promise<void>;
|
|
519
519
|
protected publishToTopics(output: Message, options: AgentInvokeOptions): Promise<void>;
|
|
520
|
+
formatOutput(output: O): PromiseOrValue<string>;
|
|
520
521
|
/**
|
|
521
522
|
* Core processing method of the agent, must be implemented in subclasses
|
|
522
523
|
*
|
|
@@ -783,12 +784,31 @@ export interface AgentResponseProgress {
|
|
|
783
784
|
} | {
|
|
784
785
|
event: "agentFailed";
|
|
785
786
|
error: Error;
|
|
787
|
+
} | {
|
|
788
|
+
event: "message";
|
|
789
|
+
message: ChatModelInputMessage;
|
|
786
790
|
}) & Omit<AgentEvent, "agent"> & {
|
|
787
791
|
agent: {
|
|
788
792
|
name: string;
|
|
789
793
|
};
|
|
790
794
|
};
|
|
791
795
|
}
|
|
796
|
+
export type AgentResponseProgressMessageItem = {
|
|
797
|
+
type: "text";
|
|
798
|
+
content: string;
|
|
799
|
+
} | {
|
|
800
|
+
type: "thinking";
|
|
801
|
+
thoughts: string;
|
|
802
|
+
} | {
|
|
803
|
+
type: "tool_use";
|
|
804
|
+
toolUseId: string;
|
|
805
|
+
name: string;
|
|
806
|
+
input: unknown;
|
|
807
|
+
} | {
|
|
808
|
+
type: "tool_result";
|
|
809
|
+
toolUseId: string;
|
|
810
|
+
content: unknown;
|
|
811
|
+
};
|
|
792
812
|
export declare function isAgentResponseProgress<T>(chunk: AgentResponseChunk<T>): chunk is AgentResponseProgress;
|
|
793
813
|
/**
|
|
794
814
|
* Creates a text delta for streaming responses
|
|
@@ -870,6 +890,17 @@ export interface FunctionAgentOptions<I extends Message = Message, O extends Mes
|
|
|
870
890
|
*/
|
|
871
891
|
export declare class FunctionAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
872
892
|
tag: string;
|
|
893
|
+
static schema(): ZodObject<{
|
|
894
|
+
process: ZodType<FunctionAgentFn>;
|
|
895
|
+
}, "strip", z.ZodTypeAny, {
|
|
896
|
+
process: FunctionAgentFn<any, any, FunctionAgent<any, any>>;
|
|
897
|
+
}, {
|
|
898
|
+
process: FunctionAgentFn<any, any, FunctionAgent<any, any>>;
|
|
899
|
+
}>;
|
|
900
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
901
|
+
filepath: string;
|
|
902
|
+
parsed: object;
|
|
903
|
+
}): Promise<Agent<I, O>>;
|
|
873
904
|
/**
|
|
874
905
|
* Create a function agent from a function or options
|
|
875
906
|
*
|
package/lib/esm/agents/agent.js
CHANGED
|
@@ -3,8 +3,10 @@ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
|
|
|
3
3
|
import equal from "fast-deep-equal";
|
|
4
4
|
import nunjucks from "nunjucks";
|
|
5
5
|
import { joinURL } from "ufo";
|
|
6
|
+
import { stringify } from "yaml";
|
|
6
7
|
import { z } from "zod";
|
|
7
8
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
9
|
+
import { codeToFunctionAgentFn } from "../loader/function-agent.js";
|
|
8
10
|
import { sortHooks } from "../utils/agent-utils.js";
|
|
9
11
|
import { getZodObjectKeys, isZodSchema } from "../utils/json-schema.js";
|
|
10
12
|
import { logger } from "../utils/logger.js";
|
|
@@ -103,7 +105,6 @@ export class Agent {
|
|
|
103
105
|
if (options.skills?.length)
|
|
104
106
|
this.skills.push(...options.skills.map(functionToAgent));
|
|
105
107
|
this.disableEvents = options.disableEvents;
|
|
106
|
-
this.historyConfig = options.historyConfig;
|
|
107
108
|
if (Array.isArray(options.memory)) {
|
|
108
109
|
this.memories.push(...options.memory);
|
|
109
110
|
}
|
|
@@ -130,15 +131,15 @@ export class Agent {
|
|
|
130
131
|
: options.retryOnError;
|
|
131
132
|
this.guideRails = options.guideRails;
|
|
132
133
|
}
|
|
134
|
+
afs;
|
|
135
|
+
tag;
|
|
133
136
|
/**
|
|
134
137
|
* List of memories this agent can use
|
|
135
138
|
*
|
|
136
139
|
* @deprecated use afs instead
|
|
137
140
|
*/
|
|
138
141
|
memories = [];
|
|
139
|
-
afs;
|
|
140
142
|
asyncMemoryRecord;
|
|
141
|
-
tag;
|
|
142
143
|
/**
|
|
143
144
|
* Maximum number of memory items to retrieve
|
|
144
145
|
*/
|
|
@@ -283,7 +284,6 @@ export class Agent {
|
|
|
283
284
|
* agentSucceed, or agentFailed
|
|
284
285
|
*/
|
|
285
286
|
disableEvents;
|
|
286
|
-
historyConfig;
|
|
287
287
|
subscriptions = [];
|
|
288
288
|
/**
|
|
289
289
|
* Attach agent to context:
|
|
@@ -414,11 +414,15 @@ export class Agent {
|
|
|
414
414
|
: isAsyncGenerator(response)
|
|
415
415
|
? asyncGeneratorToReadableStream(response)
|
|
416
416
|
: objectToAgentResponseStream(response);
|
|
417
|
+
const messages = [];
|
|
417
418
|
for await (const chunk of stream) {
|
|
418
419
|
mergeAgentResponseChunk(output, chunk);
|
|
419
420
|
yield chunk;
|
|
421
|
+
if (isAgentResponseProgress(chunk) && chunk.progress.event === "message") {
|
|
422
|
+
messages.push(chunk.progress.message);
|
|
423
|
+
}
|
|
420
424
|
}
|
|
421
|
-
let result = await this.processAgentOutput(input, output, options);
|
|
425
|
+
let result = await this.processAgentOutput(input, output, { ...options, messages });
|
|
422
426
|
if (attempt > 0) {
|
|
423
427
|
result = { ...result, $meta: { ...result.$meta, retries: attempt } };
|
|
424
428
|
}
|
|
@@ -503,6 +507,7 @@ export class Agent {
|
|
|
503
507
|
...options,
|
|
504
508
|
model: this.model || options.model,
|
|
505
509
|
imageModel: this.imageModel || options.imageModel,
|
|
510
|
+
caller: this,
|
|
506
511
|
});
|
|
507
512
|
});
|
|
508
513
|
/**
|
|
@@ -515,7 +520,7 @@ export class Agent {
|
|
|
515
520
|
* @param options Invocation options
|
|
516
521
|
* @returns Final processed output
|
|
517
522
|
*/
|
|
518
|
-
async processAgentOutput(input, output, options) {
|
|
523
|
+
async processAgentOutput(input, output, { messages, ...options }) {
|
|
519
524
|
const { context } = options;
|
|
520
525
|
if (!isRecord(output)) {
|
|
521
526
|
throw new Error(`expect to return a record type such as {result: ...}, but got (${typeof output}): ${output}`);
|
|
@@ -527,8 +532,14 @@ export class Agent {
|
|
|
527
532
|
const o = await this.callHooks(["onSuccess", "onEnd"], { input, output: finalOutput }, options);
|
|
528
533
|
if (o?.output)
|
|
529
534
|
finalOutput = o.output;
|
|
530
|
-
|
|
531
|
-
this.
|
|
535
|
+
this.afs?.emit("agentSucceed", {
|
|
536
|
+
agentId: this.name,
|
|
537
|
+
userId: context.userContext.userId,
|
|
538
|
+
sessionId: context.userContext.sessionId,
|
|
539
|
+
input,
|
|
540
|
+
output: finalOutput,
|
|
541
|
+
messages,
|
|
542
|
+
});
|
|
532
543
|
if (!this.disableEvents)
|
|
533
544
|
context.emit("agentSucceed", { agent: this, output: finalOutput });
|
|
534
545
|
return finalOutput;
|
|
@@ -658,6 +669,9 @@ export class Agent {
|
|
|
658
669
|
});
|
|
659
670
|
}
|
|
660
671
|
}
|
|
672
|
+
formatOutput(output) {
|
|
673
|
+
return stringify(output);
|
|
674
|
+
}
|
|
661
675
|
/**
|
|
662
676
|
* Shut down the agent and clean up resources
|
|
663
677
|
*
|
|
@@ -824,6 +838,18 @@ function checkAgentInputOutputSchema(schema) {
|
|
|
824
838
|
*/
|
|
825
839
|
export class FunctionAgent extends Agent {
|
|
826
840
|
tag = "FunctionAgent";
|
|
841
|
+
static schema() {
|
|
842
|
+
return z.object({
|
|
843
|
+
process: z.preprocess((v) => (typeof v === "string" ? codeToFunctionAgentFn(v) : v), z.custom()),
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
static async load(options) {
|
|
847
|
+
const valid = await FunctionAgent.schema().parseAsync(options.parsed);
|
|
848
|
+
return new FunctionAgent({
|
|
849
|
+
...options.parsed,
|
|
850
|
+
process: valid.process,
|
|
851
|
+
});
|
|
852
|
+
}
|
|
827
853
|
/**
|
|
828
854
|
* Create a function agent from a function or options
|
|
829
855
|
*
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { type ZodObject, type ZodType, z } from "zod";
|
|
2
|
+
import { type NestAgentSchema } from "../loader/agent-yaml.js";
|
|
3
|
+
import type { AgentLoadOptions } from "../loader/index.js";
|
|
4
|
+
import { type Instructions } from "../loader/schema.js";
|
|
5
|
+
import type { CompactConfig, SessionMemoryConfig, UserMemoryConfig } from "../prompt/agent-session.js";
|
|
2
6
|
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
3
7
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type AgentProcessResult, type Message } from "./agent.js";
|
|
4
8
|
import type { ChatModel, ChatModelInput } from "./chat-model.js";
|
|
@@ -23,8 +27,6 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
|
|
|
23
27
|
* more complex prompt templates
|
|
24
28
|
*/
|
|
25
29
|
instructions?: string | PromptBuilder;
|
|
26
|
-
autoReorderSystemMessages?: boolean;
|
|
27
|
-
autoMergeSystemMessages?: boolean;
|
|
28
30
|
/**
|
|
29
31
|
* Pick a message from input to use as the user's message
|
|
30
32
|
*/
|
|
@@ -124,6 +126,53 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
|
|
|
124
126
|
*/
|
|
125
127
|
memoryPromptTemplate?: string;
|
|
126
128
|
useMemoriesFromContext?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Agent session configuration
|
|
131
|
+
*
|
|
132
|
+
* Controls history recording, memory extraction, and conversation compaction.
|
|
133
|
+
* By default, mode is "auto" (enabled). Set `{ mode: "disabled" }` to disable
|
|
134
|
+
* for internal utility agents (extractors, compactors, etc.).
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* // Default behavior - session features enabled
|
|
139
|
+
* new AIAgent({
|
|
140
|
+
* session: {
|
|
141
|
+
* compact: { mode: "auto" },
|
|
142
|
+
* sessionMemory: { mode: "auto" },
|
|
143
|
+
* userMemory: { mode: "auto" }
|
|
144
|
+
* }
|
|
145
|
+
* })
|
|
146
|
+
*
|
|
147
|
+
* // Disable for internal utility agents
|
|
148
|
+
* new AIAgent({
|
|
149
|
+
* session: { mode: "disabled" }
|
|
150
|
+
* })
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
session?: Partial<Omit<import("../prompt/agent-session.js").AgentSessionOptions, "sessionId" | "userId" | "agentId" | "afs">>;
|
|
154
|
+
}
|
|
155
|
+
export interface AIAgentLoadSchema {
|
|
156
|
+
instructions?: Instructions;
|
|
157
|
+
inputKey?: string;
|
|
158
|
+
inputFileKey?: string;
|
|
159
|
+
outputKey?: string;
|
|
160
|
+
outputFileKey?: string;
|
|
161
|
+
toolChoice?: AIAgentToolChoice;
|
|
162
|
+
toolCallsConcurrency?: number;
|
|
163
|
+
keepTextInToolUses?: boolean;
|
|
164
|
+
session?: {
|
|
165
|
+
mode?: "auto" | "disabled";
|
|
166
|
+
compact?: Omit<CompactConfig, "compactor"> & {
|
|
167
|
+
compactor?: NestAgentSchema;
|
|
168
|
+
};
|
|
169
|
+
sessionMemory?: Omit<SessionMemoryConfig, "extractor"> & {
|
|
170
|
+
extractor?: NestAgentSchema;
|
|
171
|
+
};
|
|
172
|
+
userMemory?: Omit<UserMemoryConfig, "extractor"> & {
|
|
173
|
+
extractor?: NestAgentSchema;
|
|
174
|
+
};
|
|
175
|
+
};
|
|
127
176
|
}
|
|
128
177
|
/**
|
|
129
178
|
* Tool choice options for AI agents
|
|
@@ -188,6 +237,14 @@ export declare const aiAgentOptionsSchema: ZodObject<{
|
|
|
188
237
|
*/
|
|
189
238
|
export declare class AIAgent<I extends Message = any, O extends Message = any> extends Agent<I, O> {
|
|
190
239
|
tag: string;
|
|
240
|
+
static schema<T>({ filepath }: {
|
|
241
|
+
filepath: string;
|
|
242
|
+
}): ZodType<T>;
|
|
243
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
244
|
+
filepath: string;
|
|
245
|
+
parsed: object;
|
|
246
|
+
options?: AgentLoadOptions;
|
|
247
|
+
}): Promise<Agent<I, O>>;
|
|
191
248
|
/**
|
|
192
249
|
* Create an AIAgent with the specified options
|
|
193
250
|
*
|
|
@@ -218,8 +275,6 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
|
|
|
218
275
|
* {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-prompt-builder}
|
|
219
276
|
*/
|
|
220
277
|
instructions: PromptBuilder;
|
|
221
|
-
autoReorderSystemMessages?: boolean;
|
|
222
|
-
autoMergeSystemMessages?: boolean;
|
|
223
278
|
/**
|
|
224
279
|
* Pick a message from input to use as the user's message
|
|
225
280
|
*/
|
|
@@ -315,6 +370,10 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
|
|
|
315
370
|
metadataEnd: string;
|
|
316
371
|
parse: (raw: string) => object;
|
|
317
372
|
};
|
|
373
|
+
/**
|
|
374
|
+
* Agent session configuration
|
|
375
|
+
*/
|
|
376
|
+
session?: Partial<Omit<import("../prompt/agent-session.js").AgentSessionOptions, "sessionId" | "userId" | "agentId" | "afs">>;
|
|
318
377
|
get inputSchema(): ZodType<I>;
|
|
319
378
|
/**
|
|
320
379
|
* Process an input message and generate a response
|