@framers/agentos 0.1.46 → 0.1.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/cognitive_substrate/IGMI.d.ts +2 -0
- package/dist/cognitive_substrate/IGMI.d.ts.map +1 -1
- package/dist/cognitive_substrate/IGMI.js.map +1 -1
- package/dist/cognitive_substrate/personas/IPersonaDefinition.d.ts +2 -0
- package/dist/cognitive_substrate/personas/IPersonaDefinition.d.ts.map +1 -1
- package/dist/core/audio/AdaptiveVAD.d.ts +147 -0
- package/dist/core/audio/AdaptiveVAD.d.ts.map +1 -0
- package/dist/core/audio/AdaptiveVAD.js +239 -0
- package/dist/core/audio/AdaptiveVAD.js.map +1 -0
- package/dist/core/audio/AudioProcessor.d.ts +121 -0
- package/dist/core/audio/AudioProcessor.d.ts.map +1 -0
- package/dist/core/audio/AudioProcessor.js +299 -0
- package/dist/core/audio/AudioProcessor.js.map +1 -0
- package/dist/core/audio/EnvironmentalCalibrator.d.ts +187 -0
- package/dist/core/audio/EnvironmentalCalibrator.d.ts.map +1 -0
- package/dist/core/audio/EnvironmentalCalibrator.js +360 -0
- package/dist/core/audio/EnvironmentalCalibrator.js.map +1 -0
- package/dist/core/audio/SilenceDetector.d.ts +111 -0
- package/dist/core/audio/SilenceDetector.d.ts.map +1 -0
- package/dist/core/audio/SilenceDetector.js +178 -0
- package/dist/core/audio/SilenceDetector.js.map +1 -0
- package/dist/core/llm/IPromptEngine.d.ts +2 -0
- package/dist/core/llm/IPromptEngine.d.ts.map +1 -1
- package/dist/core/llm/IPromptEngine.js.map +1 -1
- package/dist/core/llm/providers/implementations/OllamaProvider.js +2 -2
- package/dist/core/llm/providers/implementations/OllamaProvider.js.map +1 -1
- package/dist/core/llm/providers/implementations/OpenAIProvider.d.ts.map +1 -1
- package/dist/core/llm/providers/implementations/OpenAIProvider.js +8 -1
- package/dist/core/llm/providers/implementations/OpenAIProvider.js.map +1 -1
- package/dist/discovery/CapabilityIndex.d.ts.map +1 -1
- package/dist/discovery/CapabilityIndex.js +18 -4
- package/dist/discovery/CapabilityIndex.js.map +1 -1
- package/dist/extensions/ExtensionManager.d.ts.map +1 -1
- package/dist/extensions/ExtensionManager.js +9 -1
- package/dist/extensions/ExtensionManager.js.map +1 -1
- package/dist/extensions/types.d.ts +20 -2
- package/dist/extensions/types.d.ts.map +1 -1
- package/dist/extensions/types.js +4 -0
- package/dist/extensions/types.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/memory/CognitiveMemoryManager.d.ts +133 -0
- package/dist/memory/CognitiveMemoryManager.d.ts.map +1 -0
- package/dist/memory/CognitiveMemoryManager.js +519 -0
- package/dist/memory/CognitiveMemoryManager.js.map +1 -0
- package/dist/memory/config.d.ts +135 -0
- package/dist/memory/config.d.ts.map +1 -0
- package/dist/memory/config.js +28 -0
- package/dist/memory/config.js.map +1 -0
- package/dist/memory/consolidation/ConsolidationPipeline.d.ts +70 -0
- package/dist/memory/consolidation/ConsolidationPipeline.d.ts.map +1 -0
- package/dist/memory/consolidation/ConsolidationPipeline.js +301 -0
- package/dist/memory/consolidation/ConsolidationPipeline.js.map +1 -0
- package/dist/memory/context/CompactionEngine.d.ts +21 -0
- package/dist/memory/context/CompactionEngine.d.ts.map +1 -0
- package/dist/memory/context/CompactionEngine.js +35 -0
- package/dist/memory/context/CompactionEngine.js.map +1 -0
- package/dist/memory/context/CompactionLog.d.ts +50 -0
- package/dist/memory/context/CompactionLog.d.ts.map +1 -0
- package/dist/memory/context/CompactionLog.js +139 -0
- package/dist/memory/context/CompactionLog.js.map +1 -0
- package/dist/memory/context/ContextWindowManager.d.ts +114 -0
- package/dist/memory/context/ContextWindowManager.d.ts.map +1 -0
- package/dist/memory/context/ContextWindowManager.js +225 -0
- package/dist/memory/context/ContextWindowManager.js.map +1 -0
- package/dist/memory/context/RollingSummaryChain.d.ts +53 -0
- package/dist/memory/context/RollingSummaryChain.d.ts.map +1 -0
- package/dist/memory/context/RollingSummaryChain.js +193 -0
- package/dist/memory/context/RollingSummaryChain.js.map +1 -0
- package/dist/memory/context/index.d.ts +15 -0
- package/dist/memory/context/index.d.ts.map +1 -0
- package/dist/memory/context/index.js +14 -0
- package/dist/memory/context/index.js.map +1 -0
- package/dist/memory/context/strategies/HierarchicalStrategy.d.ts +25 -0
- package/dist/memory/context/strategies/HierarchicalStrategy.d.ts.map +1 -0
- package/dist/memory/context/strategies/HierarchicalStrategy.js +240 -0
- package/dist/memory/context/strategies/HierarchicalStrategy.js.map +1 -0
- package/dist/memory/context/strategies/HybridStrategy.d.ts +26 -0
- package/dist/memory/context/strategies/HybridStrategy.d.ts.map +1 -0
- package/dist/memory/context/strategies/HybridStrategy.js +245 -0
- package/dist/memory/context/strategies/HybridStrategy.js.map +1 -0
- package/dist/memory/context/strategies/SlidingSummaryStrategy.d.ts +22 -0
- package/dist/memory/context/strategies/SlidingSummaryStrategy.d.ts.map +1 -0
- package/dist/memory/context/strategies/SlidingSummaryStrategy.js +203 -0
- package/dist/memory/context/strategies/SlidingSummaryStrategy.js.map +1 -0
- package/dist/memory/context/types.d.ts +120 -0
- package/dist/memory/context/types.d.ts.map +1 -0
- package/dist/memory/context/types.js +17 -0
- package/dist/memory/context/types.js.map +1 -0
- package/dist/memory/decay/DecayModel.d.ts +87 -0
- package/dist/memory/decay/DecayModel.d.ts.map +1 -0
- package/dist/memory/decay/DecayModel.js +117 -0
- package/dist/memory/decay/DecayModel.js.map +1 -0
- package/dist/memory/decay/RetrievalPriorityScorer.d.ts +63 -0
- package/dist/memory/decay/RetrievalPriorityScorer.d.ts.map +1 -0
- package/dist/memory/decay/RetrievalPriorityScorer.js +110 -0
- package/dist/memory/decay/RetrievalPriorityScorer.js.map +1 -0
- package/dist/memory/encoding/ContentFeatureDetector.d.ts +37 -0
- package/dist/memory/encoding/ContentFeatureDetector.d.ts.map +1 -0
- package/dist/memory/encoding/ContentFeatureDetector.js +176 -0
- package/dist/memory/encoding/ContentFeatureDetector.js.map +1 -0
- package/dist/memory/encoding/EncodingModel.d.ts +67 -0
- package/dist/memory/encoding/EncodingModel.d.ts.map +1 -0
- package/dist/memory/encoding/EncodingModel.js +171 -0
- package/dist/memory/encoding/EncodingModel.js.map +1 -0
- package/dist/memory/extension/CognitiveMemoryExtension.d.ts +18 -0
- package/dist/memory/extension/CognitiveMemoryExtension.d.ts.map +1 -0
- package/dist/memory/extension/CognitiveMemoryExtension.js +131 -0
- package/dist/memory/extension/CognitiveMemoryExtension.js.map +1 -0
- package/dist/memory/graph/GraphologyMemoryGraph.d.ts +29 -0
- package/dist/memory/graph/GraphologyMemoryGraph.d.ts.map +1 -0
- package/dist/memory/graph/GraphologyMemoryGraph.js +224 -0
- package/dist/memory/graph/GraphologyMemoryGraph.js.map +1 -0
- package/dist/memory/graph/IMemoryGraph.d.ts +70 -0
- package/dist/memory/graph/IMemoryGraph.d.ts.map +1 -0
- package/dist/memory/graph/IMemoryGraph.js +15 -0
- package/dist/memory/graph/IMemoryGraph.js.map +1 -0
- package/dist/memory/graph/KnowledgeGraphMemoryGraph.d.ts +38 -0
- package/dist/memory/graph/KnowledgeGraphMemoryGraph.d.ts.map +1 -0
- package/dist/memory/graph/KnowledgeGraphMemoryGraph.js +264 -0
- package/dist/memory/graph/KnowledgeGraphMemoryGraph.js.map +1 -0
- package/dist/memory/graph/SpreadingActivation.d.ts +36 -0
- package/dist/memory/graph/SpreadingActivation.d.ts.map +1 -0
- package/dist/memory/graph/SpreadingActivation.js +100 -0
- package/dist/memory/graph/SpreadingActivation.js.map +1 -0
- package/dist/memory/index.d.ts +52 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +43 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/observation/MemoryObserver.d.ts +59 -0
- package/dist/memory/observation/MemoryObserver.d.ts.map +1 -0
- package/dist/memory/observation/MemoryObserver.js +136 -0
- package/dist/memory/observation/MemoryObserver.js.map +1 -0
- package/dist/memory/observation/MemoryReflector.d.ts +51 -0
- package/dist/memory/observation/MemoryReflector.d.ts.map +1 -0
- package/dist/memory/observation/MemoryReflector.js +184 -0
- package/dist/memory/observation/MemoryReflector.js.map +1 -0
- package/dist/memory/observation/ObservationBuffer.d.ts +51 -0
- package/dist/memory/observation/ObservationBuffer.d.ts.map +1 -0
- package/dist/memory/observation/ObservationBuffer.js +81 -0
- package/dist/memory/observation/ObservationBuffer.js.map +1 -0
- package/dist/memory/prompt/MemoryFormatters.d.ts +22 -0
- package/dist/memory/prompt/MemoryFormatters.d.ts.map +1 -0
- package/dist/memory/prompt/MemoryFormatters.js +113 -0
- package/dist/memory/prompt/MemoryFormatters.js.map +1 -0
- package/dist/memory/prompt/MemoryPromptAssembler.d.ts +40 -0
- package/dist/memory/prompt/MemoryPromptAssembler.d.ts.map +1 -0
- package/dist/memory/prompt/MemoryPromptAssembler.js +180 -0
- package/dist/memory/prompt/MemoryPromptAssembler.js.map +1 -0
- package/dist/memory/prospective/ProspectiveMemoryManager.d.ts +83 -0
- package/dist/memory/prospective/ProspectiveMemoryManager.d.ts.map +1 -0
- package/dist/memory/prospective/ProspectiveMemoryManager.js +128 -0
- package/dist/memory/prospective/ProspectiveMemoryManager.js.map +1 -0
- package/dist/memory/store/MemoryStore.d.ts +76 -0
- package/dist/memory/store/MemoryStore.d.ts.map +1 -0
- package/dist/memory/store/MemoryStore.js +320 -0
- package/dist/memory/store/MemoryStore.js.map +1 -0
- package/dist/memory/types.d.ts +184 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +14 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/memory/working/CognitiveWorkingMemory.d.ts +87 -0
- package/dist/memory/working/CognitiveWorkingMemory.d.ts.map +1 -0
- package/dist/memory/working/CognitiveWorkingMemory.js +230 -0
- package/dist/memory/working/CognitiveWorkingMemory.js.map +1 -0
- package/dist/rag/EmbeddingManager.d.ts.map +1 -1
- package/dist/rag/EmbeddingManager.js +8 -1
- package/dist/rag/EmbeddingManager.js.map +1 -1
- package/dist/rag/HydeRetriever.d.ts +111 -0
- package/dist/rag/HydeRetriever.d.ts.map +1 -0
- package/dist/rag/HydeRetriever.js +143 -0
- package/dist/rag/HydeRetriever.js.map +1 -0
- package/dist/rag/IRetrievalAugmentor.d.ts +15 -0
- package/dist/rag/IRetrievalAugmentor.d.ts.map +1 -1
- package/dist/rag/index.d.ts +1 -0
- package/dist/rag/index.d.ts.map +1 -1
- package/dist/rag/index.js +2 -0
- package/dist/rag/index.js.map +1 -1
- package/dist/speech/SpeechProviderRegistry.d.ts +17 -0
- package/dist/speech/SpeechProviderRegistry.d.ts.map +1 -0
- package/dist/speech/SpeechProviderRegistry.js +47 -0
- package/dist/speech/SpeechProviderRegistry.js.map +1 -0
- package/dist/speech/SpeechRuntime.d.ts +30 -0
- package/dist/speech/SpeechRuntime.d.ts.map +1 -0
- package/dist/speech/SpeechRuntime.js +156 -0
- package/dist/speech/SpeechRuntime.js.map +1 -0
- package/dist/speech/SpeechSession.d.ts +37 -0
- package/dist/speech/SpeechSession.d.ts.map +1 -0
- package/dist/speech/SpeechSession.js +285 -0
- package/dist/speech/SpeechSession.js.map +1 -0
- package/dist/speech/audio.d.ts +3 -0
- package/dist/speech/audio.d.ts.map +1 -0
- package/dist/speech/audio.js +39 -0
- package/dist/speech/audio.js.map +1 -0
- package/dist/speech/index.d.ts +11 -0
- package/dist/speech/index.d.ts.map +1 -0
- package/dist/speech/index.js +11 -0
- package/dist/speech/index.js.map +1 -0
- package/dist/speech/providerCatalog.d.ts +7 -0
- package/dist/speech/providerCatalog.d.ts.map +1 -0
- package/dist/speech/providerCatalog.js +243 -0
- package/dist/speech/providerCatalog.js.map +1 -0
- package/dist/speech/providers/BuiltInAdaptiveVadProvider.d.ts +20 -0
- package/dist/speech/providers/BuiltInAdaptiveVadProvider.d.ts.map +1 -0
- package/dist/speech/providers/BuiltInAdaptiveVadProvider.js +29 -0
- package/dist/speech/providers/BuiltInAdaptiveVadProvider.js.map +1 -0
- package/dist/speech/providers/ElevenLabsTextToSpeechProvider.d.ts +20 -0
- package/dist/speech/providers/ElevenLabsTextToSpeechProvider.d.ts.map +1 -0
- package/dist/speech/providers/ElevenLabsTextToSpeechProvider.js +95 -0
- package/dist/speech/providers/ElevenLabsTextToSpeechProvider.js.map +1 -0
- package/dist/speech/providers/OpenAITextToSpeechProvider.d.ts +20 -0
- package/dist/speech/providers/OpenAITextToSpeechProvider.d.ts.map +1 -0
- package/dist/speech/providers/OpenAITextToSpeechProvider.js +75 -0
- package/dist/speech/providers/OpenAITextToSpeechProvider.js.map +1 -0
- package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.d.ts +18 -0
- package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.d.ts.map +1 -0
- package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.js +109 -0
- package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.js.map +1 -0
- package/dist/speech/types.d.ts +272 -0
- package/dist/speech/types.d.ts.map +1 -0
- package/dist/speech/types.js +2 -0
- package/dist/speech/types.js.map +1 -0
- package/package.json +22 -2
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Ebbinghaus forgetting curve, spaced repetition, and
|
|
3
|
+
* interference management.
|
|
4
|
+
*
|
|
5
|
+
* Cognitive science foundations:
|
|
6
|
+
* - **Ebbinghaus forgetting curve**: S(t) = S₀ · e^(-t / stability)
|
|
7
|
+
* - **Spaced repetition**: Each successful retrieval increases stability
|
|
8
|
+
* (desirable difficulty effect — harder retrievals grow stability more).
|
|
9
|
+
* - **Proactive interference**: Old similar memories impair new encoding.
|
|
10
|
+
* - **Retroactive interference**: New memories weaken old similar ones.
|
|
11
|
+
*
|
|
12
|
+
* @module agentos/memory/decay/DecayModel
|
|
13
|
+
*/
|
|
14
|
+
import type { MemoryTrace } from '../types.js';
|
|
15
|
+
import type { DecayConfig } from '../config.js';
|
|
16
|
+
/**
|
|
17
|
+
* Compute the current effective strength of a memory trace using the
|
|
18
|
+
* Ebbinghaus forgetting curve:
|
|
19
|
+
*
|
|
20
|
+
* S(t) = S₀ · e^(-Δt / stability)
|
|
21
|
+
*
|
|
22
|
+
* where Δt = now - lastAccessedAt.
|
|
23
|
+
*/
|
|
24
|
+
export declare function computeCurrentStrength(trace: MemoryTrace, now: number): number;
|
|
25
|
+
export interface RetrievalUpdateResult {
|
|
26
|
+
/** New encoding strength (small bump). */
|
|
27
|
+
encodingStrength: number;
|
|
28
|
+
/** New stability (grows based on difficulty). */
|
|
29
|
+
stability: number;
|
|
30
|
+
/** Incremented retrieval count. */
|
|
31
|
+
retrievalCount: number;
|
|
32
|
+
/** Updated timestamp. */
|
|
33
|
+
lastAccessedAt: number;
|
|
34
|
+
/** Incremented access count. */
|
|
35
|
+
accessCount: number;
|
|
36
|
+
/** Doubled reinforcement interval. */
|
|
37
|
+
reinforcementInterval: number;
|
|
38
|
+
/** Next reinforcement due. */
|
|
39
|
+
nextReinforcementAt: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Update a trace's decay parameters after a successful retrieval.
|
|
43
|
+
*
|
|
44
|
+
* Implements the **desirable difficulty** effect: memories that were
|
|
45
|
+
* harder to retrieve (lower current strength) receive a larger stability
|
|
46
|
+
* boost, making the next retrieval easier and longer-lasting.
|
|
47
|
+
*
|
|
48
|
+
* Stability growth also accounts for:
|
|
49
|
+
* - Diminishing returns on repeated retrievals (logarithmic saturation)
|
|
50
|
+
* - Emotional intensity bonus (emotional memories consolidate faster)
|
|
51
|
+
*/
|
|
52
|
+
export declare function updateOnRetrieval(trace: MemoryTrace, now: number): RetrievalUpdateResult;
|
|
53
|
+
export interface InterferenceVictim {
|
|
54
|
+
traceId: string;
|
|
55
|
+
strengthReduction: number;
|
|
56
|
+
}
|
|
57
|
+
export interface InterferenceResult {
|
|
58
|
+
/** Existing traces whose strength should be reduced (retroactive). */
|
|
59
|
+
retroactiveVictims: InterferenceVictim[];
|
|
60
|
+
/** Amount to reduce new trace's strength by (proactive). */
|
|
61
|
+
proactiveReduction: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Compute interference effects when a new trace is encoded alongside
|
|
65
|
+
* existing similar traces.
|
|
66
|
+
*
|
|
67
|
+
* - **Proactive interference**: Old similar traces impair new encoding
|
|
68
|
+
* (reduce new trace's initial strength).
|
|
69
|
+
* - **Retroactive interference**: New trace weakens old similar traces
|
|
70
|
+
* (reduce their encoding strength).
|
|
71
|
+
*
|
|
72
|
+
* Similarity is provided externally (cosine similarity of embeddings).
|
|
73
|
+
*
|
|
74
|
+
* @param similarities Array of { traceId, similarity } for existing traces.
|
|
75
|
+
* @param config Decay configuration with interference threshold.
|
|
76
|
+
*/
|
|
77
|
+
export declare function computeInterference(similarities: Array<{
|
|
78
|
+
traceId: string;
|
|
79
|
+
similarity: number;
|
|
80
|
+
currentStrength: number;
|
|
81
|
+
}>, config?: DecayConfig): InterferenceResult;
|
|
82
|
+
/**
|
|
83
|
+
* Identify traces that have decayed below the pruning threshold.
|
|
84
|
+
* These should be soft-deleted (isActive = false).
|
|
85
|
+
*/
|
|
86
|
+
export declare function findPrunableTraces(traces: MemoryTrace[], now: number, config?: DecayConfig): string[];
|
|
87
|
+
//# sourceMappingURL=DecayModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DecayModel.d.ts","sourceRoot":"","sources":["../../../src/memory/decay/DecayModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAOhD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAG9E;AAMD,MAAM,WAAW,qBAAqB;IACpC,0CAA0C;IAC1C,gBAAgB,EAAE,MAAM,CAAC;IACzB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,yBAAyB;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,gCAAgC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,sCAAsC;IACtC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,8BAA8B;IAC9B,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,qBAAqB,CA4BxF;AAMD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,kBAAkB,EAAE,kBAAkB,EAAE,CAAC;IACzC,4DAA4D;IAC5D,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,KAAK,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,CAAC,EACrF,MAAM,GAAE,WAAkC,GACzC,kBAAkB,CAuBpB;AAMD;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,WAAW,EAAE,EACrB,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,WAAkC,GACzC,MAAM,EAAE,CAWV"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Ebbinghaus forgetting curve, spaced repetition, and
|
|
3
|
+
* interference management.
|
|
4
|
+
*
|
|
5
|
+
* Cognitive science foundations:
|
|
6
|
+
* - **Ebbinghaus forgetting curve**: S(t) = S₀ · e^(-t / stability)
|
|
7
|
+
* - **Spaced repetition**: Each successful retrieval increases stability
|
|
8
|
+
* (desirable difficulty effect — harder retrievals grow stability more).
|
|
9
|
+
* - **Proactive interference**: Old similar memories impair new encoding.
|
|
10
|
+
* - **Retroactive interference**: New memories weaken old similar ones.
|
|
11
|
+
*
|
|
12
|
+
* @module agentos/memory/decay/DecayModel
|
|
13
|
+
*/
|
|
14
|
+
import { DEFAULT_DECAY_CONFIG } from '../config.js';
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// Current strength calculation
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
/**
|
|
19
|
+
* Compute the current effective strength of a memory trace using the
|
|
20
|
+
* Ebbinghaus forgetting curve:
|
|
21
|
+
*
|
|
22
|
+
* S(t) = S₀ · e^(-Δt / stability)
|
|
23
|
+
*
|
|
24
|
+
* where Δt = now - lastAccessedAt.
|
|
25
|
+
*/
|
|
26
|
+
export function computeCurrentStrength(trace, now) {
|
|
27
|
+
const elapsed = Math.max(0, now - trace.lastAccessedAt);
|
|
28
|
+
return trace.encodingStrength * Math.exp(-elapsed / trace.stability);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Update a trace's decay parameters after a successful retrieval.
|
|
32
|
+
*
|
|
33
|
+
* Implements the **desirable difficulty** effect: memories that were
|
|
34
|
+
* harder to retrieve (lower current strength) receive a larger stability
|
|
35
|
+
* boost, making the next retrieval easier and longer-lasting.
|
|
36
|
+
*
|
|
37
|
+
* Stability growth also accounts for:
|
|
38
|
+
* - Diminishing returns on repeated retrievals (logarithmic saturation)
|
|
39
|
+
* - Emotional intensity bonus (emotional memories consolidate faster)
|
|
40
|
+
*/
|
|
41
|
+
export function updateOnRetrieval(trace, now) {
|
|
42
|
+
const currentStrength = computeCurrentStrength(trace, now);
|
|
43
|
+
// Desirable difficulty: weaker current strength → more stability growth
|
|
44
|
+
const difficultyBonus = Math.max(0.1, 1 - currentStrength);
|
|
45
|
+
// Diminishing returns on repeated retrievals
|
|
46
|
+
const retrievalDiminish = 1 / (1 + 0.1 * trace.retrievalCount);
|
|
47
|
+
// Emotional consolidation bonus
|
|
48
|
+
const emotionalBonus = 1 + trace.emotionalContext.intensity * 0.3;
|
|
49
|
+
// Stability growth factor
|
|
50
|
+
const growthFactor = (1.5 + difficultyBonus * 2.0) * retrievalDiminish * emotionalBonus;
|
|
51
|
+
const newStability = trace.stability * growthFactor;
|
|
52
|
+
const newStrength = Math.min(1.0, trace.encodingStrength + 0.1);
|
|
53
|
+
const newInterval = trace.reinforcementInterval * 2;
|
|
54
|
+
return {
|
|
55
|
+
encodingStrength: newStrength,
|
|
56
|
+
stability: newStability,
|
|
57
|
+
retrievalCount: trace.retrievalCount + 1,
|
|
58
|
+
lastAccessedAt: now,
|
|
59
|
+
accessCount: trace.accessCount + 1,
|
|
60
|
+
reinforcementInterval: newInterval,
|
|
61
|
+
nextReinforcementAt: now + newInterval,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Compute interference effects when a new trace is encoded alongside
|
|
66
|
+
* existing similar traces.
|
|
67
|
+
*
|
|
68
|
+
* - **Proactive interference**: Old similar traces impair new encoding
|
|
69
|
+
* (reduce new trace's initial strength).
|
|
70
|
+
* - **Retroactive interference**: New trace weakens old similar traces
|
|
71
|
+
* (reduce their encoding strength).
|
|
72
|
+
*
|
|
73
|
+
* Similarity is provided externally (cosine similarity of embeddings).
|
|
74
|
+
*
|
|
75
|
+
* @param similarities Array of { traceId, similarity } for existing traces.
|
|
76
|
+
* @param config Decay configuration with interference threshold.
|
|
77
|
+
*/
|
|
78
|
+
export function computeInterference(similarities, config = DEFAULT_DECAY_CONFIG) {
|
|
79
|
+
const victims = [];
|
|
80
|
+
let proactiveReduction = 0;
|
|
81
|
+
for (const entry of similarities) {
|
|
82
|
+
if (entry.similarity <= config.interferenceThreshold)
|
|
83
|
+
continue;
|
|
84
|
+
const overlapStrength = entry.similarity - config.interferenceThreshold;
|
|
85
|
+
// Scale: 0 at threshold, ~0.15 at similarity 1.0
|
|
86
|
+
const scaledOverlap = overlapStrength / (1 - config.interferenceThreshold);
|
|
87
|
+
// Retroactive: new trace interferes with old
|
|
88
|
+
const retroReduction = scaledOverlap * 0.15;
|
|
89
|
+
victims.push({ traceId: entry.traceId, strengthReduction: retroReduction });
|
|
90
|
+
// Proactive: old trace interferes with new
|
|
91
|
+
proactiveReduction += scaledOverlap * 0.1 * entry.currentStrength;
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
retroactiveVictims: victims,
|
|
95
|
+
proactiveReduction: Math.min(0.3, proactiveReduction), // cap proactive interference
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
// Batch decay sweep (for consolidation pipeline)
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
/**
|
|
102
|
+
* Identify traces that have decayed below the pruning threshold.
|
|
103
|
+
* These should be soft-deleted (isActive = false).
|
|
104
|
+
*/
|
|
105
|
+
export function findPrunableTraces(traces, now, config = DEFAULT_DECAY_CONFIG) {
|
|
106
|
+
return traces
|
|
107
|
+
.filter((t) => {
|
|
108
|
+
if (!t.isActive)
|
|
109
|
+
return false;
|
|
110
|
+
const strength = computeCurrentStrength(t, now);
|
|
111
|
+
return (strength < config.pruningThreshold &&
|
|
112
|
+
t.emotionalContext.intensity < 0.3 // don't prune emotional memories easily
|
|
113
|
+
);
|
|
114
|
+
})
|
|
115
|
+
.map((t) => t.id);
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=DecayModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DecayModel.js","sourceRoot":"","sources":["../../../src/memory/decay/DecayModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,8EAA8E;AAC9E,+BAA+B;AAC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Z,IAAI,CAAC,CAAC,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC9B,MAAM,QAAQ,GAAG,sBAAsB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAChD,OAAO,CACL,QAAQ,GAAG,MAAM,CAAC,gBAAgB;YAClC,CAAC,CAAC,gBAAgB,CAAC,SAAS,GAAG,GAAG,CAAC,wCAAwC;SAC5E,CAAC;IACJ,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Composite retrieval priority scoring.
|
|
3
|
+
*
|
|
4
|
+
* Combines multiple signals into a single score for ranking memory traces:
|
|
5
|
+
* - Current strength (Ebbinghaus decay)
|
|
6
|
+
* - Vector similarity (semantic relevance)
|
|
7
|
+
* - Recency boost (temporal proximity)
|
|
8
|
+
* - Emotional congruence (mood-congruent recall)
|
|
9
|
+
* - Graph activation (spreading activation — 0 in Batch 1)
|
|
10
|
+
* - Importance (inherent importance of the memory)
|
|
11
|
+
*
|
|
12
|
+
* @module agentos/memory/decay/RetrievalPriorityScorer
|
|
13
|
+
*/
|
|
14
|
+
import type { MemoryTrace, ScoredMemoryTrace, PartiallyRetrievedTrace } from '../types.js';
|
|
15
|
+
import type { PADState, DecayConfig } from '../config.js';
|
|
16
|
+
export interface ScoringWeights {
|
|
17
|
+
strength: number;
|
|
18
|
+
similarity: number;
|
|
19
|
+
recency: number;
|
|
20
|
+
emotionalCongruence: number;
|
|
21
|
+
graphActivation: number;
|
|
22
|
+
importance: number;
|
|
23
|
+
}
|
|
24
|
+
export declare const DEFAULT_SCORING_WEIGHTS: ScoringWeights;
|
|
25
|
+
/**
|
|
26
|
+
* Recency boost: exponential decay from recent events.
|
|
27
|
+
* Recent memories (within the half-life window) get a small bonus.
|
|
28
|
+
*
|
|
29
|
+
* boost = 1 + 0.2 · e^(-elapsed / halfLife)
|
|
30
|
+
*/
|
|
31
|
+
export declare function computeRecencyBoost(lastAccessedAt: number, now: number, halfLifeMs?: number): number;
|
|
32
|
+
/**
|
|
33
|
+
* Mood-congruent recall: current mood biases retrieval toward memories
|
|
34
|
+
* with matching emotional valence.
|
|
35
|
+
*
|
|
36
|
+
* congruence = 1 + max(0, currentValence · traceValence) · 0.25
|
|
37
|
+
*/
|
|
38
|
+
export declare function computeEmotionalCongruence(currentMood: PADState, traceValence: number): number;
|
|
39
|
+
export interface ScoringContext {
|
|
40
|
+
currentMood: PADState;
|
|
41
|
+
now: number;
|
|
42
|
+
/** Set to true to disable emotional congruence bias. */
|
|
43
|
+
neutralMood?: boolean;
|
|
44
|
+
decayConfig?: DecayConfig;
|
|
45
|
+
weights?: ScoringWeights;
|
|
46
|
+
}
|
|
47
|
+
export interface CandidateTrace {
|
|
48
|
+
trace: MemoryTrace;
|
|
49
|
+
/** Cosine similarity from vector search (0-1). */
|
|
50
|
+
vectorSimilarity: number;
|
|
51
|
+
/** Activation level from spreading activation (0-1). 0 if graph not available. */
|
|
52
|
+
graphActivation?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Score a batch of candidate traces and return them sorted by priority.
|
|
56
|
+
*/
|
|
57
|
+
export declare function scoreAndRankTraces(candidates: CandidateTrace[], context: ScoringContext): ScoredMemoryTrace[];
|
|
58
|
+
/**
|
|
59
|
+
* Detect partially-accessible memories (high relevance but low strength).
|
|
60
|
+
* These are memories the agent "almost" remembers — like tip-of-the-tongue states.
|
|
61
|
+
*/
|
|
62
|
+
export declare function detectPartiallyRetrieved(candidates: CandidateTrace[], now: number): PartiallyRetrievedTrace[];
|
|
63
|
+
//# sourceMappingURL=RetrievalPriorityScorer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RetrievalPriorityScorer.d.ts","sourceRoot":"","sources":["../../../src/memory/decay/RetrievalPriorityScorer.ts"],"names":[],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AAc,EAAE,EAC5B,GAAG,EAAE,MAAM,GACV,uBAAuB,EAAE,CAc3B"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Composite retrieval priority scoring.
|
|
3
|
+
*
|
|
4
|
+
* Combines multiple signals into a single score for ranking memory traces:
|
|
5
|
+
* - Current strength (Ebbinghaus decay)
|
|
6
|
+
* - Vector similarity (semantic relevance)
|
|
7
|
+
* - Recency boost (temporal proximity)
|
|
8
|
+
* - Emotional congruence (mood-congruent recall)
|
|
9
|
+
* - Graph activation (spreading activation — 0 in Batch 1)
|
|
10
|
+
* - Importance (inherent importance of the memory)
|
|
11
|
+
*
|
|
12
|
+
* @module agentos/memory/decay/RetrievalPriorityScorer
|
|
13
|
+
*/
|
|
14
|
+
import { DEFAULT_DECAY_CONFIG } from '../config.js';
|
|
15
|
+
import { computeCurrentStrength } from './DecayModel.js';
|
|
16
|
+
export const DEFAULT_SCORING_WEIGHTS = {
|
|
17
|
+
strength: 0.25,
|
|
18
|
+
similarity: 0.35,
|
|
19
|
+
recency: 0.10,
|
|
20
|
+
emotionalCongruence: 0.15,
|
|
21
|
+
graphActivation: 0.10,
|
|
22
|
+
importance: 0.05,
|
|
23
|
+
};
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Individual score components
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
/**
|
|
28
|
+
* Recency boost: exponential decay from recent events.
|
|
29
|
+
* Recent memories (within the half-life window) get a small bonus.
|
|
30
|
+
*
|
|
31
|
+
* boost = 1 + 0.2 · e^(-elapsed / halfLife)
|
|
32
|
+
*/
|
|
33
|
+
export function computeRecencyBoost(lastAccessedAt, now, halfLifeMs = DEFAULT_DECAY_CONFIG.recencyHalfLifeMs) {
|
|
34
|
+
const elapsed = Math.max(0, now - lastAccessedAt);
|
|
35
|
+
return 1 + 0.2 * Math.exp(-elapsed / halfLifeMs);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Mood-congruent recall: current mood biases retrieval toward memories
|
|
39
|
+
* with matching emotional valence.
|
|
40
|
+
*
|
|
41
|
+
* congruence = 1 + max(0, currentValence · traceValence) · 0.25
|
|
42
|
+
*/
|
|
43
|
+
export function computeEmotionalCongruence(currentMood, traceValence) {
|
|
44
|
+
const match = Math.max(0, currentMood.valence * traceValence);
|
|
45
|
+
return 1 + match * 0.25;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Score a batch of candidate traces and return them sorted by priority.
|
|
49
|
+
*/
|
|
50
|
+
export function scoreAndRankTraces(candidates, context) {
|
|
51
|
+
const w = context.weights ?? DEFAULT_SCORING_WEIGHTS;
|
|
52
|
+
const config = context.decayConfig ?? DEFAULT_DECAY_CONFIG;
|
|
53
|
+
const scored = candidates.map(({ trace, vectorSimilarity, graphActivation }) => {
|
|
54
|
+
const strengthScore = computeCurrentStrength(trace, context.now);
|
|
55
|
+
const similarityScore = vectorSimilarity;
|
|
56
|
+
const recencyScore = computeRecencyBoost(trace.lastAccessedAt, context.now, config.recencyHalfLifeMs);
|
|
57
|
+
const emotionalCongruenceScore = context.neutralMood
|
|
58
|
+
? 1.0
|
|
59
|
+
: computeEmotionalCongruence(context.currentMood, trace.emotionalContext.valence);
|
|
60
|
+
const graphActivationScore = graphActivation ?? 0;
|
|
61
|
+
const importanceScore = trace.provenance.confidence * 0.5 + 0.5; // blend confidence with base
|
|
62
|
+
// Normalise recency and emotional congruence to ~0-1 range for weighted sum
|
|
63
|
+
const normRecency = (recencyScore - 1.0) / 0.2; // 0 when no boost, 1 when max boost
|
|
64
|
+
const normEmotional = (emotionalCongruenceScore - 1.0) / 0.25;
|
|
65
|
+
const compositeScore = w.strength * strengthScore +
|
|
66
|
+
w.similarity * similarityScore +
|
|
67
|
+
w.recency * normRecency +
|
|
68
|
+
w.emotionalCongruence * normEmotional +
|
|
69
|
+
w.graphActivation * graphActivationScore +
|
|
70
|
+
w.importance * importanceScore;
|
|
71
|
+
return {
|
|
72
|
+
...trace,
|
|
73
|
+
retrievalScore: Math.max(0, Math.min(1, compositeScore)),
|
|
74
|
+
scoreBreakdown: {
|
|
75
|
+
strengthScore,
|
|
76
|
+
similarityScore,
|
|
77
|
+
recencyScore: normRecency,
|
|
78
|
+
emotionalCongruenceScore: normEmotional,
|
|
79
|
+
graphActivationScore,
|
|
80
|
+
importanceScore,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
// Sort descending by composite score
|
|
85
|
+
scored.sort((a, b) => b.retrievalScore - a.retrievalScore);
|
|
86
|
+
return scored;
|
|
87
|
+
}
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
// Tip-of-the-tongue detection
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
/**
|
|
92
|
+
* Detect partially-accessible memories (high relevance but low strength).
|
|
93
|
+
* These are memories the agent "almost" remembers — like tip-of-the-tongue states.
|
|
94
|
+
*/
|
|
95
|
+
export function detectPartiallyRetrieved(candidates, now) {
|
|
96
|
+
return candidates
|
|
97
|
+
.filter(({ trace, vectorSimilarity }) => {
|
|
98
|
+
const strength = computeCurrentStrength(trace, now);
|
|
99
|
+
return vectorSimilarity > 0.6 && (strength < 0.3 || trace.provenance.confidence < 0.4);
|
|
100
|
+
})
|
|
101
|
+
.map(({ trace, vectorSimilarity }) => ({
|
|
102
|
+
traceId: trace.id,
|
|
103
|
+
confidence: Math.min(trace.provenance.confidence, vectorSimilarity * 0.5),
|
|
104
|
+
partialContent: trace.content.length > 100
|
|
105
|
+
? trace.content.substring(0, 100) + '...'
|
|
106
|
+
: trace.content,
|
|
107
|
+
suggestedCues: trace.tags.slice(0, 3),
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=RetrievalPriorityScorer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RetrievalPriorityScorer.js","sourceRoot":"","sources":["../../../src/memory/decay/RetrievalPrioritySc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feature detection for memory encoding.
|
|
3
|
+
*
|
|
4
|
+
* Three strategies (configurable per-agent):
|
|
5
|
+
* - `keyword` — fast regex/lexicon-based heuristics (zero latency, no LLM cost)
|
|
6
|
+
* - `llm` — cheap LLM call for accurate classification
|
|
7
|
+
* - `hybrid` — keywords in real-time, LLM retroactively during consolidation
|
|
8
|
+
*
|
|
9
|
+
* @module agentos/memory/encoding/ContentFeatureDetector
|
|
10
|
+
*/
|
|
11
|
+
import type { ContentFeatures } from '../types.js';
|
|
12
|
+
export interface IContentFeatureDetector {
|
|
13
|
+
detect(text: string): Promise<ContentFeatures>;
|
|
14
|
+
}
|
|
15
|
+
export declare class KeywordFeatureDetector implements IContentFeatureDetector {
|
|
16
|
+
detect(text: string): Promise<ContentFeatures>;
|
|
17
|
+
}
|
|
18
|
+
export declare class LlmFeatureDetector implements IContentFeatureDetector {
|
|
19
|
+
private llmInvoker;
|
|
20
|
+
constructor(llmInvoker: (system: string, user: string) => Promise<string>);
|
|
21
|
+
detect(text: string): Promise<ContentFeatures>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Uses keyword detection for real-time encoding. Exposes `detectWithLlm()`
|
|
25
|
+
* for retroactive re-classification during consolidation.
|
|
26
|
+
*/
|
|
27
|
+
export declare class HybridFeatureDetector implements IContentFeatureDetector {
|
|
28
|
+
private keyword;
|
|
29
|
+
private llm;
|
|
30
|
+
constructor(llmInvoker?: (system: string, user: string) => Promise<string>);
|
|
31
|
+
/** Real-time detection: keyword only (zero latency). */
|
|
32
|
+
detect(text: string): Promise<ContentFeatures>;
|
|
33
|
+
/** Deferred detection: LLM-based (called during consolidation). */
|
|
34
|
+
detectWithLlm(text: string): Promise<ContentFeatures>;
|
|
35
|
+
}
|
|
36
|
+
export declare function createFeatureDetector(strategy: 'keyword' | 'llm' | 'hybrid', llmInvoker?: (system: string, user: string) => Promise<string>): IContentFeatureDetector;
|
|
37
|
+
//# sourceMappingURL=ContentFeatureDetector.d.ts.map
|
|
@@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azB"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Content feature detection for memory encoding.
|
|
3
|
+
*
|
|
4
|
+
* Three strategies (configurable per-agent):
|
|
5
|
+
* - `keyword` — fast regex/lexicon-based heuristics (zero latency, no LLM cost)
|
|
6
|
+
* - `llm` — cheap LLM call for accurate classification
|
|
7
|
+
* - `hybrid` — keywords in real-time, LLM retroactively during consolidation
|
|
8
|
+
*
|
|
9
|
+
* @module agentos/memory/encoding/ContentFeatureDetector
|
|
10
|
+
*/
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Keyword patterns
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
const PROCEDURE_PATTERNS = [
|
|
15
|
+
/\bstep[\s-]?\d/i,
|
|
16
|
+
/\bfirst[\s,]/i,
|
|
17
|
+
/\bthen[\s,]/i,
|
|
18
|
+
/\bfinally[\s,]/i,
|
|
19
|
+
/\binstructions?\b/i,
|
|
20
|
+
/\bhow[\s-]to\b/i,
|
|
21
|
+
/\bprocedure\b/i,
|
|
22
|
+
/\brecipe\b/i,
|
|
23
|
+
/\bworkflow\b/i,
|
|
24
|
+
/\b\d+\.\s+\w/, // numbered lists
|
|
25
|
+
];
|
|
26
|
+
const EMOTION_PATTERNS = [
|
|
27
|
+
/\bhappy\b|\bsad\b|\bangry\b|\bfrustrat/i,
|
|
28
|
+
/\bexcit/i, /\bworri/i, /\banxious\b/i,
|
|
29
|
+
/\blove\b|\bhate\b|\bfear\b/i,
|
|
30
|
+
/\bthank/i, /\bsorry\b/i, /\bgrateful\b/i,
|
|
31
|
+
/\bdisappoint/i, /\bdeligh/i, /\bupset\b/i,
|
|
32
|
+
/[!]{2,}/, /(?:\u{1F600}|\u{1F64F}|\u{1F923}|\u{1F602}|\u{2764}\u{FE0F}|\u{1F60D}|\u{1F60A}|\u{1F97A}|\u{1F62D}|\u{1F618}|\u{1F914}|\u{1F605}|\u{1F629}|\u{1F970}|\u{1F621}|\u{1F480})/u,
|
|
33
|
+
];
|
|
34
|
+
const SOCIAL_PATTERNS = [
|
|
35
|
+
/\bteam\b|\bcolleague\b|\bmanager\b/i,
|
|
36
|
+
/\bmeeting\b|\bcall\b|\bdiscuss/i,
|
|
37
|
+
/\bfriend\b|\bfamily\b|\bpartner\b/i,
|
|
38
|
+
/\bhe\s+(said|told|asked)\b/i,
|
|
39
|
+
/\bshe\s+(said|told|asked)\b/i,
|
|
40
|
+
/\bthey\s+(said|told|asked)\b/i,
|
|
41
|
+
];
|
|
42
|
+
const COOPERATION_PATTERNS = [
|
|
43
|
+
/\btogether\b|\bcollaborat/i,
|
|
44
|
+
/\bagree\b|\bconsensus\b/i,
|
|
45
|
+
/\bhelp\b|\bassist\b|\bsupport\b/i,
|
|
46
|
+
/\bshare\b|\bcontribut/i,
|
|
47
|
+
/\bcompromis/i,
|
|
48
|
+
];
|
|
49
|
+
const ETHICAL_PATTERNS = [
|
|
50
|
+
/\bfair\b|\bunfair\b|\bjust\b|\bunjust\b/i,
|
|
51
|
+
/\bright\b.*\bwrong\b|\bwrong\b.*\bright\b/i,
|
|
52
|
+
/\bethic/i, /\bmoral/i, /\bhonest/i,
|
|
53
|
+
/\bprivacy\b|\bconsent\b|\btranspar/i,
|
|
54
|
+
/\bresponsib/i, /\baccountab/i,
|
|
55
|
+
];
|
|
56
|
+
const CONTRADICTION_PATTERNS = [
|
|
57
|
+
/\bactually\b.*\bnot\b/i,
|
|
58
|
+
/\bthat'?s\s+(wrong|incorrect|false)\b/i,
|
|
59
|
+
/\bcorrect(ion|ed)\b/i,
|
|
60
|
+
/\bcontrad/i,
|
|
61
|
+
/\bhowever\b.*\b(not|isn'?t|wasn'?t|doesn'?t)\b/i,
|
|
62
|
+
/\bin\s+fact\b/i,
|
|
63
|
+
/\bmistak/i,
|
|
64
|
+
/\bno,\s/i,
|
|
65
|
+
];
|
|
66
|
+
const NOVELTY_PATTERNS = [
|
|
67
|
+
/\bnew\b|\bnovel\b|\bunexpect/i,
|
|
68
|
+
/\bsurpris/i, /\bfirst\s+time\b/i,
|
|
69
|
+
/\bnever\s+(seen|heard|done)\b/i,
|
|
70
|
+
/\bdiscover/i, /\bbreakthrough\b/i,
|
|
71
|
+
/\binnovati/i, /\bunique\b/i,
|
|
72
|
+
];
|
|
73
|
+
function matchesAny(text, patterns) {
|
|
74
|
+
return patterns.some((p) => p.test(text));
|
|
75
|
+
}
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
// Keyword-based detector
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
export class KeywordFeatureDetector {
|
|
80
|
+
async detect(text) {
|
|
81
|
+
return {
|
|
82
|
+
hasNovelty: matchesAny(text, NOVELTY_PATTERNS),
|
|
83
|
+
hasProcedure: matchesAny(text, PROCEDURE_PATTERNS),
|
|
84
|
+
hasEmotion: matchesAny(text, EMOTION_PATTERNS),
|
|
85
|
+
hasSocialContent: matchesAny(text, SOCIAL_PATTERNS),
|
|
86
|
+
hasCooperation: matchesAny(text, COOPERATION_PATTERNS),
|
|
87
|
+
hasEthicalContent: matchesAny(text, ETHICAL_PATTERNS),
|
|
88
|
+
hasContradiction: matchesAny(text, CONTRADICTION_PATTERNS),
|
|
89
|
+
topicRelevance: 0.5, // keywords can't assess task relevance
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
// LLM-based detector
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
const LLM_SYSTEM_PROMPT = `You are a content feature classifier. Given text, output a JSON object with exactly these boolean fields and one number field:
|
|
97
|
+
{
|
|
98
|
+
"hasNovelty": bool,
|
|
99
|
+
"hasProcedure": bool,
|
|
100
|
+
"hasEmotion": bool,
|
|
101
|
+
"hasSocialContent": bool,
|
|
102
|
+
"hasCooperation": bool,
|
|
103
|
+
"hasEthicalContent": bool,
|
|
104
|
+
"hasContradiction": bool,
|
|
105
|
+
"topicRelevance": number (0-1)
|
|
106
|
+
}
|
|
107
|
+
Respond ONLY with the JSON object, no explanation.`;
|
|
108
|
+
export class LlmFeatureDetector {
|
|
109
|
+
constructor(llmInvoker) {
|
|
110
|
+
this.llmInvoker = llmInvoker;
|
|
111
|
+
}
|
|
112
|
+
async detect(text) {
|
|
113
|
+
try {
|
|
114
|
+
const response = await this.llmInvoker(LLM_SYSTEM_PROMPT, text);
|
|
115
|
+
const parsed = JSON.parse(response.trim());
|
|
116
|
+
return {
|
|
117
|
+
hasNovelty: !!parsed.hasNovelty,
|
|
118
|
+
hasProcedure: !!parsed.hasProcedure,
|
|
119
|
+
hasEmotion: !!parsed.hasEmotion,
|
|
120
|
+
hasSocialContent: !!parsed.hasSocialContent,
|
|
121
|
+
hasCooperation: !!parsed.hasCooperation,
|
|
122
|
+
hasEthicalContent: !!parsed.hasEthicalContent,
|
|
123
|
+
hasContradiction: !!parsed.hasContradiction,
|
|
124
|
+
topicRelevance: typeof parsed.topicRelevance === 'number'
|
|
125
|
+
? Math.max(0, Math.min(1, parsed.topicRelevance))
|
|
126
|
+
: 0.5,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// Fallback to keyword detection on LLM failure
|
|
131
|
+
return new KeywordFeatureDetector().detect(text);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// ---------------------------------------------------------------------------
|
|
136
|
+
// Hybrid detector (keyword real-time, LLM deferred)
|
|
137
|
+
// ---------------------------------------------------------------------------
|
|
138
|
+
/**
|
|
139
|
+
* Uses keyword detection for real-time encoding. Exposes `detectWithLlm()`
|
|
140
|
+
* for retroactive re-classification during consolidation.
|
|
141
|
+
*/
|
|
142
|
+
export class HybridFeatureDetector {
|
|
143
|
+
constructor(llmInvoker) {
|
|
144
|
+
this.keyword = new KeywordFeatureDetector();
|
|
145
|
+
this.llm = llmInvoker ? new LlmFeatureDetector(llmInvoker) : null;
|
|
146
|
+
}
|
|
147
|
+
/** Real-time detection: keyword only (zero latency). */
|
|
148
|
+
async detect(text) {
|
|
149
|
+
return this.keyword.detect(text);
|
|
150
|
+
}
|
|
151
|
+
/** Deferred detection: LLM-based (called during consolidation). */
|
|
152
|
+
async detectWithLlm(text) {
|
|
153
|
+
if (this.llm) {
|
|
154
|
+
return this.llm.detect(text);
|
|
155
|
+
}
|
|
156
|
+
return this.keyword.detect(text);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// ---------------------------------------------------------------------------
|
|
160
|
+
// Factory
|
|
161
|
+
// ---------------------------------------------------------------------------
|
|
162
|
+
export function createFeatureDetector(strategy, llmInvoker) {
|
|
163
|
+
switch (strategy) {
|
|
164
|
+
case 'llm':
|
|
165
|
+
if (!llmInvoker) {
|
|
166
|
+
throw new Error('LLM feature detection requires an llmInvoker function');
|
|
167
|
+
}
|
|
168
|
+
return new LlmFeatureDetector(llmInvoker);
|
|
169
|
+
case 'hybrid':
|
|
170
|
+
return new HybridFeatureDetector(llmInvoker);
|
|
171
|
+
case 'keyword':
|
|
172
|
+
default:
|
|
173
|
+
return new KeywordFeatureDetector();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=ContentFeatureDetector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentFeatureDetector.js","sourceRoot":"","sources":["../../../src/memory/encoding/ContentFeatureDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAYH,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,MAAM,kBAAkB,GAAG;IACzB,iBAAiB;IACjB,eAAe;IACf,cAAc;IACd,iBAAiB;IACjB,oBAAoB;IACpB,iBAAiB;IACjB,gBAAgB;IAChB,aAAa;IACb,eAAe;IACf,cAAc,EAAG,iBAAiB;CACnC,CAAC;AAEF,MAAM,gBAAgB,GAAG;IACvB,yCAAyC;IACzC,UAAU,EAAE,UAAU,EAAE,cAAc;IACtC,6BAA6B;IAC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