You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Default top-level observational memory early activation settings to observations only, while allowing per-phase overrides under `observation` and `reflection`.
Copy file name to clipboardExpand all lines: docs/src/content/en/docs/memory/observational-memory.mdx
+49-5Lines changed: 49 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,6 +93,48 @@ The observer also sees these markers when it processes the thread, so the observ
93
93
94
94
See [the API reference](/reference/memory/observational-memory#configuration) for the full configuration shape.
95
95
96
+
## Early activation
97
+
98
+
OM can activate buffered observations before the token threshold is reached. This is useful when a prompt cache is likely to expire, or when the agent changes model providers.
99
+
100
+
Top-level early activation settings apply to observations by default:
101
+
102
+
```typescript title="src/mastra/agents/agent.ts"
103
+
const memory =newMemory({
104
+
options: {
105
+
observationalMemory: {
106
+
model: 'google/gemini-2.5-flash',
107
+
activateAfterIdle: '5m',
108
+
activateOnProviderChange: true,
109
+
},
110
+
},
111
+
})
112
+
```
113
+
114
+
Use nested `observation` and `reflection` settings for per-phase control. Reflection early activation is opt-in, so top-level settings affect only observations.
115
+
116
+
```typescript title="src/mastra/agents/agent.ts"
117
+
const memory =newMemory({
118
+
options: {
119
+
observationalMemory: {
120
+
model: 'google/gemini-2.5-flash',
121
+
activateAfterIdle: '5m',
122
+
observation: {
123
+
activateAfterIdle: false,
124
+
},
125
+
reflection: {
126
+
activateAfterIdle: '10m',
127
+
activateOnProviderChange: true,
128
+
},
129
+
},
130
+
},
131
+
})
132
+
```
133
+
134
+
In this example, the top-level idle setting is disabled for observations, while reflections opt into idle and provider-change activation.
135
+
136
+
See [the API reference](/reference/memory/observational-memory#configuration) for the full configuration shape.
137
+
96
138
## Benefits
97
139
98
140
-**Prompt caching**: OM's context is stable and observations append over time rather than being dynamically retrieved each turn. This keeps the prompt prefix cacheable, which reduces costs.
@@ -397,12 +439,14 @@ Reflection works similarly — the Reflector runs in the background when observa
397
439
|`observation.bufferTokens`|`0.2`| How often to buffer. `0.2` means every 20% of `messageTokens` — with the default 30k threshold, that's roughly every 6k tokens. Can also be an absolute token count (e.g. `5000`). |
398
440
|`observation.bufferActivation`|`0.8`| How aggressively to clear the message window on activation. `0.8` means remove enough messages to keep only 20% of `messageTokens` remaining. Lower values keep more message history. |
399
441
|`observation.blockAfter`|`1.2`| Safety threshold as a multiplier of `messageTokens`. At `1.2`, synchronous observation is forced at 36k tokens (1.2 × 30k). Only matters if buffering can't keep up. |
400
-
|`activateAfterIdle`| none | Forces buffered observations and buffered reflections to activate after a period of inactivity, even if their token thresholds have not been reached yet. Accepts milliseconds or duration strings like `300_000`, `"5m"`, or `"1hr"`. Set this to your prompt cache TTL if you want activation to happen before the next cold prompt. |
401
-
|`activateOnProviderChange`|`false`| Forces buffered observations and reflections to activate when the next step uses a different `provider/model` than the one that produced the latest assistant step. Use this when switching providers or models would invalidate prompt cache reuse. |
442
+
|`activateAfterIdle`| none | Forces buffered observations to activate after a period of inactivity, even before `observation.messageTokens` is reached. Accepts a numeric millisecond value such as `300_000`, or duration strings like `"5m"` or `"1hr"`. Set this to your prompt cache TTL if you want activation to happen before the next cold prompt. |
443
+
|`activateOnProviderChange`|`false`| Forces buffered observations to activate when the next step uses a different `provider/model` than the one that produced the latest assistant step. Use this when switching providers or models would invalidate prompt cache reuse. |
402
444
|`reflection.bufferActivation`|`0.5`| When to start background reflection. `0.5` means reflection begins when observations reach 50% of the `observationTokens` threshold. |
|`reflection.blockAfter`|`1.2`| Safety threshold for reflection, same logic as observation. |
404
448
405
-
If you're relying on prompt caching, set `activateAfterIdle` to match your cache TTL. That way, once a thread has been idle long enough for the cache to expire, the next request can activate buffered observations or reflections first and send a smaller compressed context window.
449
+
If you're relying on prompt caching, set `activateAfterIdle` to match your cache TTL. That way, once a thread has been idle long enough for the cache to expire, the next request can activate buffered observations first and send a smaller compressed context window.
406
450
407
451
```typescript
408
452
const memory =newMemory({
@@ -416,9 +460,9 @@ const memory = new Memory({
416
460
})
417
461
```
418
462
419
-
With a 5-minute prompt cache TTL, this activates buffered context after 5 minutes of inactivity so the next uncached prompt uses observations and reflections instead of a larger raw message window. If you prefer, `300_000` works the same way.
463
+
With a 5-minute prompt cache TTL, this activates buffered observations after 5 minutes of inactivity so the next uncached prompt uses compressed observations instead of a larger raw message window. If you prefer, `300_000` works the same way.
420
464
421
-
Changing model or providers mid-thread will invalidate the prompt cache. If your agent can switch between providers or models mid-thread, `activateOnProviderChange: true` forces buffered context to activate before the new provider runs. That avoids sending a large raw window to a provider that cannot reuse the previous prompt cache.
465
+
Changing model or providers mid-thread will invalidate the prompt cache. If your agent can switch between providers or models mid-thread, `activateOnProviderChange: true` forces buffered observations to activate before the new provider runs. That avoids sending a large raw window to a provider that can't reuse the previous prompt cache.
Copy file name to clipboardExpand all lines: docs/src/content/en/reference/memory/observational-memory.mdx
+39-2Lines changed: 39 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,11 +66,19 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
66
66
},
67
67
{
68
68
name: 'activateAfterIdle',
69
-
type: 'number | string',
69
+
type: 'number | string | false',
70
70
description:
71
-
'Time before buffered observations or buffered reflections are forced to activate after inactivity, even if their token thresholds have not been reached yet. Accepts milliseconds or duration strings like `300_000`, `"5m"`, or `"1hr"`. When the gap between the current time and the last assistant message part timestamp exceeds this value, buffered observational memory activates before the next prompt. Useful for aligning with prompt cache TTLs.',
71
+
'Time before buffered observations are forced to activate after inactivity, even before `observation.messageTokens` is reached. Accepts a numeric millisecond value such as `300_000`, duration strings like `"5m"` or `"1hr"`, or `false` to disable inherited observation idle activation. Reflections do not inherit this setting. Use `reflection.activateAfterIdle` to opt reflections into idle activation.',
72
72
isOptional: true,
73
73
},
74
+
{
75
+
name: 'activateOnProviderChange',
76
+
type: 'boolean',
77
+
description:
78
+
'Force buffered observations to activate when the actor provider or model changes. Reflections do not inherit this setting. Use `reflection.activateOnProviderChange` to opt reflections into provider-change activation.',
79
+
isOptional: true,
80
+
defaultValue: 'false',
81
+
},
74
82
{
75
83
name: 'shareTokenBudget',
76
84
type: 'boolean',
@@ -186,6 +194,20 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
186
194
isOptional: true,
187
195
defaultValue: '0.8',
188
196
},
197
+
{
198
+
name: 'activateAfterIdle',
199
+
type: 'number | string | false',
200
+
description:
201
+
'Time before buffered observations are forced to activate after inactivity. Accepts milliseconds, a duration string, or `false`. If unset, the top-level `activateAfterIdle` value is used for observations. Set `false` to disable the top-level idle setting for observations.',
202
+
isOptional: true,
203
+
},
204
+
{
205
+
name: 'activateOnProviderChange',
206
+
type: 'boolean',
207
+
description:
208
+
'Force buffered observations to activate when the actor provider or model changes. If unset, the top-level `activateOnProviderChange` value is used for observations.',
209
+
isOptional: true,
210
+
},
189
211
{
190
212
name: 'blockAfter',
191
213
type: 'number',
@@ -273,6 +295,21 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
273
295
isOptional: true,
274
296
defaultValue: '0.5',
275
297
},
298
+
{
299
+
name: 'activateAfterIdle',
300
+
type: 'number | string | false',
301
+
description:
302
+
'Time before buffered reflections are forced to activate after inactivity. Accepts milliseconds, a duration string, or `false`. Reflections do not inherit top-level `activateAfterIdle`; set this explicitly to opt reflections into idle activation.',
303
+
isOptional: true,
304
+
},
305
+
{
306
+
name: 'activateOnProviderChange',
307
+
type: 'boolean',
308
+
description:
309
+
'Force buffered reflections to activate when the actor provider or model changes. Reflections do not inherit top-level `activateOnProviderChange`; set this explicitly to opt reflections into provider-change activation.',
0 commit comments