@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.
Files changed (30) hide show
  1. package/dist/docs/SKILL.md +1 -1
  2. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  3. package/dist/docs/references/reference-memory-observational-memory.md +2 -0
  4. package/dist/index.cjs +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/processors/index.cjs +1 -1
  7. package/dist/processors/index.js +1 -1
  8. package/dist/processors/observational-memory/markers.d.ts +2 -0
  9. package/dist/processors/observational-memory/markers.d.ts.map +1 -1
  10. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
  11. package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
  12. package/dist/processors/observational-memory/observer-agent.d.ts +5 -12
  13. package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -1
  14. package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
  15. package/dist/processors/observational-memory/reflector-agent.d.ts.map +1 -1
  16. package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
  17. package/dist/processors/observational-memory/retry.d.ts +23 -0
  18. package/dist/processors/observational-memory/retry.d.ts.map +1 -1
  19. package/dist/processors/observational-memory/temporary-memory.d.ts +5 -1
  20. package/dist/processors/observational-memory/temporary-memory.d.ts.map +1 -1
  21. package/dist/processors/observational-memory/tool-result-helpers.d.ts.map +1 -1
  22. package/dist/processors/observational-memory/types.d.ts +2 -0
  23. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  24. package/dist/{src-BBl5Qedz.cjs → src-DwfyRK9Q.cjs} +173 -84
  25. package/dist/src-DwfyRK9Q.cjs.map +1 -0
  26. package/dist/{src-BQOm4kZc.js → src-yhShj4JX.js} +173 -84
  27. package/dist/src-yhShj4JX.js.map +1 -0
  28. package/package.json +5 -5
  29. package/dist/src-BBl5Qedz.cjs.map +0 -1
  30. package/dist/src-BQOm4kZc.js.map +0 -1
@@ -18784,8 +18784,38 @@ const TRANSIENT_MESSAGE_SUBSTRINGS = [
18784
18784
  "request timed out",
18785
18785
  "request timeout",
18786
18786
  "connection reset",
18787
- "connection closed"
18787
+ "connection closed",
18788
+ "finished with finishreason \"other\""
18788
18789
  ];
18790
+ const INCOMPLETE_FINISH_REASONS = /* @__PURE__ */ new Set(["other", "unknown"]);
18791
+ /**
18792
+ * A model reply that ended before the model finished. Carries the AI SDK's
18793
+ * `isRetryable` flag, which `isTransientLLMError` and core's error processors
18794
+ * already recognize.
18795
+ *
18796
+ * @internal
18797
+ */
18798
+ var OmIncompleteResponseError = class extends Error {
18799
+ finishReason;
18800
+ isRetryable = true;
18801
+ constructor(label, finishReason) {
18802
+ super(`${label} response ended early (finishReason: ${finishReason})`);
18803
+ this.finishReason = finishReason;
18804
+ this.name = "OmIncompleteResponseError";
18805
+ }
18806
+ };
18807
+ /**
18808
+ * OM calls are single-step (`maxSteps: 1`). A step that ends with `other` or
18809
+ * `unknown` means the stream closed before the model finished, so its text is
18810
+ * partial. Throw a retryable error so `withRetry` re-runs the whole call
18811
+ * instead of saving it.
18812
+ *
18813
+ * @internal
18814
+ */
18815
+ function assertCompleteModelResponse(output, label) {
18816
+ if (output.finishReason && INCOMPLETE_FINISH_REASONS.has(output.finishReason)) throw new OmIncompleteResponseError(label, output.finishReason);
18817
+ return output;
18818
+ }
18789
18819
  function isRecord$5(value) {
18790
18820
  return typeof value === "object" && value !== null;
18791
18821
  }
@@ -20022,8 +20052,9 @@ function stringifyToolResult(value) {
20022
20052
  }
