@reactive-agents/memory 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tyler Buell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # @reactive-agents/memory
2
+
3
+ Memory system for the [Reactive Agents](https://tylerjrbuell.github.io/reactive-agents-ts/) framework.
4
+
5
+ Four memory types backed by `bun:sqlite` — Working, Semantic, Episodic, and Procedural — with FTS5 full-text search (Tier 1) and optional vector embeddings (Tier 2).
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ bun add @reactive-agents/memory effect
11
+ ```
12
+
13
+ > **Requires Bun** — uses `bun:sqlite` natively.
14
+
15
+ ## Memory Types
16
+
17
+ | Type | Purpose | Backend |
18
+ |------|---------|---------|
19
+ | Working | Short-term in-session context | SQLite in-memory |
20
+ | Semantic | Long-term knowledge store | SQLite + FTS5 |
21
+ | Episodic | Conversation history | SQLite |
22
+ | Procedural | Learned workflows | SQLite |
23
+
24
+ ## Tiers
25
+
26
+ - **Tier 1** — FTS5 full-text search. Fast, no external API needed.
27
+ - **Tier 2** — `sqlite-vec` KNN vector search. Requires an embedding provider.
28
+
29
+ ## Usage
30
+
31
+ ```typescript
32
+ import { ReactiveAgents } from "reactive-agents";
33
+
34
+ const agent = await ReactiveAgents.create()
35
+ .withName("my-agent")
36
+ .withProvider("anthropic")
37
+ .withMemory("1") // Tier 1: FTS5
38
+ // .withMemory("2") // Tier 2: vector embeddings
39
+ .build();
40
+ ```
41
+
42
+ ## Environment Variables (Tier 2 only)
43
+
44
+ ```bash
45
+ EMBEDDING_PROVIDER=openai
46
+ EMBEDDING_MODEL=text-embedding-3-small
47
+ OPENAI_API_KEY=sk-...
48
+ ```
49
+
50
+ ## Documentation
51
+
52
+ Full documentation at [tylerjrbuell.github.io/reactive-agents-ts/guides/memory/](https://tylerjrbuell.github.io/reactive-agents-ts/guides/memory/)
@@ -0,0 +1,516 @@
1
+ import { Schema, Context, Effect, Layer } from 'effect';
2
+ import * as effect_Cause from 'effect/Cause';
3
+ import * as effect_Types from 'effect/Types';
4
+
5
+ declare const MemoryId: Schema.brand<typeof Schema.String, "MemoryId">;
6
+ type MemoryId = typeof MemoryId.Type;
7
+ declare const MemoryType: Schema.Literal<["semantic", "episodic", "procedural", "working"]>;
8
+ type MemoryType = typeof MemoryType.Type;
9
+ declare const MemorySourceSchema: Schema.Struct<{
10
+ type: Schema.Literal<["agent", "user", "tool", "system", "llm-extraction"]>;
11
+ id: typeof Schema.String;
12
+ taskId: Schema.optional<typeof Schema.String>;
13
+ }>;
14
+ type MemorySource = typeof MemorySourceSchema.Type;
15
+ declare const MemoryEntrySchema: Schema.Struct<{
16
+ id: Schema.brand<typeof Schema.String, "MemoryId">;
17
+ agentId: typeof Schema.String;
18
+ type: Schema.Literal<["semantic", "episodic", "procedural", "working"]>;
19
+ content: typeof Schema.String;
20
+ importance: Schema.filter<typeof Schema.Number>;
21
+ createdAt: typeof Schema.DateFromSelf;
22
+ updatedAt: typeof Schema.DateFromSelf;
23
+ source: Schema.Struct<{
24
+ type: Schema.Literal<["agent", "user", "tool", "system", "llm-extraction"]>;
25
+ id: typeof Schema.String;
26
+ taskId: Schema.optional<typeof Schema.String>;
27
+ }>;
28
+ tags: Schema.Array$<typeof Schema.String>;
29
+ metadata: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
30
+ }>;
31
+ type MemoryEntry = typeof MemoryEntrySchema.Type;
32
+ declare const SemanticEntrySchema: Schema.Struct<{
33
+ id: Schema.brand<typeof Schema.String, "MemoryId">;
34
+ agentId: typeof Schema.String;
35
+ content: typeof Schema.String;
36
+ summary: typeof Schema.String;
37
+ importance: Schema.filter<typeof Schema.Number>;
38
+ verified: typeof Schema.Boolean;
39
+ tags: Schema.Array$<typeof Schema.String>;
40
+ embedding: Schema.optional<Schema.Array$<typeof Schema.Number>>;
41
+ createdAt: typeof Schema.DateFromSelf;
42
+ updatedAt: typeof Schema.DateFromSelf;
43
+ accessCount: typeof Schema.Number;
44
+ lastAccessedAt: typeof Schema.DateFromSelf;
45
+ }>;
46
+ type SemanticEntry = typeof SemanticEntrySchema.Type;
47
+ declare const DailyLogEntrySchema: Schema.Struct<{
48
+ id: Schema.brand<typeof Schema.String, "MemoryId">;
49
+ agentId: typeof Schema.String;
50
+ date: typeof Schema.String;
51
+ content: typeof Schema.String;
52
+ taskId: Schema.optional<typeof Schema.String>;
53
+ eventType: Schema.Literal<["task-started", "task-completed", "task-failed", "decision-made", "error-encountered", "user-feedback", "tool-call", "observation"]>;
54
+ cost: Schema.optional<typeof Schema.Number>;
55
+ duration: Schema.optional<typeof Schema.Number>;
56
+ metadata: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
57
+ createdAt: typeof Schema.DateFromSelf;
58
+ }>;
59
+ type DailyLogEntry = typeof DailyLogEntrySchema.Type;
60
+ declare const SessionSnapshotSchema: Schema.Struct<{
61
+ id: typeof Schema.String;
62
+ agentId: typeof Schema.String;
63
+ messages: Schema.Array$<typeof Schema.Unknown>;
64
+ summary: typeof Schema.String;
65
+ keyDecisions: Schema.Array$<typeof Schema.String>;
66
+ taskIds: Schema.Array$<typeof Schema.String>;
67
+ startedAt: typeof Schema.DateFromSelf;
68
+ endedAt: typeof Schema.DateFromSelf;
69
+ totalCost: typeof Schema.Number;
70
+ totalTokens: typeof Schema.Number;
71
+ }>;
72
+ type SessionSnapshot = typeof SessionSnapshotSchema.Type;
73
+ declare const ProceduralEntrySchema: Schema.Struct<{
74
+ id: Schema.brand<typeof Schema.String, "MemoryId">;
75
+ agentId: typeof Schema.String;
76
+ name: typeof Schema.String;
77
+ description: typeof Schema.String;
78
+ pattern: typeof Schema.String;
79
+ successRate: Schema.filter<typeof Schema.Number>;
80
+ useCount: typeof Schema.Number;
81
+ tags: Schema.Array$<typeof Schema.String>;
82
+ createdAt: typeof Schema.DateFromSelf;
83
+ updatedAt: typeof Schema.DateFromSelf;
84
+ }>;
85
+ type ProceduralEntry = typeof ProceduralEntrySchema.Type;
86
+ declare const WorkingMemoryItemSchema: Schema.Struct<{
87
+ id: Schema.brand<typeof Schema.String, "MemoryId">;
88
+ content: typeof Schema.String;
89
+ importance: Schema.filter<typeof Schema.Number>;
90
+ addedAt: typeof Schema.DateFromSelf;
91
+ source: Schema.Struct<{
92
+ type: Schema.Literal<["agent", "user", "tool", "system", "llm-extraction"]>;
93
+ id: typeof Schema.String;
94
+ taskId: Schema.optional<typeof Schema.String>;
95
+ }>;
96
+ }>;
97
+ type WorkingMemoryItem = typeof WorkingMemoryItemSchema.Type;
98
+ declare const LinkType: Schema.Literal<["similar", "sequential", "causal", "contradicts", "supports", "elaborates"]>;
99
+ type LinkType = typeof LinkType.Type;
100
+ declare const ZettelLinkSchema: Schema.Struct<{
101
+ source: Schema.brand<typeof Schema.String, "MemoryId">;
102
+ target: Schema.brand<typeof Schema.String, "MemoryId">;
103
+ strength: Schema.filter<typeof Schema.Number>;
104
+ type: Schema.Literal<["similar", "sequential", "causal", "contradicts", "supports", "elaborates"]>;
105
+ createdAt: typeof Schema.DateFromSelf;
106
+ }>;
107
+ type ZettelLink = typeof ZettelLinkSchema.Type;
108
+ declare const CompactionStrategySchema: Schema.Literal<["count", "time", "semantic", "progressive"]>;
109
+ type CompactionStrategy = typeof CompactionStrategySchema.Type;
110
+ declare const CompactionConfigSchema: Schema.Struct<{
111
+ strategy: Schema.Literal<["count", "time", "semantic", "progressive"]>;
112
+ maxEntries: Schema.optional<typeof Schema.Number>;
113
+ intervalMs: Schema.optional<typeof Schema.Number>;
114
+ similarityThreshold: Schema.optional<typeof Schema.Number>;
115
+ decayFactor: Schema.optional<typeof Schema.Number>;
116
+ }>;
117
+ type CompactionConfig = typeof CompactionConfigSchema.Type;
118
+ declare const SearchOptionsSchema: Schema.Struct<{
119
+ query: typeof Schema.String;
120
+ types: Schema.optional<Schema.Array$<Schema.Literal<["semantic", "episodic", "procedural", "working"]>>>;
121
+ limit: Schema.optional<typeof Schema.Number>;
122
+ threshold: Schema.optional<typeof Schema.Number>;
123
+ useVector: Schema.optional<typeof Schema.Boolean>;
124
+ agentId: typeof Schema.String;
125
+ }>;
126
+ type SearchOptions = typeof SearchOptionsSchema.Type;
127
+ declare const MemoryBootstrapResultSchema: Schema.Struct<{
128
+ agentId: typeof Schema.String;
129
+ semanticContext: typeof Schema.String;
130
+ recentEpisodes: Schema.Array$<Schema.Struct<{
131
+ id: Schema.brand<typeof Schema.String, "MemoryId">;
132
+ agentId: typeof Schema.String;
133
+ date: typeof Schema.String;
134
+ content: typeof Schema.String;
135
+ taskId: Schema.optional<typeof Schema.String>;
136
+ eventType: Schema.Literal<["task-started", "task-completed", "task-failed", "decision-made", "error-encountered", "user-feedback", "tool-call", "observation"]>;
137
+ cost: Schema.optional<typeof Schema.Number>;
138
+ duration: Schema.optional<typeof Schema.Number>;
139
+ metadata: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
140
+ createdAt: typeof Schema.DateFromSelf;
141
+ }>>;
142
+ activeWorkflows: Schema.Array$<Schema.Struct<{
143
+ id: Schema.brand<typeof Schema.String, "MemoryId">;
144
+ agentId: typeof Schema.String;
145
+ name: typeof Schema.String;
146
+ description: typeof Schema.String;
147
+ pattern: typeof Schema.String;
148
+ successRate: Schema.filter<typeof Schema.Number>;
149
+ useCount: typeof Schema.Number;
150
+ tags: Schema.Array$<typeof Schema.String>;
151
+ createdAt: typeof Schema.DateFromSelf;
152
+ updatedAt: typeof Schema.DateFromSelf;
153
+ }>>;
154
+ workingMemory: Schema.Array$<Schema.Struct<{
155
+ id: Schema.brand<typeof Schema.String, "MemoryId">;
156
+ content: typeof Schema.String;
157
+ importance: Schema.filter<typeof Schema.Number>;
158
+ addedAt: typeof Schema.DateFromSelf;
159
+ source: Schema.Struct<{
160
+ type: Schema.Literal<["agent", "user", "tool", "system", "llm-extraction"]>;
161
+ id: typeof Schema.String;
162
+ taskId: Schema.optional<typeof Schema.String>;
163
+ }>;
164
+ }>>;
165
+ bootstrappedAt: typeof Schema.DateFromSelf;
166
+ tier: Schema.Literal<["1", "2"]>;
167
+ }>;
168
+ type MemoryBootstrapResult = typeof MemoryBootstrapResultSchema.Type;
169
+ declare const EvictionPolicy: Schema.Literal<["fifo", "lru", "importance"]>;
170
+ type EvictionPolicy = typeof EvictionPolicy.Type;
171
+ declare const MemoryConfigSchema: Schema.Struct<{
172
+ tier: Schema.Literal<["1", "2"]>;
173
+ agentId: typeof Schema.String;
174
+ dbPath: typeof Schema.String;
175
+ working: Schema.Struct<{
176
+ capacity: typeof Schema.Number;
177
+ evictionPolicy: Schema.Literal<["fifo", "lru", "importance"]>;
178
+ }>;
179
+ semantic: Schema.Struct<{
180
+ maxMarkdownLines: typeof Schema.Number;
181
+ importanceThreshold: typeof Schema.Number;
182
+ }>;
183
+ episodic: Schema.Struct<{
184
+ retainDays: typeof Schema.Number;
185
+ maxSnapshotsPerSession: typeof Schema.Number;
186
+ }>;
187
+ compaction: Schema.Struct<{
188
+ strategy: Schema.Literal<["count", "time", "semantic", "progressive"]>;
189
+ maxEntries: Schema.optional<typeof Schema.Number>;
190
+ intervalMs: Schema.optional<typeof Schema.Number>;
191
+ similarityThreshold: Schema.optional<typeof Schema.Number>;
192
+ decayFactor: Schema.optional<typeof Schema.Number>;
193
+ }>;
194
+ zettelkasten: Schema.Struct<{
195
+ enabled: typeof Schema.Boolean;
196
+ linkingThreshold: Schema.filter<typeof Schema.Number>;
197
+ maxLinksPerEntry: typeof Schema.Number;
198
+ }>;
199
+ }>;
200
+ type MemoryConfig = typeof MemoryConfigSchema.Type;
201
+ declare const defaultMemoryConfig: (agentId: string) => MemoryConfig;
202
+
203
+ declare const MemoryError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
204
+ readonly _tag: "MemoryError";
205
+ } & Readonly<A>;
206
+ declare class MemoryError extends MemoryError_base<{
207
+ readonly message: string;
208
+ readonly cause?: unknown;
209
+ }> {
210
+ }
211
+ declare const MemoryNotFoundError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
212
+ readonly _tag: "MemoryNotFoundError";
213
+ } & Readonly<A>;
214
+ declare class MemoryNotFoundError extends MemoryNotFoundError_base<{
215
+ readonly memoryId: string;
216
+ readonly message: string;
217
+ }> {
218
+ }
219
+ declare const DatabaseError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
220
+ readonly _tag: "DatabaseError";
221
+ } & Readonly<A>;
222
+ declare class DatabaseError extends DatabaseError_base<{
223
+ readonly message: string;
224
+ readonly operation: "read" | "write" | "delete" | "search" | "migrate";
225
+ readonly cause?: unknown;
226
+ }> {
227
+ }
228
+ declare const CapacityExceededError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
229
+ readonly _tag: "CapacityExceededError";
230
+ } & Readonly<A>;
231
+ declare class CapacityExceededError extends CapacityExceededError_base<{
232
+ readonly message: string;
233
+ readonly capacity: number;
234
+ readonly current: number;
235
+ }> {
236
+ }
237
+ declare const ContextError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
238
+ readonly _tag: "ContextError";
239
+ } & Readonly<A>;
240
+ declare class ContextError extends ContextError_base<{
241
+ readonly message: string;
242
+ readonly cause?: unknown;
243
+ }> {
244
+ }
245
+ declare const CompactionError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
246
+ readonly _tag: "CompactionError";
247
+ } & Readonly<A>;
248
+ declare class CompactionError extends CompactionError_base<{
249
+ readonly message: string;
250
+ readonly strategy: string;
251
+ readonly cause?: unknown;
252
+ }> {
253
+ }
254
+ declare const SearchError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
255
+ readonly _tag: "SearchError";
256
+ } & Readonly<A>;
257
+ declare class SearchError extends SearchError_base<{
258
+ readonly message: string;
259
+ readonly cause?: unknown;
260
+ }> {
261
+ }
262
+ declare const ExtractionError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
263
+ readonly _tag: "ExtractionError";
264
+ } & Readonly<A>;
265
+ declare class ExtractionError extends ExtractionError_base<{
266
+ readonly message: string;
267
+ readonly cause?: unknown;
268
+ }> {
269
+ }
270
+
271
+ interface MemoryDatabaseService {
272
+ /** Execute a query with parameters. Returns rows. */
273
+ readonly query: <T = Record<string, unknown>>(sql: string, params?: readonly unknown[]) => Effect.Effect<T[], DatabaseError>;
274
+ /** Execute a statement (INSERT/UPDATE/DELETE). Returns changes count. */
275
+ readonly exec: (sql: string, params?: readonly unknown[]) => Effect.Effect<number, DatabaseError>;
276
+ /** Execute multiple statements in a transaction. */
277
+ readonly transaction: <T>(fn: (db: MemoryDatabaseService) => Effect.Effect<T, DatabaseError>) => Effect.Effect<T, DatabaseError>;
278
+ /** Close the database connection. */
279
+ readonly close: () => Effect.Effect<void, never>;
280
+ }
281
+ declare const MemoryDatabase_base: Context.TagClass<MemoryDatabase, "MemoryDatabase", MemoryDatabaseService>;
282
+ declare class MemoryDatabase extends MemoryDatabase_base {
283
+ }
284
+ declare const MemoryDatabaseLive: (config: MemoryConfig) => Layer.Layer<MemoryDatabase, DatabaseError, never>;
285
+
286
+ declare const MemorySearchService_base: Context.TagClass<MemorySearchService, "MemorySearchService", {
287
+ /** Full-text search across semantic memory (FTS5). Tier 1 + 2. */
288
+ readonly searchSemantic: (options: SearchOptions) => Effect.Effect<SemanticEntry[], DatabaseError>;
289
+ /** Full-text search across episodic log (FTS5). Tier 1 + 2. */
290
+ readonly searchEpisodic: (options: SearchOptions) => Effect.Effect<DailyLogEntry[], DatabaseError>;
291
+ /**
292
+ * Vector KNN search across semantic memory (sqlite-vec). Tier 2 only.
293
+ * Returns DatabaseError if vec0 extension not loaded.
294
+ */
295
+ readonly searchVector: (queryEmbedding: readonly number[], agentId: string, limit: number) => Effect.Effect<SemanticEntry[], DatabaseError>;
296
+ }>;
297
+ declare class MemorySearchService extends MemorySearchService_base {
298
+ }
299
+ declare const MemorySearchServiceLive: Layer.Layer<MemorySearchService, never, MemoryDatabase>;
300
+
301
+ declare const WorkingMemoryService_base: Context.TagClass<WorkingMemoryService, "WorkingMemoryService", {
302
+ /** Add item to working memory. Evicts according to policy if at capacity. */
303
+ readonly add: (item: WorkingMemoryItem) => Effect.Effect<void, never>;
304
+ /** Get all items in working memory (newest first). */
305
+ readonly get: () => Effect.Effect<readonly WorkingMemoryItem[], never>;
306
+ /** Clear all items. */
307
+ readonly clear: () => Effect.Effect<void, never>;
308
+ /** Evict one item according to policy and return it. */
309
+ readonly evict: () => Effect.Effect<WorkingMemoryItem, MemoryError>;
310
+ /** Current count. */
311
+ readonly size: () => Effect.Effect<number, never>;
312
+ /** Find item by content similarity (text contains). */
313
+ readonly find: (query: string) => Effect.Effect<readonly WorkingMemoryItem[], never>;
314
+ }>;
315
+ declare class WorkingMemoryService extends WorkingMemoryService_base {
316
+ }
317
+ declare const WorkingMemoryServiceLive: (capacity?: number, evictionPolicy?: EvictionPolicy) => Layer.Layer<WorkingMemoryService, never, never>;
318
+
319
+ declare const SemanticMemoryService_base: Context.TagClass<SemanticMemoryService, "SemanticMemoryService", {
320
+ /** Store a semantic memory entry. */
321
+ readonly store: (entry: SemanticEntry) => Effect.Effect<MemoryId, DatabaseError>;
322
+ /** Get entry by ID. */
323
+ readonly get: (id: MemoryId) => Effect.Effect<SemanticEntry, MemoryNotFoundError | DatabaseError>;
324
+ /** Update an existing entry. */
325
+ readonly update: (id: MemoryId, patch: Partial<Pick<SemanticEntry, "content" | "summary" | "importance" | "verified" | "tags">>) => Effect.Effect<void, DatabaseError>;
326
+ /** Delete an entry. */
327
+ readonly delete: (id: MemoryId) => Effect.Effect<void, DatabaseError>;
328
+ /** Get all entries for an agent, sorted by importance desc. */
329
+ readonly listByAgent: (agentId: string, limit?: number) => Effect.Effect<SemanticEntry[], DatabaseError>;
330
+ /** Increment access count and update last_accessed_at. */
331
+ readonly recordAccess: (id: MemoryId) => Effect.Effect<void, DatabaseError>;
332
+ /** Generate memory.md projection (top N entries by importance, max 200 lines). */
333
+ readonly generateMarkdown: (agentId: string, maxLines?: number) => Effect.Effect<string, DatabaseError>;
334
+ }>;
335
+ declare class SemanticMemoryService extends SemanticMemoryService_base {
336
+ }
337
+ declare const SemanticMemoryServiceLive: Layer.Layer<SemanticMemoryService, never, MemoryDatabase>;
338
+
339
+ declare const EpisodicMemoryService_base: Context.TagClass<EpisodicMemoryService, "EpisodicMemoryService", {
340
+ /** Log an episodic event. */
341
+ readonly log: (entry: DailyLogEntry) => Effect.Effect<MemoryId, DatabaseError>;
342
+ /** Get today's log for an agent. */
343
+ readonly getToday: (agentId: string) => Effect.Effect<DailyLogEntry[], DatabaseError>;
344
+ /** Get recent log entries (newest first). */
345
+ readonly getRecent: (agentId: string, limit: number) => Effect.Effect<DailyLogEntry[], DatabaseError>;
346
+ /** Get entries by task ID. */
347
+ readonly getByTask: (taskId: string) => Effect.Effect<DailyLogEntry[], DatabaseError>;
348
+ /** Save a session snapshot. */
349
+ readonly saveSnapshot: (snapshot: SessionSnapshot) => Effect.Effect<void, DatabaseError>;
350
+ /** Get the most recent session snapshot for an agent. */
351
+ readonly getLatestSnapshot: (agentId: string) => Effect.Effect<SessionSnapshot | null, DatabaseError>;
352
+ /** Prune entries older than retainDays. */
353
+ readonly prune: (agentId: string, retainDays: number) => Effect.Effect<number, DatabaseError>;
354
+ }>;
355
+ declare class EpisodicMemoryService extends EpisodicMemoryService_base {
356
+ }
357
+ declare const EpisodicMemoryServiceLive: Layer.Layer<EpisodicMemoryService, never, MemoryDatabase>;
358
+
359
+ declare const ProceduralMemoryService_base: Context.TagClass<ProceduralMemoryService, "ProceduralMemoryService", {
360
+ /** Store a new workflow/pattern. */
361
+ readonly store: (entry: ProceduralEntry) => Effect.Effect<MemoryId, DatabaseError>;
362
+ /** Get workflow by ID. */
363
+ readonly get: (id: MemoryId) => Effect.Effect<ProceduralEntry, MemoryNotFoundError | DatabaseError>;
364
+ /** Update success rate and use count after execution. */
365
+ readonly recordOutcome: (id: MemoryId, success: boolean) => Effect.Effect<void, DatabaseError>;
366
+ /** List active workflows for an agent (sorted by success rate). */
367
+ readonly listActive: (agentId: string) => Effect.Effect<ProceduralEntry[], DatabaseError>;
368
+ /** Find workflows matching tags. */
369
+ readonly findByTags: (agentId: string, tags: readonly string[]) => Effect.Effect<ProceduralEntry[], DatabaseError>;
370
+ }>;
371
+ declare class ProceduralMemoryService extends ProceduralMemoryService_base {
372
+ }
373
+ declare const ProceduralMemoryServiceLive: Layer.Layer<ProceduralMemoryService, never, MemoryDatabase>;
374
+
375
+ declare const MemoryFileSystem_base: Context.TagClass<MemoryFileSystem, "MemoryFileSystem", {
376
+ /** Write memory.md projection for an agent. */
377
+ readonly writeMarkdown: (agentId: string, content: string, basePath: string) => Effect.Effect<void, MemoryError>;
378
+ /** Read memory.md for bootstrap. Returns empty string if not found. */
379
+ readonly readMarkdown: (agentId: string, basePath: string) => Effect.Effect<string, MemoryError>;
380
+ /** Ensure agent memory directory exists. */
381
+ readonly ensureDirectory: (agentId: string, basePath: string) => Effect.Effect<void, MemoryError>;
382
+ }>;
383
+ declare class MemoryFileSystem extends MemoryFileSystem_base {
384
+ }
385
+ declare const MemoryFileSystemLive: Layer.Layer<MemoryFileSystem, never, never>;
386
+
387
+ declare const ZettelkastenService_base: Context.TagClass<ZettelkastenService, "ZettelkastenService", {
388
+ /** Add a link between two memory entries. */
389
+ readonly addLink: (link: ZettelLink) => Effect.Effect<void, DatabaseError>;
390
+ /** Get all links for a memory ID (as source or target). */
391
+ readonly getLinks: (memoryId: MemoryId) => Effect.Effect<ZettelLink[], DatabaseError>;
392
+ /** Get IDs of all memories linked to a given ID. */
393
+ readonly getLinked: (memoryId: MemoryId) => Effect.Effect<MemoryId[], DatabaseError>;
394
+ /** Traverse link graph up to `depth` hops from startId. */
395
+ readonly traverse: (startId: MemoryId, depth: number) => Effect.Effect<MemoryId[], DatabaseError>;
396
+ /** Delete all links for a memory (when entry is deleted). */
397
+ readonly deleteLinks: (memoryId: MemoryId) => Effect.Effect<void, DatabaseError>;
398
+ /**
399
+ * Auto-link via FTS5 similarity (find semantically similar entries
400
+ * and create "similar" links if above threshold).
401
+ */
402
+ readonly autoLinkText: (memoryId: MemoryId, content: string, agentId: string, threshold?: number) => Effect.Effect<ZettelLink[], DatabaseError>;
403
+ }>;
404
+ declare class ZettelkastenService extends ZettelkastenService_base {
405
+ }
406
+ declare const ZettelkastenServiceLive: Layer.Layer<ZettelkastenService, never, MemoryDatabase>;
407
+
408
+ declare const MemoryService_base: Context.TagClass<MemoryService, "MemoryService", {
409
+ /**
410
+ * Bootstrap: load semantic context + recent episodes for agent.
411
+ * Called by ExecutionEngine at Phase 1 (BOOTSTRAP).
412
+ */
413
+ readonly bootstrap: (agentId: string) => Effect.Effect<MemoryBootstrapResult, MemoryError | DatabaseError>;
414
+ /**
415
+ * Flush: generate memory.md projection from SQLite and write to disk.
416
+ */
417
+ readonly flush: (agentId: string) => Effect.Effect<void, MemoryError | DatabaseError>;
418
+ /**
419
+ * Snapshot: save session messages to episodic SQLite storage.
420
+ */
421
+ readonly snapshot: (snapshot: SessionSnapshot) => Effect.Effect<void, DatabaseError>;
422
+ /**
423
+ * Store a working memory item (adds to in-process Ref).
424
+ */
425
+ readonly addToWorking: (item: WorkingMemoryItem) => Effect.Effect<void, never>;
426
+ /**
427
+ * Store a semantic memory entry (persists to SQLite).
428
+ * Auto-links via Zettelkasten if enabled.
429
+ */
430
+ readonly storeSemantic: (entry: SemanticEntry) => Effect.Effect<MemoryId, DatabaseError>;
431
+ /**
432
+ * Log an episodic event (persists to SQLite).
433
+ */
434
+ readonly logEpisode: (entry: DailyLogEntry) => Effect.Effect<MemoryId, DatabaseError>;
435
+ /**
436
+ * Get current working memory contents.
437
+ */
438
+ readonly getWorking: () => Effect.Effect<readonly WorkingMemoryItem[], never>;
439
+ }>;
440
+ declare class MemoryService extends MemoryService_base {
441
+ }
442
+ declare const MemoryServiceLive: (config: MemoryConfig) => Layer.Layer<MemoryService, never, WorkingMemoryService | SemanticMemoryService | EpisodicMemoryService | ProceduralMemoryService | MemoryFileSystem | ZettelkastenService>;
443
+
444
+ declare const CompactionService_base: Context.TagClass<CompactionService, "CompactionService", {
445
+ /** Run compaction for an agent using the given strategy. */
446
+ readonly compact: (agentId: string, config: CompactionConfig) => Effect.Effect<number, CompactionError | DatabaseError>;
447
+ /** Count-based compaction: remove lowest-importance entries above threshold. */
448
+ readonly compactByCount: (agentId: string, maxEntries: number) => Effect.Effect<number, DatabaseError>;
449
+ /** Time-based compaction: remove entries older than interval. */
450
+ readonly compactByTime: (agentId: string, intervalMs: number) => Effect.Effect<number, DatabaseError>;
451
+ /** Semantic compaction: merge near-duplicate entries (by FTS5 similarity). */
452
+ readonly compactBySimilarity: (agentId: string, threshold: number) => Effect.Effect<number, DatabaseError>;
453
+ /** Progressive compaction: count -> time -> decay. */
454
+ readonly compactProgressive: (agentId: string, config: CompactionConfig) => Effect.Effect<number, DatabaseError>;
455
+ }>;
456
+ declare class CompactionService extends CompactionService_base {
457
+ }
458
+ declare const CompactionServiceLive: Layer.Layer<CompactionService, never, MemoryDatabase>;
459
+
460
+ declare const MemoryExtractor_base: Context.TagClass<MemoryExtractor, "MemoryExtractor", {
461
+ /**
462
+ * Extract semantic memories from a conversation.
463
+ * In Tier 1, this uses simple heuristic extraction (no LLM).
464
+ * In Tier 2, this uses LLMService for intelligent extraction.
465
+ */
466
+ readonly extractFromConversation: (agentId: string, messages: readonly {
467
+ role: string;
468
+ content: string;
469
+ }[]) => Effect.Effect<SemanticEntry[], ExtractionError>;
470
+ /**
471
+ * Extract episodic events from a conversation.
472
+ */
473
+ readonly extractEpisodic: (agentId: string, messages: readonly {
474
+ role: string;
475
+ content: string;
476
+ }[]) => Effect.Effect<DailyLogEntry[], ExtractionError>;
477
+ }>;
478
+ declare class MemoryExtractor extends MemoryExtractor_base {
479
+ }
480
+ declare const MemoryExtractorLive: Layer.Layer<MemoryExtractor, never, never>;
481
+
482
+ declare const MemoryConsolidator_base: Context.TagClass<MemoryConsolidator, "MemoryConsolidator", {
483
+ /**
484
+ * Run a consolidation cycle: merge near-duplicates, decay old entries,
485
+ * promote high-access entries.
486
+ * Returns the number of entries affected.
487
+ */
488
+ readonly consolidate: (agentId: string) => Effect.Effect<number, DatabaseError>;
489
+ /**
490
+ * Decay importance of entries that haven't been accessed recently.
491
+ */
492
+ readonly decayUnused: (agentId: string, decayFactor: number) => Effect.Effect<number, DatabaseError>;
493
+ /**
494
+ * Promote entries that have high access counts.
495
+ */
496
+ readonly promoteActive: (agentId: string) => Effect.Effect<number, DatabaseError>;
497
+ }>;
498
+ declare class MemoryConsolidator extends MemoryConsolidator_base {
499
+ }
500
+ declare const MemoryConsolidatorLive: (config: MemoryConfig) => Layer.Layer<MemoryConsolidator, never, MemoryDatabase>;
501
+
502
+ /**
503
+ * Create the complete memory layer.
504
+ *
505
+ * Tier 1 (zero deps): FTS5 full-text search only.
506
+ * Tier 2 (sqlite-vec): FTS5 + KNN vector search.
507
+ *
508
+ * Usage:
509
+ * const MemoryLive = createMemoryLayer("1", { agentId: "my-agent" });
510
+ * myProgram.pipe(Effect.provide(MemoryLive));
511
+ */
512
+ declare const createMemoryLayer: (tier: "1" | "2", configOverrides?: Partial<MemoryConfig> & {
513
+ agentId: string;
514
+ }) => Layer.Layer<MemoryDatabase | MemorySearchService | WorkingMemoryService | SemanticMemoryService | EpisodicMemoryService | ProceduralMemoryService | MemoryFileSystem | ZettelkastenService | MemoryService, DatabaseError, never>;
515
+
516
+ export { CapacityExceededError, type CompactionConfig, CompactionConfigSchema, CompactionError, CompactionService, CompactionServiceLive, type CompactionStrategy, CompactionStrategySchema, ContextError, type DailyLogEntry, DailyLogEntrySchema, DatabaseError, EpisodicMemoryService, EpisodicMemoryServiceLive, EvictionPolicy, EvictionPolicy as EvictionPolicySchema, ExtractionError, LinkType, LinkType as LinkTypeSchema, type MemoryBootstrapResult, MemoryBootstrapResultSchema, type MemoryConfig, MemoryConfigSchema, MemoryConsolidator, MemoryConsolidatorLive, MemoryDatabase, MemoryDatabaseLive, type MemoryDatabaseService, type MemoryEntry, MemoryEntrySchema, MemoryError, MemoryExtractor, MemoryExtractorLive, MemoryFileSystem, MemoryFileSystemLive, MemoryId, MemoryId as MemoryIdSchema, MemoryNotFoundError, MemorySearchService, MemorySearchServiceLive, MemoryService, MemoryServiceLive, type MemorySource, MemorySourceSchema, MemoryType, MemoryType as MemoryTypeSchema, type ProceduralEntry, ProceduralEntrySchema, ProceduralMemoryService, ProceduralMemoryServiceLive, SearchError, type SearchOptions, SearchOptionsSchema, type SemanticEntry, SemanticEntrySchema, SemanticMemoryService, SemanticMemoryServiceLive, type SessionSnapshot, SessionSnapshotSchema, type WorkingMemoryItem, WorkingMemoryItemSchema, WorkingMemoryService, WorkingMemoryServiceLive, type ZettelLink, ZettelLinkSchema, ZettelkastenService, ZettelkastenServiceLive, createMemoryLayer, defaultMemoryConfig };