@mastra/mcp-docs-server 1.3.8 → 1.3.9-alpha.10
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/guardrails.md +3 -0
- package/.docs/docs/agents/human-in-the-loop.md +2 -1
- package/.docs/docs/agents/processors.md +3 -0
- package/.docs/docs/harness/agent-controller.md +1 -1
- package/.docs/docs/harness/background-tasks.md +11 -0
- package/.docs/docs/harness/durable-agents.md +24 -8
- package/.docs/docs/harness/signals.md +3 -1
- package/.docs/docs/mastra-platform/connect/channels.md +14 -2
- package/.docs/docs/mastra-platform/connect/overview.md +1 -1
- package/.docs/docs/mastra-platform/connect/providers.md +1 -0
- package/.docs/docs/mastra-platform/connect/tools.md +25 -3
- package/.docs/docs/mastra-platform/observability.md +1 -1
- package/.docs/docs/memory/observational-memory.md +4 -2
- package/.docs/docs/memory/semantic-recall.md +2 -0
- package/.docs/docs/studio/overview.md +8 -0
- package/.docs/docs/workflows/control-flow.md +3 -1
- package/.docs/docs/workflows/overview.md +2 -0
- package/.docs/docs/workflows/time-travel.md +1 -1
- package/.docs/integrations/databases/clickhouse.md +1 -1
- package/.docs/integrations/voice/google.md +6 -0
- package/.docs/models/embeddings.md +2 -1
- package/.docs/models/environment-variables.md +2 -0
- package/.docs/models/gateways/merge-gateway.md +4 -1
- package/.docs/models/gateways/netlify.md +14 -4
- package/.docs/models/gateways/openrouter.md +11 -4
- package/.docs/models/gateways/vercel.md +11 -3
- package/.docs/models/index.md +3 -1
- package/.docs/models/providers/302ai.md +2 -1
- package/.docs/models/providers/aimlapi.md +3 -3
- package/.docs/models/providers/alibaba-token-plan-cn.md +31 -30
- package/.docs/models/providers/ambient.md +2 -1
- package/.docs/models/providers/baseten.md +27 -25
- package/.docs/models/providers/cloudflare-workers-ai.md +2 -1
- package/.docs/models/providers/commandcode.md +147 -0
- package/.docs/models/providers/coralbricks.md +5 -8
- package/.docs/models/providers/cortecs.md +5 -6
- package/.docs/models/providers/databricks.md +2 -1
- package/.docs/models/providers/deepinfra.md +3 -1
- package/.docs/models/providers/edenai.md +11 -3
- package/.docs/models/providers/empiriolabs.md +3 -1
- package/.docs/models/providers/engy.md +12 -11
- package/.docs/models/providers/fireworks-ai.md +3 -1
- package/.docs/models/providers/huggingface.md +2 -1
- package/.docs/models/providers/hyper.md +26 -24
- package/.docs/models/providers/iteracompute.md +11 -10
- package/.docs/models/providers/kenari.md +1 -1
- package/.docs/models/providers/kilo.md +34 -27
- package/.docs/models/providers/llmgateway-providers.md +9 -12
- package/.docs/models/providers/llmgateway.md +3 -4
- package/.docs/models/providers/melious.md +16 -15
- package/.docs/models/providers/minimax-cn-coding-plan.md +2 -1
- package/.docs/models/providers/minimax-cn.md +3 -2
- package/.docs/models/providers/minimax-coding-plan.md +2 -1
- package/.docs/models/providers/minimax.md +3 -2
- package/.docs/models/providers/nano-gpt.md +62 -55
- package/.docs/models/providers/nearai.md +1 -1
- package/.docs/models/providers/nebius.md +4 -1
- package/.docs/models/providers/novita-ai.md +2 -1
- package/.docs/models/providers/nvidia.md +2 -1
- package/.docs/models/providers/ofox.md +26 -25
- package/.docs/models/providers/ollama-cloud.md +31 -28
- package/.docs/models/providers/openai.md +1 -1
- package/.docs/models/providers/opencode-go.md +8 -8
- package/.docs/models/providers/opencode.md +91 -92
- package/.docs/models/providers/pioneer.md +120 -119
- package/.docs/models/providers/prime.md +5 -2
- package/.docs/models/providers/reflection.md +77 -0
- package/.docs/models/providers/requesty.md +7 -2
- package/.docs/models/providers/scaleway.md +2 -1
- package/.docs/models/providers/standardcompute.md +47 -8
- package/.docs/models/providers/togetherai.md +4 -1
- package/.docs/models/providers/upstage.md +8 -7
- package/.docs/models/providers/wandb.md +26 -23
- package/.docs/models/providers/xai.md +0 -1
- package/.docs/models/providers/xiaomi-token-plan-ams.md +0 -2
- package/.docs/models/providers/xiaomi-token-plan-cn.md +0 -2
- package/.docs/models/providers/xiaomi-token-plan-sgp.md +0 -2
- package/.docs/models/providers/xiaomi.md +0 -3
- package/.docs/models/providers/zenmux.md +2 -1
- package/.docs/models/providers.md +2 -0
- package/.docs/reference/agent-controller/session.md +3 -2
- package/.docs/reference/agents/channels.md +5 -1
- package/.docs/reference/agents/durable-agent.md +16 -7
- package/.docs/reference/agents/inngest-agent.md +4 -4
- package/.docs/reference/classifier/classifier.md +31 -7
- package/.docs/reference/cli/mastra.md +44 -7
- package/.docs/reference/client-js/agent-controller.md +2 -0
- package/.docs/reference/client-js/agents.md +20 -0
- package/.docs/reference/client-js/observability.md +165 -6
- package/.docs/reference/configuration.md +30 -0
- package/.docs/reference/connect/channels.md +2 -2
- package/.docs/reference/connect/providers.md +38 -3
- package/.docs/reference/connect/tools.md +21 -2
- package/.docs/reference/core/mastra-class.md +7 -1
- package/.docs/reference/datasets/list.md +9 -1
- package/.docs/reference/evals/create-classifier-scorer.md +1 -0
- package/.docs/reference/index.md +1 -1
- package/.docs/reference/memory/observational-memory.md +2 -2
- package/.docs/reference/memory/settled.md +13 -5
- package/.docs/reference/observability/metrics/automatic-metrics.md +3 -3
- package/.docs/reference/observability/metrics/queries.md +1 -0
- package/.docs/reference/observability/tracing/{trace-query.md → advanced-queries.md} +477 -158
- package/.docs/reference/observability/tracing/interfaces.md +6 -0
- package/.docs/reference/processors/classifier-processor.md +8 -6
- package/.docs/reference/processors/model-selection-processor.md +2 -2
- package/.docs/reference/processors/moderation-processor.md +5 -1
- package/.docs/reference/processors/system-prompt-scrubber.md +4 -0
- package/.docs/reference/rag/embeddings.md +18 -0
- package/.docs/reference/signals/create-notification-inbox-tool.md +11 -9
- package/.docs/reference/streaming/agents/stream.md +19 -1
- package/.docs/reference/tools/create-tool.md +2 -2
- package/.docs/reference/tools/mcp-client.md +2 -2
- package/.docs/reference/workflows/dynamic-workflow-definition.md +1 -1
- package/.docs/reference/workflows/run-methods/resume.md +1 -1
- package/.docs/reference/workflows/run-methods/timeTravel.md +15 -16
- package/.docs/reference/workflows/step.md +1 -0
- package/.docs/reference/workflows/workflow-methods/classifier.md +1 -0
- package/.docs/reference/workspace/factory-sandbox.md +2 -0
- package/.docs/reference/workspace/filesystem.md +4 -0
- package/.docs/reference/workspace/workspace-class.md +10 -10
- package/package.json +8 -9
|
@@ -65,6 +65,165 @@ const selected = await mastraClient.getTrace(list.spans[0].traceId)
|
|
|
65
65
|
|
|
66
66
|
It accepts the same filtering, ordering and delta-polling arguments as `listTraces()`. Use `listTraces()` when you actually need the full span payloads.
|
|
67
67
|
|
|
68
|
+
## Querying spans
|
|
69
|
+
|
|
70
|
+
`querySpans()` returns completed span summaries across traces. It requires a positive ISO timestamp range over span start time and supports cursor pagination:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const result = await mastraClient.querySpans({
|
|
74
|
+
timeRange: {
|
|
75
|
+
from: '2026-10-01T00:00:00.000Z',
|
|
76
|
+
to: '2026-10-02T00:00:00.000Z',
|
|
77
|
+
},
|
|
78
|
+
where: {
|
|
79
|
+
op: 'and',
|
|
80
|
+
args: [
|
|
81
|
+
{ op: 'eq', left: { path: 'threadId' }, right: { literal: 'thread-123' } },
|
|
82
|
+
{ op: 'gte', left: { path: 'durationMs' }, right: { literal: 1000 } },
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
orderBy: [{ field: 'startedAt', direction: 'desc' }],
|
|
86
|
+
page: { limit: 100 },
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
// Pass result.page.next as page.after to continue with the same filters and ordering.
|
|
90
|
+
console.log(result.spans)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Pages default to 100 rows and allow at most 1,000. The response is `{ spans, page: { next } }`, without a total count. Ordering accepts exactly one of `startedAt` or `endedAt`, ascending or descending, and defaults to descending start time.
|
|
94
|
+
|
|
95
|
+
| Fields | Operators |
|
|
96
|
+
| -------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
97
|
+
| `traceId`, `spanId`, `parentSpanId`, `threadId` | `eq`, `ne`, `in`, `notIn`, `exists`, `notExists` |
|
|
98
|
+
| `organizationId`, `resourceId`, `runId`, `sessionId`, `userId`, `requestId`, `serviceName`, `experimentId`, `environment`, `executionSource` | Same string operators |
|
|
99
|
+
| Entity, parent entity and root entity `Type`, `Id`, `Name`, `VersionId` fields, such as `parentEntityId` | Same string operators |
|
|
100
|
+
| `name`, `spanType`, `status` | Same string operators; `name` also accepts `matches` / `notMatches` for normalized whole words and phrases |
|
|
101
|
+
| `startedAt`, `endedAt`, `durationMs` | Comparisons, membership and presence |
|
|
102
|
+
| `error` | `exists`, `notExists` |
|
|
103
|
+
|
|
104
|
+
Combine predicates with `and`, `or` and `not`. Membership uses `{ op: 'in', value: { path: 'spanType' }, set: ['agent_run', 'tool_call'] }`. A span's status is `error` when it has an error and `success` otherwise.
|
|
105
|
+
|
|
106
|
+
Each summary includes identity, context, entity lineage, status, timestamps, `durationMs`, model/provider and input/output/error previews. Model/provider are available in returned rows but aren't filterable.
|
|
107
|
+
|
|
108
|
+
The additional identity, context and parent/root entity filters require an updated storage adapter. With an older adapter, requests using these filters return a structured `422` error.
|
|
109
|
+
|
|
110
|
+
DuckDB returns `null` for parent/root entity type, ID and name, and for `executionSource`. Equality filters on these fields match no spans. Parent/root entity version IDs remain available.
|
|
111
|
+
|
|
112
|
+
## Querying threads
|
|
113
|
+
|
|
114
|
+
`queryTraceThreads()` returns thread summaries from completed traces through `POST /observability/threads/query`. Each row includes activity timestamps, trace counts, context and previews. Traces without a thread ID aren't included.
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
const result = await mastraClient.queryTraceThreads({
|
|
118
|
+
timeRange: {
|
|
119
|
+
traces: {
|
|
120
|
+
from: '2026-10-01T00:00:00.000Z',
|
|
121
|
+
to: '2026-10-02T00:00:00.000Z',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
where: { op: 'eq', left: { path: 'status' }, right: { literal: 'error' } },
|
|
125
|
+
orderBy: [{ field: 'endedAt', direction: 'desc' }],
|
|
126
|
+
page: { limit: 100 },
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
for (const thread of result.threads) {
|
|
130
|
+
console.log(thread.firstTraceId, thread.lastTraceId, thread.traceCount, thread.outputPreview)
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Thread time ranges
|
|
135
|
+
|
|
136
|
+
Choose exactly one time selector. Each range requires ISO timestamps with `from` earlier than `to`. The range includes `from` and excludes `to`.
|
|
137
|
+
|
|
138
|
+
| Selector | Matches threads with |
|
|
139
|
+
| ----------------------------------------------------- | --------------------------------------------- |
|
|
140
|
+
| `timeRange.traces: { from, to }` | At least one trace that started in the window |
|
|
141
|
+
| `timeRange.threads: { field: 'startedAt', from, to }` | Their first activity in the window |
|
|
142
|
+
| `timeRange.threads: { field: 'endedAt', from, to }` | Their last activity in the window |
|
|
143
|
+
|
|
144
|
+
For example, find threads whose most recent activity falls on October 1:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const result = await mastraClient.queryTraceThreads({
|
|
148
|
+
timeRange: {
|
|
149
|
+
threads: {
|
|
150
|
+
field: 'endedAt',
|
|
151
|
+
from: '2026-10-01T00:00:00.000Z',
|
|
152
|
+
to: '2026-10-02T00:00:00.000Z',
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
})
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Rows include the full retained history within the authorized scope, including traces before and after the window. Filters apply to these complete rows. An `environment` filter checks the first trace's environment.
|
|
159
|
+
|
|
160
|
+
### Thread filters
|
|
161
|
+
|
|
162
|
+
Use `where` to filter thread rows. Combine predicates with `and`, `or` and `not`.
|
|
163
|
+
|
|
164
|
+
| Fields | Operators |
|
|
165
|
+
| -------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
|
|
166
|
+
| `threadId`, `organizationId`, `firstTraceId`, `lastTraceId` | `eq`, `ne`, `in`, `notIn`, `exists`, `notExists` |
|
|
167
|
+
| `resourceId`, `userId`, `runId`, `sessionId`, `requestId`, `serviceName`, `experimentId`, `environment`, `executionSource` | Same string operators |
|
|
168
|
+
| `entityType`, `entityId`, `entityName`, `entityVersionId` | Same string operators |
|
|
169
|
+
| `status` | `eq`, `ne`, `in`, `notIn`, with values `success` or `error` |
|
|
170
|
+
| `startedAt`, `endedAt`, `timeToFirstChunkMs` | `eq`, `ne`, `lt`, `lte`, `gt`, `gte`, `in`, `notIn`, `exists`, `notExists` |
|
|
171
|
+
| `traceCount` | `eq`, `ne`, `lt`, `lte`, `gt`, `gte` |
|
|
172
|
+
|
|
173
|
+
For example, filter for threads from selected agents with at least three traces:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
const result = await mastraClient.queryTraceThreads({
|
|
177
|
+
timeRange: {
|
|
178
|
+
traces: {
|
|
179
|
+
from: '2026-10-01T00:00:00.000Z',
|
|
180
|
+
to: '2026-10-02T00:00:00.000Z',
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
where: {
|
|
184
|
+
op: 'and',
|
|
185
|
+
args: [
|
|
186
|
+
{ op: 'in', value: { path: 'entityId' }, set: ['support-agent', 'sales-agent'] },
|
|
187
|
+
{ op: 'gte', left: { path: 'traceCount' }, right: { literal: 3 } },
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
})
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Presence filters use `{ op: 'exists', path: 'userId' }` to check for a non-null value. Model/provider and previews are available in returned rows but aren't filterable.
|
|
194
|
+
|
|
195
|
+
### Thread response
|
|
196
|
+
|
|
197
|
+
The response is `{ threads, page: { next } }`, without a total count. Each entry in `threads` contains these fields:
|
|
198
|
+
|
|
199
|
+
| Returned fields | Meaning |
|
|
200
|
+
| -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
201
|
+
| `threadId`, `organizationId` | Thread identity. Equal thread IDs in different organizations remain separate. |
|
|
202
|
+
| `firstTraceId`, `lastTraceId` | Earliest and latest trace by start time. Equal start times use trace ID as a deterministic tie-breaker. |
|
|
203
|
+
| `resourceId`, `userId`, `runId`, `sessionId`, `requestId`, `serviceName`, `experimentId`, `environment`, `executionSource` | First-trace context, or `null` when missing. |
|
|
204
|
+
| `entityType`, `entityId`, `entityName`, `entityVersionId` | First-trace entity. |
|
|
205
|
+
| `startedAt`, `endedAt` | Earliest start and maximum end time across the thread. |
|
|
206
|
+
| `status` | `error` when the last-started trace's root span has an error, otherwise `success`. |
|
|
207
|
+
| `traceCount` | Number of logical traces in the thread. |
|
|
208
|
+
| `inputPreview` | First trace's input preview. |
|
|
209
|
+
| `outputPreview`, `errorPreview` | Last-started trace's previews. |
|
|
210
|
+
| `timeToFirstChunkMs` | First trace's root agent time to first chunk, in milliseconds. `null` when unavailable or the root isn't an agent. |
|
|
211
|
+
| `model`, `provider` | Model/provider from the first completed model generation directly under the first trace's root agent. `null` when unavailable. |
|
|
212
|
+
|
|
213
|
+
An earlier-started trace can finish last. In that case, it supplies `endedAt`, while the last-started trace still supplies status and output/error previews. Missing first-trace values aren't replaced with values from a later trace.
|
|
214
|
+
|
|
215
|
+
### Thread ordering and pagination
|
|
216
|
+
|
|
217
|
+
Ordering accepts exactly one of `startedAt` or `endedAt`, with direction `asc` or `desc`. The default is `endedAt` descending. Pages default to 100 rows and allow at most 1,000. Pass `result.page.next` as `page.after` with the same time selector, filters, scope and ordering. A `null` cursor means no more pages are available. Pagination reflects live data, so new traces can move a thread between pages.
|
|
218
|
+
|
|
219
|
+
To load the traces within a thread, use [`queryTraces()`](#querying-traces) with a `threadId` filter and a time range covering the thread's activity.
|
|
220
|
+
|
|
221
|
+
### Thread query support
|
|
222
|
+
|
|
223
|
+
Check `capabilities.threadQueryRows` from `getObservabilityCapabilities()` before using this contract. A missing or false value means full thread rows aren't available. Older core or storage packages return a structured `501` for these requests. Legacy identity requests remain supported for mixed package versions.
|
|
224
|
+
|
|
225
|
+
ClickHouse rejects broad thread queries when the authorized history exceeds 250,000 stored trace-root rows, including duplicate copies. A narrower time range can still succeed by selecting fewer candidate threads. Rejected queries return `503 TRACE_QUERY_RESOURCE_LIMIT` without partial results.
|
|
226
|
+
|
|
68
227
|
## Querying traces
|
|
69
228
|
|
|
70
229
|
`queryTraces()` finds completed logical traces using trace fields and conditions over related spans. Every query requires an ISO timestamp range.
|
|
@@ -89,7 +248,7 @@ const result = await mastraClient.queryTraces({
|
|
|
89
248
|
})
|
|
90
249
|
```
|
|
91
250
|
|
|
92
|
-
See [
|
|
251
|
+
See [Query traces](https://mastra.ai/reference/observability/tracing/advanced-queries) for request fields, predicates, limits, response shapes, and errors.
|
|
93
252
|
|
|
94
253
|
### Load a page and poll for traces
|
|
95
254
|
|
|
@@ -116,7 +275,7 @@ const changes = await mastraClient.queryTraces({
|
|
|
116
275
|
|
|
117
276
|
Merge `changes.traces` by `traceId`, retain `changes.deltaCursor`, and continue while `changes.delta.hasMore` is `true`. Keep the same time range and predicate across polls. Only completed traces are returned; polling doesn't guarantee notifications for related-record updates, deletions, or traces that stop matching.
|
|
118
277
|
|
|
119
|
-
See [Delta polling](https://mastra.ai/reference/observability/tracing/
|
|
278
|
+
See [Delta polling](https://mastra.ai/reference/observability/tracing/advanced-queries) for bootstrap behavior, cursor lifetime, retention, and a complete polling loop.
|
|
120
279
|
|
|
121
280
|
### Aggregate traces
|
|
122
281
|
|
|
@@ -141,9 +300,9 @@ if (capabilities.traceAggregate) {
|
|
|
141
300
|
}
|
|
142
301
|
```
|
|
143
302
|
|
|
144
|
-
Each row has `dimensions` keyed by `groupBy` field, `measures` keyed by measure name, a `bucket` timestamp when `interval` is set, and `cost` coverage when a cost measure is requested. `truncated` is `true` when more groups matched than `limit`.
|
|
303
|
+
Each row has `dimensions` keyed by `groupBy` field, `measures` keyed by measure name, a `bucket` timestamp when `interval` is set, and `cost` coverage when a cost measure is requested. `truncated` is `true` when more groups matched than `limit`. Check `capabilities.traceAggregate` before calling. The client retries server errors like `queryTraces()` but doesn't retry `422` validation errors.
|
|
145
304
|
|
|
146
|
-
|
|
305
|
+
See [Aggregate traces](https://mastra.ai/reference/observability/tracing/advanced-queries) for dimensions, measures, token and cost semantics, time buckets, limits, and errors.
|
|
147
306
|
|
|
148
307
|
### Discover trace-query fields and values
|
|
149
308
|
|
|
@@ -163,7 +322,7 @@ const fields = await mastraClient.getTraceQueryFields({
|
|
|
163
322
|
})
|
|
164
323
|
```
|
|
165
324
|
|
|
166
|
-
For the `trace` scope on a server that supports aggregation, the response also includes `aggregate`: the `dimensions` you can pass to `groupBy` and the `measures` you can request.
|
|
325
|
+
For the `trace` scope on a server that supports aggregation, the response also includes `aggregate`: the `dimensions` you can pass to `groupBy` and the `measures` you can request. See [Discover fields and values](https://mastra.ai/reference/observability/tracing/advanced-queries).
|
|
167
326
|
|
|
168
327
|
Use the exact local path from the response with the same scope. For example, `model` belongs inside a `spans.some` or `spans.none` predicate. A field picker can fetch the `trace` and `spans` scopes in parallel.
|
|
169
328
|
|
|
@@ -341,7 +500,7 @@ const ratingPercentiles = await mastraClient.getFeedbackPercentiles({
|
|
|
341
500
|
|
|
342
501
|
## Related
|
|
343
502
|
|
|
344
|
-
- [
|
|
503
|
+
- [Advanced trace queries](https://mastra.ai/reference/observability/tracing/advanced-queries): Query and aggregate completed traces with recursive predicates
|
|
345
504
|
- [Feedback guide](https://mastra.ai/docs/observability/feedback): Learn how to create, list, and query feedback
|
|
346
505
|
- [Feedback reference](https://mastra.ai/reference/observability/feedback): Review feedback schemas and HTTP routes
|
|
347
506
|
- [Agents API](https://mastra.ai/reference/client-js/agents): Learn about agent interactions that generate traces
|
|
@@ -99,6 +99,8 @@ export const mastra = new Mastra({
|
|
|
99
99
|
|
|
100
100
|
**waitTimeoutMs** (`number`): How long the agentic loop waits for a background task to complete before moving on. If a task has not finished within this time, the loop proceeds without setting isContinued. Default: undefined (do not wait). Can be overridden per-agent or per-tool.
|
|
101
101
|
|
|
102
|
+
**untilIdleMaxIdleMs** (`number`): Default idle timeout, in milliseconds, for agent.stream(..., { untilIdle: true }) calls that do not set maxIdleMs. The stream closes when background tasks are still running but no event has arrived for this long. Set it above your longest expected background task so its completion still triggers a continuation turn. A per-call untilIdle: { maxIdleMs } takes precedence. Default: 5 minutes. (Default: `300000`)
|
|
103
|
+
|
|
102
104
|
**onTaskComplete** (`(task: BackgroundTask) => void | Promise<void>`): Global callback invoked when any background task completes successfully. Fires in addition to per-tool and per-agent callbacks.
|
|
103
105
|
|
|
104
106
|
**onTaskFailed** (`(task: BackgroundTask) => void | Promise<void>`): Global callback invoked when any background task fails. Fires in addition to per-tool and per-agent callbacks.
|
|
@@ -615,6 +617,34 @@ export const mastra = new Mastra({
|
|
|
615
617
|
})
|
|
616
618
|
```
|
|
617
619
|
|
|
620
|
+
### bundler.pnpmWorkspaceSettings
|
|
621
|
+
|
|
622
|
+
**Type:** `Record<string, JSONValue>`\
|
|
623
|
+
**Default:** `{}`
|
|
624
|
+
|
|
625
|
+
Explicit settings to write to the generated `pnpm-workspace.yaml` when installing deployment dependencies with pnpm. Values can be strings, numbers, booleans, null, arrays, or nested objects. Other package managers ignore this option.
|
|
626
|
+
|
|
627
|
+
Use this option for pnpm install-policy settings that your deployment install should follow:
|
|
628
|
+
|
|
629
|
+
```typescript
|
|
630
|
+
import { Mastra } from '@mastra/core'
|
|
631
|
+
|
|
632
|
+
export const mastra = new Mastra({
|
|
633
|
+
bundler: {
|
|
634
|
+
pnpmWorkspaceSettings: {
|
|
635
|
+
blockExoticSubdeps: false,
|
|
636
|
+
minimumReleaseAge: 0,
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
})
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
Explicit values override copied source settings. Omitting this option preserves the existing workspace-copy behavior; it doesn't copy all settings from the source workspace.
|
|
643
|
+
|
|
644
|
+
Only these keys are supported: `allowBuilds`, `onlyBuiltDependencies`, `ignoredBuiltDependencies`, `minimumReleaseAge`, `minimumReleaseAgeExclude`, `trustPolicy`, `trustPolicyExclude`, `trustPolicyIgnoreAfter`, and `blockExoticSubdeps`. Any other key throws an error before pnpm runs, including keys Mastra generates for deployment output (`packages`, `overrides`, `patchedDependencies`, `allowUnusedPatches`, `supportedArchitectures`, `nodeLinker`) and settings that change TLS verification, registries, network access, store integrity, dependency extensions, catalogs, or build-script permissions. `neverBuiltDependencies` is rejected because pnpm 10 runs every build script it doesn't list. This option doesn't accept command-line flags and isn't a place for secrets.
|
|
645
|
+
|
|
646
|
+
Explicit `allowBuilds` and `onlyBuiltDependencies` values use the same validation as copied source build approvals.
|
|
647
|
+
|
|
618
648
|
## Server options
|
|
619
649
|
|
|
620
650
|
### server.apiRoutes
|
|
@@ -18,9 +18,9 @@ export const mastra = new Mastra({
|
|
|
18
18
|
|
|
19
19
|
Returns: `Promise<ChannelsResolver>`. See [The resolver](#the-resolver).
|
|
20
20
|
|
|
21
|
-
The [documented channel setup](https://mastra.ai/docs/mastra-platform/connect/channels) covers Slack, Telegram, and
|
|
21
|
+
The [documented channel setup](https://mastra.ai/docs/mastra-platform/connect/channels) covers Slack, Telegram, Discord, and Microsoft Teams. Their implementations come from `@mastra/slack`, `@mastra/telegram`, `@mastra/discord`, and `@mastra/teams`, loaded on demand. Use those packages directly to configure a channel outside the platform connection flow.
|
|
22
22
|
|
|
23
|
-
The
|
|
23
|
+
The Teams provider encrypts stored bot secrets with `MASTRA_ENCRYPTION_KEY` when set. When it isn't, the key is derived from the platform access token and a warning is logged while a Teams connection is active. Rotating the platform access token makes stored bot credentials unreadable (disconnect and reconnect to re-provision). Projects without a Teams connection are unaffected.
|
|
24
24
|
|
|
25
25
|
## Parameters
|
|
26
26
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
# Provider toolsets
|
|
6
6
|
|
|
7
|
-
This page documents generated toolsets for
|
|
7
|
+
This page documents generated toolsets for 22 providers (910 tools in this version of `@mastra/connect`). It isn't an exhaustive list of providers registered in the SDK or available in the platform catalog. [`tools()`](https://mastra.ai/reference/connect/tools) exposes a provider's toolset when the project has an active connection for its provider ID.
|
|
8
8
|
|
|
9
9
|
Tool keys are stable identifiers of the form `<provider>_<action>` and are the values accepted by `allowTools` and `disallowTools`. Toolsets are versioned with the package: the exact list depends on the installed `@mastra/connect` version, and this page reflects the version it was generated from.
|
|
10
10
|
|
|
@@ -18,13 +18,14 @@ MCP providers (Attio, Canva, Clay, Neon, Render, Robinhood, and Sanity) serve th
|
|
|
18
18
|
|  [GitHub](#github) | `github` | 49 |
|
|
19
19
|
|  [Google Calendar](#google-calendar) | `google-calendar` | 43 |
|
|
20
20
|
|  [Google Docs](#google-docs) | `google-docs` | 37 |
|
|
21
|
-
|  [Google Drive](#google-drive) | `google-drive` |
|
|
21
|
+
|  [Google Drive](#google-drive) | `google-drive` | 32 |
|
|
22
22
|
|  [Gmail](#gmail) | `google-mail` | 52 |
|
|
23
23
|
|  [Google Sheets](#google-sheets) | `google-sheet` | 18 |
|
|
24
24
|
|  [HubSpot](#hubspot) | `hubspot` | 50 |
|
|
25
25
|
|  [incident.io](#incidentio) | `incident-io` | 66 |
|
|
26
26
|
|  [Jira](#jira) | `jira` | 38 |
|
|
27
27
|
|  [Linear](#linear) | `linear` | 46 |
|
|
28
|
+
|  [Microsoft Teams](#microsoft-teams) | `microsoft-teams` | 25 |
|
|
28
29
|
|  [Notion](#notion) | `notion` | 44 |
|
|
29
30
|
|  [OpenAI](#openai) | `openai` | 26 |
|
|
30
31
|
|  [PostHog](#posthog) | `posthog` | 67 |
|
|
@@ -310,7 +311,7 @@ Provider ID: `google-docs` · 37 tools
|
|
|
310
311
|
|
|
311
312
|
## Google Drive
|
|
312
313
|
|
|
313
|
-
Provider ID: `google-drive` ·
|
|
314
|
+
Provider ID: `google-drive` · 32 tools
|
|
314
315
|
|
|
315
316
|
| Tool | Description |
|
|
316
317
|
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
@@ -323,6 +324,7 @@ Provider ID: `google-drive` · 30 tools
|
|
|
323
324
|
| `google_drive_delete_permission` | Remove a permission from a file |
|
|
324
325
|
| `google_drive_delete_shared_drive` | Delete a shared drive |
|
|
325
326
|
| `google_drive_empty_trash` | Permanently delete all trashed files |
|
|
327
|
+
| `google_drive_export_file` | Export a Google Workspace file (Doc, Sheet, Slide, etc.) to the specified MIME type. |
|
|
326
328
|
| `google_drive_find_file` | Search for files by name or query in Google Drive |
|
|
327
329
|
| `google_drive_find_folder` | Search for a folder by name or query |
|
|
328
330
|
| `google_drive_get_about` | Get the user's drive info and storage quota |
|
|
@@ -337,6 +339,7 @@ Provider ID: `google-drive` · 30 tools
|
|
|
337
339
|
| `google_drive_list_drives` | List shared drives the user can access, with cursor pagination and drive metadata like hidden, capabilities, and restrictions. |
|
|
338
340
|
| `google_drive_list_files_non_unified` | List immediate files and folders for a folder ID, or root when omitted, with cursor pagination and shared-drive support. |
|
|
339
341
|
| `google_drive_list_permissions` | List permissions on a file |
|
|
342
|
+
| `google_drive_list_revisions` | List the revision history for a Drive file. |
|
|
340
343
|
| `google_drive_move_file` | Move a file to a different folder |
|
|
341
344
|
| `google_drive_unhide_shared_drive` | Restore a hidden shared drive to default view |
|
|
342
345
|
| `google_drive_update_comment` | Update a comment on a file |
|
|
@@ -657,6 +660,38 @@ Provider ID: `linear` · 46 tools
|
|
|
657
660
|
| `linear_update_issue_relation` | Update fields on an existing Linear issue relation. |
|
|
658
661
|
| `linear_update_project` | Update an existing Linear project. |
|
|
659
662
|
|
|
663
|
+
## Microsoft Teams
|
|
664
|
+
|
|
665
|
+
Provider ID: `microsoft-teams` · 25 tools
|
|
666
|
+
|
|
667
|
+
| Tool | Description |
|
|
668
|
+
| ------------------------------------------ | ------------------------------------------------ |
|
|
669
|
+
| `microsoft_teams_add_team_member` | Add a member to a team |
|
|
670
|
+
| `microsoft_teams_create_channel` | Create a channel in a team. |
|
|
671
|
+
| `microsoft_teams_create_channel_message` | Post a root message in a channel |
|
|
672
|
+
| `microsoft_teams_create_channel_tab` | Add a tab to a channel. |
|
|
673
|
+
| `microsoft_teams_create_chat` | Create a one-on-one or group chat. |
|
|
674
|
+
| `microsoft_teams_create_chat_message` | Send a message in a chat |
|
|
675
|
+
| `microsoft_teams_create_team` | Create a team from a template or existing group. |
|
|
676
|
+
| `microsoft_teams_delete_channel` | Delete a channel from a team |
|
|
677
|
+
| `microsoft_teams_get_channel` | Retrieve a channel by ID. |
|
|
678
|
+
| `microsoft_teams_get_channel_message` | Retrieve a channel message by ID. |
|
|
679
|
+
| `microsoft_teams_get_chat` | Retrieve a chat by ID. |
|
|
680
|
+
| `microsoft_teams_get_chat_message` | Retrieve a chat message by ID. |
|
|
681
|
+
| `microsoft_teams_get_team` | Retrieve a team by ID. |
|
|
682
|
+
| `microsoft_teams_list_channel_messages` | List root messages in a channel. |
|
|
683
|
+
| `microsoft_teams_list_channel_replies` | List replies under a channel message thread |
|
|
684
|
+
| `microsoft_teams_list_channel_tabs` | List tabs configured on a channel. |
|
|
685
|
+
| `microsoft_teams_list_channels` | List channels in a team. |
|
|
686
|
+
| `microsoft_teams_list_chat_members` | List members in a chat |
|
|
687
|
+
| `microsoft_teams_list_chat_messages` | List messages in a chat. |
|
|
688
|
+
| `microsoft_teams_list_chats` | List chats for a user. |
|
|
689
|
+
| `microsoft_teams_list_joined_teams` | List teams the user has joined |
|
|
690
|
+
| `microsoft_teams_list_team_members` | List members in a team. |
|
|
691
|
+
| `microsoft_teams_remove_team_member` | Remove a member from a team. |
|
|
692
|
+
| `microsoft_teams_reply_to_channel_message` | Reply to a channel message thread. |
|
|
693
|
+
| `microsoft_teams_update_channel` | Update mutable channel properties. |
|
|
694
|
+
|
|
660
695
|
## Notion
|
|
661
696
|
|
|
662
697
|
Provider ID: `notion` · 44 tools
|
|
@@ -25,7 +25,7 @@ See [Connect](https://mastra.ai/docs/mastra-platform/connect/overview) to get st
|
|
|
25
25
|
|
|
26
26
|
## Parameters
|
|
27
27
|
|
|
28
|
-
**options** (`ToolsOptions`): Optional discovery and client configuration.
|
|
28
|
+
**options** (`ToolsOptions | ((ctx?: ToolsResolverContext) => ToolsOptions | Promise<ToolsOptions>)`): Optional discovery and client configuration, or a callback returning it per request. See Per-request options below.
|
|
29
29
|
|
|
30
30
|
**options.projectId** (`string`): Platform project whose connections to discover. Falls back to MASTRA\_PROJECT\_ID.
|
|
31
31
|
|
|
@@ -41,6 +41,25 @@ See [Connect](https://mastra.ai/docs/mastra-platform/connect/overview) to get st
|
|
|
41
41
|
|
|
42
42
|
**options.ttlMs** (`number`): How long a resolved snapshot stays fresh, in milliseconds. Default 30000. 0 revalidates on every resolution.
|
|
43
43
|
|
|
44
|
+
### Per-request options
|
|
45
|
+
|
|
46
|
+
Pass a callback instead of an options object to vary options per request, for example role-based filters or approval policies. The callback runs on every resolution (sync or async) and receives the same context Mastra passes the resolver (`requestContext` is populated when the resolver is an agent's `tools` option):
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
const connected = tools(ctx => ({
|
|
50
|
+
providers: {
|
|
51
|
+
linear:
|
|
52
|
+
ctx?.requestContext?.get('role') === 'viewer'
|
|
53
|
+
? { allowTools: ['linear_list_*'] }
|
|
54
|
+
: { requireApproval: ['linear_delete_*'] },
|
|
55
|
+
},
|
|
56
|
+
}))
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The resolver memoizes snapshots per distinct options value, so requests producing the same options share one cached snapshot with the usual `ttlMs` and stale-while-revalidate semantics. Structurally equal options returned from different calls count as the same value; non-serializable values such as a custom `client.fetch` compare by identity. The resolver keeps caches for at most 32 distinct options values and evicts the least recently used one (closing its MCP transports) past that, so derive options from a small, closed set of inputs such as roles, not from unbounded per-request data.
|
|
60
|
+
|
|
61
|
+
With the callback form, option validation runs at the first resolution that produces a given options value rather than at `tools()` time, and a validation error fails that resolution. `refresh()` fetches for the options the callback returns without a context (the same variant a direct `await connected()` call uses), and `disconnect()` closes every memoized variant.
|
|
62
|
+
|
|
44
63
|
### Per-provider options
|
|
45
64
|
|
|
46
65
|
Each value in the `providers` record form is `true`, `false`, or a `ToolsProviderOptions`:
|
|
@@ -89,7 +108,7 @@ The resolver also exposes methods for manual control:
|
|
|
89
108
|
|
|
90
109
|
Errors fall into four groups:
|
|
91
110
|
|
|
92
|
-
- Configuration errors (missing project ID or token, a malformed provider ID, both `allowTools` and `disallowTools` at one level, invalid `ttlMs`) throw when you call `tools()`.
|
|
111
|
+
- Configuration errors (missing project ID or token, a malformed provider ID, both `allowTools` and `disallowTools` at one level, invalid `ttlMs`) throw when you call `tools()`. With [the callback form](#per-request-options), they fail the first resolution that produces the invalid options instead.
|
|
93
112
|
- An enabled provider ID that the platform catalog confirms is unknown fails the resolution with `invalid_options`. An unknown tool key or zero-match glob in a per-provider filter does the same. If the catalog can't be reached, an unknown ID downgrades to a warning and is skipped.
|
|
94
113
|
- If a background refresh fails while a snapshot is cached, the resolver keeps serving the cached toolsets and warns. It rejects only when nothing was ever cached.
|
|
95
114
|
- A problem with one provider, such as a connection that needs reauthorization, logs a warning and skips that provider. The other providers' tools still load.
|
|
@@ -147,6 +147,12 @@ Re-drives every orphaned `running` durable-agent run across all registered durab
|
|
|
147
147
|
|
|
148
148
|
Requires persistent storage. With an in-memory store, there's nothing to recover after a process restart.
|
|
149
149
|
|
|
150
|
+
Agents and their runs are attempted serially. Each built-in `recoverActiveRuns()` attempt waits up to 30 seconds in total for `recover()` setup and settlement of the whole recovered workflow, then traversal can continue to later runs and agents. This isn't an overall recovery deadline: discovery and overridden custom recovery methods aren't bounded by this budget.
|
|
151
|
+
|
|
152
|
+
A timed-out attempt continues in the background. Its outcome is `status: 'skipped'` with `reason: 'recovery-timeout'` and no `retryAt`. It contributes only to `skipped`, not `recovered`, `succeeded`, or `failed`, and Mastra doesn't automatically retry it. Late settlement doesn't change the returned counts.
|
|
153
|
+
|
|
154
|
+
When shutdown begins, recovery stops dispatching new agents and runs. The recovery traversal and original attempts, including timed-out setup or execution, participate in the same shared shutdown drain as active executions. A recovery wait timeout doesn't cancel the attempt or give it a separate shutdown drain window.
|
|
155
|
+
|
|
150
156
|
A run that another execution still drives isn't taken over. It's counted in `skipped` and checked again once that execution's claim could have lapsed, so a run whose process crashed is recovered without another call. `shutdown()` cancels pending re-checks. See [run ownership](https://mastra.ai/docs/harness/durable-agents).
|
|
151
157
|
|
|
152
158
|
```typescript
|
|
@@ -164,4 +170,4 @@ Returns:
|
|
|
164
170
|
|
|
165
171
|
**failed** (`number`): Runs whose restart threw an error.
|
|
166
172
|
|
|
167
|
-
**skipped** (`number`): Runs
|
|
173
|
+
**skipped** (`number`): Runs skipped because they are already active, recovery is already in progress, or the recovery wait timed out. Only ownership skips eligible for re-checks are checked again; recovery timeouts are not automatically retried.
|
|
@@ -32,13 +32,19 @@ const filtered = await mastra.datasets.list({
|
|
|
32
32
|
const forAgents = await mastra.datasets.list({
|
|
33
33
|
filters: { targetIds: ['agent-a', 'agent-b'] },
|
|
34
34
|
})
|
|
35
|
+
|
|
36
|
+
// Fetch specific datasets by ID, all on one page
|
|
37
|
+
const byId = await mastra.datasets.list({
|
|
38
|
+
perPage: false,
|
|
39
|
+
filters: { datasetIds: ['dataset-1', 'dataset-2'] },
|
|
40
|
+
})
|
|
35
41
|
```
|
|
36
42
|
|
|
37
43
|
## Parameters
|
|
38
44
|
|
|
39
45
|
**page** (`number`): Page number. Defaults to 0.
|
|
40
46
|
|
|
41
|
-
**perPage** (`number`): Number of datasets per page. Defaults to 20.
|
|
47
|
+
**perPage** (`number | false`): Number of datasets per page, or false to return every match on one page. Defaults to 20.
|
|
42
48
|
|
|
43
49
|
**filters** (`object`): Optional filters applied at the storage layer.
|
|
44
50
|
|
|
@@ -54,6 +60,8 @@ const forAgents = await mastra.datasets.list({
|
|
|
54
60
|
|
|
55
61
|
**filters.targetIds** (`string[]`): Restrict to datasets whose targetIds intersect this list (any-overlap match). Empty array is treated as no filter.
|
|
56
62
|
|
|
63
|
+
**filters.datasetIds** (`string[]`): Restrict to datasets with these IDs. Empty array matches no datasets. Pass perPage: false to get every match on one page.
|
|
64
|
+
|
|
57
65
|
**filters.name** (`string`): Case-insensitive substring match on dataset name. Empty string is treated as no filter.
|
|
58
66
|
|
|
59
67
|
## Returns
|
|
@@ -183,6 +183,7 @@ The factory also accepts `name` and `description` from `createScorer()`.
|
|
|
183
183
|
Failures while the scorer runs reject `scorer.run()` with a `ScorerRunError` whose `failedStep` is `analyze`, and the original error is available as its `cause`. This covers:
|
|
184
184
|
|
|
185
185
|
- Classifier evaluation fails or doesn't return an answer for the selected question.
|
|
186
|
+
- The decision model refuses the selected question. The error names the classifier, the question, and the scorer.
|
|
186
187
|
- A classifier ID is used before the scorer is registered with Mastra, or the ID isn't present in `classifiers`.
|
|
187
188
|
- A registered classifier has an invalid configuration for this scorer.
|
|
188
189
|
|
package/.docs/reference/index.md
CHANGED
|
@@ -266,11 +266,11 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
266
266
|
- [Automatic Metrics](https://mastra.ai/reference/observability/metrics/automatic-metrics)
|
|
267
267
|
- [Metric queries](https://mastra.ai/reference/observability/metrics/queries)
|
|
268
268
|
- [Configuration](https://mastra.ai/reference/observability/tracing/configuration)
|
|
269
|
+
- [Advanced trace queries](https://mastra.ai/reference/observability/tracing/advanced-queries)
|
|
269
270
|
- [Instances](https://mastra.ai/reference/observability/tracing/instances)
|
|
270
271
|
- [Interfaces](https://mastra.ai/reference/observability/tracing/interfaces)
|
|
271
272
|
- [Span filtering](https://mastra.ai/reference/observability/tracing/span-filtering)
|
|
272
273
|
- [Spans](https://mastra.ai/reference/observability/tracing/spans)
|
|
273
|
-
- [Trace queries](https://mastra.ai/reference/observability/tracing/trace-query)
|
|
274
274
|
- [AgentsMDInjector](https://mastra.ai/reference/processors/agents-md-injector)
|
|
275
275
|
- [BatchPartsProcessor](https://mastra.ai/reference/processors/batch-parts-processor)
|
|
276
276
|
- [ClassifierProcessor](https://mastra.ai/reference/processors/classifier-processor)
|
|
@@ -75,7 +75,7 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
|
|
|
75
75
|
|
|
76
76
|
**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.
|
|
77
77
|
|
|
78
|
-
**observation.failurePolicy** (`'abort' | 'continue'`): Terminal policy once Observer retries are exhausted. 'abort' aborts the agent turn. 'continue' emits the existing failure diagnostic, keeps the failed input pending for a later cycle, and allows the main agent turn to continue. Persistence, indexing, transform, locking, invariant, and explicit abort failures remain fatal. This setting doesn't prevent the underlying provider error or change blockAfter or attachment handling, and it has no backstop for a sustained outage: pending messages keep accruing in the main agent's context until they reach the model's context limit.
|
|
78
|
+
**observation.failurePolicy** (`'abort' | 'continue'`): Terminal policy once Observer retries are exhausted in a synchronous observation. Background buffered observation failures are reported as om\_buffering\_failed and never stop the turn. 'abort' aborts the agent turn. 'continue' emits the existing failure diagnostic, keeps the failed input pending for a later cycle, and allows the main agent turn to continue. Persistence, indexing, transform, locking, invariant, and explicit abort failures remain fatal. This setting doesn't prevent the underlying provider error or change blockAfter or attachment handling, and it has no backstop for a sustained outage: pending messages keep accruing in the main agent's context until they reach the model's context limit.
|
|
79
79
|
|
|
80
80
|
**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.
|
|
81
81
|
|
|
@@ -111,7 +111,7 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
|
|
|
111
111
|
|
|
112
112
|
**reflection.maxRetries** (`number`): Retries after the initial Reflector model call on transient provider errors. Governs OM's own retry ladder; the Reflector model call itself is configured with no provider-level retries.
|
|
113
113
|
|
|
114
|
-
**reflection.failurePolicy** (`'abort' | 'continue'`): Terminal policy once Reflector retries are exhausted. 'abort' aborts the agent turn. 'continue' emits the failure diagnostic and allows the turn to continue, leaving already-persisted observations committed and deferring reflection to the next threshold crossing. A provider outage usually takes out both stages, so set the policy on observation too if the turn should survive one.
|
|
114
|
+
**reflection.failurePolicy** (`'abort' | 'continue'`): Terminal policy once Reflector retries are exhausted in a synchronous reflection. Background buffered reflection failures are reported as om\_buffering\_failed and never stop the turn. 'abort' aborts the agent turn. 'continue' emits the failure diagnostic and allows the turn to continue, leaving already-persisted observations committed and deferring reflection to the next threshold crossing. A provider outage usually takes out both stages, so set the policy on observation too if the turn should survive one.
|
|
115
115
|
|
|
116
116
|
**reflection.instruction** (`string`): Custom instruction appended to the Reflector's system prompt. Use this to customize how the Reflector consolidates observations, such as prioritizing certain types of information.
|
|
117
117
|
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
# Memory.settled()
|
|
6
6
|
|
|
7
|
-
The `.settled()` method resolves once
|
|
7
|
+
The `.settled()` method resolves once background work the `Memory` instance started has finished. Some memory work continues after an agent run returns:
|
|
8
8
|
|
|
9
9
|
- Observational memory cycles (buffered observation and reflection, including the nested agent runs they spawn)
|
|
10
10
|
- Vector cleanup started by `deleteThread()` and `deleteMessages()`
|
|
11
11
|
|
|
12
|
-
Await this method before closing a storage connection you own. Without it, background statements can run against a closed connection.
|
|
12
|
+
Await this method before closing a storage connection you own. Without it, background statements can run against a closed connection. A scoped call can return while other threads still use the store, so call `settled()` without a scope before closing shared storage.
|
|
13
13
|
|
|
14
|
-
The method is declared on the base memory class, so it's also available on the `MastraMemory` instance returned by `agent.getMemory()`.
|
|
14
|
+
The method is declared on the base memory class, so it's also available on the `MastraMemory` instance returned by `agent.getMemory()`. The `scope` parameter is only on `Memory` from `@mastra/memory`.
|
|
15
15
|
|
|
16
16
|
## Usage example
|
|
17
17
|
|
|
@@ -26,11 +26,19 @@ await store.close()
|
|
|
26
26
|
|
|
27
27
|
## Parameters
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
**scope** (`{ threadId?: string | null; resourceId?: string | null }`): Waits only for observational memory work on this thread (or resource, when observational memory uses resource scope). If the scope omits the id observational memory is keyed on (threadId for thread scope, resourceId for resource scope), it waits for all work. Vector cleanup is always included.
|
|
30
30
|
|
|
31
31
|
## Returns
|
|
32
32
|
|
|
33
|
-
**void** (`Promise<void>`): A promise that resolves when
|
|
33
|
+
**void** (`Promise<void>`): A promise that resolves when the requested background memory work has finished (all work, if unscoped). Background work that fails does not reject this promise.
|
|
34
|
+
|
|
35
|
+
## Wait for one conversation
|
|
36
|
+
|
|
37
|
+
On a busy server, waiting for all work can take a long time because other threads keep starting new work. Pass a scope to wait for less. When observational memory uses thread scope, the call below waits for `thread-123` only. When it uses resource scope, it waits for every thread under `user-456`:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
await memory.settled({ threadId: 'thread-123', resourceId: 'user-456' })
|
|
41
|
+
```
|
|
34
42
|
|
|
35
43
|
## Extended usage example
|
|
36
44
|
|
|
@@ -10,7 +10,7 @@ For setup instructions, see the [Metrics overview](https://mastra.ai/docs/observ
|
|
|
10
10
|
|
|
11
11
|
## When Mastra emits automatic metrics
|
|
12
12
|
|
|
13
|
-
Metrics are extracted from spans when they end. The observability layer inspects each completed span, calculates duration, and
|
|
13
|
+
Metrics are extracted from spans when they end. The observability layer inspects each completed span, calculates duration, and reads token usage data from model generation and classifier evaluation spans. No manual instrumentation is needed.
|
|
14
14
|
|
|
15
15
|
### What affects whether a metric is available
|
|
16
16
|
|
|
@@ -35,7 +35,7 @@ Duration metrics record execution time in milliseconds, calculated from the span
|
|
|
35
35
|
|
|
36
36
|
## Token usage metrics
|
|
37
37
|
|
|
38
|
-
Token metrics are emitted
|
|
38
|
+
Token metrics are emitted from `MODEL_GENERATION` and `CLASSIFIER_EVALUATION` spans that include `usage` data. Token metrics require usage data from the provider.
|
|
39
39
|
|
|
40
40
|
### Input token metrics
|
|
41
41
|
|
|
@@ -142,7 +142,7 @@ When you spot a spike in latency or token usage on the Metrics dashboard, correl
|
|
|
142
142
|
|
|
143
143
|
### Token metrics are missing
|
|
144
144
|
|
|
145
|
-
- **Span is a model generation**: Token metrics are only emitted from `MODEL_GENERATION` spans.
|
|
145
|
+
- **Span is a model generation or classifier evaluation**: Token metrics are only emitted from `MODEL_GENERATION` and `CLASSIFIER_EVALUATION` spans.
|
|
146
146
|
- **Provider reports usage**: The model provider must include `usage` data in its response. Usage data is required to emit token metrics.
|
|
147
147
|
|
|
148
148
|
## Related
|
|
@@ -110,6 +110,7 @@ All metric operations accept the same optional `filters` object. Raw list reques
|
|
|
110
110
|
| `userId` | `string` | User ID |
|
|
111
111
|
| `organizationId` | `string` | Organization ID |
|
|
112
112
|
| `experimentId` | `string` | Experiment or evaluation run ID |
|
|
113
|
+
| `experimentIds` | `string[]` | One to 1,000 experiment IDs |
|
|
113
114
|
| `serviceName` | `string` | Service name |
|
|
114
115
|
| `environment` | `string` | Environment name |
|
|
115
116
|
| `resourceId` | `string` | Resource ID |
|