@mastra/memory 1.10.1-alpha.3 → 1.11.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/{chunk-SKRONGCV.js → chunk-D4D6ZFBQ.js} +355 -105
  3. package/dist/chunk-D4D6ZFBQ.js.map +1 -0
  4. package/dist/{chunk-DTAZSLVU.cjs → chunk-VINRPDYQ.cjs} +355 -105
  5. package/dist/chunk-VINRPDYQ.cjs.map +1 -0
  6. package/dist/docs/SKILL.md +1 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +47 -47
  8. package/dist/docs/references/docs-memory-observational-memory.md +49 -4
  9. package/dist/docs/references/reference-memory-observational-memory.md +32 -6
  10. package/dist/index.cjs +577 -36
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.ts +46 -0
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +570 -29
  15. package/dist/index.js.map +1 -1
  16. package/dist/{observational-memory-XIZTJN3S.cjs → observational-memory-FATH657E.cjs} +26 -26
  17. package/dist/{observational-memory-XIZTJN3S.cjs.map → observational-memory-FATH657E.cjs.map} +1 -1
  18. package/dist/{observational-memory-UGDENJPE.js → observational-memory-SN7GKMHZ.js} +3 -3
  19. package/dist/{observational-memory-UGDENJPE.js.map → observational-memory-SN7GKMHZ.js.map} +1 -1
  20. package/dist/processors/index.cjs +24 -24
  21. package/dist/processors/index.js +1 -1
  22. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
  23. package/dist/processors/observational-memory/observation-strategies/base.d.ts +9 -0
  24. package/dist/processors/observational-memory/observation-strategies/base.d.ts.map +1 -1
  25. package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts.map +1 -1
  26. package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
  27. package/dist/processors/observational-memory/observation-strategies/types.d.ts +2 -0
  28. package/dist/processors/observational-memory/observation-strategies/types.d.ts.map +1 -1
  29. package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
  30. package/dist/processors/observational-memory/observation-turn/turn.d.ts +4 -0
  31. package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
  32. package/dist/processors/observational-memory/observational-memory.d.ts +27 -2
  33. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  34. package/dist/processors/observational-memory/observer-runner.d.ts +14 -3
  35. package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
  36. package/dist/processors/observational-memory/processor.d.ts +8 -12
  37. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  38. package/dist/processors/observational-memory/reflector-runner.d.ts +11 -1
  39. package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
  40. package/dist/processors/observational-memory/tracing.d.ts +17 -0
  41. package/dist/processors/observational-memory/tracing.d.ts.map +1 -0
  42. package/dist/processors/observational-memory/types.d.ts +19 -1
  43. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  44. package/dist/tools/om-tools.d.ts +96 -4
  45. package/dist/tools/om-tools.d.ts.map +1 -1
  46. package/package.json +7 -7
  47. package/dist/chunk-DTAZSLVU.cjs.map +0 -1
  48. package/dist/chunk-SKRONGCV.js.map +0 -1
@@ -11,6 +11,7 @@ var path = require('path');
11
11
  var crypto$1 = require('crypto');
12
12
  var tokenx = require('tokenx');
13
13
  var agent = require('@mastra/core/agent');
14
+ var observability = require('@mastra/core/observability');
14
15
  var async_hooks = require('async_hooks');
15
16
  var imageSize = require('image-size');
16
17
  var util = require('util');
@@ -966,7 +967,8 @@ var ObservationStrategy = class _ObservationStrategy {
966
967
  writer,
967
968
  abortSignal,
968
969
  reflectionHooks,
969
- requestContext
970
+ requestContext,
971
+ observabilityContext: this.opts.observabilityContext
970
972
  });
971
973
  }
