@mastra/memory 1.19.0-alpha.1 → 1.19.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 +49 -0
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-agent-approval.md +2 -0
- package/dist/docs/references/docs-agents-background-tasks.md +9 -6
- package/dist/docs/references/docs-memory-multi-user-threads.md +206 -0
- package/dist/docs/references/docs-memory-observational-memory.md +1 -0
- package/dist/docs/references/docs-memory-overview.md +1 -0
- package/dist/docs/references/docs-memory-working-memory.md +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 1.19.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added `activateAfterIdle: "auto"` for Observational Memory early activation. ([#16663](https://github.com/mastra-ai/mastra/pull/16663))
|
|
8
|
+
|
|
9
|
+
Mastra can now choose an idle activation timeout from the active model provider's prompt cache behavior. OpenAI also respects `providerOptions.openai.promptCacheRetention` when available.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const memory = new Memory({
|
|
13
|
+
options: {
|
|
14
|
+
observationalMemory: {
|
|
15
|
+
model: 'google/gemini-2.5-flash',
|
|
16
|
+
activateAfterIdle: 'auto',
|
|
17
|
+
activateOnProviderChange: true,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- Add `observeAttachments` to `ObservationConfig` for Observational Memory. Use it to control whether image/file parts on observed messages are forwarded to the Observer model alongside their placeholder text lines. ([#16671](https://github.com/mastra-ai/mastra/pull/16671))
|
|
24
|
+
- `true` (default) — forward all attachments (existing behavior).
|
|
25
|
+
- `false` — drop all attachments; placeholders still appear in the observer transcript.
|
|
26
|
+
- `string[]` — allowlist of mimeType patterns, e.g. `['image/*']` or `['application/pdf']`. Matching is case-insensitive and supports exact, `type/*`, and `*` patterns.
|
|
27
|
+
|
|
28
|
+
Useful when the Observer model is text-only (some DeepSeek endpoints, etc.) while the main agent uses a multimodal model. Tool-result attachments are filtered with the same rule.
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
new Memory({
|
|
32
|
+
options: {
|
|
33
|
+
observationalMemory: {
|
|
34
|
+
observation: {
|
|
35
|
+
model: 'deepseek/deepseek-chat', // text-only observer
|
|
36
|
+
observeAttachments: false, // or e.g. ['image/*', 'application/pdf']
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- feat(memory): start background buffering of unobserved messages when agent goes idle ([#16694](https://github.com/mastra-ai/mastra/pull/16694))
|
|
46
|
+
|
|
47
|
+
In OM buffering mode, when the agent goes idle (turn.end()), any unobserved messages are now buffered in the background via a fire-and-forget buffer() call. This ensures observations are computed proactively rather than waiting for the next turn's step.prepare().
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [[`452036a`](https://github.com/mastra-ai/mastra/commit/452036a0d965b4f4c1efd93606e4f03b50b807a5), [`c272d50`](https://github.com/mastra-ai/mastra/commit/c272d50610a54496b6b6d92ccd4d37b333a2613a), [`27fd1b7`](https://github.com/mastra-ai/mastra/commit/27fd1b79ac62eb7694f92587eb7d1be05b59be01), [`5ba7253`](https://github.com/mastra-ai/mastra/commit/5ba7253745c85e8df8012a76d954c640ffa336f7), [`5556cc1`](https://github.com/mastra-ai/mastra/commit/5556cc1befec71518d84f826b3bfe3a079a9daf7), [`f73980d`](https://github.com/mastra-ai/mastra/commit/f73980d651eb5f7f1ab20582de4615a1b6f10fce), [`5499303`](https://github.com/mastra-ai/mastra/commit/54993032c1ebc09642625b78d2014e0cf84a3cae), [`a702009`](https://github.com/mastra-ai/mastra/commit/a702009d3cfaa745120f501e21c783ed4d6a3072), [`9aee493`](https://github.com/mastra-ai/mastra/commit/9aee493ed6089b5133472623dcce49934bf2d509), [`d8692af`](https://github.com/mastra-ai/mastra/commit/d8692afa253028e39cdce2aafa0ac414071a762e), [`1a9cc60`](https://github.com/mastra-ai/mastra/commit/1a9cc6069f9910fc3d59e4953ac8cd95d89ad6f5), [`8cdb86c`](https://github.com/mastra-ai/mastra/commit/8cdb86ceed1137bc2768e147dce85a0692b9fb26), [`8534d79`](https://github.com/mastra-ai/mastra/commit/8534d791fa1cb70fe1c19e2604c4b63cc10dd051), [`eda90c5`](https://github.com/mastra-ai/mastra/commit/eda90c5bfd7de11805ecc9f4552716c895fbaf78), [`a935b0a`](https://github.com/mastra-ai/mastra/commit/a935b0a0977ae3f196b33ec7621f528069c82db0), [`9c88701`](https://github.com/mastra-ai/mastra/commit/9c8870195b41a38dc40b6ba2aa55eda04df8fa69), [`c78f8cd`](https://github.com/mastra-ai/mastra/commit/c78f8cd6222a86e6c60ae5210b6929ad5221b6fb), [`e146aad`](https://github.com/mastra-ai/mastra/commit/e146aadbba66c410ba0e74bac4c50135495cb8dd), [`ac79462`](https://github.com/mastra-ai/mastra/commit/ac79462b98f1062394c45093aa515b0766f27ee2), [`1a0ec78`](https://github.com/mastra-ai/mastra/commit/1a0ec789a26cae443744e9abbd62ed6ee676af39), [`e47bca7`](https://github.com/mastra-ai/mastra/commit/e47bca7b72866d3abd173b9f530ac4318113a8ff), [`afc004f`](https://github.com/mastra-ai/mastra/commit/afc004f5cc7e30697809e7021820b9f5881e6719), [`0031d0f`](https://github.com/mastra-ai/mastra/commit/0031d0f13831d7843ac5d498734a7d92862e2ce3), [`841a222`](https://github.com/mastra-ai/mastra/commit/841a222560d8c19238f8213713f30535cdd82284), [`64c1e0b`](https://github.com/mastra-ai/mastra/commit/64c1e0b35165c96b659818bd0177aa18794ef11f), [`40d83a9`](https://github.com/mastra-ai/mastra/commit/40d83a90d9be31a1b83e04649edb703eb7753e33), [`4e88dc6`](https://github.com/mastra-ai/mastra/commit/4e88dc6b89f154c0eae37221c8126be0c23c569f), [`19018f0`](https://github.com/mastra-ai/mastra/commit/19018f05722af74a5978781a7731a654b26f7f2a), [`19281c7`](https://github.com/mastra-ai/mastra/commit/19281c70424f757219782de16c2699743c5e04d0), [`3498b49`](https://github.com/mastra-ai/mastra/commit/3498b4946be94f4313cd817733589680dcda5278), [`d52b6fe`](https://github.com/mastra-ai/mastra/commit/d52b6fe1c56853eb38864baae0bbfa75cc739ccb), [`408be73`](https://github.com/mastra-ai/mastra/commit/408be73449dfab92b51eab8c6623b6c443debc25), [`359439b`](https://github.com/mastra-ai/mastra/commit/359439bb8c635e048176306828195f8297f50021), [`71a820b`](https://github.com/mastra-ai/mastra/commit/71a820b2353fa1406772c50760a3732058a8b337), [`1698f5e`](https://github.com/mastra-ai/mastra/commit/1698f5ec141d34f22a873efdb145ce3cdf848a5e)]:
|
|
50
|
+
- @mastra/core@1.36.0
|
|
51
|
+
|
|
3
52
|
## 1.19.0-alpha.1
|
|
4
53
|
|
|
5
54
|
### Minor Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -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.19.0
|
|
6
|
+
version: "1.19.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -23,6 +23,7 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
23
23
|
- [Evals with memory](references/docs-evals-evals-with-memory.md) - Run scorers against memory-enabled agents — including observational memory in thread scope — using runEvals and dataset experiments.
|
|
24
24
|
- [Memory processors](references/docs-memory-memory-processors.md) - Learn how to use memory processors in Mastra to filter, trim, and transform messages before they're sent to the language model to manage context window limits.
|
|
25
25
|
- [Message history](references/docs-memory-message-history.md) - Learn how to configure message history in Mastra to store recent messages from the current conversation.
|
|
26
|
+
- [Multi-user threads](references/docs-memory-multi-user-threads.md) - Share one Mastra thread between multiple users by carrying speaker identity in the message body.
|
|
26
27
|
- [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
28
|
- [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
29
|
- [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.
|
|
@@ -92,6 +92,8 @@ A tool can also pause _during_ its `execute` function by calling `suspend()`. Th
|
|
|
92
92
|
|
|
93
93
|
The stream emits a `tool-call-suspended` chunk with a custom payload defined by the tool's `suspendSchema`. You resume by calling `resumeStream()` with data matching the tool's `resumeSchema`.
|
|
94
94
|
|
|
95
|
+
> **Note:** `suspend()` does not throw — return immediately after calling it (e.g. `return await suspend({ ... })`). Code after `await suspend(...)` still runs before the tool pauses.
|
|
96
|
+
|
|
95
97
|
## Tool approval with `generate()`
|
|
96
98
|
|
|
97
99
|
Tool approval also works with `generate()` for non-streaming use cases. When a tool requires approval, `generate()` returns immediately with `finishReason: 'suspended'`, a `suspendPayload` containing the tool call details (`toolCallId`, `toolName`, `args`), and a `runId`:
|
|
@@ -40,11 +40,12 @@ The full set of options is listed in the [backgroundTasks configuration referenc
|
|
|
40
40
|
|
|
41
41
|
## Run a tool in the background
|
|
42
42
|
|
|
43
|
-
Enabling the manager doesn't run anything in the background by itself as every tool defaults to foreground execution.
|
|
43
|
+
Enabling the manager doesn't run anything in the background by itself as every tool defaults to foreground execution. Tools opt in at one of two layers:
|
|
44
44
|
|
|
45
|
-
1. **
|
|
45
|
+
1. **Tool-level config**: the tool itself declares it as background-eligible.
|
|
46
46
|
2. **Agent-level config**: the agent declares which of its tools are background-eligible.
|
|
47
|
-
|
|
47
|
+
|
|
48
|
+
Once a tool has opted in, the LLM can optionally include a `_background` field in the tool arguments to override the resolved config for a specific call (timeout, retries, or to flip the call back to foreground).
|
|
48
49
|
|
|
49
50
|
### Tool-level
|
|
50
51
|
|
|
@@ -103,13 +104,15 @@ When a tool is registered on an agent that has background tasks enabled, the mod
|
|
|
103
104
|
}
|
|
104
105
|
```
|
|
105
106
|
|
|
107
|
+
The `_background` override is a _modifier_ on tools the developer has already opted in at the tool or agent layer — it is not a standalone opt-in. If a tool hasn't been opted in, `_background.enabled: true` from the model is ignored and the tool runs in the foreground. This keeps deterministic, foreground-only tools (calculators, lookups, schema validators) from being silently dispatched as tasks.
|
|
108
|
+
|
|
106
109
|
### Resolution order
|
|
107
110
|
|
|
108
111
|
When a tool call is dispatched, the resolved background config is computed in this priority order:
|
|
109
112
|
|
|
110
|
-
1.
|
|
111
|
-
2.
|
|
112
|
-
3.
|
|
113
|
+
1. Agent-level `backgroundTasks.tools` entry for the tool.
|
|
114
|
+
2. Tool-level `backgroundTasks` config.
|
|
115
|
+
3. LLM `_background.enabled` override (only used to enable background dispatch when the tool was opted in at one of the layers above).
|
|
113
116
|
4. Manager defaults (`defaultTimeoutMs`, `defaultRetries`).
|
|
114
117
|
|
|
115
118
|
If the agent has `backgroundTasks.disabled: true`, every tool call runs synchronously regardless of the layers above.
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Multi-user threads
|
|
2
|
+
|
|
3
|
+
A single Mastra thread can be shared by multiple users, each with their own name and functional role. You carry speaker identity in the message body so the agent can tell users apart while reading from a single shared thread.
|
|
4
|
+
|
|
5
|
+
## When to use multi-user threads
|
|
6
|
+
|
|
7
|
+
Use multi-user threads when several people collaborate on the same subject through one agent:
|
|
8
|
+
|
|
9
|
+
- Collaborative documents with editors, reviewers, and approvers
|
|
10
|
+
- Group chats where one assistant serves many participants
|
|
11
|
+
- Multi-stakeholder reviews where different roles have different authority
|
|
12
|
+
|
|
13
|
+
## Share one `resourceId` across all participants
|
|
14
|
+
|
|
15
|
+
A thread belongs to exactly one `resourceId`, so all participants on a shared thread need to pass the same value. Instead of using a user id (the default for single-user apps), key `resourceId` on the conversation itself — for example `doc_${docId}` for a shared document, or `room_${roomId}` for a group chat. With everyone pointing at the same `resourceId`, they read and write the same history.
|
|
16
|
+
|
|
17
|
+
## Tag each user message with the speaker's identity
|
|
18
|
+
|
|
19
|
+
The model needs to know who's talking on every turn. Since the message body is the one place that survives into history and back into context, wrap each user message in a small `<turn>` tag with the speaker's id, name, and role. The tag stays attached to the message, so when prior turns are recalled the model still sees who said what.
|
|
20
|
+
|
|
21
|
+
Build the tag with a small helper. The example below is one way to do it — copy it into your project and adapt it to your shape of user data:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
export type Speaker = {
|
|
25
|
+
id: string
|
|
26
|
+
name: string
|
|
27
|
+
role: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function escapeAttr(value: string) {
|
|
31
|
+
return value
|
|
32
|
+
.replace(/&/g, '&')
|
|
33
|
+
.replace(/"/g, '"')
|
|
34
|
+
.replace(/</g, '<')
|
|
35
|
+
.replace(/>/g, '>')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function asUserTurn(speaker: Speaker, text: string) {
|
|
39
|
+
const id = escapeAttr(speaker.id)
|
|
40
|
+
const name = escapeAttr(speaker.name)
|
|
41
|
+
const role = escapeAttr(speaker.role)
|
|
42
|
+
return {
|
|
43
|
+
role: 'user' as const,
|
|
44
|
+
content: `<turn author_id="${id}" author_name="${name}" functional_role="${role}">
|
|
45
|
+
${text}
|
|
46
|
+
</turn>`,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Teach the agent how to read the `<turn>` tag in its instructions. The agent must have `memory` configured so it can be called with a `thread` and `resource`:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { Agent } from '@mastra/core/agent'
|
|
55
|
+
import { Memory } from '@mastra/memory'
|
|
56
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
57
|
+
|
|
58
|
+
const memory = new Memory({
|
|
59
|
+
storage: new LibSQLStore({ url: 'file:./collab.db' }),
|
|
60
|
+
options: {
|
|
61
|
+
lastMessages: 20,
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
export const collabAgent = new Agent({
|
|
66
|
+
id: 'collab',
|
|
67
|
+
name: 'CollabAgent',
|
|
68
|
+
model: 'openai/gpt-5.4-mini',
|
|
69
|
+
memory,
|
|
70
|
+
instructions: `
|
|
71
|
+
You are a collaborative document assistant. Multiple users talk to you in the SAME thread.
|
|
72
|
+
|
|
73
|
+
Every user message is wrapped in a <turn> tag carrying the user's identity:
|
|
74
|
+
|
|
75
|
+
<turn author_id="u_alice" author_name="Alice" functional_role="editor">
|
|
76
|
+
...message text...
|
|
77
|
+
</turn>
|
|
78
|
+
|
|
79
|
+
Rules:
|
|
80
|
+
1. Address users by their author_name.
|
|
81
|
+
2. Respect functional_role: editors propose changes, reviewers approve.
|
|
82
|
+
3. When attributing past statements, read author_name from the surrounding <turn> tag.
|
|
83
|
+
4. Do not echo the <turn> tags back at users.
|
|
84
|
+
`.trim(),
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Call the agent with the wrapped message. Every participant shares the same `thread` and `resource`:
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { asUserTurn } from './identity'
|
|
92
|
+
|
|
93
|
+
const docResourceId = 'doc_42'
|
|
94
|
+
const docThreadId = 'doc_42'
|
|
95
|
+
|
|
96
|
+
const alice = { id: 'u_alice', name: 'Alice', role: 'editor' }
|
|
97
|
+
const bob = { id: 'u_bob', name: 'Bob', role: 'reviewer' }
|
|
98
|
+
|
|
99
|
+
await collabAgent.generate([asUserTurn(alice, 'My favorite color is teal.')], {
|
|
100
|
+
memory: { thread: docThreadId, resource: docResourceId },
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
await collabAgent.generate([asUserTurn(bob, 'I want QA sign-off before publish.')], {
|
|
104
|
+
memory: { thread: docThreadId, resource: docResourceId },
|
|
105
|
+
})
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The `<turn>` tag persists in the message body, so when history is recalled on later turns the model still sees who said what.
|
|
109
|
+
|
|
110
|
+
## Combining with memory layers
|
|
111
|
+
|
|
112
|
+
The user-tagging pattern composes with every memory layer. Pick the layer based on how long the conversation needs to remember per-user facts:
|
|
113
|
+
|
|
114
|
+
- **Short conversations** (a single session, or a thread small enough to fit in `lastMessages`), or when you need a verbatim record of who said what: use [message history alone](#message-history-alone). The user tags in history are enough; no extra memory layer needed.
|
|
115
|
+
- **Long-running threads** (conversations that outgrow `lastMessages`, where you need per-user facts to survive history eviction): use [observational memory](#with-observational-memory-recommended).
|
|
116
|
+
- **Need a structured participants list, or your storage adapter doesn't support OM** (OM requires LibSQL, PG, or MongoDB): use [working memory](#with-working-memory).
|
|
117
|
+
|
|
118
|
+
We recommend using observational memory or working memory, not both — they cover overlapping needs, and running both at once adds latency and token cost without much benefit.
|
|
119
|
+
|
|
120
|
+
### Message history alone
|
|
121
|
+
|
|
122
|
+
For short conversations, or when you need a verbatim record of who said what, the user tags in history are enough. `lastMessages` brings prior turns back into context with their attribution intact:
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { Memory } from '@mastra/memory'
|
|
126
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
127
|
+
|
|
128
|
+
const memory = new Memory({
|
|
129
|
+
storage: new LibSQLStore({ url: 'file:./collab.db' }),
|
|
130
|
+
options: {
|
|
131
|
+
lastMessages: 20,
|
|
132
|
+
},
|
|
133
|
+
})
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The model reads identity from the `<turn>` tag on the current message and from prior tagged messages brought back through `lastMessages`.
|
|
137
|
+
|
|
138
|
+
### With observational memory (recommended)
|
|
139
|
+
|
|
140
|
+
[Observational Memory](https://mastra.ai/docs/memory/observational-memory) (OM) extracts per-user facts into a background log without burning the agent's tool budget. The default Observer model reads `<turn>` tags natively and produces named attribution like `Alice stated her favorite color is teal.` and `Bob asked for QA sign-off before publish.`
|
|
141
|
+
|
|
142
|
+
Prefer OM over working memory for multi-user threads when your storage supports it. OM extracts facts automatically, scales to any number of participants, and doesn't need template upkeep. Enable it with no overrides:
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import { Memory } from '@mastra/memory'
|
|
146
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
147
|
+
|
|
148
|
+
const memory = new Memory({
|
|
149
|
+
storage: new LibSQLStore({ url: 'file:./collab.db' }),
|
|
150
|
+
options: {
|
|
151
|
+
lastMessages: 20,
|
|
152
|
+
observationalMemory: true,
|
|
153
|
+
},
|
|
154
|
+
})
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
OM requires a storage adapter that supports it: `@mastra/libsql`, `@mastra/pg`, or `@mastra/mongodb`.
|
|
158
|
+
|
|
159
|
+
> **Note:** If you switch the Observer to a weaker model and see facts collapse to a generic `User`, use [`observation.instruction`](https://mastra.ai/reference/memory/observational-memory) to teach the Observer how to read the `<turn>` tag.
|
|
160
|
+
|
|
161
|
+
### With working memory
|
|
162
|
+
|
|
163
|
+
Use working memory when OM isn't an option — for example, when your storage adapter doesn't support OM, or when you need a structured, deterministic participants list the agent can read and write on every turn.
|
|
164
|
+
|
|
165
|
+
The default [working memory](https://mastra.ai/docs/memory/working-memory) template assumes one user per thread ("First Name", "Last Name", etc.). For multi-user threads, provide a template with a participants list:
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import { Memory } from '@mastra/memory'
|
|
169
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
170
|
+
|
|
171
|
+
const memory = new Memory({
|
|
172
|
+
storage: new LibSQLStore({ url: 'file:./collab.db' }),
|
|
173
|
+
options: {
|
|
174
|
+
lastMessages: 20,
|
|
175
|
+
workingMemory: {
|
|
176
|
+
enabled: true,
|
|
177
|
+
scope: 'thread',
|
|
178
|
+
template: `# Document Collaboration State
|
|
179
|
+
|
|
180
|
+
## Participants
|
|
181
|
+
<!-- One entry per known collaborator. Use author_id as the stable key. -->
|
|
182
|
+
<!-- - **<author_name>** (<author_id>, <functional_role>): <their position> -->
|
|
183
|
+
|
|
184
|
+
## Open Questions
|
|
185
|
+
|
|
186
|
+
## Decisions
|
|
187
|
+
`,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
})
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Set `scope: 'thread'` so the participants list belongs to the document, not to any individual user. Add one instruction telling the agent to append new participants to the list whenever a new `author_id` shows up in a `<turn>`.
|
|
194
|
+
|
|
195
|
+
For more on templates, see [Custom templates](https://mastra.ai/docs/memory/working-memory).
|
|
196
|
+
|
|
197
|
+
## Security
|
|
198
|
+
|
|
199
|
+
Set the `speaker` from your authenticated request context, never from the request body. If a client can choose its own `author_id`, one user can impersonate another. Use [Request Context](https://mastra.ai/docs/server/request-context) to read the verified user from your auth layer and build the `<turn>` tag on the server before calling the agent.
|
|
200
|
+
|
|
201
|
+
## Related
|
|
202
|
+
|
|
203
|
+
- [Working memory](https://mastra.ai/docs/memory/working-memory)
|
|
204
|
+
- [Observational memory](https://mastra.ai/docs/memory/observational-memory)
|
|
205
|
+
- [Share memory between agents](https://mastra.ai/docs/memory/overview)
|
|
206
|
+
- [`Memory` reference](https://mastra.ai/reference/memory/memory-class)
|
|
@@ -565,6 +565,7 @@ No manual migration needed. OM reads existing messages and observes them lazily
|
|
|
565
565
|
- **[Message history](https://mastra.ai/docs/memory/message-history)**: High-fidelity record of the current conversation
|
|
566
566
|
- **[Working memory](https://mastra.ai/docs/memory/working-memory)**: Small, structured state (JSON or markdown) for user preferences, names, goals
|
|
567
567
|
- **[Semantic Recall](https://mastra.ai/docs/memory/semantic-recall)**: RAG-based retrieval of relevant past messages
|
|
568
|
+
- **[Multi-user threads](https://mastra.ai/docs/memory/multi-user-threads)**: How OM attributes facts to individual users when several people share a single thread
|
|
568
569
|
|
|
569
570
|
If you're using working memory to store conversation summaries or ongoing state that grows over time, OM is a better fit. Working memory is for small, structured data; OM is for long-running event logs. OM also manages message history automatically—the `messageTokens` setting controls how much raw history remains before observation runs.
|
|
570
571
|
|
|
@@ -7,6 +7,7 @@ Mastra agents can be configured to store [message history](https://mastra.ai/doc
|
|
|
7
7
|
- [Observational Memory](https://mastra.ai/docs/memory/observational-memory) (Recommended): Uses background agents to maintain a dense observation log that replaces raw message history as it grows. This keeps the context window small while preserving long-term memory.
|
|
8
8
|
- [Working memory](https://mastra.ai/docs/memory/working-memory): Stores persistent, structured user data such as names, preferences, and goals.
|
|
9
9
|
- [Semantic recall](https://mastra.ai/docs/memory/semantic-recall): Retrieves relevant past messages based on semantic meaning rather than exact keywords.
|
|
10
|
+
- [Multi-user threads](https://mastra.ai/docs/memory/multi-user-threads): Share one thread between multiple users.
|
|
10
11
|
|
|
11
12
|
If the combined memory exceeds the model's context limit, [memory processors](https://mastra.ai/docs/memory/memory-processors) can filter, trim, or prioritize content so the most relevant information is preserved.
|
|
12
13
|
|
|
@@ -130,7 +130,7 @@ Resource-scoped working memory requires specific storage adapters that support t
|
|
|
130
130
|
|
|
131
131
|
## Custom templates
|
|
132
132
|
|
|
133
|
-
Templates guide the agent on what information to track and update in working memory. While a default template is used if none is provided, you'll typically want to define a custom template tailored to your agent's specific use case to ensure it remembers the most relevant information.
|
|
133
|
+
Templates guide the agent on what information to track and update in working memory. While a default template is used if none is provided, you'll typically want to define a custom template tailored to your agent's specific use case to ensure it remembers the most relevant information. For threads shared by multiple users, see [Multi-user threads](https://mastra.ai/docs/memory/multi-user-threads).
|
|
134
134
|
|
|
135
135
|
Here's an example of a custom template. In this example the agent will store the users name, location, timezone, etc as soon as the user sends a message containing any of the info:
|
|
136
136
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/memory",
|
|
3
|
-
"version": "1.19.0
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -59,12 +59,12 @@
|
|
|
59
59
|
"typescript-eslint": "^8.57.0",
|
|
60
60
|
"vitest": "4.1.5",
|
|
61
61
|
"zod": "^4.3.6",
|
|
62
|
-
"@internal/ai-sdk-v4": "0.0.
|
|
63
|
-
"@internal/ai-sdk-v5": "0.0.
|
|
64
|
-
"@internal/
|
|
65
|
-
"@internal/
|
|
66
|
-
"@
|
|
67
|
-
"@
|
|
62
|
+
"@internal/ai-sdk-v4": "0.0.44",
|
|
63
|
+
"@internal/ai-sdk-v5": "0.0.44",
|
|
64
|
+
"@internal/ai-v6": "0.0.44",
|
|
65
|
+
"@internal/lint": "0.0.97",
|
|
66
|
+
"@mastra/core": "1.36.0",
|
|
67
|
+
"@internal/types-builder": "0.0.72"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"@mastra/core": ">=1.4.1-0 <2.0.0-0",
|