@mastra/memory 1.36.0-alpha.3 → 1.36.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-memory-observational-memory.md +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/processors/index.cjs +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/markers.d.ts +2 -0
- package/dist/processors/observational-memory/markers.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
- package/dist/processors/observational-memory/observer-agent.d.ts +5 -12
- package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -1
- package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/reflector-agent.d.ts.map +1 -1
- package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/retry.d.ts +23 -0
- package/dist/processors/observational-memory/retry.d.ts.map +1 -1
- package/dist/processors/observational-memory/temporary-memory.d.ts +5 -1
- package/dist/processors/observational-memory/temporary-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/tool-result-helpers.d.ts.map +1 -1
- package/dist/processors/observational-memory/types.d.ts +2 -0
- package/dist/processors/observational-memory/types.d.ts.map +1 -1
- package/dist/{src-BBl5Qedz.cjs → src-DwfyRK9Q.cjs} +173 -84
- package/dist/src-DwfyRK9Q.cjs.map +1 -0
- package/dist/{src-BQOm4kZc.js → src-yhShj4JX.js} +173 -84
- package/dist/src-yhShj4JX.js.map +1 -0
- package/package.json +5 -5
- package/dist/src-BBl5Qedz.cjs.map +0 -1
- package/dist/src-BQOm4kZc.js.map +0 -1
|
@@ -18805,8 +18805,38 @@ const TRANSIENT_MESSAGE_SUBSTRINGS = [
|
|
|
18805
18805
|
"request timed out",
|
|
18806
18806
|
"request timeout",
|
|
18807
18807
|
"connection reset",
|
|
18808
|
-
"connection closed"
|
|
18808
|
+
"connection closed",
|
|
18809
|
+
"finished with finishreason \"other\""
|
|
18809
18810
|
];
|
|
18811
|
+
const INCOMPLETE_FINISH_REASONS = /* @__PURE__ */ new Set(["other", "unknown"]);
|
|
18812
|
+
/**
|
|
18813
|
+
* A model reply that ended before the model finished. Carries the AI SDK's
|
|
18814
|
+
* `isRetryable` flag, which `isTransientLLMError` and core's error processors
|
|
18815
|
+
* already recognize.
|
|
18816
|
+
*
|
|
18817
|
+
* @internal
|
|
18818
|
+
*/
|
|
18819
|
+
var OmIncompleteResponseError = class extends Error {
|
|
18820
|
+
finishReason;
|
|
18821
|
+
isRetryable = true;
|
|
18822
|
+
constructor(label, finishReason) {
|
|
18823
|
+
super(`${label} response ended early (finishReason: ${finishReason})`);
|
|
18824
|
+
this.finishReason = finishReason;
|
|
18825
|
+
this.name = "OmIncompleteResponseError";
|
|
18826
|
+
}
|
|
18827
|
+
};
|
|
18828
|
+
/**
|
|
18829
|
+
* OM calls are single-step (`maxSteps: 1`). A step that ends with `other` or
|
|
18830
|
+
* `unknown` means the stream closed before the model finished, so its text is
|
|
18831
|
+
* partial. Throw a retryable error so `withRetry` re-runs the whole call
|
|
18832
|
+
* instead of saving it.
|
|
18833
|
+
*
|
|
18834
|
+
* @internal
|
|
18835
|
+
*/
|
|
18836
|
+
function assertCompleteModelResponse(output, label) {
|
|
18837
|
+
if (output.finishReason && INCOMPLETE_FINISH_REASONS.has(output.finishReason)) throw new OmIncompleteResponseError(label, output.finishReason);
|
|
18838
|
+
return output;
|
|
18839
|
+
}
|
|
18810
18840
|
function isRecord$5(value) {
|
|
18811
18841
|
return typeof value === "object" && value !== null;
|
|
18812
18842
|
}
|
|
@@ -20043,8 +20073,9 @@ function stringifyToolResult(value) {
|
|
|
20043
20073
|
}
|
|
20044
20074
|
function resolveToolResultValue(part, invocationResult) {
|
|
20045
20075
|
const mastraMetadata = part?.providerMetadata?.mastra;
|
|
20046
|
-
|
|
20047
|
-
|
|
20076
|
+
const modelOutput = mastraMetadata && typeof mastraMetadata === "object" ? mastraMetadata.modelOutput : void 0;
|
|
20077
|
+
if (modelOutput != null) return {
|
|
20078
|
+
value: modelOutput,
|
|
20048
20079
|
usingStoredModelOutput: true
|
|
20049
20080
|
};
|
|
20050
20081
|
return {
|
|
@@ -21087,7 +21118,7 @@ function buildMultiThreadObserverContextPrompt(existingObservations, threadOrder
|
|
|
21087
21118
|
*/
|
|
21088
21119
|
function parseMultiThreadObserverOutput(output, extractors = []) {
|
|
21089
21120
|
const threads = /* @__PURE__ */ new Map();
|
|
21090
|
-
if (detectDegenerateRepetition(output)) return {
|
|
21121
|
+
if (detectDegenerateRepetition(sanitizeObservationLines(output))) return {
|
|
21091
21122
|
threads,
|
|
21092
21123
|
rawOutput: output,
|
|
21093
21124
|
degenerate: true
|
|
@@ -21193,7 +21224,7 @@ function getStringExtractedValue$1(values, slug) {
|
|
|
21193
21224
|
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
21194
21225
|
}
|
|
21195
21226
|
function parseObserverOutput(output, extractors = []) {
|
|
21196
|
-
if (detectDegenerateRepetition(output)) return {
|
|
21227
|
+
if (detectDegenerateRepetition(sanitizeObservationLines(output))) return {
|
|
21197
21228
|
observations: "",
|
|
21198
21229
|
rawOutput: output,
|
|
21199
21230
|
degenerate: true
|
|
@@ -21256,6 +21287,34 @@ const MAX_OBSERVATION_LINE_CHARS = 1e4;
|
|
|
21256
21287
|
*/
|
|
21257
21288
|
const MIN_DUPLICATE_LINE_CHARS = 24;
|
|
21258
21289
|
/**
|
|
21290
|
+
* Collapse a run of back-to-back identical lines to a single line when that
|
|
21291
|
+
* run is the line's only occurrence and is no bigger than one maximum-length
|
|
21292
|
+
* observation line. A faithful summary of a repetitive tool loop (e.g. 30×
|
|
21293
|
+
* "pnpm --filter … build → ok") produces exactly that shape at any line
|
|
21294
|
+
* length. Loops are left intact: a model stuck on one line runs far past the
|
|
21295
|
+
* size bound, and a line that keeps recurring between other lines has more
|
|
21296
|
+
* than one run.
|
|
21297
|
+
*/
|
|
21298
|
+
function collapseBoundedLineRuns(lines) {
|
|
21299
|
+
const runs = [];
|
|
21300
|
+
for (const line of lines) {
|
|
21301
|
+
const last = runs[runs.length - 1];
|
|
21302
|
+
if (last && last.line === line) last.count++;
|
|
21303
|
+
else runs.push({
|
|
21304
|
+
line,
|
|
21305
|
+
count: 1
|
|
21306
|
+
});
|
|
21307
|
+
}
|
|
21308
|
+
const runsPerLine = /* @__PURE__ */ new Map();
|
|
21309
|
+
for (const run of runs) runsPerLine.set(run.line, (runsPerLine.get(run.line) ?? 0) + 1);
|
|
21310
|
+
const result = [];
|
|
21311
|
+
for (const run of runs) {
|
|
21312
|
+
const collapse = runsPerLine.get(run.line) === 1 && run.count * (run.line.length + 1) <= MAX_OBSERVATION_LINE_CHARS;
|
|
21313
|
+
for (let j = 0; j < (collapse ? 1 : run.count); j++) result.push(run.line);
|
|
21314
|
+
}
|
|
21315
|
+
return result;
|
|
21316
|
+
}
|
|
21317
|
+
/**
|
|
21259
21318
|
* Truncate individual observation lines that exceed the maximum length.
|
|
21260
21319
|
*/
|
|
21261
21320
|
function sanitizeObservationLines(observations) {
|
|
@@ -21268,31 +21327,28 @@ function sanitizeObservationLines(observations) {
|
|
|
21268
21327
|
}
|
|
21269
21328
|
return changed ? lines.join("\n") : observations;
|
|
21270
21329
|
}
|
|
21271
|
-
|
|
21272
|
-
|
|
21273
|
-
|
|
21274
|
-
* which indicates an LLM repeat-penalty bug (e.g., Gemini Flash looping).
|
|
21275
|
-
*
|
|
21276
|
-
* Strategy: sample sequential chunks of the text and check if a high
|
|
21277
|
-
* proportion are near-identical to previous chunks.
|
|
21278
|
-
*/
|
|
21279
|
-
function detectDegenerateRepetition(text) {
|
|
21280
|
-
if (!text || text.length < 2e3) return false;
|
|
21330
|
+
function analyzeDegenerateRepetition(text) {
|
|
21331
|
+
const lines = collapseBoundedLineRuns(text.split("\n"));
|
|
21332
|
+
const windowText = lines.filter((line) => line.trim().length >= MIN_DUPLICATE_LINE_CHARS && line.length <= MAX_OBSERVATION_LINE_CHARS).join("\n");
|
|
21281
21333
|
const windowSize = 200;
|
|
21282
|
-
const step = Math.max(1, Math.floor(
|
|
21334
|
+
const step = Math.max(1, Math.floor(windowText.length / 50));
|
|
21283
21335
|
const seen = /* @__PURE__ */ new Map();
|
|
21284
21336
|
let duplicateWindows = 0;
|
|
21285
21337
|
let totalWindows = 0;
|
|
21286
|
-
|
|
21287
|
-
|
|
21338
|
+
let topWindow = "";
|
|
21339
|
+
let topWindowCount = 0;
|
|
21340
|
+
for (let i = 0; i + windowSize <= windowText.length; i += step) {
|
|
21341
|
+
const window = windowText.slice(i, i + windowSize);
|
|
21288
21342
|
totalWindows++;
|
|
21289
21343
|
const count = (seen.get(window) ?? 0) + 1;
|
|
21290
21344
|
seen.set(window, count);
|
|
21291
21345
|
if (count > 1) duplicateWindows++;
|
|
21346
|
+
if (count > topWindowCount) {
|
|
21347
|
+
topWindowCount = count;
|
|
21348
|
+
topWindow = window;
|
|
21349
|
+
}
|
|
21292
21350
|
}
|
|
21293
|
-
|
|
21294
|
-
const lines = text.split("\n");
|
|
21295
|
-
for (const line of lines) if (line.length > 5e4) return true;
|
|
21351
|
+
const windowFired = windowText.length >= 2e3 && totalWindows > 5 && duplicateWindows / totalWindows > .4;
|
|
21296
21352
|
const seenLines = /* @__PURE__ */ new Map();
|
|
21297
21353
|
let duplicateLines = 0;
|
|
21298
21354
|
let totalCountedLines = 0;
|
|
@@ -21304,8 +21360,50 @@ function detectDegenerateRepetition(text) {
|
|
|
21304
21360
|
seenLines.set(trimmed, count);
|
|
21305
21361
|
if (count > 1) duplicateLines++;
|
|
21306
21362
|
}
|
|
21307
|
-
|
|
21308
|
-
|
|
21363
|
+
const lineFired = totalCountedLines >= 20 && duplicateLines / totalCountedLines > .5;
|
|
21364
|
+
let shortLineFired = false;
|
|
21365
|
+
let shortLineCounts = /* @__PURE__ */ new Map();
|
|
21366
|
+
const runExceedsBudget = () => {
|
|
21367
|
+
let repeatedShortChars = 0;
|
|
21368
|
+
for (const { count, chars } of shortLineCounts.values()) if (count > 1) repeatedShortChars += chars;
|
|
21369
|
+
return repeatedShortChars - 1 > MAX_OBSERVATION_LINE_CHARS;
|
|
21370
|
+
};
|
|
21371
|
+
for (const line of lines) {
|
|
21372
|
+
const trimmed = line.trim();
|
|
21373
|
+
if (!trimmed) continue;
|
|
21374
|
+
if (trimmed.length >= MIN_DUPLICATE_LINE_CHARS) {
|
|
21375
|
+
if (runExceedsBudget()) shortLineFired = true;
|
|
21376
|
+
shortLineCounts = /* @__PURE__ */ new Map();
|
|
21377
|
+
continue;
|
|
21378
|
+
}
|
|
21379
|
+
if (/^<\/?[A-Za-z][\w-]*(?:\s[^<>]*)?>$/.test(trimmed) || trimmed.startsWith("Date:")) continue;
|
|
21380
|
+
const entry = shortLineCounts.get(trimmed) ?? {
|
|
21381
|
+
count: 0,
|
|
21382
|
+
chars: 0
|
|
21383
|
+
};
|
|
21384
|
+
entry.count++;
|
|
21385
|
+
entry.chars += line.length + 1;
|
|
21386
|
+
shortLineCounts.set(trimmed, entry);
|
|
21387
|
+
}
|
|
21388
|
+
if (runExceedsBudget()) shortLineFired = true;
|
|
21389
|
+
const eligible = text.length >= 2e3;
|
|
21390
|
+
return {
|
|
21391
|
+
windowText,
|
|
21392
|
+
totalWindows,
|
|
21393
|
+
duplicateWindows,
|
|
21394
|
+
topWindow,
|
|
21395
|
+
topWindowCount,
|
|
21396
|
+
totalCountedLines,
|
|
21397
|
+
duplicateLines,
|
|
21398
|
+
windowFired: eligible && windowFired,
|
|
21399
|
+
lineFired: eligible && lineFired,
|
|
21400
|
+
shortLineFired: eligible && shortLineFired
|
|
21401
|
+
};
|
|
21402
|
+
}
|
|
21403
|
+
function detectDegenerateRepetition(text) {
|
|
21404
|
+
if (!text || text.length < 2e3) return false;
|
|
21405
|
+
const analysis = analyzeDegenerateRepetition(text);
|
|
21406
|
+
return analysis.windowFired || analysis.lineFired || analysis.shortLineFired;
|
|
21309
21407
|
}
|
|
21310
21408
|
/**
|
|
21311
21409
|
* Build a single-line diagnostic description of output flagged by
|
|
@@ -21314,55 +21412,35 @@ function detectDegenerateRepetition(text) {
|
|
|
21314
21412
|
* without it there is no way to tell a real repetition loop apart from a
|
|
21315
21413
|
* detector false-positive on legitimately repetitive content.
|
|
21316
21414
|
*
|
|
21317
|
-
*
|
|
21318
|
-
*
|
|
21319
|
-
*
|
|
21320
|
-
*
|
|
21415
|
+
* Runs the detector's analysis on the same sanitized text the detector judges
|
|
21416
|
+
* (giant lines truncated), so `strategy=` names what triggered the rejection.
|
|
21417
|
+
* For a short-line loop the window and line ratios read n/a or low, because
|
|
21418
|
+
* short lines are excluded from both. `length` and `longestLine` describe the
|
|
21419
|
+
* raw output. Snippets are JSON-escaped so the result stays on one line.
|
|
21321
21420
|
*/
|
|
21322
21421
|
function describeDegenerateOutput(text, snippetChars = 400) {
|
|
21323
|
-
const
|
|
21324
|
-
const step = Math.max(1, Math.floor(text.length / 50));
|
|
21325
|
-
const seen = /* @__PURE__ */ new Map();
|
|
21326
|
-
let duplicateWindows = 0;
|
|
21327
|
-
let totalWindows = 0;
|
|
21328
|
-
for (let i = 0; i + windowSize <= text.length; i += step) {
|
|
21329
|
-
const window = text.slice(i, i + windowSize);
|
|
21330
|
-
totalWindows++;
|
|
21331
|
-
const count = (seen.get(window) ?? 0) + 1;
|
|
21332
|
-
seen.set(window, count);
|
|
21333
|
-
if (count > 1) duplicateWindows++;
|
|
21334
|
-
}
|
|
21335
|
-
let topWindow = "";
|
|
21336
|
-
let topCount = 0;
|
|
21337
|
-
for (const [window, count] of seen) if (count > topCount) {
|
|
21338
|
-
topCount = count;
|
|
21339
|
-
topWindow = window;
|
|
21340
|
-
}
|
|
21422
|
+
const a = analyzeDegenerateRepetition(sanitizeObservationLines(text));
|
|
21341
21423
|
let longestLine = 0;
|
|
21342
|
-
const
|
|
21343
|
-
|
|
21344
|
-
|
|
21345
|
-
|
|
21346
|
-
|
|
21347
|
-
|
|
21348
|
-
|
|
21349
|
-
|
|
21350
|
-
const count = (seenLines.get(trimmed) ?? 0) + 1;
|
|
21351
|
-
seenLines.set(trimmed, count);
|
|
21352
|
-
if (count > 1) duplicateLines++;
|
|
21353
|
-
}
|
|
21354
|
-
const duplicateRatio = totalWindows > 0 ? (duplicateWindows / totalWindows).toFixed(2) : "n/a";
|
|
21355
|
-
const duplicateLineRatio = totalCountedLines > 0 ? (duplicateLines / totalCountedLines).toFixed(2) : "n/a";
|
|
21424
|
+
for (const line of text.split("\n")) if (line.length > longestLine) longestLine = line.length;
|
|
21425
|
+
const fired = [
|
|
21426
|
+
a.windowFired && "window",
|
|
21427
|
+
a.lineFired && "duplicateLines",
|
|
21428
|
+
a.shortLineFired && "shortLineLoop"
|
|
21429
|
+
].filter(Boolean).join("+") || "none";
|
|
21430
|
+
const duplicateRatio = a.totalWindows > 0 ? (a.duplicateWindows / a.totalWindows).toFixed(2) : "n/a";
|
|
21431
|
+
const duplicateLineRatio = a.totalCountedLines > 0 ? (a.duplicateLines / a.totalCountedLines).toFixed(2) : "n/a";
|
|
21356
21432
|
const parts = [
|
|
21433
|
+
`strategy=${fired}`,
|
|
21357
21434
|
`length=${text.length}`,
|
|
21358
|
-
`
|
|
21435
|
+
`windowTextLength=${a.windowText.length}`,
|
|
21436
|
+
`sampledWindows=${a.totalWindows}`,
|
|
21359
21437
|
`duplicateRatio=${duplicateRatio}`,
|
|
21360
21438
|
`duplicateLineRatio=${duplicateLineRatio}`,
|
|
21361
|
-
`countedLines=${totalCountedLines}`,
|
|
21439
|
+
`countedLines=${a.totalCountedLines}`,
|
|
21362
21440
|
`longestLine=${longestLine}`,
|
|
21363
|
-
`topWindowCount=${
|
|
21441
|
+
`topWindowCount=${a.topWindowCount}`
|
|
21364
21442
|
];
|
|
21365
|
-
if (
|
|
21443
|
+
if (a.topWindowCount > 1) parts.push(`topWindow=${JSON.stringify(a.topWindow)}`);
|
|
21366
21444
|
parts.push(`head=${JSON.stringify(text.slice(0, snippetChars))}`);
|
|
21367
21445
|
if (text.length > snippetChars * 2) parts.push(`tail=${JSON.stringify(text.slice(-snippetChars))}`);
|
|
21368
21446
|
return parts.join(" ");
|
|
@@ -21417,20 +21495,20 @@ function optimizeObservationsForContext(observations) {
|
|
|
21417
21495
|
//#endregion
|
|
21418
21496
|
//#region src/processors/observational-memory/temporary-memory.ts
|
|
21419
21497
|
function createTemporaryOmMemoryContext(prefix) {
|
|
21420
|
-
const
|
|
21421
|
-
|
|
21422
|
-
|
|
21423
|
-
options: {
|
|
21424
|
-
lastMessages: 10,
|
|
21425
|
-
generateTitle: false
|
|
21426
|
-
}
|
|
21498
|
+
const memoryOptions = {
|
|
21499
|
+
lastMessages: 10,
|
|
21500
|
+
generateTitle: false
|
|
21427
21501
|
};
|
|
21428
21502
|
return {
|
|
21429
21503
|
memory: new Memory({
|
|
21430
21504
|
storage: new _mastra_core_storage.InMemoryStore(),
|
|
21431
|
-
options:
|
|
21505
|
+
options: memoryOptions
|
|
21432
21506
|
}),
|
|
21433
|
-
|
|
21507
|
+
newThread: () => ({
|
|
21508
|
+
thread: `${prefix}-${globalThis.crypto.randomUUID()}`,
|
|
21509
|
+
resource: prefix,
|
|
21510
|
+
options: memoryOptions
|
|
21511
|
+
})
|
|
21434
21512
|
};
|
|
21435
21513
|
}
|
|
21436
21514
|
//#endregion
|
|
@@ -21575,6 +21653,7 @@ var ObserverRunner = class {
|
|
|
21575
21653
|
id: isMultiThread ? "multi-thread-observer" : "observational-memory-observer",
|
|
21576
21654
|
name: isMultiThread ? "multi-thread-observer" : "Observer",
|
|
21577
21655
|
maxRetries: 0,
|
|
21656
|
+
errorProcessorDefaults: false,
|
|
21578
21657
|
instructions: buildObserverSystemPrompt(isMultiThread, this.observationConfig.instruction, this.observationConfig.threadTitle, extractors),
|
|
21579
21658
|
model: agentModel,
|
|
21580
21659
|
...memory ? { memory } : {},
|
|
@@ -21663,6 +21742,7 @@ var ObserverRunner = class {
|
|
|
21663
21742
|
const temporaryMemory = activeExtractors.filter((extractor) => extractor.mode === "structured").length > 0 ? await createTemporaryOmMemoryContext("structured-observer") : void 0;
|
|
21664
21743
|
const agent = temporaryMemory ? this.createAgent(resolvedModel.model, false, temporaryMemory.memory, activeExtractors) : this.createAgent(resolvedModel.model, false, void 0, activeExtractors);
|
|
21665
21744
|
const internalRequestContext = withOmInternalThreadId(options?.requestContext, agent.id);
|
|
21745
|
+
let attemptMemory;
|
|
21666
21746
|
const attachmentFilter = this.resolveAttachmentFilter(resolvedModel.model, options?.requestContext);
|
|
21667
21747
|
const observerMessages = [buildObserverRequestMessage(existingObservations, messagesToObserve, {
|
|
21668
21748
|
...options,
|
|
@@ -21690,14 +21770,16 @@ var ObserverRunner = class {
|
|
|
21690
21770
|
},
|
|
21691
21771
|
callback: (childObservabilityContext) => this.withAbortCheck(async () => {
|
|
21692
21772
|
try {
|
|
21693
|
-
|
|
21773
|
+
attemptMemory = temporaryMemory?.newThread();
|
|
21774
|
+
return assertCompleteModelResponse(await (await agent.stream(observerMessages, {
|
|
21775
|
+
maxSteps: 1,
|
|
21694
21776
|
modelSettings: { ...this.observationConfig.modelSettings },
|
|
21695
21777
|
providerOptions: this.observationConfig.providerOptions,
|
|
21696
|
-
...
|
|
21778
|
+
...attemptMemory ? { memory: attemptMemory } : {},
|
|
21697
21779
|
...abortSignal ? { abortSignal } : {},
|
|
21698
21780
|
...internalRequestContext ? { requestContext: internalRequestContext } : {},
|
|
21699
21781
|
...childObservabilityContext
|
|
21700
|
-
})).getFullOutput();
|
|
21782
|
+
})).getFullOutput(), "OM observer");
|
|
21701
21783
|
} catch (error) {
|
|
21702
21784
|
this.mastra?.getLogger?.().error("OM observer provider call failed", {
|
|
21703
21785
|
diagnostic: formatOmError(error),
|
|
@@ -21736,7 +21818,7 @@ var ObserverRunner = class {
|
|
|
21736
21818
|
agent,
|
|
21737
21819
|
source: "observer",
|
|
21738
21820
|
extractors: activeExtractors,
|
|
21739
|
-
memory:
|
|
21821
|
+
memory: attemptMemory,
|
|
21740
21822
|
priorExtractedValues: options?.priorExtractedValues,
|
|
21741
21823
|
requestContext: internalRequestContext,
|
|
21742
21824
|
observabilityContext: options?.observabilityContext,
|
|
@@ -21896,13 +21978,14 @@ var ObserverRunner = class {
|
|
|
21896
21978
|
},
|
|
21897
21979
|
callback: (childObservabilityContext) => this.withAbortCheck(async () => {
|
|
21898
21980
|
try {
|
|
21899
|
-
return await (await agent.stream(observerMessages, {
|
|
21981
|
+
return assertCompleteModelResponse(await (await agent.stream(observerMessages, {
|
|
21982
|
+
maxSteps: 1,
|
|
21900
21983
|
modelSettings: { ...this.observationConfig.modelSettings },
|
|
21901
21984
|
providerOptions: this.observationConfig.providerOptions,
|
|
21902
21985
|
...abortSignal ? { abortSignal } : {},
|
|
21903
21986
|
...internalRequestContext ? { requestContext: internalRequestContext } : {},
|
|
21904
21987
|
...childObservabilityContext
|
|
21905
|
-
})).getFullOutput();
|
|
21988
|
+
})).getFullOutput(), "OM multi-thread observer");
|
|
21906
21989
|
} catch (error) {
|
|
21907
21990
|
this.mastra?.getLogger?.().error("OM multi-thread observer provider call failed", {
|
|
21908
21991
|
diagnostic: formatOmError(error),
|
|
@@ -26417,6 +26500,7 @@ function createObservationFailedMarker(params) {
|
|
|
26417
26500
|
tokensAttempted: params.tokensAttempted,
|
|
26418
26501
|
error: formatOmError(params.error),
|
|
26419
26502
|
...getOmFailureMetadata(params.error, params.failurePolicy ?? "abort"),
|
|
26503
|
+
...params.retrying ? { retrying: true } : {},
|
|
26420
26504
|
recordId: params.recordId,
|
|
26421
26505
|
threadId: params.threadId
|
|
26422
26506
|
}
|
|
@@ -28713,7 +28797,7 @@ function getStringExtractedValue(values, slug) {
|
|
|
28713
28797
|
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
28714
28798
|
}
|
|
28715
28799
|
function parseReflectorOutput(output, sourceObservations, extractors = []) {
|
|
28716
|
-
if (detectDegenerateRepetition(output)) return {
|
|
28800
|
+
if (detectDegenerateRepetition(sanitizeObservationLines(output))) return {
|
|
28717
28801
|
observations: "",
|
|
28718
28802
|
degenerate: true
|
|
28719
28803
|
};
|
|
@@ -28906,6 +28990,7 @@ var ReflectorRunner = class {
|
|
|
28906
28990
|
instructions: buildReflectorSystemPrompt(this.reflectionConfig.instruction, extractors),
|
|
28907
28991
|
model: agentModel,
|
|
28908
28992
|
maxRetries: 0,
|
|
28993
|
+
errorProcessorDefaults: false,
|
|
28909
28994
|
...memory ? { memory } : {},
|
|
28910
28995
|
...this.mastra ? { mastra: this.mastra } : {}
|
|
28911
28996
|
});
|
|
@@ -28946,6 +29031,7 @@ var ReflectorRunner = class {
|
|
|
28946
29031
|
const temporaryMemory = activeExtractors.filter((extractor) => extractor.mode === "structured").length > 0 ? await createTemporaryOmMemoryContext("structured-reflector") : void 0;
|
|
28947
29032
|
const agent = temporaryMemory ? this.createAgent(resolvedModel.model, temporaryMemory.memory, activeExtractors) : this.createAgent(resolvedModel.model, void 0, activeExtractors);
|
|
28948
29033
|
const internalRequestContext = withOmInternalThreadId(requestContext, agent.id);
|
|
29034
|
+
let attemptMemory;
|
|
28949
29035
|
const targetThreshold = observationTokensThreshold ?? getMaxThreshold(this.reflectionConfig.observationTokens);
|
|
28950
29036
|
let totalUsage = {
|
|
28951
29037
|
inputTokens: 0,
|
|
@@ -28988,10 +29074,12 @@ var ReflectorRunner = class {
|
|
|
28988
29074
|
callback: (childObservabilityContext) => withAbortCheck(async () => {
|
|
28989
29075
|
chunkCount = 0;
|
|
28990
29076
|
try {
|
|
28991
|
-
|
|
29077
|
+
attemptMemory = temporaryMemory?.newThread();
|
|
29078
|
+
return assertCompleteModelResponse(await (await agent.stream(prompt, {
|
|
29079
|
+
maxSteps: 1,
|
|
28992
29080
|
modelSettings: { ...this.reflectionConfig.modelSettings },
|
|
28993
29081
|
providerOptions: this.reflectionConfig.providerOptions,
|
|
28994
|
-
...
|
|
29082
|
+
...attemptMemory ? { memory: attemptMemory } : {},
|
|
28995
29083
|
...abortSignal ? { abortSignal } : {},
|
|
28996
29084
|
...internalRequestContext ? { requestContext: internalRequestContext } : {},
|
|
28997
29085
|
...childObservabilityContext,
|
|
@@ -29013,7 +29101,7 @@ var ReflectorRunner = class {
|
|
|
29013
29101
|
omError(`[OM:callReflector] onError after ${chunkCount} chunks`, error);
|
|
29014
29102
|
}
|
|
29015
29103
|
} : {}
|
|
29016
|
-
})).getFullOutput();
|
|
29104
|
+
})).getFullOutput(), "OM reflector");
|
|
29017
29105
|
} catch (error) {
|
|
29018
29106
|
if (abortSignal?.aborted || !isOmModelExecutionFailure(error)) throw error;
|
|
29019
29107
|
throw new OmModelExecutionError("reflector-model", error);
|
|
@@ -29054,6 +29142,7 @@ var ReflectorRunner = class {
|
|
|
29054
29142
|
startedAt: streamContext.startedAt,
|
|
29055
29143
|
tokensAttempted: originalTokens,
|
|
29056
29144
|
error: `Did not compress below threshold (${originalTokens} → ${reflectedTokens}, target: ${targetThreshold}), retrying at level ${currentLevel + 1}`,
|
|
29145
|
+
retrying: true,
|
|
29057
29146
|
recordId: streamContext.recordId,
|
|
29058
29147
|
threadId: streamContext.threadId
|
|
29059
29148
|
});
|
|
@@ -29087,7 +29176,7 @@ var ReflectorRunner = class {
|
|
|
29087
29176
|
agent,
|
|
29088
29177
|
source: "reflector",
|
|
29089
29178
|
extractors: activeExtractors,
|
|
29090
|
-
memory:
|
|
29179
|
+
memory: attemptMemory,
|
|
29091
29180
|
priorExtractedValues,
|
|
29092
29181
|
requestContext: internalRequestContext,
|
|
29093
29182
|
observabilityContext,
|
|
@@ -35611,4 +35700,4 @@ Object.defineProperty(exports, "wrapInObservationGroup", {
|
|
|
35611
35700
|
}
|
|
35612
35701
|
});
|
|
35613
35702
|
|
|
35614
|
-
//# sourceMappingURL=src-
|
|
35703
|
+
//# sourceMappingURL=src-DwfyRK9Q.cjs.map
|