@aigne/core 1.72.0-beta.9 → 1.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +342 -0
  2. package/lib/cjs/agents/agent.d.ts +5 -0
  3. package/lib/cjs/agents/agent.js +5 -0
  4. package/lib/cjs/agents/ai-agent.d.ts +41 -5
  5. package/lib/cjs/agents/ai-agent.js +89 -29
  6. package/lib/cjs/agents/chat-model.d.ts +3 -0
  7. package/lib/cjs/agents/chat-model.js +18 -1
  8. package/lib/cjs/agents/image-model.js +1 -1
  9. package/lib/cjs/agents/model.d.ts +3 -3
  10. package/lib/cjs/agents/model.js +2 -2
  11. package/lib/cjs/agents/video-model.js +1 -1
  12. package/lib/cjs/aigne/context.js +1 -3
  13. package/lib/cjs/prompt/agent-session.d.ts +115 -5
  14. package/lib/cjs/prompt/agent-session.js +746 -83
  15. package/lib/cjs/prompt/compact/compactor.js +4 -0
  16. package/lib/cjs/prompt/compact/session-memory-extractor.d.ts +7 -0
  17. package/lib/cjs/prompt/compact/session-memory-extractor.js +143 -0
  18. package/lib/cjs/prompt/compact/types.d.ts +257 -0
  19. package/lib/cjs/prompt/compact/types.js +35 -1
  20. package/lib/cjs/prompt/compact/user-memory-extractor.d.ts +7 -0
  21. package/lib/cjs/prompt/compact/user-memory-extractor.js +124 -0
  22. package/lib/cjs/prompt/prompt-builder.js +3 -3
  23. package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +2 -0
  24. package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.js +6 -0
  25. package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.d.ts +1 -2
  26. package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +14 -26
  27. package/lib/cjs/prompt/skills/afs/list.d.ts +2 -0
  28. package/lib/cjs/prompt/skills/afs/list.js +9 -1
  29. package/lib/cjs/prompt/skills/afs/read.d.ts +3 -1
  30. package/lib/cjs/prompt/skills/afs/read.js +5 -0
  31. package/lib/cjs/utils/mcp-utils.js +1 -1
  32. package/lib/cjs/utils/token-estimator.js +1 -1
  33. package/lib/cjs/utils/type-utils.js +0 -1
  34. package/lib/dts/agents/agent.d.ts +5 -0
  35. package/lib/dts/agents/ai-agent.d.ts +41 -5
  36. package/lib/dts/agents/chat-model.d.ts +3 -0
  37. package/lib/dts/agents/model.d.ts +3 -3
  38. package/lib/dts/prompt/agent-session.d.ts +115 -5
  39. package/lib/dts/prompt/compact/session-memory-extractor.d.ts +7 -0
  40. package/lib/dts/prompt/compact/types.d.ts +257 -0
  41. package/lib/dts/prompt/compact/user-memory-extractor.d.ts +7 -0
  42. package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +2 -0
  43. package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +1 -2
  44. package/lib/dts/prompt/skills/afs/list.d.ts +2 -0
  45. package/lib/dts/prompt/skills/afs/read.d.ts +3 -1
  46. package/lib/esm/agents/agent.d.ts +5 -0
  47. package/lib/esm/agents/agent.js +5 -0
  48. package/lib/esm/agents/ai-agent.d.ts +41 -5
  49. package/lib/esm/agents/ai-agent.js +89 -29
  50. package/lib/esm/agents/chat-model.d.ts +3 -0
  51. package/lib/esm/agents/chat-model.js +18 -1
  52. package/lib/esm/agents/image-model.js +1 -1
  53. package/lib/esm/agents/model.d.ts +3 -3
  54. package/lib/esm/agents/model.js +2 -2
  55. package/lib/esm/agents/video-model.js +1 -1
  56. package/lib/esm/aigne/context.js +2 -4
  57. package/lib/esm/prompt/agent-session.d.ts +115 -5
  58. package/lib/esm/prompt/agent-session.js +744 -84
  59. package/lib/esm/prompt/compact/compactor.js +4 -0
  60. package/lib/esm/prompt/compact/session-memory-extractor.d.ts +7 -0
  61. package/lib/esm/prompt/compact/session-memory-extractor.js +139 -0
  62. package/lib/esm/prompt/compact/types.d.ts +257 -0
  63. package/lib/esm/prompt/compact/types.js +34 -0
  64. package/lib/esm/prompt/compact/user-memory-extractor.d.ts +7 -0
  65. package/lib/esm/prompt/compact/user-memory-extractor.js +120 -0
  66. package/lib/esm/prompt/prompt-builder.js +3 -3
  67. package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +2 -0
  68. package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.js +6 -0
  69. package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.d.ts +1 -2
  70. package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +13 -24
  71. package/lib/esm/prompt/skills/afs/list.d.ts +2 -0
  72. package/lib/esm/prompt/skills/afs/list.js +9 -1
  73. package/lib/esm/prompt/skills/afs/read.d.ts +3 -1
  74. package/lib/esm/prompt/skills/afs/read.js +5 -0
  75. package/lib/esm/utils/mcp-utils.js +1 -1
  76. package/lib/esm/utils/token-estimator.js +1 -1
  77. package/lib/esm/utils/type-utils.js +0 -1
  78. package/package.json +6 -6
