@mastra/memory 1.6.3-alpha.0 → 1.7.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.
- package/CHANGELOG.md +28 -0
- package/dist/{chunk-3CM4XQJO.js → chunk-M7RAJAZ6.js} +11 -28
- package/dist/chunk-M7RAJAZ6.js.map +1 -0
- package/dist/{chunk-5W5463NI.cjs → chunk-SHID74TI.cjs} +11 -29
- package/dist/chunk-SHID74TI.cjs.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +25 -25
- package/dist/docs/references/docs-memory-observational-memory.md +2 -2
- package/dist/docs/references/reference-memory-observational-memory.md +4 -2
- package/dist/docs/references/reference-processors-token-limiter-processor.md +30 -4
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{observational-memory-C5LO7RBR.cjs → observational-memory-AU6MIH4Q.cjs} +17 -17
- package/dist/{observational-memory-C5LO7RBR.cjs.map → observational-memory-AU6MIH4Q.cjs.map} +1 -1
- package/dist/{observational-memory-OYK4MEUD.js → observational-memory-YRWU6CY3.js} +3 -3
- package/dist/{observational-memory-OYK4MEUD.js.map → observational-memory-YRWU6CY3.js.map} +1 -1
- package/dist/processors/index.cjs +15 -15
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/token-counter.d.ts +2 -5
- package/dist/processors/observational-memory/token-counter.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/chunk-3CM4XQJO.js.map +0 -1
- package/dist/chunk-5W5463NI.cjs.map +0 -1
package/dist/docs/SKILL.md
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.7.0",
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
23
|
+
"implementation": "dist/chunk-M7RAJAZ6.js"
|
|
24
24
|
},
|
|
25
25
|
"ObservationalMemory": {
|
|
26
26
|
"types": "dist/processors/index.d.ts",
|
|
27
|
-
"implementation": "dist/chunk-
|
|
28
|
-
"line":
|
|
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-
|
|
33
|
-
"line":
|
|
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-
|
|
38
|
-
"line":
|
|
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-
|
|
43
|
-
"line":
|
|
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-
|
|
48
|
-
"line":
|
|
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-
|
|
53
|
-
"line":
|
|
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-
|
|
58
|
-
"line":
|
|
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-
|
|
63
|
-
"line":
|
|
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-
|
|
68
|
-
"line":
|
|
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-
|
|
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
|
-
|
|
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
|
|
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.
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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-
|
|
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-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
29
|
+
get: function () { return chunkSHID74TI_cjs.ObservationalMemory; }
|
|
30
30
|
});
|
|
31
31
|
Object.defineProperty(exports, "TokenCounter", {
|
|
32
32
|
enumerable: true,
|
|
33
|
-
get: function () { return
|
|
33
|
+
get: function () { return chunkSHID74TI_cjs.TokenCounter; }
|
|
34
34
|
});
|
|
35
35
|
Object.defineProperty(exports, "buildObserverPrompt", {
|
|
36
36
|
enumerable: true,
|
|
37
|
-
get: function () { return
|
|
37
|
+
get: function () { return chunkSHID74TI_cjs.buildObserverPrompt; }
|
|
38
38
|
});
|
|
39
39
|
Object.defineProperty(exports, "buildObserverSystemPrompt", {
|
|
40
40
|
enumerable: true,
|
|
41
|
-
get: function () { return
|
|
41
|
+
get: function () { return chunkSHID74TI_cjs.buildObserverSystemPrompt; }
|
|
42
42
|
});
|
|
43
43
|
Object.defineProperty(exports, "extractCurrentTask", {
|
|
44
44
|
enumerable: true,
|
|
45
|
-
get: function () { return
|
|
45
|
+
get: function () { return chunkSHID74TI_cjs.extractCurrentTask; }
|
|
46
46
|
});
|
|
47
47
|
Object.defineProperty(exports, "formatMessagesForObserver", {
|
|
48
48
|
enumerable: true,
|
|
49
|
-
get: function () { return
|
|
49
|
+
get: function () { return chunkSHID74TI_cjs.formatMessagesForObserver; }
|
|
50
50
|
});
|
|
51
51
|
Object.defineProperty(exports, "hasCurrentTaskSection", {
|
|
52
52
|
enumerable: true,
|
|
53
|
-
get: function () { return
|
|
53
|
+
get: function () { return chunkSHID74TI_cjs.hasCurrentTaskSection; }
|
|
54
54
|
});
|
|
55
55
|
Object.defineProperty(exports, "optimizeObservationsForContext", {
|
|
56
56
|
enumerable: true,
|
|
57
|
-
get: function () { return
|
|
57
|
+
get: function () { return chunkSHID74TI_cjs.optimizeObservationsForContext; }
|
|
58
58
|
});
|
|
59
59
|
Object.defineProperty(exports, "parseObserverOutput", {
|
|
60
60
|
enumerable: true,
|
|
61
|
-
get: function () { return
|
|
61
|
+
get: function () { return chunkSHID74TI_cjs.parseObserverOutput; }
|
|
62
62
|
});
|
|
63
|
-
//# sourceMappingURL=observational-memory-
|
|
64
|
-
//# sourceMappingURL=observational-memory-
|
|
63
|
+
//# sourceMappingURL=observational-memory-AU6MIH4Q.cjs.map
|
|
64
|
+
//# sourceMappingURL=observational-memory-AU6MIH4Q.cjs.map
|
package/dist/{observational-memory-C5LO7RBR.cjs.map → observational-memory-AU6MIH4Q.cjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-
|
|
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-
|
|
2
|
-
//# sourceMappingURL=observational-memory-
|
|
3
|
-
//# sourceMappingURL=observational-memory-
|
|
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-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-YRWU6CY3.js"}
|
|
@@ -1,64 +1,64 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
29
|
+
get: function () { return chunkSHID74TI_cjs.ObservationalMemory; }
|
|
30
30
|
});
|
|
31
31
|
Object.defineProperty(exports, "TokenCounter", {
|
|
32
32
|
enumerable: true,
|
|
33
|
-
get: function () { return
|
|
33
|
+
get: function () { return chunkSHID74TI_cjs.TokenCounter; }
|
|
34
34
|
});
|
|
35
35
|
Object.defineProperty(exports, "buildObserverPrompt", {
|
|
36
36
|
enumerable: true,
|
|
37
|
-
get: function () { return
|
|
37
|
+
get: function () { return chunkSHID74TI_cjs.buildObserverPrompt; }
|
|
38
38
|
});
|
|
39
39
|
Object.defineProperty(exports, "buildObserverSystemPrompt", {
|
|
40
40
|
enumerable: true,
|
|
41
|
-
get: function () { return
|
|
41
|
+
get: function () { return chunkSHID74TI_cjs.buildObserverSystemPrompt; }
|
|
42
42
|
});
|
|
43
43
|
Object.defineProperty(exports, "extractCurrentTask", {
|
|
44
44
|
enumerable: true,
|
|
45
|
-
get: function () { return
|
|
45
|
+
get: function () { return chunkSHID74TI_cjs.extractCurrentTask; }
|
|
46
46
|
});
|
|
47
47
|
Object.defineProperty(exports, "formatMessagesForObserver", {
|
|
48
48
|
enumerable: true,
|
|
49
|
-
get: function () { return
|
|
49
|
+
get: function () { return chunkSHID74TI_cjs.formatMessagesForObserver; }
|
|
50
50
|
});
|
|
51
51
|
Object.defineProperty(exports, "hasCurrentTaskSection", {
|
|
52
52
|
enumerable: true,
|
|
53
|
-
get: function () { return
|
|
53
|
+
get: function () { return chunkSHID74TI_cjs.hasCurrentTaskSection; }
|
|
54
54
|
});
|
|
55
55
|
Object.defineProperty(exports, "optimizeObservationsForContext", {
|
|
56
56
|
enumerable: true,
|
|
57
|
-
get: function () { return
|
|
57
|
+
get: function () { return chunkSHID74TI_cjs.optimizeObservationsForContext; }
|
|
58
58
|
});
|
|
59
59
|
Object.defineProperty(exports, "parseObserverOutput", {
|
|
60
60
|
enumerable: true,
|
|
61
|
-
get: function () { return
|
|
61
|
+
get: function () { return chunkSHID74TI_cjs.parseObserverOutput; }
|
|
62
62
|
});
|
|
63
63
|
//# sourceMappingURL=index.cjs.map
|
|
64
64
|
//# sourceMappingURL=index.cjs.map
|
package/dist/processors/index.js
CHANGED
|
@@ -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-
|
|
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
|
|
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(
|
|
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/processors/observational-memory/token-counter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"token-counter.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/token-counter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAW1D,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,KAAK,CAAC,EAAE,MAAM,GAAG,wBAAwB,CAAC;CAC3C,CAAC;AA8iCF;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAA2B;IAChE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAiE;IACrG,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAkD;IAI3F,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAO;IAEjD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,uBAAuB,CAAM;gBAEzC,OAAO,CAAC,EAAE,mBAAmB;IAKzC,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,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.
|
|
3
|
+
"version": "1.7.0",
|
|
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.1
|
|
46
|
+
"@mastra/schema-compat": "1.2.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-
|
|
63
|
-
"@internal/
|
|
64
|
-
"@internal/
|
|
65
|
-
"@
|
|
66
|
-
"@
|
|
67
|
-
"@internal/
|
|
62
|
+
"@internal/ai-sdk-v5": "0.0.15",
|
|
63
|
+
"@internal/types-builder": "0.0.43",
|
|
64
|
+
"@internal/lint": "0.0.68",
|
|
65
|
+
"@mastra/core": "1.12.0",
|
|
66
|
+
"@internal/ai-sdk-v4": "0.0.15",
|
|
67
|
+
"@internal/ai-v6": "0.0.15"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"@mastra/core": ">=1.4.1-0 <2.0.0-0",
|