@memberjunction/ai-agents 5.29.0 → 5.30.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/dist/AgentRunner.js +1 -1
- package/dist/AgentRunner.js.map +1 -1
- package/dist/base-agent.d.ts +7 -0
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +68 -3
- package/dist/base-agent.js.map +1 -1
- package/dist/memory-cleanup-agent.d.ts +10 -3
- package/dist/memory-cleanup-agent.d.ts.map +1 -1
- package/dist/memory-cleanup-agent.js +10 -3
- package/dist/memory-cleanup-agent.js.map +1 -1
- package/dist/memory-manager-agent.d.ts +341 -7
- package/dist/memory-manager-agent.d.ts.map +1 -1
- package/dist/memory-manager-agent.js +1723 -373
- package/dist/memory-manager-agent.js.map +1 -1
- package/package.json +15 -15
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { BaseAgent } from './base-agent.js';
|
|
2
2
|
import { ExecuteAgentParams, AgentConfiguration, BaseAgentNextStep } from '@memberjunction/ai-core-plus';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* @deprecated Archival logic has been replaced by the Ebbinghaus decay function in MemoryManagerAgent
|
|
5
|
+
* (see memory-manager-agent.ts, decayBasedArchival method). The Memory Manager now handles all memory
|
|
6
|
+
* lifecycle operations in a single sequential pipeline: extraction, importance scoring, consolidation,
|
|
7
|
+
* verification, contradiction detection, stale reference pruning, and decay-based archival.
|
|
5
8
|
*
|
|
6
|
-
* This
|
|
9
|
+
* This class is retained for reference and rollback purposes. Its scheduled job should be disabled
|
|
10
|
+
* (set Status='Disabled' in .memory-cleanup-job.json metadata).
|
|
11
|
+
*
|
|
12
|
+
* Original behavior:
|
|
7
13
|
* 1. Archives notes not accessed within NoteRetentionDays (per agent config, default 90)
|
|
8
14
|
* 2. Archives examples with SuccessScore < 50 after ExampleRetentionDays (default 180)
|
|
9
15
|
* 3. Archives any items past their ExpiresAt timestamp
|
|
10
16
|
*
|
|
11
|
-
*
|
|
17
|
+
* Replaced by: MemoryManagerAgent.decayBasedArchival() which uses continuous Ebbinghaus-inspired
|
|
18
|
+
* decay with importance-weighted retention, protection tiers, and per-agent configuration.
|
|
12
19
|
*/
|
|
13
20
|
export declare class MemoryCleanupAgent extends BaseAgent {
|
|
14
21
|
private readonly DEFAULT_NOTE_RETENTION_DAYS;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-cleanup-agent.d.ts","sourceRoot":"","sources":["../src/memory-cleanup-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,kBAAkB,EAA2B,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAclI
|
|
1
|
+
{"version":3,"file":"memory-cleanup-agent.d.ts","sourceRoot":"","sources":["../src/memory-cleanup-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,kBAAkB,EAA2B,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAclI;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,kBAAmB,SAAQ,SAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAAM;IAClD,OAAO,CAAC,QAAQ,CAAC,8BAA8B,CAAO;IACtD,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAAM;IAElD;;OAEG;cACsB,oBAAoB,CAAC,CAAC,GAAG,GAAG,EACjD,MAAM,EAAE,kBAAkB,EAC1B,MAAM,EAAE,kBAAkB,GAC3B,OAAO,CAAC;QAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAC,CAAC;IAyChE;;OAEG;YACW,mBAAmB;IA0BjC;;OAEG;YACW,iBAAiB;IAmC/B;;OAEG;YACW,iBAAiB;IAY/B;;OAEG;YACW,oBAAoB;IAYlC;;OAEG;YACW,eAAe;IA+B7B;;OAEG;YACW,kBAAkB;IAiChC;;OAEG;YACW,WAAW;IAoBzB;;OAEG;YACW,cAAc;IAoB5B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAU5B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAS/B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAO7B;;OAEG;IACH,OAAO,CAAC,aAAa;IAMrB;;OAEG;IACH,OAAO,CAAC,YAAY;CA0BvB"}
|
|
@@ -2,14 +2,21 @@ import { BaseAgent } from './base-agent.js';
|
|
|
2
2
|
import { RunView, LogError, LogStatus } from '@memberjunction/core';
|
|
3
3
|
import { AIEngine } from '@memberjunction/aiengine';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* @deprecated Archival logic has been replaced by the Ebbinghaus decay function in MemoryManagerAgent
|
|
6
|
+
* (see memory-manager-agent.ts, decayBasedArchival method). The Memory Manager now handles all memory
|
|
7
|
+
* lifecycle operations in a single sequential pipeline: extraction, importance scoring, consolidation,
|
|
8
|
+
* verification, contradiction detection, stale reference pruning, and decay-based archival.
|
|
6
9
|
*
|
|
7
|
-
* This
|
|
10
|
+
* This class is retained for reference and rollback purposes. Its scheduled job should be disabled
|
|
11
|
+
* (set Status='Disabled' in .memory-cleanup-job.json metadata).
|
|
12
|
+
*
|
|
13
|
+
* Original behavior:
|
|
8
14
|
* 1. Archives notes not accessed within NoteRetentionDays (per agent config, default 90)
|
|
9
15
|
* 2. Archives examples with SuccessScore < 50 after ExampleRetentionDays (default 180)
|
|
10
16
|
* 3. Archives any items past their ExpiresAt timestamp
|
|
11
17
|
*
|
|
12
|
-
*
|
|
18
|
+
* Replaced by: MemoryManagerAgent.decayBasedArchival() which uses continuous Ebbinghaus-inspired
|
|
19
|
+
* decay with importance-weighted retention, protection tiers, and per-agent configuration.
|
|
13
20
|
*/
|
|
14
21
|
export class MemoryCleanupAgent extends BaseAgent {
|
|
15
22
|
constructor() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-cleanup-agent.js","sourceRoot":"","sources":["../src/memory-cleanup-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAsB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGxF,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAapD
|
|
1
|
+
{"version":3,"file":"memory-cleanup-agent.js","sourceRoot":"","sources":["../src/memory-cleanup-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAsB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGxF,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAapD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,kBAAmB,SAAQ,SAAS;IAAjD;;QACqB,gCAA2B,GAAG,EAAE,CAAC;QACjC,mCAA8B,GAAG,GAAG,CAAC;QACrC,gCAA2B,GAAG,EAAE,CAAC;IA+UtD,CAAC;IA7UG;;OAEG;IACgB,KAAK,CAAC,oBAAoB,CACzC,MAA0B,EAC1B,MAA0B;QAE1B,SAAS,CAAC,8CAA8C,CAAC,CAAC;QAE1D,MAAM,WAAW,GAAG,MAAM,CAAC,WAAY,CAAC;QACxC,MAAM,MAAM,GAAkB;YAC1B,aAAa,EAAE,CAAC;YAChB,gBAAgB,EAAE,CAAC;YACnB,YAAY,EAAE,CAAC;YACf,eAAe,EAAE,CAAC;YAClB,MAAM,EAAE,EAAE;SACb,CAAC;QAEF,IAAI,CAAC;YACD,yEAAyE;YACzE,MAAM,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;YAEpD,uDAAuD;YACvD,MAAM,IAAI,CAAC,iBAAiB,CAAC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AC5C,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3B,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,qBAAqB,CAAC,CAAC;QAC7D,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;CACJ"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { BaseAgent } from './base-agent.js';
|
|
2
2
|
import { UserInfo } from '@memberjunction/core';
|
|
3
3
|
import { ExecuteAgentParams, AgentConfiguration, BaseAgentNextStep } from '@memberjunction/ai-core-plus';
|
|
4
|
+
/** Per-cluster verification result, aggregated into a phase-level observability step. */
|
|
5
|
+
interface ConsolidationVerificationResult {
|
|
6
|
+
entitiesChecked: number;
|
|
7
|
+
entitiesMissing: string[];
|
|
8
|
+
passed: boolean;
|
|
9
|
+
}
|
|
4
10
|
/**
|
|
5
11
|
* Memory Manager Agent - automatically extracts notes and examples from conversations.
|
|
6
12
|
* This agent runs on a schedule (every 15 minutes) and analyzes high-quality conversations
|
|
@@ -15,6 +21,8 @@ export declare class MemoryManagerAgent extends BaseAgent {
|
|
|
15
21
|
private _stepCounter;
|
|
16
22
|
/** Context user for step operations */
|
|
17
23
|
private _contextUser;
|
|
24
|
+
/** Check if a string is a valid UUID format. Filters out LLM-generated placeholders like "user-uuid-here". */
|
|
25
|
+
private static isValidUUID;
|
|
18
26
|
/**
|
|
19
27
|
* Create an agent run step record for observability.
|
|
20
28
|
* Returns null if agentRunID is not set (defensive check).
|
|
@@ -52,19 +60,81 @@ export declare class MemoryManagerAgent extends BaseAgent {
|
|
|
52
60
|
*/
|
|
53
61
|
private ExtractNotesFromConversations;
|
|
54
62
|
/**
|
|
55
|
-
* Common extraction logic for note extraction.
|
|
56
|
-
*
|
|
63
|
+
* Common extraction logic for note extraction. Thin orchestrator that coordinates:
|
|
64
|
+
* (1) running the extraction prompt,
|
|
65
|
+
* (2) normalizing merge-field shape from the LLM,
|
|
66
|
+
* (3) applying confidence/length filters,
|
|
67
|
+
* (4) enforcing per-message/per-conversation sparsity caps,
|
|
68
|
+
* (5) collapsing duplicate merge candidates,
|
|
69
|
+
* (6) deduplicating against existing notes,
|
|
70
|
+
* (7) enriching with conversation context (userId, agentRunId).
|
|
71
|
+
*
|
|
72
|
+
* Each step is its own private helper so the pipeline can be read top-to-bottom.
|
|
57
73
|
*/
|
|
58
74
|
private executeNoteExtraction;
|
|
75
|
+
/**
|
|
76
|
+
* Execute the extraction prompt, wrap it in an observability run step, and
|
|
77
|
+
* parse the raw result into a typed array. Returns null on any failure so the
|
|
78
|
+
* caller short-circuits cleanly.
|
|
79
|
+
*/
|
|
80
|
+
private runNoteExtractionPrompt;
|
|
81
|
+
/** Look up the extraction prompt, logging available prompts on miss. */
|
|
82
|
+
private findNoteExtractionPrompt;
|
|
83
|
+
/** Verbose-only logging block for extraction prompt context. */
|
|
84
|
+
private logExtractionPromptContext;
|
|
85
|
+
/**
|
|
86
|
+
* Parse an extraction prompt result into an ExtractedNote array, tolerating JSON-fenced
|
|
87
|
+
* strings from models like Gemini. Returns null on failure.
|
|
88
|
+
*/
|
|
89
|
+
private parseNoteExtractionResult;
|
|
90
|
+
/**
|
|
91
|
+
* Normalize the legacy singular `mergeWithExistingId` field into the plural
|
|
92
|
+
* `mergeWithExistingIds` array. The extraction prompt still emits the singular
|
|
93
|
+
* field in some paths; downstream code only reads the plural form.
|
|
94
|
+
*/
|
|
95
|
+
private normalizeMergeCandidates;
|
|
96
|
+
/**
|
|
97
|
+
* Filter raw extracted notes against the confidence and content-length thresholds
|
|
98
|
+
* from EXTRACTION_CONFIG. Notes below either threshold are silently dropped.
|
|
99
|
+
*/
|
|
100
|
+
private filterByConfidenceAndLength;
|
|
101
|
+
/**
|
|
102
|
+
* Enforce per-message and per-conversation note caps from EXTRACTION_CONFIG.
|
|
103
|
+
* Drops any candidates that would exceed either cap.
|
|
104
|
+
*/
|
|
105
|
+
private applySparsityLimits;
|
|
106
|
+
/**
|
|
107
|
+
* Deduplicate candidate notes against existing notes in the database using:
|
|
108
|
+
* 1. Exact text match (fast reject),
|
|
109
|
+
* 2. Semantic similarity lookup (top-N with ≥85% threshold),
|
|
110
|
+
* 3. Dedup prompt to resolve genuinely-similar candidates.
|
|
111
|
+
*
|
|
112
|
+
* Candidates flagged as merge/replacement by the extraction LLM are auto-approved
|
|
113
|
+
* (dedup would reject them as "too similar" to the note they are intentionally
|
|
114
|
+
* replacing). Creates and finalizes its own observability run step.
|
|
115
|
+
*/
|
|
116
|
+
private deduplicateCandidates;
|
|
117
|
+
/**
|
|
118
|
+
* Evaluate a single candidate: merge markers auto-approve, exact-text duplicates are
|
|
119
|
+
* rejected, otherwise run semantic similarity + LLM dedup. Returns true if the candidate
|
|
120
|
+
* should be kept. Mutates `stats` for rejection + LLM call counts as a side effect.
|
|
121
|
+
*/
|
|
122
|
+
private evaluateCandidateForApproval;
|
|
123
|
+
/**
|
|
124
|
+
* Invoke the dedupe LLM prompt for a single candidate note against its similar
|
|
125
|
+
* neighbors. Returns the decision plus reason string — callers handle logging.
|
|
126
|
+
*/
|
|
127
|
+
private runDedupePromptForCandidate;
|
|
128
|
+
/**
|
|
129
|
+
* Populate userId and sourceAgentRunId on approved notes from the source
|
|
130
|
+
* conversation's context. Only fills fields the LLM didn't already set.
|
|
131
|
+
*/
|
|
132
|
+
private enrichWithConversationContext;
|
|
59
133
|
/**
|
|
60
134
|
* Extract examples from conversation details with high ratings.
|
|
61
135
|
* Uses LLM-based deduplication to avoid adding redundant examples.
|
|
62
136
|
*/
|
|
63
137
|
private ExtractExamples;
|
|
64
|
-
/**
|
|
65
|
-
* Check if a string is a valid UUID format.
|
|
66
|
-
*/
|
|
67
|
-
private isValidUUID;
|
|
68
138
|
/**
|
|
69
139
|
* Create note records from extracted data.
|
|
70
140
|
* Inherits scope from source agent run and applies scopeLevel to determine scope specificity.
|
|
@@ -77,6 +147,47 @@ export declare class MemoryManagerAgent extends BaseAgent {
|
|
|
77
147
|
* replacing both a pepperoni note and a mushrooms note).
|
|
78
148
|
*/
|
|
79
149
|
private collapseMergeCandidates;
|
|
150
|
+
/**
|
|
151
|
+
* Compute composite importance scores for all active notes.
|
|
152
|
+
* Uses a 7-signal weighted formula based on Park et al.'s Generative Agents (2023).
|
|
153
|
+
* Signals not available for a given note use neutral defaults (0.5) with proportional weight redistribution.
|
|
154
|
+
*
|
|
155
|
+
* Auto-promotes Standard-tier notes to Protected via two paths:
|
|
156
|
+
* 1. ImportanceScore >= IMPORTANCE_CONFIG.autoPromoteThreshold (default 8.0)
|
|
157
|
+
* 2. Uniqueness at or above the 95th percentile of the cohort (outlier protection,
|
|
158
|
+
* FR-094). The cohort must be at least OUTLIER_PROMOTION_MIN_COHORT notes for
|
|
159
|
+
* the percentile to be meaningful.
|
|
160
|
+
*
|
|
161
|
+
* Also reports the score distribution (min/max/mean/median) so the observability
|
|
162
|
+
* step can surface it in the agent run step output.
|
|
163
|
+
*/
|
|
164
|
+
private computeImportanceScores;
|
|
165
|
+
/**
|
|
166
|
+
* Pre-compute uniqueness (1 - maxSimilarity to nearest neighbor) for each note in
|
|
167
|
+
* one pass. Returns a map keyed by note ID. Notes without content get an
|
|
168
|
+
* unavailable signal so downstream scoring falls back to the neutral default.
|
|
169
|
+
*/
|
|
170
|
+
private precomputeUniqueness;
|
|
171
|
+
/**
|
|
172
|
+
* Derive the 95th-percentile uniqueness threshold across the cohort. Returns null
|
|
173
|
+
* when the cohort is smaller than OUTLIER_PROMOTION_MIN_COHORT (percentile isn't
|
|
174
|
+
* meaningful) or when no uniqueness was actually computable.
|
|
175
|
+
*/
|
|
176
|
+
private computeUniquenessP95;
|
|
177
|
+
/**
|
|
178
|
+
* Summarize importance scores into min/max/mean/median. Returns null for an empty
|
|
179
|
+
* input so the caller can serialize it as an explicit "no data" signal in the
|
|
180
|
+
* observability step.
|
|
181
|
+
*/
|
|
182
|
+
private summarizeScores;
|
|
183
|
+
/**
|
|
184
|
+
* Gather the 7 importance signals for a single note. Uniqueness is precomputed by
|
|
185
|
+
* the caller so the full cohort can be examined in one pass for percentile
|
|
186
|
+
* analysis. Other signals are derived from the note itself.
|
|
187
|
+
*/
|
|
188
|
+
private gatherImportanceSignals;
|
|
189
|
+
/** Compute a weighted importance score (0-10) from signals, redistributing weight from unavailable signals. */
|
|
190
|
+
private computeWeightedImportanceScore;
|
|
80
191
|
/**
|
|
81
192
|
* Determine whether consolidation should run based on CONSOLIDATION_CONFIG.frequency.
|
|
82
193
|
* Uses AIAgentRun history instead of static in-memory state so that timing
|
|
@@ -87,35 +198,257 @@ export declare class MemoryManagerAgent extends BaseAgent {
|
|
|
87
198
|
* - 'hourly': Run if 1+ hour since last completed MM run
|
|
88
199
|
* - 'daily': Run if 24+ hours since last completed MM run
|
|
89
200
|
* - number: Run every N completed MM runs
|
|
201
|
+
*
|
|
202
|
+
* @param forceMaintenance When true, bypasses all gating and runs maintenance
|
|
203
|
+
* regardless of frequency/history. Set by callers via `params.data.forceMaintenance`
|
|
204
|
+
* (see `executeAgentInternal`). Intended for tests, manual admin triggers, and
|
|
205
|
+
* the E2E verification script — NOT for production config. Previously this was
|
|
206
|
+
* an env var (`FORCE_MAINTENANCE=1`), which was removed because an env-var
|
|
207
|
+
* sidechannel could accidentally leak into production and cause massive DB/LLM
|
|
208
|
+
* churn on every run.
|
|
209
|
+
*
|
|
210
|
+
* Returns both a boolean and the reason it fired so the observability layer can
|
|
211
|
+
* record the trigger type on the parent consolidation run step.
|
|
90
212
|
*/
|
|
91
213
|
private shouldRunConsolidation;
|
|
214
|
+
/**
|
|
215
|
+
* Time-window frequency gate: returns shouldRun=true with triggerType='time' when
|
|
216
|
+
* enough time has passed since the last memory-manager run, or triggerType='event'
|
|
217
|
+
* when the event-driven new-note threshold has been crossed. Falls back to
|
|
218
|
+
* triggerType='not-triggered' when neither condition fires.
|
|
219
|
+
*/
|
|
220
|
+
private shouldRunConsolidationByTimeWindow;
|
|
221
|
+
/** Run-count frequency gate: consolidate every N completed runs. */
|
|
222
|
+
private shouldRunConsolidationByRunCount;
|
|
92
223
|
/**
|
|
93
224
|
* Consolidate related notes into single, comprehensive notes.
|
|
94
225
|
* This method finds clusters of similar notes and synthesizes them.
|
|
95
226
|
*
|
|
227
|
+
* Returns per-cluster verification results alongside the consolidation counts so
|
|
228
|
+
* the phase-level "Verify Consolidation Output" run step can aggregate them.
|
|
229
|
+
*
|
|
96
230
|
* @param agentId Optional - consolidate notes for a specific agent only
|
|
97
231
|
* @param contextUser The context user for database operations
|
|
98
|
-
* @returns Number of notes consolidated (archived)
|
|
99
232
|
*/
|
|
100
233
|
consolidateRelatedNotes(agentId: string | null, contextUser: UserInfo): Promise<{
|
|
101
234
|
consolidated: number;
|
|
102
235
|
archived: number;
|
|
236
|
+
newNoteIds: string[];
|
|
237
|
+
verifications: ConsolidationVerificationResult[];
|
|
103
238
|
}>;
|
|
104
239
|
/**
|
|
105
240
|
* Find clusters of semantically similar notes suitable for consolidation.
|
|
106
241
|
* Each cluster contains notes that exceed the similarity threshold and meet the minimum cluster size.
|
|
107
242
|
*/
|
|
108
243
|
private findConsolidationClusters;
|
|
244
|
+
/**
|
|
245
|
+
* Split a cluster that exceeds maxClusterSize into sub-clusters.
|
|
246
|
+
* Takes the first maxClusterSize notes (sorted by position in original cluster, which preserves
|
|
247
|
+
* similarity ordering from FindSimilarAgentNotes), and forms a second cluster from the remainder
|
|
248
|
+
* if it meets minClusterSize.
|
|
249
|
+
*/
|
|
250
|
+
private splitOversizedCluster;
|
|
251
|
+
/**
|
|
252
|
+
* Walk DerivedFromNoteIDs chains breadth-first to find all generation-0 (original) source notes.
|
|
253
|
+
* Batches each depth level into a single `ID IN (...)` query instead of one query per ID.
|
|
254
|
+
*/
|
|
255
|
+
private resolveOriginalSources;
|
|
256
|
+
/** Load a batch of notes by ID with the fields needed for source resolution. */
|
|
257
|
+
private loadResolvedNotes;
|
|
258
|
+
/**
|
|
259
|
+
* Partition a batch of resolved notes into terminal originals (pushed into `originals`)
|
|
260
|
+
* and parent IDs that need further resolution. Mutates `originals` and `visited`.
|
|
261
|
+
*/
|
|
262
|
+
private collectNextLevelSourceIds;
|
|
263
|
+
/**
|
|
264
|
+
* Verify that a consolidated note preserves key entities from its source notes.
|
|
265
|
+
* Extracts numbers, dates, and proper nouns from source notes and checks they appear in the output.
|
|
266
|
+
* Non-blocking: returns verification results but does not prevent consolidation.
|
|
267
|
+
*/
|
|
268
|
+
private verifyConsolidationOutput;
|
|
269
|
+
/**
|
|
270
|
+
* Harvest numbers, dates, proper nouns, and camelCase identifiers from a note's text
|
|
271
|
+
* into the supplied set. Used only by verifyConsolidationOutput to assemble a
|
|
272
|
+
* best-effort entity inventory for post-consolidation checks.
|
|
273
|
+
*/
|
|
274
|
+
private extractVerifiableEntities;
|
|
275
|
+
/**
|
|
276
|
+
* Detect and resolve contradictions between semantically similar notes.
|
|
277
|
+
* Uses a three-stage pipeline: embedding pre-filter, entity-attribute extraction, LLM judgment.
|
|
278
|
+
* High-importance pairs (both >= highImportanceThreshold) are flagged but preserved.
|
|
279
|
+
* Protected-tier notes are never auto-revoked.
|
|
280
|
+
*
|
|
281
|
+
* Aggregates the per-pair entity-attribute-value triple count so the observability
|
|
282
|
+
* step can report how much structural reasoning the LLM produced.
|
|
283
|
+
*/
|
|
284
|
+
private detectAndResolveContradictions;
|
|
285
|
+
/** Build unique candidate pairs of semantically similar notes for contradiction analysis. */
|
|
286
|
+
private buildContradictionCandidatePairs;
|
|
287
|
+
/** Evaluate a single note pair for contradiction using the LLM prompt. */
|
|
288
|
+
private evaluateContradictionPair;
|
|
289
|
+
/**
|
|
290
|
+
* Count entity-attribute-value triples returned by the contradiction detection prompt.
|
|
291
|
+
* Accepts any shape the LLM may produce: object of arrays keyed by noteId, flat array,
|
|
292
|
+
* or null/undefined. Unrecognized shapes return 0 so a malformed response can't poison
|
|
293
|
+
* the aggregate counter.
|
|
294
|
+
*/
|
|
295
|
+
private countEntityTriples;
|
|
296
|
+
/** Resolve a detected contradiction: flag both notes if high-importance/Protected, otherwise revoke the loser. */
|
|
297
|
+
private resolveContradiction;
|
|
298
|
+
/** Decide whether a contradiction pair must be flagged rather than auto-resolved. */
|
|
299
|
+
private shouldFlagContradiction;
|
|
300
|
+
/** Flag both notes in a contradiction pair with a cross-referencing audit comment. */
|
|
301
|
+
private flagContradictionPair;
|
|
109
302
|
/**
|
|
110
303
|
* Process a single consolidation cluster: run the LLM prompt, create the consolidated note,
|
|
111
304
|
* and revoke source notes.
|
|
305
|
+
*
|
|
306
|
+
* Emits a per-cluster "Process Consolidation Cluster" observability step that runs
|
|
307
|
+
* between the parent consolidation step's create/finalize calls, producing an
|
|
308
|
+
* implicit parent-child relationship via step-number ordering.
|
|
112
309
|
*/
|
|
113
310
|
private processConsolidationCluster;
|
|
311
|
+
/**
|
|
312
|
+
* Prepare the prompt payload for consolidation. Handles drift prevention: if any source
|
|
313
|
+
* note is at the consolidation count cap, resolve back to original generation-0 sources
|
|
314
|
+
* to avoid re-summarizing summaries. Returns both the notes used (for verification) and
|
|
315
|
+
* the prompt data.
|
|
316
|
+
*/
|
|
317
|
+
private buildConsolidationPromptData;
|
|
318
|
+
/**
|
|
319
|
+
* Execute the consolidation prompt and parse the result. Returns null on any failure
|
|
320
|
+
* so the caller can short-circuit.
|
|
321
|
+
*/
|
|
322
|
+
private runConsolidationPrompt;
|
|
323
|
+
/**
|
|
324
|
+
* Build, validate, and save the consolidated note. Returns the saved entity on success,
|
|
325
|
+
* null on save failure. The LLM-returned Type is validated against the allowed union and
|
|
326
|
+
* falls back to the template note's Type on hallucination — previously a blind `as` cast
|
|
327
|
+
* silently wrote invalid values.
|
|
328
|
+
*/
|
|
329
|
+
private createConsolidatedNote;
|
|
330
|
+
/**
|
|
331
|
+
* Run post-consolidation entity verification and, if entities are missing, append a
|
|
332
|
+
* warning to the saved note's Comments (best-effort, non-blocking). Returns the
|
|
333
|
+
* verification result so the caller can aggregate it into the phase-level
|
|
334
|
+
* observability step.
|
|
335
|
+
*/
|
|
336
|
+
private annotateConsolidationVerification;
|
|
337
|
+
/**
|
|
338
|
+
* Revoke source notes in parallel, linking each to the consolidated replacement.
|
|
339
|
+
* Returns the number of notes successfully revoked.
|
|
340
|
+
*/
|
|
341
|
+
private revokeSourceNotes;
|
|
114
342
|
/**
|
|
115
343
|
* Apply scope fields to a consolidated note based on the LLM's scope recommendation.
|
|
116
344
|
* Mirrors the scoping logic in CreateNoteRecords.
|
|
117
345
|
*/
|
|
118
346
|
private applyScopeToConsolidatedNote;
|
|
347
|
+
/**
|
|
348
|
+
* Prune notes that reference entities which no longer exist or are inactive.
|
|
349
|
+
* Checks AgentID, UserID, CompanyID, and SourceConversationID against current database state.
|
|
350
|
+
* Immutable-tier notes are never pruned. Caps at 200 notes per cycle.
|
|
351
|
+
*/
|
|
352
|
+
private pruneStaleReferences;
|
|
353
|
+
/**
|
|
354
|
+
* Load auto-generated, non-immutable Active notes that are candidates for orphan pruning.
|
|
355
|
+
*/
|
|
356
|
+
private loadPruneCandidateNotes;
|
|
357
|
+
/**
|
|
358
|
+
* Build in-memory lookup caches of which referenced users/companies/conversations still
|
|
359
|
+
* exist and which agents are still Active. Runs all three existence lookups in a single
|
|
360
|
+
* RunViews batch to minimize round trips.
|
|
361
|
+
*/
|
|
362
|
+
private buildReferenceExistenceCache;
|
|
363
|
+
/**
|
|
364
|
+
* Collect unique referenced IDs from the note batch and assemble a RunViews query list
|
|
365
|
+
* for existence checks. Returns the query list alongside a parallel mapping array that
|
|
366
|
+
* tells the caller which target cache each query result belongs in.
|
|
367
|
+
*/
|
|
368
|
+
private buildExistenceLookupQueries;
|
|
369
|
+
/**
|
|
370
|
+
* Evaluate a single note's foreign-key references against the existence caches, returning
|
|
371
|
+
* human-readable reasons for any orphaned fields. Increments the supplied counter as a
|
|
372
|
+
* side effect so aggregate totals are tracked without a second pass.
|
|
373
|
+
*/
|
|
374
|
+
private detectOrphanReasons;
|
|
375
|
+
/**
|
|
376
|
+
* Archive a single orphaned note with an audit-trail Comments entry. Returns true on success.
|
|
377
|
+
*/
|
|
378
|
+
private archiveOrphanedNote;
|
|
379
|
+
/**
|
|
380
|
+
* Compute Ebbinghaus-inspired proportional decay factor for a note.
|
|
381
|
+
* Returns a multiplier (0-1) to apply to the note's ImportanceScore.
|
|
382
|
+
* Per research: "decay should be proportional (multiply all strengths by a factor <1),
|
|
383
|
+
* not threshold-based deletion — this preserves relative importance ordering."
|
|
384
|
+
*/
|
|
385
|
+
private computeDecayFactor;
|
|
386
|
+
/**
|
|
387
|
+
* Decay-based archival replacing fixed 90/180-day retention windows.
|
|
388
|
+
* Uses Ebbinghaus-inspired decay function weighted by ImportanceScore.
|
|
389
|
+
* Respects protection tiers: Immutable=never, Protected=365d extended, Ephemeral=2x decay.
|
|
390
|
+
* Handles both notes and examples. Respects per-agent AutoArchiveEnabled.
|
|
391
|
+
*/
|
|
392
|
+
private decayBasedArchival;
|
|
393
|
+
/**
|
|
394
|
+
* Summarize raw decay factors (values in [0,1]) into a min/max/mean triple for
|
|
395
|
+
* the observability step. Returns null when no factors were computed (empty
|
|
396
|
+
* cohort or all notes skipped via tier/config).
|
|
397
|
+
*/
|
|
398
|
+
private summarizeDecayFactors;
|
|
399
|
+
/** Archive notes and examples past their explicit ExpiresAt timestamp, regardless of decay score. */
|
|
400
|
+
private archiveExpiredItems;
|
|
401
|
+
private loadExpiredItems;
|
|
402
|
+
private archiveExpiredNote;
|
|
403
|
+
private archiveExpiredExample;
|
|
404
|
+
/**
|
|
405
|
+
* Apply proportional decay to ImportanceScores, archiving only when score reaches the floor.
|
|
406
|
+
* Per research: "decay should be proportional (multiply all strengths by a factor <1),
|
|
407
|
+
* not threshold-based deletion — this preserves relative importance ordering while reducing overall load."
|
|
408
|
+
* Notes without ImportanceScore (not yet scored) are skipped entirely.
|
|
409
|
+
*
|
|
410
|
+
* Threads a stats accumulator through decayOneNote/decayOneExample to collect
|
|
411
|
+
* decay-factor distribution and tier-specific counts for observability.
|
|
412
|
+
*/
|
|
413
|
+
private applyProportionalDecay;
|
|
414
|
+
/**
|
|
415
|
+
* Fetch notes and examples in parallel — they're independent.
|
|
416
|
+
*/
|
|
417
|
+
private loadDecayCandidates;
|
|
418
|
+
/**
|
|
419
|
+
* Apply proportional decay to a single note. Archives if the decayed score drops below
|
|
420
|
+
* the archival floor, otherwise writes the reduced score (skipping when the factor is
|
|
421
|
+
* effectively 1.0 to avoid unnecessary saves).
|
|
422
|
+
*/
|
|
423
|
+
private decayOneNote;
|
|
424
|
+
/**
|
|
425
|
+
* Apply proportional decay to a single example, using SuccessScore as a proxy importance.
|
|
426
|
+
* Archives if the effective score drops below the archival floor.
|
|
427
|
+
*/
|
|
428
|
+
private decayOneExample;
|
|
429
|
+
/**
|
|
430
|
+
* Run all 5 maintenance phases in order: importance scoring, consolidation,
|
|
431
|
+
* contradiction detection, stale-reference pruning, and decay-based archival.
|
|
432
|
+
* Each phase is wrapped in try/catch so a failure in one does not abort the rest.
|
|
433
|
+
*
|
|
434
|
+
* `triggerType` flows through to the parent consolidation run step so observability
|
|
435
|
+
* records *why* the maintenance cycle fired this run.
|
|
436
|
+
*/
|
|
437
|
+
private runMaintenancePhases;
|
|
438
|
+
private runImportancePhase;
|
|
439
|
+
private runConsolidationPhase;
|
|
440
|
+
/** Aggregate per-cluster verification results into a single phase-level run step. */
|
|
441
|
+
private emitVerificationRunStep;
|
|
442
|
+
private runContradictionPhase;
|
|
443
|
+
/**
|
|
444
|
+
* Prune and decay are independent — run in parallel via Promise.allSettled so one failure
|
|
445
|
+
* doesn't block the other.
|
|
446
|
+
*/
|
|
447
|
+
private runPruneAndDecayPhases;
|
|
448
|
+
private runPrunePhase;
|
|
449
|
+
private runDecayPhase;
|
|
450
|
+
/** Build a human-readable summary string from maintenance phase results. */
|
|
451
|
+
private buildMaintenanceSummary;
|
|
119
452
|
/**
|
|
120
453
|
* Create example records from extracted data.
|
|
121
454
|
* Inherits scope from source agent run and applies scopeLevel to determine scope specificity.
|
|
@@ -129,4 +462,5 @@ export declare class MemoryManagerAgent extends BaseAgent {
|
|
|
129
462
|
stepCount: number;
|
|
130
463
|
}>;
|
|
131
464
|
}
|
|
465
|
+
export {};
|
|
132
466
|
//# sourceMappingURL=memory-manager-agent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-manager-agent.d.ts","sourceRoot":"","sources":["../src/memory-manager-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAoD,MAAM,sBAAsB,CAAC;AAUlG,OAAO,EAAqC,kBAAkB,EAAE,kBAAkB,EAAE,iBAAiB,EAAqD,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"memory-manager-agent.d.ts","sourceRoot":"","sources":["../src/memory-manager-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAoD,MAAM,sBAAsB,CAAC;AAUlG,OAAO,EAAqC,kBAAkB,EAAE,kBAAkB,EAAE,iBAAiB,EAAqD,MAAM,8BAA8B,CAAC;AA2J/L,yFAAyF;AACzF,UAAU,+BAA+B;IACrC,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,MAAM,EAAE,OAAO,CAAC;CACnB;AAkRD;;;;GAIG;AACH,qBACa,kBAAmB,SAAQ,SAAS;IAC7C,+CAA+C;IAC/C,OAAO,CAAC,QAAQ,CAAkB;IAClC,0CAA0C;IAC1C,OAAO,CAAC,WAAW,CAAuB;IAC1C,iDAAiD;IACjD,OAAO,CAAC,YAAY,CAAa;IACjC,uCAAuC;IACvC,OAAO,CAAC,YAAY,CAAyB;IAE7C,8GAA8G;IAC9G,OAAO,CAAC,MAAM,CAAC,WAAW;IAK1B;;;OAGG;YACW,aAAa;IAyC3B;;OAEG;YAC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