@@ -3,10 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.loadSkill = loadSkill;
7
- exports.loadSkills = loadSkills;
6
+ exports.discoverSkillsFromAFS = discoverSkillsFromAFS;
8
7
  exports.loadAgentSkillFromAFS = loadAgentSkillFromAFS;
9
- const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
10
8
  const front_matter_1 = __importDefault(require("front-matter"));
11
9
  const agent_skill_js_1 = require("./agent-skill.js");
12
10
  function parseSkill(content, path) {
@@ -18,42 +16,32 @@ function parseSkill(content, path) {
18
16
  content: meta.body,
19
17
  };
20
18
  }
21
- async function loadSkill(path) {
22
- const entry = index_js_1.nodejs.path.join(path, "SKILL.md");
23
- const skill = await index_js_1.nodejs.fs.readFile(entry, "utf-8");
24
- return parseSkill(skill, path);
25
- }
26
- async function loadSkills(paths) {
27
- const skills = [];
28
- for (const path of paths) {
29
- const skill = await loadSkill(path);
30
- skills.push(skill);
31
- }
32
- return skills;
33
- }
34
- async function loadAgentSkillFromAFS({ afs, }) {
19
+ async function discoverSkillsFromAFS(afs) {
35
20
  const modules = await afs.listModules();
36
- const filtered = modules.filter(({ module: m }) => "options" in m &&
37
- typeof m.options === "object" &&
38
- m.options &&
39
- "agentSkills" in m.options &&
40
- m.options.agentSkills === true);
21
+ const filtered = modules.filter(({ module: m }) => m.agentSkills === true);
41
22
  if (!filtered.length)
42
- return;
23
+ return [];
43
24
  const skills = [];
44
25
  for (const module of filtered) {
45
- const data = (await afs.list(module.path, {
26
+ const data = (await afs
27
+ .list(module.path, {
46
28
  pattern: "**/SKILL.md",
47
29
  maxDepth: 10,
48
- })).data;
30
+ })
31
+ .catch(() => ({ data: [] }))).data;
49
32
  for (const entry of data) {
50
33
  const { data: file } = await afs.read(entry.path);
51
34
  if (typeof file?.content !== "string")
52
35
  continue;
53
- const skill = parseSkill(file.content, index_js_1.nodejs.path.dirname(entry.path));
36
+ const dirname = entry.path.split("/").slice(0, -1).join("/");
37
+ const skill = parseSkill(file.content, dirname);
54
38
  skills.push(skill);
55
39
  }
56
40
  }
41
+ return skills;
42
+ }
43
+ async function loadAgentSkillFromAFS({ afs, }) {
44
+ const skills = await discoverSkillsFromAFS(afs);
57
45
  if (!skills.length)
58
46
  return;
59
47
  return new agent_skill_js_1.AgentSkill({
@@ -1,5 +1,6 @@
1
1
  import type { AFSListOptions } from "@aigne/afs";
2
2
  import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
3
+ import type { PromiseOrValue } from "../../../utils/type-utils.js";
3
4
  import { AFSSkillBase } from "./base.js";
4
5
  export interface AFSListInput extends Message {
5
6
  path: string;
@@ -18,5 +19,6 @@ export interface AFSListAgentOptions extends AgentOptions<AFSListInput, AFSListO
18
19
  }
19
20
  export declare class AFSListAgent extends AFSSkillBase<AFSListInput, AFSListOutput> {
20
21
  constructor(options: AFSListAgentOptions);
22
+ formatOutput(output: AFSListOutput): PromiseOrValue<string>;
21
23
  process(input: AFSListInput, _options: AgentInvokeOptions): Promise<AFSListOutput>;
22
24
  }
@@ -56,10 +56,18 @@ Usage:
56
56
  }),
57
57
  });
