@mastra/memory 1.2.0 → 1.3.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 +94 -0
- package/dist/{chunk-5YW6JV6Y.js → chunk-F5P5HTMC.js} +135 -67
- package/dist/chunk-F5P5HTMC.js.map +1 -0
- package/dist/{chunk-7SCXX4S7.cjs → chunk-LXATBJ2L.cjs} +137 -66
- package/dist/chunk-LXATBJ2L.cjs.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +26 -14
- package/dist/docs/references/docs-memory-observational-memory.md +86 -11
- package/dist/docs/references/reference-memory-observational-memory.md +318 -9
- package/dist/index.cjs +22 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -1
- package/dist/index.js.map +1 -1
- package/dist/observational-memory-3DA7KJIH.js +3 -0
- package/dist/{observational-memory-LI6QFTRE.js.map → observational-memory-3DA7KJIH.js.map} +1 -1
- package/dist/observational-memory-SA5RITIG.cjs +64 -0
- package/dist/{observational-memory-G3HACXHE.cjs.map → observational-memory-SA5RITIG.cjs.map} +1 -1
- package/dist/processors/index.cjs +24 -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 +41 -4
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/package.json +7 -7
- package/dist/chunk-5YW6JV6Y.js.map +0 -1
- package/dist/chunk-7SCXX4S7.cjs.map +0 -1
- package/dist/observational-memory-G3HACXHE.cjs +0 -52
- package/dist/observational-memory-LI6QFTRE.js +0 -3
|
@@ -1033,7 +1033,7 @@ var TokenCounter = class _TokenCounter {
|
|
|
1033
1033
|
if (toolResultCount > 0) {
|
|
1034
1034
|
overhead += toolResultCount * _TokenCounter.TOKENS_PER_MESSAGE;
|
|
1035
1035
|
}
|
|
1036
|
-
return this.encoder.encode(tokenString, "all").length + overhead;
|
|
1036
|
+
return Math.round(this.encoder.encode(tokenString, "all").length + overhead);
|
|
1037
1037
|
}
|
|
1038
1038
|
/**
|
|
1039
1039
|
* Count tokens in an array of messages
|
|
@@ -1287,6 +1287,17 @@ var OBSERVATIONAL_MEMORY_DEFAULTS = {
|
|
|
1287
1287
|
// Start buffering at 50% of observationTokens
|
|
1288
1288
|
}
|
|
1289
1289
|
};
|
|
1290
|
+
var OBSERVATION_CONTINUATION_HINT = `This message is not from the user, the conversation history grew too long and wouldn't fit in context! Thankfully the entire conversation is stored in your memory observations. Please continue from where the observations left off. Do not refer to your "memory observations" directly, the user doesn't know about them, they are your memories! Just respond naturally as if you're remembering the conversation (you are!). Do not say "Hi there!" or "based on our previous conversation" as if the conversation is just starting, this is not a new conversation. This is an ongoing conversation, keep continuity by responding based on your memory. For example do not say "I understand. I've reviewed my memory observations", or "I remember [...]". Answer naturally following the suggestion from your memory. Note that your memory may contain a suggested first response, which you should follow.
|
|
1291
|
+
|
|
1292
|
+
IMPORTANT: this system reminder is NOT from the user. The system placed it here as part of your memory system. This message is part of you remembering your conversation with the user.
|
|
1293
|
+
|
|
1294
|
+
NOTE: Any messages following this system reminder are newer than your memories.`;
|
|
1295
|
+
var OBSERVATION_CONTEXT_PROMPT = `The following observations block contains your memory of past conversations with this user.`;
|
|
1296
|
+
var OBSERVATION_CONTEXT_INSTRUCTIONS = `IMPORTANT: When responding, reference specific details from these observations. Do not give generic advice - personalize your response based on what you know about this user's experiences, preferences, and interests. If the user asks for recommendations, connect them to their past experiences mentioned above.
|
|
1297
|
+
|
|
1298
|
+
KNOWLEDGE UPDATES: When asked about current state (e.g., "where do I currently...", "what is my current..."), always prefer the MOST RECENT information. Observations include dates - if you see conflicting information, the newer observation supersedes the older one. Look for phrases like "will start", "is switching", "changed to", "moved to" as indicators that previous information has been updated.
|
|
1299
|
+
|
|
1300
|
+
PLANNED ACTIONS: If the user stated they planned to do something (e.g., "I'm going to...", "I'm looking forward to...", "I will...") and the date they planned to do it is now in the past (check the relative time like "3 weeks ago"), assume they completed the action unless there's evidence they didn't. For example, if someone said "I'll start my new diet on Monday" and that was 2 weeks ago, assume they started the diet.`;
|
|
1290
1301
|
var ObservationalMemory = class _ObservationalMemory {
|
|
1291
1302
|
id = "observational-memory";
|
|
1292
1303
|
name = "Observational Memory";
|
|
@@ -1874,6 +1885,16 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
1874
1885
|
const effectiveThreshold = Math.max(totalBudget - currentObservationTokens, baseThreshold);
|
|
1875
1886
|
return Math.round(effectiveThreshold);
|
|
1876
1887
|
}
|
|
1888
|
+
/**
|
|
1889
|
+
* Check whether the unobserved message tokens meet the observation threshold.
|
|
1890
|
+
*/
|
|
1891
|
+
meetsObservationThreshold(opts) {
|
|
1892
|
+
const { record, unobservedTokens, extraTokens = 0 } = opts;
|
|
1893
|
+
const pendingTokens = (record.pendingMessageTokens ?? 0) + unobservedTokens + extraTokens;
|
|
1894
|
+
const currentObservationTokens = record.observationTokenCount ?? 0;
|
|
1895
|
+
const threshold = this.calculateDynamicThreshold(this.observationConfig.messageTokens, currentObservationTokens);
|
|
1896
|
+
return pendingTokens >= threshold;
|
|
1897
|
+
}
|
|
1877
1898
|
/**
|
|
1878
1899
|
* Get or create the Observer agent
|
|
1879
1900
|
*/
|
|
@@ -1920,7 +1941,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
1920
1941
|
};
|
|
1921
1942
|
}
|
|
1922
1943
|
/**
|
|
1923
|
-
* Get or create the observational memory record
|
|
1944
|
+
* Get or create the observational memory record.
|
|
1945
|
+
* Returns the existing record if one exists, otherwise initializes a new one.
|
|
1924
1946
|
*/
|
|
1925
1947
|
async getOrCreateRecord(threadId, resourceId) {
|
|
1926
1948
|
const ids = this.getStorageIds(threadId, resourceId);
|
|
@@ -2589,17 +2611,13 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
2589
2611
|
optimized = addRelativeTimeToObservations(optimized, currentDate);
|
|
2590
2612
|
}
|
|
2591
2613
|
let content = `
|
|
2592
|
-
|
|
2614
|
+
${OBSERVATION_CONTEXT_PROMPT}
|
|
2593
2615
|
|
|
2594
2616
|
<observations>
|
|
2595
2617
|
${optimized}
|
|
2596
2618
|
</observations>
|
|
2597
2619
|
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
KNOWLEDGE UPDATES: When asked about current state (e.g., "where do I currently...", "what is my current..."), always prefer the MOST RECENT information. Observations include dates - if you see conflicting information, the newer observation supersedes the older one. Look for phrases like "will start", "is switching", "changed to", "moved to" as indicators that previous information has been updated.
|
|
2601
|
-
|
|
2602
|
-
PLANNED ACTIONS: If the user stated they planned to do something (e.g., "I'm going to...", "I'm looking forward to...", "I will...") and the date they planned to do it is now in the past (check the relative time like "3 weeks ago"), assume they completed the action unless there's evidence they didn't. For example, if someone said "I'll start my new diet on Monday" and that was 2 weeks ago, assume they started the diet.`;
|
|
2620
|
+
${OBSERVATION_CONTEXT_INSTRUCTIONS}`;
|
|
2603
2621
|
if (unobservedContextBlocks) {
|
|
2604
2622
|
content += `
|
|
2605
2623
|
|
|
@@ -2863,16 +2881,22 @@ ${suggestedResponse}
|
|
|
2863
2881
|
if (freshUnobservedMessages.length > 0) {
|
|
2864
2882
|
try {
|
|
2865
2883
|
if (this.scope === "resource" && resourceId) {
|
|
2866
|
-
await this.doResourceScopedObservation(
|
|
2867
|
-
freshRecord,
|
|
2868
|
-
threadId,
|
|
2884
|
+
await this.doResourceScopedObservation({
|
|
2885
|
+
record: freshRecord,
|
|
2886
|
+
currentThreadId: threadId,
|
|
2869
2887
|
resourceId,
|
|
2870
|
-
freshUnobservedMessages,
|
|
2888
|
+
currentThreadMessages: freshUnobservedMessages,
|
|
2871
2889
|
writer,
|
|
2872
2890
|
abortSignal
|
|
2873
|
-
);
|
|
2891
|
+
});
|
|
2874
2892
|
} else {
|
|
2875
|
-
await this.doSynchronousObservation(
|
|
2893
|
+
await this.doSynchronousObservation({
|
|
2894
|
+
record: freshRecord,
|
|
2895
|
+
threadId,
|
|
2896
|
+
unobservedMessages: freshUnobservedMessages,
|
|
2897
|
+
writer,
|
|
2898
|
+
abortSignal
|
|
2899
|
+
});
|
|
2876
2900
|
}
|
|
2877
2901
|
updatedRecord = await this.getOrCreateRecord(threadId, resourceId);
|
|
2878
2902
|
const updatedTime = updatedRecord.lastObservedAt?.getTime() ?? 0;
|
|
@@ -3012,12 +3036,7 @@ ${suggestedResponse}
|
|
|
3012
3036
|
parts: [
|
|
3013
3037
|
{
|
|
3014
3038
|
type: "text",
|
|
3015
|
-
text: `<system-reminder
|
|
3016
|
-
|
|
3017
|
-
IMPORTANT: this system reminder is NOT from the user. The system placed it here as part of your memory system. This message is part of you remembering your conversation with the user.
|
|
3018
|
-
|
|
3019
|
-
NOTE: Any messages following this system reminder are newer than your memories.
|
|
3020
|
-
</system-reminder>`
|
|
3039
|
+
text: `<system-reminder>${OBSERVATION_CONTINUATION_HINT}</system-reminder>`
|
|
3021
3040
|
}
|
|
3022
3041
|
]
|
|
3023
3042
|
},
|
|
@@ -3174,14 +3193,13 @@ NOTE: Any messages following this system reminder are newer than your memories.
|
|
|
3174
3193
|
_ObservationalMemory.lastBufferedBoundary.set(bufKey, 0);
|
|
3175
3194
|
this.storage.setBufferingObservationFlag(record.id, false, 0).catch(() => {
|
|
3176
3195
|
});
|
|
3177
|
-
await this.maybeReflect(
|
|
3196
|
+
await this.maybeReflect({
|
|
3178
3197
|
record,
|
|
3179
|
-
record.observationTokenCount ?? 0,
|
|
3198
|
+
observationTokens: record.observationTokenCount ?? 0,
|
|
3180
3199
|
threadId,
|
|
3181
3200
|
writer,
|
|
3182
|
-
void 0,
|
|
3183
3201
|
messageList
|
|
3184
|
-
);
|
|
3202
|
+
});
|
|
3185
3203
|
record = await this.getOrCreateRecord(threadId, resourceId);
|
|
3186
3204
|
}
|
|
3187
3205
|
}
|
|
@@ -3191,7 +3209,7 @@ NOTE: Any messages following this system reminder are newer than your memories.
|
|
|
3191
3209
|
const obsTokens = record.observationTokenCount ?? 0;
|
|
3192
3210
|
if (this.shouldReflect(obsTokens)) {
|
|
3193
3211
|
omDebug(`[OM:step0-reflect] obsTokens=${obsTokens} over reflectThreshold, triggering reflection`);
|
|
3194
|
-
await this.maybeReflect(record, obsTokens, threadId, writer,
|
|
3212
|
+
await this.maybeReflect({ record, observationTokens: obsTokens, threadId, writer, messageList });
|
|
3195
3213
|
record = await this.getOrCreateRecord(threadId, resourceId);
|
|
3196
3214
|
} else if (this.isAsyncReflectionEnabled()) {
|
|
3197
3215
|
const lockKey = this.getLockKey(threadId, resourceId);
|
|
@@ -3531,21 +3549,35 @@ ${newThreadSection}`;
|
|
|
3531
3549
|
}
|
|
3532
3550
|
const newThreadId = threadIdMatch[1];
|
|
3533
3551
|
const newDate = dateMatch[1];
|
|
3534
|
-
const
|
|
3535
|
-
|
|
3536
|
-
);
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3552
|
+
const threadOpen = `<thread id="${newThreadId}">`;
|
|
3553
|
+
const threadClose = "</thread>";
|
|
3554
|
+
const startIdx = existingObservations.indexOf(threadOpen);
|
|
3555
|
+
let existingSection = null;
|
|
3556
|
+
let existingSectionStart = -1;
|
|
3557
|
+
let existingSectionEnd = -1;
|
|
3558
|
+
if (startIdx !== -1) {
|
|
3559
|
+
const closeIdx = existingObservations.indexOf(threadClose, startIdx);
|
|
3560
|
+
if (closeIdx !== -1) {
|
|
3561
|
+
existingSectionEnd = closeIdx + threadClose.length;
|
|
3562
|
+
existingSectionStart = startIdx;
|
|
3563
|
+
const section = existingObservations.slice(startIdx, existingSectionEnd);
|
|
3564
|
+
if (section.includes(`Date: ${newDate}`) || section.includes(`Date:${newDate}`)) {
|
|
3565
|
+
existingSection = section;
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
if (existingSection) {
|
|
3570
|
+
const dateLineEnd = newThreadSection.indexOf("\n", newThreadSection.indexOf("Date:"));
|
|
3571
|
+
const newCloseIdx = newThreadSection.lastIndexOf(threadClose);
|
|
3572
|
+
if (dateLineEnd !== -1 && newCloseIdx !== -1) {
|
|
3573
|
+
const newObsContent = newThreadSection.slice(dateLineEnd + 1, newCloseIdx).trim();
|
|
3574
|
+
if (newObsContent) {
|
|
3575
|
+
const withoutClose = existingSection.slice(0, existingSection.length - threadClose.length).trimEnd();
|
|
3576
|
+
const merged = `${withoutClose}
|
|
3545
3577
|
${newObsContent}
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3578
|
+
${threadClose}`;
|
|
3579
|
+
return existingObservations.slice(0, existingSectionStart) + merged + existingObservations.slice(existingSectionEnd);
|
|
3580
|
+
}
|
|
3549
3581
|
}
|
|
3550
3582
|
}
|
|
3551
3583
|
return `${existingObservations}
|
|
@@ -3569,7 +3601,8 @@ ${newThreadSection}`;
|
|
|
3569
3601
|
/**
|
|
3570
3602
|
* Do synchronous observation (fallback when no buffering)
|
|
3571
3603
|
*/
|
|
3572
|
-
async doSynchronousObservation(
|
|
3604
|
+
async doSynchronousObservation(opts) {
|
|
3605
|
+
const { record, threadId, unobservedMessages, writer, abortSignal, reflectionHooks } = opts;
|
|
3573
3606
|
this.emitDebugEvent({
|
|
3574
3607
|
type: "observation_triggered",
|
|
3575
3608
|
timestamp: /* @__PURE__ */ new Date(),
|
|
@@ -3694,13 +3727,14 @@ ${result.observations}` : result.observations;
|
|
|
3694
3727
|
})),
|
|
3695
3728
|
usage: result.usage
|
|
3696
3729
|
});
|
|
3697
|
-
await this.maybeReflect(
|
|
3698
|
-
{ ...record, activeObservations: newObservations },
|
|
3699
|
-
totalTokenCount,
|
|
3730
|
+
await this.maybeReflect({
|
|
3731
|
+
record: { ...record, activeObservations: newObservations },
|
|
3732
|
+
observationTokens: totalTokenCount,
|
|
3700
3733
|
threadId,
|
|
3701
3734
|
writer,
|
|
3702
|
-
abortSignal
|
|
3703
|
-
|
|
3735
|
+
abortSignal,
|
|
3736
|
+
reflectionHooks
|
|
3737
|
+
});
|
|
3704
3738
|
} catch (error) {
|
|
3705
3739
|
if (lastMessage?.id) {
|
|
3706
3740
|
const failedMarker = this.createObservationFailedMarker({
|
|
@@ -4243,7 +4277,8 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4243
4277
|
* 3. Only updates lastObservedAt AFTER all threads are observed
|
|
4244
4278
|
* 4. Only triggers reflection AFTER all threads are observed
|
|
4245
4279
|
*/
|
|
4246
|
-
async doResourceScopedObservation(
|
|
4280
|
+
async doResourceScopedObservation(opts) {
|
|
4281
|
+
const { record, currentThreadId, resourceId, currentThreadMessages, writer, abortSignal, reflectionHooks } = opts;
|
|
4247
4282
|
const { threads: allThreads } = await this.storage.listThreads({ filter: { resourceId } });
|
|
4248
4283
|
const threadMetadataMap = /* @__PURE__ */ new Map();
|
|
4249
4284
|
for (const thread of allThreads) {
|
|
@@ -4505,13 +4540,14 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4505
4540
|
}
|
|
4506
4541
|
}
|
|
4507
4542
|
}
|
|
4508
|
-
await this.maybeReflect(
|
|
4509
|
-
{ ...record, activeObservations: currentObservations },
|
|
4510
|
-
totalTokenCount,
|
|
4511
|
-
currentThreadId,
|
|
4543
|
+
await this.maybeReflect({
|
|
4544
|
+
record: { ...record, activeObservations: currentObservations },
|
|
4545
|
+
observationTokens: totalTokenCount,
|
|
4546
|
+
threadId: currentThreadId,
|
|
4512
4547
|
writer,
|
|
4513
|
-
abortSignal
|
|
4514
|
-
|
|
4548
|
+
abortSignal,
|
|
4549
|
+
reflectionHooks
|
|
4550
|
+
});
|
|
4515
4551
|
} catch (error) {
|
|
4516
4552
|
for (const [threadId, msgs] of threadsWithMessages) {
|
|
4517
4553
|
const lastMessage = msgs[msgs.length - 1];
|
|
@@ -4582,7 +4618,8 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4582
4618
|
* When async buffering is enabled via `bufferTokens`, reflection is triggered
|
|
4583
4619
|
* in the background at intervals, and activated when the threshold is reached.
|
|
4584
4620
|
*/
|
|
4585
|
-
async maybeReflect(
|
|
4621
|
+
async maybeReflect(opts) {
|
|
4622
|
+
const { record, observationTokens, writer, abortSignal, messageList, reflectionHooks } = opts;
|
|
4586
4623
|
const lockKey = this.getLockKey(record.threadId, record.resourceId);
|
|
4587
4624
|
const reflectThreshold = this.getMaxThreshold(this.reflectionConfig.observationTokens);
|
|
4588
4625
|
if (this.isAsyncReflectionEnabled() && observationTokens < reflectThreshold) {
|
|
@@ -4618,11 +4655,12 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4618
4655
|
return;
|
|
4619
4656
|
}
|
|
4620
4657
|
}
|
|
4658
|
+
reflectionHooks?.onReflectionStart?.();
|
|
4621
4659
|
await this.storage.setReflectingFlag(record.id, true);
|
|
4622
4660
|
registerOp(record.id, "reflecting");
|
|
4623
4661
|
const cycleId = crypto.randomUUID();
|
|
4624
4662
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
4625
|
-
const threadId =
|
|
4663
|
+
const threadId = opts.threadId ?? "unknown";
|
|
4626
4664
|
if (writer) {
|
|
4627
4665
|
const startMarker = this.createObservationStartMarker({
|
|
4628
4666
|
cycleId,
|
|
@@ -4708,26 +4746,45 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4708
4746
|
omError("[OM] Reflection failed", error);
|
|
4709
4747
|
} finally {
|
|
4710
4748
|
await this.storage.setReflectingFlag(record.id, false);
|
|
4749
|
+
reflectionHooks?.onReflectionEnd?.();
|
|
4711
4750
|
unregisterOp(record.id, "reflecting");
|
|
4712
4751
|
}
|
|
4713
4752
|
}
|
|
4714
4753
|
/**
|
|
4715
4754
|
* Manually trigger observation.
|
|
4755
|
+
*
|
|
4756
|
+
* When `messages` is provided, those are used directly (filtered for unobserved)
|
|
4757
|
+
* instead of reading from storage. This allows external systems (e.g., opencode)
|
|
4758
|
+
* to pass conversation messages without duplicating them into Mastra's DB.
|
|
4716
4759
|
*/
|
|
4717
|
-
async observe(
|
|
4760
|
+
async observe(opts) {
|
|
4761
|
+
const { threadId, resourceId, messages, hooks } = opts;
|
|
4718
4762
|
const lockKey = this.getLockKey(threadId, resourceId);
|
|
4763
|
+
const reflectionHooks = hooks ? { onReflectionStart: hooks.onReflectionStart, onReflectionEnd: hooks.onReflectionEnd } : void 0;
|
|
4719
4764
|
await this.withLock(lockKey, async () => {
|
|
4720
4765
|
const freshRecord = await this.getOrCreateRecord(threadId, resourceId);
|
|
4721
4766
|
if (this.scope === "resource" && resourceId) {
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4767
|
+
const currentMessages = messages ?? [];
|
|
4768
|
+
if (!this.meetsObservationThreshold({
|
|
4769
|
+
record: freshRecord,
|
|
4770
|
+
unobservedTokens: this.tokenCounter.countMessages(currentMessages)
|
|
4771
|
+
})) {
|
|
4772
|
+
return;
|
|
4773
|
+
}
|
|
4774
|
+
hooks?.onObservationStart?.();
|
|
4775
|
+
try {
|
|
4776
|
+
await this.doResourceScopedObservation({
|
|
4777
|
+
record: freshRecord,
|
|
4778
|
+
currentThreadId: threadId,
|
|
4779
|
+
resourceId,
|
|
4780
|
+
currentThreadMessages: currentMessages,
|
|
4781
|
+
reflectionHooks
|
|
4782
|
+
});
|
|
4783
|
+
} finally {
|
|
4784
|
+
hooks?.onObservationEnd?.();
|
|
4785
|
+
}
|
|
4729
4786
|
} else {
|
|
4730
|
-
const unobservedMessages = await this.loadUnobservedMessages(
|
|
4787
|
+
const unobservedMessages = messages ? this.getUnobservedMessages(messages, freshRecord) : await this.loadUnobservedMessages(
|
|
4731
4788
|
threadId,
|
|
4732
4789
|
resourceId,
|
|
4733
4790
|
freshRecord.lastObservedAt ? new Date(freshRecord.lastObservedAt) : void 0
|
|
@@ -4735,7 +4792,18 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4735
4792
|
if (unobservedMessages.length === 0) {
|
|
4736
4793
|
return;
|
|
4737
4794
|
}
|
|
4738
|
-
|
|
4795
|
+
if (!this.meetsObservationThreshold({
|
|
4796
|
+
record: freshRecord,
|
|
4797
|
+
unobservedTokens: this.tokenCounter.countMessages(unobservedMessages)
|
|
4798
|
+
})) {
|
|
4799
|
+
return;
|
|
4800
|
+
}
|
|
4801
|
+
hooks?.onObservationStart?.();
|
|
4802
|
+
try {
|
|
4803
|
+
await this.doSynchronousObservation({ record: freshRecord, threadId, unobservedMessages, reflectionHooks });
|
|
4804
|
+
} finally {
|
|
4805
|
+
hooks?.onObservationEnd?.();
|
|
4806
|
+
}
|
|
4739
4807
|
}
|
|
4740
4808
|
});
|
|
4741
4809
|
}
|
|
@@ -4828,6 +4896,9 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4828
4896
|
};
|
|
4829
4897
|
|
|
4830
4898
|
exports.OBSERVATIONAL_MEMORY_DEFAULTS = OBSERVATIONAL_MEMORY_DEFAULTS;
|
|
4899
|
+
exports.OBSERVATION_CONTEXT_INSTRUCTIONS = OBSERVATION_CONTEXT_INSTRUCTIONS;
|
|
4900
|
+
exports.OBSERVATION_CONTEXT_PROMPT = OBSERVATION_CONTEXT_PROMPT;
|
|
4901
|
+
exports.OBSERVATION_CONTINUATION_HINT = OBSERVATION_CONTINUATION_HINT;
|
|
4831
4902
|
exports.OBSERVER_SYSTEM_PROMPT = OBSERVER_SYSTEM_PROMPT;
|
|
4832
4903
|
exports.ObservationalMemory = ObservationalMemory;
|
|
4833
4904
|
exports.TokenCounter = TokenCounter;
|
|
@@ -4838,5 +4909,5 @@ exports.formatMessagesForObserver = formatMessagesForObserver;
|
|
|
4838
4909
|
exports.hasCurrentTaskSection = hasCurrentTaskSection;
|
|
4839
4910
|
exports.optimizeObservationsForContext = optimizeObservationsForContext;
|
|
4840
4911
|
exports.parseObserverOutput = parseObserverOutput;
|
|
4841
|
-
//# sourceMappingURL=chunk-
|
|
4842
|
-
//# sourceMappingURL=chunk-
|
|
4912
|
+
//# sourceMappingURL=chunk-LXATBJ2L.cjs.map
|
|
4913
|
+
//# sourceMappingURL=chunk-LXATBJ2L.cjs.map
|