@aigne/core 1.71.0 → 1.72.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +158 -0
- package/lib/cjs/agents/agent.d.ts +42 -29
- package/lib/cjs/agents/agent.js +32 -11
- package/lib/cjs/agents/ai-agent.d.ts +63 -4
- package/lib/cjs/agents/ai-agent.js +148 -20
- package/lib/cjs/agents/chat-model.d.ts +162 -0
- package/lib/cjs/agents/chat-model.js +56 -5
- 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 +17 -2
- package/lib/cjs/agents/image-model.js +2 -0
- package/lib/cjs/agents/mcp-agent.d.ts +17 -0
- package/lib/cjs/agents/mcp-agent.js +18 -0
- 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 +15 -0
- package/lib/cjs/agents/video-model.js +2 -0
- package/lib/cjs/aigne/usage.d.ts +5 -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 +27 -64
- package/lib/cjs/loader/agent-yaml.js +22 -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 +46 -82
- 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 +135 -0
- package/lib/cjs/prompt/agent-session.js +889 -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/session-memory-extractor.d.ts +7 -0
- package/lib/cjs/prompt/compact/session-memory-extractor.js +139 -0
- package/lib/cjs/prompt/compact/types.d.ts +329 -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 +120 -0
- package/lib/cjs/prompt/context/afs/history.d.ts +9 -0
- package/lib/cjs/prompt/context/afs/history.js +33 -0
- package/lib/cjs/prompt/context/afs/index.d.ts +20 -0
- package/lib/cjs/prompt/context/afs/index.js +54 -0
- package/lib/cjs/prompt/context/index.d.ts +31 -0
- package/lib/cjs/prompt/context/index.js +18 -0
- package/lib/cjs/prompt/prompt-builder.d.ts +11 -9
- package/lib/cjs/prompt/prompt-builder.js +81 -151
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +18 -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 +13 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +62 -0
- package/lib/cjs/prompt/skills/afs/base.d.ts +4 -0
- package/lib/cjs/prompt/skills/afs/base.js +8 -0
- package/lib/cjs/prompt/skills/afs/delete.d.ts +3 -2
- package/lib/cjs/prompt/skills/afs/delete.js +17 -5
- package/lib/cjs/prompt/skills/afs/edit.d.ts +9 -11
- package/lib/cjs/prompt/skills/afs/edit.js +89 -63
- package/lib/cjs/prompt/skills/afs/exec.d.ts +4 -3
- package/lib/cjs/prompt/skills/afs/exec.js +23 -7
- package/lib/cjs/prompt/skills/afs/index.js +4 -1
- package/lib/cjs/prompt/skills/afs/list.d.ts +4 -4
- package/lib/cjs/prompt/skills/afs/list.js +38 -55
- package/lib/cjs/prompt/skills/afs/read.d.ts +10 -5
- package/lib/cjs/prompt/skills/afs/read.js +66 -19
- package/lib/cjs/prompt/skills/afs/rename.d.ts +3 -2
- package/lib/cjs/prompt/skills/afs/rename.js +20 -6
- package/lib/cjs/prompt/skills/afs/search.d.ts +4 -3
- package/lib/cjs/prompt/skills/afs/search.js +24 -8
- package/lib/cjs/prompt/skills/afs/write.d.ts +3 -2
- package/lib/cjs/prompt/skills/afs/write.js +22 -8
- package/lib/cjs/prompt/template.d.ts +84 -9
- package/lib/cjs/prompt/template.js +46 -17
- package/lib/dts/agents/agent.d.ts +42 -29
- package/lib/dts/agents/ai-agent.d.ts +63 -4
- package/lib/dts/agents/chat-model.d.ts +162 -0
- package/lib/dts/agents/image-agent.d.ts +17 -1
- package/lib/dts/agents/image-model.d.ts +17 -2
- package/lib/dts/agents/mcp-agent.d.ts +17 -0
- 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 +15 -0
- package/lib/dts/aigne/context.d.ts +2 -2
- package/lib/dts/aigne/usage.d.ts +5 -0
- package/lib/dts/index.d.ts +1 -0
- package/lib/dts/loader/agent-yaml.d.ts +27 -64
- 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 +135 -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 +329 -0
- package/lib/dts/prompt/compact/user-memory-extractor.d.ts +7 -0
- package/lib/dts/prompt/context/afs/history.d.ts +9 -0
- package/lib/dts/prompt/context/afs/index.d.ts +20 -0
- package/lib/dts/prompt/context/index.d.ts +31 -0
- package/lib/dts/prompt/prompt-builder.d.ts +11 -9
- package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +18 -0
- package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
- package/lib/dts/prompt/skills/afs/base.d.ts +4 -0
- package/lib/dts/prompt/skills/afs/delete.d.ts +3 -2
- package/lib/dts/prompt/skills/afs/edit.d.ts +9 -11
- package/lib/dts/prompt/skills/afs/exec.d.ts +4 -3
- package/lib/dts/prompt/skills/afs/list.d.ts +4 -4
- package/lib/dts/prompt/skills/afs/read.d.ts +10 -5
- package/lib/dts/prompt/skills/afs/rename.d.ts +3 -2
- package/lib/dts/prompt/skills/afs/search.d.ts +4 -3
- package/lib/dts/prompt/skills/afs/write.d.ts +3 -2
- package/lib/dts/prompt/template.d.ts +84 -9
- package/lib/esm/agents/agent.d.ts +42 -29
- package/lib/esm/agents/agent.js +32 -11
- package/lib/esm/agents/ai-agent.d.ts +63 -4
- package/lib/esm/agents/ai-agent.js +148 -20
- package/lib/esm/agents/chat-model.d.ts +162 -0
- package/lib/esm/agents/chat-model.js +55 -4
- 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 +17 -2
- package/lib/esm/agents/image-model.js +2 -0
- package/lib/esm/agents/mcp-agent.d.ts +17 -0
- package/lib/esm/agents/mcp-agent.js +18 -0
- 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 +15 -0
- package/lib/esm/agents/video-model.js +2 -0
- package/lib/esm/aigne/context.d.ts +2 -2
- package/lib/esm/aigne/usage.d.ts +5 -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 +27 -64
- package/lib/esm/loader/agent-yaml.js +22 -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 +47 -82
- 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 +135 -0
- package/lib/esm/prompt/agent-session.js +849 -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/session-memory-extractor.d.ts +7 -0
- package/lib/esm/prompt/compact/session-memory-extractor.js +135 -0
- package/lib/esm/prompt/compact/types.d.ts +329 -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 +116 -0
- package/lib/esm/prompt/context/afs/history.d.ts +9 -0
- package/lib/esm/prompt/context/afs/history.js +30 -0
- package/lib/esm/prompt/context/afs/index.d.ts +20 -0
- package/lib/esm/prompt/context/afs/index.js +51 -0
- package/lib/esm/prompt/context/index.d.ts +31 -0
- package/lib/esm/prompt/context/index.js +15 -0
- package/lib/esm/prompt/prompt-builder.d.ts +11 -9
- package/lib/esm/prompt/prompt-builder.js +80 -150
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +18 -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 +13 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +54 -0
- package/lib/esm/prompt/skills/afs/base.d.ts +4 -0
- package/lib/esm/prompt/skills/afs/base.js +4 -0
- package/lib/esm/prompt/skills/afs/delete.d.ts +3 -2
- package/lib/esm/prompt/skills/afs/delete.js +17 -5
- package/lib/esm/prompt/skills/afs/edit.d.ts +9 -11
- package/lib/esm/prompt/skills/afs/edit.js +89 -63
- package/lib/esm/prompt/skills/afs/exec.d.ts +4 -3
- package/lib/esm/prompt/skills/afs/exec.js +23 -7
- package/lib/esm/prompt/skills/afs/index.js +4 -1
- package/lib/esm/prompt/skills/afs/list.d.ts +4 -4
- package/lib/esm/prompt/skills/afs/list.js +38 -55
- package/lib/esm/prompt/skills/afs/read.d.ts +10 -5
- package/lib/esm/prompt/skills/afs/read.js +66 -19
- package/lib/esm/prompt/skills/afs/rename.d.ts +3 -2
- package/lib/esm/prompt/skills/afs/rename.js +20 -6
- package/lib/esm/prompt/skills/afs/search.d.ts +4 -3
- package/lib/esm/prompt/skills/afs/search.js +24 -8
- package/lib/esm/prompt/skills/afs/write.d.ts +3 -2
- package/lib/esm/prompt/skills/afs/write.js +22 -8
- package/lib/esm/prompt/template.d.ts +84 -9
- package/lib/esm/prompt/template.js +46 -17
- package/package.json +6 -5
|
@@ -5,9 +5,8 @@ import type { ChatModel } from "../agents/chat-model.js";
|
|
|
5
5
|
import type { ImageModel } from "../agents/image-model.js";
|
|
6
6
|
import type { AIGNEOptions } from "../aigne/aigne.js";
|
|
7
7
|
import type { MemoryAgent, MemoryAgentOptions } from "../memory/memory.js";
|
|
8
|
-
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
9
8
|
import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
10
|
-
import {
|
|
9
|
+
import { loadAgentFromYamlFile, type NestAgentSchema } from "./agent-yaml.js";
|
|
11
10
|
export interface LoadOptions {
|
|
12
11
|
memories?: {
|
|
13
12
|
new (parameters?: MemoryAgentOptions): MemoryAgent;
|
|
@@ -19,7 +18,10 @@ export interface LoadOptions {
|
|
|
19
18
|
availableModules?: {
|
|
20
19
|
module: string;
|
|
21
20
|
alias?: string[];
|
|
22
|
-
|
|
21
|
+
load: (options: {
|
|
22
|
+
filepath: string;
|
|
23
|
+
parsed?: object;
|
|
24
|
+
}) => PromiseOrValue<AFSModule>;
|
|
23
25
|
}[];
|
|
24
26
|
};
|
|
25
27
|
aigne?: z.infer<typeof aigneFileSchema>;
|
|
@@ -27,6 +29,9 @@ export interface LoadOptions {
|
|
|
27
29
|
parent?: string;
|
|
28
30
|
}) => Promise<any>;
|
|
29
31
|
}
|
|
32
|
+
export interface AgentLoadOptions extends LoadOptions {
|
|
33
|
+
loadNestAgent: (path: string, agent: NestAgentSchema, options: LoadOptions, agentOptions?: AgentOptions<any, any> & Record<string, unknown>) => Promise<Agent>;
|
|
34
|
+
}
|
|
30
35
|
export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
|
|
31
36
|
export declare function loadAgent(path: string, options: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
32
37
|
export declare function loadNestAgent(path: string, agent: NestAgentSchema, options: LoadOptions, agentOptions?: AgentOptions<any, any> & Record<string, unknown>): Promise<Agent>;
|
|
@@ -67,9 +72,9 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
67
72
|
} | undefined, z.ZodTypeDef, number | {
|
|
68
73
|
$get: string;
|
|
69
74
|
} | undefined>;
|
|
70
|
-
thinkingEffort: ZodType<number | "high" | "
|
|
75
|
+
thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
|
|
71
76
|
$get: string;
|
|
72
|
-
} | undefined, z.ZodTypeDef, number | "high" | "
|
|
77
|
+
} | undefined, z.ZodTypeDef, number | "high" | "low" | "medium" | "minimal" | {
|
|
73
78
|
$get: string;
|
|
74
79
|
} | undefined>;
|
|
75
80
|
}, z.ZodTypeAny, "passthrough"> | undefined, z.ZodTypeDef, z.objectInputType<{
|
|
@@ -98,9 +103,9 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
98
103
|
} | undefined, z.ZodTypeDef, number | {
|
|
99
104
|
$get: string;
|
|
100
105
|
} | undefined>;
|
|
101
|
-
thinkingEffort: ZodType<number | "high" | "
|
|
106
|
+
thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
|
|
102
107
|
$get: string;
|
|
103
|
-
} | undefined, z.ZodTypeDef, number | "high" | "
|
|
108
|
+
} | undefined, z.ZodTypeDef, number | "high" | "low" | "medium" | "minimal" | {
|
|
104
109
|
$get: string;
|
|
105
110
|
} | undefined>;
|
|
106
111
|
}, z.ZodTypeAny, "passthrough"> | undefined>;
|
|
@@ -158,9 +163,9 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
158
163
|
} | undefined, z.ZodTypeDef, number | {
|
|
159
164
|
$get: string;
|
|
160
165
|
} | undefined>;
|
|
161
|
-
thinkingEffort: ZodType<number | "high" | "
|
|
166
|
+
thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
|
|
162
167
|
$get: string;
|
|
163
|
-
} | undefined, z.ZodTypeDef, number | "high" | "
|
|
168
|
+
} | undefined, z.ZodTypeDef, number | "high" | "low" | "medium" | "minimal" | {
|
|
164
169
|
$get: string;
|
|
165
170
|
} | undefined>;
|
|
166
171
|
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
@@ -209,9 +214,9 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
209
214
|
} | undefined, z.ZodTypeDef, number | {
|
|
210
215
|
$get: string;
|
|
211
216
|
} | undefined>;
|
|
212
|
-
thinkingEffort: ZodType<number | "high" | "
|
|
217
|
+
thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
|
|
213
218
|
$get: string;
|
|
214
|
-
} | undefined, z.ZodTypeDef, number | "high" | "
|
|
219
|
+
} | undefined, z.ZodTypeDef, number | "high" | "low" | "medium" | "minimal" | {
|
|
215
220
|
$get: string;
|
|
216
221
|
} | undefined>;
|
|
217
222
|
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
@@ -239,5 +244,4 @@ export declare function loadAIGNEFile(path: string): Promise<{
|
|
|
239
244
|
rootDir: string;
|
|
240
245
|
}>;
|
|
241
246
|
export declare function findAIGNEFile(path: string): Promise<string>;
|
|
242
|
-
export declare function instructionsToPromptBuilder(instructions: Instructions): PromptBuilder;
|
|
243
247
|
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type ZodType, z } from "zod";
|
|
2
|
+
import { type Role } from "../agents/chat-model.js";
|
|
3
|
+
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
2
4
|
export declare const inputOutputSchema: ({ path }: {
|
|
3
5
|
path: string;
|
|
4
6
|
}) => z.ZodUnion<[ZodType<any, z.ZodTypeDef, any>, z.ZodEffects<z.ZodObject<{
|
|
@@ -55,9 +57,9 @@ declare const chatModelObjectSchema: z.ZodObject<{
|
|
|
55
57
|
} | undefined, z.ZodTypeDef, number | {
|
|
56
58
|
$get: string;
|
|
57
59
|
} | undefined>;
|
|
58
|
-
thinkingEffort: ZodType<number | "high" | "
|
|
60
|
+
thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
|
|
59
61
|
$get: string;
|
|
60
|
-
} | undefined, z.ZodTypeDef, number | "high" | "
|
|
62
|
+
} | undefined, z.ZodTypeDef, number | "high" | "low" | "medium" | "minimal" | {
|
|
61
63
|
$get: string;
|
|
62
64
|
} | undefined>;
|
|
63
65
|
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
@@ -86,9 +88,9 @@ declare const chatModelObjectSchema: z.ZodObject<{
|
|
|
86
88
|
} | undefined, z.ZodTypeDef, number | {
|
|
87
89
|
$get: string;
|
|
88
90
|
} | undefined>;
|
|
89
|
-
thinkingEffort: ZodType<number | "high" | "
|
|
91
|
+
thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
|
|
90
92
|
$get: string;
|
|
91
|
-
} | undefined, z.ZodTypeDef, number | "high" | "
|
|
93
|
+
} | undefined, z.ZodTypeDef, number | "high" | "low" | "medium" | "minimal" | {
|
|
92
94
|
$get: string;
|
|
93
95
|
} | undefined>;
|
|
94
96
|
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
@@ -117,9 +119,9 @@ declare const chatModelObjectSchema: z.ZodObject<{
|
|
|
117
119
|
} | undefined, z.ZodTypeDef, number | {
|
|
118
120
|
$get: string;
|
|
119
121
|
} | undefined>;
|
|
120
|
-
thinkingEffort: ZodType<number | "high" | "
|
|
122
|
+
thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
|
|
121
123
|
$get: string;
|
|
122
|
-
} | undefined, z.ZodTypeDef, number | "high" | "
|
|
124
|
+
} | undefined, z.ZodTypeDef, number | "high" | "low" | "medium" | "minimal" | {
|
|
123
125
|
$get: string;
|
|
124
126
|
} | undefined>;
|
|
125
127
|
}, z.ZodTypeAny, "passthrough">>;
|
|
@@ -149,4 +151,17 @@ export declare function camelizeSchema<T extends ZodType>(schema: T, { shallow }
|
|
|
149
151
|
shallow?: boolean;
|
|
150
152
|
}): T;
|
|
151
153
|
export declare function preprocessSchema<T extends ZodType>(fn: (data: unknown) => unknown, schema: T): T;
|
|
154
|
+
export type Instructions = {
|
|
155
|
+
role: Exclude<Role, "tool">;
|
|
156
|
+
content: string;
|
|
157
|
+
path: string;
|
|
158
|
+
cacheControl?: {
|
|
159
|
+
type: "ephemeral";
|
|
160
|
+
ttl?: "5m" | "1h";
|
|
161
|
+
};
|
|
162
|
+
}[];
|
|
163
|
+
export declare const getInstructionsSchema: ({ filepath }: {
|
|
164
|
+
filepath: string;
|
|
165
|
+
}) => ZodType<Instructions>;
|
|
166
|
+
export declare function instructionsToPromptBuilder(instructions: Instructions | string): PromptBuilder;
|
|
152
167
|
export {};
|
|
@@ -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,135 @@
|
|
|
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 SessionMemoryConfig, type SessionMode, type UserMemoryConfig } from "./compact/types.js";
|
|
5
|
+
export * from "./compact/types.js";
|
|
6
|
+
export interface AgentSessionOptions {
|
|
7
|
+
sessionId: string;
|
|
8
|
+
userId?: string;
|
|
9
|
+
agentId?: string;
|
|
10
|
+
afs?: AFS;
|
|
11
|
+
/**
|
|
12
|
+
* Session mode
|
|
13
|
+
* - "auto": Enable history recording, compaction, and memory extraction
|
|
14
|
+
* - "disabled": Disable all session features (history, compaction, memory)
|
|
15
|
+
*
|
|
16
|
+
* **Should be "disabled" for internal utility agents** (extractors, compactors, etc.)
|
|
17
|
+
* to avoid recursive memory extraction and unnecessary overhead.
|
|
18
|
+
*
|
|
19
|
+
* @default DEFAULT_SESSION_MODE ("auto")
|
|
20
|
+
*/
|
|
21
|
+
mode?: SessionMode;
|
|
22
|
+
/**
|
|
23
|
+
* Compaction configuration
|
|
24
|
+
*/
|
|
25
|
+
compact?: CompactConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Session memory configuration
|
|
28
|
+
*/
|
|
29
|
+
sessionMemory?: SessionMemoryConfig;
|
|
30
|
+
/**
|
|
31
|
+
* User memory configuration
|
|
32
|
+
*/
|
|
33
|
+
userMemory?: UserMemoryConfig;
|
|
34
|
+
}
|
|
35
|
+
export declare class AgentSession {
|
|
36
|
+
readonly sessionId: string;
|
|
37
|
+
readonly userId?: string;
|
|
38
|
+
readonly agentId?: string;
|
|
39
|
+
private afs?;
|
|
40
|
+
private historyModulePath?;
|
|
41
|
+
private mode;
|
|
42
|
+
private compactConfig;
|
|
43
|
+
private sessionMemoryConfig;
|
|
44
|
+
private userMemoryConfig;
|
|
45
|
+
private runtimeState;
|
|
46
|
+
private initialized?;
|
|
47
|
+
private compactionPromise?;
|
|
48
|
+
private sessionMemoryUpdatePromise?;
|
|
49
|
+
private userMemoryUpdatePromise?;
|
|
50
|
+
constructor(options: AgentSessionOptions);
|
|
51
|
+
/**
|
|
52
|
+
* Check if memory extraction is enabled
|
|
53
|
+
* Memory extraction requires mode to be "auto" AND AFS history module to be available
|
|
54
|
+
*/
|
|
55
|
+
private get isMemoryEnabled();
|
|
56
|
+
setSystemMessages(...messages: ChatModelInputMessage[]): Promise<void>;
|
|
57
|
+
getMessages(): Promise<ChatModelInputMessage[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Format user memory facts into a system message
|
|
60
|
+
* Applies token budget limit to ensure memory injection fits within constraints
|
|
61
|
+
*/
|
|
62
|
+
private formatUserMemory;
|
|
63
|
+
/**
|
|
64
|
+
* Format session memory facts into a system message
|
|
65
|
+
* Applies token budget limit to ensure memory injection fits within constraints
|
|
66
|
+
*/
|
|
67
|
+
private formatSessionMemory;
|
|
68
|
+
private formatMemoryTemplate;
|
|
69
|
+
startMessage(input: unknown, message: ChatModelInputMessage, options: AgentInvokeOptions): Promise<void>;
|
|
70
|
+
endMessage(output: unknown, message: ChatModelInputMessage | undefined, options: AgentInvokeOptions): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Manually trigger compaction
|
|
73
|
+
*/
|
|
74
|
+
compact(options: AgentInvokeOptions): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Internal method that performs the actual compaction
|
|
77
|
+
*/
|
|
78
|
+
private doCompact;
|
|
79
|
+
private compactCurrentEntry;
|
|
80
|
+
private maybeCompactCurrentEntry;
|
|
81
|
+
private maybeAutoCompact;
|
|
82
|
+
/**
|
|
83
|
+
* Estimate token count for an array of messages
|
|
84
|
+
*/
|
|
85
|
+
private estimateMessagesTokens;
|
|
86
|
+
/**
|
|
87
|
+
* Split entries into batches based on token limit
|
|
88
|
+
* Each batch will not exceed the specified maxTokens
|
|
89
|
+
*/
|
|
90
|
+
private splitIntoBatches;
|
|
91
|
+
appendCurrentMessages(messages: ChatModelInputMessage | ChatModelInputMessage[], options: AgentInvokeOptions): Promise<void>;
|
|
92
|
+
private truncateLargeMessage;
|
|
93
|
+
private ensureInitialized;
|
|
94
|
+
private initialize;
|
|
95
|
+
/**
|
|
96
|
+
* Load session memory facts
|
|
97
|
+
* @returns Array of memory fact entries for the current session
|
|
98
|
+
*/
|
|
99
|
+
private loadSessionMemory;
|
|
100
|
+
/**
|
|
101
|
+
* Load user memory facts
|
|
102
|
+
* @returns Array of memory fact entries for the current user
|
|
103
|
+
*/
|
|
104
|
+
private loadUserMemory;
|
|
105
|
+
/**
|
|
106
|
+
* Load session history including compact summary and history entries
|
|
107
|
+
* @returns Object containing compact summary and history entries
|
|
108
|
+
*/
|
|
109
|
+
private loadSessionHistory;
|
|
110
|
+
/**
|
|
111
|
+
* Manually trigger session memory update
|
|
112
|
+
*/
|
|
113
|
+
updateSessionMemory(options: AgentInvokeOptions): Promise<void>;
|
|
114
|
+
private maybeAutoUpdateSessionMemory;
|
|
115
|
+
private maybeAutoUpdateUserMemory;
|
|
116
|
+
/**
|
|
117
|
+
* Internal method that performs the actual session memory update
|
|
118
|
+
*/
|
|
119
|
+
private doUpdateSessionMemory;
|
|
120
|
+
/**
|
|
121
|
+
* Manually trigger user memory update
|
|
122
|
+
*/
|
|
123
|
+
updateUserMemory(options: AgentInvokeOptions): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Internal method that performs the actual user memory extraction
|
|
126
|
+
*/
|
|
127
|
+
private doUpdateUserMemory;
|
|
128
|
+
private initializeDefaultCompactor;
|
|
129
|
+
private initializeDefaultSessionMemoryExtractor;
|
|
130
|
+
private initializeDefaultUserMemoryExtractor;
|
|
131
|
+
private get maxTokens();
|
|
132
|
+
private get keepRecentRatio();
|
|
133
|
+
private get keepTokenBudget();
|
|
134
|
+
private get singleMessageLimit();
|
|
135
|
+
}
|
|
@@ -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,7 @@
|
|
|
1
|
+
import { AIAgent, type AIAgentOptions } from "../../agents/ai-agent.js";
|
|
2
|
+
import type { MemoryExtractorInput, MemoryExtractorOutput } from "./types.js";
|
|
3
|
+
export interface CreateSessionMemoryExtractorOptions extends AIAgentOptions<MemoryExtractorInput, MemoryExtractorOutput> {
|
|
4
|
+
}
|
|
5
|
+
export declare class AISessionMemoryExtractor extends AIAgent<MemoryExtractorInput, MemoryExtractorOutput> {
|
|
6
|
+
constructor(options?: CreateSessionMemoryExtractorOptions);
|
|
7
|
+
}
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import type { Agent, Message } from "../../agents/agent.js";
|
|
2
|
+
import type { ChatModelInputMessage } from "../../agents/chat-model.js";
|
|
3
|
+
/**
|
|
4
|
+
* Session mode type
|
|
5
|
+
*/
|
|
6
|
+
export type SessionMode = "auto" | "disabled";
|
|
7
|
+
/**
|
|
8
|
+
* Default session mode
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_SESSION_MODE: SessionMode;
|
|
11
|
+
/**
|
|
12
|
+
* Default compaction mode
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEFAULT_COMPACT_MODE: "auto";
|
|
15
|
+
/**
|
|
16
|
+
* Default maximum tokens before triggering compaction
|
|
17
|
+
*/
|
|
18
|
+
export declare const DEFAULT_MAX_TOKENS = 80000;
|
|
19
|
+
/**
|
|
20
|
+
* Default ratio of maxTokens to reserve for keeping recent messages
|
|
21
|
+
*/
|
|
22
|
+
export declare const DEFAULT_KEEP_RECENT_RATIO = 0.5;
|
|
23
|
+
/**
|
|
24
|
+
* Default async mode for compaction
|
|
25
|
+
*/
|
|
26
|
+
export declare const DEFAULT_COMPACT_ASYNC = true;
|
|
27
|
+
/**
|
|
28
|
+
* Content structure for history entries
|
|
29
|
+
*/
|
|
30
|
+
export interface EntryContent {
|
|
31
|
+
input?: unknown;
|
|
32
|
+
output?: unknown;
|
|
33
|
+
messages?: ChatModelInputMessage[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Output structure from the compactor agent
|
|
37
|
+
*/
|
|
38
|
+
export interface CompactContent extends Message {
|
|
39
|
+
summary: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Input structure for the compactor agent
|
|
43
|
+
*/
|
|
44
|
+
export interface CompactorInput extends Message {
|
|
45
|
+
previousSummary?: string[];
|
|
46
|
+
messages: ChatModelInputMessage[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Type alias for a compactor agent
|
|
50
|
+
*/
|
|
51
|
+
export type Compactor = Agent<CompactorInput, CompactContent>;
|
|
52
|
+
/**
|
|
53
|
+
* Configuration for session compaction
|
|
54
|
+
*/
|
|
55
|
+
export interface CompactConfig {
|
|
56
|
+
/**
|
|
57
|
+
* Compaction mode
|
|
58
|
+
* @default DEFAULT_COMPACT_MODE ("auto")
|
|
59
|
+
*/
|
|
60
|
+
mode?: "auto" | "disabled";
|
|
61
|
+
/**
|
|
62
|
+
* Maximum tokens before triggering compaction
|
|
63
|
+
* @default DEFAULT_MAX_TOKENS (80000)
|
|
64
|
+
*/
|
|
65
|
+
maxTokens?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Ratio of maxTokens to reserve for keeping recent messages (0-1)
|
|
68
|
+
*
|
|
69
|
+
* Defines what portion of maxTokens budget should be allocated for
|
|
70
|
+
* preserving recent conversation history without compaction.
|
|
71
|
+
*
|
|
72
|
+
* @default 0.5 (50% of maxTokens)
|
|
73
|
+
* @example 0.5 means if maxTokens=80000, keep up to 40000 tokens of recent messages
|
|
74
|
+
*/
|
|
75
|
+
keepRecentRatio?: number;
|
|
76
|
+
/**
|
|
77
|
+
* Whether to perform compaction asynchronously
|
|
78
|
+
* @default DEFAULT_COMPACT_ASYNC (true)
|
|
79
|
+
*/
|
|
80
|
+
async?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Agent that generates summaries from conversation entries
|
|
83
|
+
* Input: { entries: EntryContent[] }
|
|
84
|
+
* Output: { summary: string }
|
|
85
|
+
*/
|
|
86
|
+
compactor?: Compactor;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Default ratio of maxTokens to allocate for user memory
|
|
90
|
+
*/
|
|
91
|
+
export declare const DEFAULT_MEMORY_RATIO = 0.04;
|
|
92
|
+
/**
|
|
93
|
+
* Default query limit for loading memory facts
|
|
94
|
+
*/
|
|
95
|
+
export declare const DEFAULT_MEMORY_QUERY_LIMIT = 200;
|
|
96
|
+
/**
|
|
97
|
+
* Content structure for a single memory fact
|
|
98
|
+
*
|
|
99
|
+
* Used by both session memory and user memory to store learned facts.
|
|
100
|
+
* Each fact is stored as an individual AFSEntry with metadata at the AFSEntry level.
|
|
101
|
+
*
|
|
102
|
+
* Storage paths:
|
|
103
|
+
* - Session Memory:
|
|
104
|
+
* - List: /by-session/:sessionId/@metadata/memory
|
|
105
|
+
* - Create: /by-session/:sessionId/@metadata/memory/new
|
|
106
|
+
* - Read: /by-session/:sessionId/@metadata/memory/:memoryId
|
|
107
|
+
* - User Memory:
|
|
108
|
+
* - List: /by-user/:userId/@metadata/memory
|
|
109
|
+
* - Create: /by-user/:userId/@metadata/memory/new
|
|
110
|
+
* - Read: /by-user/:userId/@metadata/memory/:memoryId
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* AFSEntry<MemoryFact> {
|
|
114
|
+
* id: "fact-001", // AFSEntry ID (auto-generated)
|
|
115
|
+
* userId: "user-001",
|
|
116
|
+
* agentId: "assistant", // which agent learned this fact
|
|
117
|
+
* sessionId: "session-123", // which session it was learned from (if applicable)
|
|
118
|
+
* createdAt: Date,
|
|
119
|
+
* content: {
|
|
120
|
+
* label: "pref-package-manager", // semantic label for this fact
|
|
121
|
+
* fact: "User prefers using pnpm",
|
|
122
|
+
* confidence: 0.9,
|
|
123
|
+
* tags: ["preference", "tooling"]
|
|
124
|
+
* }
|
|
125
|
+
* }
|
|
126
|
+
*/
|
|
127
|
+
export interface MemoryFact {
|
|
128
|
+
/**
|
|
129
|
+
* Semantic label for this fact (short, human-readable)
|
|
130
|
+
* Used for updates and deletions to uniquely identify facts
|
|
131
|
+
* @example "pref-package-manager", "skill-typescript", "proj-main-language"
|
|
132
|
+
*/
|
|
133
|
+
label: string;
|
|
134
|
+
/**
|
|
135
|
+
* The fact content (text description)
|
|
136
|
+
*/
|
|
137
|
+
fact: string;
|
|
138
|
+
/**
|
|
139
|
+
* Confidence score (0-1)
|
|
140
|
+
* Higher values indicate more certain facts
|
|
141
|
+
* @default 1.0
|
|
142
|
+
*/
|
|
143
|
+
confidence?: number;
|
|
144
|
+
/**
|
|
145
|
+
* Classification tags for the fact
|
|
146
|
+
* @example ['preference', 'technical', 'project-specific']
|
|
147
|
+
*/
|
|
148
|
+
tags?: string[];
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Input structure for the memory extractor agent
|
|
152
|
+
*/
|
|
153
|
+
export interface MemoryExtractorInput extends Message {
|
|
154
|
+
/**
|
|
155
|
+
* User memory facts (long-term, cross-session) to avoid duplication
|
|
156
|
+
*/
|
|
157
|
+
existingUserFacts?: MemoryFact[];
|
|
158
|
+
/**
|
|
159
|
+
* Existing session memory facts (for context and deduplication)
|
|
160
|
+
*/
|
|
161
|
+
existingFacts?: MemoryFact[];
|
|
162
|
+
/**
|
|
163
|
+
* Recent conversation messages to extract facts from
|
|
164
|
+
*/
|
|
165
|
+
messages: ChatModelInputMessage[];
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Output structure from the memory extractor agent
|
|
169
|
+
*/
|
|
170
|
+
export interface MemoryExtractorOutput extends Message {
|
|
171
|
+
/**
|
|
172
|
+
* New or updated facts from the conversation
|
|
173
|
+
* Only include facts that need to be added or updated
|
|
174
|
+
* Do not include unchanged facts that already exist
|
|
175
|
+
*/
|
|
176
|
+
newFacts: MemoryFact[];
|
|
177
|
+
/**
|
|
178
|
+
* Fact labels to remove from existing memory
|
|
179
|
+
* Each string should match a label in existingFacts
|
|
180
|
+
* @example ["pref-package-manager", "skill-old-framework"]
|
|
181
|
+
*/
|
|
182
|
+
removeFacts?: string[];
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Type alias for a memory extractor agent
|
|
186
|
+
*/
|
|
187
|
+
export type MemoryExtractor = Agent<MemoryExtractorInput, MemoryExtractorOutput>;
|
|
188
|
+
/**
|
|
189
|
+
* Default session memory mode
|
|
190
|
+
*/
|
|
191
|
+
export declare const DEFAULT_SESSION_MEMORY_MODE: "auto";
|
|
192
|
+
/**
|
|
193
|
+
* Default async mode for session memory extraction
|
|
194
|
+
*/
|
|
195
|
+
export declare const DEFAULT_SESSION_MEMORY_ASYNC = true;
|
|
196
|
+
/**
|
|
197
|
+
* Metadata for tracking session memory extraction progress
|
|
198
|
+
*
|
|
199
|
+
* This metadata is stored in each memory entry's metadata field.
|
|
200
|
+
* When extracting new facts, the latestEntryId is recorded in the metadata
|
|
201
|
+
* to track which history entries have been processed.
|
|
202
|
+
*/
|
|
203
|
+
export interface SessionMemoryMetadata {
|
|
204
|
+
/**
|
|
205
|
+
* ID of the last extracted history entry
|
|
206
|
+
* Used to determine which entries still need processing
|
|
207
|
+
*/
|
|
208
|
+
latestEntryId?: string;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Default user memory mode
|
|
212
|
+
*/
|
|
213
|
+
export declare const DEFAULT_USER_MEMORY_MODE: "auto";
|
|
214
|
+
/**
|
|
215
|
+
* Default async mode for user memory consolidation
|
|
216
|
+
*/
|
|
217
|
+
export declare const DEFAULT_USER_MEMORY_ASYNC = true;
|
|
218
|
+
/**
|
|
219
|
+
* Input structure for the user memory extractor agent
|
|
220
|
+
*/
|
|
221
|
+
export interface UserMemoryExtractorInput extends Message {
|
|
222
|
+
/**
|
|
223
|
+
* Session memory facts from multiple sessions to consolidate
|
|
224
|
+
*/
|
|
225
|
+
sessionFacts: MemoryFact[];
|
|
226
|
+
/**
|
|
227
|
+
* Existing user memory facts (for context and deduplication)
|
|
228
|
+
*/
|
|
229
|
+
existingUserFacts?: MemoryFact[];
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Output structure from the user memory extractor agent
|
|
233
|
+
*/
|
|
234
|
+
export interface UserMemoryExtractorOutput extends Message {
|
|
235
|
+
/**
|
|
236
|
+
* New or updated facts for user memory
|
|
237
|
+
* Only include facts that need to be added or updated
|
|
238
|
+
* Do not include unchanged facts that already exist
|
|
239
|
+
* Each label should be unique - these will replace old facts with same labels
|
|
240
|
+
*/
|
|
241
|
+
newFacts: MemoryFact[];
|
|
242
|
+
/**
|
|
243
|
+
* Fact labels to remove from user memory
|
|
244
|
+
* Each string should match a label in existingUserFacts
|
|
245
|
+
*/
|
|
246
|
+
removeFacts?: string[];
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Type alias for a user memory extractor agent
|
|
250
|
+
*/
|
|
251
|
+
export type UserMemoryExtractor = Agent<UserMemoryExtractorInput, UserMemoryExtractorOutput>;
|
|
252
|
+
/**
|
|
253
|
+
* Configuration for user memory
|
|
254
|
+
* User memory contains long-term facts consolidated from multiple sessions
|
|
255
|
+
*/
|
|
256
|
+
export interface UserMemoryConfig {
|
|
257
|
+
/**
|
|
258
|
+
* User memory mode
|
|
259
|
+
* - "auto": Enable memory and auto-consolidate at appropriate times
|
|
260
|
+
* - "disabled": Disable user memory completely
|
|
261
|
+
* @default DEFAULT_USER_MEMORY_MODE ("auto")
|
|
262
|
+
*/
|
|
263
|
+
mode?: "auto" | "disabled";
|
|
264
|
+
/**
|
|
265
|
+
* Ratio of maxTokens to allocate for user memory (0-1)
|
|
266
|
+
*
|
|
267
|
+
* Defines what portion of maxTokens budget should be allocated for
|
|
268
|
+
* injecting user memory facts into the prompt.
|
|
269
|
+
*
|
|
270
|
+
* @default DEFAULT_MEMORY_RATIO (0.04 = 4% of maxTokens)
|
|
271
|
+
* @example 0.04 means if maxTokens=80000, allocate 3200 tokens for memory
|
|
272
|
+
*/
|
|
273
|
+
memoryRatio?: number;
|
|
274
|
+
/**
|
|
275
|
+
* Maximum number of fact entries to load from storage
|
|
276
|
+
* @default DEFAULT_MEMORY_QUERY_LIMIT (200)
|
|
277
|
+
*/
|
|
278
|
+
queryLimit?: number;
|
|
279
|
+
/**
|
|
280
|
+
* Whether to perform memory consolidation asynchronously
|
|
281
|
+
* @default DEFAULT_USER_MEMORY_ASYNC (true)
|
|
282
|
+
*/
|
|
283
|
+
async?: boolean;
|
|
284
|
+
/**
|
|
285
|
+
* Agent that extracts user memory facts from session memory
|
|
286
|
+
* Input: { sessionFacts: MemoryFact[], existingUserFacts?: MemoryFact[] }
|
|
287
|
+
* Output: { newFacts: MemoryFact[], removeFacts?: string[] }
|
|
288
|
+
*/
|
|
289
|
+
extractor?: UserMemoryExtractor;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Configuration for session memory
|
|
293
|
+
* Session memory contains facts extracted from the current session's conversation
|
|
294
|
+
*/
|
|
295
|
+
export interface SessionMemoryConfig {
|
|
296
|
+
/**
|
|
297
|
+
* Session memory mode
|
|
298
|
+
* - "auto": Enable memory and auto-update after each conversation turn
|
|
299
|
+
* - "disabled": Disable memory completely
|
|
300
|
+
* @default DEFAULT_SESSION_MEMORY_MODE ("auto")
|
|
301
|
+
*/
|
|
302
|
+
mode?: "auto" | "disabled";
|
|
303
|
+
/**
|
|
304
|
+
* Ratio of maxTokens to allocate for session memory (0-1)
|
|
305
|
+
*
|
|
306
|
+
* Defines what portion of maxTokens budget should be allocated for
|
|
307
|
+
* injecting session memory facts into the prompt.
|
|
308
|
+
*
|
|
309
|
+
* @default DEFAULT_MEMORY_RATIO (0.04 = 4% of maxTokens)
|
|
310
|
+
* @example 0.04 means if maxTokens=80000, allocate 3200 tokens for memory
|
|
311
|
+
*/
|
|
312
|
+
memoryRatio?: number;
|
|
313
|
+
/**
|
|
314
|
+
* Maximum number of fact entries to load from storage
|
|
315
|
+
* @default DEFAULT_MEMORY_QUERY_LIMIT (200)
|
|
316
|
+
*/
|
|
317
|
+
queryLimit?: number;
|
|
318
|
+
/**
|
|
319
|
+
* Whether to perform memory extraction asynchronously
|
|
320
|
+
* @default DEFAULT_SESSION_MEMORY_ASYNC (true)
|
|
321
|
+
*/
|
|
322
|
+
async?: boolean;
|
|
323
|
+
/**
|
|
324
|
+
* Agent that extracts facts from conversation messages
|
|
325
|
+
* Input: { existingUserFacts?: MemoryFact[], existingFacts?: MemoryFact[], messages: ChatModelInputMessage[] }
|
|
326
|
+
* Output: { newFacts: MemoryFact[], removeFacts?: string[] }
|
|
327
|
+
*/
|
|
328
|
+
extractor?: MemoryExtractor;
|
|
329
|
+
}
|