58
58
  }
59
+ formatOutput(output) {
60
+ if (typeof output.data === "string")
61
+ return output.data;
62
+ return super.formatOutput(output);
63
+ }
59
64
  async process(input, _options) {
60
65
  if (!this.afs)
61
66
  throw new Error("AFS is not configured for this agent.");
62
- const { data, message } = await this.afs.list(input.path, input.options);
67
+ const { data, message } = await this.afs.list(input.path, {
68
+ ...input.options,
69
+ format: "simple-list",
70
+ });
63
71
  return {
64
72
  status: "success",
65
73
  tool: "afs_list",
@@ -1,5 +1,6 @@
1
1
  import type { AFSEntry } from "@aigne/afs";
2
2
  import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
3
+ import type { PromiseOrValue } from "../../../utils/type-utils.js";
3
4
  import { AFSSkillBase } from "./base.js";
4
5
  export interface AFSReadInput extends Message {
5
6
  path: string;
@@ -10,7 +11,7 @@ export interface AFSReadOutput extends Message {
10
11
  status: string;
11
12
  tool: string;
12
13
  path: string;
13
- data?: AFSEntry;
14
+ data?: AFSEntry | null;
14
15
  message?: string;
15
16
  totalLines?: number;
16
17
  returnedLines?: number;
@@ -22,5 +23,6 @@ export interface AFSReadAgentOptions extends AgentOptions<AFSReadInput, AFSReadO
22
23
  }
23
24
  export declare class AFSReadAgent extends AFSSkillBase<AFSReadInput, AFSReadOutput> {
24
25
  constructor(options: AFSReadAgentOptions);
26
+ formatOutput(output: AFSReadOutput): PromiseOrValue<string>;
25
27
  process(input: AFSReadInput, _options: AgentInvokeOptions): Promise<AFSReadOutput>;
26
28
  }
@@ -51,6 +51,11 @@ Usage:
51
51
  }),
52
52
  });
53
53
  }
54
+ formatOutput(output) {
55
+ if (typeof output.data?.content === "string" && output.data.content)
56
+ return output.data.content;
57
+ return super.formatOutput({ ...output, data: output.data || null });
58
+ }
54
59
  async process(input, _options) {
55
60
  if (!this.afs)
56
61
  throw new Error("AFS is not configured for this agent.");
@@ -48,5 +48,5 @@ function resourceFromMCPResource(resource, options) {
48
48
  });
49
49
  }
50
50
  function isResourceTemplate(resource) {
51
- return typeof resource.uriTemplate === "string";
51
+ return "uriTemplate" in resource && typeof resource.uriTemplate === "string";
52
52
  }
@@ -8,7 +8,7 @@ exports.estimateTokens = estimateTokens;
8
8
  const CHAR_TYPE_RATIOS = {
9
9
  chinese: 1.5, // Chinese characters: ~1.5 characters per token
10
10
  word: 0.75, // English words: ~0.75 tokens per word (accounting for subword tokenization)
11
- other: 4, // Other characters (punctuation, numbers, etc.): ~4 characters per token
11
+ other: 1, // Other characters (punctuation, numbers, etc.): ~1 character per token
12
12
  };
13
13
  /**
14
14
  * Regular expressions for character type detection
@@ -58,7 +58,6 @@ function duplicates(arr, key = (item) => item) {
58
58
  function remove(arr, remove) {
59
59
  const removed = [];
60
60
  for (let i = 0; i < arr.length; i++) {
61
- // biome-ignore lint/style/noNonNullAssertion: false positive
62
61
  const item = arr[i];
63
62
  if ((Array.isArray(remove) && remove.includes(item)) ||
64
63
  (typeof remove === "function" && remove(item))) {
@@ -172,6 +172,10 @@ export interface AgentInvokeOptions<U extends UserContext = UserContext> {
172
172
  * This property only exists in the CLI context by command `aigne run`
173
173
  */
174
174
  prompts?: typeof prompts;
175
+ /**
176
+ * The caller agent that invoked this agent
177
+ */
178
+ caller?: Agent;
175
179
  }
