@mastra/memory 1.6.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/dist/{chunk-5UYAHJVJ.cjs → chunk-D6II7EP4.cjs} +660 -531
- package/dist/chunk-D6II7EP4.cjs.map +1 -0
- package/dist/{chunk-A62BQK35.js → chunk-GBBQIJQF.js} +660 -531
- package/dist/chunk-GBBQIJQF.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +25 -25
- package/dist/docs/references/docs-agents-agent-approval.md +61 -31
- package/dist/docs/references/docs-agents-supervisor-agents.md +1 -1
- package/dist/docs/references/docs-memory-observational-memory.md +9 -0
- package/dist/docs/references/docs-memory-semantic-recall.md +17 -1
- package/dist/docs/references/reference-core-getMemory.md +2 -2
- package/dist/docs/references/reference-core-listMemory.md +1 -1
- package/dist/docs/references/reference-memory-clone-utilities.md +5 -5
- package/dist/docs/references/reference-memory-cloneThread.md +17 -21
- package/dist/docs/references/reference-memory-createThread.md +10 -10
- package/dist/docs/references/reference-memory-getThreadById.md +2 -2
- package/dist/docs/references/reference-memory-listThreads.md +5 -5
- package/dist/docs/references/reference-memory-memory-class.md +12 -14
- package/dist/docs/references/reference-memory-observational-memory.md +102 -94
- package/dist/docs/references/reference-processors-token-limiter-processor.md +11 -13
- package/dist/docs/references/reference-storage-dynamodb.md +9 -9
- package/dist/docs/references/reference-storage-libsql.md +2 -2
- package/dist/docs/references/reference-storage-mongodb.md +5 -5
- package/dist/docs/references/reference-storage-postgresql.md +25 -25
- package/dist/docs/references/reference-storage-upstash.md +3 -3
- package/dist/docs/references/reference-vectors-libsql.md +31 -31
- package/dist/docs/references/reference-vectors-mongodb.md +32 -32
- package/dist/docs/references/reference-vectors-pg.md +60 -44
- package/dist/docs/references/reference-vectors-upstash.md +25 -25
- package/dist/index.cjs +246 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +246 -57
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-MXI54VC7.cjs → observational-memory-AHVELJX4.cjs} +17 -17
- package/dist/{observational-memory-MXI54VC7.cjs.map → observational-memory-AHVELJX4.cjs.map} +1 -1
- package/dist/{observational-memory-SR6G4HN5.js → observational-memory-QFQUF5EY.js} +3 -3
- package/dist/{observational-memory-SR6G4HN5.js.map → observational-memory-QFQUF5EY.js.map} +1 -1
- package/dist/processors/index.cjs +15 -15
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/date-utils.d.ts +35 -0
- package/dist/processors/observational-memory/date-utils.d.ts.map +1 -0
- package/dist/processors/observational-memory/markers.d.ts +94 -0
- package/dist/processors/observational-memory/markers.d.ts.map +1 -0
- package/dist/processors/observational-memory/observational-memory.d.ts +0 -76
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/operation-registry.d.ts +14 -0
- package/dist/processors/observational-memory/operation-registry.d.ts.map +1 -0
- package/dist/processors/observational-memory/thresholds.d.ts +52 -0
- package/dist/processors/observational-memory/thresholds.d.ts.map +1 -0
- package/dist/processors/observational-memory/token-counter.d.ts +4 -0
- package/dist/processors/observational-memory/token-counter.d.ts.map +1 -1
- package/dist/tools/working-memory.d.ts.map +1 -1
- package/package.json +7 -7
- package/dist/chunk-5UYAHJVJ.cjs.map +0 -1
- package/dist/chunk-A62BQK35.js.map +0 -1
|
@@ -22,35 +22,33 @@ export const agent = new Agent({
|
|
|
22
22
|
})
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
> To enable `workingMemory` on an agent, you’ll need a storage provider configured on your main Mastra instance. See [Mastra class](https://mastra.ai/reference/core/mastra-class) for more information.
|
|
25
|
+
> **Note:** To enable `workingMemory` on an agent, you’ll need a storage provider configured on your main Mastra instance. See [Mastra class](https://mastra.ai/reference/core/mastra-class) for more information.
|
|
26
26
|
|
|
27
27
|
## Constructor parameters
|
|
28
28
|
|
|
29
|
-
**storage
|
|
29
|
+
**storage** (`MastraCompositeStore`): Storage implementation for persisting memory data. Defaults to \`new DefaultStorage({ config: { url: "file:memory.db" } })\` if not provided.
|
|
30
30
|
|
|
31
|
-
**vector
|
|
31
|
+
**vector** (`MastraVector | false`): Vector store for semantic search capabilities. Set to \`false\` to disable vector operations.
|
|
32
32
|
|
|
33
|
-
**embedder
|
|
33
|
+
**embedder** (`EmbeddingModel<string> | EmbeddingModelV2<string>`): Embedder instance for vector embeddings. Required when semantic recall is enabled.
|
|
34
34
|
|
|
35
|
-
**options
|
|
35
|
+
**options** (`MemoryConfig`): Memory configuration options.
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
**options.lastMessages** (`number | false`): Number of most recent messages to include in context. Set to \`false\` to disable loading conversation history into context. Use \`Number.MAX\_SAFE\_INTEGER\` to retrieve all messages with no limit. To prevent saving new messages, use the \`readOnly\` option instead.
|
|
38
38
|
|
|
39
|
-
**
|
|
39
|
+
**options.readOnly** (`boolean`): When true, prevents memory from saving new messages and provides working memory as read-only context (without the updateWorkingMemory tool). Useful for read-only operations like previews, internal routing agents, or sub agents that should reference but not modify memory.
|
|
40
40
|
|
|
41
|
-
**
|
|
41
|
+
**options.semanticRecall** (`boolean | { topK: number; messageRange: number | { before: number; after: number }; scope?: 'thread' | 'resource' }`): Enable semantic search in message history. Can be a boolean or an object with configuration options. When enabled, requires both vector store and embedder to be configured. Default topK is 4, default messageRange is {before: 1, after: 1}.
|
|
42
42
|
|
|
43
|
-
**
|
|
43
|
+
**options.workingMemory** (`WorkingMemory`): Configuration for working memory feature. Can be \`{ enabled: boolean; template?: string; schema?: ZodObject\<any> | JSONSchema7; scope?: 'thread' | 'resource' }\` or \`{ enabled: boolean }\` to disable.
|
|
44
44
|
|
|
45
|
-
**
|
|
45
|
+
**options.observationalMemory** (`boolean | ObservationalMemoryOptions`): Enable Observational Memory for long-context agentic memory. Set to \`true\` for defaults, or pass a config object to customize token budgets, models, and scope. See \[Observational Memory reference]\(/reference/memory/observational-memory) for configuration details.
|
|
46
46
|
|
|
47
|
-
**
|
|
48
|
-
|
|
49
|
-
**generateTitle?:** (`boolean | { model: DynamicArgument<MastraLanguageModel>; instructions?: DynamicArgument<string> }`): Controls automatic thread title generation from the user's first message. Can be a boolean or an object with custom model and instructions. (Default: `false`)
|
|
47
|
+
**options.generateTitle** (`boolean | { model: DynamicArgument<MastraLanguageModel>; instructions?: DynamicArgument<string> }`): Controls automatic thread title generation from the user's first message. Can be a boolean or an object with custom model and instructions.
|
|
50
48
|
|
|
51
49
|
## Returns
|
|
52
50
|
|
|
53
|
-
**memory
|
|
51
|
+
**memory** (`Memory`): A new Memory instance with the specified configuration.
|
|
54
52
|
|
|
55
53
|
## Extended usage example
|
|
56
54
|
|
|
@@ -26,55 +26,63 @@ export const agent = new Agent({
|
|
|
26
26
|
|
|
27
27
|
The `observationalMemory` option accepts `true`, a configuration object, or `false`. Setting `true` enables OM with `google/gemini-2.5-flash` as the default model. When passing a config object, a `model` must be explicitly set — either at the top level, or on `observation.model` and/or `reflection.model`.
|
|
28
28
|
|
|
29
|
-
**enabled
|
|
29
|
+
**enabled** (`boolean`): Enable or disable Observational Memory. When omitted from a config object, defaults to \`true\`. Only \`enabled: false\` explicitly disables it. (Default: `true`)
|
|
30
30
|
|
|
31
|
-
**model
|
|
31
|
+
**model** (`string | LanguageModel | DynamicModel | ModelWithRetries[]`): Model for both the Observer and Reflector agents. Sets the model for both at once. Cannot be used together with \`observation.model\` or \`reflection.model\` — an error will be thrown if both are set. When using \`observationalMemory: true\`, defaults to \`google/gemini-2.5-flash\`. When passing a config object, this or \`observation.model\`/\`reflection.model\` must be set. Use \`"default"\` to explicitly use the default model (\`google/gemini-2.5-flash\`). (Default: `'google/gemini-2.5-flash' (when using observationalMemory: true)`)
|
|
32
32
|
|
|
33
|
-
**scope
|
|
33
|
+
**scope** (`'resource' | 'thread'`): Memory scope for observations. \`'thread'\` keeps observations per-thread. \`'resource'\` (experimental) shares observations across all threads for a resource, enabling cross-conversation memory. (Default: `'thread'`)
|
|
34
34
|
|
|
35
|
-
**shareTokenBudget
|
|
35
|
+
**shareTokenBudget** (`boolean`): Share the token budget between messages and observations. When enabled, the total budget is \`observation.messageTokens + reflection.observationTokens\`. Messages can use more space when observations are small, and vice versa. This maximizes context usage through flexible allocation. \`shareTokenBudget\` is not yet compatible with async buffering. You must set \`observation: { bufferTokens: false }\` when using this option (this is a temporary limitation). (Default: `false`)
|
|
36
36
|
|
|
37
|
-
**observation
|
|
37
|
+
**observation** (`ObservationalMemoryObservationConfig`): Configuration for the observation step. Controls when the Observer agent runs and how it behaves.
|
|
38
38
|
|
|
39
|
-
**
|
|
39
|
+
**observation.model** (`string | LanguageModel | DynamicModel | ModelWithRetries[]`): Model for the Observer agent. Cannot be set if a top-level \`model\` is also provided. If neither this nor the top-level \`model\` is set, falls back to \`reflection.model\`.
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
**observation.instruction** (`string`): Custom instruction appended to the Observer's system prompt. Use this to customize what the Observer focuses on, such as domain-specific preferences or priorities.
|
|
42
42
|
|
|
43
|
-
**
|
|
43
|
+
**observation.messageTokens** (`number`): Token count of unobserved messages that triggers observation. When unobserved message tokens exceed this threshold, the Observer agent is called.
|
|
44
44
|
|
|
45
|
-
**
|
|
45
|
+
**observation.maxTokensPerBatch** (`number`): Maximum tokens per batch when observing multiple threads in resource scope. Threads are chunked into batches of this size and processed in parallel. Lower values mean more parallelism but more API calls.
|
|
46
46
|
|
|
47
|
-
**
|
|
47
|
+
**observation.modelSettings** (`ObservationalMemoryModelSettings`): Model settings for the Observer agent.
|
|
48
48
|
|
|
49
|
-
**
|
|
49
|
+
**observation.modelSettings.temperature** (`number`): Temperature for generation. Lower values produce more consistent output.
|
|
50
50
|
|
|
51
|
-
**modelSettings
|
|
51
|
+
**observation.modelSettings.maxOutputTokens** (`number`): Maximum output tokens. Set high to prevent truncation of observations.
|
|
52
52
|
|
|
53
|
-
**bufferTokens
|
|
53
|
+
**observation.bufferTokens** (`number | false`): Token interval for async background observation buffering. Can be an absolute token count (e.g. \`5000\`) or a fraction of \`messageTokens\` (e.g. \`0.25\` = buffer every 25% of threshold). When set, observations run in the background at this interval, storing results in a buffer. When the main \`messageTokens\` threshold is reached, buffered observations activate instantly without a blocking LLM call. Must resolve to less than \`messageTokens\`. Set to \`false\` to explicitly disable all async buffering (both observation and reflection).
|
|
54
54
|
|
|
55
|
-
**bufferActivation
|
|
55
|
+
**observation.bufferActivation** (`number`): Controls how much of the message window to retain after activation. Accepts a ratio (0-1) or an absolute token count (≥ 1000). For example, \`0.8\` means: activate enough buffers to remove 80% of \`messageTokens\` and leave 20% as active message history. An absolute token count like \`4000\` targets a goal of keeping \~4k message tokens remaining after activation. Higher values remove more message history per activation when using a ratio. Higher values keep more message history when using a token count.
|
|
56
56
|
|
|
57
|
-
**blockAfter
|
|
57
|
+
**observation.blockAfter** (`number`): Token threshold above which synchronous (blocking) observation is forced. Between \`messageTokens\` and \`blockAfter\`, only async buffering/activation is used. Above \`blockAfter\`, a synchronous observation runs as a last resort, while buffered activation still preserves a minimum remaining context (min(1000, retention floor)). Accepts a multiplier (1 < value < 2, multiplied by \`messageTokens\`) or an absolute token count (≥ 2, must be greater than \`messageTokens\`). Only relevant when \`bufferTokens\` is set. Defaults to \`1.2\` when async buffering is enabled.
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
**reflection** (`ObservationalMemoryReflectionConfig`): Configuration for the reflection step. Controls when the Reflector agent runs and how it behaves.
|
|
60
60
|
|
|
61
|
-
**model
|
|
61
|
+
**reflection.model** (`string | LanguageModel | DynamicModel | ModelWithRetries[]`): Model for the Reflector agent. Cannot be set if a top-level \`model\` is also provided. If neither this nor the top-level \`model\` is set, falls back to \`observation.model\`.
|
|
62
62
|
|
|
63
|
-
**instruction
|
|
63
|
+
**reflection.instruction** (`string`): Custom instruction appended to the Reflector's system prompt. Use this to customize how the Reflector consolidates observations, such as prioritizing certain types of information.
|
|
64
64
|
|
|
65
|
-
**observationTokens
|
|
65
|
+
**reflection.observationTokens** (`number`): Token count of observations that triggers reflection. When observation tokens exceed this threshold, the Reflector agent is called to condense them.
|
|
66
66
|
|
|
67
|
-
**modelSettings
|
|
67
|
+
**reflection.modelSettings** (`ObservationalMemoryModelSettings`): Model settings for the Reflector agent.
|
|
68
68
|
|
|
69
|
-
**
|
|
69
|
+
**reflection.modelSettings.temperature** (`number`): Temperature for generation. Lower values produce more consistent output.
|
|
70
70
|
|
|
71
|
-
**
|
|
71
|
+
**reflection.modelSettings.maxOutputTokens** (`number`): Maximum output tokens. Set high to prevent truncation of observations.
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
**reflection.bufferActivation** (`number`): Ratio (0-1) controlling when async reflection buffering starts. When observation tokens reach \`observationTokens \* bufferActivation\`, reflection runs in the background. On activation at the full threshold, the buffered reflection replaces the observations it covers, preserving any new observations appended after that range.
|
|
74
74
|
|
|
75
|
-
**
|
|
75
|
+
**reflection.blockAfter** (`number`): Token threshold above which synchronous (blocking) reflection is forced. Between \`observationTokens\` and \`blockAfter\`, only async buffering/activation is used. Above \`blockAfter\`, a synchronous reflection runs as a last resort. Accepts a multiplier (1 < value < 2, multiplied by \`observationTokens\`) or an absolute token count (≥ 2, must be greater than \`observationTokens\`). Only relevant when \`bufferActivation\` is set. Defaults to \`1.2\` when async reflection is enabled.
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
### Token estimate metadata cache
|
|
78
|
+
|
|
79
|
+
OM persists token payload estimates so repeated counting can reuse prior tiktoken work.
|
|
80
|
+
|
|
81
|
+
- Part-level cache: `part.providerMetadata.mastra`.
|
|
82
|
+
- String-content fallback cache: message-level metadata when no parts exist.
|
|
83
|
+
- Cache entries are ignored and recomputed if cache version/tokenizer source does not match.
|
|
84
|
+
- Per-message and per-conversation overhead are always recomputed at runtime and are not cached.
|
|
85
|
+
- `data-*` and `reasoning` parts are skipped and do not receive cache entries.
|
|
78
86
|
|
|
79
87
|
## Examples
|
|
80
88
|
|
|
@@ -357,161 +365,161 @@ if (inputObservationTokens > 0) {
|
|
|
357
365
|
|
|
358
366
|
Emitted when the Observer or Reflector agent begins processing.
|
|
359
367
|
|
|
360
|
-
**cycleId
|
|
368
|
+
**cycleId** (`string`): Unique ID for this cycle — shared between start/end/failed markers.
|
|
361
369
|
|
|
362
|
-
**operationType
|
|
370
|
+
**operationType** (`'observation' | 'reflection'`): Whether this is an observation or reflection operation.
|
|
363
371
|
|
|
364
|
-
**startedAt
|
|
372
|
+
**startedAt** (`string`): ISO timestamp when processing started.
|
|
365
373
|
|
|
366
|
-
**tokensToObserve
|
|
374
|
+
**tokensToObserve** (`number`): Message tokens (input) being processed in this batch.
|
|
367
375
|
|
|
368
|
-
**recordId
|
|
376
|
+
**recordId** (`string`): The OM record ID.
|
|
369
377
|
|
|
370
|
-
**threadId
|
|
378
|
+
**threadId** (`string`): This thread's ID.
|
|
371
379
|
|
|
372
|
-
**threadIds
|
|
380
|
+
**threadIds** (`string[]`): All thread IDs in this batch (for resource-scoped).
|
|
373
381
|
|
|
374
|
-
**config
|
|
382
|
+
**config** (`ObservationMarkerConfig`): Snapshot of \`messageTokens\`, \`observationTokens\`, and \`scope\` at observation time.
|
|
375
383
|
|
|
376
384
|
### `data-om-observation-end`
|
|
377
385
|
|
|
378
386
|
Emitted when observation or reflection completes successfully.
|
|
379
387
|
|
|
380
|
-
**cycleId
|
|
388
|
+
**cycleId** (`string`): Matches the corresponding \`start\` marker.
|
|
381
389
|
|
|
382
|
-
**operationType
|
|
390
|
+
**operationType** (`'observation' | 'reflection'`): Type of operation that completed.
|
|
383
391
|
|
|
384
|
-
**completedAt
|
|
392
|
+
**completedAt** (`string`): ISO timestamp when processing completed.
|
|
385
393
|
|
|
386
|
-
**durationMs
|
|
394
|
+
**durationMs** (`number`): Duration in milliseconds.
|
|
387
395
|
|
|
388
|
-
**tokensObserved
|
|
396
|
+
**tokensObserved** (`number`): Message tokens (input) that were processed.
|
|
389
397
|
|
|
390
|
-
**observationTokens
|
|
398
|
+
**observationTokens** (`number`): Resulting observation tokens (output) after the Observer compressed them.
|
|
391
399
|
|
|
392
|
-
**observations
|
|
400
|
+
**observations** (`string`): The generated observations text.
|
|
393
401
|
|
|
394
|
-
**currentTask
|
|
402
|
+
**currentTask** (`string`): Current task extracted by the Observer.
|
|
395
403
|
|
|
396
|
-
**suggestedResponse
|
|
404
|
+
**suggestedResponse** (`string`): Suggested response extracted by the Observer.
|
|
397
405
|
|
|
398
|
-
**recordId
|
|
406
|
+
**recordId** (`string`): The OM record ID.
|
|
399
407
|
|
|
400
|
-
**threadId
|
|
408
|
+
**threadId** (`string`): This thread's ID.
|
|
401
409
|
|
|
402
410
|
### `data-om-observation-failed`
|
|
403
411
|
|
|
404
412
|
Emitted when observation or reflection fails. The system falls back to synchronous processing.
|
|
405
413
|
|
|
406
|
-
**cycleId
|
|
414
|
+
**cycleId** (`string`): Matches the corresponding \`start\` marker.
|
|
407
415
|
|
|
408
|
-
**operationType
|
|
416
|
+
**operationType** (`'observation' | 'reflection'`): Type of operation that failed.
|
|
409
417
|
|
|
410
|
-
**failedAt
|
|
418
|
+
**failedAt** (`string`): ISO timestamp when the failure occurred.
|
|
411
419
|
|
|
412
|
-
**durationMs
|
|
420
|
+
**durationMs** (`number`): Duration until failure in milliseconds.
|
|
413
421
|
|
|
414
|
-
**tokensAttempted
|
|
422
|
+
**tokensAttempted** (`number`): Message tokens (input) that were attempted.
|
|
415
423
|
|
|
416
|
-
**error
|
|
424
|
+
**error** (`string`): Error message.
|
|
417
425
|
|
|
418
|
-
**observations
|
|
426
|
+
**observations** (`string`): Any partial content available for display.
|
|
419
427
|
|
|
420
|
-
**recordId
|
|
428
|
+
**recordId** (`string`): The OM record ID.
|
|
421
429
|
|
|
422
|
-
**threadId
|
|
430
|
+
**threadId** (`string`): This thread's ID.
|
|
423
431
|
|
|
424
432
|
### `data-om-buffering-start`
|
|
425
433
|
|
|
426
434
|
Emitted when async buffering begins in the background. Buffering pre-computes observations or reflections before the main threshold is reached.
|
|
427
435
|
|
|
428
|
-
**cycleId
|
|
436
|
+
**cycleId** (`string`): Unique ID for this buffering cycle.
|
|
429
437
|
|
|
430
|
-
**operationType
|
|
438
|
+
**operationType** (`'observation' | 'reflection'`): Type of operation being buffered.
|
|
431
439
|
|
|
432
|
-
**startedAt
|
|
440
|
+
**startedAt** (`string`): ISO timestamp when buffering started.
|
|
433
441
|
|
|
434
|
-
**tokensToBuffer
|
|
442
|
+
**tokensToBuffer** (`number`): Message tokens (input) being buffered in this cycle.
|
|
435
443
|
|
|
436
|
-
**recordId
|
|
444
|
+
**recordId** (`string`): The OM record ID.
|
|
437
445
|
|
|
438
|
-
**threadId
|
|
446
|
+
**threadId** (`string`): This thread's ID.
|
|
439
447
|
|
|
440
|
-
**threadIds
|
|
448
|
+
**threadIds** (`string[]`): All thread IDs being buffered (for resource-scoped).
|
|
441
449
|
|
|
442
|
-
**config
|
|
450
|
+
**config** (`ObservationMarkerConfig`): Snapshot of config at buffering time.
|
|
443
451
|
|
|
444
452
|
### `data-om-buffering-end`
|
|
445
453
|
|
|
446
454
|
Emitted when async buffering completes. The content is stored but not yet activated in the main context.
|
|
447
455
|
|
|
448
|
-
**cycleId
|
|
456
|
+
**cycleId** (`string`): Matches the corresponding \`buffering-start\` marker.
|
|
449
457
|
|
|
450
|
-
**operationType
|
|
458
|
+
**operationType** (`'observation' | 'reflection'`): Type of operation that was buffered.
|
|
451
459
|
|
|
452
|
-
**completedAt
|
|
460
|
+
**completedAt** (`string`): ISO timestamp when buffering completed.
|
|
453
461
|
|
|
454
|
-
**durationMs
|
|
462
|
+
**durationMs** (`number`): Duration in milliseconds.
|
|
455
463
|
|
|
456
|
-
**tokensBuffered
|
|
464
|
+
**tokensBuffered** (`number`): Message tokens (input) that were buffered.
|
|
457
465
|
|
|
458
|
-
**bufferedTokens
|
|
466
|
+
**bufferedTokens** (`number`): Observation tokens (output) after the Observer compressed them.
|
|
459
467
|
|
|
460
|
-
**observations
|
|
468
|
+
**observations** (`string`): The buffered content.
|
|
461
469
|
|
|
462
|
-
**recordId
|
|
470
|
+
**recordId** (`string`): The OM record ID.
|
|
463
471
|
|
|
464
|
-
**threadId
|
|
472
|
+
**threadId** (`string`): This thread's ID.
|
|
465
473
|
|
|
466
474
|
### `data-om-buffering-failed`
|
|
467
475
|
|
|
468
476
|
Emitted when async buffering fails. The system falls back to synchronous processing when the threshold is reached.
|
|
469
477
|
|
|
470
|
-
**cycleId
|
|
478
|
+
**cycleId** (`string`): Matches the corresponding \`buffering-start\` marker.
|
|
471
479
|
|
|
472
|
-
**operationType
|
|
480
|
+
**operationType** (`'observation' | 'reflection'`): Type of operation that failed.
|
|
473
481
|
|
|
474
|
-
**failedAt
|
|
482
|
+
**failedAt** (`string`): ISO timestamp when the failure occurred.
|
|
475
483
|
|
|
476
|
-
**durationMs
|
|
484
|
+
**durationMs** (`number`): Duration until failure in milliseconds.
|
|
477
485
|
|
|
478
|
-
**tokensAttempted
|
|
486
|
+
**tokensAttempted** (`number`): Message tokens (input) that were attempted to buffer.
|
|
479
487
|
|
|
480
|
-
**error
|
|
488
|
+
**error** (`string`): Error message.
|
|
481
489
|
|
|
482
|
-
**observations
|
|
490
|
+
**observations** (`string`): Any partial content.
|
|
483
491
|
|
|
484
|
-
**recordId
|
|
492
|
+
**recordId** (`string`): The OM record ID.
|
|
485
493
|
|
|
486
|
-
**threadId
|
|
494
|
+
**threadId** (`string`): This thread's ID.
|
|
487
495
|
|
|
488
496
|
### `data-om-activation`
|
|
489
497
|
|
|
490
498
|
Emitted when buffered observations or reflections are activated (moved into the active context window). This is an instant operation — no LLM call is involved.
|
|
491
499
|
|
|
492
|
-
**cycleId
|
|
500
|
+
**cycleId** (`string`): Unique ID for this activation event.
|
|
493
501
|
|
|
494
|
-
**operationType
|
|
502
|
+
**operationType** (`'observation' | 'reflection'`): Type of content activated.
|
|
495
503
|
|
|
496
|
-
**activatedAt
|
|
504
|
+
**activatedAt** (`string`): ISO timestamp when activation occurred.
|
|
497
505
|
|
|
498
|
-
**chunksActivated
|
|
506
|
+
**chunksActivated** (`number`): Number of buffered chunks activated.
|
|
499
507
|
|
|
500
|
-
**tokensActivated
|
|
508
|
+
**tokensActivated** (`number`): Message tokens (input) from activated chunks. For observation activation, these are removed from the message window. For reflection activation, this is the observation tokens that were compressed.
|
|
501
509
|
|
|
502
|
-
**observationTokens
|
|
510
|
+
**observationTokens** (`number`): Resulting observation tokens after activation.
|
|
503
511
|
|
|
504
|
-
**messagesActivated
|
|
512
|
+
**messagesActivated** (`number`): Number of messages that were observed via activation.
|
|
505
513
|
|
|
506
|
-
**generationCount
|
|
514
|
+
**generationCount** (`number`): Current reflection generation count.
|
|
507
515
|
|
|
508
|
-
**observations
|
|
516
|
+
**observations** (`string`): The activated observations text.
|
|
509
517
|
|
|
510
|
-
**recordId
|
|
518
|
+
**recordId** (`string`): The OM record ID.
|
|
511
519
|
|
|
512
|
-
**threadId
|
|
520
|
+
**threadId** (`string`): This thread's ID.
|
|
513
521
|
|
|
514
|
-
**config
|
|
522
|
+
**config** (`ObservationMarkerConfig`): Snapshot of config at activation time.
|
|
515
523
|
|
|
516
524
|
## Standalone usage
|
|
517
525
|
|
|
@@ -552,11 +560,11 @@ export const agent = new Agent({
|
|
|
552
560
|
|
|
553
561
|
The standalone `ObservationalMemory` class accepts all the same options as the `observationalMemory` config object above, plus the following:
|
|
554
562
|
|
|
555
|
-
**storage
|
|
563
|
+
**storage** (`MemoryStorage`): Storage adapter for persisting observations. Must be a MemoryStorage instance (from \`MastraStorage.stores.memory\`).
|
|
556
564
|
|
|
557
|
-
**onDebugEvent
|
|
565
|
+
**onDebugEvent** (`(event: ObservationDebugEvent) => void`): Debug callback for observation events. Called whenever observation-related events occur. Useful for debugging and understanding the observation flow.
|
|
558
566
|
|
|
559
|
-
**obscureThreadIds
|
|
567
|
+
**obscureThreadIds** (`boolean`): When enabled, thread IDs are hashed before being included in observation context. This prevents the LLM from recognizing patterns in thread identifiers. Automatically enabled when using resource scope through the Memory class. (Default: `false`)
|
|
560
568
|
|
|
561
569
|
### Related
|
|
562
570
|
|
|
@@ -19,31 +19,29 @@ const processor = new TokenLimiterProcessor({
|
|
|
19
19
|
|
|
20
20
|
## Constructor parameters
|
|
21
21
|
|
|
22
|
-
**options
|
|
22
|
+
**options** (`number | Options`): Either a simple number for token limit, or configuration options object
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
**options.limit** (`number`): Maximum number of tokens to allow in the response
|
|
25
25
|
|
|
26
|
-
**
|
|
26
|
+
**options.encoding** (`TiktokenBPE`): Optional encoding to use. Defaults to o200k\_base which is used by gpt-5.1
|
|
27
27
|
|
|
28
|
-
**
|
|
28
|
+
**options.strategy** (`'truncate' | 'abort'`): Strategy when token limit is reached: 'truncate' stops emitting chunks, 'abort' calls abort() to stop the stream
|
|
29
29
|
|
|
30
|
-
**
|
|
31
|
-
|
|
32
|
-
**countMode?:** (`'cumulative' | 'part'`): Whether to count tokens from the beginning of the stream or just the current part: 'cumulative' counts all tokens from start, 'part' only counts tokens in current part
|
|
30
|
+
**options.countMode** (`'cumulative' | 'part'`): Whether to count tokens from the beginning of the stream or just the current part: 'cumulative' counts all tokens from start, 'part' only counts tokens in current part
|
|
33
31
|
|
|
34
32
|
## Returns
|
|
35
33
|
|
|
36
|
-
**id
|
|
34
|
+
**id** (`string`): Processor identifier set to 'token-limiter'
|
|
37
35
|
|
|
38
|
-
**name
|
|
36
|
+
**name** (`string`): Optional processor display name
|
|
39
37
|
|
|
40
|
-
**processInput
|
|
38
|
+
**processInput** (`(args: { messages: MastraDBMessage[]; abort: (reason?: string) => never }) => Promise<MastraDBMessage[]>`): Filters input messages to fit within token limit, prioritizing recent messages while preserving system messages
|
|
41
39
|
|
|
42
|
-
**processOutputStream
|
|
40
|
+
**processOutputStream** (`(args: { part: ChunkType; streamParts: ChunkType[]; state: Record<string, any>; abort: (reason?: string) => never }) => Promise<ChunkType | null>`): Processes streaming output parts to limit token count during streaming
|
|
43
41
|
|
|
44
|
-
**processOutputResult
|
|
42
|
+
**processOutputResult** (`(args: { messages: MastraDBMessage[]; abort: (reason?: string) => never }) => Promise<MastraDBMessage[]>`): Processes final output results to limit token count in non-streaming scenarios
|
|
45
43
|
|
|
46
|
-
**getMaxTokens
|
|
44
|
+
**getMaxTokens** (`() => number`): Get the maximum token limit
|
|
47
45
|
|
|
48
46
|
## Error behavior
|
|
49
47
|
|
|
@@ -108,17 +108,17 @@ For local development, you can use [DynamoDB Local](https://docs.aws.amazon.com/
|
|
|
108
108
|
|
|
109
109
|
## Parameters
|
|
110
110
|
|
|
111
|
-
**id
|
|
111
|
+
**id** (`string`): Unique identifier for this storage instance.
|
|
112
112
|
|
|
113
|
-
**config.tableName
|
|
113
|
+
**config.tableName** (`string`): The name of your DynamoDB table.
|
|
114
114
|
|
|
115
|
-
**config.region
|
|
115
|
+
**config.region** (`string`): AWS region. Defaults to 'us-east-1'. For local development, can be set to 'localhost' or similar.
|
|
116
116
|
|
|
117
|
-
**config.endpoint
|
|
117
|
+
**config.endpoint** (`string`): Custom endpoint for DynamoDB (e.g., 'http\://localhost:8000' for local development).
|
|
118
118
|
|
|
119
|
-
**config.credentials
|
|
119
|
+
**config.credentials** (`object`): AWS credentials object with \`accessKeyId\` and \`secretAccessKey\`. If not provided, the AWS SDK will attempt to source credentials from environment variables, IAM roles (e.g., for EC2/Lambda), or the shared AWS credentials file.
|
|
120
120
|
|
|
121
|
-
**config.ttl
|
|
121
|
+
**config.ttl** (`object`): TTL (Time To Live) configuration for automatic data expiration. Configure per entity type: thread, message, trace, eval, workflow\_snapshot, resource, score. Each entity config includes: enabled (boolean), attributeName (string, default: 'ttl'), defaultTtlSeconds (number).
|
|
122
122
|
|
|
123
123
|
## TTL (Time To Live) Configuration
|
|
124
124
|
|
|
@@ -188,11 +188,11 @@ TTL can be configured for these entity types:
|
|
|
188
188
|
|
|
189
189
|
Each entity type accepts the following configuration:
|
|
190
190
|
|
|
191
|
-
**enabled
|
|
191
|
+
**enabled** (`boolean`): Whether TTL is enabled for this entity type.
|
|
192
192
|
|
|
193
|
-
**attributeName
|
|
193
|
+
**attributeName** (`string`): The DynamoDB attribute name to use for TTL. Must match the TTL attribute configured on your DynamoDB table. Defaults to 'ttl'.
|
|
194
194
|
|
|
195
|
-
**defaultTtlSeconds
|
|
195
|
+
**defaultTtlSeconds** (`number`): Default TTL in seconds from item creation time. Items will be automatically deleted by DynamoDB after this duration.
|
|
196
196
|
|
|
197
197
|
### Enabling TTL on Your DynamoDB Table
|
|
198
198
|
|
|
@@ -89,9 +89,9 @@ storage: new LibSQLStore({
|
|
|
89
89
|
|
|
90
90
|
## Options
|
|
91
91
|
|
|
92
|
-
**url
|
|
92
|
+
**url** (`string`): Database URL. Use \`:memory:\` for in-memory database, \`file:filename.db\` for a file database, or a libSQL connection string (e.g., \`libsql://your-database.turso.io\`) for remote storage.
|
|
93
93
|
|
|
94
|
-
**authToken
|
|
94
|
+
**authToken** (`string`): Authentication token for remote libSQL databases.
|
|
95
95
|
|
|
96
96
|
## Initialization
|
|
97
97
|
|
|
@@ -44,15 +44,15 @@ const storage = new MongoDBStore({
|
|
|
44
44
|
|
|
45
45
|
## Parameters
|
|
46
46
|
|
|
47
|
-
**id
|
|
47
|
+
**id** (`string`): Unique identifier for this storage instance.
|
|
48
48
|
|
|
49
|
-
**uri
|
|
49
|
+
**uri** (`string`): MongoDB connection string (e.g., mongodb+srv://user:password\@cluster.mongodb.net)
|
|
50
50
|
|
|
51
|
-
**url
|
|
51
|
+
**url** (`string`): Deprecated. Use uri instead. MongoDB connection string (supported for backward compatibility).
|
|
52
52
|
|
|
53
|
-
**dbName
|
|
53
|
+
**dbName** (`string`): The name of the database you want the storage to use.
|
|
54
54
|
|
|
55
|
-
**options
|
|
55
|
+
**options** (`MongoClientOptions`): MongoDB client options for advanced configuration (SSL, connection pooling, etc.).
|
|
56
56
|
|
|
57
57
|
> **Deprecation Notice:** The `url` parameter is deprecated but still supported for backward compatibility. Please use `uri` instead in all new code.
|
|
58
58
|
|