memo-grafter 0.2.3 → 0.2.4
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/USER_GUIDE.md +200 -68
- package/dist/MemoGrafterAgent.d.ts.map +1 -1
- package/dist/MemoGrafterAgent.js +2 -0
- package/dist/MemoGrafterAgent.js.map +1 -1
- package/dist/crawler/ConflictDetectionPass.d.ts +6 -0
- package/dist/crawler/ConflictDetectionPass.d.ts.map +1 -0
- package/dist/crawler/ConflictDetectionPass.js +46 -0
- package/dist/crawler/ConflictDetectionPass.js.map +1 -0
- package/dist/crawler/DecayScoringPass.d.ts +17 -0
- package/dist/crawler/DecayScoringPass.d.ts.map +1 -0
- package/dist/crawler/DecayScoringPass.js +73 -0
- package/dist/crawler/DecayScoringPass.js.map +1 -0
- package/dist/crawler/MemoGrafterCrawler.d.ts +14 -0
- package/dist/crawler/MemoGrafterCrawler.d.ts.map +1 -0
- package/dist/crawler/MemoGrafterCrawler.js +108 -0
- package/dist/crawler/MemoGrafterCrawler.js.map +1 -0
- package/dist/crawler/VersioningPass.d.ts +6 -0
- package/dist/crawler/VersioningPass.d.ts.map +1 -0
- package/dist/crawler/VersioningPass.js +43 -0
- package/dist/crawler/VersioningPass.js.map +1 -0
- package/dist/crawler/decayScoring.d.ts +7 -0
- package/dist/crawler/decayScoring.d.ts.map +1 -0
- package/dist/crawler/decayScoring.js +9 -0
- package/dist/crawler/decayScoring.js.map +1 -0
- package/dist/crawler/index.d.ts +7 -0
- package/dist/crawler/index.d.ts.map +1 -0
- package/dist/crawler/index.js +5 -0
- package/dist/crawler/index.js.map +1 -0
- package/dist/crawler/memoryMaintenance.d.ts +14 -0
- package/dist/crawler/memoryMaintenance.d.ts.map +1 -0
- package/dist/crawler/memoryMaintenance.js +40 -0
- package/dist/crawler/memoryMaintenance.js.map +1 -0
- package/dist/crawler/types.d.ts +63 -0
- package/dist/crawler/types.d.ts.map +1 -0
- package/dist/crawler/types.js +2 -0
- package/dist/crawler/types.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/pipeline/GrafterPipeline.d.ts.map +1 -1
- package/dist/pipeline/GrafterPipeline.js +42 -1
- package/dist/pipeline/GrafterPipeline.js.map +1 -1
- package/dist/prompts/memoryInjectionPrompt.d.ts +6 -2
- package/dist/prompts/memoryInjectionPrompt.d.ts.map +1 -1
- package/dist/prompts/memoryInjectionPrompt.js +25 -2
- package/dist/prompts/memoryInjectionPrompt.js.map +1 -1
- package/dist/store/GraphStore.d.ts +10 -1
- package/dist/store/GraphStore.d.ts.map +1 -1
- package/dist/store/postgres-pgvector/GraphStore.d.ts +11 -1
- package/dist/store/postgres-pgvector/GraphStore.d.ts.map +1 -1
- package/dist/store/postgres-pgvector/GraphStore.js +105 -1
- package/dist/store/postgres-pgvector/GraphStore.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/USER_GUIDE.md
CHANGED
|
@@ -84,11 +84,11 @@ Current v1 tables:
|
|
|
84
84
|
- `mg_topic_nodes`
|
|
85
85
|
- `mg_topic_edges`
|
|
86
86
|
- `mg_memory_nodes`
|
|
87
|
-
- `mg_memory_edges`
|
|
88
|
-
- `mg_fleets`
|
|
89
|
-
- `mg_fleet_agents`
|
|
90
|
-
- `mg_session_ingest_state`
|
|
91
|
-
- `mg_graft_registry`
|
|
87
|
+
- `mg_memory_edges`
|
|
88
|
+
- `mg_fleets`
|
|
89
|
+
- `mg_fleet_agents`
|
|
90
|
+
- `mg_session_ingest_state`
|
|
91
|
+
- `mg_graft_registry`
|
|
92
92
|
|
|
93
93
|
## Quick Start
|
|
94
94
|
|
|
@@ -197,10 +197,13 @@ Important fields:
|
|
|
197
197
|
- `confidence`: confidence score from `0` to `1`.
|
|
198
198
|
- `topicNodeId`: parent topic node ID.
|
|
199
199
|
- `decayed`: whether the memory is stale.
|
|
200
|
+
- `hasConflict`: whether crawler maintenance found a conflicting active fact.
|
|
200
201
|
- `supersededBy`: newer memory ID when this memory has been replaced.
|
|
201
202
|
|
|
202
203
|
Memory nodes are stored in `mg_memory_nodes`.
|
|
203
204
|
|
|
205
|
+
`decayed`, `hasConflict`, and `supersededBy` are maintenance fields. Normal ingestion creates active memories. Optional crawler passes can later annotate existing memory rows, but they do not delete rows or rewrite topic summaries.
|
|
206
|
+
|
|
204
207
|
### Graph Edges
|
|
205
208
|
|
|
206
209
|
Edges connect related topic nodes. They can represent temporal, semantic, grafted, or reentry relationships.
|
|
@@ -212,6 +215,19 @@ Edges connect related topic nodes. They can represent temporal, semantic, grafte
|
|
|
212
215
|
|
|
213
216
|
Edges are stored in `mg_topic_edges`.
|
|
214
217
|
|
|
218
|
+
Memory edges are stored separately in `mg_memory_edges`. They can represent:
|
|
219
|
+
|
|
220
|
+
- `semantic`: two memory facts are similar.
|
|
221
|
+
- `conflicts`: two active memory facts disagree.
|
|
222
|
+
- `updates`: a newer memory supersedes an older memory.
|
|
223
|
+
- `related`: reserved for broader memory relationships.
|
|
224
|
+
|
|
225
|
+
For version edges, MemoGrafter uses this direction:
|
|
226
|
+
|
|
227
|
+
```text
|
|
228
|
+
newer_memory --updates--> older_memory
|
|
229
|
+
```
|
|
230
|
+
|
|
215
231
|
### Grafting
|
|
216
232
|
|
|
217
233
|
Grafting is the process of selecting topic nodes and turning them into useful context for another prompt or another chatbot.
|
|
@@ -221,9 +237,9 @@ There are two common forms:
|
|
|
221
237
|
- Preview memory with `graft()`.
|
|
222
238
|
- Copy memory into another chatbot with `absorbFromAgent()` or `ingestGraftedNodes()`.
|
|
223
239
|
|
|
224
|
-
When topic nodes are absorbed into another session, MemoGrafter also copies their active memory nodes so targeted recall can find the transferred facts. Copied memory rows get fresh IDs, keep their existing embeddings, and are copied as active memories only when the source row is not decayed or superseded.
|
|
225
|
-
|
|
226
|
-
Absorbed topic nodes are also registered in `mg_graft_registry`. The registry records the destination session, copied node ID, source session ID, source node ID, and graft timestamp so applications can inspect provenance or remove a graft later.
|
|
240
|
+
When topic nodes are absorbed into another session, MemoGrafter also copies their active memory nodes so targeted recall can find the transferred facts. Copied memory rows get fresh IDs, keep their existing embeddings, and are copied as active memories only when the source row is not decayed or superseded.
|
|
241
|
+
|
|
242
|
+
Absorbed topic nodes are also registered in `mg_graft_registry`. The registry records the destination session, copied node ID, source session ID, source node ID, and graft timestamp so applications can inspect provenance or remove a graft later.
|
|
227
243
|
|
|
228
244
|
## Using MemoGrafterAgent
|
|
229
245
|
|
|
@@ -334,25 +350,29 @@ Read a complete session graph snapshot:
|
|
|
334
350
|
const snapshot = await agent.getGraphSnapshot();
|
|
335
351
|
|
|
336
352
|
console.log(snapshot.sessionId);
|
|
337
|
-
console.log(snapshot.nodes);
|
|
338
|
-
console.log(snapshot.snapshotNodes);
|
|
339
|
-
console.log(snapshot.edges);
|
|
340
|
-
console.log(snapshot.memories);
|
|
341
|
-
console.log(snapshot.
|
|
353
|
+
console.log(snapshot.nodes);
|
|
354
|
+
console.log(snapshot.snapshotNodes);
|
|
355
|
+
console.log(snapshot.edges);
|
|
356
|
+
console.log(snapshot.memories);
|
|
357
|
+
console.log(snapshot.memoryEdges);
|
|
358
|
+
console.log(snapshot.capturedAt);
|
|
342
359
|
```
|
|
343
360
|
|
|
344
361
|
`getGraphSnapshot()` returns a `GraphSnapshot`:
|
|
345
362
|
|
|
346
|
-
- `sessionId`: current agent session ID.
|
|
347
|
-
- `nodes`: active topic nodes for the session.
|
|
348
|
-
- `snapshotNodes`: active topic nodes wrapped with provenance metadata when a node came from a graft.
|
|
349
|
-
- `edges`: topic edges where either endpoint belongs to a session topic node.
|
|
350
|
-
- `memories`: all memory nodes for the session, including decayed or superseded rows.
|
|
351
|
-
- `
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
363
|
+
- `sessionId`: current agent session ID.
|
|
364
|
+
- `nodes`: active topic nodes for the session.
|
|
365
|
+
- `snapshotNodes`: active topic nodes wrapped with provenance metadata when a node came from a graft.
|
|
366
|
+
- `edges`: topic edges where either endpoint belongs to a session topic node.
|
|
367
|
+
- `memories`: all memory nodes for the session, including decayed or superseded rows.
|
|
368
|
+
- `memoryEdges`: memory-level edges such as `semantic`, `conflicts`, `updates`, and `related`.
|
|
369
|
+
- `capturedAt`: ISO timestamp for when the snapshot was produced.
|
|
370
|
+
|
|
371
|
+
Each `snapshotNodes` entry contains the topic `node` and an optional `graftOrigin` with `sourceSessionId`, `sourceNodeId`, and `graftedAt`. The plain `nodes` array remains available for callers that only need the topic nodes.
|
|
372
|
+
|
|
373
|
+
This method is read-only. It does not include raw `mg_message_buffer` content and does not add rendering, layout, or color decisions. Like `getActiveNodes()` and `getActiveSegments()`, it waits for the agent's pending ingest work before reading. If called immediately after `invoke()` in queue mode, it waits for the current ingest job to settle before returning.
|
|
374
|
+
|
|
375
|
+
Graph snapshots intentionally include stale and maintenance metadata so visualizers can show memory lifecycle state. For example, a UI can fade `decayed` memories, show `hasConflict` badges, draw `conflicts` edges between contradictory facts, and draw `updates` edges from the current fact to the older fact it replaced.
|
|
356
376
|
|
|
357
377
|
Read active topic nodes:
|
|
358
378
|
|
|
@@ -417,6 +437,112 @@ const graft = await agent.graft([nodes[0]!.id]);
|
|
|
417
437
|
- `nodes`: selected topic nodes.
|
|
418
438
|
- `tokenCount`: estimated token count.
|
|
419
439
|
|
|
440
|
+
Graft prompts include topic summaries because they preserve useful conversation context. Topic summaries are historical: if an older topic summary says "the user lives in Delhi" and a later memory says "the user lives in Bangalore", MemoGrafter does not rewrite the old summary. Instead, when crawler maintenance has marked a contradiction or supersession, graft prompt assembly adds deterministic maintenance notes and active memory facts:
|
|
441
|
+
|
|
442
|
+
```text
|
|
443
|
+
Memory maintenance notes:
|
|
444
|
+
- The fact "user location: Delhi" was superseded by "Bangalore".
|
|
445
|
+
- Prefer active memory facts over contradictory historical summary details.
|
|
446
|
+
Active memory facts:
|
|
447
|
+
- user location: Bangalore
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
This keeps history intact while telling the downstream model which fact is current.
|
|
451
|
+
|
|
452
|
+
## Maintaining Memory With The Crawler
|
|
453
|
+
|
|
454
|
+
`MemoGrafterCrawler` is an optional graph maintenance worker. It can run once on demand or on a simple in-process interval. It does not use Redis, BullMQ, OpenAI, embeddings, or LLMs for the built-in conflict/versioning/decay passes.
|
|
455
|
+
|
|
456
|
+
Typical usage with the real store:
|
|
457
|
+
|
|
458
|
+
```ts
|
|
459
|
+
import {
|
|
460
|
+
ConflictDetectionPass,
|
|
461
|
+
DecayScoringPass,
|
|
462
|
+
MemoGrafter,
|
|
463
|
+
MemoGrafterCrawler,
|
|
464
|
+
VersioningPass,
|
|
465
|
+
} from "memo-grafter";
|
|
466
|
+
|
|
467
|
+
const memo = new MemoGrafter(config);
|
|
468
|
+
await memo.initialize();
|
|
469
|
+
|
|
470
|
+
const crawler = new MemoGrafterCrawler({
|
|
471
|
+
store: memo.store,
|
|
472
|
+
intervalMs: 60_000,
|
|
473
|
+
passes: [
|
|
474
|
+
new ConflictDetectionPass(),
|
|
475
|
+
new VersioningPass(),
|
|
476
|
+
new DecayScoringPass({
|
|
477
|
+
halfLifeDays: 90,
|
|
478
|
+
minScore: 0.25,
|
|
479
|
+
}),
|
|
480
|
+
],
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
const report = await crawler.runOnce();
|
|
484
|
+
console.log(report);
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
`runOnce()` executes the configured passes exactly one time and returns a `CrawlerReport`. `intervalMs` does not affect `runOnce()`.
|
|
488
|
+
|
|
489
|
+
To run the crawler in-process on a schedule:
|
|
490
|
+
|
|
491
|
+
```ts
|
|
492
|
+
crawler.start();
|
|
493
|
+
|
|
494
|
+
// Later, during shutdown:
|
|
495
|
+
crawler.stop();
|
|
496
|
+
await memo.close();
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
`start()` is safe to call more than once; it does not create duplicate intervals. If a scheduled tick fires while the previous run is still executing, that tick is skipped.
|
|
500
|
+
|
|
501
|
+
The built-in conflict/versioning passes use deterministic matching:
|
|
502
|
+
|
|
503
|
+
- they group active memories by session, normalized `subject`, and normalized `predicate`;
|
|
504
|
+
- a group conflicts when it has different normalized `value` strings;
|
|
505
|
+
- decayed memories are skipped;
|
|
506
|
+
- already superseded memories are skipped;
|
|
507
|
+
- the newest conflicting fact wins by `createdAt`;
|
|
508
|
+
- if timestamps tie, deterministic ID ordering is used.
|
|
509
|
+
|
|
510
|
+
`DecayScoringPass` uses confidence-weighted exponential recency decay:
|
|
511
|
+
|
|
512
|
+
```text
|
|
513
|
+
recency_factor = exp(-(ln(2) / half_life_days) * age_days)
|
|
514
|
+
decay_score = confidence * recency_factor
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
If `decay_score < minScore`, the memory is marked `decayed: true`. Superseded memories and already decayed memories are skipped. Conservative defaults are used when options are omitted:
|
|
518
|
+
|
|
519
|
+
```ts
|
|
520
|
+
new DecayScoringPass({
|
|
521
|
+
halfLifeDays: 90,
|
|
522
|
+
minScore: 0.25,
|
|
523
|
+
});
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
By default the pass does not change stored `confidence`; confidence is treated as extraction confidence, while decay score is temporal freshness. If you explicitly want the score written back as confidence, pass `updateConfidence: true`.
|
|
527
|
+
|
|
528
|
+
When conflicts are found:
|
|
529
|
+
|
|
530
|
+
- both active facts get `hasConflict: true`;
|
|
531
|
+
- a `conflicts` memory edge is created;
|
|
532
|
+
- the older fact gets `supersededBy` pointing to the newer fact;
|
|
533
|
+
- an `updates` edge is created as `newer_memory --updates--> older_memory`.
|
|
534
|
+
- stale active memories can be marked `decayed: true` by the decay pass.
|
|
535
|
+
|
|
536
|
+
Crawler maintenance is non-destructive. It annotates existing memory rows and creates memory edges. It does not delete nodes, does not rebuild topics, and does not rewrite topic summaries.
|
|
537
|
+
|
|
538
|
+
Do not put crawler behavior inside `clearSession()`. `clearSession()` is a destructive reset. The crawler is a non-destructive maintenance worker. If you intentionally rebuild a session graph, use this order:
|
|
539
|
+
|
|
540
|
+
```ts
|
|
541
|
+
await agent.clearSession();
|
|
542
|
+
await memo.ingestNow(messages, sessionId);
|
|
543
|
+
await crawler.runOnce();
|
|
544
|
+
```
|
|
545
|
+
|
|
420
546
|
## Absorbing Memory Into Another Chatbot
|
|
421
547
|
|
|
422
548
|
Use `absorbFromAgent()` to copy selected memory from one chatbot into another.
|
|
@@ -447,37 +573,37 @@ const response = await writingBot.invoke(
|
|
|
447
573
|
console.log(response);
|
|
448
574
|
```
|
|
449
575
|
|
|
450
|
-
Absorbing copies selected topic nodes into the target session and creates `grafted` edges back to their source nodes. It also copies active memory facts attached to those topic nodes into the target session so future `recall()` and `invoke()` calls can surface the transferred context. Decayed or superseded source memories are not copied.
|
|
451
|
-
|
|
452
|
-
Each copied topic node is recorded in the graft registry. Registry entries let you answer where a graft came from and which copied destination node owns it.
|
|
453
|
-
|
|
454
|
-
Known limitation: if a source topic node has no associated memory rows in `mg_memory_nodes`, there are no facts to copy. The topic node can still be grafted, but targeted recall will not return facts for that node unless memory extraction produced them.
|
|
455
|
-
|
|
456
|
-
### Inspect Graft Registry
|
|
457
|
-
|
|
458
|
-
```ts
|
|
459
|
-
const registry = await writingBot.getGraftRegistry();
|
|
460
|
-
|
|
461
|
-
for (const entry of registry) {
|
|
462
|
-
console.log({
|
|
463
|
-
nodeId: entry.nodeId,
|
|
464
|
-
sourceSessionId: entry.sourceSessionId,
|
|
465
|
-
sourceNodeId: entry.sourceNodeId,
|
|
466
|
-
graftedAt: entry.graftedAt,
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
```
|
|
470
|
-
|
|
471
|
-
Use this when your app needs to display transferred memory provenance or decide which graft to remove.
|
|
472
|
-
|
|
473
|
-
### Remove A Graft
|
|
474
|
-
|
|
475
|
-
```ts
|
|
476
|
-
const registry = await writingBot.getGraftRegistry();
|
|
477
|
-
await writingBot.removeGraft(registry[0]!.nodeId);
|
|
478
|
-
```
|
|
479
|
-
|
|
480
|
-
`removeGraft()` removes the copied graft node from the current session. The registry row is removed with it. The method is scoped to the current agent session and throws if the node is not a registered graft for that session.
|
|
576
|
+
Absorbing copies selected topic nodes into the target session and creates `grafted` edges back to their source nodes. It also copies active memory facts attached to those topic nodes into the target session so future `recall()` and `invoke()` calls can surface the transferred context. Decayed or superseded source memories are not copied.
|
|
577
|
+
|
|
578
|
+
Each copied topic node is recorded in the graft registry. Registry entries let you answer where a graft came from and which copied destination node owns it.
|
|
579
|
+
|
|
580
|
+
Known limitation: if a source topic node has no associated memory rows in `mg_memory_nodes`, there are no facts to copy. The topic node can still be grafted, but targeted recall will not return facts for that node unless memory extraction produced them.
|
|
581
|
+
|
|
582
|
+
### Inspect Graft Registry
|
|
583
|
+
|
|
584
|
+
```ts
|
|
585
|
+
const registry = await writingBot.getGraftRegistry();
|
|
586
|
+
|
|
587
|
+
for (const entry of registry) {
|
|
588
|
+
console.log({
|
|
589
|
+
nodeId: entry.nodeId,
|
|
590
|
+
sourceSessionId: entry.sourceSessionId,
|
|
591
|
+
sourceNodeId: entry.sourceNodeId,
|
|
592
|
+
graftedAt: entry.graftedAt,
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
Use this when your app needs to display transferred memory provenance or decide which graft to remove.
|
|
598
|
+
|
|
599
|
+
### Remove A Graft
|
|
600
|
+
|
|
601
|
+
```ts
|
|
602
|
+
const registry = await writingBot.getGraftRegistry();
|
|
603
|
+
await writingBot.removeGraft(registry[0]!.nodeId);
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
`removeGraft()` removes the copied graft node from the current session. The registry row is removed with it. The method is scoped to the current agent session and throws if the node is not a registered graft for that session.
|
|
481
607
|
|
|
482
608
|
### Absorb By Semantic Prompt
|
|
483
609
|
|
|
@@ -579,9 +705,10 @@ Useful store inspection methods include:
|
|
|
579
705
|
- `getTopicNode(topicNodeId, sessionId?)`: read one topic node by ID.
|
|
580
706
|
- `getSegmentsBySession(sessionId)`: read topic segments for a session.
|
|
581
707
|
- `getEdgesByType(sessionId, type)`: inspect graph edges such as `"reentry"`, `"semantic"`, `"temporal"`, or `"grafted"`.
|
|
582
|
-
- `getEdgesBySession(sessionId)`: read all topic edges where either endpoint belongs to the session's topic nodes.
|
|
583
|
-
- `getMemoriesBySession(sessionId)`: read all memory nodes for a session, including decayed and superseded rows.
|
|
584
|
-
- `
|
|
708
|
+
- `getEdgesBySession(sessionId)`: read all topic edges where either endpoint belongs to the session's topic nodes.
|
|
709
|
+
- `getMemoriesBySession(sessionId)`: read all memory nodes for a session, including decayed and superseded rows.
|
|
710
|
+
- `getMemoryEdgesBySession(sessionId)`: read memory-level edges such as `conflicts` and `updates`.
|
|
711
|
+
- `getGraftRegistry(sessionId)`: read graft provenance entries for a session.
|
|
585
712
|
|
|
586
713
|
### `llm`
|
|
587
714
|
|
|
@@ -1112,6 +1239,10 @@ Main exports:
|
|
|
1112
1239
|
- `OpenAILLMAdapter`
|
|
1113
1240
|
- `OpenAIEmbedAdapter`
|
|
1114
1241
|
- `PostgresGraphStore`
|
|
1242
|
+
- `MemoGrafterCrawler`
|
|
1243
|
+
- `ConflictDetectionPass`
|
|
1244
|
+
- `DecayScoringPass`
|
|
1245
|
+
- `VersioningPass`
|
|
1115
1246
|
- `GrafterPipeline`
|
|
1116
1247
|
- `IngestPipeline`
|
|
1117
1248
|
- `RetrieverPipeline`
|
|
@@ -1129,6 +1260,7 @@ Useful `GraphStore` inspection methods:
|
|
|
1129
1260
|
- `getEdgesByType(sessionId, type)`
|
|
1130
1261
|
- `getEdgesBySession(sessionId)`
|
|
1131
1262
|
- `getMemoriesBySession(sessionId)`
|
|
1263
|
+
- `getMemoryEdgesBySession(sessionId)`
|
|
1132
1264
|
- `getSessionNodeCount(sessionId)`
|
|
1133
1265
|
- `getSessionIngestState(sessionId)`
|
|
1134
1266
|
|
|
@@ -1138,14 +1270,14 @@ Common `MemoGrafterAgent` methods:
|
|
|
1138
1270
|
- `invoke(message)`: send a user message and receive an assistant response.
|
|
1139
1271
|
- `getHistory()`: read local chat history.
|
|
1140
1272
|
- `getSessionId()`: read the current session ID.
|
|
1141
|
-
- `getGraphSnapshot()`: read nodes, edges, memories, session ID, and capture timestamp for visualization or inspection.
|
|
1142
|
-
- `getGraftRegistry()`: inspect provenance for grafted nodes in the current session.
|
|
1143
|
-
- `getActiveNodes()`: inspect topic nodes.
|
|
1144
|
-
- `getActiveSegments()`: inspect topic segments.
|
|
1145
|
-
- `clearSession()`: explicitly clear local history and stored session memory.
|
|
1146
|
-
- `recall(query, options?)`: retrieve structured memory by semantic query.
|
|
1147
|
-
- `graft(topicIds?)`: preview memory injection.
|
|
1148
|
-
- `ingestGraftedNodes(nodes)`: copy provided nodes into this agent.
|
|
1149
|
-
- `absorbFromAgent(sourceAgent, options)`: select and copy memory from another agent.
|
|
1150
|
-
- `removeGraft(nodeId)`: remove a registered graft node from the current session.
|
|
1151
|
-
- `close()`: close database and queue resources.
|
|
1273
|
+
- `getGraphSnapshot()`: read nodes, edges, memories, session ID, and capture timestamp for visualization or inspection.
|
|
1274
|
+
- `getGraftRegistry()`: inspect provenance for grafted nodes in the current session.
|
|
1275
|
+
- `getActiveNodes()`: inspect topic nodes.
|
|
1276
|
+
- `getActiveSegments()`: inspect topic segments.
|
|
1277
|
+
- `clearSession()`: explicitly clear local history and stored session memory.
|
|
1278
|
+
- `recall(query, options?)`: retrieve structured memory by semantic query.
|
|
1279
|
+
- `graft(topicIds?)`: preview memory injection.
|
|
1280
|
+
- `ingestGraftedNodes(nodes)`: copy provided nodes into this agent.
|
|
1281
|
+
- `absorbFromAgent(sourceAgent, options)`: select and copy memory from another agent.
|
|
1282
|
+
- `removeGraft(nodeId)`: remove a registered graft node from the current session.
|
|
1283
|
+
- `close()`: close database and queue resources.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoGrafterAgent.d.ts","sourceRoot":"","sources":["../src/MemoGrafterAgent.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,sBAAsB,EACtB,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,OAAO,EACP,eAAe,EACf,eAAe,EACf,SAAS,EACT,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAc;IACnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA6B;IACzD,OAAO,CAAC,aAAa,CAAoC;gBAE7C,MAAM,EAAE,iBAAiB;IASrC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBlD,UAAU,IAAI,OAAO,EAAE;IAIvB,YAAY,IAAI,MAAM;IAIhB,cAAc,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAMtC,iBAAiB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAM5C,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"MemoGrafterAgent.d.ts","sourceRoot":"","sources":["../src/MemoGrafterAgent.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,sBAAsB,EACtB,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,OAAO,EACP,eAAe,EACf,eAAe,EACf,SAAS,EACT,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,qBAAa,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,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAKhH,OAAO,CAAC,uBAAuB;YAUjB,mBAAmB;IAsBjC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGvB"}
|
package/dist/MemoGrafterAgent.js
CHANGED
|
@@ -60,6 +60,7 @@ export class MemoGrafterAgent {
|
|
|
60
60
|
const { nodes } = await this.core.getTopics(this.sessionId);
|
|
61
61
|
const edges = await this.core.store.getEdgesBySession(this.sessionId);
|
|
62
62
|
const memories = await this.core.store.getMemoriesBySession(this.sessionId);
|
|
63
|
+
const memoryEdges = await this.core.store.getMemoryEdgesBySession(this.sessionId);
|
|
63
64
|
const registry = await this.core.store.getGraftRegistry(this.sessionId);
|
|
64
65
|
const registryByNodeId = new Map(registry.map((entry) => [entry.nodeId, entry]));
|
|
65
66
|
return {
|
|
@@ -82,6 +83,7 @@ export class MemoGrafterAgent {
|
|
|
82
83
|
}),
|
|
83
84
|
edges,
|
|
84
85
|
memories,
|
|
86
|
+
memoryEdges,
|
|
85
87
|
capturedAt: new Date().toISOString(),
|
|
86
88
|
};
|
|
87
89
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoGrafterAgent.js","sourceRoot":"","sources":["../src/MemoGrafterAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAcpE,MAAM,OAAO,gBAAgB;IACV,IAAI,CAAc;IAClB,SAAS,GAAG,UAAU,EAAE,CAAC;IACzB,OAAO,GAAc,EAAE,CAAC;IACxB,gBAAgB,CAAS;IACzB,gBAAgB,CAAS;IACzB,WAAW,CAAS;IACpB,mBAAmB,CAAS;IAC5B,WAAW,CAA6B;IACjD,aAAa,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAEzD,YAAY,MAAy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ionPass implements CrawlerPass {
|
|
3
|
+
readonly name = "conflict-detection";
|
|
4
|
+
run(context: CrawlerPassContext): Promise<CrawlerPassResult>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=ConflictDetectionPass.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConflictDetectionPass.d.ts","sourceRoot":"","sources":["../../src/crawler/ConflictDetectionPass.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGrF,qBAAa,qBAAsB,YAAW,WAAW;IACvD,QAAQ,CAAC,IAAI,wBAAwB;IAE/B,GAAG,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CA6CnE"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { findMemoryConflictGroups, getSkippedMaintenanceCounts } from "./memoryMaintenance.js";
|
|
2
|
+
export class ConflictDetectionPass {
|
|
3
|
+
name = "conflict-detection";
|
|
4
|
+
async run(context) {
|
|
5
|
+
if (!context.store) {
|
|
6
|
+
throw new Error("ConflictDetectionPass requires a crawler maintenance store.");
|
|
7
|
+
}
|
|
8
|
+
const memories = await context.store.listMemoryNodesForMaintenance();
|
|
9
|
+
const conflictGroups = findMemoryConflictGroups(memories);
|
|
10
|
+
const conflictingNodeIds = new Set();
|
|
11
|
+
let conflictEdgesCreated = 0;
|
|
12
|
+
for (const group of conflictGroups) {
|
|
13
|
+
for (const node of group.nodes) {
|
|
14
|
+
conflictingNodeIds.add(node.id);
|
|
15
|
+
}
|
|
16
|
+
for (let sourceIndex = 0; sourceIndex < group.nodes.length; sourceIndex += 1) {
|
|
17
|
+
const source = group.nodes[sourceIndex];
|
|
18
|
+
if (!source)
|
|
19
|
+
continue;
|
|
20
|
+
for (let targetIndex = sourceIndex + 1; targetIndex < group.nodes.length; targetIndex += 1) {
|
|
21
|
+
const target = group.nodes[targetIndex];
|
|
22
|
+
if (!target)
|
|
23
|
+
continue;
|
|
24
|
+
const created = await context.store.upsertMemoryEdge({
|
|
25
|
+
sourceId: source.id,
|
|
26
|
+
targetId: target.id,
|
|
27
|
+
edgeType: "conflicts",
|
|
28
|
+
weight: 1,
|
|
29
|
+
});
|
|
30
|
+
if (created)
|
|
31
|
+
conflictEdgesCreated += 1;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const nodesMarkedConflicting = await context.store.markMemoryNodesConflicting([...conflictingNodeIds]);
|
|
36
|
+
const skipped = getSkippedMaintenanceCounts(memories);
|
|
37
|
+
return {
|
|
38
|
+
inspected: memories.length,
|
|
39
|
+
conflictsDetected: conflictGroups.length,
|
|
40
|
+
nodesMarkedConflicting,
|
|
41
|
+
conflictEdgesCreated,
|
|
42
|
+
...skipped,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=ConflictDetectionPass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConflictDetectionPass.js","sourceRoot":"","sources":["../../src/crawler/ConflictDetectionPass.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAE/F,MAAM,OAAO,qBAAqB;IACvB,IAAI,GAAG,oBAAoB,CAAC;IAErC,KAAK,CAAC,GAAG,CAAC,OAA2B;QACnC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;QACjF,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,CAAC;QACrE,MAAM,cAAc,GAAG,wBAAwB,CAAC,QAAQ,CAAC,CAAC;QAC1D,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAU,CAAC;QAC7C,IAAI,oBAAoB,GAAG,CAAC,C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;YACtB,oBAAoB;YACpB,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CrawlerPass, CrawlerPassContext, CrawlerPassResult } from "./types.js";
|
|
2
|
+
export interface DecayScoringPassOptions {
|
|
3
|
+
halfLifeDays?: number;
|
|
4
|
+
minScore?: number;
|
|
5
|
+
now?: () => Date;
|
|
6
|
+
updateConfidence?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class DecayScoringPass implements CrawlerPass {
|
|
9
|
+
readonly name = "decay-scoring";
|
|
10
|
+
private readonly halfLifeDays;
|
|
11
|
+
private readonly minScore;
|
|
12
|
+
private readonly now;
|
|
13
|
+
private readonly updateConfidence;
|
|
14
|
+
constructor(options?: DecayScoringPassOptions);
|
|
15
|
+
run(context: CrawlerPassContext): Promise<CrawlerPassResult>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=DecayScoringPass.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DecayScoringPass.d.ts","sourceRoot":"","sources":["../../src/crawler/DecayScoringPass.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAErF,MAAM,WAAW,uBAAuB;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAKD,qBAAa,gBAAiB,YAAW,WAAW;IAClD,QAAQ,CAAC,IAAI,mBAAmB;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAa;IACjC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAU;gBAE/B,OAAO,GAAE,uBAA4B;IAe3C,GAAG,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAqDnE"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { computeMemoryDecayScore } from "./decayScoring.js";
|
|
2
|
+
const DEFAULT_HALF_LIFE_DAYS = 90;
|
|
3
|
+
const DEFAULT_MIN_SCORE = 0.25;
|
|
4
|
+
export class DecayScoringPass {
|
|
5
|
+
name = "decay-scoring";
|
|
6
|
+
halfLifeDays;
|
|
7
|
+
minScore;
|
|
8
|
+
now;
|
|
9
|
+
updateConfidence;
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
this.halfLifeDays = options.halfLifeDays ?? DEFAULT_HALF_LIFE_DAYS;
|
|
12
|
+
this.minScore = options.minScore ?? DEFAULT_MIN_SCORE;
|
|
13
|
+
this.now = options.now ?? (() => new Date());
|
|
14
|
+
this.updateConfidence = options.updateConfidence ?? false;
|
|
15
|
+
if (!Number.isFinite(this.halfLifeDays) || this.halfLifeDays <= 0) {
|
|
16
|
+
throw new Error("DecayScoringPass halfLifeDays must be greater than 0.");
|
|
17
|
+
}
|
|
18
|
+
if (!Number.isFinite(this.minScore) || this.minScore < 0) {
|
|
19
|
+
throw new Error("DecayScoringPass minScore must be greater than or equal to 0.");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async run(context) {
|
|
23
|
+
if (!context.store) {
|
|
24
|
+
throw new Error("DecayScoringPass requires a crawler maintenance store.");
|
|
25
|
+
}
|
|
26
|
+
const memories = await context.store.listMemoryNodesForMaintenance();
|
|
27
|
+
const now = this.now();
|
|
28
|
+
let decayScored = 0;
|
|
29
|
+
let nodesDecayed = 0;
|
|
30
|
+
let skippedAlreadyDecayed = 0;
|
|
31
|
+
let skippedSuperseded = 0;
|
|
32
|
+
let minDecayScore;
|
|
33
|
+
let maxDecayScore;
|
|
34
|
+
for (const memory of memories) {
|
|
35
|
+
if (memory.supersededBy != null) {
|
|
36
|
+
skippedSuperseded += 1;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (memory.decayed) {
|
|
40
|
+
skippedAlreadyDecayed += 1;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const score = computeMemoryDecayScore(memory, {
|
|
44
|
+
now,
|
|
45
|
+
halfLifeDays: this.halfLifeDays,
|
|
46
|
+
});
|
|
47
|
+
decayScored += 1;
|
|
48
|
+
minDecayScore = minDecayScore === undefined ? score : Math.min(minDecayScore, score);
|
|
49
|
+
maxDecayScore = maxDecayScore === undefined ? score : Math.max(maxDecayScore, score);
|
|
50
|
+
if (this.updateConfidence && context.store.updateMemoryNodeConfidence) {
|
|
51
|
+
await context.store.updateMemoryNodeConfidence(memory.id, clampConfidence(score));
|
|
52
|
+
}
|
|
53
|
+
if (score < this.minScore) {
|
|
54
|
+
const decayed = await context.store.markMemoryNodeDecayed(memory.id);
|
|
55
|
+
if (decayed)
|
|
56
|
+
nodesDecayed += 1;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
inspected: memories.length,
|
|
61
|
+
decayScored,
|
|
62
|
+
nodesDecayed,
|
|
63
|
+
skippedAlreadyDecayed,
|
|
64
|
+
skippedSuperseded,
|
|
65
|
+
...(minDecayScore !== undefined ? { minDecayScore } : {}),
|
|
66
|
+
...(maxDecayScore !== undefined ? { maxDecayScore } : {}),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function clampConfidence(value) {
|
|
71
|
+
return Math.max(0, Math.min(1, value));
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=DecayScoringPass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DecayScoringPass.js","sourceRoot":"","sources":["../../src/crawler/DecayScoringPass.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAU5D,MAAM,s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AAI,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;QAED,OAAO;YACL,SAAS,EAAE,QAAQ,CAAC,MAAM;YAC1B,WAAW;YACX,YAAY;YACZ,qBAAqB;YACrB,iBAAiB;YACjB,GAAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACzD,GAAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1D,CAAC;IACJ,CAAC;CACF;AAED,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CrawlerConfig, CrawlerReport } from "./types.js";
|
|
2
|
+
export declare class MemoGrafterCrawler {
|
|
3
|
+
private readonly config;
|
|
4
|
+
private intervalHandle;
|
|
5
|
+
private isRunning;
|
|
6
|
+
private isExecuting;
|
|
7
|
+
constructor(config?: CrawlerConfig);
|
|
8
|
+
start(): void;
|
|
9
|
+
stop(): void;
|
|
10
|
+
runOnce(): Promise<CrawlerReport>;
|
|
11
|
+
private runScheduledTick;
|
|
12
|
+
private runPass;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=MemoGrafterCrawler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoGrafterCrawler.d.ts","sourceRoot":"","sources":["../../src/crawler/MemoGrafterCrawler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAGb,aAAa,EACd,MAAM,YAAY,CAAC;AAIpB,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CACmB;IAC1C,OAAO,CAAC,cAAc,CAA6C;IACnE,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,WAAW,CAAS;gBAEhB,MAAM,GAAE,aAAkB;IAStC,KAAK,IAAI,IAAI;IAWb,IAAI,IAAI,IAAI;IASN,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC;YA2BzB,gBAAgB;YAahB,OAAO;CA8BtB"}
|