@mastra/memory 1.6.2 → 1.7.0-alpha.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.
@@ -3,7 +3,7 @@ name: mastra-memory
3
3
  description: Documentation for @mastra/memory. Use when working with @mastra/memory APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/memory"
6
- version: "1.6.2"
6
+ version: "1.7.0-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -26,7 +26,7 @@ Read the individual reference documents for detailed explanations and code examp
26
26
  - [Observational memory](references/docs-memory-observational-memory.md) - Learn how Observational Memory keeps your agent's context window small while preserving long-term memory across conversations.
27
27
  - [Memory overview](references/docs-memory-overview.md) - Learn how Mastra's memory system works with working memory, message history, semantic recall, and observational memory.
28
28
  - [Semantic recall](references/docs-memory-semantic-recall.md) - Learn how to use semantic recall in Mastra to retrieve relevant messages from past conversations using vector search and embeddings.
29
- - [Storage](references/docs-memory-storage.md) - Configure storage for Mastra's memory system to persist conversations, workflows, and traces.
29
+ - [Storage](references/docs-memory-storage.md) - Configure storage for Mastra to persist conversations and other runtime state.
30
30
  - [Working memory](references/docs-memory-working-memory.md) - Learn how to configure working memory in Mastra to store persistent user data, preferences.
31
31
 
32
32
  ### Reference