972
974
  } catch (error) {
@@ -1107,6 +1109,27 @@ ${threadClose}`;
1107
1109
  const boundary = lastObservedAt ? _ObservationStrategy.createMessageBoundary(lastObservedAt) : "\n\n";
1108
1110
  return `${existingObservations}${boundary}${newThreadSection}`;
1109
1111
  }
1112
+ async indexObservationGroups(observations, threadId, resourceId, observedAt) {
1113
+ if (!resourceId || !this.deps.onIndexObservations) {
1114
+ return;
1115
+ }
1116
+ const groups = parseObservationGroups(observations);
1117
+ if (groups.length === 0) {
1118
+ return;
1119
+ }
1120
+ await Promise.all(
1121
+ groups.map(
1122
+ (group) => this.deps.onIndexObservations({
1123
+ text: group.content,
1124
+ groupId: group.id,
1125
+ range: group.range,
1126
+ threadId,
1127
+ resourceId,
1128
+ observedAt
1129
+ })
1130
+ )
1131
+ );
1132
+ }
1110
1133
  // ── Marker persistence ──────────────────────────────────────
1111
1134
  /**
1112
1135
  * Persist a marker to the last assistant message in storage.
@@ -1240,6 +1263,7 @@ var SyncObservationStrategy = class extends ObservationStrategy {
1240
1263
  const omMeta = thread ? memory.getThreadOMMetadata(thread.metadata) : void 0;
1241
1264
  const result = await this.deps.observer.call(existingObservations, messages, this.opts.abortSignal, {
1242
1265
  requestContext: this.opts.requestContext,
1266
+ observabilityContext: this.opts.observabilityContext,
1243
1267
  priorCurrentTask: omMeta?.currentTask,
1244
1268
  priorSuggestedResponse: omMeta?.suggestedResponse,
1245
1269
  priorThreadTitle: omMeta?.threadTitle
@@ -1289,7 +1313,7 @@ var SyncObservationStrategy = class extends ObservationStrategy {
1289
1313
  };
1290
1314
  }
1291
1315
  async persist(processed) {
1292
- const { record, threadId, messages } = this.opts;
1316
+ const { record, threadId, resourceId, messages } = this.opts;
1293
1317
  const thread = await this.storage.getThreadById({ threadId });
1294
1318
  let threadUpdateMarker;
1295
1319
  if (thread) {
@@ -1326,6 +1350,7 @@ var SyncObservationStrategy = class extends ObservationStrategy {
1326
1350
  lastObservedAt: processed.lastObservedAt,
1327
1351
  observedMessageIds: processed.observedMessageIds
1328
1352
  });
1353
+ await this.indexObservationGroups(processed.observations, threadId, resourceId, processed.lastObservedAt);
1329
1354
  }
1330
1355
  async emitEndMarkers(cycleId, processed) {
1331
1356
  const actualTokensObserved = await this.tokenCounter.countMessagesAsync(this.opts.messages);
@@ -1391,7 +1416,8 @@ var AsyncBufferObservationStrategy = class extends ObservationStrategy {
1391
1416
  async observe(existingObservations, messages) {
1392
1417
  return this.deps.observer.call(existingObservations, messages, void 0, {
1393
1418
  skipContinuationHints: true,
1394
- requestContext: this.opts.requestContext
1419
+ requestContext: this.opts.requestContext,
1420
+ observabilityContext: this.opts.observabilityContext
1395
1421
  });
1396
1422
  }
1397
1423
  async process(output, _existingObservations) {
@@ -1430,7 +1456,7 @@ var AsyncBufferObservationStrategy = class extends ObservationStrategy {
1430
1456
  }
1431
1457
  async persist(processed) {
1432
1458
  if (!processed.observations) return;
1433
- const { record, messages } = this.opts;
1459
+ const { record, threadId, resourceId, messages } = this.opts;
1434
1460
  const messageTokens = await this.tokenCounter.countMessagesAsync(messages);
1435
1461
  await this.storage.updateBufferedObservations({
1436
1462
  id: record.id,
@@ -1447,6 +1473,7 @@ var AsyncBufferObservationStrategy = class extends ObservationStrategy {
1447
1473
  },
1448
1474
  lastBufferedAtTime: processed.lastObservedAt
1449
1475
  });
1476
+ await this.indexObservationGroups(processed.observations, threadId, resourceId, processed.lastObservedAt);
1450
1477
  }
1451
1478
  async emitEndMarkers(_cycleId, processed) {
1452
1479
  if (!processed.observations || !this.opts.writer) return;
@@ -1661,7 +1688,8 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
1661
1688
  batch.threadIds,
1662
1689
  this.opts.abortSignal,
1663
1690
  this.opts.requestContext,
1664
- this.priorMetadataByThread
1691
+ this.priorMetadataByThread,
1692
+ this.opts.observabilityContext
1665
1693
  );
1666
1694
  })
1667
1695
  );
@@ -1745,7 +1773,7 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
1745
1773
  };
1746
1774
  }
1747
1775
  async persist(processed) {
1748
- const { record } = this.opts;
1776
+ const { record, resourceId } = this.opts;
1749
1777
  const threadUpdateMarkers = [];
1750
1778
  if (processed.threadMetadataUpdates) {
1751
1779
  for (const update of processed.threadMetadataUpdates) {
@@ -1789,6 +1817,18 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
1789
1817
  lastObservedAt: processed.lastObservedAt,
1790
1818
  observedMessageIds: processed.observedMessageIds
1791
1819
  });
1820
+ if (resourceId) {
1821
+ await Promise.all(
1822
+ this.observationResults.map(
1823
+ ({ threadId, threadMessages, result }) => this.indexObservationGroups(
1824
+ result.observations,
1825
+ threadId,
1826
+ resourceId,
1827
+ this.getMaxMessageTimestamp(threadMessages)
1828
+ )
1829
+ )
1830
+ );
1831
+ }
1792
1832
  }
1793
1833
  async emitEndMarkers(cycleId, processed) {
1794
1834
  for (const obsResult of this.observationResults) {
@@ -1846,6 +1886,7 @@ ObservationStrategy.create = ((om, opts) => {
1846
1886
  reflector: om.reflector,
1847
1887
  observedMessageIds: om.observedMessageIds,
1848
1888
  obscureThreadIds: om.getObscureThreadIds(),
1889
+ onIndexObservations: om.onIndexObservations,
1849
1890
  emitDebugEvent: (e) => om.emitDebugEvent(e)
1850
1891
  };
1851
1892
  if (opts.cycleId) return new AsyncBufferObservationStrategy(deps, opts);
@@ -1914,7 +1955,8 @@ var ObservationStep = class {
1914
1955
  observationTokens: obsTokens,
1915
1956
  threadId,
1916
1957
  writer: this.turn.writer,
1917
- requestContext: this.turn.requestContext
1958
+ requestContext: this.turn.requestContext,
1959
+ observabilityContext: this.turn.observabilityContext
1918
1960
  });
1919
1961
  await this.turn.refreshRecord();
1920
1962
  if (this.turn.record.generationCount > preReflectGeneration) {
@@ -1946,6 +1988,7 @@ var ObservationStep = class {
1946
1988
  record: statusSnapshot.record,
1947
1989
  writer: this.turn.writer,
1948
1990
  requestContext: this.turn.requestContext,
1991
+ observabilityContext: this.turn.observabilityContext,
1949
1992
  beforeBuffer: async (candidates) => {
1950
1993
  if (candidates.length === 0) {
1951
1994
  return;
@@ -2082,7 +2125,8 @@ var ObservationStep = class {
2082
2125
  threadId,
2083
2126
  writer: this.turn.writer,
2084
2127
  messageList,
2085
- requestContext: this.turn.requestContext
2128
+ requestContext: this.turn.requestContext,
2129
+ observabilityContext: this.turn.observabilityContext
2086
2130
  });
2087
2131
  return {
2088
2132
  succeeded: true,
@@ -2096,7 +2140,8 @@ var ObservationStep = class {
2096
2140
  resourceId,
2097
2141
  messages: messageList.get.all.db(),
2098
2142
  requestContext: this.turn.requestContext,
2099
- writer: this.turn.writer
2143
+ writer: this.turn.writer,
2144
+ observabilityContext: this.turn.observabilityContext
2100
2145
  });
2101
2146
  return { succeeded: obsResult.observed, record: obsResult.record };
2102
2147
  }
@@ -2117,6 +2162,8 @@ var ObservationTurn = class {
2117
2162
  writer;
2118
2163
  /** Optional request context for observation calls. */
2119
2164
  requestContext;
2165
+ /** Optional observability context for nested OM spans. */
2166
+ observabilityContext;
2120
2167
  /** Optional processor-provided hooks for turn/step lifecycle integration. */
2121
2168
  hooks;
2122
2169
  constructor(opts) {
@@ -2124,6 +2171,7 @@ var ObservationTurn = class {
2124
2171
  this.threadId = opts.threadId;
2125
2172
  this.resourceId = opts.resourceId;
2126
2173
  this.messageList = opts.messageList;
2174
+ this.observabilityContext = opts.observabilityContext;
2127
2175
  this.hooks = opts.hooks;
2128
2176
  }
2129
2177
  om;
@@ -3368,13 +3416,64 @@ function optimizeObservationsForContext(observations) {
3368
3416
  optimized = optimized.replace(/\n{3,}/g, "\n\n");
3369
3417
  return optimized.trim();
3370
3418
  }
3419
+ var PHASE_CONFIG = {
3420
+ observer: {
3421
+ name: "om.observer",
3422
+ entityName: "Observer"
3423
+ },
3424
+ "observer-multi-thread": {
3425
+ name: "om.observer.multi-thread",
3426
+ entityName: "MultiThreadObserver"
3427
+ },
3428
+ reflector: {
3429
+ name: "om.reflector",
3430
+ entityName: "Reflector"
3431
+ }
3432
+ };
3433
+ async function withOmTracingSpan({
3434
+ phase,
3435
+ model,
3436
+ inputTokens,
3437
+ requestContext,
3438
+ observabilityContext,
3439
+ metadata,
3440
+ callback
3441
+ }) {
3442
+ const config = PHASE_CONFIG[phase];
3443
+ const span = observability.getOrCreateSpan({
3444
+ type: observability.SpanType.GENERIC,
3445
+ name: config.name,
3446
+ entityType: observability.EntityType.OUTPUT_STEP_PROCESSOR,
3447
+ entityName: config.entityName,
3448
+ tracingContext: observabilityContext?.tracingContext ?? observabilityContext?.tracing,
3449
+ attributes: {
3450
+ metadata: {
3451
+ omPhase: phase,
3452
+ omInputTokens: inputTokens,
3453
+ omSelectedModel: typeof model === "string" ? model : "(dynamic-model)",
3454
+ ...metadata
3455
+ }
3456
+ },
3457
+ requestContext
3458
+ });
3459
+ const childObservabilityContext = observability.createObservabilityContext({ currentSpan: span });
3460
+ if (!span) {
3461
+ return callback(childObservabilityContext);
3462
+ }
3463
+ return span.executeInContext(() => callback(childObservabilityContext));
3464
+ }
3465
+
3466
+ // src/processors/observational-memory/observer-runner.ts
3371
3467
  var ObserverRunner = class {
3372
3468
  observationConfig;
3373
3469
  observedMessageIds;
3374
- observerAgent;
3470
+ resolveModel;
3471
+ tokenCounter;
3375
3472
  constructor(opts) {
3376
3473
  this.observationConfig = opts.observationConfig;
3377
3474
  this.observedMessageIds = opts.observedMessageIds;
3475
+ this.resolveModel = opts.resolveModel;
3476
+ this.tokenCounter = opts.tokenCounter;
3378
3477
  }
3379
3478
  createAgent(model, isMultiThread = false) {
3380
3479
  return new agent.Agent({
@@ -3388,10 +3487,6 @@ var ObserverRunner = class {
3388
3487
  model
3389
3488
  });
3390
3489
  }
3391
- getAgent(model) {
3392
- this.observerAgent ??= this.createAgent(model);
3393
- return this.observerAgent;
3394
- }
3395
3490
  async withAbortCheck(fn, abortSignal) {
3396
3491
  if (abortSignal?.aborted) {
3397
3492
  throw new Error("The operation was aborted.");
@@ -3406,7 +3501,9 @@ var ObserverRunner = class {
3406
3501
  * Call the Observer agent for a single thread.
3407
3502
  */
3408
3503
  async call(existingObservations, messagesToObserve, abortSignal, options) {
3409
- const agent = options?.model ? this.createAgent(options.model) : this.getAgent(this.observationConfig.model);
3504
+ const inputTokens = this.tokenCounter.countMessages(messagesToObserve);
3505
+ const resolvedModel = options?.model ? { model: options.model } : this.resolveModel(inputTokens);
3506
+ const agent = this.createAgent(resolvedModel.model);
3410
3507
  const observerMessages = [
3411
3508
  {
3412
3509
  role: "user",
@@ -3418,15 +3515,32 @@ var ObserverRunner = class {
3418
3515
  buildObserverHistoryMessage(messagesToObserve)
3419
3516
  ];
3420
3517
  const doGenerate = async () => {
3421
- return this.withAbortCheck(async () => {
3422
- const streamResult = await agent.stream(observerMessages, {
3423
- modelSettings: { ...this.observationConfig.modelSettings },
3424
- providerOptions: this.observationConfig.providerOptions,
3425
- ...abortSignal ? { abortSignal } : {},
3426
- ...options?.requestContext ? { requestContext: options.requestContext } : {}
3427
- });
3428
- return streamResult.getFullOutput();
3429
- }, abortSignal);
3518
+ return withOmTracingSpan({
3519
+ phase: "observer",
3520
+ model: resolvedModel.model,
3521
+ inputTokens,
3522
+ requestContext: options?.requestContext,
3523
+ observabilityContext: options?.observabilityContext,
3524
+ metadata: {
3525
+ omPreviousObserverTokens: this.observationConfig.previousObserverTokens,
3526
+ omThreadTitleEnabled: this.observationConfig.threadTitle,
3527
+ omSkipContinuationHints: options?.skipContinuationHints ?? false,
3528
+ omWasTruncated: options?.wasTruncated ?? false,
3529
+ ...resolvedModel.selectedThreshold !== void 0 ? { omSelectedThreshold: resolvedModel.selectedThreshold } : {},
3530
+ ...resolvedModel.routingStrategy ? { omRoutingStrategy: resolvedModel.routingStrategy } : {},
3531
+ ...resolvedModel.routingThresholds ? { omRoutingThresholds: resolvedModel.routingThresholds } : {}
3532
+ },
3533
+ callback: (childObservabilityContext) => this.withAbortCheck(async () => {
3534
+ const streamResult = await agent.stream(observerMessages, {
3535
+ modelSettings: { ...this.observationConfig.modelSettings },
3536
+ providerOptions: this.observationConfig.providerOptions,
3537
+ ...abortSignal ? { abortSignal } : {},
3538
+ ...options?.requestContext ? { requestContext: options.requestContext } : {},
3539
+ ...childObservabilityContext
3540
+ });
3541
+ return streamResult.getFullOutput();
3542
+ }, abortSignal)
3543
+ });
3430
3544
  };
3431
3545
  let result = await doGenerate();
3432
3546
  let parsed = parseObserverOutput(result.text);
@@ -3451,8 +3565,13 @@ var ObserverRunner = class {
3451
3565
  /**
3452
3566
  * Call the Observer agent for multiple threads in a single batched request.
3453
3567
  */
3454
- async callMultiThread(existingObservations, messagesByThread, threadOrder, abortSignal, requestContext, priorMetadataByThread, model) {
3455
- const agent = this.createAgent(model ?? this.observationConfig.model, true);
3568
+ async callMultiThread(existingObservations, messagesByThread, threadOrder, abortSignal, requestContext, priorMetadataByThread, observabilityContext, model) {
3569
+ const inputTokens = Array.from(messagesByThread.values()).reduce(
3570
+ (total, messages) => total + this.tokenCounter.countMessages(messages),
3571
+ 0
3572
+ );
3573
+ const resolvedModel = model ? { model } : this.resolveModel(inputTokens);
3574
+ const agent = this.createAgent(resolvedModel.model, true);
3456
3575
  const observerMessages = [
3457
3576
  {
3458
3577
  role: "user",
@@ -3472,15 +3591,31 @@ var ObserverRunner = class {
3472
3591
  }
3473
3592
  }
3474
3593
  const doGenerate = async () => {
3475
- return this.withAbortCheck(async () => {
3476
- const streamResult = await agent.stream(observerMessages, {
3477
- modelSettings: { ...this.observationConfig.modelSettings },
3478
- providerOptions: this.observationConfig.providerOptions,
3479
- ...abortSignal ? { abortSignal } : {},
3480
- ...requestContext ? { requestContext } : {}
3481
- });
3482
- return streamResult.getFullOutput();
3483
- }, abortSignal);
3594
+ return withOmTracingSpan({
3595
+ phase: "observer-multi-thread",
3596
+ model: resolvedModel.model,
3597
+ inputTokens,
3598
+ requestContext,
3599
+ observabilityContext,
3600
+ metadata: {
3601
+ omThreadCount: threadOrder.length,
3602
+ omPreviousObserverTokens: this.observationConfig.previousObserverTokens,
3603
+ omThreadTitleEnabled: this.observationConfig.threadTitle,
3604
+ ...resolvedModel.selectedThreshold !== void 0 ? { omSelectedThreshold: resolvedModel.selectedThreshold } : {},
3605
+ ...resolvedModel.routingStrategy ? { omRoutingStrategy: resolvedModel.routingStrategy } : {},
3606
+ ...resolvedModel.routingThresholds ? { omRoutingThresholds: resolvedModel.routingThresholds } : {}
3607
+ },
3608
+ callback: (childObservabilityContext) => this.withAbortCheck(async () => {
3609
+ const streamResult = await agent.stream(observerMessages, {
3610
+ modelSettings: { ...this.observationConfig.modelSettings },
3611
+ providerOptions: this.observationConfig.providerOptions,
3612
+ ...abortSignal ? { abortSignal } : {},
3613
+ ...requestContext ? { requestContext } : {},
3614
+ ...childObservabilityContext
3615
+ });
3616
+ return streamResult.getFullOutput();
3617
+ }, abortSignal)
3618
+ });
3484
3619
  };
3485
3620
  let result = await doGenerate();
3486
3621
  let parsed = parseMultiThreadObserverOutput(result.text);
@@ -3787,6 +3922,7 @@ var ReflectorRunner = class {
3787
3922
  reflectionConfig;
3788
3923
  observationConfig;
3789
3924
  tokenCounter;
3925
+ resolveModel;
3790
3926
  storage;
3791
3927
  scope;
3792
3928
  buffering;
@@ -3798,6 +3934,7 @@ var ReflectorRunner = class {
3798
3934
  this.reflectionConfig = opts.reflectionConfig;
3799
3935
  this.observationConfig = opts.observationConfig;
3800
3936
  this.tokenCounter = opts.tokenCounter;
3937
+ this.resolveModel = opts.resolveModel;
3801
3938
  this.storage = opts.storage;
3802
3939
  this.scope = opts.scope;
3803
3940
  this.buffering = opts.buffering;
@@ -3824,9 +3961,10 @@ var ReflectorRunner = class {
3824
3961
  /**
3825
3962
  * Call the Reflector agent with escalating compression levels.
3826
3963
  */
3827
- async call(observations, manualPrompt, streamContext, observationTokensThreshold, abortSignal, skipContinuationHints, compressionStartLevel, requestContext, model) {
3828
- const agent = this.createAgent(model ?? this.reflectionConfig.model);
3964
+ async call(observations, manualPrompt, streamContext, observationTokensThreshold, abortSignal, skipContinuationHints, compressionStartLevel, requestContext, observabilityContext, model) {
3829
3965
  const originalTokens = this.tokenCounter.countObservations(observations);
3966
+ const resolvedModel = model ? { model } : this.resolveModel(originalTokens);
3967
+ const agent = this.createAgent(resolvedModel.model);
3830
3968
  const targetThreshold = observationTokensThreshold ?? getMaxThreshold(this.reflectionConfig.observationTokens);
3831
3969
  let totalUsage = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
3832
3970
  const startLevel = compressionStartLevel ?? 0;
@@ -3843,37 +3981,54 @@ var ReflectorRunner = class {
3843
3981
  `[OM:callReflector] ${isRetry ? `retry #${attemptNumber - 1}` : "first attempt"}: level=${currentLevel}, originalTokens=${originalTokens}, targetThreshold=${targetThreshold}, promptLen=${prompt.length}, skipContinuationHints=${skipContinuationHints}`
3844
3982
  );
3845
3983
  let chunkCount = 0;
3846
- const result = await withAbortCheck(async () => {
3847
- const streamResult = await agent.stream(prompt, {
3848
- modelSettings: {
3849
- ...this.reflectionConfig.modelSettings
3850
- },
3851
- providerOptions: this.reflectionConfig.providerOptions,
3852
- ...abortSignal ? { abortSignal } : {},
3853
- ...requestContext ? { requestContext } : {},
3854
- ...attemptNumber === 1 ? {
3855
- onChunk(chunk) {
3856
- chunkCount++;
3857
- if (chunkCount === 1 || chunkCount % 50 === 0) {
3858
- const preview = chunk.type === "text-delta" ? ` text="${chunk.textDelta?.slice(0, 80)}..."` : chunk.type === "tool-call" ? ` tool=${chunk.toolName}` : "";
3859
- omDebug(`[OM:callReflector] chunk#${chunkCount}: type=${chunk.type}${preview}`);
3860
- }
3861
- },
3862
- onFinish(event) {
3863
- omDebug(
3864
- `[OM:callReflector] onFinish: chunks=${chunkCount}, finishReason=${event.finishReason}, inputTokens=${event.usage?.inputTokens}, outputTokens=${event.usage?.outputTokens}, textLen=${event.text?.length}`
3865
- );
3866
- },
3867
- onAbort(event) {
3868
- omDebug(`[OM:callReflector] onAbort: chunks=${chunkCount}, reason=${event?.reason ?? "unknown"}`);
3984
+ const result = await withOmTracingSpan({
3985
+ phase: "reflector",
3986
+ model: resolvedModel.model,
3987
+ inputTokens: originalTokens,
3988
+ requestContext,
3989
+ observabilityContext,
3990
+ metadata: {
3991
+ omCompressionLevel: currentLevel,
3992
+ omCompressionAttempt: attemptNumber,
3993
+ omTargetThreshold: targetThreshold,
3994
+ omSkipContinuationHints: skipContinuationHints ?? false,
3995
+ ...resolvedModel.selectedThreshold !== void 0 ? { omSelectedThreshold: resolvedModel.selectedThreshold } : {},
3996
+ ...resolvedModel.routingStrategy ? { omRoutingStrategy: resolvedModel.routingStrategy } : {},
3997
+ ...resolvedModel.routingThresholds ? { omRoutingThresholds: resolvedModel.routingThresholds } : {}
3998
+ },
3999
+ callback: (childObservabilityContext) => withAbortCheck(async () => {
4000
+ const streamResult = await agent.stream(prompt, {
4001
+ modelSettings: {
4002
+ ...this.reflectionConfig.modelSettings
3869
4003
  },
3870
- onError({ error }) {
3871
- omError(`[OM:callReflector] onError after ${chunkCount} chunks`, error);
3872
- }
3873
- } : {}
3874
- });
3875
- return streamResult.getFullOutput();
3876
- }, abortSignal);
4004
+ providerOptions: this.reflectionConfig.providerOptions,
4005
+ ...abortSignal ? { abortSignal } : {},
4006
+ ...requestContext ? { requestContext } : {},
4007
+ ...childObservabilityContext,
4008
+ ...attemptNumber === 1 ? {
4009
+ onChunk(chunk) {
4010
+ chunkCount++;
4011
+ if (chunkCount === 1 || chunkCount % 50 === 0) {
4012
+ const preview = chunk.type === "text-delta" ? ` text="${chunk.textDelta?.slice(0, 80)}..."` : chunk.type === "tool-call" ? ` tool=${chunk.toolName}` : "";
4013
+ omDebug(`[OM:callReflector] chunk#${chunkCount}: type=${chunk.type}${preview}`);
4014
+ }
4015
+ },
4016
+ onFinish(event) {
4017
+ omDebug(
4018
+ `[OM:callReflector] onFinish: chunks=${chunkCount}, finishReason=${event.finishReason}, inputTokens=${event.usage?.inputTokens}, outputTokens=${event.usage?.outputTokens}, textLen=${event.text?.length}`
4019
+ );
4020
+ },
4021
+ onAbort(event) {
4022
+ omDebug(`[OM:callReflector] onAbort: chunks=${chunkCount}, reason=${event?.reason ?? "unknown"}`);
4023
+ },
4024
+ onError({ error }) {
4025
+ omError(`[OM:callReflector] onError after ${chunkCount} chunks`, error);
4026
+ }
4027
+ } : {}
4028
+ });
4029
+ return streamResult.getFullOutput();
4030
+ }, abortSignal)
4031
+ });
3877
4032
  omDebug(
3878
4033
  `[OM:callReflector] attempt #${attemptNumber} returned: textLen=${result.text?.length}, textPreview="${result.text?.slice(0, 120)}...", inputTokens=${result.usage?.inputTokens ?? result.totalUsage?.inputTokens}, outputTokens=${result.usage?.outputTokens ?? result.totalUsage?.outputTokens}`
3879
4034
  );
