@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,336 @@
|
|
|
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
|
+
* Last Agent Skill content in the session
|
|
42
|
+
* Preserved across compactions to maintain skill instructions
|
|
43
|
+
*/
|
|
44
|
+
lastAgentSkill?: {
|
|
45
|
+
content: string;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Input structure for the compactor agent
|
|
50
|
+
*/
|
|
51
|
+
export interface CompactorInput extends Message {
|
|
52
|
+
previousSummary?: string[];
|
|
53
|
+
messages: ChatModelInputMessage[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Type alias for a compactor agent
|
|
57
|
+
*/
|
|
58
|
+
export type Compactor = Agent<CompactorInput, CompactContent>;
|
|
59
|
+
/**
|
|
60
|
+
* Configuration for session compaction
|
|
61
|
+
*/
|
|
62
|
+
export interface CompactConfig {
|
|
63
|
+
/**
|
|
64
|
+
* Compaction mode
|
|
65
|
+
* @default DEFAULT_COMPACT_MODE ("auto")
|
|
66
|
+
*/
|
|
67
|
+
mode?: "auto" | "disabled";
|
|
68
|
+
/**
|
|
69
|
+
* Maximum tokens before triggering compaction
|
|
70
|
+
* @default DEFAULT_MAX_TOKENS (80000)
|
|
71
|
+
*/
|
|
72
|
+
maxTokens?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Ratio of maxTokens to reserve for keeping recent messages (0-1)
|
|
75
|
+
*
|
|
76
|
+
* Defines what portion of maxTokens budget should be allocated for
|
|
77
|
+
* preserving recent conversation history without compaction.
|
|
78
|
+
*
|
|
79
|
+
* @default 0.5 (50% of maxTokens)
|
|
80
|
+
* @example 0.5 means if maxTokens=80000, keep up to 40000 tokens of recent messages
|
|
81
|
+
*/
|
|
82
|
+
keepRecentRatio?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Whether to perform compaction asynchronously
|
|
85
|
+
* @default DEFAULT_COMPACT_ASYNC (true)
|
|
86
|
+
*/
|
|
87
|
+
async?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Agent that generates summaries from conversation entries
|
|
90
|
+
* Input: { entries: EntryContent[] }
|
|
91
|
+
* Output: { summary: string }
|
|
92
|
+
*/
|
|
93
|
+
compactor?: Compactor;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Default ratio of maxTokens to allocate for user memory
|
|
97
|
+
*/
|
|
98
|
+
export declare const DEFAULT_MEMORY_RATIO = 0.04;
|
|
99
|
+
/**
|
|
100
|
+
* Default query limit for loading memory facts
|
|
101
|
+
*/
|
|
102
|
+
export declare const DEFAULT_MEMORY_QUERY_LIMIT = 200;
|
|
103
|
+
/**
|
|
104
|
+
* Content structure for a single memory fact
|
|
105
|
+
*
|
|
106
|
+
* Used by both session memory and user memory to store learned facts.
|
|
107
|
+
* Each fact is stored as an individual AFSEntry with metadata at the AFSEntry level.
|
|
108
|
+
*
|
|
109
|
+
* Storage paths:
|
|
110
|
+
* - Session Memory:
|
|
111
|
+
* - List: /by-session/:sessionId/@metadata/memory
|
|
112
|
+
* - Create: /by-session/:sessionId/@metadata/memory/new
|
|
113
|
+
* - Read: /by-session/:sessionId/@metadata/memory/:memoryId
|
|
114
|
+
* - User Memory:
|
|
115
|
+
* - List: /by-user/:userId/@metadata/memory
|
|
116
|
+
* - Create: /by-user/:userId/@metadata/memory/new
|
|
117
|
+
* - Read: /by-user/:userId/@metadata/memory/:memoryId
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* AFSEntry<MemoryFact> {
|
|
121
|
+
* id: "fact-001", // AFSEntry ID (auto-generated)
|
|
122
|
+
* userId: "user-001",
|
|
123
|
+
* agentId: "assistant", // which agent learned this fact
|
|
124
|
+
* sessionId: "session-123", // which session it was learned from (if applicable)
|
|
125
|
+
* createdAt: Date,
|
|
126
|
+
* content: {
|
|
127
|
+
* label: "pref-package-manager", // semantic label for this fact
|
|
128
|
+
* fact: "User prefers using pnpm",
|
|
129
|
+
* confidence: 0.9,
|
|
130
|
+
* tags: ["preference", "tooling"]
|
|
131
|
+
* }
|
|
132
|
+
* }
|
|
133
|
+
*/
|
|
134
|
+
export interface MemoryFact {
|
|
135
|
+
/**
|
|
136
|
+
* Semantic label for this fact (short, human-readable)
|
|
137
|
+
* Used for updates and deletions to uniquely identify facts
|
|
138
|
+
* @example "pref-package-manager", "skill-typescript", "proj-main-language"
|
|
139
|
+
*/
|
|
140
|
+
label: string;
|
|
141
|
+
/**
|
|
142
|
+
* The fact content (text description)
|
|
143
|
+
*/
|
|
144
|
+
fact: string;
|
|
145
|
+
/**
|
|
146
|
+
* Confidence score (0-1)
|
|
147
|
+
* Higher values indicate more certain facts
|
|
148
|
+
* @default 1.0
|
|
149
|
+
*/
|
|
150
|
+
confidence?: number;
|
|
151
|
+
/**
|
|
152
|
+
* Classification tags for the fact
|
|
153
|
+
* @example ['preference', 'technical', 'project-specific']
|
|
154
|
+
*/
|
|
155
|
+
tags?: string[];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Input structure for the memory extractor agent
|
|
159
|
+
*/
|
|
160
|
+
export interface MemoryExtractorInput extends Message {
|
|
161
|
+
/**
|
|
162
|
+
* User memory facts (long-term, cross-session) to avoid duplication
|
|
163
|
+
*/
|
|
164
|
+
existingUserFacts?: MemoryFact[];
|
|
165
|
+
/**
|
|
166
|
+
* Existing session memory facts (for context and deduplication)
|
|
167
|
+
*/
|
|
168
|
+
existingFacts?: MemoryFact[];
|
|
169
|
+
/**
|
|
170
|
+
* Recent conversation messages to extract facts from
|
|
171
|
+
*/
|
|
172
|
+
messages: ChatModelInputMessage[];
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Output structure from the memory extractor agent
|
|
176
|
+
*/
|
|
177
|
+
export interface MemoryExtractorOutput extends Message {
|
|
178
|
+
/**
|
|
179
|
+
* New or updated facts from the conversation
|
|
180
|
+
* Only include facts that need to be added or updated
|
|
181
|
+
* Do not include unchanged facts that already exist
|
|
182
|
+
*/
|
|
183
|
+
newFacts: MemoryFact[];
|
|
184
|
+
/**
|
|
185
|
+
* Fact labels to remove from existing memory
|
|
186
|
+
* Each string should match a label in existingFacts
|
|
187
|
+
* @example ["pref-package-manager", "skill-old-framework"]
|
|
188
|
+
*/
|
|
189
|
+
removeFacts?: string[];
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Type alias for a memory extractor agent
|
|
193
|
+
*/
|
|
194
|
+
export type MemoryExtractor = Agent<MemoryExtractorInput, MemoryExtractorOutput>;
|
|
195
|
+
/**
|
|
196
|
+
* Default session memory mode
|
|
197
|
+
*/
|
|
198
|
+
export declare const DEFAULT_SESSION_MEMORY_MODE: "auto";
|
|
199
|
+
/**
|
|
200
|
+
* Default async mode for session memory extraction
|
|
201
|
+
*/
|
|
202
|
+
export declare const DEFAULT_SESSION_MEMORY_ASYNC = true;
|
|
203
|
+
/**
|
|
204
|
+
* Metadata for tracking session memory extraction progress
|
|
205
|
+
*
|
|
206
|
+
* This metadata is stored in each memory entry's metadata field.
|
|
207
|
+
* When extracting new facts, the latestEntryId is recorded in the metadata
|
|
208
|
+
* to track which history entries have been processed.
|
|
209
|
+
*/
|
|
210
|
+
export interface SessionMemoryMetadata {
|
|
211
|
+
/**
|
|
212
|
+
* ID of the last extracted history entry
|
|
213
|
+
* Used to determine which entries still need processing
|
|
214
|
+
*/
|
|
215
|
+
latestEntryId?: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Default user memory mode
|
|
219
|
+
*/
|
|
220
|
+
export declare const DEFAULT_USER_MEMORY_MODE: "auto";
|
|
221
|
+
/**
|
|
222
|
+
* Default async mode for user memory consolidation
|
|
223
|
+
*/
|
|
224
|
+
export declare const DEFAULT_USER_MEMORY_ASYNC = true;
|
|
225
|
+
/**
|
|
226
|
+
* Input structure for the user memory extractor agent
|
|
227
|
+
*/
|
|
228
|
+
export interface UserMemoryExtractorInput extends Message {
|
|
229
|
+
/**
|
|
230
|
+
* Session memory facts from multiple sessions to consolidate
|
|
231
|
+
*/
|
|
232
|
+
sessionFacts: MemoryFact[];
|
|
233
|
+
/**
|
|
234
|
+
* Existing user memory facts (for context and deduplication)
|
|
235
|
+
*/
|
|
236
|
+
existingUserFacts?: MemoryFact[];
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Output structure from the user memory extractor agent
|
|
240
|
+
*/
|
|
241
|
+
export interface UserMemoryExtractorOutput extends Message {
|
|
242
|
+
/**
|
|
243
|
+
* New or updated facts for user memory
|
|
244
|
+
* Only include facts that need to be added or updated
|
|
245
|
+
* Do not include unchanged facts that already exist
|
|
246
|
+
* Each label should be unique - these will replace old facts with same labels
|
|
247
|
+
*/
|
|
248
|
+
newFacts: MemoryFact[];
|
|
249
|
+
/**
|
|
250
|
+
* Fact labels to remove from user memory
|
|
251
|
+
* Each string should match a label in existingUserFacts
|
|
252
|
+
*/
|
|
253
|
+
removeFacts?: string[];
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Type alias for a user memory extractor agent
|
|
257
|
+
*/
|
|
258
|
+
export type UserMemoryExtractor = Agent<UserMemoryExtractorInput, UserMemoryExtractorOutput>;
|
|
259
|
+
/**
|
|
260
|
+
* Configuration for user memory
|
|
261
|
+
* User memory contains long-term facts consolidated from multiple sessions
|
|
262
|
+
*/
|
|
263
|
+
export interface UserMemoryConfig {
|
|
264
|
+
/**
|
|
265
|
+
* User memory mode
|
|
266
|
+
* - "auto": Enable memory and auto-consolidate at appropriate times
|
|
267
|
+
* - "disabled": Disable user memory completely
|
|
268
|
+
* @default DEFAULT_USER_MEMORY_MODE ("auto")
|
|
269
|
+
*/
|
|
270
|
+
mode?: "auto" | "disabled";
|
|
271
|
+
/**
|
|
272
|
+
* Ratio of maxTokens to allocate for user memory (0-1)
|
|
273
|
+
*
|
|
274
|
+
* Defines what portion of maxTokens budget should be allocated for
|
|
275
|
+
* injecting user memory facts into the prompt.
|
|
276
|
+
*
|
|
277
|
+
* @default DEFAULT_MEMORY_RATIO (0.04 = 4% of maxTokens)
|
|
278
|
+
* @example 0.04 means if maxTokens=80000, allocate 3200 tokens for memory
|
|
279
|
+
*/
|
|
280
|
+
memoryRatio?: number;
|
|
281
|
+
/**
|
|
282
|
+
* Maximum number of fact entries to load from storage
|
|
283
|
+
* @default DEFAULT_MEMORY_QUERY_LIMIT (200)
|
|
284
|
+
*/
|
|
285
|
+
queryLimit?: number;
|
|
286
|
+
/**
|
|
287
|
+
* Whether to perform memory consolidation asynchronously
|
|
288
|
+
* @default DEFAULT_USER_MEMORY_ASYNC (true)
|
|
289
|
+
*/
|
|
290
|
+
async?: boolean;
|
|
291
|
+
/**
|
|
292
|
+
* Agent that extracts user memory facts from session memory
|
|
293
|
+
* Input: { sessionFacts: MemoryFact[], existingUserFacts?: MemoryFact[] }
|
|
294
|
+
* Output: { newFacts: MemoryFact[], removeFacts?: string[] }
|
|
295
|
+
*/
|
|
296
|
+
extractor?: UserMemoryExtractor;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Configuration for session memory
|
|
300
|
+
* Session memory contains facts extracted from the current session's conversation
|
|
301
|
+
*/
|
|
302
|
+
export interface SessionMemoryConfig {
|
|
303
|
+
/**
|
|
304
|
+
* Session memory mode
|
|
305
|
+
* - "auto": Enable memory and auto-update after each conversation turn
|
|
306
|
+
* - "disabled": Disable memory completely
|
|
307
|
+
* @default DEFAULT_SESSION_MEMORY_MODE ("auto")
|
|
308
|
+
*/
|
|
309
|
+
mode?: "auto" | "disabled";
|
|
310
|
+
/**
|
|
311
|
+
* Ratio of maxTokens to allocate for session memory (0-1)
|
|
312
|
+
*
|
|
313
|
+
* Defines what portion of maxTokens budget should be allocated for
|
|
314
|
+
* injecting session memory facts into the prompt.
|
|
315
|
+
*
|
|
316
|
+
* @default DEFAULT_MEMORY_RATIO (0.04 = 4% of maxTokens)
|
|
317
|
+
* @example 0.04 means if maxTokens=80000, allocate 3200 tokens for memory
|
|
318
|
+
*/
|
|
319
|
+
memoryRatio?: number;
|
|
320
|
+
/**
|
|
321
|
+
* Maximum number of fact entries to load from storage
|
|
322
|
+
* @default DEFAULT_MEMORY_QUERY_LIMIT (200)
|
|
323
|
+
*/
|
|
324
|
+
queryLimit?: number;
|
|
325
|
+
/**
|
|
326
|
+
* Whether to perform memory extraction asynchronously
|
|
327
|
+
* @default DEFAULT_SESSION_MEMORY_ASYNC (true)
|
|
328
|
+
*/
|
|
329
|
+
async?: boolean;
|
|
330
|
+
/**
|
|
331
|
+
* Agent that extracts facts from conversation messages
|
|
332
|
+
* Input: { existingUserFacts?: MemoryFact[], existingFacts?: MemoryFact[], messages: ChatModelInputMessage[] }
|
|
333
|
+
* Output: { newFacts: MemoryFact[], removeFacts?: string[] }
|
|
334
|
+
*/
|
|
335
|
+
extractor?: MemoryExtractor;
|
|
336
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AIAgent, type AIAgentOptions } from "../../agents/ai-agent.js";
|
|
2
|
+
import type { UserMemoryExtractorInput, UserMemoryExtractorOutput } from "./types.js";
|
|
3
|
+
export interface CreateUserMemoryExtractorOptions extends AIAgentOptions<UserMemoryExtractorInput, UserMemoryExtractorOutput> {
|
|
4
|
+
}
|
|
5
|
+
export declare class AIUserMemoryExtractor extends AIAgent<UserMemoryExtractorInput, UserMemoryExtractorOutput> {
|
|
6
|
+
constructor(options?: CreateUserMemoryExtractorOptions);
|
|
7
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import type { AFSListOptions } from "@aigne/afs";
|
|
1
2
|
import type { Agent } from "../../../agents/agent.js";
|
|
2
|
-
export declare function getHistories(agent
|
|
3
|
+
export declare function getHistories({ filter, agent, }: {
|
|
4
|
+
filter: AFSListOptions["filter"];
|
|
5
|
+
agent: Agent;
|
|
6
|
+
}): Promise<{
|
|
3
7
|
role: "user" | "agent";
|
|
4
8
|
content: unknown;
|
|
5
9
|
}[]>;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import type { GetPromptResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
import { Agent, type
|
|
2
|
+
import { Agent, type Message } from "../agents/agent.js";
|
|
3
3
|
import { type AIAgent } from "../agents/ai-agent.js";
|
|
4
|
-
import type { ChatModel, ChatModelInput } from "../agents/chat-model.js";
|
|
4
|
+
import type { ChatModel, ChatModelInput, ChatModelInputMessage } from "../agents/chat-model.js";
|
|
5
5
|
import { type FileUnionContent } from "../agents/model.js";
|
|
6
|
+
import type { Context } from "../aigne/context.js";
|
|
7
|
+
import { AgentSession } from "./agent-session.js";
|
|
6
8
|
import { ChatMessagesTemplate } from "./template.js";
|
|
7
9
|
export interface PromptBuilderOptions {
|
|
8
10
|
instructions?: string | ChatMessagesTemplate;
|
|
9
11
|
workingDir?: string;
|
|
10
12
|
}
|
|
11
|
-
export interface PromptBuildOptions
|
|
13
|
+
export interface PromptBuildOptions {
|
|
14
|
+
context?: Context;
|
|
12
15
|
agent?: AIAgent;
|
|
13
16
|
input?: Message;
|
|
14
17
|
model?: ChatModel;
|
|
@@ -26,7 +29,9 @@ export declare class PromptBuilder {
|
|
|
26
29
|
instructions?: string | ChatMessagesTemplate;
|
|
27
30
|
workingDir?: string;
|
|
28
31
|
copy(): PromptBuilder;
|
|
29
|
-
build(options: PromptBuildOptions): Promise<ChatModelInput & {
|
|
32
|
+
build(options: PromptBuildOptions): Promise<Omit<ChatModelInput, "messages"> & {
|
|
33
|
+
session: AgentSession;
|
|
34
|
+
userMessage: ChatModelInputMessage;
|
|
30
35
|
toolAgents?: Agent[];
|
|
31
36
|
}>;
|
|
32
37
|
buildPrompt(options: Pick<PromptBuildOptions, "input" | "context"> & {
|
|
@@ -37,11 +42,8 @@ export declare class PromptBuilder {
|
|
|
37
42
|
}>;
|
|
38
43
|
private getTemplateVariables;
|
|
39
44
|
private buildMessages;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
content: unknown;
|
|
43
|
-
}[]>;
|
|
44
|
-
private refineMessages;
|
|
45
|
+
private mergeMessages;
|
|
46
|
+
protected deprecatedMemories(message: string | undefined, options: PromptBuildOptions): Promise<ChatModelInputMessage[]>;
|
|
45
47
|
private convertMemoriesToMessages;
|
|
46
48
|
private buildResponseFormat;
|
|
47
49
|
private buildTools;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Agent, type AgentOptions, type Message } from "../../../../agents/agent.js";
|
|
2
|
+
import type { PromiseOrValue } from "../../../../utils/type-utils.js";
|
|
3
|
+
import type { Skill } from "./skill-loader.js";
|
|
4
|
+
export interface SkillToolInput extends Message {
|
|
5
|
+
skill: string;
|
|
6
|
+
args?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SkillToolOutput extends Message {
|
|
9
|
+
result: string;
|
|
10
|
+
}
|
|
11
|
+
export interface SkillToolOptions extends AgentOptions<SkillToolInput, SkillToolOutput> {
|
|
12
|
+
agentSkills: Skill[];
|
|
13
|
+
}
|
|
14
|
+
export declare class AgentSkill extends Agent<SkillToolInput, SkillToolOutput> {
|
|
15
|
+
formatOutput(output: SkillToolOutput | Message): PromiseOrValue<string>;
|
|
16
|
+
constructor(options: SkillToolOptions);
|
|
17
|
+
private agentSkills;
|
|
18
|
+
process(input: SkillToolInput): Promise<SkillToolOutput>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AFS } from "@aigne/afs";
|
|
2
|
+
import { AgentSkill } from "./agent-skill.js";
|
|
3
|
+
export interface Skill {
|
|
4
|
+
path: string;
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
content: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function discoverSkillsFromAFS(afs: AFS): Promise<Skill[]>;
|
|
10
|
+
export declare function loadAgentSkillFromAFS({ afs, }: {
|
|
11
|
+
afs: AFS;
|
|
12
|
+
}): Promise<AgentSkill | undefined>;
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
|
|
2
2
|
import { AFSSkillBase } from "./base.js";
|
|
3
|
-
export interface Patch {
|
|
4
|
-
start_line: number;
|
|
5
|
-
end_line: number;
|
|
6
|
-
replace?: string;
|
|
7
|
-
delete: boolean;
|
|
8
|
-
}
|
|
9
3
|
export interface AFSEditInput extends Message {
|
|
10
4
|
path: string;
|
|
11
|
-
|
|
5
|
+
oldString: string;
|
|
6
|
+
newString: string;
|
|
7
|
+
replaceAll?: boolean;
|
|
12
8
|
}
|
|
13
9
|
export interface AFSEditOutput extends Message {
|
|
14
10
|
status: string;
|
|
15
11
|
tool: string;
|
|
16
12
|
path: string;
|
|
17
13
|
message: string;
|
|
18
|
-
|
|
14
|
+
snippet: string;
|
|
19
15
|
}
|
|
20
16
|
export interface AFSEditAgentOptions extends AgentOptions<AFSEditInput, AFSEditOutput> {
|
|
21
17
|
afs: NonNullable<AgentOptions<AFSEditInput, AFSEditOutput>["afs"]>;
|
|
@@ -23,5 +19,6 @@ export interface AFSEditAgentOptions extends AgentOptions<AFSEditInput, AFSEditO
|
|
|
23
19
|
export declare class AFSEditAgent extends AFSSkillBase<AFSEditInput, AFSEditOutput> {
|
|
24
20
|
constructor(options: AFSEditAgentOptions);
|
|
25
21
|
process(input: AFSEditInput, _options: AgentInvokeOptions): Promise<AFSEditOutput>;
|
|
26
|
-
|
|
22
|
+
private countOccurrences;
|
|
23
|
+
private extractSnippet;
|
|
27
24
|
}
|
|
@@ -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
|
}
|
|
@@ -1,22 +1,28 @@
|
|
|
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;
|
|
6
|
-
|
|
7
|
+
offset?: number;
|
|
8
|
+
limit?: number;
|
|
7
9
|
}
|
|
8
10
|
export interface AFSReadOutput extends Message {
|
|
9
11
|
status: string;
|
|
10
12
|
tool: string;
|
|
11
13
|
path: string;
|
|
12
|
-
|
|
13
|
-
data?: AFSEntry;
|
|
14
|
+
data?: AFSEntry | null;
|
|
14
15
|
message?: string;
|
|
16
|
+
totalLines?: number;
|
|
17
|
+
returnedLines?: number;
|
|
18
|
+
truncated?: boolean;
|
|
19
|
+
offset?: number;
|
|
15
20
|
}
|
|
16
21
|
export interface AFSReadAgentOptions extends AgentOptions<AFSReadInput, AFSReadOutput> {
|
|
17
22
|
afs: NonNullable<AgentOptions<AFSReadInput, AFSReadOutput>["afs"]>;
|
|
18
23
|
}
|
|
19
24
|
export declare class AFSReadAgent extends AFSSkillBase<AFSReadInput, AFSReadOutput> {
|
|
20
25
|
constructor(options: AFSReadAgentOptions);
|
|
26
|
+
formatOutput(output: AFSReadOutput): PromiseOrValue<string>;
|
|
21
27
|
process(input: AFSReadInput, _options: AgentInvokeOptions): Promise<AFSReadOutput>;
|
|
22
28
|
}
|