@framers/agentos 0.1.181 → 0.1.182
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 +101 -0
- package/dist/api/agent.d.ts +24 -0
- package/dist/api/agent.d.ts.map +1 -1
- package/dist/api/agent.js.map +1 -1
- package/dist/core/validation/ValidatedLlmInvoker.d.ts +80 -0
- package/dist/core/validation/ValidatedLlmInvoker.d.ts.map +1 -0
- package/dist/core/validation/ValidatedLlmInvoker.js +176 -0
- package/dist/core/validation/ValidatedLlmInvoker.js.map +1 -0
- package/dist/core/validation/errors.d.ts +53 -0
- package/dist/core/validation/errors.d.ts.map +1 -0
- package/dist/core/validation/errors.js +42 -0
- package/dist/core/validation/errors.js.map +1 -0
- package/dist/core/validation/extractJson.d.ts +35 -0
- package/dist/core/validation/extractJson.d.ts.map +1 -0
- package/dist/core/validation/extractJson.js +179 -0
- package/dist/core/validation/extractJson.js.map +1 -0
- package/dist/core/validation/index.d.ts +14 -0
- package/dist/core/validation/index.d.ts.map +1 -0
- package/dist/core/validation/index.js +14 -0
- package/dist/core/validation/index.js.map +1 -0
- package/dist/core/validation/schema-primitives.d.ts +132 -0
- package/dist/core/validation/schema-primitives.d.ts.map +1 -0
- package/dist/core/validation/schema-primitives.js +141 -0
- package/dist/core/validation/schema-primitives.js.map +1 -0
- package/dist/memory/AgentMemory.d.ts +118 -1
- package/dist/memory/AgentMemory.d.ts.map +1 -1
- package/dist/memory/AgentMemory.js +388 -0
- package/dist/memory/AgentMemory.js.map +1 -1
- package/dist/memory/CognitiveMemoryManager.d.ts +44 -0
- package/dist/memory/CognitiveMemoryManager.d.ts.map +1 -1
- package/dist/memory/CognitiveMemoryManager.js +131 -5
- package/dist/memory/CognitiveMemoryManager.js.map +1 -1
- package/dist/memory/core/config.d.ts +49 -9
- package/dist/memory/core/config.d.ts.map +1 -1
- package/dist/memory/core/config.js +13 -0
- package/dist/memory/core/config.js.map +1 -1
- package/dist/memory/core/prompt/MemoryPromptAssembler.d.ts.map +1 -1
- package/dist/memory/core/prompt/MemoryPromptAssembler.js +59 -5
- package/dist/memory/core/prompt/MemoryPromptAssembler.js.map +1 -1
- package/dist/memory/core/types.d.ts +97 -0
- package/dist/memory/core/types.d.ts.map +1 -1
- package/dist/memory/pipeline/observation/MemoryReflector.d.ts +28 -1
- package/dist/memory/pipeline/observation/MemoryReflector.d.ts.map +1 -1
- package/dist/memory/pipeline/observation/MemoryReflector.js +80 -8
- package/dist/memory/pipeline/observation/MemoryReflector.js.map +1 -1
- package/dist/memory/retrieval/hyde/MemoryHydeRetriever.d.ts +69 -0
- package/dist/memory/retrieval/hyde/MemoryHydeRetriever.d.ts.map +1 -0
- package/dist/memory/retrieval/hyde/MemoryHydeRetriever.js +97 -0
- package/dist/memory/retrieval/hyde/MemoryHydeRetriever.js.map +1 -0
- package/dist/memory/retrieval/store/MemoryStore.d.ts +15 -0
- package/dist/memory/retrieval/store/MemoryStore.d.ts.map +1 -1
- package/dist/memory/retrieval/store/MemoryStore.js +67 -0
- package/dist/memory/retrieval/store/MemoryStore.js.map +1 -1
- package/dist/memory/retrieval/store/SqliteBrain.d.ts +7 -0
- package/dist/memory/retrieval/store/SqliteBrain.d.ts.map +1 -1
- package/dist/memory/retrieval/store/SqliteBrain.js +39 -0
- package/dist/memory/retrieval/store/SqliteBrain.js.map +1 -1
- package/package.json +1 -1
|
@@ -199,6 +199,103 @@ export interface MemoryHealthReport {
|
|
|
199
199
|
tracesPerType: Record<MemoryType, number>;
|
|
200
200
|
tracesPerScope: Record<MemoryScope, number>;
|
|
201
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Serializable snapshot of the full memory graph for visualization.
|
|
204
|
+
* Contains nodes (traces), edges (associations), clusters, and aggregate stats.
|
|
205
|
+
* Used by wilds-ai companion sidebar, memory graph view, and devtools.
|
|
206
|
+
*/
|
|
207
|
+
export interface MemoryGraphSnapshot {
|
|
208
|
+
nodes: Array<{
|
|
209
|
+
id: string;
|
|
210
|
+
type: MemoryType;
|
|
211
|
+
content: string;
|
|
212
|
+
strength: number;
|
|
213
|
+
isFlashbulb: boolean;
|
|
214
|
+
createdAt: number;
|
|
215
|
+
lastAccessedAt: number;
|
|
216
|
+
retrievalCount: number;
|
|
217
|
+
}>;
|
|
218
|
+
edges: Array<{
|
|
219
|
+
sourceId: string;
|
|
220
|
+
targetId: string;
|
|
221
|
+
type: string;
|
|
222
|
+
weight: number;
|
|
223
|
+
}>;
|
|
224
|
+
clusters: Array<{
|
|
225
|
+
clusterId: string;
|
|
226
|
+
memberIds: string[];
|
|
227
|
+
density: number;
|
|
228
|
+
}>;
|
|
229
|
+
stats: {
|
|
230
|
+
nodeCount: number;
|
|
231
|
+
edgeCount: number;
|
|
232
|
+
clusterCount: number;
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Observation pipeline health stats for devtools/monitoring.
|
|
237
|
+
* Exposes the state of the 3-tier pipeline: notes → compressed → reflected.
|
|
238
|
+
*/
|
|
239
|
+
export interface ObservationPipelineStats {
|
|
240
|
+
/** Number of raw observation notes pending compression. */
|
|
241
|
+
pendingNotes: number;
|
|
242
|
+
/** Number of compressed observations pending reflection. */
|
|
243
|
+
pendingCompressed: number;
|
|
244
|
+
/** Total observation notes produced since initialization. */
|
|
245
|
+
totalNotesProduced: number;
|
|
246
|
+
/** Total reflection cycles completed. */
|
|
247
|
+
totalReflectionsProduced: number;
|
|
248
|
+
/** Timestamp of last reflection cycle, or null if none. */
|
|
249
|
+
lastReflectionAt: number | null;
|
|
250
|
+
/** Average compression ratio (input tokens / output tokens). */
|
|
251
|
+
avgCompressionRatio: number;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Full exportable memory state for character portability across worlds.
|
|
255
|
+
* Used for companion export/import in wilds-ai.
|
|
256
|
+
*/
|
|
257
|
+
export interface CognitiveMemorySnapshot {
|
|
258
|
+
/** Snapshot format version. */
|
|
259
|
+
version: string;
|
|
260
|
+
/** Agent/entity ID that owns this memory. */
|
|
261
|
+
agentId: string;
|
|
262
|
+
/** All active memory traces. */
|
|
263
|
+
traces: MemoryTrace[];
|
|
264
|
+
/** Graph edges between traces. */
|
|
265
|
+
graphEdges: Array<{
|
|
266
|
+
sourceId: string;
|
|
267
|
+
targetId: string;
|
|
268
|
+
type: string;
|
|
269
|
+
weight: number;
|
|
270
|
+
createdAt: number;
|
|
271
|
+
}>;
|
|
272
|
+
/** Active prospective memory items. */
|
|
273
|
+
prospectiveItems: Array<{
|
|
274
|
+
id: string;
|
|
275
|
+
content: string;
|
|
276
|
+
triggerType: string;
|
|
277
|
+
importance: number;
|
|
278
|
+
triggered: boolean;
|
|
279
|
+
createdAt: number;
|
|
280
|
+
}>;
|
|
281
|
+
/** Snapshot metadata for import validation. */
|
|
282
|
+
metadata: {
|
|
283
|
+
exportedAt: number;
|
|
284
|
+
traceCount: number;
|
|
285
|
+
typeDistribution: Record<MemoryType, number>;
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
/** Strength distribution stats per memory type. */
|
|
289
|
+
export interface MemoryTypeStats {
|
|
290
|
+
/** Total traces of this type. */
|
|
291
|
+
count: number;
|
|
292
|
+
/** Average encoding strength across traces. */
|
|
293
|
+
avgStrength: number;
|
|
294
|
+
/** Number of traces below 0.3 strength (fading). */
|
|
295
|
+
decaying: number;
|
|
296
|
+
/** Number of flashbulb-strength traces (above 0.8). */
|
|
297
|
+
flashbulb: number;
|
|
298
|
+
}
|
|
202
299
|
export type { EmbeddingConfig, ExtendedConsolidationConfig, IngestionConfig, MemoryConfig, RememberOptions, RecallOptions, IngestOptions, IngestResult, ExportOptions, ImportOptions, ImportResult, ConsolidationResult, MemoryHealth, LoadOptions, LoadedDocument, DocumentMetadata, DocumentChunk, ExtractedImage, ExtractedTable, } from '../io/facade/types.js';
|
|
203
300
|
export type { CompactionEntry, CompactionInput, CompactionResult, ContextMessage, ICompactionStrategy, InfiniteContextConfig, SummaryChainNode, } from '../pipeline/context/types.js';
|
|
204
301
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/memory/core/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,mEAAmE;AACnE,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,UAAU,GAAG,YAAY,GAAG,aAAa,GAAG,YAAY,CAAC;AAE/F,uDAAuD;AACvD,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,cAAc,CAAC;AAEzE,8DAA8D;AAC9D,MAAM,MAAM,gBAAgB,GACxB,gBAAgB,GAChB,iBAAiB,GACjB,aAAa,GACb,aAAa,GACb,YAAY,GACZ,UAAU,CAAC;AAMf,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,gBAAgB,CAAC;IAC7B,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,eAAe,EAAE,MAAM,CAAC;IACxB,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAC;IACnB,gEAAgE;IAChE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oDAAoD;IACpD,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAMD,MAAM,WAAW,gBAAgB;IAC/B,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;CACjB;AAMD,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;IACpB,gBAAgB,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UAAU,EAAE,MAAM,CAAC;QACnB,gBAAgB,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;KAC9C,CAAC;CACH;AAED,mDAAmD;AACnD,MAAM,WAAW,eAAe;IAC9B,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,YAAY,EACV,eAAe,EACf,2BAA2B,EAC3B,eAAe,EACf,YAAY,EACZ,eAAe,EACf,aAAa,EACb,aAAa,EACb,YAAY,EACZ,aAAa,EACb,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,cAAc,GACf,MAAM,uBAAuB,CAAC;AAE/B,YAAY,EACV,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,8BAA8B,CAAC"}
|
|
@@ -15,9 +15,23 @@
|
|
|
15
15
|
import type { MemoryTrace } from '../../core/types.js';
|
|
16
16
|
import type { HexacoTraits, ReflectorConfig } from '../../core/config.js';
|
|
17
17
|
import type { ObservationNote } from './MemoryObserver.js';
|
|
18
|
+
/**
|
|
19
|
+
* Result of a reflection cycle.
|
|
20
|
+
*
|
|
21
|
+
* Contains the consolidated long-term traces (typed as episodic, semantic,
|
|
22
|
+
* procedural, prospective, or relational), any superseded trace IDs, the
|
|
23
|
+
* consumed note IDs, and the compression ratio achieved.
|
|
24
|
+
*/
|
|
18
25
|
export interface MemoryReflectionResult {
|
|
19
26
|
/** New long-term memory traces to store. */
|
|
20
|
-
traces: Omit<MemoryTrace, 'id' | 'encodingStrength' | 'stability' | 'retrievalCount' | 'lastAccessedAt' | 'accessCount' | 'reinforcementInterval' | 'createdAt' | 'updatedAt'>
|
|
27
|
+
traces: (Omit<MemoryTrace, 'id' | 'encodingStrength' | 'stability' | 'retrievalCount' | 'lastAccessedAt' | 'accessCount' | 'reinforcementInterval' | 'createdAt' | 'updatedAt'> & {
|
|
28
|
+
/**
|
|
29
|
+
* Reflector's chain-of-thought reasoning for why this trace matters.
|
|
30
|
+
* Available for devtools/debugging; stripped before the trace is
|
|
31
|
+
* passed to `CognitiveMemoryManager.encode()` for storage.
|
|
32
|
+
*/
|
|
33
|
+
reasoning?: string;
|
|
34
|
+
})[];
|
|
21
35
|
/** IDs of existing traces that should be superseded. */
|
|
22
36
|
supersededTraceIds: string[];
|
|
23
37
|
/** IDs of observation notes that were consumed. */
|
|
@@ -46,6 +60,19 @@ export declare class MemoryReflector {
|
|
|
46
60
|
getPendingNoteCount(): number;
|
|
47
61
|
/** Clear all pending notes. */
|
|
48
62
|
clear(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Parse the LLM's reflection response into structured trace data.
|
|
65
|
+
*
|
|
66
|
+
* Handles:
|
|
67
|
+
* - Stripping `<thinking>...</thinking>` blocks (chain-of-thought reasoning)
|
|
68
|
+
* - Parsing one JSON object per line
|
|
69
|
+
* - Validating and normalizing type/scope enums
|
|
70
|
+
* - Preserving the optional `reasoning` field for devtools
|
|
71
|
+
* - Collecting superseded and consumed note IDs
|
|
72
|
+
*
|
|
73
|
+
* @param llmResponse - Raw LLM output containing optional thinking block + JSON lines
|
|
74
|
+
* @returns Parsed reflection result with typed traces
|
|
75
|
+
*/
|
|
49
76
|
private parseReflection;
|
|
50
77
|
}
|
|
51
78
|
//# sourceMappingURL=MemoryReflector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryReflector.d.ts","sourceRoot":"","sources":["../../../../src/memory/pipeline/observation/MemoryReflector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,WAAW,EAA2B,MAAM,qBA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C,UAAU,CAAC,CAAgE;IACnF,OAAO,CAAC,MAAM,CAAkB;gBAG9B,MAAM,EAAE,YAAY,EACpB,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC;IAWnC;;;OAGG;IACG,QAAQ,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC;IAShF,iEAAiE;IACjE,cAAc,IAAI,OAAO;IAQzB;;OAEG;IACG,OAAO,CAAC,qBAAqB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAkC9E,8BAA8B;IAC9B,mBAAmB,IAAI,MAAM;IAI7B,+BAA+B;IAC/B,KAAK,IAAI,IAAI;IAMb;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,eAAe;CA4ExB"}
|
|
@@ -15,31 +15,77 @@
|
|
|
15
15
|
// ---------------------------------------------------------------------------
|
|
16
16
|
// Personality-aware system prompt
|
|
17
17
|
// ---------------------------------------------------------------------------
|
|
18
|
+
/**
|
|
19
|
+
* Build a personality-biased system prompt for the memory reflector.
|
|
20
|
+
*
|
|
21
|
+
* Personality influences (grounded in HEXACO model of personality):
|
|
22
|
+
* - High honesty → prefer newer info over old on contradiction (source monitoring)
|
|
23
|
+
* - High agreeableness → keep both versions on contradiction (cognitive flexibility)
|
|
24
|
+
* - High conscientiousness → structured, categorized output (organizational encoding)
|
|
25
|
+
* - High openness → rich, associative output (spreading activation style)
|
|
26
|
+
* - High emotionality → heightened sensitivity to relational/emotional signals
|
|
27
|
+
* - High extraversion → captures social dynamics and group interactions
|
|
28
|
+
*
|
|
29
|
+
* The chain-of-thought `<thinking>` block asks the LLM to reason about
|
|
30
|
+
* each memory type before extraction, improving classification accuracy
|
|
31
|
+
* and ensuring relational signals are not overlooked.
|
|
32
|
+
*
|
|
33
|
+
* @param traits - HEXACO personality traits of the agent
|
|
34
|
+
* @returns System prompt string for the LLM reflector call
|
|
35
|
+
*/
|
|
18
36
|
function buildReflectorSystemPrompt(traits) {
|
|
19
37
|
const clamp = (v) => v == null ? 0.5 : Math.max(0, Math.min(1, v));
|
|
38
|
+
// Conflict resolution strategy — mirrors source monitoring in cognitive psychology.
|
|
39
|
+
// High honesty agents trust newer information; high agreeableness agents preserve both.
|
|
20
40
|
const conflictStrategy = clamp(traits.honesty) > 0.6
|
|
21
41
|
? 'When you detect a contradiction with existing knowledge, prefer the newer information and flag the old memory for supersession.'
|
|
22
42
|
: clamp(traits.agreeableness) > 0.6
|
|
23
43
|
? 'When you detect a contradiction, keep both versions and note the discrepancy.'
|
|
24
44
|
: 'When you detect a contradiction, keep the version with higher confidence.';
|
|
45
|
+
// Memory organization style — mirrors encoding specificity principle.
|
|
25
46
|
const memoryStyle = clamp(traits.conscientiousness) > 0.6
|
|
26
47
|
? 'Produce structured, well-organized memory traces with clear categories.'
|
|
27
48
|
: clamp(traits.openness) > 0.6
|
|
28
49
|
? 'Produce rich, associative memory traces that capture connections and context.'
|
|
29
50
|
: 'Produce concise, factual memory traces focused on key information.';
|
|
51
|
+
// Relational sensitivity — emotionality and agreeableness heighten
|
|
52
|
+
// detection of trust signals, boundary events, and social cues.
|
|
53
|
+
const relationalEmphases = [];
|
|
54
|
+
if (clamp(traits.emotionality) > 0.6) {
|
|
55
|
+
relationalEmphases.push('Pay special attention to emotional subtleties, vulnerability signals, and shifts in emotional tone — these are important relational memories.');
|
|
56
|
+
}
|
|
57
|
+
if (clamp(traits.agreeableness) > 0.6) {
|
|
58
|
+
relationalEmphases.push('Notice rapport cues, harmony signals, and moments of mutual understanding.');
|
|
59
|
+
}
|
|
60
|
+
if (clamp(traits.extraversion) > 0.6) {
|
|
61
|
+
relationalEmphases.push('Capture social dynamics, group interactions, and interpersonal energy shifts.');
|
|
62
|
+
}
|
|
63
|
+
const relationalBlock = relationalEmphases.length > 0
|
|
64
|
+
? `\n\nRelational sensitivity:\n${relationalEmphases.map((e) => `- ${e}`).join('\n')}`
|
|
65
|
+
: '';
|
|
30
66
|
return `You are a memory reflector. Your job is to consolidate observation notes into long-term memory traces.
|
|
31
67
|
|
|
68
|
+
Before producing traces, reason step by step inside <thinking> tags:
|
|
69
|
+
1. What new FACTS did the user reveal? (semantic)
|
|
70
|
+
2. What EVENTS happened worth remembering? (episodic)
|
|
71
|
+
3. What PATTERNS or PREFERENCES emerged? (procedural)
|
|
72
|
+
4. What FUTURE INTENTIONS were expressed? (prospective)
|
|
73
|
+
5. What RELATIONSHIP SIGNALS appeared — vulnerability, trust, conflict, warmth? (relational)
|
|
74
|
+
6. Do any of these CONTRADICT existing memories? If so, which is more reliable?
|
|
75
|
+
7. What can be MERGED from multiple notes into a single trace?
|
|
76
|
+
|
|
32
77
|
Rules:
|
|
33
78
|
1. Merge redundant or overlapping observations into single traces
|
|
34
|
-
2. Assign each trace a type: "episodic" (events), "semantic" (facts/knowledge), "procedural" (how-to),
|
|
79
|
+
2. Assign each trace a type: "episodic" (events/experiences), "semantic" (facts/knowledge), "procedural" (how-to/patterns), "prospective" (future intentions/reminders), or "relational" (trust signals, boundary events, emotional bonds, relationship shifts)
|
|
35
80
|
3. Assign a scope: "user" (about the user), "thread" (conversation-specific), "persona" (about the agent), or "organization" (shared)
|
|
36
81
|
4. ${conflictStrategy}
|
|
37
82
|
5. ${memoryStyle}
|
|
38
|
-
6. Target 5-40x compression: many notes → few high-quality traces
|
|
83
|
+
6. Target 5-40x compression: many notes → few high-quality traces${relationalBlock}
|
|
39
84
|
|
|
40
|
-
|
|
85
|
+
After your <thinking> block, output JSON objects, one per line:
|
|
41
86
|
{
|
|
42
|
-
"
|
|
87
|
+
"reasoning": "brief explanation of why this trace matters",
|
|
88
|
+
"type": "episodic|semantic|procedural|prospective|relational",
|
|
43
89
|
"scope": "user|thread|persona|organization",
|
|
44
90
|
"scopeId": "relevant_id",
|
|
45
91
|
"content": "consolidated memory content",
|
|
@@ -51,7 +97,7 @@ For each trace, output a JSON object on its own line:
|
|
|
51
97
|
"consumedNotes": ["note_id1", "note_id2"]
|
|
52
98
|
}
|
|
53
99
|
|
|
54
|
-
Output ONLY valid JSON objects, one per line.`;
|
|
100
|
+
Output your <thinking> block first, then ONLY valid JSON objects, one per line.`;
|
|
55
101
|
}
|
|
56
102
|
// ---------------------------------------------------------------------------
|
|
57
103
|
// MemoryReflector
|
|
@@ -123,20 +169,41 @@ export class MemoryReflector {
|
|
|
123
169
|
this.pendingNotes = [];
|
|
124
170
|
}
|
|
125
171
|
// --- Internal ---
|
|
172
|
+
/**
|
|
173
|
+
* Parse the LLM's reflection response into structured trace data.
|
|
174
|
+
*
|
|
175
|
+
* Handles:
|
|
176
|
+
* - Stripping `<thinking>...</thinking>` blocks (chain-of-thought reasoning)
|
|
177
|
+
* - Parsing one JSON object per line
|
|
178
|
+
* - Validating and normalizing type/scope enums
|
|
179
|
+
* - Preserving the optional `reasoning` field for devtools
|
|
180
|
+
* - Collecting superseded and consumed note IDs
|
|
181
|
+
*
|
|
182
|
+
* @param llmResponse - Raw LLM output containing optional thinking block + JSON lines
|
|
183
|
+
* @returns Parsed reflection result with typed traces
|
|
184
|
+
*/
|
|
126
185
|
parseReflection(llmResponse) {
|
|
127
186
|
const traces = [];
|
|
128
187
|
const supersededTraceIds = [];
|
|
129
188
|
const consumedNoteIds = [];
|
|
130
|
-
|
|
189
|
+
// Strip <thinking>...</thinking> blocks before parsing JSON lines.
|
|
190
|
+
// The thinking block contains the reflector's chain-of-thought reasoning
|
|
191
|
+
// which is useful for debugging but not part of the trace data.
|
|
192
|
+
const cleaned = llmResponse.replace(/<thinking>[\s\S]*?<\/thinking>/gi, '');
|
|
193
|
+
const lines = cleaned.split('\n').filter((l) => l.trim());
|
|
131
194
|
const now = Date.now();
|
|
132
195
|
for (const line of lines) {
|
|
133
196
|
try {
|
|
134
197
|
const parsed = JSON.parse(line.trim());
|
|
135
198
|
if (!parsed.content)
|
|
136
199
|
continue;
|
|
200
|
+
// Validate memory type — defaults to 'semantic' for unrecognized types.
|
|
201
|
+
// All 5 Tulving-extended types are accepted: episodic, semantic,
|
|
202
|
+
// procedural, prospective, and relational.
|
|
137
203
|
const type = (['episodic', 'semantic', 'procedural', 'prospective', 'relational'].includes(parsed.type)
|
|
138
204
|
? parsed.type
|
|
139
205
|
: 'semantic');
|
|
206
|
+
// Validate memory scope — defaults to 'user' for unrecognized scopes.
|
|
140
207
|
const scope = (['user', 'thread', 'persona', 'organization'].includes(parsed.scope)
|
|
141
208
|
? parsed.scope
|
|
142
209
|
: 'user');
|
|
@@ -162,6 +229,9 @@ export class MemoryReflector {
|
|
|
162
229
|
},
|
|
163
230
|
associatedTraceIds: [],
|
|
164
231
|
isActive: true,
|
|
232
|
+
// Preserve reasoning for devtools — CognitiveMemoryManager strips
|
|
233
|
+
// this before passing to encode() since it's not part of MemoryTrace.
|
|
234
|
+
reasoning: typeof parsed.reasoning === 'string' ? parsed.reasoning : undefined,
|
|
165
235
|
});
|
|
166
236
|
if (Array.isArray(parsed.supersedes)) {
|
|
167
237
|
supersededTraceIds.push(...parsed.supersedes);
|
|
@@ -171,10 +241,12 @@ export class MemoryReflector {
|
|
|
171
241
|
}
|
|
172
242
|
}
|
|
173
243
|
catch {
|
|
174
|
-
// Skip malformed lines
|
|
244
|
+
// Skip malformed lines — common when LLM outputs markdown fences or commentary
|
|
175
245
|
}
|
|
176
246
|
}
|
|
177
|
-
// If no specific notes were claimed, consider all pending consumed
|
|
247
|
+
// If no specific notes were claimed, consider all pending consumed.
|
|
248
|
+
// This handles the case where the LLM omits consumedNotes fields
|
|
249
|
+
// but still produces valid traces from the input notes.
|
|
178
250
|
if (consumedNoteIds.length === 0 && traces.length > 0) {
|
|
179
251
|
consumedNoteIds.push(...this.pendingNotes.map((n) => n.id));
|
|
180
252
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryReflector.js","sourceRoot":"","sources":["../../../../src/memory/pipeline/observation/MemoryReflector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;
|
|
1
|
+
{"version":3,"file":"Memory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AAC,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC,EAAE,CAAC;IAC9E,CAAC;CACF"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Memory-specific HyDE (Hypothetical Document Embedding) retriever.
|
|
3
|
+
*
|
|
4
|
+
* Improves memory recall for vague or abstract queries by generating a
|
|
5
|
+
* hypothetical memory trace BEFORE embedding. The hypothesis is closer
|
|
6
|
+
* in embedding space to actual stored traces than the raw query.
|
|
7
|
+
*
|
|
8
|
+
* Cognitive science grounding: this mirrors the "generation effect" —
|
|
9
|
+
* generating information about a topic activates related neural pathways
|
|
10
|
+
* more strongly than passive recognition. By generating what a memory
|
|
11
|
+
* WOULD look like, we activate the right retrieval pathways.
|
|
12
|
+
*
|
|
13
|
+
* Effective for:
|
|
14
|
+
* - Abstract queries ("that deployment discussion")
|
|
15
|
+
* - Emotional recall ("when they were upset")
|
|
16
|
+
* - Temporal queries ("something from last week")
|
|
17
|
+
* - Vague references ("the thing about cats")
|
|
18
|
+
*
|
|
19
|
+
* Auto-attached by CognitiveMemoryManager when any LLM invoker is available.
|
|
20
|
+
* Remains opt-in per query via `options.hyde: true` on `retrieve()`.
|
|
21
|
+
*
|
|
22
|
+
* @module agentos/memory/retrieval/hyde/MemoryHydeRetriever
|
|
23
|
+
* @see {@link CognitiveMemoryManager.retrieve} — consumes the hypothesis
|
|
24
|
+
*/
|
|
25
|
+
/** LLM invoker function signature matching AgentOS observer/reflector convention. */
|
|
26
|
+
type LlmInvoker = (systemPrompt: string, userPrompt: string) => Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Memory-specific HyDE retriever that generates hypothetical memory traces.
|
|
29
|
+
*
|
|
30
|
+
* Implements the same `generateHypothesis()` interface expected by
|
|
31
|
+
* CognitiveMemoryManager so it can be assigned via `setHydeRetriever()`.
|
|
32
|
+
*
|
|
33
|
+
* Lightweight: uses `maxTokens: 150` with no chain-of-thought. Target
|
|
34
|
+
* latency is under 500ms with a fast model.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const retriever = new MemoryHydeRetriever(llmInvoker);
|
|
39
|
+
* const result = await retriever.generateHypothesis('what does the user like?');
|
|
40
|
+
* // result.hypothesis = "User mentioned they enjoy hiking and cooking..."
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare class MemoryHydeRetriever {
|
|
44
|
+
private readonly llmInvoker;
|
|
45
|
+
/**
|
|
46
|
+
* @param llmInvoker - Function that calls an LLM with (systemPrompt, userPrompt).
|
|
47
|
+
* Typically reused from the observer, reflector, or feature detection config.
|
|
48
|
+
*/
|
|
49
|
+
constructor(llmInvoker: LlmInvoker);
|
|
50
|
+
/**
|
|
51
|
+
* Generate a hypothetical memory trace for a recall query.
|
|
52
|
+
*
|
|
53
|
+
* The generated hypothesis is used as the embedding input for vector
|
|
54
|
+
* search, producing results that are more semantically aligned with
|
|
55
|
+
* actual stored traces.
|
|
56
|
+
*
|
|
57
|
+
* Returns the same shape as `HydeRetriever.generateHypothesis()` so
|
|
58
|
+
* CognitiveMemoryManager can use it interchangeably.
|
|
59
|
+
*
|
|
60
|
+
* @param query - The recall query (e.g., "what does the user do for work?")
|
|
61
|
+
* @returns Object with `hypothesis` text and `latencyMs` timing
|
|
62
|
+
*/
|
|
63
|
+
generateHypothesis(query: string): Promise<{
|
|
64
|
+
hypothesis: string;
|
|
65
|
+
latencyMs: number;
|
|
66
|
+
}>;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=MemoryHydeRetriever.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryHydeRetriever.d.ts","sourceRoot":"","sources":["../../../../src/memory/retrieval/hyde/MemoryHydeRetriever.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,qFAAqF;AACrF,KAAK,UAAU,GAAG,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAuBhF;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IAExC;;;OAGG;gBACS,UAAU,EAAE,UAAU;IAIlC;;;;;;;;;;;;OAYG;IACG,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAa5F"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Memory-specific HyDE (Hypothetical Document Embedding) retriever.
|
|
3
|
+
*
|
|
4
|
+
* Improves memory recall for vague or abstract queries by generating a
|
|
5
|
+
* hypothetical memory trace BEFORE embedding. The hypothesis is closer
|
|
6
|
+
* in embedding space to actual stored traces than the raw query.
|
|
7
|
+
*
|
|
8
|
+
* Cognitive science grounding: this mirrors the "generation effect" —
|
|
9
|
+
* generating information about a topic activates related neural pathways
|
|
10
|
+
* more strongly than passive recognition. By generating what a memory
|
|
11
|
+
* WOULD look like, we activate the right retrieval pathways.
|
|
12
|
+
*
|
|
13
|
+
* Effective for:
|
|
14
|
+
* - Abstract queries ("that deployment discussion")
|
|
15
|
+
* - Emotional recall ("when they were upset")
|
|
16
|
+
* - Temporal queries ("something from last week")
|
|
17
|
+
* - Vague references ("the thing about cats")
|
|
18
|
+
*
|
|
19
|
+
* Auto-attached by CognitiveMemoryManager when any LLM invoker is available.
|
|
20
|
+
* Remains opt-in per query via `options.hyde: true` on `retrieve()`.
|
|
21
|
+
*
|
|
22
|
+
* @module agentos/memory/retrieval/hyde/MemoryHydeRetriever
|
|
23
|
+
* @see {@link CognitiveMemoryManager.retrieve} — consumes the hypothesis
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* System prompt for hypothesis generation.
|
|
27
|
+
*
|
|
28
|
+
* Instructs the LLM to output what a STORED memory trace would look like,
|
|
29
|
+
* not to answer the query. This produces embeddings that are semantically
|
|
30
|
+
* closer to actual stored traces than raw recall queries.
|
|
31
|
+
*/
|
|
32
|
+
const HYDE_SYSTEM_PROMPT = `You are a memory system. Given a recall query, generate what a stored memory trace about this topic would look like. Write it as a first-person observation note, 1-2 sentences, as if you recorded it when it happened.
|
|
33
|
+
|
|
34
|
+
Do NOT answer the query. Generate what the STORED MEMORY would say.
|
|
35
|
+
|
|
36
|
+
Examples:
|
|
37
|
+
Query: "what does the user do for work?"
|
|
38
|
+
Hypothesis: "User mentioned they are a software engineer working on backend systems at a startup."
|
|
39
|
+
|
|
40
|
+
Query: "when were they upset?"
|
|
41
|
+
Hypothesis: "User expressed frustration and stress about a missed deadline. Emotional tone was tense."
|
|
42
|
+
|
|
43
|
+
Query: "that thing about cats"
|
|
44
|
+
Hypothesis: "User talked about having two cats named Luna and Mochi. They seem important to the user."`;
|
|
45
|
+
/**
|
|
46
|
+
* Memory-specific HyDE retriever that generates hypothetical memory traces.
|
|
47
|
+
*
|
|
48
|
+
* Implements the same `generateHypothesis()` interface expected by
|
|
49
|
+
* CognitiveMemoryManager so it can be assigned via `setHydeRetriever()`.
|
|
50
|
+
*
|
|
51
|
+
* Lightweight: uses `maxTokens: 150` with no chain-of-thought. Target
|
|
52
|
+
* latency is under 500ms with a fast model.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const retriever = new MemoryHydeRetriever(llmInvoker);
|
|
57
|
+
* const result = await retriever.generateHypothesis('what does the user like?');
|
|
58
|
+
* // result.hypothesis = "User mentioned they enjoy hiking and cooking..."
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export class MemoryHydeRetriever {
|
|
62
|
+
/**
|
|
63
|
+
* @param llmInvoker - Function that calls an LLM with (systemPrompt, userPrompt).
|
|
64
|
+
* Typically reused from the observer, reflector, or feature detection config.
|
|
65
|
+
*/
|
|
66
|
+
constructor(llmInvoker) {
|
|
67
|
+
this.llmInvoker = llmInvoker;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Generate a hypothetical memory trace for a recall query.
|
|
71
|
+
*
|
|
72
|
+
* The generated hypothesis is used as the embedding input for vector
|
|
73
|
+
* search, producing results that are more semantically aligned with
|
|
74
|
+
* actual stored traces.
|
|
75
|
+
*
|
|
76
|
+
* Returns the same shape as `HydeRetriever.generateHypothesis()` so
|
|
77
|
+
* CognitiveMemoryManager can use it interchangeably.
|
|
78
|
+
*
|
|
79
|
+
* @param query - The recall query (e.g., "what does the user do for work?")
|
|
80
|
+
* @returns Object with `hypothesis` text and `latencyMs` timing
|
|
81
|
+
*/
|
|
82
|
+
async generateHypothesis(query) {
|
|
83
|
+
const start = Date.now();
|
|
84
|
+
try {
|
|
85
|
+
const hypothesis = await this.llmInvoker(HYDE_SYSTEM_PROMPT, `Query: "${query}"`);
|
|
86
|
+
return {
|
|
87
|
+
hypothesis: hypothesis.trim(),
|
|
88
|
+
latencyMs: Date.now() - start,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
// HyDE is non-critical — return empty hypothesis to fall through to raw query
|
|
93
|
+
return { hypothesis: '', latencyMs: Date.now() - start };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=MemoryHydeRetriever.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryHydeRetriever.js","sourceRoot":"","sources":["../../../../src/memory/retrieval/hyde/MemoryHydeRetriever.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAKH;;;;;;GAMG;AACH,MAAM,kBAAkB,GAAG;;;;;;;;;;;;uGAY4E,CAAC;AAExG;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,mBAAmB;IAG9B;;;OAGG;IACH,YAAY,UAAsB;QAChC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,kBAAkB,CAAC,KAAa;QACpC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,kBAAkB,EAAE,WAAW,KAAK,GAAG,CAAC,CAAC;YAClF,OAAO;gBACL,UAAU,EAAE,UAAU,CAAC,IAAI,EAAE;gBAC7B,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;aAC9B,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,8EAA8E;YAC9E,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;QAC3D,CAAC;IACH,CAAC;CACF"}
|
|
@@ -40,7 +40,22 @@ export declare class MemoryStore {
|
|
|
40
40
|
private knownScopes;
|
|
41
41
|
/** Optional cognitive mechanisms engine for retrieval-time hooks. */
|
|
42
42
|
private mechanismsEngine?;
|
|
43
|
+
/**
|
|
44
|
+
* Optional SqliteBrain for durable write-through persistence.
|
|
45
|
+
* When set, store/softDelete/recordAccess also write to the brain's SQL tables.
|
|
46
|
+
* The in-memory vector index remains the hot read path (fast); the brain is
|
|
47
|
+
* the durable backing store that survives process restarts.
|
|
48
|
+
*/
|
|
49
|
+
private brain;
|
|
43
50
|
constructor(config: MemoryStoreConfig);
|
|
51
|
+
/**
|
|
52
|
+
* Attach a SqliteBrain for durable write-through persistence.
|
|
53
|
+
* Once attached, all store/softDelete/recordAccess operations also
|
|
54
|
+
* write to the brain's `memory_traces` table.
|
|
55
|
+
*
|
|
56
|
+
* @param brain - SqliteBrain instance (already initialized with schema)
|
|
57
|
+
*/
|
|
58
|
+
setBrain(brain: import('./SqliteBrain.js').SqliteBrain): void;
|
|
44
59
|
/**
|
|
45
60
|
* Store a new memory trace: embed content, upsert into vector store,
|
|
46
61
|
* and record as episodic memory in the knowledge graph.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryStore.d.ts","sourceRoot":"","sources":["../../../../src/memory/retrieval/store/MemoryStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,YAAY,EAIb,MAAM,4CAA4C,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,yBAAyB,EACzB,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAElE,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,gCAAgC,CAAC;AAYxC,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,YAAY,CAAC;IAC1B,gBAAgB,EAAE,iBAAiB,CAAC;IACpC,cAAc,EAAE,eAAe,CAAC;IAChC,gDAAgD;IAChD,gBAAgB,EAAE,MAAM,CAAC;IACzB,uDAAuD;IACvD,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,qEAAqE;IACrE,gBAAgB,CAAC,EAAE,OAAO,+CAA+C,EAAE,yBAAyB,CAAC;IACrG,4EAA4E;IAC5E,YAAY,CAAC,EAAE,MAAM,QAAQ,CAAC;CAC/B;AAwED,qBAAa,WAA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