@mastra/memory 1.1.0-alpha.1 → 1.2.0-alpha.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/CHANGELOG.md +112 -0
- package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +30 -17
- package/dist/{chunk-FQJWVCDF.cjs → chunk-AWE2QQPI.cjs} +1884 -312
- package/dist/chunk-AWE2QQPI.cjs.map +1 -0
- package/dist/chunk-EQ4M72KU.js +439 -0
- package/dist/chunk-EQ4M72KU.js.map +1 -0
- package/dist/{chunk-O3CS4UGX.cjs → chunk-IDRQZVB4.cjs} +4 -4
- package/dist/{chunk-O3CS4UGX.cjs.map → chunk-IDRQZVB4.cjs.map} +1 -1
- package/dist/{chunk-YF4R74L2.js → chunk-RC6RZVYE.js} +4 -4
- package/dist/{chunk-YF4R74L2.js.map → chunk-RC6RZVYE.js.map} +1 -1
- package/dist/{chunk-6TXUWFIU.js → chunk-TYVPTNCP.js} +1885 -313
- package/dist/chunk-TYVPTNCP.js.map +1 -0
- package/dist/chunk-ZD3BKU5O.cjs +441 -0
- package/dist/chunk-ZD3BKU5O.cjs.map +1 -0
- package/dist/docs/SKILL.md +51 -50
- package/dist/docs/{SOURCE_MAP.json → assets/SOURCE_MAP.json} +22 -22
- package/dist/docs/{agents/03-agent-approval.md → references/docs-agents-agent-approval.md} +19 -19
- package/dist/docs/references/docs-agents-agent-memory.md +212 -0
- package/dist/docs/{agents/04-network-approval.md → references/docs-agents-network-approval.md} +13 -12
- package/dist/docs/{agents/02-networks.md → references/docs-agents-networks.md} +10 -12
- package/dist/docs/{memory/06-memory-processors.md → references/docs-memory-memory-processors.md} +6 -8
- package/dist/docs/{memory/03-message-history.md → references/docs-memory-message-history.md} +31 -20
- package/dist/docs/references/docs-memory-observational-memory.md +238 -0
- package/dist/docs/{memory/01-overview.md → references/docs-memory-overview.md} +8 -8
- package/dist/docs/{memory/05-semantic-recall.md → references/docs-memory-semantic-recall.md} +33 -17
- package/dist/docs/{memory/02-storage.md → references/docs-memory-storage.md} +29 -39
- package/dist/docs/{memory/04-working-memory.md → references/docs-memory-working-memory.md} +16 -27
- package/dist/docs/references/reference-core-getMemory.md +50 -0
- package/dist/docs/references/reference-core-listMemory.md +56 -0
- package/dist/docs/references/reference-memory-clone-utilities.md +199 -0
- package/dist/docs/references/reference-memory-cloneThread.md +130 -0
- package/dist/docs/references/reference-memory-createThread.md +68 -0
- package/dist/docs/references/reference-memory-getThreadById.md +24 -0
- package/dist/docs/references/reference-memory-listThreads.md +145 -0
- package/dist/docs/references/reference-memory-memory-class.md +147 -0
- package/dist/docs/references/reference-memory-observational-memory.md +528 -0
- package/dist/docs/{processors/01-reference.md → references/reference-processors-token-limiter-processor.md} +25 -12
- package/dist/docs/references/reference-storage-dynamodb.md +282 -0
- package/dist/docs/references/reference-storage-libsql.md +135 -0
- package/dist/docs/references/reference-storage-mongodb.md +262 -0
- package/dist/docs/references/reference-storage-postgresql.md +529 -0
- package/dist/docs/references/reference-storage-upstash.md +160 -0
- package/dist/docs/references/reference-vectors-libsql.md +305 -0
- package/dist/docs/references/reference-vectors-mongodb.md +295 -0
- package/dist/docs/references/reference-vectors-pg.md +408 -0
- package/dist/docs/references/reference-vectors-upstash.md +294 -0
- package/dist/index.cjs +919 -507
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +914 -502
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-3Q42SITP.cjs → observational-memory-3UO64HYD.cjs} +14 -14
- package/dist/{observational-memory-3Q42SITP.cjs.map → observational-memory-3UO64HYD.cjs.map} +1 -1
- package/dist/{observational-memory-VXLHOSDZ.js → observational-memory-TVHT3HP4.js} +3 -3
- package/dist/{observational-memory-VXLHOSDZ.js.map → observational-memory-TVHT3HP4.js.map} +1 -1
- package/dist/processors/index.cjs +12 -12
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/index.d.ts +1 -1
- package/dist/processors/observational-memory/index.d.ts.map +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts +267 -1
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/observer-agent.d.ts +3 -1
- package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -1
- package/dist/processors/observational-memory/reflector-agent.d.ts +10 -3
- package/dist/processors/observational-memory/reflector-agent.d.ts.map +1 -1
- package/dist/processors/observational-memory/types.d.ts +243 -19
- package/dist/processors/observational-memory/types.d.ts.map +1 -1
- package/dist/{token-6GSAFR2W-WGTMOPEU.js → token-APYSY3BW-2DN6RAUY.js} +11 -11
- package/dist/token-APYSY3BW-2DN6RAUY.js.map +1 -0
- package/dist/{token-6GSAFR2W-2B4WM6AQ.cjs → token-APYSY3BW-ZQ7TMBY7.cjs} +14 -14
- package/dist/token-APYSY3BW-ZQ7TMBY7.cjs.map +1 -0
- package/dist/token-util-RMHT2CPJ-6TGPE335.cjs +10 -0
- package/dist/token-util-RMHT2CPJ-6TGPE335.cjs.map +1 -0
- package/dist/token-util-RMHT2CPJ-RJEA3FAN.js +8 -0
- package/dist/token-util-RMHT2CPJ-RJEA3FAN.js.map +1 -0
- package/dist/tools/working-memory.d.ts.map +1 -1
- package/package.json +9 -10
- package/dist/chunk-6TXUWFIU.js.map +0 -1
- package/dist/chunk-FQJWVCDF.cjs.map +0 -1
- package/dist/chunk-WM6IIUQW.js +0 -250
- package/dist/chunk-WM6IIUQW.js.map +0 -1
- package/dist/chunk-ZSBBXHNM.cjs +0 -252
- package/dist/chunk-ZSBBXHNM.cjs.map +0 -1
- package/dist/docs/README.md +0 -36
- package/dist/docs/agents/01-agent-memory.md +0 -166
- package/dist/docs/core/01-reference.md +0 -114
- package/dist/docs/memory/07-reference.md +0 -687
- package/dist/docs/storage/01-reference.md +0 -1218
- package/dist/docs/vectors/01-reference.md +0 -942
- package/dist/token-6GSAFR2W-2B4WM6AQ.cjs.map +0 -1
- package/dist/token-6GSAFR2W-WGTMOPEU.js.map +0 -1
- package/dist/token-util-NEHG7TUY-TV2H7N56.js +0 -8
- package/dist/token-util-NEHG7TUY-TV2H7N56.js.map +0 -1
- package/dist/token-util-NEHG7TUY-WJZIPNNX.cjs +0 -10
- package/dist/token-util-NEHG7TUY-WJZIPNNX.cjs.map +0 -1
|
@@ -1,52 +1,52 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkAWE2QQPI_cjs = require('./chunk-AWE2QQPI.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "OBSERVATIONAL_MEMORY_DEFAULTS", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkAWE2QQPI_cjs.OBSERVATIONAL_MEMORY_DEFAULTS; }
|
|
10
10
|
});
|
|
11
11
|
Object.defineProperty(exports, "OBSERVER_SYSTEM_PROMPT", {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkAWE2QQPI_cjs.OBSERVER_SYSTEM_PROMPT; }
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, "ObservationalMemory", {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunkAWE2QQPI_cjs.ObservationalMemory; }
|
|
18
18
|
});
|
|
19
19
|
Object.defineProperty(exports, "TokenCounter", {
|
|
20
20
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
21
|
+
get: function () { return chunkAWE2QQPI_cjs.TokenCounter; }
|
|
22
22
|
});
|
|
23
23
|
Object.defineProperty(exports, "buildObserverPrompt", {
|
|
24
24
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
25
|
+
get: function () { return chunkAWE2QQPI_cjs.buildObserverPrompt; }
|
|
26
26
|
});
|
|
27
27
|
Object.defineProperty(exports, "buildObserverSystemPrompt", {
|
|
28
28
|
enumerable: true,
|
|
29
|
-
get: function () { return
|
|
29
|
+
get: function () { return chunkAWE2QQPI_cjs.buildObserverSystemPrompt; }
|
|
30
30
|
});
|
|
31
31
|
Object.defineProperty(exports, "extractCurrentTask", {
|
|
32
32
|
enumerable: true,
|
|
33
|
-
get: function () { return
|
|
33
|
+
get: function () { return chunkAWE2QQPI_cjs.extractCurrentTask; }
|
|
34
34
|
});
|
|
35
35
|
Object.defineProperty(exports, "formatMessagesForObserver", {
|
|
36
36
|
enumerable: true,
|
|
37
|
-
get: function () { return
|
|
37
|
+
get: function () { return chunkAWE2QQPI_cjs.formatMessagesForObserver; }
|
|
38
38
|
});
|
|
39
39
|
Object.defineProperty(exports, "hasCurrentTaskSection", {
|
|
40
40
|
enumerable: true,
|
|
41
|
-
get: function () { return
|
|
41
|
+
get: function () { return chunkAWE2QQPI_cjs.hasCurrentTaskSection; }
|
|
42
42
|
});
|
|
43
43
|
Object.defineProperty(exports, "optimizeObservationsForContext", {
|
|
44
44
|
enumerable: true,
|
|
45
|
-
get: function () { return
|
|
45
|
+
get: function () { return chunkAWE2QQPI_cjs.optimizeObservationsForContext; }
|
|
46
46
|
});
|
|
47
47
|
Object.defineProperty(exports, "parseObserverOutput", {
|
|
48
48
|
enumerable: true,
|
|
49
|
-
get: function () { return
|
|
49
|
+
get: function () { return chunkAWE2QQPI_cjs.parseObserverOutput; }
|
|
50
50
|
});
|
|
51
|
-
//# sourceMappingURL=observational-memory-
|
|
52
|
-
//# sourceMappingURL=observational-memory-
|
|
51
|
+
//# sourceMappingURL=observational-memory-3UO64HYD.cjs.map
|
|
52
|
+
//# sourceMappingURL=observational-memory-3UO64HYD.cjs.map
|
package/dist/{observational-memory-3Q42SITP.cjs.map → observational-memory-3UO64HYD.cjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-3UO64HYD.cjs"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput } from './chunk-
|
|
2
|
-
//# sourceMappingURL=observational-memory-
|
|
3
|
-
//# sourceMappingURL=observational-memory-
|
|
1
|
+
export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput } from './chunk-TYVPTNCP.js';
|
|
2
|
+
//# sourceMappingURL=observational-memory-TVHT3HP4.js.map
|
|
3
|
+
//# sourceMappingURL=observational-memory-TVHT3HP4.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-TVHT3HP4.js"}
|
|
@@ -1,52 +1,52 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkAWE2QQPI_cjs = require('../chunk-AWE2QQPI.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "OBSERVATIONAL_MEMORY_DEFAULTS", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkAWE2QQPI_cjs.OBSERVATIONAL_MEMORY_DEFAULTS; }
|
|
10
10
|
});
|
|
11
11
|
Object.defineProperty(exports, "OBSERVER_SYSTEM_PROMPT", {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkAWE2QQPI_cjs.OBSERVER_SYSTEM_PROMPT; }
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, "ObservationalMemory", {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunkAWE2QQPI_cjs.ObservationalMemory; }
|
|
18
18
|
});
|
|
19
19
|
Object.defineProperty(exports, "TokenCounter", {
|
|
20
20
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
21
|
+
get: function () { return chunkAWE2QQPI_cjs.TokenCounter; }
|
|
22
22
|
});
|
|
23
23
|
Object.defineProperty(exports, "buildObserverPrompt", {
|
|
24
24
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
25
|
+
get: function () { return chunkAWE2QQPI_cjs.buildObserverPrompt; }
|
|
26
26
|
});
|
|
27
27
|
Object.defineProperty(exports, "buildObserverSystemPrompt", {
|
|
28
28
|
enumerable: true,
|
|
29
|
-
get: function () { return
|
|
29
|
+
get: function () { return chunkAWE2QQPI_cjs.buildObserverSystemPrompt; }
|
|
30
30
|
});
|
|
31
31
|
Object.defineProperty(exports, "extractCurrentTask", {
|
|
32
32
|
enumerable: true,
|
|
33
|
-
get: function () { return
|
|
33
|
+
get: function () { return chunkAWE2QQPI_cjs.extractCurrentTask; }
|
|
34
34
|
});
|
|
35
35
|
Object.defineProperty(exports, "formatMessagesForObserver", {
|
|
36
36
|
enumerable: true,
|
|
37
|
-
get: function () { return
|
|
37
|
+
get: function () { return chunkAWE2QQPI_cjs.formatMessagesForObserver; }
|
|
38
38
|
});
|
|
39
39
|
Object.defineProperty(exports, "hasCurrentTaskSection", {
|
|
40
40
|
enumerable: true,
|
|
41
|
-
get: function () { return
|
|
41
|
+
get: function () { return chunkAWE2QQPI_cjs.hasCurrentTaskSection; }
|
|
42
42
|
});
|
|
43
43
|
Object.defineProperty(exports, "optimizeObservationsForContext", {
|
|
44
44
|
enumerable: true,
|
|
45
|
-
get: function () { return
|
|
45
|
+
get: function () { return chunkAWE2QQPI_cjs.optimizeObservationsForContext; }
|
|
46
46
|
});
|
|
47
47
|
Object.defineProperty(exports, "parseObserverOutput", {
|
|
48
48
|
enumerable: true,
|
|
49
|
-
get: function () { return
|
|
49
|
+
get: function () { return chunkAWE2QQPI_cjs.parseObserverOutput; }
|
|
50
50
|
});
|
|
51
51
|
//# sourceMappingURL=index.cjs.map
|
|
52
52
|
//# sourceMappingURL=index.cjs.map
|
package/dist/processors/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput } from '../chunk-
|
|
1
|
+
export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput } from '../chunk-TYVPTNCP.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* - Reflector: Condenses observations when they exceed threshold
|
|
12
12
|
*/
|
|
13
13
|
export { ObservationalMemory, OBSERVATIONAL_MEMORY_DEFAULTS, type ObservationalMemoryConfig, type ObservationDebugEvent, } from './observational-memory.js';
|
|
14
|
-
export type { ObservationConfig, ReflectionConfig, ObserverResult, ReflectorResult } from './types.js';
|
|
14
|
+
export type { ObservationConfig, ReflectionConfig, ObserverResult, ReflectorResult, DataOmBufferingStartPart, DataOmBufferingEndPart, DataOmBufferingFailedPart, DataOmBufferingPart, DataOmActivationPart, DataOmPart, } from './types.js';
|
|
15
15
|
export { OBSERVER_SYSTEM_PROMPT, buildObserverSystemPrompt, buildObserverPrompt, parseObserverOutput, optimizeObservationsForContext, formatMessagesForObserver, hasCurrentTaskSection, extractCurrentTask, type ObserverResult as ObserverAgentResult, } from './observer-agent.js';
|
|
16
16
|
export type { ObservationalMemoryRecord, ObservationalMemoryScope, ObservationalMemoryOriginType, CreateObservationalMemoryInput, UpdateActiveObservationsInput, UpdateBufferedObservationsInput, CreateReflectionGenerationInput, } from '@mastra/core/storage';
|
|
17
17
|
export { TokenCounter } from './token-counter.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EACL,mBAAmB,EACnB,6BAA6B,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,GAC3B,MAAM,wBAAwB,CAAC;AAGhC,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EACL,mBAAmB,EACnB,6BAA6B,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,GAC3B,MAAM,wBAAwB,CAAC;AAGhC,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,eAAe,EAEf,wBAAwB,EACxB,sBAAsB,EACtB,yBAAyB,EACzB,mBAAmB,EAEnB,oBAAoB,EACpB,UAAU,GACX,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,mBAAmB,EACnB,mBAAmB,EACnB,8BAA8B,EAC9B,yBAAyB,EACzB,qBAAqB,EACrB,kBAAkB,EAClB,KAAK,cAAc,IAAI,mBAAmB,GAC3C,MAAM,kBAAkB,CAAC;AAG1B,YAAY,EACV,yBAAyB,EACzB,wBAAwB,EACxB,6BAA6B,EAC7B,8BAA8B,EAC9B,6BAA6B,EAC7B,+BAA+B,EAC/B,+BAA+B,GAChC,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -113,6 +113,12 @@ interface ResolvedObservationConfig {
|
|
|
113
113
|
modelSettings: ModelSettings;
|
|
114
114
|
providerOptions: ProviderOptions;
|
|
115
115
|
maxTokensPerBatch: number;
|
|
116
|
+
/** Token interval for async background observation buffering (resolved from config) */
|
|
117
|
+
bufferTokens?: number;
|
|
118
|
+
/** Ratio of buffered observations to activate (0-1 float) */
|
|
119
|
+
bufferActivation?: number;
|
|
120
|
+
/** Token threshold above which synchronous observation is forced */
|
|
121
|
+
blockAfter?: number;
|
|
116
122
|
}
|
|
117
123
|
interface ResolvedReflectionConfig {
|
|
118
124
|
model: AgentConfig['model'];
|
|
@@ -123,6 +129,10 @@ interface ResolvedReflectionConfig {
|
|
|
123
129
|
/** Model settings - merged with user config and defaults */
|
|
124
130
|
modelSettings: ModelSettings;
|
|
125
131
|
providerOptions: ProviderOptions;
|
|
132
|
+
/** Ratio (0-1) controlling when async reflection buffering starts */
|
|
133
|
+
bufferActivation?: number;
|
|
134
|
+
/** Token threshold above which synchronous reflection is forced */
|
|
135
|
+
blockAfter?: number;
|
|
126
136
|
}
|
|
127
137
|
/**
|
|
128
138
|
* Default configuration values matching the spec
|
|
@@ -143,6 +153,8 @@ export declare const OBSERVATIONAL_MEMORY_DEFAULTS: {
|
|
|
143
153
|
};
|
|
144
154
|
};
|
|
145
155
|
readonly maxTokensPerBatch: 10000;
|
|
156
|
+
readonly bufferTokens: number | undefined;
|
|
157
|
+
readonly bufferActivation: number | undefined;
|
|
146
158
|
};
|
|
147
159
|
readonly reflection: {
|
|
148
160
|
readonly model: "google/gemini-2.5-flash";
|
|
@@ -158,6 +170,7 @@ export declare const OBSERVATIONAL_MEMORY_DEFAULTS: {
|
|
|
158
170
|
};
|
|
159
171
|
};
|
|
160
172
|
};
|
|
173
|
+
readonly bufferActivation: number | undefined;
|
|
161
174
|
};
|
|
162
175
|
};
|
|
163
176
|
/**
|
|
@@ -236,6 +249,90 @@ export declare class ObservationalMemory implements Processor<'observational-mem
|
|
|
236
249
|
* accept eventual consistency (acceptable for v1).
|
|
237
250
|
*/
|
|
238
251
|
private locks;
|
|
252
|
+
/**
|
|
253
|
+
* Track in-flight async buffering operations per resource/thread.
|
|
254
|
+
* STATIC: Shared across all ObservationalMemory instances in this process.
|
|
255
|
+
* This is critical because multiple OM instances are created per agent loop step,
|
|
256
|
+
* and we need them to share knowledge of in-flight operations.
|
|
257
|
+
* Key format: "obs:{lockKey}" or "refl:{lockKey}"
|
|
258
|
+
* Value: Promise that resolves when buffering completes
|
|
259
|
+
*/
|
|
260
|
+
private static asyncBufferingOps;
|
|
261
|
+
/**
|
|
262
|
+
* Track the last token boundary at which we started buffering.
|
|
263
|
+
* STATIC: Shared across all instances so boundary tracking persists across OM recreations.
|
|
264
|
+
* Key format: "obs:{lockKey}" or "refl:{lockKey}"
|
|
265
|
+
*/
|
|
266
|
+
private static lastBufferedBoundary;
|
|
267
|
+
/**
|
|
268
|
+
* Track the timestamp cursor for buffered messages.
|
|
269
|
+
* STATIC: Shared across all instances so each buffer only observes messages
|
|
270
|
+
* newer than the previous buffer's boundary.
|
|
271
|
+
* Key format: "obs:{lockKey}"
|
|
272
|
+
*/
|
|
273
|
+
private static lastBufferedAtTime;
|
|
274
|
+
/**
|
|
275
|
+
* Tracks cycleId for in-flight buffered reflections.
|
|
276
|
+
* STATIC: Shared across instances so we can match cycleId at activation time.
|
|
277
|
+
* Key format: "refl:{lockKey}"
|
|
278
|
+
*/
|
|
279
|
+
private static reflectionBufferCycleIds;
|
|
280
|
+
/**
|
|
281
|
+
* Track message IDs that have been sealed during async buffering.
|
|
282
|
+
* STATIC: Shared across all instances so saveMessagesWithSealedIdTracking
|
|
283
|
+
* generates new IDs when re-saving messages that were sealed in a previous step.
|
|
284
|
+
* Key format: threadId
|
|
285
|
+
* Value: Set of sealed message IDs
|
|
286
|
+
*/
|
|
287
|
+
private static sealedMessageIds;
|
|
288
|
+
/**
|
|
289
|
+
* Check if async buffering is enabled for observations.
|
|
290
|
+
*/
|
|
291
|
+
private isAsyncObservationEnabled;
|
|
292
|
+
/**
|
|
293
|
+
* Check if async buffering is enabled for reflections.
|
|
294
|
+
* Reflection buffering is enabled when bufferActivation is set (triggers at threshold * bufferActivation).
|
|
295
|
+
*/
|
|
296
|
+
private isAsyncReflectionEnabled;
|
|
297
|
+
/**
|
|
298
|
+
* Get the buffer interval boundary key for observations.
|
|
299
|
+
*/
|
|
300
|
+
private getObservationBufferKey;
|
|
301
|
+
/**
|
|
302
|
+
* Get the buffer interval boundary key for reflections.
|
|
303
|
+
*/
|
|
304
|
+
private getReflectionBufferKey;
|
|
305
|
+
/**
|
|
306
|
+
* Clean up static maps for a thread/resource to prevent memory leaks.
|
|
307
|
+
* Called after activation (to remove activated message IDs from sealedMessageIds)
|
|
308
|
+
* and from clear() (to fully remove all static state for a thread).
|
|
309
|
+
*/
|
|
310
|
+
private cleanupStaticMaps;
|
|
311
|
+
/**
|
|
312
|
+
* Safely get bufferedObservationChunks as an array.
|
|
313
|
+
* Handles cases where it might be a JSON string or undefined.
|
|
314
|
+
*/
|
|
315
|
+
private getBufferedChunks;
|
|
316
|
+
/**
|
|
317
|
+
* Calculate the projected message tokens that would be removed if activation happened now.
|
|
318
|
+
* This replicates the chunk boundary logic in swapBufferedToActive without actually activating.
|
|
319
|
+
*/
|
|
320
|
+
private calculateProjectedMessageRemoval;
|
|
321
|
+
/**
|
|
322
|
+
* Check if we've crossed a new bufferTokens interval boundary.
|
|
323
|
+
* Returns true if async buffering should be triggered.
|
|
324
|
+
*/
|
|
325
|
+
private shouldTriggerAsyncObservation;
|
|
326
|
+
/**
|
|
327
|
+
* Check if async reflection buffering should be triggered.
|
|
328
|
+
* Triggers once when observation tokens reach `threshold * bufferActivation`.
|
|
329
|
+
* Only allows one buffered reflection at a time.
|
|
330
|
+
*/
|
|
331
|
+
private shouldTriggerAsyncReflection;
|
|
332
|
+
/**
|
|
333
|
+
* Check if an async buffering operation is already in progress.
|
|
334
|
+
*/
|
|
335
|
+
private isAsyncBufferingInProgress;
|
|
239
336
|
/**
|
|
240
337
|
* Acquire a lock for the given key, execute the callback, then release.
|
|
241
338
|
* If a lock is already held, waits for it to be released before acquiring.
|
|
@@ -278,6 +375,24 @@ export declare class ObservationalMemory implements Processor<'observational-mem
|
|
|
278
375
|
* Emit a debug event if the callback is configured
|
|
279
376
|
*/
|
|
280
377
|
private emitDebugEvent;
|
|
378
|
+
/**
|
|
379
|
+
* Validate buffer configuration on first use.
|
|
380
|
+
* Ensures bufferTokens is less than the threshold and bufferActivation is valid.
|
|
381
|
+
*/
|
|
382
|
+
private validateBufferConfig;
|
|
383
|
+
/**
|
|
384
|
+
* Resolve bufferTokens: if it's a fraction (0 < value < 1), multiply by messageTokens threshold.
|
|
385
|
+
* Otherwise return the absolute token count.
|
|
386
|
+
*/
|
|
387
|
+
private resolveBufferTokens;
|
|
388
|
+
/**
|
|
389
|
+
* Resolve blockAfter config value.
|
|
390
|
+
* Values between 1 and 2 (exclusive) are treated as multipliers of the threshold.
|
|
391
|
+
* e.g. blockAfter: 1.5 with messageTokens: 20_000 → 30_000
|
|
392
|
+
* Values >= 2 are treated as absolute token counts.
|
|
393
|
+
* Defaults to 1.2 (120% of threshold) when async buffering is enabled but blockAfter is omitted.
|
|
394
|
+
*/
|
|
395
|
+
private resolveBlockAfter;
|
|
281
396
|
/**
|
|
282
397
|
* Get the maximum value from a threshold (simple number or range)
|
|
283
398
|
*/
|
|
@@ -332,6 +447,28 @@ export declare class ObservationalMemory implements Processor<'observational-mem
|
|
|
332
447
|
* Create a failed marker for when observation fails.
|
|
333
448
|
*/
|
|
334
449
|
private createObservationFailedMarker;
|
|
450
|
+
/**
|
|
451
|
+
* Create a start marker for when async buffering begins.
|
|
452
|
+
*/
|
|
453
|
+
private createBufferingStartMarker;
|
|
454
|
+
/**
|
|
455
|
+
* Create an end marker for when async buffering completes successfully.
|
|
456
|
+
*/
|
|
457
|
+
private createBufferingEndMarker;
|
|
458
|
+
/**
|
|
459
|
+
* Create a failed marker for when async buffering fails.
|
|
460
|
+
*/
|
|
461
|
+
private createBufferingFailedMarker;
|
|
462
|
+
/**
|
|
463
|
+
* Create an activation marker for when buffered observations are activated.
|
|
464
|
+
*/
|
|
465
|
+
private createActivationMarker;
|
|
466
|
+
/**
|
|
467
|
+
* Persist a data-om-* marker part on the last assistant message in messageList
|
|
468
|
+
* AND save the updated message to the DB so it survives page reload.
|
|
469
|
+
* (data-* parts are filtered out before sending to the LLM, so they don't affect model calls.)
|
|
470
|
+
*/
|
|
471
|
+
private persistMarkerToMessage;
|
|
335
472
|
/**
|
|
336
473
|
* Find the last completed observation boundary in a message's parts.
|
|
337
474
|
* A completed observation is a start marker followed by an end marker.
|
|
@@ -344,6 +481,23 @@ export declare class ObservationalMemory implements Processor<'observational-mem
|
|
|
344
481
|
* Check if a message has an in-progress observation (start without end).
|
|
345
482
|
*/
|
|
346
483
|
private hasInProgressObservation;
|
|
484
|
+
/**
|
|
485
|
+
* Seal messages to prevent new parts from being merged into them.
|
|
486
|
+
* This is used when starting buffering to capture the current content state.
|
|
487
|
+
*
|
|
488
|
+
* Sealing works by:
|
|
489
|
+
* 1. Setting `message.content.metadata.mastra.sealed = true` (message-level flag)
|
|
490
|
+
* 2. Adding `metadata.mastra.sealedAt` to the last part (boundary marker)
|
|
491
|
+
*
|
|
492
|
+
* When MessageList.add() receives a message with the same ID as a sealed message,
|
|
493
|
+
* it creates a new message with only the parts beyond the seal boundary.
|
|
494
|
+
*
|
|
495
|
+
* The messages are mutated in place - since they're references to the same objects
|
|
496
|
+
* in the MessageList, the seal will be recognized immediately.
|
|
497
|
+
*
|
|
498
|
+
* @param messages - Messages to seal (mutated in place)
|
|
499
|
+
*/
|
|
500
|
+
private sealMessagesForBuffering;
|
|
347
501
|
/**
|
|
348
502
|
* Insert an observation marker into a message.
|
|
349
503
|
* The marker is appended directly to the message's parts array (mutating in place).
|
|
@@ -426,6 +580,45 @@ export declare class ObservationalMemory implements Processor<'observational-mem
|
|
|
426
580
|
* Get threadId and resourceId from either RequestContext or MessageList
|
|
427
581
|
*/
|
|
428
582
|
private getThreadContext;
|
|
583
|
+
/**
|
|
584
|
+
* Load historical unobserved messages into the message list (step 0 only).
|
|
585
|
+
* In resource scope, loads only current thread's messages.
|
|
586
|
+
* In thread scope, loads all unobserved messages for the thread.
|
|
587
|
+
*/
|
|
588
|
+
private loadHistoricalMessagesIfNeeded;
|
|
589
|
+
/**
|
|
590
|
+
* Calculate all threshold-related values for observation decision making.
|
|
591
|
+
*/
|
|
592
|
+
private calculateObservationThresholds;
|
|
593
|
+
/**
|
|
594
|
+
* Emit debug event and stream progress part for UI feedback.
|
|
595
|
+
*/
|
|
596
|
+
private emitStepProgress;
|
|
597
|
+
/**
|
|
598
|
+
* Handle observation when threshold is reached.
|
|
599
|
+
* Tries async activation first if enabled, then falls back to sync observation.
|
|
600
|
+
* Returns whether observation succeeded.
|
|
601
|
+
*/
|
|
602
|
+
private handleThresholdReached;
|
|
603
|
+
/**
|
|
604
|
+
* Remove observed messages from message list after successful observation.
|
|
605
|
+
* Accepts optional observedMessageIds for activation-based cleanup (when no markers are present).
|
|
606
|
+
*/
|
|
607
|
+
private cleanupAfterObservation;
|
|
608
|
+
/**
|
|
609
|
+
* Handle per-step save when threshold is not reached.
|
|
610
|
+
* Persists messages incrementally to prevent data loss on interruption.
|
|
611
|
+
*/
|
|
612
|
+
private handlePerStepSave;
|
|
613
|
+
/**
|
|
614
|
+
* Inject observations as system message and add continuation reminder.
|
|
615
|
+
*/
|
|
616
|
+
private injectObservationsIntoContext;
|
|
617
|
+
/**
|
|
618
|
+
* Filter out already-observed messages from message list (step 0 only).
|
|
619
|
+
* Historical messages loaded from DB may contain observation markers from previous sessions.
|
|
620
|
+
*/
|
|
621
|
+
private filterAlreadyObservedMessages;
|
|
429
622
|
/**
|
|
430
623
|
* Process input at each step - check threshold, observe if needed, save, inject observations.
|
|
431
624
|
* This is the ONLY processor method - all OM logic happens here.
|
|
@@ -509,6 +702,71 @@ export declare class ObservationalMemory implements Processor<'observational-mem
|
|
|
509
702
|
* Do synchronous observation (fallback when no buffering)
|
|
510
703
|
*/
|
|
511
704
|
private doSynchronousObservation;
|
|
705
|
+
/**
|
|
706
|
+
* Start an async background observation that stores results to bufferedObservations.
|
|
707
|
+
* This is a fire-and-forget operation that runs in the background.
|
|
708
|
+
* The results will be swapped to active when the main threshold is reached.
|
|
709
|
+
*
|
|
710
|
+
* If another buffering operation is already in progress for this scope, this will
|
|
711
|
+
* wait for it to complete before starting a new one (mutex behavior).
|
|
712
|
+
*
|
|
713
|
+
* @param record - Current OM record
|
|
714
|
+
* @param threadId - Thread ID
|
|
715
|
+
* @param unobservedMessages - All unobserved messages (will be filtered for already-buffered)
|
|
716
|
+
* @param lockKey - Lock key for this scope
|
|
717
|
+
* @param writer - Optional stream writer for emitting buffering markers
|
|
718
|
+
*/
|
|
719
|
+
private startAsyncBufferedObservation;
|
|
720
|
+
/**
|
|
721
|
+
* Internal method that waits for existing buffering operation and then runs new buffering.
|
|
722
|
+
* This implements the mutex-wait behavior.
|
|
723
|
+
*/
|
|
724
|
+
private runAsyncBufferedObservation;
|
|
725
|
+
/**
|
|
726
|
+
* Perform async buffered observation - observes messages and stores to bufferedObservations.
|
|
727
|
+
* Does NOT update activeObservations or trigger reflection.
|
|
728
|
+
*
|
|
729
|
+
* The observer sees: active observations + existing buffered observations + message history
|
|
730
|
+
* (excluding already-buffered messages).
|
|
731
|
+
*/
|
|
732
|
+
private doAsyncBufferedObservation;
|
|
733
|
+
/**
|
|
734
|
+
* Combine active and buffered observations for the buffering observer context.
|
|
735
|
+
* The buffering observer needs to see both so it doesn't duplicate content.
|
|
736
|
+
*/
|
|
737
|
+
private combineObservationsForBuffering;
|
|
738
|
+
/**
|
|
739
|
+
* Try to activate buffered observations when threshold is reached.
|
|
740
|
+
* Returns true if activation succeeded, false if no buffered content or activation failed.
|
|
741
|
+
*
|
|
742
|
+
* @param record - Current OM record
|
|
743
|
+
* @param lockKey - Lock key for this scope
|
|
744
|
+
* @param writer - Optional writer for emitting UI markers
|
|
745
|
+
*/
|
|
746
|
+
private tryActivateBufferedObservations;
|
|
747
|
+
/**
|
|
748
|
+
* Start an async background reflection that stores results to bufferedReflection.
|
|
749
|
+
* This is a fire-and-forget operation that runs in the background.
|
|
750
|
+
* The results will be swapped to active when the main reflection threshold is reached.
|
|
751
|
+
*
|
|
752
|
+
* @param record - Current OM record
|
|
753
|
+
* @param observationTokens - Current observation token count
|
|
754
|
+
* @param lockKey - Lock key for this scope
|
|
755
|
+
*/
|
|
756
|
+
private startAsyncBufferedReflection;
|
|
757
|
+
/**
|
|
758
|
+
* Perform async buffered reflection - reflects observations and stores to bufferedReflection.
|
|
759
|
+
* Does NOT create a new generation or update activeObservations.
|
|
760
|
+
*/
|
|
761
|
+
private doAsyncBufferedReflection;
|
|
762
|
+
/**
|
|
763
|
+
* Try to activate buffered reflection when threshold is reached.
|
|
764
|
+
* Returns true if activation succeeded, false if no buffered content or activation failed.
|
|
765
|
+
*
|
|
766
|
+
* @param record - Current OM record
|
|
767
|
+
* @param lockKey - Lock key for this scope
|
|
768
|
+
*/
|
|
769
|
+
private tryActivateBufferedReflection;
|
|
512
770
|
/**
|
|
513
771
|
* Resource-scoped observation: observe ALL threads with unobserved messages.
|
|
514
772
|
* Threads are observed in oldest-first order to ensure no thread's messages
|
|
@@ -521,9 +779,17 @@ export declare class ObservationalMemory implements Processor<'observational-mem
|
|
|
521
779
|
* 4. Only triggers reflection AFTER all threads are observed
|
|
522
780
|
*/
|
|
523
781
|
private doResourceScopedObservation;
|
|
782
|
+
/**
|
|
783
|
+
* Check if async reflection should be triggered or activated.
|
|
784
|
+
* Only handles the async path — will never do synchronous (blocking) reflection.
|
|
785
|
+
* Safe to call after buffered observation activation.
|
|
786
|
+
*/
|
|
787
|
+
private maybeAsyncReflect;
|
|
524
788
|
/**
|
|
525
789
|
* Check if reflection needed and trigger if so.
|
|
526
|
-
*
|
|
790
|
+
* Supports both synchronous reflection and async buffered reflection.
|
|
791
|
+
* When async buffering is enabled via `bufferTokens`, reflection is triggered
|
|
792
|
+
* in the background at intervals, and activated when the threshold is reached.
|
|
527
793
|
*/
|
|
528
794
|
private maybeReflect;
|
|
529
795
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observational-memory.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/observational-memory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"observational-memory.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/observational-memory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGpF,OAAO,KAAK,EACV,SAAS,EAET,oBAAoB,EACpB,uBAAuB,EAExB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB,EAA4B,MAAM,sBAAsB,CAAC;AAkF/G,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,eAAe,EAWhB,MAAM,SAAS,CAAC;AAiOjB;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EACA,uBAAuB,GACvB,sBAAsB,GACtB,sBAAsB,GACtB,qBAAqB,GACrB,oBAAoB,GACpB,eAAe,CAAC;IACpB,SAAS,EAAE,IAAI,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpD,mBAAmB;IACnB,aAAa,CAAC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CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAMzF;;OAEG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC;IAKjG;;OAEG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,EAAE,CAAC;IAK7G;;OAEG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjE;;OAEG;IACH,UAAU,IAAI,aAAa;IAI3B;;OAEG;IACH,eAAe,IAAI,YAAY;IAI/B;;OAEG;IACH,oBAAoB,IAAI,yBAAyB;IAIjD;;OAEG;IACH,mBAAmB,IAAI,wBAAwB;CAGhD"}
|
|
@@ -73,7 +73,9 @@ export declare function parseMultiThreadObserverOutput(output: string): MultiThr
|
|
|
73
73
|
* Build the full prompt for the Observer agent.
|
|
74
74
|
* Includes emphasis on the most recent user message for priority handling.
|
|
75
75
|
*/
|
|
76
|
-
export declare function buildObserverPrompt(existingObservations: string | undefined, messagesToObserve: MastraDBMessage[]
|
|
76
|
+
export declare function buildObserverPrompt(existingObservations: string | undefined, messagesToObserve: MastraDBMessage[], options?: {
|
|
77
|
+
skipContinuationHints?: boolean;
|
|
78
|
+
}): string;
|
|
77
79
|
/**
|
|
78
80
|
* Parse the Observer's output to extract observations, current task, and suggested response.
|
|
79
81
|
* Uses XML tag parsing for structured extraction.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observer-agent.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/observer-agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,M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AgB,8BAA8B,CAAC,MAAM,EAAE,MAAM,GAAG,yBAAyB,CAsDxF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,oBAAoB,EAAE,MAAM,GAAG,SAAS,EACxC,iBAAiB,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"observer-agent.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/observer-agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AA0T1D;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,QAIC,CAAC;AAqD/C;;GAEG;AACH,eAAO,MAAM,2BAA2B,+8CAoClB,CAAC;AAevB;;;GAGG;AACH,eAAO,MAAM,mBAAmB,QAa0D,CAAC;AAE3F;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,GAAE,OAAe,GAAG,MAAM,CAyF9E;AAED;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,QAA8B,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAC;IAErB,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,mDAAmD;IACnD,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,eAAe,EAAE,EAAE,OAAO,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAqDnH;AAUD;;;GAGG;AACH,wBAAgB,oCAAoC,CAClD,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC,EAChD,WAAW,EAAE,MAAM,EAAE,GACpB,MAAM,CAYR;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAC5C,oBAAoB,EAAE,MAAM,GAAG,SAAS,EACxC,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC,EAChD,WAAW,EAAE,MAAM,EAAE,GACpB,MAAM,CAgCR;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,yBAAyB;IACzB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACrC,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,MAAM,GAAG,yBAAyB,CAsDxF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,oBAAoB,EAAE,MAAM,GAAG,SAAS,EACxC,iBAAiB,EAAE,eAAe,EAAE,EACpC,OAAO,CAAC,EAAE;IAAE,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5C,MAAM,CAqBR;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAalE;AAED;;GAEG;AACH,UAAU,mBAAmB;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB,CAsC1E;AAqBD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAenE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUtE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAoB3E"}
|
|
@@ -23,13 +23,20 @@ export declare function buildReflectorSystemPrompt(): string;
|
|
|
23
23
|
*/
|
|
24
24
|
export declare const REFLECTOR_SYSTEM_PROMPT: string;
|
|
25
25
|
/**
|
|
26
|
-
* Compression
|
|
26
|
+
* Compression guidance by level.
|
|
27
|
+
* - Level 0: No compression guidance (used as first attempt for regular reflection)
|
|
28
|
+
* - Level 1: Gentle compression guidance (original wording — "slightly more" goes a long way for LLMs)
|
|
29
|
+
* - Level 2: Aggressive compression guidance (stronger push when level 1 didn't work)
|
|
27
30
|
*/
|
|
28
|
-
export declare const
|
|
31
|
+
export declare const COMPRESSION_GUIDANCE: Record<0 | 1 | 2, string>;
|
|
32
|
+
/**
|
|
33
|
+
* Compression retry prompt - backwards compat alias for level 1
|
|
34
|
+
*/
|
|
35
|
+
export declare const COMPRESSION_RETRY_PROMPT: string;
|
|
29
36
|
/**
|
|
30
37
|
* Build the prompt for the Reflector agent
|
|
31
38
|
*/
|
|
32
|
-
export declare function buildReflectorPrompt(observations: string, manualPrompt?: string,
|
|
39
|
+
export declare function buildReflectorPrompt(observations: string, manualPrompt?: string, compressionLevel?: boolean | 0 | 1 | 2, skipContinuationHints?: boolean): string;
|
|
33
40
|
/**
|
|
34
41
|
* Parse the Reflector's output to extract observations, current task, and suggested response.
|
|
35
42
|
* Uses XML tag parsing for structured extraction.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reflector-agent.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/reflector-agent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,IAAI,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEtE;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,mBAAmB;IAC1D,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,CA8FnD;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,QAA+B,CAAC;AAEpE;;GAEG;AACH,eAAO,MAAM,wBAAwB,
|
|
1
|
+
{"version":3,"file":"reflector-agent.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/reflector-agent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,IAAI,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEtE;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,mBAAmB;IAC1D,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,CA8FnD;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,QAA+B,CAAC;AAEpE;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,CA+B1D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,QAA0B,CAAC;AAEhE;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,EACpB,YAAY,CAAC,EAAE,MAAM,EACrB,gBAAgB,CAAC,EAAE,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EACtC,qBAAqB,CAAC,EAAE,OAAO,GAC9B,MAAM,CAgCR;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,CAYpE;AAsED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,eAAe,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAG7F"}
|