@@ -3940,7 +4095,7 @@ var ReflectorRunner = class {
3940
4095
  /**
3941
4096
  * Start an async buffered reflection in the background.
3942
4097
  */
3943
- startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext) {
4098
+ startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext, observabilityContext) {
3944
4099
  const bufferKey = this.buffering.getReflectionBufferKey(lockKey);
3945
4100
  if (this.buffering.isAsyncBufferingInProgress(bufferKey)) {
3946
4101
  return;
@@ -3950,7 +4105,7 @@ var ReflectorRunner = class {
3950
4105
  this.storage.setBufferingReflectionFlag(record.id, true).catch((err) => {
3951
4106
  omError("[OM] Failed to set buffering reflection flag", err);
3952
4107
  });
3953
- const asyncOp = this.doAsyncBufferedReflection(record, bufferKey, writer, requestContext).catch(async (error) => {
4108
+ const asyncOp = this.doAsyncBufferedReflection(record, bufferKey, writer, requestContext, observabilityContext).catch(async (error) => {
3954
4109
  if (writer) {
3955
4110
  const failedMarker = createBufferingFailedMarker({
3956
4111
  cycleId: `reflect-buf-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`,
@@ -3980,7 +4135,7 @@ var ReflectorRunner = class {
3980
4135
  * Perform async buffered reflection — reflects observations and stores to bufferedReflection.
3981
4136
  * Does NOT create a new generation or update activeObservations.
3982
4137
  */
3983
- async doAsyncBufferedReflection(record, _bufferKey, writer, requestContext) {
4138
+ async doAsyncBufferedReflection(record, _bufferKey, writer, requestContext, observabilityContext) {
3984
4139
  const freshRecord = await this.storage.getObservationalMemory(record.threadId, record.resourceId);
3985
4140
  const currentRecord = freshRecord ?? record;
3986
4141
  const observationTokens = currentRecord.observationTokenCount ?? 0;
@@ -4027,7 +4182,8 @@ var ReflectorRunner = class {
4027
4182
  void 0,
4028
4183
  true,
4029
4184
  compressionStartLevel,
4030
- requestContext
4185
+ requestContext,
4186
+ observabilityContext
4031
4187
  );
4032
4188
  const reflectionTokenCount = this.tokenCounter.countObservations(reflectResult.observations);
4033
4189
  omDebug(
@@ -4143,7 +4299,16 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
4143
4299
  * @internal Used by observation strategies. Do not call directly.
4144
4300
  */
4145
4301
  async maybeReflect(opts) {
4146
- const { record, observationTokens, writer, abortSignal, messageList, reflectionHooks, requestContext } = opts;
4302
+ const {
4303
+ record,
4304
+ observationTokens,
4305
+ writer,
4306
+ abortSignal,
4307
+ messageList,
4308
+ reflectionHooks,
4309
+ requestContext,
4310
+ observabilityContext
4311
+ } = opts;
4147
4312
  const lockKey = this.buffering.getLockKey(record.threadId, record.resourceId);
4148
4313
  const reflectThreshold = getMaxThreshold(this.reflectionConfig.observationTokens);
4149
4314
  if (this.buffering.isAsyncReflectionEnabled() && observationTokens < reflectThreshold) {
@@ -4163,7 +4328,14 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
4163
4328
  return observationTokens >= activationPoint;
4164
4329
  })();
4165
4330
  if (shouldTrigger) {
4166
- this.startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext);
4331
+ this.startAsyncBufferedReflection(
4332
+ record,
4333
+ observationTokens,
4334
+ lockKey,
4335
+ writer,
4336
+ requestContext,
4337
+ observabilityContext
4338
+ );
4167
4339
  }
4168
4340
  }
4169
4341
  if (observationTokens < reflectThreshold) {
@@ -4190,7 +4362,14 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
4190
4362
  omDebug(
4191
4363
  `[OM:reflect] async activation failed, no blockAfter or below it (obsTokens=${observationTokens}, blockAfter=${this.reflectionConfig.blockAfter}) \u2014 starting background reflection`
4192
4364
  );
4193
- this.startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext);
4365
+ this.startAsyncBufferedReflection(
4366
+ record,
4367
+ observationTokens,
4368
+ lockKey,
4369
+ writer,
4370
+ requestContext,
4371
+ observabilityContext
4372
+ );
4194
4373
  return;
4195
4374
  }
4196
4375
  }
@@ -4238,7 +4417,8 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
4238
4417
  abortSignal,
4239
4418
  void 0,
4240
4419
  compressionStartLevel,
4241
- requestContext
4420
+ requestContext,
4421
+ observabilityContext
4242
4422
  );
4243
4423
  const reflectionTokenCount = this.tokenCounter.countObservations(reflectResult.observations);
4244
4424
  await this.storage.createReflectionGeneration({
@@ -5526,11 +5706,12 @@ var ObservationalMemory = class _ObservationalMemory {
5526
5706
  storage;
5527
5707
  tokenCounter;
5528
5708
  scope;
5529
- /** Whether retrieval-mode observation groups are enabled (thread scope only). */
5709
+ /** Whether retrieval-mode observation groups are enabled. */
5530
5710
  retrieval;
5531
5711
  observationConfig;
5532
5712
  reflectionConfig;
5533
5713
  onDebugEvent;
5714
+ onIndexObservations;
5534
5715
  /** Observer agent runner — handles LLM calls for extracting observations. */
5535
5716
  observer;
5536
5717
  /** Reflector agent runner — handles LLM calls for compressing observations. */
@@ -5603,7 +5784,8 @@ var ObservationalMemory = class _ObservationalMemory {
5603
5784
  this.shouldObscureThreadIds = config.obscureThreadIds || false;
5604
5785
  this.storage = config.storage;
5605
5786
  this.scope = config.scope ?? "thread";
5606
- this.retrieval = this.scope === "thread" && (config.retrieval ?? false);
5787
+ this.retrieval = Boolean(config.retrieval);
5788
+ this.onIndexObservations = config.onIndexObservations;
5607
5789
  const resolveModel = (m) => m === "default" ? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.model : m;
5608
5790
  const observationModel = resolveModel(config.model) ?? resolveModel(config.observation?.model) ?? resolveModel(config.reflection?.model);
5609
5791
  const reflectionModel = resolveModel(config.model) ?? resolveModel(config.reflection?.model) ?? resolveModel(config.observation?.model);
@@ -5697,7 +5879,9 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
5697
5879
  this.messageHistory = new processors.MessageHistory({ storage: this.storage });
5698
5880
  this.observer = new ObserverRunner({
5699
5881
  observationConfig: this.observationConfig,
5700
- observedMessageIds: this.observedMessageIds
5882
+ observedMessageIds: this.observedMessageIds,
5883
+ resolveModel: (inputTokens) => this.resolveObservationModel(inputTokens),
5884
+ tokenCounter: this.tokenCounter
5701
5885
  });
5702
5886
  this.buffering = new BufferingCoordinator({
5703
5887
  observationConfig: this.observationConfig,
@@ -5714,7 +5898,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
5714
5898
  emitDebugEvent: (e) => this.emitDebugEvent(e),
5715
5899
  persistMarkerToStorage: (m, t, r) => this.persistMarkerToStorage(m, t, r),
5716
5900
  persistMarkerToMessage: (m, ml, t, r) => this.persistMarkerToMessage(m, ml, t, r),
5717
- getCompressionStartLevel: (rc) => this.getCompressionStartLevel(rc)
5901
+ getCompressionStartLevel: (rc) => this.getCompressionStartLevel(rc),
5902
+ resolveModel: (inputTokens) => this.resolveReflectionModel(inputTokens)
5718
5903
  });
5719
5904
  this.validateBufferConfig();
5720
5905
  omDebug(
@@ -5776,6 +5961,54 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
5776
5961
  }
5777
5962
  return model.provider ? `${model.provider}/${model.modelId}` : model.modelId;
5778
5963
  }
5964
+ resolveObservationModel(inputTokens) {
5965
+ return this.resolveTieredModel(this.observationConfig.model, inputTokens);
5966
+ }
5967
+ resolveReflectionModel(inputTokens) {
5968
+ return this.resolveTieredModel(this.reflectionConfig.model, inputTokens);
5969
+ }
5970
+ resolveTieredModel(model, inputTokens) {
5971
+ if (!(model instanceof ModelByInputTokens)) {
5972
+ return {
5973
+ model
5974
+ };
5975
+ }
5976
+ const thresholds = model.getThresholds();
5977
+ const selectedThreshold = thresholds.find((upTo) => inputTokens <= upTo) ?? thresholds.at(-1);
5978
+ return {
5979
+ model: model.resolve(inputTokens),
5980
+ selectedThreshold,
5981
+ routingStrategy: "model-by-input-tokens",
5982
+ routingThresholds: thresholds.join(",")
5983
+ };
5984
+ }
5985
+ async resolveModelRouting(modelConfig, requestContext) {
5986
+ try {
5987
+ if (modelConfig instanceof ModelByInputTokens) {
5988
+ const routing = await Promise.all(
5989
+ modelConfig.getThresholds().map(async (upTo) => {
5990
+ const resolvedModel = modelConfig.resolve(upTo);
5991
+ const resolved2 = await this.resolveModelContext(resolvedModel, requestContext);
5992
+ return {
5993
+ upTo,
5994
+ model: resolved2?.modelId ? this.formatModelName(resolved2) : "(unknown)"
5995
+ };
5996
+ })
5997
+ );
5998
+ return {
5999
+ model: routing[0]?.model ?? "(unknown)",
6000
+ routing
6001
+ };
6002
+ }
6003
+ const resolved = await this.resolveModelContext(modelConfig, requestContext);
6004
+ return {
6005
+ model: resolved?.modelId ? this.formatModelName(resolved) : "(unknown)"
6006
+ };
6007
+ } catch (error) {
6008
+ omError("[OM] Failed to resolve model config", error);
6009
+ return { model: "(unknown)" };
6010
+ }
6011
+ }
5779
6012
  async resolveModelContext(modelConfig, requestContext, inputTokens) {
5780
6013
  const modelToResolve = this.getModelToResolve(modelConfig, inputTokens);
5781
6014
  if (!modelToResolve) {
@@ -5808,29 +6041,22 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
5808
6041
  * This is async because it needs to resolve the model configs.
5809
6042
  */
5810
6043
  async getResolvedConfig(requestContext) {
5811
- const safeResolveModel = async (modelConfig) => {
5812
- try {
5813
- const resolved = await this.resolveModelContext(modelConfig, requestContext);
5814
- return resolved?.modelId ? this.formatModelName(resolved) : "(unknown)";
5815
- } catch (error) {
5816
- omError("[OM] Failed to resolve model config", error);
5817
- return "(unknown)";
5818
- }
5819
- };
5820
- const [observationModelName, reflectionModelName] = await Promise.all([
5821
- safeResolveModel(this.observationConfig.model),
5822
- safeResolveModel(this.reflectionConfig.model)
6044
+ const [observationResolved, reflectionResolved] = await Promise.all([
6045
+ this.resolveModelRouting(this.observationConfig.model, requestContext),
6046
+ this.resolveModelRouting(this.reflectionConfig.model, requestContext)
5823
6047
  ]);
5824
6048
  return {
5825
6049
  scope: this.scope,
5826
6050
  observation: {
5827
6051
  messageTokens: this.observationConfig.messageTokens,
5828
- model: observationModelName,
5829
- previousObserverTokens: this.observationConfig.previousObserverTokens
6052
+ model: observationResolved.model,
6053
+ previousObserverTokens: this.observationConfig.previousObserverTokens,
6054
+ routing: observationResolved.routing
5830
6055
  },
5831
6056
  reflection: {
5832
6057
  observationTokens: this.reflectionConfig.observationTokens,
5833
- model: reflectionModelName
6058
+ model: reflectionResolved.model,
6059
+ routing: reflectionResolved.routing
5834
6060
  }
5835
6061
  };
5836
6062
  }
@@ -6637,7 +6863,7 @@ ${grouped}` : grouped;
6637
6863
  * @param lockKey - Lock key for this scope
6638
6864
  * @param writer - Optional stream writer for emitting buffering markers
6639
6865
  */
6640
- async startAsyncBufferedObservation(record, threadId, unobservedMessages, lockKey, writer, contextWindowTokens, requestContext) {
6866
+ async startAsyncBufferedObservation(record, threadId, unobservedMessages, lockKey, writer, contextWindowTokens, requestContext, observabilityContext) {
6641
6867
  const bufferKey = this.buffering.getObservationBufferKey(lockKey);
6642
6868
  const currentTokens = contextWindowTokens ?? await this.tokenCounter.countMessagesAsync(unobservedMessages) + (record.pendingMessageTokens ?? 0);
6643
6869
  BufferingCoordinator.lastBufferedBoundary.set(bufferKey, currentTokens);
@@ -6651,7 +6877,8 @@ ${grouped}` : grouped;
6651
6877
  unobservedMessages,
6652
6878
  bufferKey,
6653
6879
  writer,
6654
- requestContext
6880
+ requestContext,
6881
+ observabilityContext
6655
6882
  ).finally(() => {
6656
6883
  BufferingCoordinator.asyncBufferingOps.delete(bufferKey);
6657
6884
  unregisterOp(record.id, "bufferingObservation");
@@ -6665,7 +6892,7 @@ ${grouped}` : grouped;
6665
6892
  * Internal method that waits for existing buffering operation and then runs new buffering.
6666
6893
  * This implements the mutex-wait behavior.
6667
6894
  */
6668
- async runAsyncBufferedObservation(record, threadId, unobservedMessages, bufferKey, writer, requestContext) {
6895
+ async runAsyncBufferedObservation(record, threadId, unobservedMessages, bufferKey, writer, requestContext, observabilityContext) {
6669
6896
  const existingOp = BufferingCoordinator.asyncBufferingOps.get(bufferKey);
6670
6897
  if (existingOp) {
6671
6898
  try {
@@ -6737,7 +6964,8 @@ ${grouped}` : grouped;
6737
6964
  cycleId,
6738
6965
  startedAt,
6739
6966
  writer,
6740
- requestContext
6967
+ requestContext,
6968
+ observabilityContext
6741
6969
  }).run();
6742
6970
  const maxTs = this.getMaxMessageTimestamp(messagesToBuffer);
6743
6971
  const cursor = new Date(maxTs.getTime() + 1);
@@ -7284,7 +7512,7 @@ ${grouped}` : grouped;
7284
7512
  */
7285
7513
  /** @internal Used by ObservationStep. */
7286
7514
  async buffer(opts) {
7287
- const { threadId, resourceId, requestContext } = opts;
7515
+ const { threadId, resourceId, requestContext, observabilityContext } = opts;
7288
7516
  let record = opts.record ?? await this.getOrCreateRecord(threadId, resourceId);
7289
7517
  if (!this.buffering.isAsyncObservationEnabled()) {
7290
7518
  return { buffered: false, record };
@@ -7380,7 +7608,8 @@ ${grouped}` : grouped;
7380
7608
  cycleId,
7381
7609
  startedAt,
7382
7610
  writer,
7383
- requestContext
7611
+ requestContext,
7612
+ observabilityContext
7384
7613
  }).run();
7385
7614
  await this.storage.setBufferingObservationFlag(record.id, false, newTokens).catch(() => {
7386
7615
  });
@@ -7584,7 +7813,8 @@ ${grouped}` : grouped;
7584
7813
  messages: unobservedMessages,
7585
7814
  reflectionHooks,
7586
7815
  requestContext,
7587
- writer: opts.writer
7816
+ writer: opts.writer,
7817
+ observabilityContext: opts.observabilityContext
7588
7818
  }).run();
7589
7819
  observed = true;
7590
7820
  } finally {
@@ -7606,7 +7836,7 @@ ${grouped}` : grouped;
7606
7836
  * );
7607
7837
  * ```
7608
7838
  */
7609
- async reflect(threadId, resourceId, prompt, requestContext) {
7839
+ async reflect(threadId, resourceId, prompt, requestContext, observabilityContext) {
7610
7840
  const record = await this.getOrCreateRecord(threadId, resourceId);
7611
7841
  if (!record.activeObservations) {
7612
7842
  return { reflected: false, record };
@@ -7623,7 +7853,9 @@ ${grouped}` : grouped;
7623
7853
  void 0,
7624
7854
  void 0,
7625
7855
  void 0,
7626
- requestContext
7856
+ requestContext,
7857
+ observabilityContext,
7858
+ void 0
7627
7859
  );
7628
7860
  const reflectionTokenCount = this.tokenCounter.countObservations(reflectResult.observations);
7629
7861
  await this.storage.createReflectionGeneration({
@@ -7730,6 +7962,7 @@ ${grouped}` : grouped;
7730
7962
  threadId: opts.threadId,
7731
7963
  resourceId: opts.resourceId,
7732
7964
  messageList: opts.messageList,
7965
+ observabilityContext: opts.observabilityContext,
7733
7966
  hooks: opts.hooks
7734
7967
  });
7735
7968
  }
@@ -7980,6 +8213,17 @@ function writeProcessInputStepReproCapture(params) {
7980
8213
  }
7981
8214
 
7982
8215
  // src/processors/observational-memory/processor.ts
8216
+ function getOmObservabilityContext(args) {
8217
+ if (!args.tracing || !args.tracingContext || !args.loggerVNext || !args.metrics) {
8218
+ return void 0;
8219
+ }
8220
+ return {
8221
+ tracing: args.tracing,
8222
+ tracingContext: args.tracingContext,
8223
+ loggerVNext: args.loggerVNext,
8224
+ metrics: args.metrics
8225
+ };
8226
+ }
7983
8227
  var ObservationalMemoryProcessor = class {
7984
8228
  id = "observational-memory";
7985
8229
  name = "Observational Memory";
@@ -8037,6 +8281,7 @@ var ObservationalMemoryProcessor = class {
8037
8281
  threadId,
8038
8282
  resourceId,
8039
8283
  messageList,
8284
+ observabilityContext: getOmObservabilityContext(args),
8040
8285
  hooks: {
8041
8286
  onBufferChunkSealed: rotateResponseMessageId
8042
8287
  }
@@ -8046,6 +8291,9 @@ var ObservationalMemoryProcessor = class {
8046
8291
  await this.turn.start(this.memory);
8047
8292
  state.__omTurn = this.turn;
8048
8293
  }
8294
+ const observabilityContext = getOmObservabilityContext(args);
8295
+ state.__omObservabilityContext = observabilityContext;
8296
+ this.turn.observabilityContext = observabilityContext;
8049
8297
  {
8050
8298
  const step = this.turn.step(stepNumber);
8051
8299
  let ctx;
@@ -8126,6 +8374,8 @@ var ObservationalMemoryProcessor = class {
8126
8374
  const state = _state ?? {};
8127
8375
  const context = this.engine.getThreadContext(requestContext, messageList);
8128
8376
  if (!context) return messageList;
8377
+ const observabilityContext = getOmObservabilityContext(args);
8378
+ state.__omObservabilityContext = observabilityContext;
8129
8379
  return this.engine.getTokenCounter().runWithModelContext(state.__omActorModelContext, async () => {
8130
8380
  const memoryContext = memory.parseMemoryRequestContext(requestContext);
8131
8381
  if (memoryContext?.memoryConfig?.readOnly) return messageList;
@@ -8200,5 +8450,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
8200
8450
  exports.stripObservationGroups = stripObservationGroups;
8201
8451
  exports.truncateStringByTokens = truncateStringByTokens;
8202
8452
  exports.wrapInObservationGroup = wrapInObservationGroup;
8203
- //# sourceMappingURL=chunk-DTAZSLVU.cjs.map
8204
- //# sourceMappingURL=chunk-DTAZSLVU.cjs.map
8453
+ //# sourceMappingURL=chunk-VINRPDYQ.cjs.map
8454
+ //# sourceMappingURL=chunk-VINRPDYQ.cjs.map