@agentskit/memory 0.5.5 → 0.6.1
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/README.md +34 -6
- package/dist/index.cjs +516 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +239 -2
- package/dist/index.d.ts +239 -2
- package/dist/index.js +507 -1
- package/dist/index.js.map +1 -1
- package/package.json +13 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChatMemory, VectorMemory } from '@agentskit/core';
|
|
1
|
+
import { ChatMemory, VectorMemory, Message } from '@agentskit/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* ChatMemory backed by a JSON file on disk. Node-only.
|
|
@@ -70,4 +70,241 @@ interface FileVectorMemoryConfig {
|
|
|
70
70
|
}
|
|
71
71
|
declare function fileVectorMemory(config: FileVectorMemoryConfig): VectorMemory;
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Personalization — a persisted profile per subject (user id,
|
|
75
|
+
* account id, device). The agent reads it on every run to
|
|
76
|
+
* condition responses; the runtime updates it when new facts
|
|
77
|
+
* appear.
|
|
78
|
+
*/
|
|
79
|
+
interface PersonalizationProfile {
|
|
80
|
+
subjectId: string;
|
|
81
|
+
/** Human-editable notes, facts, preferences. */
|
|
82
|
+
traits: Record<string, unknown>;
|
|
83
|
+
/** ISO timestamp of the latest update. */
|
|
84
|
+
updatedAt: string;
|
|
85
|
+
}
|
|
86
|
+
interface PersonalizationStore {
|
|
87
|
+
get: (subjectId: string) => Promise<PersonalizationProfile | null>;
|
|
88
|
+
set: (profile: PersonalizationProfile) => Promise<void>;
|
|
89
|
+
merge: (subjectId: string, traits: Record<string, unknown>) => Promise<PersonalizationProfile>;
|
|
90
|
+
delete?: (subjectId: string) => Promise<void>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* In-memory personalization store — tests, single-process demos.
|
|
94
|
+
* Bring your own for production (Postgres, Redis, DynamoDB).
|
|
95
|
+
*/
|
|
96
|
+
declare function createInMemoryPersonalization(): PersonalizationStore;
|
|
97
|
+
/**
|
|
98
|
+
* Render a profile into a system-prompt fragment the runtime can
|
|
99
|
+
* prepend. Kept intentionally short — full profile dumps bloat
|
|
100
|
+
* context and leak unnecessary detail to the model.
|
|
101
|
+
*/
|
|
102
|
+
declare function renderProfileContext(profile: PersonalizationProfile | null): string;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Non-linear memory: a typed knowledge graph. Use for facts the
|
|
106
|
+
* agent should remember beyond a single conversation — entities,
|
|
107
|
+
* relationships, derived beliefs. Designed to be backed by anything
|
|
108
|
+
* from an in-memory Map (tests, demos) to Neo4j / Memgraph / Neptune.
|
|
109
|
+
*/
|
|
110
|
+
interface GraphNode<TProps = Record<string, unknown>> {
|
|
111
|
+
id: string;
|
|
112
|
+
/** Type / label — 'person', 'company', 'topic'. */
|
|
113
|
+
kind: string;
|
|
114
|
+
properties?: TProps;
|
|
115
|
+
/** ISO timestamp when the node was first inserted. */
|
|
116
|
+
createdAt?: string;
|
|
117
|
+
/** ISO timestamp of the latest update. */
|
|
118
|
+
updatedAt?: string;
|
|
119
|
+
}
|
|
120
|
+
interface GraphEdge<TProps = Record<string, unknown>> {
|
|
121
|
+
id: string;
|
|
122
|
+
/** Verb / relation type — 'knows', 'works-at', 'cites'. */
|
|
123
|
+
label: string;
|
|
124
|
+
from: string;
|
|
125
|
+
to: string;
|
|
126
|
+
/** Optional weight — confidence, recency, or frequency. */
|
|
127
|
+
weight?: number;
|
|
128
|
+
properties?: TProps;
|
|
129
|
+
}
|
|
130
|
+
interface GraphQuery {
|
|
131
|
+
kind?: string;
|
|
132
|
+
label?: string;
|
|
133
|
+
from?: string;
|
|
134
|
+
to?: string;
|
|
135
|
+
}
|
|
136
|
+
interface GraphMemory {
|
|
137
|
+
upsertNode: <T>(node: GraphNode<T>) => Promise<GraphNode<T>>;
|
|
138
|
+
upsertEdge: <T>(edge: GraphEdge<T>) => Promise<GraphEdge<T>>;
|
|
139
|
+
getNode: <T>(id: string) => Promise<GraphNode<T> | null>;
|
|
140
|
+
findNodes: <T>(query?: GraphQuery) => Promise<GraphNode<T>[]>;
|
|
141
|
+
findEdges: <T>(query?: GraphQuery) => Promise<GraphEdge<T>[]>;
|
|
142
|
+
/** Breadth-first neighbors of `id` up to `depth`. Default 1. */
|
|
143
|
+
neighbors: <T>(id: string, options?: {
|
|
144
|
+
depth?: number;
|
|
145
|
+
label?: string;
|
|
146
|
+
}) => Promise<GraphNode<T>[]>;
|
|
147
|
+
deleteNode: (id: string) => Promise<void>;
|
|
148
|
+
deleteEdge: (id: string) => Promise<void>;
|
|
149
|
+
clear?: () => Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* In-memory graph — fine for tests, single-process demos, and as
|
|
153
|
+
* reference for what a backing store needs to implement.
|
|
154
|
+
*/
|
|
155
|
+
declare function createInMemoryGraph(): GraphMemory;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* pgvector-backed VectorMemory. We accept a minimal async SQL runner
|
|
159
|
+
* so the caller picks the driver (`pg`, `postgres`, `@neondatabase/serverless`,
|
|
160
|
+
* `@supabase/postgres-js`, ...). Expects a table with columns
|
|
161
|
+
* `id text primary key`, `content text`, `embedding vector(N)`,
|
|
162
|
+
* `metadata jsonb`.
|
|
163
|
+
*/
|
|
164
|
+
interface PgVectorRunner {
|
|
165
|
+
query: <T = Record<string, unknown>>(sql: string, params: unknown[]) => Promise<{
|
|
166
|
+
rows: T[];
|
|
167
|
+
}>;
|
|
168
|
+
}
|
|
169
|
+
interface PgVectorConfig {
|
|
170
|
+
runner: PgVectorRunner;
|
|
171
|
+
/** Table name. Default 'agentskit_vectors'. */
|
|
172
|
+
table?: string;
|
|
173
|
+
/** Default topK for search. Default 10. */
|
|
174
|
+
topK?: number;
|
|
175
|
+
}
|
|
176
|
+
declare function pgvector(config: PgVectorConfig): VectorMemory;
|
|
177
|
+
|
|
178
|
+
interface PineconeConfig {
|
|
179
|
+
/** Full index URL, e.g. `https://<idx>-<project>.svc.<region>.pinecone.io`. */
|
|
180
|
+
indexUrl: string;
|
|
181
|
+
apiKey: string;
|
|
182
|
+
/** Namespace. Default ''. */
|
|
183
|
+
namespace?: string;
|
|
184
|
+
/** Default topK for search. Default 10. */
|
|
185
|
+
topK?: number;
|
|
186
|
+
fetch?: typeof globalThis.fetch;
|
|
187
|
+
}
|
|
188
|
+
declare function pinecone(config: PineconeConfig): VectorMemory;
|
|
189
|
+
|
|
190
|
+
interface QdrantConfig {
|
|
191
|
+
/** Base URL, e.g. `https://xxx.cluster-qdrant.io`. */
|
|
192
|
+
url: string;
|
|
193
|
+
apiKey?: string;
|
|
194
|
+
collection: string;
|
|
195
|
+
topK?: number;
|
|
196
|
+
fetch?: typeof globalThis.fetch;
|
|
197
|
+
}
|
|
198
|
+
declare function qdrant(config: QdrantConfig): VectorMemory;
|
|
199
|
+
|
|
200
|
+
interface ChromaConfig {
|
|
201
|
+
/** Base URL of a running Chroma HTTP server. */
|
|
202
|
+
url: string;
|
|
203
|
+
collection: string;
|
|
204
|
+
topK?: number;
|
|
205
|
+
fetch?: typeof globalThis.fetch;
|
|
206
|
+
}
|
|
207
|
+
declare function chroma(config: ChromaConfig): VectorMemory;
|
|
208
|
+
|
|
209
|
+
interface UpstashVectorConfig {
|
|
210
|
+
url: string;
|
|
211
|
+
token: string;
|
|
212
|
+
topK?: number;
|
|
213
|
+
fetch?: typeof globalThis.fetch;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Upstash Vector — HTTP-only serverless vector DB. The REST surface
|
|
217
|
+
* is tiny enough to implement directly without pulling the SDK.
|
|
218
|
+
*/
|
|
219
|
+
declare function upstashVector(config: UpstashVectorConfig): VectorMemory;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Client-side encrypted ChatMemory wrapper. Keys never leave the
|
|
223
|
+
* caller — the backing store only ever sees an opaque
|
|
224
|
+
* `{ iv, ct }` payload stashed in `metadata.ciphertext` and
|
|
225
|
+
* `metadata.iv`; `content` becomes an empty string so rogue
|
|
226
|
+
* middleware can't peek at it either.
|
|
227
|
+
*
|
|
228
|
+
* Uses Web Crypto (AES-GCM, 256-bit). Available on Node 20+ and all
|
|
229
|
+
* modern browsers. BYO key material — typically generated per-user
|
|
230
|
+
* during onboarding and stored only on their device.
|
|
231
|
+
*/
|
|
232
|
+
interface EncryptedMemoryOptions {
|
|
233
|
+
backing: ChatMemory;
|
|
234
|
+
/** 32-byte raw key (e.g. `crypto.getRandomValues(new Uint8Array(32))`). */
|
|
235
|
+
key: Uint8Array | CryptoKey;
|
|
236
|
+
/** Override for tests. Defaults to `globalThis.crypto.subtle`. */
|
|
237
|
+
subtle?: SubtleCrypto;
|
|
238
|
+
/** Random source. Defaults to `globalThis.crypto.getRandomValues`. */
|
|
239
|
+
getRandomValues?: <T extends ArrayBufferView>(array: T) => T;
|
|
240
|
+
/** Optional AAD — content that binds ciphertext to context (user id, room). */
|
|
241
|
+
aad?: Uint8Array;
|
|
242
|
+
}
|
|
243
|
+
interface EncryptedEnvelope {
|
|
244
|
+
ciphertext: string;
|
|
245
|
+
iv: string;
|
|
246
|
+
/** Plaintext-length marker so the agent sees a non-empty content hint. */
|
|
247
|
+
length: number;
|
|
248
|
+
}
|
|
249
|
+
declare function createEncryptedMemory(options: EncryptedMemoryOptions): Promise<ChatMemory>;
|
|
250
|
+
|
|
251
|
+
interface HierarchicalRecall {
|
|
252
|
+
/**
|
|
253
|
+
* Index a message for later retrieval. Called once per message as
|
|
254
|
+
* it moves from working → recall (usually: embed + store in a
|
|
255
|
+
* vector DB).
|
|
256
|
+
*/
|
|
257
|
+
index: (message: Message) => void | Promise<void>;
|
|
258
|
+
/**
|
|
259
|
+
* Given the hot working window, return up to `topK` messages from
|
|
260
|
+
* the recall tier that are relevant to the current turn. The hub
|
|
261
|
+
* splices results chronologically alongside the working window.
|
|
262
|
+
*/
|
|
263
|
+
query: (input: {
|
|
264
|
+
working: Message[];
|
|
265
|
+
topK: number;
|
|
266
|
+
}) => Message[] | Promise<Message[]>;
|
|
267
|
+
}
|
|
268
|
+
interface HierarchicalMemoryOptions {
|
|
269
|
+
/** Hot window — the messages always loaded in full. */
|
|
270
|
+
working: ChatMemory;
|
|
271
|
+
/** Cold storage — every message ever seen is written here. */
|
|
272
|
+
archival: ChatMemory;
|
|
273
|
+
/**
|
|
274
|
+
* Mid-term recall layer (usually a vector store). Optional;
|
|
275
|
+
* without it the hub behaves like virtualized memory with a hard
|
|
276
|
+
* backing store.
|
|
277
|
+
*/
|
|
278
|
+
recall?: HierarchicalRecall;
|
|
279
|
+
/**
|
|
280
|
+
* Maximum messages to keep in `working`. Older messages spill
|
|
281
|
+
* into recall + archival. Default 50.
|
|
282
|
+
*/
|
|
283
|
+
workingLimit?: number;
|
|
284
|
+
/**
|
|
285
|
+
* Max recalled messages to splice on each `load()`. Default 5.
|
|
286
|
+
*/
|
|
287
|
+
recallTopK?: number;
|
|
288
|
+
}
|
|
289
|
+
interface HierarchicalMemory extends ChatMemory {
|
|
290
|
+
/** Full archival history. Always the source of truth. */
|
|
291
|
+
archival: () => Promise<Message[]>;
|
|
292
|
+
/** Current working-window snapshot. */
|
|
293
|
+
working: () => Promise<Message[]>;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* MemGPT-style tiered memory. Three tiers:
|
|
297
|
+
* - working: always-loaded hot window (bounded by `workingLimit`).
|
|
298
|
+
* - recall: mid-term searchable layer (usually a vector store).
|
|
299
|
+
* - archival: cold store that always holds the full conversation.
|
|
300
|
+
*
|
|
301
|
+
* On every `save`, new messages are appended to archival, messages
|
|
302
|
+
* that overflow the working window are indexed into recall, and the
|
|
303
|
+
* working tier is trimmed to `workingLimit`.
|
|
304
|
+
*
|
|
305
|
+
* On every `load`, the hub returns working + up to `recallTopK`
|
|
306
|
+
* messages surfaced by the recall tier, spliced chronologically.
|
|
307
|
+
*/
|
|
308
|
+
declare function createHierarchicalMemory(options: HierarchicalMemoryOptions): HierarchicalMemory;
|
|
309
|
+
|
|
310
|
+
export { type ChromaConfig, type EncryptedEnvelope, type EncryptedMemoryOptions, type FileVectorMemoryConfig, type GraphEdge, type GraphMemory, type GraphNode, type GraphQuery, type HierarchicalMemory, type HierarchicalMemoryOptions, type HierarchicalRecall, type PersonalizationProfile, type PersonalizationStore, type PgVectorConfig, type PgVectorRunner, type PineconeConfig, type QdrantConfig, type RedisChatMemoryConfig, type RedisClientAdapter, type RedisConnectionConfig, type RedisVectorMemoryConfig, type SqliteChatMemoryConfig, type UpstashVectorConfig, type VectorStore, type VectorStoreDocument, type VectorStoreResult, chroma, createEncryptedMemory, createHierarchicalMemory, createInMemoryGraph, createInMemoryPersonalization, fileChatMemory, fileVectorMemory, pgvector, pinecone, qdrant, redisChatMemory, redisVectorMemory, renderProfileContext, sqliteChatMemory, upstashVector };
|