@aigne/core 1.72.0-beta.2 → 1.72.0-beta.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +261 -0
- package/lib/cjs/agents/agent.d.ts +42 -11
- package/lib/cjs/agents/agent.js +34 -8
- package/lib/cjs/agents/ai-agent.d.ts +63 -4
- package/lib/cjs/agents/ai-agent.js +154 -20
- package/lib/cjs/agents/chat-model.d.ts +157 -0
- package/lib/cjs/agents/chat-model.js +71 -6
- package/lib/cjs/agents/image-agent.d.ts +17 -1
- package/lib/cjs/agents/image-agent.js +16 -0
- package/lib/cjs/agents/image-model.d.ts +12 -2
- package/lib/cjs/agents/image-model.js +1 -1
- package/lib/cjs/agents/mcp-agent.d.ts +17 -0
- package/lib/cjs/agents/mcp-agent.js +18 -0
- package/lib/cjs/agents/model.d.ts +3 -3
- package/lib/cjs/agents/model.js +2 -2
- package/lib/cjs/agents/team-agent.d.ts +55 -0
- package/lib/cjs/agents/team-agent.js +31 -0
- package/lib/cjs/agents/transform-agent.d.ts +12 -0
- package/lib/cjs/agents/transform-agent.js +13 -0
- package/lib/cjs/agents/video-model.d.ts +10 -0
- package/lib/cjs/agents/video-model.js +1 -1
- package/lib/cjs/aigne/context.js +1 -3
- package/lib/cjs/aigne/usage.d.ts +4 -0
- package/lib/cjs/aigne/usage.js +6 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/loader/agent-yaml.d.ts +5 -63
- package/lib/cjs/loader/agent-yaml.js +4 -129
- package/lib/cjs/loader/agents.d.ts +4 -0
- package/lib/cjs/loader/agents.js +17 -0
- package/lib/cjs/loader/index.d.ts +16 -12
- package/lib/cjs/loader/index.js +20 -81
- package/lib/cjs/loader/schema.d.ts +21 -6
- package/lib/cjs/loader/schema.js +60 -1
- package/lib/cjs/memory/recorder.d.ts +4 -4
- package/lib/cjs/memory/retriever.d.ts +4 -4
- package/lib/cjs/prompt/agent-session.d.ts +163 -0
- package/lib/cjs/prompt/agent-session.js +1008 -0
- package/lib/cjs/prompt/compact/compactor.d.ts +7 -0
- package/lib/cjs/prompt/compact/compactor.js +52 -0
- package/lib/cjs/prompt/compact/session-memory-extractor.d.ts +7 -0
- package/lib/cjs/prompt/compact/session-memory-extractor.js +143 -0
- package/lib/cjs/prompt/compact/types.d.ts +336 -0
- package/lib/cjs/prompt/compact/types.js +53 -0
- package/lib/cjs/prompt/compact/user-memory-extractor.d.ts +7 -0
- package/lib/cjs/prompt/compact/user-memory-extractor.js +124 -0
- package/lib/cjs/prompt/context/afs/history.d.ts +5 -1
- package/lib/cjs/prompt/context/afs/history.js +3 -2
- package/lib/cjs/prompt/context/afs/index.js +8 -1
- package/lib/cjs/prompt/prompt-builder.d.ts +11 -9
- package/lib/cjs/prompt/prompt-builder.js +79 -120
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +19 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.js +69 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.d.ts +12 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +50 -0
- package/lib/cjs/prompt/skills/afs/delete.js +15 -3
- package/lib/cjs/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/cjs/prompt/skills/afs/edit.js +85 -59
- package/lib/cjs/prompt/skills/afs/exec.js +17 -6
- package/lib/cjs/prompt/skills/afs/index.js +4 -1
- package/lib/cjs/prompt/skills/afs/list.d.ts +2 -0
- package/lib/cjs/prompt/skills/afs/list.js +35 -11
- package/lib/cjs/prompt/skills/afs/read.d.ts +9 -3
- package/lib/cjs/prompt/skills/afs/read.js +67 -15
- package/lib/cjs/prompt/skills/afs/rename.js +18 -4
- package/lib/cjs/prompt/skills/afs/search.js +21 -5
- package/lib/cjs/prompt/skills/afs/write.js +20 -6
- package/lib/cjs/prompt/template.d.ts +84 -9
- package/lib/cjs/prompt/template.js +46 -17
- package/lib/cjs/utils/mcp-utils.js +1 -1
- package/lib/cjs/utils/token-estimator.js +1 -1
- package/lib/dts/agents/agent.d.ts +42 -11
- package/lib/dts/agents/ai-agent.d.ts +63 -4
- package/lib/dts/agents/chat-model.d.ts +157 -0
- package/lib/dts/agents/image-agent.d.ts +17 -1
- package/lib/dts/agents/image-model.d.ts +12 -2
- package/lib/dts/agents/mcp-agent.d.ts +17 -0
- package/lib/dts/agents/model.d.ts +3 -3
- package/lib/dts/agents/team-agent.d.ts +55 -0
- package/lib/dts/agents/transform-agent.d.ts +12 -0
- package/lib/dts/agents/video-model.d.ts +10 -0
- package/lib/dts/aigne/context.d.ts +2 -2
- package/lib/dts/aigne/usage.d.ts +4 -0
- package/lib/dts/index.d.ts +1 -0
- package/lib/dts/loader/agent-yaml.d.ts +5 -63
- package/lib/dts/loader/agents.d.ts +4 -0
- package/lib/dts/loader/index.d.ts +16 -12
- package/lib/dts/loader/schema.d.ts +21 -6
- package/lib/dts/memory/recorder.d.ts +4 -4
- package/lib/dts/memory/retriever.d.ts +4 -4
- package/lib/dts/prompt/agent-session.d.ts +163 -0
- package/lib/dts/prompt/compact/compactor.d.ts +7 -0
- package/lib/dts/prompt/compact/session-memory-extractor.d.ts +7 -0
- package/lib/dts/prompt/compact/types.d.ts +336 -0
- package/lib/dts/prompt/compact/user-memory-extractor.d.ts +7 -0
- package/lib/dts/prompt/context/afs/history.d.ts +5 -1
- package/lib/dts/prompt/prompt-builder.d.ts +11 -9
- package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +19 -0
- package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +12 -0
- package/lib/dts/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/dts/prompt/skills/afs/list.d.ts +2 -0
- package/lib/dts/prompt/skills/afs/read.d.ts +9 -3
- package/lib/dts/prompt/template.d.ts +84 -9
- package/lib/esm/agents/agent.d.ts +42 -11
- package/lib/esm/agents/agent.js +34 -8
- package/lib/esm/agents/ai-agent.d.ts +63 -4
- package/lib/esm/agents/ai-agent.js +154 -20
- package/lib/esm/agents/chat-model.d.ts +157 -0
- package/lib/esm/agents/chat-model.js +70 -5
- package/lib/esm/agents/image-agent.d.ts +17 -1
- package/lib/esm/agents/image-agent.js +16 -0
- package/lib/esm/agents/image-model.d.ts +12 -2
- package/lib/esm/agents/image-model.js +1 -1
- package/lib/esm/agents/mcp-agent.d.ts +17 -0
- package/lib/esm/agents/mcp-agent.js +18 -0
- package/lib/esm/agents/model.d.ts +3 -3
- package/lib/esm/agents/model.js +2 -2
- package/lib/esm/agents/team-agent.d.ts +55 -0
- package/lib/esm/agents/team-agent.js +31 -0
- package/lib/esm/agents/transform-agent.d.ts +12 -0
- package/lib/esm/agents/transform-agent.js +13 -0
- package/lib/esm/agents/video-model.d.ts +10 -0
- package/lib/esm/agents/video-model.js +1 -1
- package/lib/esm/aigne/context.d.ts +2 -2
- package/lib/esm/aigne/context.js +2 -4
- package/lib/esm/aigne/usage.d.ts +4 -0
- package/lib/esm/aigne/usage.js +6 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/loader/agent-yaml.d.ts +5 -63
- package/lib/esm/loader/agent-yaml.js +4 -128
- package/lib/esm/loader/agents.d.ts +4 -0
- package/lib/esm/loader/agents.js +14 -0
- package/lib/esm/loader/index.d.ts +16 -12
- package/lib/esm/loader/index.js +21 -81
- package/lib/esm/loader/schema.d.ts +21 -6
- package/lib/esm/loader/schema.js +57 -0
- package/lib/esm/memory/recorder.d.ts +4 -4
- package/lib/esm/memory/retriever.d.ts +4 -4
- package/lib/esm/prompt/agent-session.d.ts +163 -0
- package/lib/esm/prompt/agent-session.js +968 -0
- package/lib/esm/prompt/compact/compactor.d.ts +7 -0
- package/lib/esm/prompt/compact/compactor.js +48 -0
- package/lib/esm/prompt/compact/session-memory-extractor.d.ts +7 -0
- package/lib/esm/prompt/compact/session-memory-extractor.js +139 -0
- package/lib/esm/prompt/compact/types.d.ts +336 -0
- package/lib/esm/prompt/compact/types.js +50 -0
- package/lib/esm/prompt/compact/user-memory-extractor.d.ts +7 -0
- package/lib/esm/prompt/compact/user-memory-extractor.js +120 -0
- package/lib/esm/prompt/context/afs/history.d.ts +5 -1
- package/lib/esm/prompt/context/afs/history.js +3 -2
- package/lib/esm/prompt/context/afs/index.js +8 -1
- package/lib/esm/prompt/prompt-builder.d.ts +11 -9
- package/lib/esm/prompt/prompt-builder.js +80 -121
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +19 -0
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.js +65 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.d.ts +12 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +43 -0
- package/lib/esm/prompt/skills/afs/delete.js +15 -3
- package/lib/esm/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/esm/prompt/skills/afs/edit.js +85 -59
- package/lib/esm/prompt/skills/afs/exec.js +17 -6
- package/lib/esm/prompt/skills/afs/index.js +4 -1
- package/lib/esm/prompt/skills/afs/list.d.ts +2 -0
- package/lib/esm/prompt/skills/afs/list.js +35 -11
- package/lib/esm/prompt/skills/afs/read.d.ts +9 -3
- package/lib/esm/prompt/skills/afs/read.js +67 -15
- package/lib/esm/prompt/skills/afs/rename.js +18 -4
- package/lib/esm/prompt/skills/afs/search.js +21 -5
- package/lib/esm/prompt/skills/afs/write.js +20 -6
- package/lib/esm/prompt/template.d.ts +84 -9
- package/lib/esm/prompt/template.js +46 -17
- package/lib/esm/utils/mcp-utils.js +1 -1
- package/lib/esm/utils/token-estimator.js +1 -1
- package/package.json +7 -6
|
@@ -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
|
+
}
|