20023
20053
  function resolveToolResultValue(part, invocationResult) {
20024
20054
  const mastraMetadata = part?.providerMetadata?.mastra;
20025
- if (mastraMetadata && typeof mastraMetadata === "object" && "modelOutput" in mastraMetadata) return {
20026
- value: mastraMetadata.modelOutput,
20055
+ const modelOutput = mastraMetadata && typeof mastraMetadata === "object" ? mastraMetadata.modelOutput : void 0;
20056
+ if (modelOutput != null) return {
20057
+ value: modelOutput,
20027
20058
  usingStoredModelOutput: true
20028
20059
  };
20029
20060
  return {
@@ -21066,7 +21097,7 @@ function buildMultiThreadObserverContextPrompt(existingObservations, threadOrder
21066
21097
  */
21067
21098
  function parseMultiThreadObserverOutput(output, extractors = []) {
21068
21099
  const threads = /* @__PURE__ */ new Map();
21069
- if (detectDegenerateRepetition(output)) return {
21100
+ if (detectDegenerateRepetition(sanitizeObservationLines(output))) return {
21070
21101
  threads,
21071
21102
  rawOutput: output,
21072
21103
  degenerate: true
@@ -21172,7 +21203,7 @@ function getStringExtractedValue$1(values, slug) {
21172
21203
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
21173
21204
  }
21174
21205
  function parseObserverOutput(output, extractors = []) {
21175
- if (detectDegenerateRepetition(output)) return {
21206
+ if (detectDegenerateRepetition(sanitizeObservationLines(output))) return {
21176
21207
  observations: "",
21177
21208
  rawOutput: output,
21178
21209
  degenerate: true
@@ -21235,6 +21266,34 @@ const MAX_OBSERVATION_LINE_CHARS = 1e4;
21235
21266
  */
21236
21267
  const MIN_DUPLICATE_LINE_CHARS = 24;
21237
21268
  /**
21269
+ * Collapse a run of back-to-back identical lines to a single line when that
21270
+ * run is the line's only occurrence and is no bigger than one maximum-length
21271
+ * observation line. A faithful summary of a repetitive tool loop (e.g. 30×
21272
+ * "pnpm --filter … build → ok") produces exactly that shape at any line
21273
+ * length. Loops are left intact: a model stuck on one line runs far past the
21274
+ * size bound, and a line that keeps recurring between other lines has more
21275
+ * than one run.
21276
+ */
21277
+ function collapseBoundedLineRuns(lines) {
21278
+ const runs = [];
21279
+ for (const line of lines) {
21280
+ const last = runs[runs.length - 1];
21281
+ if (last && last.line === line) last.count++;
21282
+ else runs.push({
21283
+ line,
21284
+ count: 1
21285
+ });
21286
+ }
21287
+ const runsPerLine = /* @__PURE__ */ new Map();
21288
+ for (const run of runs) runsPerLine.set(run.line, (runsPerLine.get(run.line) ?? 0) + 1);
21289
+ const result = [];
21290
+ for (const run of runs) {
21291
+ const collapse = runsPerLine.get(run.line) === 1 && run.count * (run.line.length + 1) <= MAX_OBSERVATION_LINE_CHARS;
21292
+ for (let j = 0; j < (collapse ? 1 : run.count); j++) result.push(run.line);
21293
+ }
21294
+ return result;
21295
+ }
21296
+ /**
21238
21297
  * Truncate individual observation lines that exceed the maximum length.
21239
21298
  */
21240
21299
  function sanitizeObservationLines(observations) {
@@ -21247,31 +21306,28 @@ function sanitizeObservationLines(observations) {
21247
21306
  }
21248
21307
  return changed ? lines.join("\n") : observations;
21249
21308
  }
21250
- /**
21251
- * Detect degenerate repetition in observer/reflector output.
21252
- * Returns true if the text contains suspicious levels of repeated content,
21253
- * which indicates an LLM repeat-penalty bug (e.g., Gemini Flash looping).
21254
- *
21255
- * Strategy: sample sequential chunks of the text and check if a high
21256
- * proportion are near-identical to previous chunks.
21257
- */
21258
- function detectDegenerateRepetition(text) {
21259
- if (!text || text.length < 2e3) return false;
21309
+ function analyzeDegenerateRepetition(text) {
21310
+ const lines = collapseBoundedLineRuns(text.split("\n"));
21311
+ const windowText = lines.filter((line) => line.trim().length >= MIN_DUPLICATE_LINE_CHARS && line.length <= MAX_OBSERVATION_LINE_CHARS).join("\n");
21260
21312
  const windowSize = 200;
21261
- const step = Math.max(1, Math.floor(text.length / 50));
21313
+ const step = Math.max(1, Math.floor(windowText.length / 50));
21262
21314
  const seen = /* @__PURE__ */ new Map();
21263
21315
  let duplicateWindows = 0;
21264
21316
  let totalWindows = 0;
21265
- for (let i = 0; i + windowSize <= text.length; i += step) {
21266
- const window = text.slice(i, i + windowSize);
21317
+ let topWindow = "";
21318
+ let topWindowCount = 0;
21319
+ for (let i = 0; i + windowSize <= windowText.length; i += step) {
21320
+ const window = windowText.slice(i, i + windowSize);
21267
21321
  totalWindows++;
21268
21322
  const count = (seen.get(window) ?? 0) + 1;
21269
21323
  seen.set(window, count);
21270
21324
  if (count > 1) duplicateWindows++;
21325
+ if (count > topWindowCount) {
21326
+ topWindowCount = count;
21327
+ topWindow = window;
21328
+ }
21271
21329
  }
21272
- if (totalWindows > 5 && duplicateWindows / totalWindows > .4) return true;
21273
- const lines = text.split("\n");
21274
- for (const line of lines) if (line.length > 5e4) return true;
21330
+ const windowFired = windowText.length >= 2e3 && totalWindows > 5 && duplicateWindows / totalWindows > .4;
21275
21331
  const seenLines = /* @__PURE__ */ new Map();
21276
21332
  let duplicateLines = 0;
21277
21333
  let totalCountedLines = 0;
@@ -21283,8 +21339,50 @@ function detectDegenerateRepetition(text) {
21283
21339
  seenLines.set(trimmed, count);
21284
21340
  if (count > 1) duplicateLines++;
21285
21341
  }
21286
- if (totalCountedLines >= 20 && duplicateLines / totalCountedLines > .5) return true;
21287
- return false;
21342
+ const lineFired = totalCountedLines >= 20 && duplicateLines / totalCountedLines > .5;
21343
+ let shortLineFired = false;
21344
+ let shortLineCounts = /* @__PURE__ */ new Map();
21345
+ const runExceedsBudget = () => {
21346
+ let repeatedShortChars = 0;
21347
+ for (const { count, chars } of shortLineCounts.values()) if (count > 1) repeatedShortChars += chars;
21348
+ return repeatedShortChars - 1 > MAX_OBSERVATION_LINE_CHARS;
21349
+ };
21350
+ for (const line of lines) {
21351
+ const trimmed = line.trim();
21352
+ if (!trimmed) continue;
21353
+ if (trimmed.length >= MIN_DUPLICATE_LINE_CHARS) {
21354
+ if (runExceedsBudget()) shortLineFired = true;
21355
+ shortLineCounts = /* @__PURE__ */ new Map();
21356
+ continue;
21357
+ }
21358
+ if (/^<\/?[A-Za-z][\w-]*(?:\s[^<>]*)?>$/.test(trimmed) || trimmed.startsWith("Date:")) continue;
21359
+ const entry = shortLineCounts.get(trimmed) ?? {
21360
+ count: 0,
21361
+ chars: 0
21362
+ };
21363
+ entry.count++;
21364
+ entry.chars += line.length + 1;
21365
+ shortLineCounts.set(trimmed, entry);
21366
+ }
21367
+ if (runExceedsBudget()) shortLineFired = true;
21368
+ const eligible = text.length >= 2e3;
21369
+ return {
21370
+ windowText,
21371
+ totalWindows,
21372
+ duplicateWindows,
21373
+ topWindow,
21374
+ topWindowCount,
21375
+ totalCountedLines,
21376
+ duplicateLines,
21377
+ windowFired: eligible && windowFired,
21378
+ lineFired: eligible && lineFired,
21379
+ shortLineFired: eligible && shortLineFired
21380
+ };
21381
+ }
21382
+ function detectDegenerateRepetition(text) {
21383
+ if (!text || text.length < 2e3) return false;
21384
+ const analysis = analyzeDegenerateRepetition(text);
21385
+ return analysis.windowFired || analysis.lineFired || analysis.shortLineFired;
21288
21386
  }
21289
21387
  /**
21290
21388
  * Build a single-line diagnostic description of output flagged by
@@ -21293,55 +21391,35 @@ function detectDegenerateRepetition(text) {
21293
21391
  * without it there is no way to tell a real repetition loop apart from a
21294
21392
  * detector false-positive on legitimately repetitive content.
21295
21393
  *
21296
- * Reuses the detector's sampling parameters (200-char windows, ~50 samples)
21297
- * so the reported duplicate ratio and most-repeated window match what
21298
- * triggered the detection. Snippets are JSON-escaped so the result stays on
21299
- * one line.
21394
+ * Runs the detector's analysis on the same sanitized text the detector judges
21395
+ * (giant lines truncated), so `strategy=` names what triggered the rejection.
21396
+ * For a short-line loop the window and line ratios read n/a or low, because
21397
+ * short lines are excluded from both. `length` and `longestLine` describe the
21398
+ * raw output. Snippets are JSON-escaped so the result stays on one line.
21300
21399
  */
21301
21400
  function describeDegenerateOutput(text, snippetChars = 400) {
21302
- const windowSize = 200;
21303
- const step = Math.max(1, Math.floor(text.length / 50));
21304
- const seen = /* @__PURE__ */ new Map();
21305
- let duplicateWindows = 0;
21306
- let totalWindows = 0;
21307
- for (let i = 0; i + windowSize <= text.length; i += step) {
21308
- const window = text.slice(i, i + windowSize);
21309
- totalWindows++;
21310
- const count = (seen.get(window) ?? 0) + 1;
21311
- seen.set(window, count);
21312
- if (count > 1) duplicateWindows++;
21313
- }
21314
- let topWindow = "";
21315
- let topCount = 0;
21316
- for (const [window, count] of seen) if (count > topCount) {
21317
- topCount = count;
21318
- topWindow = window;
21319
- }
21401
+ const a = analyzeDegenerateRepetition(sanitizeObservationLines(text));
21320
21402
  let longestLine = 0;
21321
- const seenLines = /* @__PURE__ */ new Map();
21322
- let duplicateLines = 0;
21323
- let totalCountedLines = 0;
21324
- for (const line of text.split("\n")) {
21325
- if (line.length > longestLine) longestLine = line.length;
21326
- const trimmed = line.trim();
21327
- if (trimmed.length < MIN_DUPLICATE_LINE_CHARS) continue;
21328
- totalCountedLines++;
21329
- const count = (seenLines.get(trimmed) ?? 0) + 1;
21330
- seenLines.set(trimmed, count);
21331
- if (count > 1) duplicateLines++;
21332
- }
21333
- const duplicateRatio = totalWindows > 0 ? (duplicateWindows / totalWindows).toFixed(2) : "n/a";
21334
- const duplicateLineRatio = totalCountedLines > 0 ? (duplicateLines / totalCountedLines).toFixed(2) : "n/a";
21403
+ for (const line of text.split("\n")) if (line.length > longestLine) longestLine = line.length;
21404
+ const fired = [
21405
+ a.windowFired && "window",
21406
+ a.lineFired && "duplicateLines",
21407
+ a.shortLineFired && "shortLineLoop"
21408
+ ].filter(Boolean).join("+") || "none";
21409
+ const duplicateRatio = a.totalWindows > 0 ? (a.duplicateWindows / a.totalWindows).toFixed(2) : "n/a";
21410
+ const duplicateLineRatio = a.totalCountedLines > 0 ? (a.duplicateLines / a.totalCountedLines).toFixed(2) : "n/a";
21335
21411
  const parts = [
21412
+ `strategy=${fired}`,
21336
21413
  `length=${text.length}`,
21337
- `sampledWindows=${totalWindows}`,
21414
+ `windowTextLength=${a.windowText.length}`,
21415
+ `sampledWindows=${a.totalWindows}`,
21338
21416
  `duplicateRatio=${duplicateRatio}`,
21339
21417
  `duplicateLineRatio=${duplicateLineRatio}`,
21340
- `countedLines=${totalCountedLines}`,
21418
+ `countedLines=${a.totalCountedLines}`,
21341
21419
  `longestLine=${longestLine}`,
21342
- `topWindowCount=${topCount}`
21420
+ `topWindowCount=${a.topWindowCount}`
21343
21421
  ];
21344
- if (topCount > 1) parts.push(`topWindow=${JSON.stringify(topWindow)}`);
21422
+ if (a.topWindowCount > 1) parts.push(`topWindow=${JSON.stringify(a.topWindow)}`);
21345
21423
  parts.push(`head=${JSON.stringify(text.slice(0, snippetChars))}`);
21346
21424
  if (text.length > snippetChars * 2) parts.push(`tail=${JSON.stringify(text.slice(-snippetChars))}`);
21347
21425
  return parts.join(" ");
@@ -21396,20 +21474,20 @@ function optimizeObservationsForContext(observations) {
21396
21474
  //#endregion
21397
21475
  //#region src/processors/observational-memory/temporary-memory.ts
21398
21476
  function createTemporaryOmMemoryContext(prefix) {
21399
- const options = {
21400
- thread: `${prefix}-${globalThis.crypto.randomUUID()}`,
21401
- resource: prefix,
21402
- options: {
21403
- lastMessages: 10,
21404
- generateTitle: false
21405
- }
21477
+ const memoryOptions = {
21478
+ lastMessages: 10,
21479
+ generateTitle: false
21406
21480
  };
21407
21481
  return {
21408
21482
  memory: new Memory({
21409
21483
  storage: new InMemoryStore(),
21410
- options: options.options
21484
+ options: memoryOptions
21411
21485
  }),
21412
- options
21486
+ newThread: () => ({
21487
+ thread: `${prefix}-${globalThis.crypto.randomUUID()}`,
21488
+ resource: prefix,
21489
+ options: memoryOptions
21490
+ })
21413
21491
  };
21414
21492
  }
21415
21493
  //#endregion
@@ -21554,6 +21632,7 @@ var ObserverRunner = class {
21554
21632
  id: isMultiThread ? "multi-thread-observer" : "observational-memory-observer",
21555
21633
  name: isMultiThread ? "multi-thread-observer" : "Observer",
21556
21634
  maxRetries: 0,
21635
+ errorProcessorDefaults: false,
21557
21636
  instructions: buildObserverSystemPrompt(isMultiThread, this.observationConfig.instruction, this.observationConfig.threadTitle, extractors),
21558
21637
  model: agentModel,
21559
21638
  ...memory ? { memory } : {},
@@ -21642,6 +21721,7 @@ var ObserverRunner = class {
21642
21721
  const temporaryMemory = activeExtractors.filter((extractor) => extractor.mode === "structured").length > 0 ? await createTemporaryOmMemoryContext("structured-observer") : void 0;
21643
21722
  const agent = temporaryMemory ? this.createAgent(resolvedModel.model, false, temporaryMemory.memory, activeExtractors) : this.createAgent(resolvedModel.model, false, void 0, activeExtractors);
21644
21723
  const internalRequestContext = withOmInternalThreadId(options?.requestContext, agent.id);
21724
+ let attemptMemory;
21645
21725
  const attachmentFilter = this.resolveAttachmentFilter(resolvedModel.model, options?.requestContext);
21646
21726
  const observerMessages = [buildObserverRequestMessage(existingObservations, messagesToObserve, {
21647
21727
  ...options,
@@ -21669,14 +21749,16 @@ var ObserverRunner = class {
21669
21749
  },
21670
21750
  callback: (childObservabilityContext) => this.withAbortCheck(async () => {
21671
21751
  try {
21672
- return await (await agent.stream(observerMessages, {
21752
+ attemptMemory = temporaryMemory?.newThread();
21753
+ return assertCompleteModelResponse(await (await agent.stream(observerMessages, {
21754
+ maxSteps: 1,
21673
21755
  modelSettings: { ...this.observationConfig.modelSettings },
21674
21756
  providerOptions: this.observationConfig.providerOptions,
21675
- ...temporaryMemory ? { memory: temporaryMemory.options } : {},
21757
+ ...attemptMemory ? { memory: attemptMemory } : {},
21676
21758
  ...abortSignal ? { abortSignal } : {},
21677
21759
  ...internalRequestContext ? { requestContext: internalRequestContext } : {},
21678
21760
  ...childObservabilityContext
21679
- })).getFullOutput();
21761
+ })).getFullOutput(), "OM observer");
21680
21762
  } catch (error) {
21681
21763
  this.mastra?.getLogger?.().error("OM observer provider call failed", {
21682
21764
  diagnostic: formatOmError(error),
@@ -21715,7 +21797,7 @@ var ObserverRunner = class {
21715
21797
  agent,
21716
21798
  source: "observer",
21717
21799
  extractors: activeExtractors,
21718
- memory: temporaryMemory?.options,
21800
+ memory: attemptMemory,
21719
21801
  priorExtractedValues: options?.priorExtractedValues,
21720
21802
  requestContext: internalRequestContext,
21721
21803
  observabilityContext: options?.observabilityContext,
@@ -21875,13 +21957,14 @@ var ObserverRunner = class {
21875
21957
  },
21876
21958
  callback: (childObservabilityContext) => this.withAbortCheck(async () => {
21877
21959
  try {
21878
- return await (await agent.stream(observerMessages, {
21960
+ return assertCompleteModelResponse(await (await agent.stream(observerMessages, {
21961
+ maxSteps: 1,
21879
21962
  modelSettings: { ...this.observationConfig.modelSettings },
21880
21963
  providerOptions: this.observationConfig.providerOptions,
21881
21964
  ...abortSignal ? { abortSignal } : {},
21882
21965
  ...internalRequestContext ? { requestContext: internalRequestContext } : {},
21883
21966
  ...childObservabilityContext
21884
- })).getFullOutput();
21967
+ })).getFullOutput(), "OM multi-thread observer");
21885
21968
  } catch (error) {
21886
21969
  this.mastra?.getLogger?.().error("OM multi-thread observer provider call failed", {
21887
21970
  diagnostic: formatOmError(error),
@@ -26396,6 +26479,7 @@ function createObservationFailedMarker(params) {
26396
26479
  tokensAttempted: params.tokensAttempted,
26397
26480
  error: formatOmError(params.error),
26398
26481
  ...getOmFailureMetadata(params.error, params.failurePolicy ?? "abort"),
26482
+ ...params.retrying ? { retrying: true } : {},
26399
26483
  recordId: params.recordId,
26400
26484
  threadId: params.threadId
26401
26485
  }
@@ -28692,7 +28776,7 @@ function getStringExtractedValue(values, slug) {
28692
28776
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
28693
28777
  }
28694
28778
  function parseReflectorOutput(output, sourceObservations, extractors = []) {
28695
- if (detectDegenerateRepetition(output)) return {
28779
+ if (detectDegenerateRepetition(sanitizeObservationLines(output))) return {
28696
28780
  observations: "",
28697
28781
  degenerate: true
28698
28782
  };
@@ -28885,6 +28969,7 @@ var ReflectorRunner = class {
28885
28969
  instructions: buildReflectorSystemPrompt(this.reflectionConfig.instruction, extractors),
28886
28970
  model: agentModel,
28887
28971
  maxRetries: 0,
28972
+ errorProcessorDefaults: false,
28888
28973
  ...memory ? { memory } : {},
28889
28974
  ...this.mastra ? { mastra: this.mastra } : {}
28890
28975
  });
@@ -28925,6 +29010,7 @@ var ReflectorRunner = class {
28925
29010
  const temporaryMemory = activeExtractors.filter((extractor) => extractor.mode === "structured").length > 0 ? await createTemporaryOmMemoryContext("structured-reflector") : void 0;
28926
29011
  const agent = temporaryMemory ? this.createAgent(resolvedModel.model, temporaryMemory.memory, activeExtractors) : this.createAgent(resolvedModel.model, void 0, activeExtractors);
28927
29012
  const internalRequestContext = withOmInternalThreadId(requestContext, agent.id);
29013
+ let attemptMemory;
28928
29014
  const targetThreshold = observationTokensThreshold ?? getMaxThreshold(this.reflectionConfig.observationTokens);
28929
29015
  let totalUsage = {
28930
29016
  inputTokens: 0,
@@ -28967,10 +29053,12 @@ var ReflectorRunner = class {
28967
29053
  callback: (childObservabilityContext) => withAbortCheck(async () => {
28968
29054
  chunkCount = 0;
28969
29055
  try {
28970
- return await (await agent.stream(prompt, {
29056
+ attemptMemory = temporaryMemory?.newThread();
29057
+ return assertCompleteModelResponse(await (await agent.stream(prompt, {
29058
+ maxSteps: 1,
28971
29059
  modelSettings: { ...this.reflectionConfig.modelSettings },
28972
29060
  providerOptions: this.reflectionConfig.providerOptions,
28973
- ...temporaryMemory ? { memory: temporaryMemory.options } : {},
29061
+ ...attemptMemory ? { memory: attemptMemory } : {},
28974
29062
  ...abortSignal ? { abortSignal } : {},
28975
29063
  ...internalRequestContext ? { requestContext: internalRequestContext } : {},
28976
29064
  ...childObservabilityContext,
@@ -28992,7 +29080,7 @@ var ReflectorRunner = class {
28992
29080
  omError(`[OM:callReflector] onError after ${chunkCount} chunks`, error);
28993
29081
  }
28994
29082
  } : {}
28995
- })).getFullOutput();
29083
+ })).getFullOutput(), "OM reflector");
28996
29084
  } catch (error) {
28997
29085
  if (abortSignal?.aborted || !isOmModelExecutionFailure(error)) throw error;
28998
29086
  throw new OmModelExecutionError("reflector-model", error);
@@ -29033,6 +29121,7 @@ var ReflectorRunner = class {
29033
29121
  startedAt: streamContext.startedAt,
29034
29122
  tokensAttempted: originalTokens,
29035
29123
  error: `Did not compress below threshold (${originalTokens} → ${reflectedTokens}, target: ${targetThreshold}), retrying at level ${currentLevel + 1}`,
29124
+ retrying: true,
29036
29125
  recordId: streamContext.recordId,
29037
29126
  threadId: streamContext.threadId
29038
29127
  });
@@ -29066,7 +29155,7 @@ var ReflectorRunner = class {
29066
29155
  agent,
29067
29156
  source: "reflector",
29068
29157
  extractors: activeExtractors,
29069
- memory: temporaryMemory?.options,
29158
+ memory: attemptMemory,
29070
29159
  priorExtractedValues,
29071
29160
  requestContext: internalRequestContext,
29072
29161
  observabilityContext,
@@ -35297,4 +35386,4 @@ Notes:
35297
35386
  //#endregion
35298
35387
  export { formatMessagesForObserver as A, OBSERVATION_CONTEXT_PROMPT_THREAD as B, SUMMARIZE_THREAD_DEFAULTS as C, buildObserverPrompt as D, OBSERVER_SYSTEM_PROMPT as E, parseAnchorId as F, StaleKnowledgeSemanticIndexError as G, getObservationContextPrompt as H, stripEphemeralAnchorIds as I, SUBCONSCIOUS_ACTIVITY_STATE_ID as J, SubconsciousRemindExtractor as K, OBSERVATIONAL_MEMORY_DEFAULTS as L, optimizeObservationsForContext as M, parseObserverOutput as N, buildObserverSystemPrompt as O, injectAnchorIds as P, Extractor as Q, OBSERVATION_CONTEXT_INSTRUCTIONS as R, deepMergeWorkingMemory as S, TokenCounter as T, Subconscious as U, OBSERVATION_CONTINUATION_HINT as V, KnowledgeSemanticIndexCoordinator as W, publishSubconsciousActivity as X, buildSubconsciousActivitySnapshot as Y, renderSubconsciousActivity as Z, reconcileObservationGroupsFromReflection as _, extractWorkingMemoryContent as a, wrapInObservationGroup as b, getObservationsAsOf as c, WORKING_MEMORY_STATE_ID as d, WORKING_MEMORY_STATE_PROCESSOR_ID as f, parseObservationGroups as g, deriveObservationGroupProvenance as h, WorkingMemory as i, hasCurrentTaskSection as j, extractCurrentTask as k, ObservationalMemoryProcessor as l, combineObservationGroupRanges as m, MessageHistory$1 as n, extractWorkingMemoryTags as o, WorkingMemoryStateProcessor as p, ModelByInputTokens as q, SemanticRecall as r, removeWorkingMemoryTags as s, Memory as t, ObservationalMemory as u, renderObservationGroupsForReflection as v, summarizeConversation as w, WorkingMemoryExtractor as x, stripObservationGroups as y, OBSERVATION_CONTEXT_PROMPT as z };
35299
35388
 
35300
- //# sourceMappingURL=src-BQOm4kZc.js.map
35389
+ //# sourceMappingURL=src-yhShj4JX.js.map