@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.
Files changed (175) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/lib/cjs/agents/agent.d.ts +42 -11
  3. package/lib/cjs/agents/agent.js +34 -8
  4. package/lib/cjs/agents/ai-agent.d.ts +63 -4
  5. package/lib/cjs/agents/ai-agent.js +154 -20
  6. package/lib/cjs/agents/chat-model.d.ts +157 -0
  7. package/lib/cjs/agents/chat-model.js +71 -6
  8. package/lib/cjs/agents/image-agent.d.ts +17 -1
  9. package/lib/cjs/agents/image-agent.js +16 -0
  10. package/lib/cjs/agents/image-model.d.ts +12 -2
  11. package/lib/cjs/agents/image-model.js +1 -1
  12. package/lib/cjs/agents/mcp-agent.d.ts +17 -0
  13. package/lib/cjs/agents/mcp-agent.js +18 -0
  14. package/lib/cjs/agents/model.d.ts +3 -3
  15. package/lib/cjs/agents/model.js +2 -2
  16. package/lib/cjs/agents/team-agent.d.ts +55 -0
  17. package/lib/cjs/agents/team-agent.js +31 -0
  18. package/lib/cjs/agents/transform-agent.d.ts +12 -0
  19. package/lib/cjs/agents/transform-agent.js +13 -0
  20. package/lib/cjs/agents/video-model.d.ts +10 -0
  21. package/lib/cjs/agents/video-model.js +1 -1
  22. package/lib/cjs/aigne/context.js +1 -3
  23. package/lib/cjs/aigne/usage.d.ts +4 -0
  24. package/lib/cjs/aigne/usage.js +6 -0
  25. package/lib/cjs/index.d.ts +1 -0
  26. package/lib/cjs/index.js +1 -0
  27. package/lib/cjs/loader/agent-yaml.d.ts +5 -63
  28. package/lib/cjs/loader/agent-yaml.js +4 -129
  29. package/lib/cjs/loader/agents.d.ts +4 -0
  30. package/lib/cjs/loader/agents.js +17 -0
  31. package/lib/cjs/loader/index.d.ts +16 -12
  32. package/lib/cjs/loader/index.js +20 -81
  33. package/lib/cjs/loader/schema.d.ts +21 -6
  34. package/lib/cjs/loader/schema.js +60 -1
  35. package/lib/cjs/memory/recorder.d.ts +4 -4
  36. package/lib/cjs/memory/retriever.d.ts +4 -4
  37. package/lib/cjs/prompt/agent-session.d.ts +163 -0
  38. package/lib/cjs/prompt/agent-session.js +1008 -0
  39. package/lib/cjs/prompt/compact/compactor.d.ts +7 -0
  40. package/lib/cjs/prompt/compact/compactor.js +52 -0
  41. package/lib/cjs/prompt/compact/session-memory-extractor.d.ts +7 -0
  42. package/lib/cjs/prompt/compact/session-memory-extractor.js +143 -0
  43. package/lib/cjs/prompt/compact/types.d.ts +336 -0
  44. package/lib/cjs/prompt/compact/types.js +53 -0
  45. package/lib/cjs/prompt/compact/user-memory-extractor.d.ts +7 -0
  46. package/lib/cjs/prompt/compact/user-memory-extractor.js +124 -0
  47. package/lib/cjs/prompt/context/afs/history.d.ts +5 -1
  48. package/lib/cjs/prompt/context/afs/history.js +3 -2
  49. package/lib/cjs/prompt/context/afs/index.js +8 -1
  50. package/lib/cjs/prompt/prompt-builder.d.ts +11 -9
  51. package/lib/cjs/prompt/prompt-builder.js +79 -120
  52. package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +19 -0
  53. package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.js +69 -0
  54. package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.d.ts +12 -0
  55. package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +50 -0
  56. package/lib/cjs/prompt/skills/afs/delete.js +15 -3
  57. package/lib/cjs/prompt/skills/afs/edit.d.ts +6 -9
  58. package/lib/cjs/prompt/skills/afs/edit.js +85 -59
  59. package/lib/cjs/prompt/skills/afs/exec.js +17 -6
  60. package/lib/cjs/prompt/skills/afs/index.js +4 -1
  61. package/lib/cjs/prompt/skills/afs/list.d.ts +2 -0
  62. package/lib/cjs/prompt/skills/afs/list.js +35 -11
  63. package/lib/cjs/prompt/skills/afs/read.d.ts +9 -3
  64. package/lib/cjs/prompt/skills/afs/read.js +67 -15
  65. package/lib/cjs/prompt/skills/afs/rename.js +18 -4
  66. package/lib/cjs/prompt/skills/afs/search.js +21 -5
  67. package/lib/cjs/prompt/skills/afs/write.js +20 -6
  68. package/lib/cjs/prompt/template.d.ts +84 -9
  69. package/lib/cjs/prompt/template.js +46 -17
  70. package/lib/cjs/utils/mcp-utils.js +1 -1
  71. package/lib/cjs/utils/token-estimator.js +1 -1
  72. package/lib/dts/agents/agent.d.ts +42 -11
  73. package/lib/dts/agents/ai-agent.d.ts +63 -4
  74. package/lib/dts/agents/chat-model.d.ts +157 -0
  75. package/lib/dts/agents/image-agent.d.ts +17 -1
  76. package/lib/dts/agents/image-model.d.ts +12 -2
  77. package/lib/dts/agents/mcp-agent.d.ts +17 -0
  78. package/lib/dts/agents/model.d.ts +3 -3
  79. package/lib/dts/agents/team-agent.d.ts +55 -0
  80. package/lib/dts/agents/transform-agent.d.ts +12 -0
  81. package/lib/dts/agents/video-model.d.ts +10 -0
  82. package/lib/dts/aigne/context.d.ts +2 -2
  83. package/lib/dts/aigne/usage.d.ts +4 -0
  84. package/lib/dts/index.d.ts +1 -0
  85. package/lib/dts/loader/agent-yaml.d.ts +5 -63
  86. package/lib/dts/loader/agents.d.ts +4 -0
  87. package/lib/dts/loader/index.d.ts +16 -12
  88. package/lib/dts/loader/schema.d.ts +21 -6
  89. package/lib/dts/memory/recorder.d.ts +4 -4
  90. package/lib/dts/memory/retriever.d.ts +4 -4
  91. package/lib/dts/prompt/agent-session.d.ts +163 -0
  92. package/lib/dts/prompt/compact/compactor.d.ts +7 -0
  93. package/lib/dts/prompt/compact/session-memory-extractor.d.ts +7 -0
  94. package/lib/dts/prompt/compact/types.d.ts +336 -0
  95. package/lib/dts/prompt/compact/user-memory-extractor.d.ts +7 -0
  96. package/lib/dts/prompt/context/afs/history.d.ts +5 -1
  97. package/lib/dts/prompt/prompt-builder.d.ts +11 -9
  98. package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +19 -0
  99. package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +12 -0
  100. package/lib/dts/prompt/skills/afs/edit.d.ts +6 -9
  101. package/lib/dts/prompt/skills/afs/list.d.ts +2 -0
  102. package/lib/dts/prompt/skills/afs/read.d.ts +9 -3
  103. package/lib/dts/prompt/template.d.ts +84 -9
  104. package/lib/esm/agents/agent.d.ts +42 -11
  105. package/lib/esm/agents/agent.js +34 -8
  106. package/lib/esm/agents/ai-agent.d.ts +63 -4
  107. package/lib/esm/agents/ai-agent.js +154 -20
  108. package/lib/esm/agents/chat-model.d.ts +157 -0
  109. package/lib/esm/agents/chat-model.js +70 -5
  110. package/lib/esm/agents/image-agent.d.ts +17 -1
  111. package/lib/esm/agents/image-agent.js +16 -0
  112. package/lib/esm/agents/image-model.d.ts +12 -2
  113. package/lib/esm/agents/image-model.js +1 -1
  114. package/lib/esm/agents/mcp-agent.d.ts +17 -0
  115. package/lib/esm/agents/mcp-agent.js +18 -0
  116. package/lib/esm/agents/model.d.ts +3 -3
  117. package/lib/esm/agents/model.js +2 -2
  118. package/lib/esm/agents/team-agent.d.ts +55 -0
  119. package/lib/esm/agents/team-agent.js +31 -0
  120. package/lib/esm/agents/transform-agent.d.ts +12 -0
  121. package/lib/esm/agents/transform-agent.js +13 -0
  122. package/lib/esm/agents/video-model.d.ts +10 -0
  123. package/lib/esm/agents/video-model.js +1 -1
  124. package/lib/esm/aigne/context.d.ts +2 -2
  125. package/lib/esm/aigne/context.js +2 -4
  126. package/lib/esm/aigne/usage.d.ts +4 -0
  127. package/lib/esm/aigne/usage.js +6 -0
  128. package/lib/esm/index.d.ts +1 -0
  129. package/lib/esm/index.js +1 -0
  130. package/lib/esm/loader/agent-yaml.d.ts +5 -63
  131. package/lib/esm/loader/agent-yaml.js +4 -128
  132. package/lib/esm/loader/agents.d.ts +4 -0
  133. package/lib/esm/loader/agents.js +14 -0
  134. package/lib/esm/loader/index.d.ts +16 -12
  135. package/lib/esm/loader/index.js +21 -81
  136. package/lib/esm/loader/schema.d.ts +21 -6
  137. package/lib/esm/loader/schema.js +57 -0
  138. package/lib/esm/memory/recorder.d.ts +4 -4
  139. package/lib/esm/memory/retriever.d.ts +4 -4
  140. package/lib/esm/prompt/agent-session.d.ts +163 -0
  141. package/lib/esm/prompt/agent-session.js +968 -0
  142. package/lib/esm/prompt/compact/compactor.d.ts +7 -0
  143. package/lib/esm/prompt/compact/compactor.js +48 -0
  144. package/lib/esm/prompt/compact/session-memory-extractor.d.ts +7 -0
  145. package/lib/esm/prompt/compact/session-memory-extractor.js +139 -0
  146. package/lib/esm/prompt/compact/types.d.ts +336 -0
  147. package/lib/esm/prompt/compact/types.js +50 -0
  148. package/lib/esm/prompt/compact/user-memory-extractor.d.ts +7 -0
  149. package/lib/esm/prompt/compact/user-memory-extractor.js +120 -0
  150. package/lib/esm/prompt/context/afs/history.d.ts +5 -1
  151. package/lib/esm/prompt/context/afs/history.js +3 -2
  152. package/lib/esm/prompt/context/afs/index.js +8 -1
  153. package/lib/esm/prompt/prompt-builder.d.ts +11 -9
  154. package/lib/esm/prompt/prompt-builder.js +80 -121
  155. package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +19 -0
  156. package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.js +65 -0
  157. package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.d.ts +12 -0
  158. package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +43 -0
  159. package/lib/esm/prompt/skills/afs/delete.js +15 -3
  160. package/lib/esm/prompt/skills/afs/edit.d.ts +6 -9
  161. package/lib/esm/prompt/skills/afs/edit.js +85 -59
  162. package/lib/esm/prompt/skills/afs/exec.js +17 -6
  163. package/lib/esm/prompt/skills/afs/index.js +4 -1
  164. package/lib/esm/prompt/skills/afs/list.d.ts +2 -0
  165. package/lib/esm/prompt/skills/afs/list.js +35 -11
  166. package/lib/esm/prompt/skills/afs/read.d.ts +9 -3
  167. package/lib/esm/prompt/skills/afs/read.js +67 -15
  168. package/lib/esm/prompt/skills/afs/rename.js +18 -4
  169. package/lib/esm/prompt/skills/afs/search.js +21 -5
  170. package/lib/esm/prompt/skills/afs/write.js +20 -6
  171. package/lib/esm/prompt/template.d.ts +84 -9
  172. package/lib/esm/prompt/template.js +46 -17
  173. package/lib/esm/utils/mcp-utils.js +1 -1
  174. package/lib/esm/utils/token-estimator.js +1 -1
  175. package/package.json +7 -6