176
180
  /**
177
181
  * Agent is the base class for all agents.
@@ -513,6 +517,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
513
517
  */
514
518
  protected postprocess(input: I, output: O, options: AgentInvokeOptions): Promise<void>;
515
519
  protected publishToTopics(output: Message, options: AgentInvokeOptions): Promise<void>;
520
+ formatOutput(output: O): PromiseOrValue<string>;
516
521
  /**
517
522
  * Core processing method of the agent, must be implemented in subclasses
518
523
  *
@@ -2,7 +2,7 @@ import { type ZodObject, type ZodType, z } from "zod";
2
2
  import { type NestAgentSchema } from "../loader/agent-yaml.js";
3
3
  import type { AgentLoadOptions } from "../loader/index.js";
4
4
  import { type Instructions } from "../loader/schema.js";
5
- import type { CompactConfig } from "../prompt/agent-session.js";
5
+ import type { CompactConfig, SessionMemoryConfig, UserMemoryConfig } from "../prompt/agent-session.js";
6
6
  import { PromptBuilder } from "../prompt/prompt-builder.js";
7
7
  import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type AgentProcessResult, type Message } from "./agent.js";
8
8
  import type { ChatModel, ChatModelInput } from "./chat-model.js";
@@ -126,7 +126,31 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
126
126
  */
127
127
  memoryPromptTemplate?: string;
128
128
  useMemoriesFromContext?: boolean;
129
- compact?: CompactConfig;
129
+ /**
130
+ * Agent session configuration
131
+ *
132
+ * Controls history recording, memory extraction, and conversation compaction.
133
+ * By default, mode is "auto" (enabled). Set `{ mode: "disabled" }` to disable
134
+ * for internal utility agents (extractors, compactors, etc.).
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * // Default behavior - session features enabled
139
+ * new AIAgent({
140
+ * session: {
141
+ * compact: { mode: "auto" },
142
+ * sessionMemory: { mode: "auto" },
143
+ * userMemory: { mode: "auto" }
144
+ * }
145
+ * })
146
+ *
147
+ * // Disable for internal utility agents
148
+ * new AIAgent({
149
+ * session: { mode: "disabled" }
150
+ * })
151
+ * ```
152
+ */
153
+ session?: Partial<Omit<import("../prompt/agent-session.js").AgentSessionOptions, "sessionId" | "userId" | "agentId" | "afs">>;
130
154
  }
