@aigne/core 1.72.0-beta.6 → 1.72.0-beta.8
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 +35 -0
- package/lib/cjs/agents/agent.d.ts +23 -27
- package/lib/cjs/agents/agent.js +16 -8
- package/lib/cjs/agents/ai-agent.d.ts +20 -4
- package/lib/cjs/agents/ai-agent.js +47 -55
- package/lib/cjs/agents/chat-model.d.ts +1 -0
- package/lib/cjs/agents/image-model.d.ts +4 -4
- package/lib/cjs/agents/mcp-agent.d.ts +2 -2
- package/lib/cjs/agents/video-model.d.ts +4 -4
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/loader/index.d.ts +2 -2
- 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 +53 -0
- package/lib/cjs/prompt/agent-session.js +341 -0
- package/lib/cjs/prompt/compact/compactor.d.ts +7 -0
- package/lib/cjs/prompt/compact/compactor.js +48 -0
- package/lib/cjs/prompt/compact/types.d.ts +79 -0
- package/lib/cjs/prompt/compact/types.js +19 -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 +77 -117
- package/lib/cjs/prompt/template.d.ts +16 -16
- package/lib/dts/agents/agent.d.ts +23 -27
- package/lib/dts/agents/ai-agent.d.ts +20 -4
- package/lib/dts/agents/chat-model.d.ts +1 -0
- package/lib/dts/agents/image-model.d.ts +4 -4
- package/lib/dts/agents/mcp-agent.d.ts +2 -2
- package/lib/dts/agents/video-model.d.ts +4 -4
- package/lib/dts/index.d.ts +1 -0
- package/lib/dts/loader/index.d.ts +2 -2
- 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 +53 -0
- package/lib/dts/prompt/compact/compactor.d.ts +7 -0
- package/lib/dts/prompt/compact/types.d.ts +79 -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/template.d.ts +16 -16
- package/lib/esm/agents/agent.d.ts +23 -27
- package/lib/esm/agents/agent.js +16 -8
- package/lib/esm/agents/ai-agent.d.ts +20 -4
- package/lib/esm/agents/ai-agent.js +47 -55
- package/lib/esm/agents/chat-model.d.ts +1 -0
- package/lib/esm/agents/image-model.d.ts +4 -4
- package/lib/esm/agents/mcp-agent.d.ts +2 -2
- package/lib/esm/agents/video-model.d.ts +4 -4
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/loader/index.d.ts +2 -2
- 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 +53 -0
- package/lib/esm/prompt/agent-session.js +304 -0
- package/lib/esm/prompt/compact/compactor.d.ts +7 -0
- package/lib/esm/prompt/compact/compactor.js +44 -0
- package/lib/esm/prompt/compact/types.d.ts +79 -0
- package/lib/esm/prompt/compact/types.js +16 -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 +78 -118
- package/lib/esm/prompt/template.d.ts +16 -16
- package/package.json +4 -4
|
@@ -91,7 +91,6 @@ export declare const imageModelInputSchema: z.ZodObject<{
|
|
|
91
91
|
}, "strip", z.ZodTypeAny, {
|
|
92
92
|
prompt: string;
|
|
93
93
|
modelOptions?: Record<string, unknown> | undefined;
|
|
94
|
-
outputFileType?: "local" | "url" | "file" | undefined;
|
|
95
94
|
image?: ({
|
|
96
95
|
type: "url";
|
|
97
96
|
url: string;
|
|
@@ -109,10 +108,10 @@ export declare const imageModelInputSchema: z.ZodObject<{
|
|
|
109
108
|
mimeType?: string | undefined;
|
|
110
109
|
})[] | undefined;
|
|
111
110
|
n?: number | undefined;
|
|
111
|
+
outputFileType?: "local" | "file" | "url" | undefined;
|
|
112
112
|
}, {
|
|
113
113
|
prompt: string;
|
|
114
114
|
modelOptions?: Record<string, unknown> | undefined;
|
|
115
|
-
outputFileType?: "local" | "url" | "file" | undefined;
|
|
116
115
|
image?: ({
|
|
117
116
|
type: "url";
|
|
118
117
|
url: string;
|
|
@@ -130,6 +129,7 @@ export declare const imageModelInputSchema: z.ZodObject<{
|
|
|
130
129
|
mimeType?: string | undefined;
|
|
131
130
|
})[] | undefined;
|
|
132
131
|
n?: number | undefined;
|
|
132
|
+
outputFileType?: "local" | "file" | "url" | undefined;
|
|
133
133
|
}>;
|
|
134
134
|
export interface ImageModelOutput extends Message {
|
|
135
135
|
images: FileUnionContent[];
|
|
@@ -232,6 +232,7 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
232
232
|
filename?: string | undefined;
|
|
233
233
|
mimeType?: string | undefined;
|
|
234
234
|
})[];
|
|
235
|
+
model?: string | undefined;
|
|
235
236
|
usage?: {
|
|
236
237
|
inputTokens: number;
|
|
237
238
|
outputTokens: number;
|
|
@@ -240,7 +241,6 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
240
241
|
cacheReadInputTokens?: number | undefined;
|
|
241
242
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
242
243
|
} | undefined;
|
|
243
|
-
model?: string | undefined;
|
|
244
244
|
}, {
|
|
245
245
|
images: ({
|
|
246
246
|
type: "url";
|
|
@@ -258,6 +258,7 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
258
258
|
filename?: string | undefined;
|
|
259
259
|
mimeType?: string | undefined;
|
|
260
260
|
})[];
|
|
261
|
+
model?: string | undefined;
|
|
261
262
|
usage?: {
|
|
262
263
|
inputTokens: number;
|
|
263
264
|
outputTokens: number;
|
|
@@ -266,5 +267,4 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
266
267
|
cacheReadInputTokens?: number | undefined;
|
|
267
268
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
268
269
|
} | undefined;
|
|
269
|
-
model?: string | undefined;
|
|
270
270
|
}>;
|
|
@@ -64,12 +64,12 @@ export declare class MCPAgent extends Agent {
|
|
|
64
64
|
args: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
65
65
|
}, "strip", z.ZodTypeAny, {
|
|
66
66
|
url?: string | undefined;
|
|
67
|
-
args?: string[] | undefined;
|
|
68
67
|
command?: string | undefined;
|
|
68
|
+
args?: string[] | undefined;
|
|
69
69
|
}, {
|
|
70
70
|
url?: string | undefined;
|
|
71
|
-
args?: string[] | undefined;
|
|
72
71
|
command?: string | undefined;
|
|
72
|
+
args?: string[] | undefined;
|
|
73
73
|
}>;
|
|
74
74
|
static load<I extends Message = any, O extends Message = any>(options: {
|
|
75
75
|
filepath: string;
|
|
@@ -94,7 +94,6 @@ export declare const videoModelInputSchema: z.ZodObject<{
|
|
|
94
94
|
prompt: string;
|
|
95
95
|
model?: string | undefined;
|
|
96
96
|
modelOptions?: Record<string, unknown> | undefined;
|
|
97
|
-
outputFileType?: "local" | "url" | "file" | undefined;
|
|
98
97
|
image?: {
|
|
99
98
|
type: "url";
|
|
100
99
|
url: string;
|
|
@@ -111,13 +110,13 @@ export declare const videoModelInputSchema: z.ZodObject<{
|
|
|
111
110
|
filename?: string | undefined;
|
|
112
111
|
mimeType?: string | undefined;
|
|
113
112
|
} | undefined;
|
|
113
|
+
outputFileType?: "local" | "file" | "url" | undefined;
|
|
114
114
|
size?: string | undefined;
|
|
115
115
|
seconds?: string | undefined;
|
|
116
116
|
}, {
|
|
117
117
|
prompt: string;
|
|
118
118
|
model?: string | undefined;
|
|
119
119
|
modelOptions?: Record<string, unknown> | undefined;
|
|
120
|
-
outputFileType?: "local" | "url" | "file" | undefined;
|
|
121
120
|
image?: {
|
|
122
121
|
type: "url";
|
|
123
122
|
url: string;
|
|
@@ -134,6 +133,7 @@ export declare const videoModelInputSchema: z.ZodObject<{
|
|
|
134
133
|
filename?: string | undefined;
|
|
135
134
|
mimeType?: string | undefined;
|
|
136
135
|
} | undefined;
|
|
136
|
+
outputFileType?: "local" | "file" | "url" | undefined;
|
|
137
137
|
size?: string | undefined;
|
|
138
138
|
seconds?: string | undefined;
|
|
139
139
|
}>;
|
|
@@ -240,6 +240,7 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
240
240
|
filename?: string | undefined;
|
|
241
241
|
mimeType?: string | undefined;
|
|
242
242
|
})[];
|
|
243
|
+
model?: string | undefined;
|
|
243
244
|
usage?: {
|
|
244
245
|
inputTokens: number;
|
|
245
246
|
outputTokens: number;
|
|
@@ -248,7 +249,6 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
248
249
|
cacheReadInputTokens?: number | undefined;
|
|
249
250
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
250
251
|
} | undefined;
|
|
251
|
-
model?: string | undefined;
|
|
252
252
|
seconds?: number | undefined;
|
|
253
253
|
}, {
|
|
254
254
|
videos: ({
|
|
@@ -267,6 +267,7 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
267
267
|
filename?: string | undefined;
|
|
268
268
|
mimeType?: string | undefined;
|
|
269
269
|
})[];
|
|
270
|
+
model?: string | undefined;
|
|
270
271
|
usage?: {
|
|
271
272
|
inputTokens: number;
|
|
272
273
|
outputTokens: number;
|
|
@@ -275,6 +276,5 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
275
276
|
cacheReadInputTokens?: number | undefined;
|
|
276
277
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
277
278
|
} | undefined;
|
|
278
|
-
model?: string | undefined;
|
|
279
279
|
seconds?: number | undefined;
|
|
280
280
|
}>;
|
package/lib/dts/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./agents/user-agent.js";
|
|
|
13
13
|
export * from "./agents/video-model.js";
|
|
14
14
|
export * from "./aigne/index.js";
|
|
15
15
|
export * from "./memory/index.js";
|
|
16
|
+
export * from "./prompt/agent-session.js";
|
|
16
17
|
export * from "./prompt/prompt-builder.js";
|
|
17
18
|
export * from "./prompt/template.js";
|
|
18
19
|
export * from "./utils/json-utils.js";
|
|
@@ -137,7 +137,6 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
137
137
|
chat?: string | undefined;
|
|
138
138
|
} | undefined>;
|
|
139
139
|
}, "strip", z.ZodTypeAny, {
|
|
140
|
-
name?: string | undefined;
|
|
141
140
|
model?: z.objectInputType<{
|
|
142
141
|
model: ZodType<string | {
|
|
143
142
|
$get: string;
|
|
@@ -170,6 +169,7 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
170
169
|
$get: string;
|
|
171
170
|
} | undefined>;
|
|
172
171
|
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
172
|
+
name?: string | undefined;
|
|
173
173
|
description?: string | undefined;
|
|
174
174
|
imageModel?: z.objectInputType<{
|
|
175
175
|
model: ZodType<string | {
|
|
@@ -188,7 +188,6 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
188
188
|
chat?: string | undefined;
|
|
189
189
|
} | undefined;
|
|
190
190
|
}, {
|
|
191
|
-
name?: string | undefined;
|
|
192
191
|
model?: z.objectInputType<{
|
|
193
192
|
model: ZodType<string | {
|
|
194
193
|
$get: string;
|
|
@@ -221,6 +220,7 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
221
220
|
$get: string;
|
|
222
221
|
} | undefined>;
|
|
223
222
|
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
223
|
+
name?: string | undefined;
|
|
224
224
|
description?: string | undefined;
|
|
225
225
|
imageModel?: z.objectInputType<{
|
|
226
226
|
model: ZodType<string | {
|
|
@@ -42,24 +42,24 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
|
|
|
42
42
|
content: ZodType<{}, z.ZodTypeDef, {}>;
|
|
43
43
|
createdAt: z.ZodString;
|
|
44
44
|
}, "strip", z.ZodTypeAny, {
|
|
45
|
-
content: {};
|
|
46
45
|
id: string;
|
|
46
|
+
content: {};
|
|
47
47
|
createdAt: string;
|
|
48
48
|
}, {
|
|
49
|
-
content: {};
|
|
50
49
|
id: string;
|
|
50
|
+
content: {};
|
|
51
51
|
createdAt: string;
|
|
52
52
|
}>, "many">;
|
|
53
53
|
}, "strip", z.ZodTypeAny, {
|
|
54
54
|
memories: {
|
|
55
|
-
content: {};
|
|
56
55
|
id: string;
|
|
56
|
+
content: {};
|
|
57
57
|
createdAt: string;
|
|
58
58
|
}[];
|
|
59
59
|
}, {
|
|
60
60
|
memories: {
|
|
61
|
-
content: {};
|
|
62
61
|
id: string;
|
|
62
|
+
content: {};
|
|
63
63
|
createdAt: string;
|
|
64
64
|
}[];
|
|
65
65
|
}>;
|
|
@@ -55,24 +55,24 @@ export declare const memoryRetrieverOutputSchema: z.ZodObject<{
|
|
|
55
55
|
content: z.ZodType<{}, z.ZodTypeDef, {}>;
|
|
56
56
|
createdAt: z.ZodString;
|
|
57
57
|
}, "strip", z.ZodTypeAny, {
|
|
58
|
-
content: {};
|
|
59
58
|
id: string;
|
|
59
|
+
content: {};
|
|
60
60
|
createdAt: string;
|
|
61
61
|
}, {
|
|
62
|
-
content: {};
|
|
63
62
|
id: string;
|
|
63
|
+
content: {};
|
|
64
64
|
createdAt: string;
|
|
65
65
|
}>, "many">;
|
|
66
66
|
}, "strip", z.ZodTypeAny, {
|
|
67
67
|
memories: {
|
|
68
|
-
content: {};
|
|
69
68
|
id: string;
|
|
69
|
+
content: {};
|
|
70
70
|
createdAt: string;
|
|
71
71
|
}[];
|
|
72
72
|
}, {
|
|
73
73
|
memories: {
|
|
74
|
-
content: {};
|
|
75
74
|
id: string;
|
|
75
|
+
content: {};
|
|
76
76
|
createdAt: string;
|
|
77
77
|
}[];
|
|
78
78
|
}>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AFS } from "@aigne/afs";
|
|
2
|
+
import type { AgentInvokeOptions } from "../agents/agent.js";
|
|
3
|
+
import type { ChatModelInputMessage } from "../agents/chat-model.js";
|
|
4
|
+
import { type CompactConfig, type CompactContent, type EntryContent } from "./compact/types.js";
|
|
5
|
+
export type { CompactConfig, CompactContent, EntryContent };
|
|
6
|
+
export interface AgentSessionOptions {
|
|
7
|
+
sessionId: string;
|
|
8
|
+
userId?: string;
|
|
9
|
+
agentId?: string;
|
|
10
|
+
afs?: AFS;
|
|
11
|
+
/**
|
|
12
|
+
* Compaction configuration
|
|
13
|
+
*/
|
|
14
|
+
compact?: CompactConfig;
|
|
15
|
+
}
|
|
16
|
+
export declare class AgentSession {
|
|
17
|
+
readonly sessionId: string;
|
|
18
|
+
readonly userId?: string;
|
|
19
|
+
readonly agentId?: string;
|
|
20
|
+
private afs?;
|
|
21
|
+
private historyModulePath?;
|
|
22
|
+
private compactConfig;
|
|
23
|
+
private runtimeState;
|
|
24
|
+
private initialized?;
|
|
25
|
+
private compactionPromise?;
|
|
26
|
+
constructor(options: AgentSessionOptions);
|
|
27
|
+
setSystemMessages(...messages: ChatModelInputMessage[]): Promise<void>;
|
|
28
|
+
getMessages(): Promise<ChatModelInputMessage[]>;
|
|
29
|
+
startMessage(input: unknown, message: ChatModelInputMessage, options: AgentInvokeOptions): Promise<void>;
|
|
30
|
+
endMessage(output: unknown, options: AgentInvokeOptions): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Manually trigger compaction
|
|
33
|
+
*/
|
|
34
|
+
compact(options: AgentInvokeOptions): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Internal method that performs the actual compaction
|
|
37
|
+
*/
|
|
38
|
+
private doCompact;
|
|
39
|
+
private maybeAutoCompact;
|
|
40
|
+
/**
|
|
41
|
+
* Estimate token count for an array of messages
|
|
42
|
+
*/
|
|
43
|
+
private estimateMessagesTokens;
|
|
44
|
+
/**
|
|
45
|
+
* Split entries into batches based on token limit
|
|
46
|
+
* Each batch will not exceed the specified maxTokens
|
|
47
|
+
*/
|
|
48
|
+
private splitIntoBatches;
|
|
49
|
+
appendCurrentMessages(...messages: ChatModelInputMessage[]): Promise<void>;
|
|
50
|
+
private ensureInitialized;
|
|
51
|
+
private initialize;
|
|
52
|
+
private initializeDefaultCompactor;
|
|
53
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AIAgent, type AIAgentOptions } from "../../agents/ai-agent.js";
|
|
2
|
+
import type { CompactContent, CompactorInput } from "./types.js";
|
|
3
|
+
export interface CreateCompactorOptions extends AIAgentOptions<CompactorInput, CompactContent> {
|
|
4
|
+
}
|
|
5
|
+
export declare class AISessionCompactor extends AIAgent<CompactorInput, CompactContent> {
|
|
6
|
+
constructor(options?: CreateCompactorOptions);
|
|
7
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Agent, Message } from "../../agents/agent.js";
|
|
2
|
+
import type { ChatModelInputMessage } from "../../agents/chat-model.js";
|
|
3
|
+
/**
|
|
4
|
+
* Default compaction mode
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_COMPACT_MODE: "auto";
|
|
7
|
+
/**
|
|
8
|
+
* Default maximum tokens before triggering compaction
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_MAX_TOKENS = 80000;
|
|
11
|
+
/**
|
|
12
|
+
* Default ratio of maxTokens to reserve for keeping recent messages
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEFAULT_KEEP_RECENT_RATIO = 0.5;
|
|
15
|
+
/**
|
|
16
|
+
* Default async mode for compaction
|
|
17
|
+
*/
|
|
18
|
+
export declare const DEFAULT_COMPACT_ASYNC = true;
|
|
19
|
+
/**
|
|
20
|
+
* Content structure for history entries
|
|
21
|
+
*/
|
|
22
|
+
export interface EntryContent {
|
|
23
|
+
input?: unknown;
|
|
24
|
+
output?: unknown;
|
|
25
|
+
messages?: ChatModelInputMessage[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Output structure from the compactor agent
|
|
29
|
+
*/
|
|
30
|
+
export interface CompactContent extends Message {
|
|
31
|
+
summary: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Input structure for the compactor agent
|
|
35
|
+
*/
|
|
36
|
+
export interface CompactorInput extends Message {
|
|
37
|
+
previousSummary?: string[];
|
|
38
|
+
messages: ChatModelInputMessage[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Type alias for a compactor agent
|
|
42
|
+
*/
|
|
43
|
+
export type Compactor = Agent<CompactorInput, CompactContent>;
|
|
44
|
+
/**
|
|
45
|
+
* Configuration for session compaction
|
|
46
|
+
*/
|
|
47
|
+
export interface CompactConfig {
|
|
48
|
+
/**
|
|
49
|
+
* Compaction mode
|
|
50
|
+
* @default DEFAULT_COMPACT_MODE ("auto")
|
|
51
|
+
*/
|
|
52
|
+
mode?: "auto" | "disabled";
|
|
53
|
+
/**
|
|
54
|
+
* Maximum tokens before triggering compaction
|
|
55
|
+
* @default DEFAULT_MAX_TOKENS (80000)
|
|
56
|
+
*/
|
|
57
|
+
maxTokens?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Ratio of maxTokens to reserve for keeping recent messages (0-1)
|
|
60
|
+
*
|
|
61
|
+
* Defines what portion of maxTokens budget should be allocated for
|
|
62
|
+
* preserving recent conversation history without compaction.
|
|
63
|
+
*
|
|
64
|
+
* @default 0.5 (50% of maxTokens)
|
|
65
|
+
* @example 0.5 means if maxTokens=80000, keep up to 40000 tokens of recent messages
|
|
66
|
+
*/
|
|
67
|
+
keepRecentRatio?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Whether to perform compaction asynchronously
|
|
70
|
+
* @default DEFAULT_COMPACT_ASYNC (true)
|
|
71
|
+
*/
|
|
72
|
+
async?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Agent that generates summaries from conversation entries
|
|
75
|
+
* Input: { entries: EntryContent[] }
|
|
76
|
+
* Output: { summary: string }
|
|
77
|
+
*/
|
|
78
|
+
compactor?: Compactor;
|
|
79
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import type { AFSListOptions } from "@aigne/afs";
|
|
1
2
|
import type { Agent } from "../../../agents/agent.js";
|
|
2
|
-
export declare function getHistories(agent
|
|
3
|
+
export declare function getHistories({ filter, agent, }: {
|
|
4
|
+
filter: AFSListOptions["filter"];
|
|
5
|
+
agent: Agent;
|
|
6
|
+
}): Promise<{
|
|
3
7
|
role: "user" | "agent";
|
|
4
8
|
content: unknown;
|
|
5
9
|
}[]>;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import type { GetPromptResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
import { Agent, type
|
|
2
|
+
import { Agent, type Message } from "../agents/agent.js";
|
|
3
3
|
import { type AIAgent } from "../agents/ai-agent.js";
|
|
4
|
-
import type { ChatModel, ChatModelInput } from "../agents/chat-model.js";
|
|
4
|
+
import type { ChatModel, ChatModelInput, ChatModelInputMessage } from "../agents/chat-model.js";
|
|
5
5
|
import { type FileUnionContent } from "../agents/model.js";
|
|
6
|
+
import type { Context } from "../aigne/context.js";
|
|
7
|
+
import { AgentSession } from "./agent-session.js";
|
|
6
8
|
import { ChatMessagesTemplate } from "./template.js";
|
|
7
9
|
export interface PromptBuilderOptions {
|
|
8
10
|
instructions?: string | ChatMessagesTemplate;
|
|
9
11
|
workingDir?: string;
|
|
10
12
|
}
|
|
11
|
-
export interface PromptBuildOptions
|
|
13
|
+
export interface PromptBuildOptions {
|
|
14
|
+
context?: Context;
|
|
12
15
|
agent?: AIAgent;
|
|
13
16
|
input?: Message;
|
|
14
17
|
model?: ChatModel;
|
|
@@ -26,7 +29,9 @@ export declare class PromptBuilder {
|
|
|
26
29
|
instructions?: string | ChatMessagesTemplate;
|
|
27
30
|
workingDir?: string;
|
|
28
31
|
copy(): PromptBuilder;
|
|
29
|
-
build(options: PromptBuildOptions): Promise<ChatModelInput & {
|
|
32
|
+
build(options: PromptBuildOptions): Promise<Omit<ChatModelInput, "messages"> & {
|
|
33
|
+
session: AgentSession;
|
|
34
|
+
userMessage: ChatModelInputMessage;
|
|
30
35
|
toolAgents?: Agent[];
|
|
31
36
|
}>;
|
|
32
37
|
buildPrompt(options: Pick<PromptBuildOptions, "input" | "context"> & {
|
|
@@ -37,11 +42,8 @@ export declare class PromptBuilder {
|
|
|
37
42
|
}>;
|
|
38
43
|
private getTemplateVariables;
|
|
39
44
|
private buildMessages;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
content: unknown;
|
|
43
|
-
}[]>;
|
|
44
|
-
private refineMessages;
|
|
45
|
+
private mergeMessages;
|
|
46
|
+
protected deprecatedMemories(message: string | undefined, options: PromptBuildOptions): Promise<ChatModelInputMessage[]>;
|
|
45
47
|
private convertMemoriesToMessages;
|
|
46
48
|
private buildResponseFormat;
|
|
47
49
|
private buildTools;
|
|
@@ -42,7 +42,7 @@ export declare class AgentMessageTemplate extends ChatMessageTemplate {
|
|
|
42
42
|
static from(template?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[], name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): AgentMessageTemplate;
|
|
43
43
|
constructor(content?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[] | undefined, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]);
|
|
44
44
|
format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
|
|
45
|
-
role: "
|
|
45
|
+
role: "agent" | "user" | "system" | "tool";
|
|
46
46
|
name: string | undefined;
|
|
47
47
|
content: ChatModelInputMessageContent | undefined;
|
|
48
48
|
toolCalls: ChatModelOutputToolCall[] | undefined;
|
|
@@ -54,7 +54,7 @@ export declare class ToolMessageTemplate extends ChatMessageTemplate {
|
|
|
54
54
|
static from(content: object | string, toolCallId: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): ToolMessageTemplate;
|
|
55
55
|
constructor(content: object | string, toolCallId: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]);
|
|
56
56
|
format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
|
|
57
|
-
role: "
|
|
57
|
+
role: "agent" | "user" | "system" | "tool";
|
|
58
58
|
name: string | undefined;
|
|
59
59
|
content: ChatModelInputMessageContent | undefined;
|
|
60
60
|
toolCallId: string;
|
|
@@ -83,21 +83,21 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
83
83
|
ttl?: "5m" | "1h" | undefined;
|
|
84
84
|
}>>;
|
|
85
85
|
}, "strip", z.ZodTypeAny, {
|
|
86
|
-
content: string;
|
|
87
86
|
role: "system";
|
|
87
|
+
content: string;
|
|
88
|
+
name?: string | undefined;
|
|
88
89
|
cacheControl?: {
|
|
89
90
|
type: "ephemeral";
|
|
90
91
|
ttl?: "5m" | "1h" | undefined;
|
|
91
92
|
} | undefined;
|
|
92
|
-
name?: string | undefined;
|
|
93
93
|
}, {
|
|
94
|
-
content: string;
|
|
95
94
|
role: "system";
|
|
95
|
+
content: string;
|
|
96
|
+
name?: string | undefined;
|
|
96
97
|
cacheControl?: {
|
|
97
98
|
type: "ephemeral";
|
|
98
99
|
ttl?: "5m" | "1h" | undefined;
|
|
99
100
|
} | undefined;
|
|
100
|
-
name?: string | undefined;
|
|
101
101
|
}>, z.ZodObject<{
|
|
102
102
|
role: z.ZodLiteral<"user">;
|
|
103
103
|
content: z.ZodString;
|
|
@@ -113,21 +113,21 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
113
113
|
ttl?: "5m" | "1h" | undefined;
|
|
114
114
|
}>>;
|
|
115
115
|
}, "strip", z.ZodTypeAny, {
|
|
116
|
-
content: string;
|
|
117
116
|
role: "user";
|
|
117
|
+
content: string;
|
|
118
|
+
name?: string | undefined;
|
|
118
119
|
cacheControl?: {
|
|
119
120
|
type: "ephemeral";
|
|
120
121
|
ttl?: "5m" | "1h" | undefined;
|
|
121
122
|
} | undefined;
|
|
122
|
-
name?: string | undefined;
|
|
123
123
|
}, {
|
|
124
|
-
content: string;
|
|
125
124
|
role: "user";
|
|
125
|
+
content: string;
|
|
126
|
+
name?: string | undefined;
|
|
126
127
|
cacheControl?: {
|
|
127
128
|
type: "ephemeral";
|
|
128
129
|
ttl?: "5m" | "1h" | undefined;
|
|
129
130
|
} | undefined;
|
|
130
|
-
name?: string | undefined;
|
|
131
131
|
}>, z.ZodObject<{
|
|
132
132
|
role: z.ZodLiteral<"agent">;
|
|
133
133
|
content: z.ZodOptional<z.ZodString>;
|
|
@@ -172,6 +172,7 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
172
172
|
}>>;
|
|
173
173
|
}, "strip", z.ZodTypeAny, {
|
|
174
174
|
role: "agent";
|
|
175
|
+
name?: string | undefined;
|
|
175
176
|
content?: string | undefined;
|
|
176
177
|
cacheControl?: {
|
|
177
178
|
type: "ephemeral";
|
|
@@ -185,9 +186,9 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
185
186
|
type: "function";
|
|
186
187
|
id: string;
|
|
187
188
|
}[] | undefined;
|
|
188
|
-
name?: string | undefined;
|
|
189
189
|
}, {
|
|
190
190
|
role: "agent";
|
|
191
|
+
name?: string | undefined;
|
|
191
192
|
content?: string | undefined;
|
|
192
193
|
cacheControl?: {
|
|
193
194
|
type: "ephemeral";
|
|
@@ -201,7 +202,6 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
201
202
|
type: "function";
|
|
202
203
|
id: string;
|
|
203
204
|
}[] | undefined;
|
|
204
|
-
name?: string | undefined;
|
|
205
205
|
}>, z.ZodObject<{
|
|
206
206
|
role: z.ZodLiteral<"tool">;
|
|
207
207
|
content: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>, string, string | Record<string, unknown>>;
|
|
@@ -218,23 +218,23 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
218
218
|
ttl?: "5m" | "1h" | undefined;
|
|
219
219
|
}>>;
|
|
220
220
|
}, "strip", z.ZodTypeAny, {
|
|
221
|
-
content: string;
|
|
222
221
|
role: "tool";
|
|
222
|
+
content: string;
|
|
223
223
|
toolCallId: string;
|
|
224
|
+
name?: string | undefined;
|
|
224
225
|
cacheControl?: {
|
|
225
226
|
type: "ephemeral";
|
|
226
227
|
ttl?: "5m" | "1h" | undefined;
|
|
227
228
|
} | undefined;
|
|
228
|
-
name?: string | undefined;
|
|
229
229
|
}, {
|
|
230
|
-
content: string | Record<string, unknown>;
|
|
231
230
|
role: "tool";
|
|
231
|
+
content: string | Record<string, unknown>;
|
|
232
232
|
toolCallId: string;
|
|
233
|
+
name?: string | undefined;
|
|
233
234
|
cacheControl?: {
|
|
234
235
|
type: "ephemeral";
|
|
235
236
|
ttl?: "5m" | "1h" | undefined;
|
|
236
237
|
} | undefined;
|
|
237
|
-
name?: string | undefined;
|
|
238
238
|
}>]>;
|
|
239
239
|
export declare function safeParseChatMessages(messages: unknown): ChatMessageTemplate[] | undefined;
|
|
240
240
|
export declare function parseChatMessages(messages: (z.infer<typeof chatMessageSchema> & {
|
|
@@ -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
|
*/
|
|
@@ -211,15 +210,15 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
211
210
|
parsed: object;
|
|
212
211
|
}): Promise<Agent<I, O>>;
|
|
213
212
|
constructor(options?: AgentOptions<I, O>);
|
|
213
|
+
afs?: AFS;
|
|
214
|
+
tag?: string;
|
|
214
215
|
/**
|
|
215
216
|
* List of memories this agent can use
|
|
216
217
|
*
|
|
217
218
|
* @deprecated use afs instead
|
|
218
219
|
*/
|
|
219
220
|
readonly memories: MemoryAgent[];
|
|
220
|
-
afs?: AFS;
|
|
221
221
|
asyncMemoryRecord?: boolean;
|
|
222
|
-
tag?: string;
|
|
223
222
|
/**
|
|
224
223
|
* Maximum number of memory items to retrieve
|
|
225
224
|
*/
|
|
@@ -349,11 +348,6 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
349
348
|
* agentSucceed, or agentFailed
|
|
350
349
|
*/
|
|
351
350
|
private disableEvents?;
|
|
352
|
-
historyConfig?: {
|
|
353
|
-
disabled?: boolean;
|
|
354
|
-
maxTokens?: number;
|
|
355
|
-
maxItems?: number;
|
|
356
|
-
};
|
|
357
351
|
private subscriptions;
|
|
358
352
|
/**
|
|
359
353
|
* Attach agent to context:
|
|
@@ -455,7 +449,9 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
455
449
|
* @param options Invocation options
|
|
456
450
|
* @returns Final processed output
|
|
457
451
|
*/
|
|
458
|
-
protected processAgentOutput(input: I, output: Exclude<AgentResponse<O>, AgentResponseStream<O>>, options: AgentInvokeOptions
|
|
452
|
+
protected processAgentOutput(input: I, output: Exclude<AgentResponse<O>, AgentResponseStream<O>>, { messages, ...options }: AgentInvokeOptions & {
|
|
453
|
+
messages?: ChatModelInputMessage[];
|
|
454
|
+
}): Promise<O>;
|
|
459
455
|
/**
|
|
460
456
|
* Process errors that occur during agent execution
|
|
461
457
|
*
|
|
@@ -785,29 +781,29 @@ export interface AgentResponseProgress {
|
|
|
785
781
|
error: Error;
|
|
786
782
|
} | {
|
|
787
783
|
event: "message";
|
|
788
|
-
|
|
789
|
-
message: ({
|
|
790
|
-
type: "text";
|
|
791
|
-
content: string;
|
|
792
|
-
} | {
|
|
793
|
-
type: "thinking";
|
|
794
|
-
thoughts: string;
|
|
795
|
-
} | {
|
|
796
|
-
type: "tool_use";
|
|
797
|
-
toolUseId: string;
|
|
798
|
-
name: string;
|
|
799
|
-
input: unknown;
|
|
800
|
-
} | {
|
|
801
|
-
type: "tool_result";
|
|
802
|
-
toolUseId: string;
|
|
803
|
-
content: unknown;
|
|
804
|
-
})[];
|
|
784
|
+
message: ChatModelInputMessage;
|
|
805
785
|
}) & Omit<AgentEvent, "agent"> & {
|
|
806
786
|
agent: {
|
|
807
787
|
name: string;
|
|
808
788
|
};
|
|
809
789
|
};
|
|
810
790
|
}
|
|
791
|
+
export type AgentResponseProgressMessageItem = {
|
|
792
|
+
type: "text";
|
|
793
|
+
content: string;
|
|
794
|
+
} | {
|
|
795
|
+
type: "thinking";
|
|
796
|
+
thoughts: string;
|
|
797
|
+
} | {
|
|
798
|
+
type: "tool_use";
|
|
799
|
+
toolUseId: string;
|
|
800
|
+
name: string;
|
|
801
|
+
input: unknown;
|
|
802
|
+
} | {
|
|
803
|
+
type: "tool_result";
|
|
804
|
+
toolUseId: string;
|
|
805
|
+
content: unknown;
|
|
806
|
+
};
|
|
811
807
|
export declare function isAgentResponseProgress<T>(chunk: AgentResponseChunk<T>): chunk is AgentResponseProgress;
|
|
812
808
|
/**
|
|
813
809
|
* Creates a text delta for streaming responses
|