@@ -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 { type Instructions, loadAgentFromYamlFile, type NestAgentSchema } from "./agent-yaml.js";
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
- create: (options?: Record<string, any>) => PromiseOrValue<AFSModule>;
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" | "medium" | "low" | "minimal" | {
75
+ thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
71
76
  $get: string;
72
- } | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
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" | "medium" | "low" | "minimal" | {
106
+ thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
102
107
  $get: string;
103
- } | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
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" | "medium" | "low" | "minimal" | {
166
+ thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
162
167
  $get: string;
163
- } | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
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" | "medium" | "low" | "minimal" | {
217
+ thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
213
218
  $get: string;
214
- } | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
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" | "medium" | "low" | "minimal" | {
60
+ thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
59
61
  $get: string;
60
- } | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
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" | "medium" | "low" | "minimal" | {
91
+ thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
90
92
  $get: string;
91
- } | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
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" | "medium" | "low" | "minimal" | {
122
+ thinkingEffort: ZodType<number | "high" | "low" | "medium" | "minimal" | {
121
123
  $get: string;
122
- } | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
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,163 @@
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 messages
84
+ * Applies singleMessageLimit to each text block individually
85
+ * Non-text tokens (images, tool calls) are always counted in full
86
+ */
87
+ private estimateMessagesTokens;
88
+ /**
89
+ * Split entries into batches based on token limit
90
+ * Each batch will not exceed the specified maxTokens
91
+ */
92
+ private splitIntoBatches;
93
+ appendCurrentMessages(messages: ChatModelInputMessage | ChatModelInputMessage[], options: AgentInvokeOptions): Promise<void>;
94
+ /**
95
+ * Truncate text content to fit within target token limit
96
+ * @param text The text to truncate
97
+ * @param currentTokens Current token count of the text
98
+ * @param targetTokens Target token count after truncation
99
+ * @returns Truncated text
100
+ */
101
+ private truncateText;
102
+ private truncateLargeMessage;
103
+ private ensureInitialized;
104
+ private initialize;
105
+ /**
106
+ * Load session memory facts
107
+ * @returns Array of memory fact entries for the current session
108
+ */
109
+ private loadSessionMemory;
110
+ /**
111
+ * Load user memory facts
112
+ * @returns Array of memory fact entries for the current user
113
+ */
114
+ private loadUserMemory;
115
+ /**
116
+ * Load session history including compact content and history entries
117
+ * @returns Object containing history compact and history entries
118
+ */
119
+ private loadSessionHistory;
120
+ /**
121
+ * Manually trigger session memory update
122
+ */
123
+ updateSessionMemory(options: AgentInvokeOptions): Promise<void>;
124
+ private maybeAutoUpdateSessionMemory;
125
+ private maybeAutoUpdateUserMemory;
126
+ /**
127
+ * Internal method that performs the actual session memory update
128
+ */
129
+ private doUpdateSessionMemory;
130
+ /**
131
+ * Manually trigger user memory update
132
+ */
133
+ updateUserMemory(options: AgentInvokeOptions): Promise<void>;
134
+ /**
135
+ * Internal method that performs the actual user memory extraction
136
+ */
137
+ private doUpdateUserMemory;
138
+ /**
139
+ * Find Agent Skill content from a single message
140
+ * @param msg - Message to search in
141
+ * @returns The skill content text if found, undefined otherwise
142
+ */
143
+ private findSkillContentInMessage;
144
+ /**
145
+ * Find the last Agent Skill from a list of messages
146
+ * @param messages - Messages to search through
147
+ * @returns The last Agent Skill found, or undefined if none found
148
+ */
149
+ private findLastAgentSkillFromMessages;
150
+ /**
151
+ * Find the last Agent Skill from a list of history entries
152
+ * @param entries - History entries to search through
153
+ * @returns The last Agent Skill found, or undefined if none found
154
+ */
155
+ private findLastAgentSkill;
156
+ private initializeDefaultCompactor;
157
+ private initializeDefaultSessionMemoryExtractor;
158
+ private initializeDefaultUserMemoryExtractor;
159
+ private get maxTokens();
160
+ private get keepRecentRatio();
161
+ private get keepRecentTokens();
162
+ private get singleMessageLimit();
163
+ }
@@ -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
+ }