@mastra/mcp-docs-server 1.3.13-alpha.9 → 1.3.14-alpha.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/.docs/docs/agents/code-mode.md +4 -0
- package/.docs/docs/agents/tools.md +12 -2
- package/.docs/docs/auth/custom-auth-provider.md +66 -0
- package/.docs/docs/auth/jwt.md +1 -1
- package/.docs/docs/connections/mcp.md +4 -65
- package/.docs/docs/evals/overview.md +4 -0
- package/.docs/docs/guides/authentication-identity.md +13 -1
- package/.docs/docs/harness/schedules.md +1 -1
- package/.docs/docs/knowledge/scopes-and-access.md +1 -1
- package/.docs/docs/memory/multi-user-threads.md +57 -127
- package/.docs/docs/memory/observational-memory.md +196 -756
- package/.docs/docs/memory/overview.md +4 -0
- package/.docs/docs/observability/feedback.md +5 -7
- package/.docs/docs/sandbox/overview.md +2 -0
- package/.docs/docs/sandbox/search.md +25 -0
- package/.docs/docs/server/mcp.md +347 -0
- package/.docs/docs/server/overview.md +1 -0
- package/.docs/docs/server/request-context.md +35 -0
- package/.docs/docs/server/server-adapters.md +2 -0
- package/.docs/docs/studio/auth.md +5 -1
- package/.docs/docs/studio/deployment.md +0 -1
- package/.docs/docs/studio/editor.md +17 -0
- package/.docs/docs/studio/overview.md +5 -5
- package/.docs/docs/workflows/scheduled-workflows.md +26 -5
- package/.docs/integrations/sandboxes/docker.md +39 -0
- package/.docs/integrations/sandboxes/e2b.md +1 -1
- package/.docs/integrations/voice/openai.md +2 -2
- package/.docs/models/gateways/custom-gateways.md +74 -44
- package/.docs/reference/agents/generate.md +1 -1
- package/.docs/reference/agents/generateLegacy.md +7 -23
- package/.docs/reference/auth/auth0.md +2 -0
- package/.docs/reference/auth/clerk.md +4 -0
- package/.docs/reference/auth/jwt.md +30 -2
- package/.docs/reference/cli/mastra.md +74 -6
- package/.docs/reference/client-js/observability.md +13 -5
- package/.docs/reference/configuration.md +64 -0
- package/.docs/reference/connect/tools.md +59 -0
- package/.docs/reference/editor/mastra-editor.md +1 -1
- package/.docs/reference/index.md +2 -0
- package/.docs/reference/knowledge/knowledge-class.md +1 -1
- package/.docs/reference/knowledge/knowledge-memory-scopes.md +44 -4
- package/.docs/reference/knowledge/scope-declarations.md +7 -3
- package/.docs/reference/memory/observational-memory.md +350 -151
- package/.docs/reference/observability/feedback.md +57 -14
- package/.docs/reference/observability/tracing/advanced-queries.md +3 -1
- package/.docs/reference/observability/tracing/exporters/langfuse.md +24 -1
- package/.docs/reference/observability/tracing/exporters/mastra-platform-exporter.md +19 -16
- package/.docs/reference/observability/tracing/exporters/otel.md +1 -1
- package/.docs/reference/observability/tracing/interfaces.md +2 -2
- package/.docs/reference/observability/tracing/spans.md +7 -1
- package/.docs/reference/processors/processor-interface.md +23 -0
- package/.docs/reference/rag/chunk.md +1 -1
- package/.docs/reference/rag/graph-rag-guide.md +3 -1
- package/.docs/reference/schedules/overview.md +25 -5
- package/.docs/reference/server/builtin-mcp-tools.md +135 -0
- package/.docs/reference/server/dispatch-route.md +124 -0
- package/.docs/reference/server/elysia-adapter.md +1 -1
- package/.docs/reference/server/express-adapter.md +17 -11
- package/.docs/reference/server/fastify-adapter.md +1 -1
- package/.docs/reference/server/hono-adapter.md +1 -1
- package/.docs/reference/server/invoke-route.md +10 -0
- package/.docs/reference/server/koa-adapter.md +1 -1
- package/.docs/reference/server/nestjs-adapter.md +1 -1
- package/.docs/reference/streaming/agents/stream.md +1 -1
- package/.docs/reference/tools/mcp-server.md +2 -0
- package/.docs/reference/workspace/factory-sandbox.md +20 -1
- package/.docs/reference/workspace/platform-sandbox.md +1 -1
- package/package.json +5 -5
|
@@ -41,11 +41,11 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
|
|
|
41
41
|
|
|
42
42
|
**autoModels** (`Record<string, string>`): Overrides the model automatic selection picks for a provider, keyed by provider ID. For example, { openai: "\_\_GATEWAY_OPENAI_MODEL_LUNA\_\_" }. Providers not listed use the built-in pick.
|
|
43
43
|
|
|
44
|
-
**
|
|
44
|
+
**canUseProvider** (`(providerId: string, context: { requestContext?: RequestContext }) => boolean`): Tells automatic selection whether the current request can use a provider. 'auto' prefers Gemini only when this returns true for 'google'. Use it when credentials are scoped per request, such as per tenant. When omitted, automatic selection checks GOOGLE_GENERATIVE_AI_API_KEY.
|
|
45
45
|
|
|
46
|
-
**
|
|
46
|
+
**resolveModel** (`(modelId: string, context: { requestContext?: RequestContext }) => MastraModelConfig | Promise<MastraModelConfig>`): Creates the model automatic selection picked, so it can use your credentials and routing. Receives only concrete model IDs, never "auto". When omitted, the picked ID goes through Mastra model routing.
|
|
47
47
|
|
|
48
|
-
**scope** (`'resource' | 'thread'`): Memory scope for observations. 'thread' keeps observations per-thread. 'resource' is deprecated and will be removed in a future release. It shares observations across all threads for a resource and works much worse than thread scope for prompt caching and agent understanding. For cross-thread continuity, use thread scope with retrieval
|
|
48
|
+
**scope** (`'resource' | 'thread'`): Memory scope for observations. 'thread' keeps observations per-thread. 'resource' is deprecated and will be removed in a future release. It shares observations across all threads for a resource and works much worse than thread scope for prompt caching and agent understanding. For cross-thread continuity, use thread scope with retrieval. See resource scope (deprecated). (Default: `'thread'`)
|
|
49
49
|
|
|
50
50
|
**activateAfterIdle** (`number | string | false | "auto" | Record<string, number | string | false | "auto">`): 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", "auto" for a provider-aware prompt cache TTL, false to disable inherited observation idle activation, or an object of per-provider TTLs such as { default: "auto", anthropic: "1h" }. Object keys match the actor model provider before the first ., case-insensitively, so anthropic covers the direct Anthropic provider but not Claude through another provider such as amazon-bedrock; default covers every other provider. Reflections do not inherit this setting. Use reflection.activateAfterIdle to opt reflections into idle activation.
|
|
51
51
|
|
|
@@ -55,7 +55,7 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
|
|
|
55
55
|
|
|
56
56
|
**temporalMarkers** (`boolean`): Insert temporal-gap reminder markers before new user messages when the previous message in the thread is at least 10 minutes older. The marker is persisted in memory, emitted as an inline reminder event so clients can render it specially, and shown to the observer so it can anchor observations to when events occurred. (Default: `false`)
|
|
57
57
|
|
|
58
|
-
**retrieval** (`boolean | { vector?: boolean; scope?: 'thread' | 'resource'; instructions?: string }`): Let the agent look up the raw message history behind its observations. Observation groups keep durable pointers to the original messages, and a recall tool is registered so the agent can browse them. true enables cross-thread browsing by default. { vector: true } also enables semantic search using Memory's vector store and embedder. { scope: 'thread' } restricts the recall tool to the current thread only. Default scope is 'resource'. { instructions: '...' } appends application-specific recall guidance after Mastra's built-in retrieval instructions. (Default: `false`)
|
|
58
|
+
**retrieval** (`boolean | { vector?: boolean; scope?: 'thread' | 'resource'; instructions?: string }`): Let the agent look up the raw message history behind its observations. Observation groups keep durable pointers to the original messages, and a recall tool is registered so the agent can browse them. true enables cross-thread browsing by default. { vector: true } also enables semantic search using Memory's vector store and embedder. A vector store that generates embeddings itself needs no embedder. { scope: 'thread' } restricts the recall tool to the current thread only. Default scope is 'resource'. { instructions: '...' } appends application-specific recall guidance after Mastra's built-in retrieval instructions. (Default: `false`)
|
|
59
59
|
|
|
60
60
|
**hooks** (`ObserveHooks`): Lifecycle hooks fired for every observation/reflection cycle — the manual observe()/reflect() APIs, turn-driven synchronous observation, and fire-and-forget async buffering. Callbacks receive threadId/resourceId/trigger call context ('manual' | 'turn-sync' | 'async-buffer'), and the end hooks (onObservationEnd/onReflectionEnd) additionally receive the OM model call's token usage and providerMetadata (where providers such as the AI Gateway report per-call cost), so apps can account for OM model spend without wrapping the observer/reflector models in middleware. Config-level lifecycle hooks are non-blocking by default: their errors are logged without failing the cycle. With hookExecution: 'await', config-level lifecycle errors can reject observe() or reflect(). Per-call observe({ hooks }) lifecycle hooks are also awaited and can reject observe(). A failing awaited start hook skips the model call; an end-hook failure can reject the call after its work has completed. Async-buffered cycles always use non-blocking config-level lifecycle hooks, regardless of hookExecution. Their cycle failures are reported through onObservationEnd.error or onReflectionEnd.error, rather than thrown to the caller. ObserveHooks also accepts transform hooks that intercept and can replace cycle data: beforeObservation({ messages, ...context }) runs on the messages about to be observed (return { messages } to filter/redact; an empty array skips the Observer call), afterObservation({ observations, ...context }) runs on the Observer's output before it is persisted, beforeReflection({ observations, ...context }) runs on the text sent to the Reflector, and afterReflection({ observations, ...context }) runs on the Reflector's output before it is persisted. Transform hooks return void to pass data through unchanged and are always awaited on every path. A thrown error fails the cycle before committing its transformed observation or reflection text, but doesn't roll back extractor callbacks or other side effects that already ran. The after hooks replace only text, not the separate structured extractor results stored in thread metadata. Reflection extraction and its callbacks run before afterReflection; this hook neither recomputes extracted values nor reruns callbacks. After hooks aren't a redaction boundary for all cycle data.
|
|
61
61
|
|
|
@@ -71,9 +71,9 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
|
|
|
71
71
|
|
|
72
72
|
**observation.extract** (`Extractor[]`): Custom values to extract after observation. Schema-less extractors are requested inline in the Observer output. Schema-backed extractors run as a follow-up structured output call and are stored in thread OM metadata.
|
|
73
73
|
|
|
74
|
-
**observation.manageWorkingMemory** (`boolean`): Let the Observer manage working memory through OM extraction. Adds WorkingMemoryExtractor, defaults workingMemory.agentManaged to false, and defaults workingMemory.useStateSignals to true. See
|
|
74
|
+
**observation.manageWorkingMemory** (`boolean`): Let the Observer manage working memory through OM extraction. Adds WorkingMemoryExtractor, defaults workingMemory.agentManaged to false, and defaults workingMemory.useStateSignals to true. See Let the Observer manage working memory.
|
|
75
75
|
|
|
76
|
-
**observation.observeAttachments** (`'auto' | boolean | string[]`): Controls which image/file attachments are forwarded to the Observer model alongside their placeholder text lines.
|
|
76
|
+
**observation.observeAttachments** (`'auto' | boolean | string[]`): Controls which image/file attachments are forwarded to the Observer model alongside their placeholder text lines. The default allowlist is \['image/\*', 'application/pdf']. true forwards all attachments. false drops all attachments while keeping placeholders visible. 'auto' uses the provider capabilities registry to decide: attachments are forwarded when the Observer model supports multimodal input, dropped otherwise, and forwarded when no capability data is available for the model. An array is a case-insensitive mimeType allowlist supporting exact matches ('application/pdf'), wildcard subtypes ('image/\*'), and bare '\*' for everything. Useful when the Observer model is text-only (e.g. some DeepSeek endpoints) while the main agent uses a multimodal model, or when you only want specific file types forwarded. Tool-result attachments are filtered using the same rule.
|
|
77
77
|
|
|
78
78
|
**observation.maxRetries** (`number`): Retries after the initial Observer model call on transient provider errors. Governs OM's own retry ladder; the Observer model call itself is configured with no provider-level retries.
|
|
79
79
|
|
|
@@ -139,16 +139,6 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
|
|
|
139
139
|
|
|
140
140
|
**reflection.blockAfter** (`number`): Safety net that forces a synchronous (blocking) reflection when background reflection can't keep up. Values from 1 up to (but not including) 100 are multipliers of observationTokens: 1.2 forces a blocking reflection at 120% of the threshold (48k tokens with the default 40k). Values of 100 or more are absolute token counts and must be greater than observationTokens. Between observationTokens and blockAfter, only async buffering and activation run. Only relevant when bufferActivation is set. Defaults to 1.2 when async reflection is enabled.
|
|
141
141
|
|
|
142
|
-
### Token estimate metadata cache
|
|
143
|
-
|
|
144
|
-
OM persists token payload estimates so repeated counting can reuse prior token estimation work.
|
|
145
|
-
|
|
146
|
-
- Part-level cache: `part.providerMetadata.mastra`.
|
|
147
|
-
- String-content fallback cache: message-level metadata when no parts exist.
|
|
148
|
-
- Cache entries are ignored and recomputed if cache version/tokenizer source doesn't match.
|
|
149
|
-
- Per-message and per-conversation overhead are always recomputed at runtime and aren't cached.
|
|
150
|
-
- `data-*` and `reasoning` parts are skipped and don't receive cache entries.
|
|
151
|
-
|
|
152
142
|
## Extractor API
|
|
153
143
|
|
|
154
144
|
`Extractor` defines a value that OM should extract during observation or reflection. Built-in OM values such as `current-task`, `suggested-response`, and `thread-title` use the same extractor pipeline as custom values.
|
|
@@ -208,31 +198,45 @@ const memory = new Memory({
|
|
|
208
198
|
|
|
209
199
|
## Examples
|
|
210
200
|
|
|
211
|
-
###
|
|
201
|
+
### Thresholds, instructions and buffering
|
|
212
202
|
|
|
213
|
-
|
|
203
|
+
One config that sets the main tuning options together. Every field is optional.
|
|
214
204
|
|
|
215
205
|
```typescript
|
|
216
206
|
import { Memory } from '@mastra/memory'
|
|
207
|
+
import { Agent } from '@mastra/core/agent'
|
|
217
208
|
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
209
|
+
export const agent = new Agent({
|
|
210
|
+
id: 'health-assistant',
|
|
211
|
+
name: 'health-assistant',
|
|
212
|
+
instructions: 'You are a health and wellness assistant.',
|
|
213
|
+
model: 'openai/gpt-6.1-sol',
|
|
214
|
+
memory: new Memory({
|
|
215
|
+
options: {
|
|
216
|
+
observationalMemory: {
|
|
217
|
+
model: 'auto',
|
|
218
|
+
observation: {
|
|
219
|
+
messageTokens: 20_000,
|
|
220
|
+
bufferTokens: 5_000,
|
|
221
|
+
bufferActivation: 0.7,
|
|
222
|
+
blockAfter: 1.5,
|
|
223
|
+
instruction:
|
|
224
|
+
'Prioritize health goals, dietary restrictions and exercise preferences. Skip general chit-chat.',
|
|
225
|
+
},
|
|
226
|
+
reflection: {
|
|
227
|
+
observationTokens: 60_000,
|
|
228
|
+
instruction:
|
|
229
|
+
'Group related health information together. Keep specific metrics and dates.',
|
|
230
|
+
},
|
|
227
231
|
},
|
|
228
232
|
},
|
|
229
|
-
},
|
|
233
|
+
}),
|
|
230
234
|
})
|
|
231
235
|
```
|
|
232
236
|
|
|
233
|
-
|
|
237
|
+
### Different models per agent
|
|
234
238
|
|
|
235
|
-
|
|
239
|
+
Set `observation.model` and `reflection.model` and leave the top-level `model` out. Setting the top-level `model` together with either one throws.
|
|
236
240
|
|
|
237
241
|
```typescript
|
|
238
242
|
import { Memory } from '@mastra/memory'
|
|
@@ -242,16 +246,15 @@ export const agent = new Agent({
|
|
|
242
246
|
id: 'my-agent',
|
|
243
247
|
name: 'my-agent',
|
|
244
248
|
instructions: 'You are a helpful assistant.',
|
|
245
|
-
model: 'openai/gpt-6-
|
|
249
|
+
model: 'openai/gpt-6.1-sol',
|
|
246
250
|
memory: new Memory({
|
|
247
251
|
options: {
|
|
248
252
|
observationalMemory: {
|
|
249
|
-
model: 'auto',
|
|
250
253
|
observation: {
|
|
251
|
-
|
|
254
|
+
model: 'auto',
|
|
252
255
|
},
|
|
253
256
|
reflection: {
|
|
254
|
-
|
|
257
|
+
model: 'openai/gpt-6-luna',
|
|
255
258
|
},
|
|
256
259
|
},
|
|
257
260
|
},
|
|
@@ -261,7 +264,7 @@ export const agent = new Agent({
|
|
|
261
264
|
|
|
262
265
|
### Shared token budget
|
|
263
266
|
|
|
264
|
-
When `shareTokenBudget` is enabled, the total budget is `observation.messageTokens + reflection.observationTokens`, which is 100k in this example. Observations that use only 30k tokens leave up to 70k for messages, while short messages give observations more room before reflection starts.
|
|
267
|
+
When `shareTokenBudget` is enabled, the total budget is `observation.messageTokens + reflection.observationTokens`, which is 100k in this example. Observations that use only 30k tokens leave up to 70k for messages, while short messages give observations more room before reflection starts. Shared budgets need async buffering turned off.
|
|
265
268
|
|
|
266
269
|
```typescript
|
|
267
270
|
import { Memory } from '@mastra/memory'
|
|
@@ -278,7 +281,7 @@ export const agent = new Agent({
|
|
|
278
281
|
shareTokenBudget: true,
|
|
279
282
|
observation: {
|
|
280
283
|
messageTokens: 20_000,
|
|
281
|
-
bufferTokens: false,
|
|
284
|
+
bufferTokens: false,
|
|
282
285
|
},
|
|
283
286
|
reflection: {
|
|
284
287
|
observationTokens: 80_000,
|
|
@@ -289,153 +292,336 @@ export const agent = new Agent({
|
|
|
289
292
|
})
|
|
290
293
|
```
|
|
291
294
|
|
|
292
|
-
###
|
|
295
|
+
### Async buffering
|
|
296
|
+
|
|
297
|
+
Async buffering is on by default with these settings:
|
|
298
|
+
|
|
299
|
+
- `observation.bufferTokens: 0.2` buffers every 20% of `messageTokens`.
|
|
300
|
+
- `observation.bufferActivation: 0.8` keeps 20% of the threshold after activation.
|
|
301
|
+
- `reflection.bufferActivation: 0.5` starts background reflection at half the reflection threshold.
|
|
302
|
+
|
|
303
|
+
Buffered Observer calls don't produce continuation hints, and activation clears stored ones. See [When buffering falls behind](#when-buffering-falls-behind) for what happens between the threshold and `blockAfter`.
|
|
304
|
+
|
|
305
|
+
Set `observation.bufferTokens: false` to turn off buffering for both observation and reflection. Each then runs synchronously at its threshold.
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
observationalMemory: {
|
|
309
|
+
observation: {
|
|
310
|
+
bufferTokens: false,
|
|
311
|
+
},
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Async buffering is off in the deprecated `scope: 'resource'`.
|
|
293
316
|
|
|
294
|
-
|
|
317
|
+
## Early activation
|
|
318
|
+
|
|
319
|
+
By default, buffered observations activate when message history reaches `observation.messageTokens`. OM can activate them sooner, which helps when a prompt cache is about to expire or when the agent switches model providers. In both cases the next request can't reuse the cached prompt anyway, so sending a smaller, compressed context costs nothing extra.
|
|
320
|
+
|
|
321
|
+
- `activateAfterIdle`: activate after the thread has been idle for this long. Accepts milliseconds (`300_000`), a duration string (`'5m'`, `'1hr'`), `'auto'` for a provider-aware prompt cache TTL, or a per-provider object (see [per-provider idle TTLs](#per-provider-idle-ttls)).
|
|
322
|
+
- `activateOnProviderChange`: activate when the next step uses a different `provider/model` than the one that produced the latest assistant step. Default `false`.
|
|
295
323
|
|
|
296
324
|
```typescript
|
|
297
325
|
import { Memory } from '@mastra/memory'
|
|
298
|
-
import { Agent } from '@mastra/core/agent'
|
|
299
326
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
memory: new Memory({
|
|
306
|
-
options: {
|
|
307
|
-
observationalMemory: {
|
|
308
|
-
model: 'openai/gpt-6-luna',
|
|
309
|
-
},
|
|
327
|
+
const memory = new Memory({
|
|
328
|
+
options: {
|
|
329
|
+
observationalMemory: {
|
|
330
|
+
activateAfterIdle: 'auto',
|
|
331
|
+
activateOnProviderChange: true,
|
|
310
332
|
},
|
|
311
|
-
}
|
|
333
|
+
},
|
|
312
334
|
})
|
|
313
335
|
```
|
|
314
336
|
|
|
315
|
-
|
|
337
|
+
Top-level settings apply to observations only. Reflections opt in on their own, through the nested `reflection` settings:
|
|
316
338
|
|
|
317
339
|
```typescript
|
|
318
340
|
import { Memory } from '@mastra/memory'
|
|
319
|
-
import { Agent } from '@mastra/core/agent'
|
|
320
341
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
},
|
|
332
|
-
reflection: {
|
|
333
|
-
model: 'openai/gpt-6-luna',
|
|
334
|
-
},
|
|
342
|
+
const memory = new Memory({
|
|
343
|
+
options: {
|
|
344
|
+
observationalMemory: {
|
|
345
|
+
activateAfterIdle: '5m',
|
|
346
|
+
observation: {
|
|
347
|
+
activateAfterIdle: false,
|
|
348
|
+
},
|
|
349
|
+
reflection: {
|
|
350
|
+
activateAfterIdle: '10m',
|
|
351
|
+
activateOnProviderChange: true,
|
|
335
352
|
},
|
|
336
353
|
},
|
|
337
|
-
}
|
|
354
|
+
},
|
|
338
355
|
})
|
|
339
356
|
```
|
|
340
357
|
|
|
341
|
-
|
|
358
|
+
Here observations ignore the top-level idle setting, while reflections opt into idle and provider-change activation.
|
|
342
359
|
|
|
343
|
-
|
|
360
|
+
### Automatic idle TTLs
|
|
361
|
+
|
|
362
|
+
With `activateAfterIdle: 'auto'`, Mastra picks the idle TTL from the active model provider:
|
|
363
|
+
|
|
364
|
+
| Provider | Auto TTL |
|
|
365
|
+
| ------------------------------------------------------------------------------------------------------ | --------- |
|
|
366
|
+
| Anthropic, OpenRouter, unknown providers, xAI | 5 minutes |
|
|
367
|
+
| DeepSeek | 1 hour |
|
|
368
|
+
| Google Gemini | 24 hours |
|
|
369
|
+
| Groq | 2 hours |
|
|
370
|
+
| OpenAI with `providerOptions.openai.promptCacheRetention: "24h"` | 1 hour |
|
|
371
|
+
| OpenAI with `providerOptions.openai.promptCacheRetention: "in_memory"` | 5 minutes |
|
|
372
|
+
| OpenAI `gpt-4*`, `gpt-5`, `gpt-5-*`, and `gpt-5.1` through `gpt-5.4` (including `-` suffixed variants) | 5 minutes |
|
|
373
|
+
| Other OpenAI models | 1 hour |
|
|
374
|
+
|
|
375
|
+
For a fixed TTL instead, use `'5m'` or `300_000`.
|
|
376
|
+
|
|
377
|
+
### Per-provider idle TTLs
|
|
378
|
+
|
|
379
|
+
`'auto'` can't see a cache TTL that you set on individual messages, such as Anthropic's `cacheControl: { type: 'ephemeral', ttl: '1h' }`. It keeps using the provider's 5-minute default, so buffered observations activate while the 1-hour cache is still warm. Pass an object to set the TTL per provider:
|
|
344
380
|
|
|
345
381
|
```typescript
|
|
346
382
|
import { Memory } from '@mastra/memory'
|
|
347
|
-
import { Agent } from '@mastra/core/agent'
|
|
348
383
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
384
|
+
const memory = new Memory({
|
|
385
|
+
options: {
|
|
386
|
+
observationalMemory: {
|
|
387
|
+
activateAfterIdle: { default: 'auto', anthropic: '1h' },
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
})
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
Set the `anthropic` entry to the same TTL as your `cacheControl.ttl`. Mastra doesn't read the per-message cache setting, so keep the two in sync by hand.
|
|
394
|
+
|
|
395
|
+
How the object resolves:
|
|
396
|
+
|
|
397
|
+
- Keys are provider names. Mastra compares them case-insensitively with the part of the model's provider before the first `.`, so `anthropic` matches both `anthropic` and `anthropic.messages`. Claude served through another provider uses that provider's key, for example `amazon-bedrock`. Keys must not contain `.` or `/`.
|
|
398
|
+
- Each value accepts the same forms as a single TTL: milliseconds, a duration string, `'auto'`, or `false` to turn off idle activation for that provider.
|
|
399
|
+
- `default` applies to every provider without its own key. Without `default`, those providers don't idle-activate.
|
|
400
|
+
- `observation.activateAfterIdle` and `reflection.activateAfterIdle` accept the same object. An `observation.activateAfterIdle` object replaces the top-level value and isn't merged with it.
|
|
401
|
+
|
|
402
|
+
## Buffer on idle
|
|
403
|
+
|
|
404
|
+
Set `observation.bufferOnIdle: true` to run background observation buffering when an agent turn ends and the agent becomes idle. Short turns then get observed without waiting for the next turn or the `messageTokens` threshold.
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
import { Memory } from '@mastra/memory'
|
|
408
|
+
|
|
409
|
+
const memory = new Memory({
|
|
410
|
+
options: {
|
|
411
|
+
observationalMemory: {
|
|
412
|
+
observation: {
|
|
413
|
+
bufferOnIdle: true,
|
|
368
414
|
},
|
|
369
415
|
},
|
|
370
|
-
}
|
|
416
|
+
},
|
|
371
417
|
})
|
|
372
418
|
```
|
|
373
419
|
|
|
374
|
-
|
|
420
|
+
`bufferOnIdle` is off by default. It's separate from `bufferTokens`: `bufferTokens` controls buffering during steps, `bufferOnIdle` controls buffering at the end of an idle turn.
|
|
375
421
|
|
|
376
|
-
|
|
422
|
+
## When buffering falls behind
|
|
377
423
|
|
|
378
|
-
|
|
424
|
+
When messages arrive faster than the Observer can buffer them, history can pass `messageTokens` before a buffered chunk is ready. Between `messageTokens` and `observation.blockAfter` (default `1.2`, so 36,000 tokens with the default threshold), Mastra keeps buffering in the background and activates the chunk on a later step, so the agent doesn't wait.
|
|
379
425
|
|
|
380
|
-
|
|
426
|
+
If pending tokens still reach `blockAfter` after buffered activation, for example when a large tool result leaves an uncovered tail, a synchronous observation runs. At `blockAfter`, activation first waits a bounded time for a buffered observation that's still being produced. If that takes longer, Mastra observes the remaining messages synchronously and drops the late observation if its messages are already observed. Activations triggered by the idle TTL or a provider change don't wait.
|
|
381
427
|
|
|
382
|
-
|
|
383
|
-
- `observation.bufferActivation: 0.8`: On activation, remove enough messages to keep only 20% of the threshold remaining
|
|
384
|
-
- `reflection.bufferActivation: 0.5`: start background reflection at 50% of observation threshold
|
|
428
|
+
Above `blockAfter`, activation may overshoot the retention target instead of using fewer chunks. Buffered activation usually keeps a minimum remaining context (the smaller of about 1,000 tokens or the configured retention floor), but a single chunk that covers the whole pending window still activates and can leave less.
|
|
385
429
|
|
|
386
|
-
Async buffered Observer calls don't
|
|
430
|
+
Async buffered Observer calls don't produce continuation hints, because a delayed hint can be stale by the time it activates. When buffered chunks activate, any stored suggested response and current task are cleared.
|
|
387
431
|
|
|
388
|
-
|
|
432
|
+
Reflection buffers the same way. It starts in the background when observations reach `reflection.bufferActivation` (default `0.5`) of `reflection.observationTokens`, and runs synchronously above `reflection.blockAfter` (default `1.2`) when no buffered reflection is ready.
|
|
433
|
+
|
|
434
|
+
## Retries and failure policy
|
|
435
|
+
|
|
436
|
+
Observer and Reflector model calls are retried on transient provider errors. Each stage has two settings:
|
|
437
|
+
|
|
438
|
+
- `maxRetries`: retries after the first model call. Default `8`. This is the only retry setting for the stage: the underlying model call runs with no provider-level retries.
|
|
439
|
+
- `failurePolicy`: what happens once retries run out. `'abort'` (default) fails the turn, and `'continue'` lets it go on.
|
|
389
440
|
|
|
390
441
|
```typescript
|
|
391
442
|
import { Memory } from '@mastra/memory'
|
|
392
|
-
import { Agent } from '@mastra/core/agent'
|
|
393
443
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
messageTokens: 30_000,
|
|
405
|
-
// Buffer every 5k tokens (runs in background)
|
|
406
|
-
bufferTokens: 5_000,
|
|
407
|
-
// Activate to retain 30% of threshold
|
|
408
|
-
bufferActivation: 0.7,
|
|
409
|
-
// Observe synchronously at 1.5x the threshold if no buffered chunk is ready
|
|
410
|
-
blockAfter: 1.5,
|
|
411
|
-
},
|
|
412
|
-
reflection: {
|
|
413
|
-
observationTokens: 60_000,
|
|
414
|
-
// Start background reflection at 50% of threshold
|
|
415
|
-
bufferActivation: 0.5,
|
|
416
|
-
// Force synchronous reflection at 1.2x threshold
|
|
417
|
-
blockAfter: 1.2,
|
|
418
|
-
},
|
|
444
|
+
const memory = new Memory({
|
|
445
|
+
options: {
|
|
446
|
+
observationalMemory: {
|
|
447
|
+
observation: {
|
|
448
|
+
maxRetries: 8,
|
|
449
|
+
failurePolicy: 'continue',
|
|
450
|
+
},
|
|
451
|
+
reflection: {
|
|
452
|
+
maxRetries: 8,
|
|
453
|
+
failurePolicy: 'continue',
|
|
419
454
|
},
|
|
420
455
|
},
|
|
421
|
-
}
|
|
456
|
+
},
|
|
422
457
|
})
|
|
423
458
|
```
|
|
424
459
|
|
|
425
|
-
|
|
460
|
+
A provider outage usually takes out both stages, so set the policy on both if you want the turn to survive one.
|
|
461
|
+
|
|
462
|
+
With `'continue'`, Mastra reports the failure through OM diagnostics, keeps the failed input pending for a later cycle, and lets the turn continue. It doesn't advance observation boundaries or discard unobserved messages. A Reflector failure leaves already-persisted observations committed and retries reflection at the next threshold crossing.
|
|
463
|
+
|
|
464
|
+
The policy covers only Observer and Reflector model and provider failures in synchronous runs: at `blockAfter`, when async buffering is off, and in resource-scoped observation. Persistence, indexing, transform, locking, invariant and explicit abort failures stay fatal.
|
|
465
|
+
|
|
466
|
+
Background buffering failures never stop the turn, whatever the policy. They're reported as `om_buffering_failed`, and the failed input stays pending. If it keeps growing, it reaches `blockAfter`, where synchronous observation applies `failurePolicy`.
|
|
467
|
+
|
|
468
|
+
> **Warning:** `'continue'` has no backstop for a long outage. Unobserved messages stay pending and keep growing in the main agent's context until they reach the model's context limit.
|
|
469
|
+
|
|
470
|
+
## Temporal gap markers
|
|
471
|
+
|
|
472
|
+
Temporal gap markers insert a short reminder before a new user message when at least 10 minutes have passed since the previous message in the thread. They're off by default.
|
|
426
473
|
|
|
427
474
|
```typescript
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
475
|
+
import { Memory } from '@mastra/memory'
|
|
476
|
+
|
|
477
|
+
const memory = new Memory({
|
|
478
|
+
options: {
|
|
479
|
+
observationalMemory: {
|
|
480
|
+
temporalMarkers: true,
|
|
481
|
+
},
|
|
482
|
+
},
|
|
483
|
+
})
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
The marker is stored in memory and also emitted as a transient reminder event, so clients can render it as a timeline hint. The Observer sees the markers too, so observations can say when something happened, for example "User asked about deployment after a 2-day gap".
|
|
487
|
+
|
|
488
|
+
## Token estimates
|
|
489
|
+
|
|
490
|
+
OM decides when to observe from local token estimates, not from the provider's usage report. Text is estimated with `tokenx`; images use provider-aware heuristics, which also apply to image-like `file` parts. Provider counts can run higher than the estimate, which is why [context-overflow recovery](https://mastra.ai/docs/memory/observational-memory) exists.
|
|
491
|
+
|
|
492
|
+
### Token-count cache
|
|
493
|
+
|
|
494
|
+
OM caches estimates in message metadata so threshold checks don't recount the same content:
|
|
495
|
+
|
|
496
|
+
- Per-part estimates are stored on `part.providerMetadata.mastra` and reused while the cache version and tokenizer source match.
|
|
497
|
+
- Messages with string-only content (no parts) use a message-level cache.
|
|
498
|
+
- Message and conversation overhead is recalculated every pass. Only payload estimates are cached.
|
|
499
|
+
- `data-*` and `reasoning` parts are skipped and not cached.
|
|
500
|
+
|
|
501
|
+
### Supplying your own estimate for a file
|
|
502
|
+
|
|
503
|
+
You can attach a token estimate to an `image` or `file` part with `providerMetadata.mastra.tokenEstimate`. The token counter uses it as is:
|
|
504
|
+
|
|
505
|
+
```typescript
|
|
506
|
+
const filePart = {
|
|
507
|
+
type: 'file',
|
|
508
|
+
data: 'storage://bucket/large-report.pdf',
|
|
509
|
+
mimeType: 'application/pdf',
|
|
510
|
+
filename: 'large-report.pdf',
|
|
511
|
+
providerMetadata: {
|
|
512
|
+
mastra: {
|
|
513
|
+
tokenEstimate: {
|
|
514
|
+
v: 0,
|
|
515
|
+
source: 'client',
|
|
516
|
+
key: 'client',
|
|
517
|
+
tokens: 100_000,
|
|
518
|
+
},
|
|
519
|
+
},
|
|
432
520
|
},
|
|
433
521
|
}
|
|
434
522
|
```
|
|
435
523
|
|
|
436
|
-
|
|
524
|
+
- `v`: cache schema version. Set it to `0`. OM doesn't read it for caller entries.
|
|
525
|
+
- `source`: must be `'client'`. This marks the entry as authoritative so it isn't recomputed or overwritten.
|
|
526
|
+
- `key`: set to `'client'`. Framework entries put a content hash here. `'client'` keeps your estimate stable across writes.
|
|
527
|
+
- `tokens`: the count to use. Must be a finite, non-negative number.
|
|
528
|
+
|
|
529
|
+
The estimate is honored only on `image` and `file` parts. `text` and `tool-invocation` parts are always counted.
|
|
437
530
|
|
|
438
|
-
|
|
531
|
+
## Limiting what the Observer re-reads
|
|
532
|
+
|
|
533
|
+
By default the Observer receives the full observation log as context with every batch of new messages, plus the previous `current-task` and `suggested-response` values. When the log grows large, set `observation.previousObserverTokens` to cap it:
|
|
534
|
+
|
|
535
|
+
```typescript
|
|
536
|
+
import { Memory } from '@mastra/memory'
|
|
537
|
+
|
|
538
|
+
const memory = new Memory({
|
|
539
|
+
options: {
|
|
540
|
+
observationalMemory: {
|
|
541
|
+
observation: {
|
|
542
|
+
previousObserverTokens: 10_000,
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
},
|
|
546
|
+
})
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
- `false` (default): send the full log.
|
|
550
|
+
- A number such as `2000`: keep about that many tokens of the most recent observations.
|
|
551
|
+
- `0`: send no previous observations.
|
|
552
|
+
|
|
553
|
+
When a buffered reflection is pending, the lines it already covers are replaced with the reflection before truncation.
|
|
554
|
+
|
|
555
|
+
## Let the Observer manage working memory
|
|
556
|
+
|
|
557
|
+
Set `observation.manageWorkingMemory: true` to have the Observer keep [working memory](https://mastra.ai/docs/memory/working-memory) up to date, instead of relying on the main agent to call the working memory tool.
|
|
558
|
+
|
|
559
|
+
```typescript
|
|
560
|
+
import { Memory } from '@mastra/memory'
|
|
561
|
+
|
|
562
|
+
const memory = new Memory({
|
|
563
|
+
options: {
|
|
564
|
+
workingMemory: {
|
|
565
|
+
enabled: true,
|
|
566
|
+
},
|
|
567
|
+
observationalMemory: {
|
|
568
|
+
observation: {
|
|
569
|
+
manageWorkingMemory: true,
|
|
570
|
+
},
|
|
571
|
+
},
|
|
572
|
+
},
|
|
573
|
+
})
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
This adds a `WorkingMemoryExtractor` and changes two working memory defaults:
|
|
577
|
+
|
|
578
|
+
- `workingMemory.agentManaged` defaults to `false`, so the main agent no longer gets the working memory tool and instructions. Set it to `true` to keep them.
|
|
579
|
+
- `workingMemory.useStateSignals` defaults to `true`, which moves working memory out of the system prompt into state signals so updates don't invalidate the prompt cache.
|
|
580
|
+
|
|
581
|
+
## Hooks
|
|
582
|
+
|
|
583
|
+
`observationalMemory.hooks` takes two kinds of hooks:
|
|
584
|
+
|
|
585
|
+
- **Lifecycle hooks** (`onObservationStart`, `onObservationEnd`, `onReflectionStart`, `onReflectionEnd`) are for telemetry. They receive `threadId`, `resourceId` and `trigger`; the end hooks also receive the model call's `usage`, `providerMetadata` and any `error`. They never change what OM stores.
|
|
586
|
+
- **Transform hooks** (`beforeObservation`, `afterObservation`, `beforeReflection`, `afterReflection`) change the data flowing through a cycle. Return nothing to pass the input through, or return a replacement.
|
|
587
|
+
|
|
588
|
+
```typescript
|
|
589
|
+
const memory = new Memory({
|
|
590
|
+
options: {
|
|
591
|
+
observationalMemory: {
|
|
592
|
+
hooks: {
|
|
593
|
+
// Drop or redact messages before the Observer sees them.
|
|
594
|
+
beforeObservation: ({ messages }) => ({
|
|
595
|
+
messages: messages.filter(m => !isSensitive(m)),
|
|
596
|
+
}),
|
|
597
|
+
// Rewrite observations before they are persisted.
|
|
598
|
+
afterObservation: ({ observations }) => ({
|
|
599
|
+
observations: redact(observations),
|
|
600
|
+
}),
|
|
601
|
+
// Rewrite the text the Reflector condenses.
|
|
602
|
+
beforeReflection: ({ observations }) => ({
|
|
603
|
+
observations: stripInternalNotes(observations),
|
|
604
|
+
}),
|
|
605
|
+
afterReflection: async ({ observations, resourceId }) => {
|
|
606
|
+
await syncToExternalStore(resourceId, observations)
|
|
607
|
+
},
|
|
608
|
+
},
|
|
609
|
+
},
|
|
610
|
+
},
|
|
611
|
+
})
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
Transform hooks are always awaited, on every path: manual `observe()` and `reflect()`, synchronous observation during a turn, and async buffering. If `beforeObservation` returns an empty `messages` array, the Observer call is skipped and those messages are still marked as observed. If a transform hook throws, the cycle fails before committing the transformed text. Extractor callbacks and other side effects that already ran aren't rolled back.
|
|
615
|
+
|
|
616
|
+
`afterObservation` and `afterReflection` replace only the observation or reflection text. They don't touch the structured extractor values stored in thread metadata, and reflection extraction runs before `afterReflection`. Don't treat an after hook as a redaction boundary for everything in the cycle.
|
|
617
|
+
|
|
618
|
+
Hooks receive `threadId` and `resourceId`, so they can also update working memory with `memory.updateWorkingMemory()`. Those updates aren't atomic with the OM commit.
|
|
619
|
+
|
|
620
|
+
To keep skill instructions out of the Observer, use [`skillResultRedactor`](#skillresultredactor).
|
|
621
|
+
|
|
622
|
+
## Migrating existing threads
|
|
623
|
+
|
|
624
|
+
No migration is needed. OM reads existing messages and observes them when a thread first exceeds `observation.messageTokens`, processing the backlog then. Under the deprecated resource scope, all unobserved messages across a resource's threads are processed together, which can take a long time for users with many threads.
|
|
439
625
|
|
|
440
626
|
## Streaming data parts
|
|
441
627
|
|
|
@@ -730,15 +916,15 @@ Emitted when the Observer updates the thread title. Only emitted when `observati
|
|
|
730
916
|
|
|
731
917
|
## Standalone usage
|
|
732
918
|
|
|
733
|
-
Most
|
|
919
|
+
Most apps should use the `Memory` class. Use the `ObservationalMemory` engine directly for benchmarking, experiments, or when OM must run in a specific order with other processors such as [guardrails](https://mastra.ai/docs/agents/guardrails).
|
|
734
920
|
|
|
735
|
-
|
|
921
|
+
Wrap the engine in an `ObservationalMemoryProcessor`, which needs a `Memory` instance to load and persist messages. `stores.memory` is typed as optional on storage adapters, so assert or check it:
|
|
736
922
|
|
|
737
923
|
```typescript
|
|
738
|
-
import { ObservationalMemory, ObservationalMemoryProcessor } from '@mastra/memory/processors'
|
|
739
|
-
import { Memory } from '@mastra/memory'
|
|
740
924
|
import { Agent } from '@mastra/core/agent'
|
|
741
925
|
import { LibSQLStore } from '@mastra/libsql'
|
|
926
|
+
import { Memory } from '@mastra/memory'
|
|
927
|
+
import { ObservationalMemory, ObservationalMemoryProcessor } from '@mastra/memory/processors'
|
|
742
928
|
|
|
743
929
|
const storage = new LibSQLStore({
|
|
744
930
|
id: 'my-storage',
|
|
@@ -763,7 +949,7 @@ const omProcessor = new ObservationalMemoryProcessor(om, memory)
|
|
|
763
949
|
|
|
764
950
|
export const agent = new Agent({
|
|
765
951
|
id: 'my-agent',
|
|
766
|
-
name: '
|
|
952
|
+
name: 'My Agent',
|
|
767
953
|
instructions: 'You are a helpful assistant.',
|
|
768
954
|
model: 'openai/gpt-6-luna',
|
|
769
955
|
inputProcessors: [omProcessor],
|
|
@@ -771,6 +957,17 @@ export const agent = new Agent({
|
|
|
771
957
|
})
|
|
772
958
|
```
|
|
773
959
|
|
|
960
|
+
The engine takes the same options as the `observationalMemory` config, plus `storage`, `onDebugEvent` and `obscureThreadIds`. See [standalone config](#standalone-config).
|
|
961
|
+
|
|
962
|
+
`om.observe()` only observes once pending tokens reach the threshold. Pass `force: true` to observe pending messages now. The bypass applies to that call only.
|
|
963
|
+
|
|
964
|
+
```typescript
|
|
965
|
+
const result = await om.observe({ threadId, resourceId, force: true })
|
|
966
|
+
// result.observed is true when pending messages were observed
|
|
967
|
+
```
|
|
968
|
+
|
|
969
|
+
Agents don't need this to recover from context-window errors. [Context-overflow recovery](https://mastra.ai/docs/memory/observational-memory) handles that.
|
|
970
|
+
|
|
774
971
|
### Standalone config
|
|
775
972
|
|
|
776
973
|
The standalone `ObservationalMemory` class accepts all the same options as the `observationalMemory` config object above, plus the following:
|
|
@@ -781,17 +978,6 @@ The standalone `ObservationalMemory` class accepts all the same options as the `
|
|
|
781
978
|
|
|
782
979
|
**obscureThreadIds** (`boolean`): When enabled, thread IDs are hashed before being included in observation context. This prevents the LLM from recognizing patterns in thread identifiers. Automatically enabled when using resource scope through the Memory class. (Default: `false`)
|
|
783
980
|
|
|
784
|
-
### Forcing observation
|
|
785
|
-
|
|
786
|
-
`observe()` only observes once pending tokens reach the observation threshold. Pass `force: true` to observe pending messages regardless of the threshold. The bypass applies to that call only and isn't saved to the record's config.
|
|
787
|
-
|
|
788
|
-
```typescript
|
|
789
|
-
const result = await om.observe({ threadId, resourceId, force: true })
|
|
790
|
-
// result.observed: true if pending messages were observed
|
|
791
|
-
```
|
|
792
|
-
|
|
793
|
-
Agents don't need this to recover from context-window errors. `observation.observeOnContextOverflow` handles that automatically.
|
|
794
|
-
|
|
795
981
|
## Recall tool
|
|
796
982
|
|
|
797
983
|
When `retrieval` is truthy, Mastra registers a `recall` tool that pages through raw messages behind observation group ranges. With the default resource scope, the tool can list threads (`mode: "threads"`) and browse another thread through `threadId`. It also supports cross-thread search. Set `retrieval: { vector: true }` for semantic search (`mode: "search"`), or use `scope: 'thread'` to restrict the tool to the current thread. The tool is automatically added to the agent.
|
|
@@ -824,7 +1010,7 @@ Group IDs in search results include the record that holds them (`groupId@recordI
|
|
|
824
1010
|
|
|
825
1011
|
### Parameters
|
|
826
1012
|
|
|
827
|
-
**mode** (`'messages' | 'threads' | 'search' | 'observations'`): What to retrieve. "messages" (default) pages through message history. "threads" lists threads for the current user. "search" finds messages by semantic similarity (requires vector store
|
|
1013
|
+
**mode** (`'messages' | 'threads' | 'search' | 'observations'`): What to retrieve. "messages" (default) pages through message history. "threads" lists threads for the current user. "search" finds messages by semantic similarity (requires a vector store, plus an embedder unless the store generates embeddings itself). "observations" pages original observation groups around a search hit. (Default: `'messages'`)
|
|
828
1014
|
|
|
829
1015
|
**groupId** (`string`): Required for observations mode. Copy the observation group ID exactly from a search result or continuation call. IDs shown as groupId\@recordId let paging read the record directly; a plain group ID also works.
|
|
830
1016
|
|
|
@@ -912,7 +1098,7 @@ Group IDs in search results include the record that holds them (`groupId@recordI
|
|
|
912
1098
|
new ModelByInputTokens(config)
|
|
913
1099
|
```
|
|
914
1100
|
|
|
915
|
-
Where `config` is an object with `upTo` keys that map token thresholds (numbers) to model targets. Each tier needs a concrete model
|
|
1101
|
+
Where `config` is an object with `upTo` keys that map token thresholds (numbers) to model targets. Each tier needs a concrete model ID, not `"auto"`.
|
|
916
1102
|
|
|
917
1103
|
#### Example
|
|
918
1104
|
|
|
@@ -961,6 +1147,19 @@ const memory = new Memory({
|
|
|
961
1147
|
})
|
|
962
1148
|
```
|
|
963
1149
|
|
|
1150
|
+
Pass `toolNames` to redact a different set of tools. To combine it with your own transform, chain the outputs and await each hook:
|
|
1151
|
+
|
|
1152
|
+
```typescript
|
|
1153
|
+
const dropSkillResults = skillResultRedactor()
|
|
1154
|
+
|
|
1155
|
+
hooks: {
|
|
1156
|
+
beforeObservation: async input => {
|
|
1157
|
+
const messages = (await dropSkillResults(input))?.messages ?? input.messages
|
|
1158
|
+
return { messages: messages.filter(m => m.role !== 'signal') }
|
|
1159
|
+
},
|
|
1160
|
+
}
|
|
1161
|
+
```
|
|
1162
|
+
|
|
964
1163
|
#### Parameters
|
|
965
1164
|
|
|
966
1165
|
**toolNames** (`readonly string[]`): Tool names whose results are redacted. Defaults to the built-in skill tools: skill, skill_search, and skill_read. Use this to redact a different set of tool results.
|