@@ -1,71 +1,71 @@
1
1
  {
2
- "version": "1.6.2",
2
+ "version": "1.7.0-alpha.1",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {
5
5
  "OBSERVATIONAL_MEMORY_DEFAULTS": {
6
6
  "types": "dist/processors/index.d.ts",
7
- "implementation": "dist/chunk-3CM4XQJO.js"
7
+ "implementation": "dist/chunk-M7RAJAZ6.js"
8
8
  },
9
9
  "OBSERVATION_CONTEXT_INSTRUCTIONS": {
10
10
  "types": "dist/processors/index.d.ts",
11
- "implementation": "dist/chunk-3CM4XQJO.js"
11
+ "implementation": "dist/chunk-M7RAJAZ6.js"
12
12
  },
13
13
  "OBSERVATION_CONTEXT_PROMPT": {
14
14
  "types": "dist/processors/index.d.ts",
15
- "implementation": "dist/chunk-3CM4XQJO.js"
15
+ "implementation": "dist/chunk-M7RAJAZ6.js"
16
16
  },
17
17
  "OBSERVATION_CONTINUATION_HINT": {
18
18
  "types": "dist/processors/index.d.ts",
19
- "implementation": "dist/chunk-3CM4XQJO.js"
19
+ "implementation": "dist/chunk-M7RAJAZ6.js"
20
20
  },
21
21
  "OBSERVER_SYSTEM_PROMPT": {
22
22
  "types": "dist/processors/index.d.ts",
23
- "implementation": "dist/chunk-3CM4XQJO.js"
23
+ "implementation": "dist/chunk-M7RAJAZ6.js"
24
24
  },
25
25
  "ObservationalMemory": {
26
26
  "types": "dist/processors/index.d.ts",
27
- "implementation": "dist/chunk-3CM4XQJO.js",
28
- "line": 2907
27
+ "implementation": "dist/chunk-M7RAJAZ6.js",
28
+ "line": 2890
29
29
  },
30
30
  "TokenCounter": {
31
31
  "types": "dist/processors/index.d.ts",
32
- "implementation": "dist/chunk-3CM4XQJO.js",
33
- "line": 2385
32
+ "implementation": "dist/chunk-M7RAJAZ6.js",
33
+ "line": 2371
34
34
  },
35
35
  "buildObserverPrompt": {
36
36
  "types": "dist/processors/index.d.ts",
37
- "implementation": "dist/chunk-3CM4XQJO.js",
38
- "line": 993
37
+ "implementation": "dist/chunk-M7RAJAZ6.js",
38
+ "line": 992
39
39
  },
40
40
  "buildObserverSystemPrompt": {
41
41
  "types": "dist/processors/index.d.ts",
42
- "implementation": "dist/chunk-3CM4XQJO.js",
43
- "line": 573
42
+ "implementation": "dist/chunk-M7RAJAZ6.js",
43
+ "line": 572
44
44
  },
45
45
  "extractCurrentTask": {
46
46
  "types": "dist/processors/index.d.ts",
47
- "implementation": "dist/chunk-3CM4XQJO.js",
48
- "line": 1101
47
+ "implementation": "dist/chunk-M7RAJAZ6.js",
48
+ "line": 1100
49
49
  },
50
50
  "formatMessagesForObserver": {
51
51
  "types": "dist/processors/index.d.ts",
52
- "implementation": "dist/chunk-3CM4XQJO.js",
53
- "line": 820
52
+ "implementation": "dist/chunk-M7RAJAZ6.js",
53
+ "line": 819
54
54
  },
55
55
  "hasCurrentTaskSection": {
56
56
  "types": "dist/processors/index.d.ts",
57
- "implementation": "dist/chunk-3CM4XQJO.js",
58
- "line": 1089
57
+ "implementation": "dist/chunk-M7RAJAZ6.js",
58
+ "line": 1088
59
59
  },
60
60
  "optimizeObservationsForContext": {
61
61
  "types": "dist/processors/index.d.ts",
62
- "implementation": "dist/chunk-3CM4XQJO.js",
63
- "line": 1112
62
+ "implementation": "dist/chunk-M7RAJAZ6.js",
63
+ "line": 1111
64
64
  },
65
65
  "parseObserverOutput": {
66
66
  "types": "dist/processors/index.d.ts",
67
- "implementation": "dist/chunk-3CM4XQJO.js",
68
- "line": 1003
67
+ "implementation": "dist/chunk-M7RAJAZ6.js",
68
+ "line": 1002
69
69
  },
70
70
  "extractWorkingMemoryContent": {
71
71
  "types": "dist/index.d.ts",
@@ -96,7 +96,7 @@
96
96
  "processors": {
97
97
  "index": "dist/processors/index.js",
98
98
  "chunks": [
99
- "chunk-3CM4XQJO.js"
99
+ "chunk-M7RAJAZ6.js"
100
100
  ]
101
101
  }
102
102
  }
@@ -61,7 +61,7 @@ OM solves both problems by compressing old context into dense observations.
61
61
 
62
62
  When message history tokens exceed a threshold (default: 30,000), the Observer creates observations — concise notes about what happened:
63
63
 
64
- Image parts contribute to this threshold with model-aware estimates, so multimodal conversations trigger observation at the right time. The same applies to image-like `file` parts when a transport normalizes an uploaded image as a file instead of an image part. For example, OpenAI image detail settings can materially change when OM decides to observe.
64
+ OM uses fast local token estimation for this thresholding work. Text is estimated with `tokenx`, while image parts use provider-aware heuristics so multimodal conversations still trigger observation at the right time. The same applies to image-like `file` parts when a transport normalizes an uploaded image as a file instead of an image part. For example, OpenAI image detail settings can materially change when OM decides to observe.
65
65
 
66
66
  The Observer can also see attachments in the history it reviews. OM keeps readable placeholders like `[Image #1: reference-board.png]` or `[File #1: floorplan.pdf]` in the transcript for readability, and forwards the actual attachment parts alongside the text. Image-like `file` parts are upgraded to image inputs for the Observer when possible, while non-image attachments are forwarded as file parts with normalized token counting. This applies to both normal thread observation and batched resource-scope observation.
67
67
 
@@ -176,7 +176,7 @@ const memory = new Memory({
176
176
 
177
177
  ### Token counting cache
178
178
 
179
- OM caches tiktoken part estimates in message metadata to reduce repeat counting work during threshold checks and buffering decisions.
179
+ OM caches token estimates in message metadata to reduce repeat counting work during threshold checks and buffering decisions.
180
180
 
181
181
  - Per-part estimates are stored on `part.providerMetadata.mastra` and reused on subsequent passes when the cache version/tokenizer source matches.
182
182
  - For string-only message content (without parts), OM uses a message-level metadata fallback cache.
@@ -1,6 +1,6 @@
1
1
  # Storage
2
2
 
3
- For agents to remember previous interactions, Mastra needs a database. Use a storage adapter for one of the [supported databases](#supported-providers) and pass it to your Mastra instance.
3
+ For agents to remember previous interactions, Mastra needs a storage adapter. Use one of the [supported providers](#supported-providers) and pass it to your Mastra instance.
4
4
 
5
5
  ```typescript
6
6
  import { Mastra } from '@mastra/core'
@@ -24,7 +24,7 @@ export const mastra = new Mastra({
24
24
 
25
25
  This configures instance-level storage, which all agents share by default. You can also configure [agent-level storage](#agent-level-storage) for isolated data boundaries.
26
26
 
27
- Mastra automatically creates the necessary tables on first interaction. See the [core schema](https://mastra.ai/reference/storage/overview) for details on what gets created, including tables for messages, threads, resources, workflows, traces, and evaluation datasets.
27
+ Mastra automatically initializes the necessary storage structures on first interaction. See [Storage Overview](https://mastra.ai/reference/storage/overview) for domain coverage and the schema used by the built-in database-backed domains.
28
28
 
29
29
  ## Supported providers
30
30
 
@@ -35,7 +35,7 @@ Each provider page includes installation instructions, configuration parameters,
35
35
  - [MongoDB](https://mastra.ai/reference/storage/mongodb)
36
36
  - [Upstash](https://mastra.ai/reference/storage/upstash)
37
37
  - [Cloudflare D1](https://mastra.ai/reference/storage/cloudflare-d1)
38
- - [Cloudflare Durable Objects](https://mastra.ai/reference/storage/cloudflare)
38
+ - [Cloudflare KV & Durable Objects](https://mastra.ai/reference/storage/cloudflare)
39
39
  - [Convex](https://mastra.ai/reference/storage/convex)
40
40
  - [DynamoDB](https://mastra.ai/reference/storage/dynamodb)
41
41
  - [LanceDB](https://mastra.ai/reference/storage/lance)
@@ -49,7 +49,7 @@ Storage can be configured at the instance level (shared by all agents) or at the
49
49
 
50
50
  ### Instance-level storage
51
51
 
52
- Add storage to your Mastra instance so all agents, workflows, observability traces and scores share the same memory provider:
52
+ Add storage to your Mastra instance so all agents, workflows, observability traces, and scores share the same storage backend:
53
53
 
54
54
  ```typescript
55
55
  import { Mastra } from '@mastra/core'
@@ -71,7 +71,7 @@ This is useful when all primitives share the same storage backend and have simil
71
71
 
72
72
  #### Composite storage
73
73
 
74
- [Composite storage](https://mastra.ai/reference/storage/composite) is an alternative way to configure instance-level storage. Use `MastraCompositeStore` to set the `memory` domain (and any other [domains](https://mastra.ai/reference/storage/composite) you need) to different storage providers.
74
+ [Composite storage](https://mastra.ai/reference/storage/composite) is an alternative way to configure instance-level storage. Use `MastraCompositeStore` to route `memory` and any other [supported domains](https://mastra.ai/reference/storage/composite) to different storage providers.
75
75
 
76
76
  ```typescript
77
77
  import { Mastra } from '@mastra/core'
@@ -28,6 +28,8 @@ The `observationalMemory` option accepts `true`, a configuration object, or `fal
28
28
 
29
29
  Observer input is multimodal-aware. OM keeps text placeholders like `[Image #1: screenshot.png]` in the transcript it builds for the Observer, and also sends the underlying image parts when possible. This applies to both single-thread observation and batched multi-thread observation. Non-image files appear as placeholders only.
30
30
 
31
+ OM performs thresholding with fast local token estimation. Text uses `tokenx`, and image-like inputs use provider-aware heuristics plus deterministic fallbacks when metadata is incomplete.
32
+
31
33
  **enabled** (`boolean`): Enable or disable Observational Memory. When omitted from a config object, defaults to \`true\`. Only \`enabled: false\` explicitly disables it. (Default: `true`)
32
34
 
33
35
  **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)`)
@@ -42,7 +44,7 @@ Observer input is multimodal-aware. OM keeps text placeholders like `[Image #1:
42
44
 
43
45
  **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.
44
46
 
45
- **observation.messageTokens** (`number`): Token count of unobserved messages that triggers observation. When unobserved message tokens exceed this threshold, the Observer agent is called. Image parts are included with model-aware estimates when possible, with deterministic fallbacks when image metadata is incomplete. Image-like \`file\` parts are counted the same way when uploads are normalized as files.
47
+ **observation.messageTokens** (`number`): Token count of unobserved messages that triggers observation. When unobserved message tokens exceed this threshold, the Observer agent is called. Text is estimated locally with \`tokenx\`. Image parts are included with model-aware heuristics when possible, with deterministic fallbacks when image metadata is incomplete. Image-like \`file\` parts are counted the same way when uploads are normalized as files.
46
48
 
47
49
  **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.
48
50
 
@@ -78,7 +80,7 @@ Observer input is multimodal-aware. OM keeps text placeholders like `[Image #1:
78
80
 
79
81
  ### Token estimate metadata cache
80
82
 
81
- OM persists token payload estimates so repeated counting can reuse prior tiktoken work.
83
+ OM persists token payload estimates so repeated counting can reuse prior token estimation work.
82
84
 
83
85
  - Part-level cache: `part.providerMetadata.mastra`.
84
86
  - String-content fallback cache: message-level metadata when no parts exist.
@@ -1,8 +1,9 @@
1
1
  # TokenLimiterProcessor
2
2
 
3
- The `TokenLimiterProcessor` limits the number of tokens in messages. It can be used as both an input and output processor:
3
+ The `TokenLimiterProcessor` limits the number of tokens in messages. It can be used as an input, per-step input, and output processor:
4
4
 
5
- - **Input processor**: Filters historical messages to fit within the context window, prioritizing recent messages
5
+ - **Input processor** (`processInput`): Filters historical messages to fit within the context window before the agentic loop starts, prioritizing recent messages
6
+ - **Per-step input processor** (`processInputStep`): Prunes messages at each step of a multi-step agent workflow, preventing unbounded token growth when tools trigger additional LLM calls
6
7
  - **Output processor**: Limits generated response tokens via streaming or non-streaming with configurable strategies for handling exceeded limits
7
8
 
8
9
  ## Usage example
@@ -35,7 +36,9 @@ const processor = new TokenLimiterProcessor({
35
36
 
36
37
  **name** (`string`): Optional processor display name
37
38
 
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
39
+ **processInput** (`(args: { messages: MastraDBMessage[]; abort: (reason?: string) => never }) => Promise<MastraDBMessage[]>`): Filters input messages to fit within token limit before the agentic loop starts, prioritizing recent messages while preserving system messages
40
+
41
+ **processInputStep** (`(args: ProcessInputStepArgs) => Promise<void>`): Prunes messages at each step of the agentic loop (including tool call continuations) to keep the conversation within the token limit. Mutates the messageList directly by removing oldest messages first while preserving system messages.
39
42
 
40
43
  **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
41
44
 
@@ -45,7 +48,7 @@ const processor = new TokenLimiterProcessor({
45
48
 
46
49
  ## Error behavior
47
50
 
48
- When used as an input processor, `TokenLimiterProcessor` throws a `TripWire` error in the following cases:
51
+ When used as an input processor (both `processInput` and `processInputStep`), `TokenLimiterProcessor` throws a `TripWire` error in the following cases:
49
52
 
50
53
  - **Empty messages**: If there are no messages to process, a TripWire is thrown because you can't send an LLM request with no messages.
51
54
  - **System messages exceed limit**: If system messages alone exceed the token limit, a TripWire is thrown because you can't send an LLM request with only system messages and no user/assistant messages.
@@ -86,6 +89,29 @@ export const agent = new Agent({
86
89
  })
87
90
  ```
88
91
 
92
+ ### As a per-step input processor (limit multi-step token growth)
93
+
94
+ When an agent uses tools across multiple steps (e.g. `maxSteps > 1`), each step accumulates conversation history from all previous steps. Use `inputProcessors` to also limit tokens at each step of the agentic loop — the `TokenLimiterProcessor` automatically applies to both the initial input and every subsequent step:
95
+
96
+ ```typescript
97
+ import { Agent } from '@mastra/core/agent'
98
+ import { TokenLimiterProcessor } from '@mastra/core/processors'
99
+
100
+ export const agent = new Agent({
101
+ name: 'multi-step-agent',
102
+ instructions: 'You are a helpful research assistant with access to tools',
103
+ model: 'openai/gpt-4o',
104
+ inputProcessors: [
105
+ new TokenLimiterProcessor({ limit: 8000 }), // Applied at every step
106
+ ],
107
+ })
108
+
109
+ // Each tool call step will be limited to ~8000 input tokens
110
+ const result = await agent.generate('Research this topic using your tools', {
111
+ maxSteps: 10,
112
+ })
113
+ ```
114
+
89
115
  ### As an output processor (limit response length)
90
116
 
91
117
  Use `outputProcessors` to limit the length of generated responses:
package/dist/index.cjs CHANGED
@@ -16688,7 +16688,7 @@ Notes:
16688
16688
  "Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
16689
16689
  );
16690
16690
  }
16691
- const { ObservationalMemory } = await import('./observational-memory-C5LO7RBR.cjs');
16691
+ const { ObservationalMemory } = await import('./observational-memory-AU6MIH4Q.cjs');
16692
16692
  return new ObservationalMemory({
16693
16693
  storage: memoryStore,
16694
16694
  scope: omConfig.scope,
package/dist/index.js CHANGED
@@ -16665,7 +16665,7 @@ Notes:
16665
16665
  "Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
16666
16666
  );
16667
16667
  }
16668
- const { ObservationalMemory } = await import('./observational-memory-OYK4MEUD.js');
16668
+ const { ObservationalMemory } = await import('./observational-memory-YRWU6CY3.js');
16669
16669
  return new ObservationalMemory({
16670
16670
  storage: memoryStore,
16671
16671
  scope: omConfig.scope,
@@ -1,64 +1,64 @@
1
1
  'use strict';
2
2
 
3
- var chunk5W5463NI_cjs = require('./chunk-5W5463NI.cjs');
3
+ var chunkSHID74TI_cjs = require('./chunk-SHID74TI.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "OBSERVATIONAL_MEMORY_DEFAULTS", {
8
8
  enumerable: true,
9
- get: function () { return chunk5W5463NI_cjs.OBSERVATIONAL_MEMORY_DEFAULTS; }
9
+ get: function () { return chunkSHID74TI_cjs.OBSERVATIONAL_MEMORY_DEFAULTS; }
10
10
  });
11
11
  Object.defineProperty(exports, "OBSERVATION_CONTEXT_INSTRUCTIONS", {
12
12
  enumerable: true,
13
- get: function () { return chunk5W5463NI_cjs.OBSERVATION_CONTEXT_INSTRUCTIONS; }
13
+ get: function () { return chunkSHID74TI_cjs.OBSERVATION_CONTEXT_INSTRUCTIONS; }
14
14
  });
15
15
  Object.defineProperty(exports, "OBSERVATION_CONTEXT_PROMPT", {
16
16
  enumerable: true,
17
- get: function () { return chunk5W5463NI_cjs.OBSERVATION_CONTEXT_PROMPT; }
17
+ get: function () { return chunkSHID74TI_cjs.OBSERVATION_CONTEXT_PROMPT; }
18
18
  });
19
19
  Object.defineProperty(exports, "OBSERVATION_CONTINUATION_HINT", {
20
20
  enumerable: true,
21
- get: function () { return chunk5W5463NI_cjs.OBSERVATION_CONTINUATION_HINT; }
21
+ get: function () { return chunkSHID74TI_cjs.OBSERVATION_CONTINUATION_HINT; }
22
22
  });
23
23
  Object.defineProperty(exports, "OBSERVER_SYSTEM_PROMPT", {
24
24
  enumerable: true,
25
- get: function () { return chunk5W5463NI_cjs.OBSERVER_SYSTEM_PROMPT; }
25
+ get: function () { return chunkSHID74TI_cjs.OBSERVER_SYSTEM_PROMPT; }
26
26
  });
27
27
  Object.defineProperty(exports, "ObservationalMemory", {
28
28
  enumerable: true,
29
- get: function () { return chunk5W5463NI_cjs.ObservationalMemory; }
29
+ get: function () { return chunkSHID74TI_cjs.ObservationalMemory; }
30
30
  });
31
31
  Object.defineProperty(exports, "TokenCounter", {
32
32
  enumerable: true,
33
- get: function () { return chunk5W5463NI_cjs.TokenCounter; }
33
+ get: function () { return chunkSHID74TI_cjs.TokenCounter; }
34
34
  });
35
35
  Object.defineProperty(exports, "buildObserverPrompt", {
36
36
  enumerable: true,
37
- get: function () { return chunk5W5463NI_cjs.buildObserverPrompt; }
37
+ get: function () { return chunkSHID74TI_cjs.buildObserverPrompt; }
38
38
  });
39
39
  Object.defineProperty(exports, "buildObserverSystemPrompt", {
40
40
  enumerable: true,
41
- get: function () { return chunk5W5463NI_cjs.buildObserverSystemPrompt; }
41
+ get: function () { return chunkSHID74TI_cjs.buildObserverSystemPrompt; }
42
42
  });
43
43
  Object.defineProperty(exports, "extractCurrentTask", {
44
44
  enumerable: true,
45
- get: function () { return chunk5W5463NI_cjs.extractCurrentTask; }
45
+ get: function () { return chunkSHID74TI_cjs.extractCurrentTask; }
46
46
  });
47
47
  Object.defineProperty(exports, "formatMessagesForObserver", {
48
48
  enumerable: true,
49
- get: function () { return chunk5W5463NI_cjs.formatMessagesForObserver; }
49
+ get: function () { return chunkSHID74TI_cjs.formatMessagesForObserver; }
50
50
  });
51
51
  Object.defineProperty(exports, "hasCurrentTaskSection", {
52
52
  enumerable: true,
53
- get: function () { return chunk5W5463NI_cjs.hasCurrentTaskSection; }
53
+ get: function () { return chunkSHID74TI_cjs.hasCurrentTaskSection; }
54
54
  });
55
55
  Object.defineProperty(exports, "optimizeObservationsForContext", {
56
56
  enumerable: true,
57
- get: function () { return chunk5W5463NI_cjs.optimizeObservationsForContext; }
57
+ get: function () { return chunkSHID74TI_cjs.optimizeObservationsForContext; }
58
58
  });
59
59
  Object.defineProperty(exports, "parseObserverOutput", {
60
60
  enumerable: true,
61
- get: function () { return chunk5W5463NI_cjs.parseObserverOutput; }
61
+ get: function () { return chunkSHID74TI_cjs.parseObserverOutput; }
62
62
  });
63
- //# sourceMappingURL=observational-memory-C5LO7RBR.cjs.map
64
- //# sourceMappingURL=observational-memory-C5LO7RBR.cjs.map
63
+ //# sourceMappingURL=observational-memory-AU6MIH4Q.cjs.map
64
+ //# sourceMappingURL=observational-memory-AU6MIH4Q.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-C5LO7RBR.cjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-AU6MIH4Q.cjs"}
@@ -1,3 +1,3 @@
1
- export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput } from './chunk-3CM4XQJO.js';
2
- //# sourceMappingURL=observational-memory-OYK4MEUD.js.map
3
- //# sourceMappingURL=observational-memory-OYK4MEUD.js.map
1
+ export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput } from './chunk-M7RAJAZ6.js';
2
+ //# sourceMappingURL=observational-memory-YRWU6CY3.js.map
3
+ //# sourceMappingURL=observational-memory-YRWU6CY3.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-OYK4MEUD.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-YRWU6CY3.js"}
@@ -1,64 +1,64 @@
1
1
  'use strict';
2
2
 
3
- var chunk5W5463NI_cjs = require('../chunk-5W5463NI.cjs');
3
+ var chunkSHID74TI_cjs = require('../chunk-SHID74TI.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "OBSERVATIONAL_MEMORY_DEFAULTS", {
8
8
  enumerable: true,
9
- get: function () { return chunk5W5463NI_cjs.OBSERVATIONAL_MEMORY_DEFAULTS; }
9
+ get: function () { return chunkSHID74TI_cjs.OBSERVATIONAL_MEMORY_DEFAULTS; }
10
10
  });
11
11
  Object.defineProperty(exports, "OBSERVATION_CONTEXT_INSTRUCTIONS", {
12
12
  enumerable: true,
13
- get: function () { return chunk5W5463NI_cjs.OBSERVATION_CONTEXT_INSTRUCTIONS; }
13
+ get: function () { return chunkSHID74TI_cjs.OBSERVATION_CONTEXT_INSTRUCTIONS; }
14
14
  });
15
15
  Object.defineProperty(exports, "OBSERVATION_CONTEXT_PROMPT", {
16
16
  enumerable: true,
17
- get: function () { return chunk5W5463NI_cjs.OBSERVATION_CONTEXT_PROMPT; }
17
+ get: function () { return chunkSHID74TI_cjs.OBSERVATION_CONTEXT_PROMPT; }
18
18
  });
19
19
  Object.defineProperty(exports, "OBSERVATION_CONTINUATION_HINT", {
20
20
  enumerable: true,
21
- get: function () { return chunk5W5463NI_cjs.OBSERVATION_CONTINUATION_HINT; }
21
+ get: function () { return chunkSHID74TI_cjs.OBSERVATION_CONTINUATION_HINT; }
22
22
  });
23
23
  Object.defineProperty(exports, "OBSERVER_SYSTEM_PROMPT", {
24
24
  enumerable: true,
25
- get: function () { return chunk5W5463NI_cjs.OBSERVER_SYSTEM_PROMPT; }
25
+ get: function () { return chunkSHID74TI_cjs.OBSERVER_SYSTEM_PROMPT; }
26
26
  });
27
27
  Object.defineProperty(exports, "ObservationalMemory", {
28
28
  enumerable: true,
29
- get: function () { return chunk5W5463NI_cjs.ObservationalMemory; }
29
+ get: function () { return chunkSHID74TI_cjs.ObservationalMemory; }
30
30
  });
31
31
  Object.defineProperty(exports, "TokenCounter", {
32
32
  enumerable: true,
33
- get: function () { return chunk5W5463NI_cjs.TokenCounter; }
33
+ get: function () { return chunkSHID74TI_cjs.TokenCounter; }
34
34
  });
35
35
  Object.defineProperty(exports, "buildObserverPrompt", {
36
36
  enumerable: true,
37
- get: function () { return chunk5W5463NI_cjs.buildObserverPrompt; }
37
+ get: function () { return chunkSHID74TI_cjs.buildObserverPrompt; }
38
38
  });
39
39
  Object.defineProperty(exports, "buildObserverSystemPrompt", {
40
40
  enumerable: true,
41
- get: function () { return chunk5W5463NI_cjs.buildObserverSystemPrompt; }
41
+ get: function () { return chunkSHID74TI_cjs.buildObserverSystemPrompt; }
42
42
  });
43
43
  Object.defineProperty(exports, "extractCurrentTask", {
44
44
  enumerable: true,
45
- get: function () { return chunk5W5463NI_cjs.extractCurrentTask; }
45
+ get: function () { return chunkSHID74TI_cjs.extractCurrentTask; }
46
46
  });
47
47
  Object.defineProperty(exports, "formatMessagesForObserver", {
48
48
  enumerable: true,
49
- get: function () { return chunk5W5463NI_cjs.formatMessagesForObserver; }
49
+ get: function () { return chunkSHID74TI_cjs.formatMessagesForObserver; }
50
50
  });
51
51
  Object.defineProperty(exports, "hasCurrentTaskSection", {
52
52
  enumerable: true,
53
- get: function () { return chunk5W5463NI_cjs.hasCurrentTaskSection; }
53
+ get: function () { return chunkSHID74TI_cjs.hasCurrentTaskSection; }
54
54
  });
55
55
  Object.defineProperty(exports, "optimizeObservationsForContext", {
56
56
  enumerable: true,
57
- get: function () { return chunk5W5463NI_cjs.optimizeObservationsForContext; }
57
+ get: function () { return chunkSHID74TI_cjs.optimizeObservationsForContext; }
58
58
  });
59
59
  Object.defineProperty(exports, "parseObserverOutput", {
60
60
  enumerable: true,
61
- get: function () { return chunk5W5463NI_cjs.parseObserverOutput; }
61
+ get: function () { return chunkSHID74TI_cjs.parseObserverOutput; }
62
62
  });
63
63
  //# sourceMappingURL=index.cjs.map
64
64
  //# sourceMappingURL=index.cjs.map
@@ -1,3 +1,3 @@
1
- export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput } from '../chunk-3CM4XQJO.js';
1
+ export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput } from '../chunk-M7RAJAZ6.js';
2
2
  //# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,4 @@
1
1
  import type { MastraDBMessage } from '@mastra/core/agent';
2
- import type { TiktokenBPE } from 'js-tiktoken/lite';
3
2
  export type TokenCounterModelContext = {
4
3
  provider?: string;
5
4
  modelId?: string;
@@ -8,20 +7,18 @@ type TokenCounterOptions = {
8
7
  model?: string | TokenCounterModelContext;
9
8
  };
10
9
  /**
11
- * Token counting utility using tiktoken.
12
- * Uses o200k_base (GPT-4o encoding) as a reasonable default for text and
10
+ * Token counting utility using tokenx for rough local estimation and
13
11
  * provider-aware heuristics for image parts so multimodal prompts are not
14
12
  * undercounted as generic JSON blobs.
15
13
  */
16
14
  export declare class TokenCounter {
17
- private encoder;
18
15
  private readonly cacheSource;
19
16
  private readonly defaultModelContext?;
20
17
  private readonly modelContextStorage;
21
18
  private readonly inFlightAttachmentCounts;
22
19
  private static readonly TOKENS_PER_MESSAGE;
23
20
  private static readonly TOKENS_PER_CONVERSATION;
24
- constructor(encoding?: TiktokenBPE, options?: TokenCounterOptions);
21
+ constructor(options?: TokenCounterOptions);
25
22
  runWithModelContext<T>(model: string | TokenCounterModelContext | undefined, fn: () => T): T;
26
23
  private getModelContext;
27
24
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"token-counter.d.ts","sourceRoot":"","sources":["../../../src/process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,wBAAwB,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAI5F,OAAO,CAAC,eAAe;IAIvB;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAKjC,OAAO,CAAC,yBAAyB;IAkBjC,OAAO,CAAC,8BAA8B;IAiBtC,OAAO,CAAC,4BAA4B;IAkBpC,OAAO,CAAC,iCAAiC;IAkBzC,OAAO,CAAC,wBAAwB;IAsEhC,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,2BAA2B;IAInC,OAAO,CAAC,uBAAuB;IAkB/B,OAAO,CAAC,iCAAiC;YAiC3B,oCAAoC;YAyBpC,wBAAwB;IAkFtC,OAAO,CAAC,sBAAsB;IAkF9B;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM;IAiCxC,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAiClE;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,MAAM;IAU5C,kBAAkB,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAOtE;;OAEG;IACH,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;CAGhD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/memory",
3
- "version": "1.6.2",
3
+ "version": "1.7.0-alpha.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -38,12 +38,12 @@
38
38
  "dependencies": {
39
39
  "async-mutex": "^0.5.0",
40
40
  "image-size": "^2.0.2",
41
- "js-tiktoken": "^1.0.21",
42
41
  "json-schema": "^0.4.0",
43
42
  "lru-cache": "^11.2.6",
44
43
  "probe-image-size": "^7.2.3",
44
+ "tokenx": "^1.3.0",
45
45
  "xxhash-wasm": "^1.1.0",
46
- "@mastra/schema-compat": "1.2.0"
46
+ "@mastra/schema-compat": "1.2.1-alpha.1"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@ai-sdk/openai": "^1.3.24",
@@ -59,12 +59,12 @@
59
59
  "typescript-eslint": "^8.51.0",
60
60
  "vitest": "4.0.18",
61
61
  "zod": "^4.3.6",
62
- "@internal/ai-sdk-v4": "0.0.14",
63
62
  "@internal/ai-sdk-v5": "0.0.14",
64
63
  "@internal/ai-v6": "0.0.14",
65
64
  "@internal/lint": "0.0.67",
65
+ "@mastra/core": "1.12.0-alpha.1",
66
66
  "@internal/types-builder": "0.0.42",
67
- "@mastra/core": "1.11.0"
67
+ "@internal/ai-sdk-v4": "0.0.14"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "@mastra/core": ">=1.4.1-0 <2.0.0-0",