131
155
  export interface AIAgentLoadSchema {
132
156
  instructions?: Instructions;
@@ -137,8 +161,17 @@ export interface AIAgentLoadSchema {
137
161
  toolChoice?: AIAgentToolChoice;
138
162
  toolCallsConcurrency?: number;
139
163
  keepTextInToolUses?: boolean;
140
- compact?: Omit<CompactConfig, "compactor"> & {
141
- compactor?: NestAgentSchema;
164
+ session?: {
165
+ mode?: "auto" | "disabled";
166
+ compact?: Omit<CompactConfig, "compactor"> & {
167
+ compactor?: NestAgentSchema;
168
+ };
169
+ sessionMemory?: Omit<SessionMemoryConfig, "extractor"> & {
170
+ extractor?: NestAgentSchema;
171
+ };
172
+ userMemory?: Omit<UserMemoryConfig, "extractor"> & {
173
+ extractor?: NestAgentSchema;
174
+ };
142
175
  };
143
176
  }
144
177
  /**
@@ -337,7 +370,10 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
337
370
  metadataEnd: string;
338
371
  parse: (raw: string) => object;
339
372
  };
340
- compact?: CompactConfig;
373
+ /**
374
+ * Agent session configuration
375
+ */
376
+ session?: Partial<Omit<import("../prompt/agent-session.js").AgentSessionOptions, "sessionId" | "userId" | "agentId" | "afs">>;
341
377
  get inputSchema(): ZodType<I>;
342
378
  /**
343
379
  * Process an input message and generate a response
@@ -57,7 +57,9 @@ export declare abstract class ChatModel extends Model<ChatModelInput, ChatModelO
57
57
  getModelCapabilities(): {
58
58
  supportsParallelToolCalls: boolean;
59
59
  };
60
+ getModelOptions(input: Message, options: AgentInvokeOptions): Promise<ChatModelInputOptions>;
60
61
  private validateToolNames;
62
+ countTokens(input: ChatModelInput): Promise<number>;
61
63
  /**
62
64
  * Normalizes tool names to ensure compatibility with language models
63
65
  *
@@ -226,6 +228,7 @@ export type TextContent = {
226
228
  type: "text";
227
229
  text: string;
228
230
  isThinking?: boolean;
231
+ isAgentSkill?: boolean;
229
232
  /**
230
233
  * Cache control marker (only supported by Claude)
231
234
  *
@@ -17,9 +17,9 @@ export declare abstract class Model<I extends Message = any, O extends Message =
17
17
  */
18
18
  getModelOptions(input: Message, options: AgentInvokeOptions): Promise<Record<string, unknown>>;
19
19
  protected preprocess(input: I, options: AgentInvokeOptions): Promise<void>;
20
- transformFileType(fileType: "file", data: FileUnionContent, options: AgentInvokeOptions): Promise<FileContent>;
21
- transformFileType(fileType: "local" | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<LocalContent>;
22
- transformFileType(fileType: FileType | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<FileUnionContent>;
20
+ transformFileType(fileType: "file", data: FileUnionContent): Promise<FileContent>;
21
+ transformFileType(fileType: "local" | undefined, data: FileUnionContent): Promise<LocalContent>;
22
+ transformFileType(fileType: FileType | undefined, data: FileUnionContent): Promise<FileUnionContent>;
23
23
  static getFileExtension(type: string): Promise<string | undefined>;
24
24
  static getMimeType(filename: string): Promise<string | undefined>;
25
25
  downloadFile(url: string): Promise<Response>;
@@ -1,17 +1,36 @@
1
1
  import type { AFS } from "@aigne/afs";
2
2
  import type { AgentInvokeOptions } from "../agents/agent.js";
3
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 };
4
+ import { type CompactConfig, type SessionMemoryConfig, type SessionMode, type UserMemoryConfig } from "./compact/types.js";
5
+ export * from "./compact/types.js";
6
6
  export interface AgentSessionOptions {
7
7
  sessionId: string;
8
8
  userId?: string;
9
9
  agentId?: string;
10
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;
11
22
  /**
12
23
  * Compaction configuration
13
24
  */
14
25
  compact?: CompactConfig;
26
+ /**
27
+ * Session memory configuration
28
+ */
29
+ sessionMemory?: SessionMemoryConfig;
30
+ /**
31
+ * User memory configuration
32
+ */
33
+ userMemory?: UserMemoryConfig;
15
34
  }
16
35
  export declare class AgentSession {
17
36
  readonly sessionId: string;
@@ -19,15 +38,36 @@ export declare class AgentSession {
19
38
  readonly agentId?: string;
20
39
  private afs?;
21
40
  private historyModulePath?;
41
+ private mode;
22
42
  private compactConfig;
43
+ private sessionMemoryConfig;
44
+ private userMemoryConfig;
23
45
  private runtimeState;
24
46
  private initialized?;
25
47
  private compactionPromise?;
48
+ private sessionMemoryUpdatePromise?;
49
+ private userMemoryUpdatePromise?;
26
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();
27
56
  setSystemMessages(...messages: ChatModelInputMessage[]): Promise<void>;
28
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;
29
69
  startMessage(input: unknown, message: ChatModelInputMessage, options: AgentInvokeOptions): Promise<void>;
30
- endMessage(output: unknown, options: AgentInvokeOptions): Promise<void>;
70
+ endMessage(output: unknown, message: ChatModelInputMessage | undefined, options: AgentInvokeOptions): Promise<void>;
31
71
  /**
32
72
  * Manually trigger compaction
33
73
  */
@@ -36,9 +76,13 @@ export declare class AgentSession {
36
76
  * Internal method that performs the actual compaction
37
77
  */
38
78
  private doCompact;
79
+ private compactCurrentEntry;
80
+ private maybeCompactCurrentEntry;
39
81
  private maybeAutoCompact;
40
82
  /**
41
- * Estimate token count for an array of messages
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
42
86
  */
43
87
  private estimateMessagesTokens;
44
88
  /**
@@ -46,8 +90,74 @@ export declare class AgentSession {
46
90
  * Each batch will not exceed the specified maxTokens
47
91
  */
48
92
  private splitIntoBatches;
49
- appendCurrentMessages(...messages: ChatModelInputMessage[]): Promise<void>;
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;
50
103
  private ensureInitialized;
51
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;
52
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();
53
163
  }
@@ -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
+ }