@mastra/mcp-docs-server 1.1.29-alpha.9 → 1.1.30-alpha.2
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/background-tasks.md +242 -0
- package/.docs/docs/agents/supervisor-agents.md +35 -4
- package/.docs/docs/agents/using-tools.md +1 -0
- package/.docs/docs/observability/metrics/overview.md +2 -2
- package/.docs/docs/observability/tracing/exporters/default.md +3 -3
- package/.docs/docs/observability/tracing/exporters/laminar.md +22 -14
- package/.docs/docs/streaming/background-task-streaming.md +80 -0
- package/.docs/docs/streaming/overview.md +3 -0
- package/.docs/docs/workspace/filesystem.md +1 -1
- package/.docs/guides/build-your-ui/assistant-ui.md +1 -1
- package/.docs/models/gateways/openrouter.md +3 -1
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/anthropic.md +4 -2
- package/.docs/models/providers/baseten.md +2 -1
- package/.docs/models/providers/deepinfra.md +2 -1
- package/.docs/models/providers/fireworks-ai.md +2 -1
- package/.docs/models/providers/kilo.md +3 -1
- package/.docs/models/providers/nvidia.md +2 -1
- package/.docs/models/providers/openai.md +2 -1
- package/.docs/models/providers/wandb.md +3 -2
- package/.docs/models/providers/zai-coding-plan.md +9 -8
- package/.docs/models/providers/zenmux.md +8 -1
- package/.docs/reference/client-js/agents.md +24 -0
- package/.docs/reference/configuration.md +63 -0
- package/.docs/reference/harness/harness-class.md +53 -10
- package/.docs/reference/index.md +3 -0
- package/.docs/reference/observability/metrics/automatic-metrics.md +2 -2
- package/.docs/reference/observability/tracing/interfaces.md +17 -0
- package/.docs/reference/processors/stream-error-retry-processor.md +54 -0
- package/.docs/reference/storage/clickhouse.md +274 -0
- package/.docs/reference/storage/composite.md +5 -3
- package/.docs/reference/streaming/ChunkType.md +140 -0
- package/.docs/reference/streaming/agents/streamUntilIdle.md +94 -0
- package/.docs/reference/workspace/s3-filesystem.md +79 -5
- package/CHANGELOG.md +37 -0
- package/package.json +6 -6
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# Background tasks
|
|
2
|
+
|
|
3
|
+
**Added in:** `@mastra/core@1.29.0`
|
|
4
|
+
|
|
5
|
+
Background tasks let an agent dispatch a long-running tool call without blocking the agentic loop. The tool returns an immediate acknowledgement, the LLM continues responding, and the task runs to completion in the background. When it finishes, its result is written to memory and if you use [`streamUntilIdle()`](https://mastra.ai/reference/streaming/agents/streamUntilIdle) the agent is re-invoked automatically so the result is processed in the same call.
|
|
6
|
+
|
|
7
|
+
## When to use background tasks
|
|
8
|
+
|
|
9
|
+
Use background tasks when a tool call may take long enough that the user shouldn't wait for it before seeing a response. Common cases:
|
|
10
|
+
|
|
11
|
+
- Subagent delegations that themselves run multi-step research or writing.
|
|
12
|
+
- Tool calls that hit slow external services, queues, or large data jobs.
|
|
13
|
+
- Workflows triggered from a tool call that may take minutes to complete.
|
|
14
|
+
|
|
15
|
+
For tool calls that return quickly, foreground execution using `agent.stream()` and `agent.generate()` is simpler.
|
|
16
|
+
|
|
17
|
+
> **Note:** Background tasks require a configured [storage](https://mastra.ai/docs/memory/storage) backend on the Mastra instance. Tasks are persisted so they survive process restarts.
|
|
18
|
+
|
|
19
|
+
## Quickstart
|
|
20
|
+
|
|
21
|
+
Background tasks are off by default. Enable them by setting `backgroundTasks.enabled` on the Mastra instance:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { Mastra } from '@mastra/core'
|
|
25
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
26
|
+
|
|
27
|
+
export const mastra = new Mastra({
|
|
28
|
+
storage: new LibSQLStore({ id: 'storage', url: 'file:mastra.db' }),
|
|
29
|
+
backgroundTasks: {
|
|
30
|
+
enabled: true,
|
|
31
|
+
globalConcurrency: 10,
|
|
32
|
+
perAgentConcurrency: 5,
|
|
33
|
+
backpressure: 'queue',
|
|
34
|
+
defaultTimeoutMs: 300_000,
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The full set of options is listed in the [backgroundTasks configuration reference](https://mastra.ai/reference/configuration).
|
|
40
|
+
|
|
41
|
+
## Run a tool in the background
|
|
42
|
+
|
|
43
|
+
Enabling the manager doesn't run anything in the background by itself as every tool defaults to foreground execution. You can run a tool in the background at one of three layers, in priority order:
|
|
44
|
+
|
|
45
|
+
1. **LLM per-call override**: the model decides it should run in the background and includes a `_background` field in the tool arguments.
|
|
46
|
+
2. **Agent-level config**: the agent declares which of its tools are background-eligible.
|
|
47
|
+
3. **Tool-level config**: the tool itself declares it as background-eligible.
|
|
48
|
+
|
|
49
|
+
### Tool-level
|
|
50
|
+
|
|
51
|
+
Set `backgroundTasks.enabled: true` on the tool definition. Tools opted in at this layer run in the background whenever called by an agent that has the manager enabled.
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { createTool } from '@mastra/core/tools'
|
|
55
|
+
import { z } from 'zod'
|
|
56
|
+
|
|
57
|
+
export const researchTool = createTool({
|
|
58
|
+
id: 'research',
|
|
59
|
+
description: 'Run a long research job',
|
|
60
|
+
inputSchema: z.object({ topic: z.string() }),
|
|
61
|
+
backgroundTasks: {
|
|
62
|
+
enabled: true,
|
|
63
|
+
timeoutMs: 600_000,
|
|
64
|
+
maxRetries: 1,
|
|
65
|
+
},
|
|
66
|
+
execute: async ({ context }) => {
|
|
67
|
+
// ...
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Agent-level
|
|
73
|
+
|
|
74
|
+
Use `backgroundTasks.tools` on the agent to opt in specific tools, override timeouts for individual tools, or run all background-eligible tools in the background. Use `disabled: true` to short-circuit background dispatch for the agent entirely.
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { Agent } from '@mastra/core/agent'
|
|
78
|
+
|
|
79
|
+
export const researcher = new Agent({
|
|
80
|
+
id: 'researcher',
|
|
81
|
+
instructions: 'You research topics and answer questions.',
|
|
82
|
+
model: 'openai/gpt-5.4',
|
|
83
|
+
tools: { researchTool, summarizeTool },
|
|
84
|
+
backgroundTasks: {
|
|
85
|
+
tools: {
|
|
86
|
+
researchTool: { enabled: true, timeoutMs: 600_000 },
|
|
87
|
+
summarizeTool: false,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Set `tools: 'all'` to opt in every tool the agent has.
|
|
94
|
+
|
|
95
|
+
### LLM per-call override
|
|
96
|
+
|
|
97
|
+
When a tool is registered on an agent that has background tasks enabled, the model can include a `_background` field in the tool arguments to override the resolved configuration for that specific call. The model only includes what it wants to override, all fields in `_background` are optional. The override is stripped from the arguments before the tool runs.
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"topic": "solana",
|
|
102
|
+
"_background": { "enabled": true, "timeoutMs": 900_000 }
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Resolution order
|
|
107
|
+
|
|
108
|
+
When a tool call is dispatched, the resolved background config is computed in this priority order:
|
|
109
|
+
|
|
110
|
+
1. LLM `_background` override (if present in the call's arguments).
|
|
111
|
+
2. Agent-level `backgroundTasks.tools` entry for the tool.
|
|
112
|
+
3. Tool-level `backgroundTasks` config.
|
|
113
|
+
4. Manager defaults (`defaultTimeoutMs`, `defaultRetries`).
|
|
114
|
+
|
|
115
|
+
If the agent has `backgroundTasks.disabled: true`, every tool call runs synchronously regardless of the layers above.
|
|
116
|
+
|
|
117
|
+
## Background tasks related stream chunks
|
|
118
|
+
|
|
119
|
+
When a tool call dispatches as a background task, two streams may surface lifecycle events for it: the agent's own stream and the [`backgroundTaskManager.stream()`](https://mastra.ai/docs/streaming/background-task-streaming) SSE stream. Each stream covers a different set of chunk types:
|
|
120
|
+
|
|
121
|
+
| Chunk type | When it fires | Emitted by |
|
|
122
|
+
| --------------------------- | -------------------------------------------------------------------------------------- | -------------- |
|
|
123
|
+
| `background-task-started` | The task has been enqueued and assigned a `taskId`. | Agent stream |
|
|
124
|
+
| `background-task-running` | The task picked up a worker and started executing. | Manager stream |
|
|
125
|
+
| `background-task-progress` | Shows number of running background tasks. | Agent stream |
|
|
126
|
+
| `background-task-output` | A streamed output chunk from the task's `execute`. | Manager stream |
|
|
127
|
+
| `background-task-completed` | The task finished successfully. The `payload.result` matches the eventual tool result. | Manager stream |
|
|
128
|
+
| `background-task-failed` | The task threw or timed out. | Manager stream |
|
|
129
|
+
| `background-task-cancelled` | The task was cancelled before completing. | Manager stream |
|
|
130
|
+
|
|
131
|
+
`agent.stream().fullStream` only emits the agent-loop chunks (`background-task-started`, `background-task-progress`) on its own. `agent.streamUntilIdle()` emits the same two chunks and additionally subscribes to the manager pubsub for the run's memory scope and pipes the five manager chunks (`background-task-running`, `background-task-output`, `background-task-completed`, `background-task-failed`, `background-task-cancelled`) into the same `fullStream`, so consumers of `streamUntilIdle().fullStream` see all seven types.
|
|
132
|
+
|
|
133
|
+
`backgroundTaskManager.stream()` only emits the five manager chunks.
|
|
134
|
+
|
|
135
|
+
The full payload shapes are documented in the [background task chunks reference](https://mastra.ai/reference/streaming/ChunkType).
|
|
136
|
+
|
|
137
|
+
## Keep the agent stream open with `streamUntilIdle()`
|
|
138
|
+
|
|
139
|
+
`agent.stream()` returns once the LLM emits a final response even if a background task is still running. Use `agent.streamUntilIdle()` when you want the stream to stay open until every dispatched background task has completed and the LLM has had a chance to respond to the result:
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
const stream = await agent.streamUntilIdle('Research solana for me', {
|
|
143
|
+
memory: { thread: 't1', resource: 'u1' },
|
|
144
|
+
maxIdleMs: 5 * 60_000,
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
for await (const chunk of stream.fullStream) {
|
|
148
|
+
// chunks from the initial turn AND any continuation turns triggered by
|
|
149
|
+
// background task completions flow through here
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
When a background task completes, the result is injected into the agent memory, `streamUntilIdle()` re-enters the agentic loop so the LLM can react to it. The stream closes when no tasks are running and no completions are queued.
|
|
154
|
+
|
|
155
|
+
`maxIdleMs` caps how long the stream waits between turns. The timer only runs while the wrapper is between turns, so a slow first token won't close the stream. The default is 5 minutes.
|
|
156
|
+
|
|
157
|
+
> **Note:** Visit [`Agent.streamUntilIdle()`](https://mastra.ai/reference/streaming/agents/streamUntilIdle) for the full API.
|
|
158
|
+
|
|
159
|
+
### Aggregate properties
|
|
160
|
+
|
|
161
|
+
`streamUntilIdle()` returns a `MastraModelOutput` that looks like the one from `stream()`, but only `fullStream` spans the initial turn **and** any auto-continuations. Aggregate properties (`text`, `toolCalls`, `toolResults`, `finishReason`, `messageList`, `getFullOutput()`) still resolve against the **first turn's** internal buffer. If you need an aggregate view across continuations, consume `fullStream` yourself and accumulate.
|
|
162
|
+
|
|
163
|
+
## Subagents in the background
|
|
164
|
+
|
|
165
|
+
Subagent invocations are dispatched as tool calls under the hood, so the same background configuration applies. The recommended pattern is to opt each subagent in on the supervisor, it's clearer and lets you tune `timeoutMs` per subagent in one place:
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import { Agent } from '@mastra/core/agent'
|
|
169
|
+
|
|
170
|
+
const supervisor = new Agent({
|
|
171
|
+
id: 'supervisor',
|
|
172
|
+
instructions: 'Coordinate research and writing using the available agents.',
|
|
173
|
+
model: 'openai/gpt-5.4',
|
|
174
|
+
agents: { researchAgent, writingAgent },
|
|
175
|
+
backgroundTasks: {
|
|
176
|
+
tools: {
|
|
177
|
+
researchAgent: { enabled: true, timeoutMs: 900_000 },
|
|
178
|
+
writingAgent: { enabled: true, timeoutMs: 900_000 },
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
const stream = await supervisor.streamUntilIdle('Research AI in education and write an article', {
|
|
184
|
+
memory: { thread: 't1', resource: 'u1' },
|
|
185
|
+
})
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Inheriting from the subagent
|
|
189
|
+
|
|
190
|
+
If a subagent isn't listed under the supervisor's `backgroundTasks.tools` but has background-eligible tools of its own (either via tool-level `backgroundTasks.enabled: true` or its own `backgroundTasks.tools` entry) the framework still dispatches the entire subagent invocation as a background task. The supervisor inherits the subagent's intent: the subagent itself becomes the background task, and its inner tools run in the foreground inside the subagent's loop.
|
|
191
|
+
|
|
192
|
+
The background config used for the inherited dispatch (for example `waitTimeoutMs`) is derived from the subagent's own `backgroundTasks` config.
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
const researchAgent = new Agent({
|
|
196
|
+
id: 'research-agent',
|
|
197
|
+
description: 'Gathers factual information.',
|
|
198
|
+
model: 'openai/gpt-5-mini',
|
|
199
|
+
tools: { deepResearchTool },
|
|
200
|
+
backgroundTasks: {
|
|
201
|
+
tools: {
|
|
202
|
+
deepResearchTool: { enabled: true, timeoutMs: 600_000 },
|
|
203
|
+
},
|
|
204
|
+
waitTimeoutMs: 900_000,
|
|
205
|
+
},
|
|
206
|
+
})
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
When this `researchAgent` is delegated to from a supervisor that has no backgroundTask configuration for the `researchAgent`, the supervisor still dispatches the whole `researchAgent` invocation as a background task, and `deepResearchTool` runs in the foreground inside that invocation, instead of dispatching its own nested background task.
|
|
210
|
+
|
|
211
|
+
Use this pattern when you want a subagent to behave consistently in the background regardless of which supervisor invokes it. Use the supervisor-side opt-in (above) when you want to tune background behavior centrally per supervisor.
|
|
212
|
+
|
|
213
|
+
## Lifecycle callbacks
|
|
214
|
+
|
|
215
|
+
Each layer can register terminal-state callbacks. They don't replace one another, and success/failure hooks fire for their respective outcomes:
|
|
216
|
+
|
|
217
|
+
- Tool-level `backgroundTasks.onComplete` / `onFailed`: scoped to one tool.
|
|
218
|
+
- Agent-level `backgroundTasks.onTaskComplete` / `onTaskFailed`: scoped to all tasks dispatched by this agent.
|
|
219
|
+
- Manager-level `onTaskComplete` / `onTaskFailed`: scoped globally.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
export const mastra = new Mastra({
|
|
223
|
+
storage,
|
|
224
|
+
backgroundTasks: {
|
|
225
|
+
enabled: true,
|
|
226
|
+
onTaskComplete: task => {
|
|
227
|
+
logger.info('Background task complete', { taskId: task.id, toolName: task.toolName })
|
|
228
|
+
},
|
|
229
|
+
onTaskFailed: task => {
|
|
230
|
+
logger.error('Background task failed', { taskId: task.id, error: task.error })
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
})
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Related
|
|
237
|
+
|
|
238
|
+
- [`Agent.streamUntilIdle()` reference](https://mastra.ai/reference/streaming/agents/streamUntilIdle)
|
|
239
|
+
- [backgroundTasks configuration reference](https://mastra.ai/reference/configuration)
|
|
240
|
+
- [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents)
|
|
241
|
+
- [Stream chunk types](https://mastra.ai/reference/streaming/ChunkType)
|
|
242
|
+
- [Storage](https://mastra.ai/docs/memory/storage)
|
|
@@ -300,9 +300,38 @@ Success criteria:
|
|
|
300
300
|
})
|
|
301
301
|
```
|
|
302
302
|
|
|
303
|
-
##
|
|
303
|
+
## Running subagents in the background
|
|
304
304
|
|
|
305
|
-
|
|
305
|
+
Subagent invocations are dispatched as tool calls, so they can run as [background tasks](https://mastra.ai/docs/agents/background-tasks). This is useful when one or more delegations are long-running and you don't want them to block the supervisor's response.
|
|
306
|
+
|
|
307
|
+
Enable the [backgroundTasks manager](https://mastra.ai/reference/configuration) on the Mastra instance, then opt subagents in on the supervisor:
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
const supervisor = new Agent({
|
|
311
|
+
id: 'supervisor',
|
|
312
|
+
instructions: 'Coordinate research and writing using the available agents.',
|
|
313
|
+
model: 'openai/gpt-5.4',
|
|
314
|
+
agents: { researchAgent, writingAgent },
|
|
315
|
+
backgroundTasks: {
|
|
316
|
+
tools: {
|
|
317
|
+
researchAgent: { enabled: true, timeoutMs: 900_000 },
|
|
318
|
+
writingAgent: { enabled: true, timeoutMs: 900_000 },
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
const stream = await supervisor.streamUntilIdle('Research AI in education and write an article', {
|
|
324
|
+
memory: { thread: 't1', resource: 'u1' },
|
|
325
|
+
})
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
Use [`streamUntilIdle()`](https://mastra.ai/reference/streaming/agents/streamUntilIdle) instead of `stream()` so the stream stays open until the subagents complete and the supervisor has had a chance to respond to their results.
|
|
329
|
+
|
|
330
|
+
If a subagent isn't listed on the supervisor but has its own background-eligible tools, the supervisor still dispatches the subagent as a background task and inherits its config. See [Inheriting from the subagent](https://mastra.ai/docs/agents/background-tasks) for details.
|
|
331
|
+
|
|
332
|
+
## Subagent versioning
|
|
333
|
+
|
|
334
|
+
When using the [editor](https://mastra.ai/docs/editor/overview), you can control which stored version of each subagent the supervisor uses at runtime. Set version overrides on the Mastra instance or per invocation:
|
|
306
335
|
|
|
307
336
|
```typescript
|
|
308
337
|
const result = await supervisor.generate('Research and write about AI safety', {
|
|
@@ -315,13 +344,15 @@ const result = await supervisor.generate('Research and write about AI safety', {
|
|
|
315
344
|
})
|
|
316
345
|
```
|
|
317
346
|
|
|
318
|
-
Version overrides propagate automatically through delegation. See [
|
|
347
|
+
Version overrides propagate automatically through delegation. See [Subagent versioning](https://mastra.ai/docs/editor/overview) for details on resolution order and server API usage.
|
|
319
348
|
|
|
320
349
|
## Related
|
|
321
350
|
|
|
322
|
-
- [
|
|
351
|
+
- [Background tasks](https://mastra.ai/docs/agents/background-tasks)
|
|
352
|
+
- [Subagent versioning](https://mastra.ai/docs/editor/overview)
|
|
323
353
|
- [Guide: Research coordinator](https://mastra.ai/guides/guide/research-coordinator)
|
|
324
354
|
- [Agent.stream() reference](https://mastra.ai/reference/streaming/agents/stream)
|
|
355
|
+
- [Agent.streamUntilIdle() reference](https://mastra.ai/reference/streaming/agents/streamUntilIdle)
|
|
325
356
|
- [Agent.generate() reference](https://mastra.ai/reference/agents/generate)
|
|
326
357
|
- [Agent approval](https://mastra.ai/docs/agents/agent-approval)
|
|
327
358
|
- [Memory in multi-agent systems](https://mastra.ai/docs/memory/overview)
|
|
@@ -290,6 +290,7 @@ Note that for subagents, you'll see two different identifiers in stream response
|
|
|
290
290
|
|
|
291
291
|
- [`createTool` reference](https://mastra.ai/reference/tools/create-tool)
|
|
292
292
|
- [`Agent.generate()` reference](https://mastra.ai/reference/agents/generate): Runtime options for tool selection, steps, and callbacks
|
|
293
|
+
- [Background tasks](https://mastra.ai/docs/agents/background-tasks): Run long-running tools without blocking the agent loop
|
|
293
294
|
- [MCP overview](https://mastra.ai/docs/mcp/overview)
|
|
294
295
|
- [Dynamic tool search](https://mastra.ai/reference/processors/tool-search-processor): Load tools on demand for agents with large tool libraries
|
|
295
296
|
- [Tools with structured output](https://mastra.ai/docs/agents/structured-output): Model compatibility when combining tools and structured output
|
|
@@ -8,9 +8,9 @@ Three categories of metrics are emitted automatically:
|
|
|
8
8
|
- **Token usage metrics**: Input and output token counts broken down by type (text, cache, audio, image, reasoning).
|
|
9
9
|
- **Cost estimation**: Estimated cost per model call based on an embedded pricing registry.
|
|
10
10
|
|
|
11
|
-
> **Note:** Metrics require
|
|
11
|
+
> **Note:** Metrics require an OLAP-capable store for observability. Relational databases like PostgreSQL, LibSQL, etc. are not supported for metrics. In-memory storage resets on restart.
|
|
12
12
|
>
|
|
13
|
-
> For local development,
|
|
13
|
+
> For local development, use [DuckDB](https://duckdb.org/) through `@mastra/duckdb`. For production, use [ClickHouse](https://clickhouse.com/) through `@mastra/clickhouse`.
|
|
14
14
|
|
|
15
15
|
## When to use metrics
|
|
16
16
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The `DefaultExporter` persists traces to your configured storage backend, making them accessible through Studio. It's automatically enabled when using the default observability configuration and requires no external services.
|
|
4
4
|
|
|
5
|
-
> **Production Observability:** Observability data can quickly overwhelm general-purpose databases in production. For high-traffic applications,
|
|
5
|
+
> **Production Observability:** Observability data can quickly overwhelm general-purpose databases in production. For high-traffic applications, route the observability storage domain to [ClickHouse](https://mastra.ai/reference/storage/clickhouse) through [composite storage](https://mastra.ai/reference/storage/composite). See [Production Recommendations](#production-recommendations) for details.
|
|
6
6
|
|
|
7
7
|
## Configuration
|
|
8
8
|
|
|
@@ -114,7 +114,7 @@ If you set the strategy to `'auto'`, the `DefaultExporter` automatically selects
|
|
|
114
114
|
|
|
115
115
|
| Storage Provider | Preferred Strategy | Supported Strategies | Recommended Use |
|
|
116
116
|
| ---------------------------------------------------------------- | ------------------ | ------------------------------- | ------------------------------------- |
|
|
117
|
-
| **ClickHouse
|
|
117
|
+
| **[ClickHouse](https://mastra.ai/reference/storage/clickhouse)** | insert-only | insert-only | Production (high-volume) |
|
|
118
118
|
| **[PostgreSQL](https://mastra.ai/reference/storage/postgresql)** | batch-with-updates | batch-with-updates, insert-only | Production (low volume) |
|
|
119
119
|
| **[MSSQL](https://mastra.ai/reference/storage/mssql)** | batch-with-updates | batch-with-updates, insert-only | Production (low volume) |
|
|
120
120
|
| **[MongoDB](https://mastra.ai/reference/storage/mongodb)** | batch-with-updates | batch-with-updates, insert-only | Production (low volume) |
|
|
@@ -143,7 +143,7 @@ Observability data grows quickly in production environments. A single agent inte
|
|
|
143
143
|
|
|
144
144
|
### Recommended: ClickHouse for High-Volume Production
|
|
145
145
|
|
|
146
|
-
[ClickHouse](https://mastra.ai/reference/storage/
|
|
146
|
+
[ClickHouse](https://mastra.ai/reference/storage/clickhouse) is a columnar database designed for high-volume analytics workloads. It's the recommended choice for production observability because:
|
|
147
147
|
|
|
148
148
|
- **Optimized for writes**: Handles millions of inserts per second
|
|
149
149
|
- **Efficient compression**: Reduces storage costs for trace data
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
# Laminar exporter
|
|
2
2
|
|
|
3
|
-
[Laminar](https://laminar.sh/) is an open-source platform for
|
|
3
|
+
[Laminar](https://laminar.sh/) is an open-source, OpenTelemetry-native observability platform for AI agents. Trace, debug, and monitor every Mastra agent run, model step, tool call, and sub-agent with a single `MastraExporter` wired into your `Observability` config.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
**npm**:
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install @
|
|
10
|
+
npm install @lmnr-ai/lmnr
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
**pnpm**:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
pnpm add @
|
|
16
|
+
pnpm add @lmnr-ai/lmnr
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
**Yarn**:
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
yarn add @
|
|
22
|
+
yarn add @lmnr-ai/lmnr
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
**Bun**:
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
bun add @
|
|
28
|
+
bun add @lmnr-ai/lmnr
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
## Configuration
|
|
@@ -42,7 +42,6 @@ LMNR_PROJECT_API_KEY=lmnr_...
|
|
|
42
42
|
|
|
43
43
|
# Optional
|
|
44
44
|
LMNR_BASE_URL=https://api.lmnr.ai
|
|
45
|
-
LAMINAR_ENDPOINT=https://api.lmnr.ai/v1/traces
|
|
46
45
|
```
|
|
47
46
|
|
|
48
47
|
### Zero-Config Setup
|
|
@@ -52,14 +51,16 @@ With environment variables set, use the exporter with no configuration:
|
|
|
52
51
|
```typescript
|
|
53
52
|
import { Mastra } from '@mastra/core'
|
|
54
53
|
import { Observability } from '@mastra/observability'
|
|
55
|
-
import {
|
|
54
|
+
import { Laminar, MastraExporter } from '@lmnr-ai/lmnr'
|
|
55
|
+
|
|
56
|
+
Laminar.initialize()
|
|
56
57
|
|
|
57
58
|
export const mastra = new Mastra({
|
|
58
59
|
observability: new Observability({
|
|
59
60
|
configs: {
|
|
60
61
|
laminar: {
|
|
61
62
|
serviceName: 'my-service',
|
|
62
|
-
exporters: [new
|
|
63
|
+
exporters: [new MastraExporter()],
|
|
63
64
|
},
|
|
64
65
|
},
|
|
65
66
|
}),
|
|
@@ -73,7 +74,13 @@ You can also pass credentials directly (takes precedence over environment variab
|
|
|
73
74
|
```typescript
|
|
74
75
|
import { Mastra } from '@mastra/core'
|
|
75
76
|
import { Observability } from '@mastra/observability'
|
|
76
|
-
import {
|
|
77
|
+
import { Laminar, MastraExporter } from '@lmnr-ai/lmnr'
|
|
78
|
+
|
|
79
|
+
Laminar.initialize({
|
|
80
|
+
projectApiKey: process.env.LMNR_PROJECT_API_KEY!,
|
|
81
|
+
baseUrl: process.env.LMNR_BASE_URL, // Optional
|
|
82
|
+
// ...other options
|
|
83
|
+
})
|
|
77
84
|
|
|
78
85
|
export const mastra = new Mastra({
|
|
79
86
|
observability: new Observability({
|
|
@@ -81,10 +88,7 @@ export const mastra = new Mastra({
|
|
|
81
88
|
laminar: {
|
|
82
89
|
serviceName: 'my-service',
|
|
83
90
|
exporters: [
|
|
84
|
-
new
|
|
85
|
-
apiKey: process.env.LMNR_PROJECT_API_KEY!,
|
|
86
|
-
baseUrl: process.env.LMNR_BASE_URL, // Optional
|
|
87
|
-
endpoint: process.env.LAMINAR_ENDPOINT, // Optional
|
|
91
|
+
new MastraExporter({
|
|
88
92
|
realtime: process.env.NODE_ENV === 'development', // Optional
|
|
89
93
|
}),
|
|
90
94
|
],
|
|
@@ -94,7 +98,11 @@ export const mastra = new Mastra({
|
|
|
94
98
|
})
|
|
95
99
|
```
|
|
96
100
|
|
|
101
|
+
> **Note:** For advanced usage, including the full `MastraExporter` options and multi-agent trace examples, see [Laminar's Mastra integration guide](https://laminar.sh/docs/tracing/integrations/mastra).
|
|
102
|
+
|
|
103
|
+
Mastra also ships a standalone [`LaminarExporter`](https://mastra.ai/reference/observability/tracing/exporters/laminar) in `@mastra/laminar` that sends spans over OTLP/HTTP. It cannot inherit an active OTel context and does not fully map Mastra spans to Laminar's native format, so use the `@lmnr-ai/lmnr` integration above for `observe()` wrappers, multi-agent root spans, and accurate Laminar rendering.
|
|
104
|
+
|
|
97
105
|
## Related
|
|
98
106
|
|
|
99
107
|
- [Tracing Overview](https://mastra.ai/docs/observability/tracing/overview)
|
|
100
|
-
- [Laminar Documentation](https://
|
|
108
|
+
- [Laminar Documentation](https://laminar.sh/docs)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Background task streaming
|
|
2
|
+
|
|
3
|
+
**Added in:** `@mastra/core@1.29.0`
|
|
4
|
+
|
|
5
|
+
`mastra.backgroundTaskManager.stream()` returns a `ReadableStream` of [background task](https://mastra.ai/docs/agents/background-tasks) lifecycle events. Use it to monitor running tasks across the system, for example to drive a status dashboard, surface progress in your own UI, or pipe events into an SSE response.
|
|
6
|
+
|
|
7
|
+
The stream emits the same chunk types that appear inside `Agent.streamUntilIdle()` (`background-task-running`, `background-task-output`, `background-task-completed`, `background-task-failed`, `background-task-cancelled`). See [background task chunks](https://mastra.ai/reference/streaming/ChunkType) for the full payload shapes.
|
|
8
|
+
|
|
9
|
+
> **Note:** Background tasks must be [enabled on the Mastra instance](https://mastra.ai/reference/configuration) before `backgroundTaskManager` is available. When disabled, `mastra.backgroundTaskManager` is `undefined`.
|
|
10
|
+
|
|
11
|
+
## Subscribe to all task events
|
|
12
|
+
|
|
13
|
+
Calling `stream()` with no filter returns a stream of every task event in the system. On connection, the stream emits a snapshot of all currently running tasks, then forwards live events as they happen.
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
const bgManager = mastra.backgroundTaskManager
|
|
17
|
+
if (!bgManager) throw new Error('Background tasks are not enabled')
|
|
18
|
+
|
|
19
|
+
const controller = new AbortController()
|
|
20
|
+
const stream = bgManager.stream({ abortSignal: controller.signal })
|
|
21
|
+
|
|
22
|
+
for await (const chunk of stream) {
|
|
23
|
+
switch (chunk.type) {
|
|
24
|
+
case 'background-task-running':
|
|
25
|
+
console.log('started', chunk.payload.taskId, chunk.payload.toolName)
|
|
26
|
+
break
|
|
27
|
+
case 'background-task-completed':
|
|
28
|
+
console.log('done', chunk.payload.taskId, chunk.payload.result)
|
|
29
|
+
break
|
|
30
|
+
case 'background-task-failed':
|
|
31
|
+
console.error('failed', chunk.payload.taskId, chunk.payload.error)
|
|
32
|
+
break
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The stream stays open until the caller's `AbortSignal` fires. Always pass an `abortSignal` so you can disconnect cleanly.
|
|
38
|
+
|
|
39
|
+
## Filter the stream
|
|
40
|
+
|
|
41
|
+
Pass any combination of filter options to narrow the events you receive. Filters apply to both the initial snapshot and the live event subscription.
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
const stream = bgManager.stream({
|
|
45
|
+
agentId: 'researcher',
|
|
46
|
+
threadId: 't1',
|
|
47
|
+
resourceId: 'u1',
|
|
48
|
+
abortSignal: controller.signal,
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
| Filter | Description |
|
|
53
|
+
| ------------- | --------------------------------------------------- |
|
|
54
|
+
| `agentId` | Only events from tasks dispatched by this agent |
|
|
55
|
+
| `runId` | Only events from this specific agent run |
|
|
56
|
+
| `threadId` | Only events from tasks scoped to this memory thread |
|
|
57
|
+
| `resourceId` | Only events from tasks scoped to this resource |
|
|
58
|
+
| `taskId` | Only events for a single task |
|
|
59
|
+
| `abortSignal` | Closes the stream when the signal aborts |
|
|
60
|
+
|
|
61
|
+
## Look up task state directly
|
|
62
|
+
|
|
63
|
+
For one-off lookups instead of a live stream, use `getTask` and `listTasks`:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
const task = await mastra.backgroundTaskManager?.getTask(taskId)
|
|
67
|
+
const { tasks, total } = await mastra.backgroundTaskManager?.listTasks({
|
|
68
|
+
status: 'running',
|
|
69
|
+
agentId: 'researcher',
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
These read from storage rather than the pubsub stream, so they're suitable for paginated lists and detail views.
|
|
74
|
+
|
|
75
|
+
## Related
|
|
76
|
+
|
|
77
|
+
- [Background tasks](https://mastra.ai/docs/agents/background-tasks)
|
|
78
|
+
- [`Agent.streamUntilIdle()` reference](https://mastra.ai/reference/streaming/agents/streamUntilIdle)
|
|
79
|
+
- [Background task chunks](https://mastra.ai/reference/streaming/ChunkType)
|
|
80
|
+
- [backgroundTasks configuration reference](https://mastra.ai/reference/configuration)
|
|
@@ -29,6 +29,8 @@ for await (const chunk of stream.textStream) {
|
|
|
29
29
|
|
|
30
30
|
> **Info:** Visit [Agent.stream()](https://mastra.ai/reference/streaming/agents/stream) for more information.
|
|
31
31
|
|
|
32
|
+
> **Tip:** For agents that dispatch [background tasks](https://mastra.ai/docs/agents/background-tasks), use [`Agent.streamUntilIdle()`](https://mastra.ai/reference/streaming/agents/streamUntilIdle) to keep the stream open until those tasks complete and the agent has had a chance to respond to their results.
|
|
33
|
+
|
|
32
34
|
### Output from `Agent.stream()`
|
|
33
35
|
|
|
34
36
|
The output streams the generated response from the agent.
|
|
@@ -129,5 +131,6 @@ A workflow stream provides access to various response properties:
|
|
|
129
131
|
## Related
|
|
130
132
|
|
|
131
133
|
- [Streaming events](https://mastra.ai/docs/streaming/events)
|
|
134
|
+
- [Background tasks](https://mastra.ai/docs/agents/background-tasks)
|
|
132
135
|
- [Using Agents](https://mastra.ai/docs/agents/overview)
|
|
133
136
|
- [Workflows overview](https://mastra.ai/docs/workflows/overview)
|
|
@@ -19,7 +19,7 @@ A filesystem provider handles all file operations for a workspace:
|
|
|
19
19
|
Available providers:
|
|
20
20
|
|
|
21
21
|
- [`LocalFilesystem`](https://mastra.ai/reference/workspace/local-filesystem): Stores files in a directory on disk
|
|
22
|
-
- [`S3Filesystem`](https://mastra.ai/reference/workspace/s3-filesystem): Stores files in Amazon S3 or S3-compatible storage (R2, MinIO)
|
|
22
|
+
- [`S3Filesystem`](https://mastra.ai/reference/workspace/s3-filesystem): Stores files in Amazon S3 or S3-compatible storage (R2, MinIO, Tigris)
|
|
23
23
|
- [`GCSFilesystem`](https://mastra.ai/reference/workspace/gcs-filesystem): Stores files in Google Cloud Storage
|
|
24
24
|
- [`AzureBlobFilesystem`](https://mastra.ai/reference/workspace/azure-blob-filesystem): Stores files in Azure Blob Storage
|
|
25
25
|
- [`AgentFSFilesystem`](https://mastra.ai/reference/workspace/agentfs-filesystem): Stores files in a Turso/SQLite database via AgentFS
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[Assistant UI](https://assistant-ui.com) is the TypeScript/React library for AI Chat. Built on shadcn/ui and Tailwind CSS, it enables developers to create beautiful, enterprise-grade chat experiences in minutes.
|
|
4
4
|
|
|
5
|
-
> **Info:** For a full-stack integration approach where Mastra runs directly in your Next.js API routes, see the [Full-Stack Integration Guide](https://www.assistant-ui.com/docs/
|
|
5
|
+
> **Info:** For a full-stack integration approach where Mastra runs directly in your Next.js API routes, see the [Full-Stack Integration Guide](https://www.assistant-ui.com/docs/integrations/frameworks/mastra/full-stack) on Assistant UI's documentation site.
|
|
6
6
|
|
|
7
7
|
> **Tip:** Visit Mastra's [**"UI Dojo"**](https://ui-dojo.mastra.ai/) to see real-world examples of Assistant UI integrated with Mastra.
|
|
8
8
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# OpenRouter
|
|
2
2
|
|
|
3
|
-
OpenRouter aggregates models from multiple providers with enhanced features like rate limiting and failover. Access
|
|
3
|
+
OpenRouter aggregates models from multiple providers with enhanced features like rate limiting and failover. Access 181 models through Mastra's model router.
|
|
4
4
|
|
|
5
5
|
Learn more in the [OpenRouter documentation](https://openrouter.ai/models).
|
|
6
6
|
|
|
@@ -125,6 +125,7 @@ ANTHROPIC_API_KEY=ant-...
|
|
|
125
125
|
| `nousresearch/hermes-4-405b` |
|
|
126
126
|
| `nousresearch/hermes-4-70b` |
|
|
127
127
|
| `nvidia/nemotron-3-nano-30b-a3b:free` |
|
|
128
|
+
| `nvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free` |
|
|
128
129
|
| `nvidia/nemotron-3-super-120b-a12b` |
|
|
129
130
|
| `nvidia/nemotron-3-super-120b-a12b:free` |
|
|
130
131
|
| `nvidia/nemotron-nano-12b-v2-vl:free` |
|
|
@@ -155,6 +156,7 @@ ANTHROPIC_API_KEY=ant-...
|
|
|
155
156
|
| `openai/gpt-5.4-nano` |
|
|
156
157
|
| `openai/gpt-5.4-pro` |
|
|
157
158
|
| `openai/gpt-5.5` |
|
|
159
|
+
| `openai/gpt-5.5-pro` |
|
|
158
160
|
| `openai/gpt-oss-120b` |
|
|
159
161
|
| `openai/gpt-oss-120b:exacto` |
|
|
160
162
|
| `openai/gpt-oss-120b:free` |
|
package/.docs/models/index.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Model Providers
|
|
2
2
|
|
|
3
|
-
Mastra provides a unified interface for working with LLMs across multiple providers, giving you access to
|
|
3
|
+
Mastra provides a unified interface for working with LLMs across multiple providers, giving you access to 3775 models from 106 providers through a single API.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
@@ -109,7 +109,7 @@ const response = await agent.generate("Hello!", {
|
|
|
109
109
|
|
|
110
110
|
**structuredOutputMode** (`"outputFormat" | "jsonTool" | "auto" | undefined`)
|
|
111
111
|
|
|
112
|
-
**thinking** (`{ type: "adaptive"; } | { type: "enabled"; budgetTokens?: number | undefined; } | { type: "disabled"; } | undefined`)
|
|
112
|
+
**thinking** (`{ type: "adaptive"; display?: "omitted" | "summarized" | undefined; } | { type: "enabled"; budgetTokens?: number | undefined; } | { type: "disabled"; } | undefined`)
|
|
113
113
|
|
|
114
114
|
**disableParallelToolUse** (`boolean | undefined`)
|
|
115
115
|
|
|
@@ -123,7 +123,9 @@ const response = await agent.generate("Hello!", {
|
|
|
123
123
|
|
|
124
124
|
**toolStreaming** (`boolean | undefined`)
|
|
125
125
|
|
|
126
|
-
**effort** (`"low" | "medium" | "high" | "max" | undefined`)
|
|
126
|
+
**effort** (`"low" | "medium" | "high" | "xhigh" | "max" | undefined`)
|
|
127
|
+
|
|
128
|
+
**taskBudget** (`{ type: "tokens"; total: number; remaining?: number | undefined; } | undefined`)
|
|
127
129
|
|
|
128
130
|
**speed** (`"fast" | "standard" | undefined`)
|
|
129
131
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Baseten
|
|
2
2
|
|
|
3
|
-
Access
|
|
3
|
+
Access 11 Baseten models through Mastra's model router. Authentication is handled automatically using the `BASETEN_API_KEY` environment variable.
|
|
4
4
|
|
|
5
5
|
Learn more in the [Baseten documentation](https://docs.baseten.co/development/model-apis/overview).
|
|
6
6
|
|
|
@@ -36,6 +36,7 @@ for await (const chunk of stream) {
|
|
|
36
36
|
| -------------------------------------- | ------- | ----- | --------- | ----- | ----- | ----- | ---------- | ----------- |
|
|
37
37
|
| `baseten/deepseek-ai/DeepSeek-V3-0324` | 164K | | | | | | $0.77 | $0.77 |
|
|
38
38
|
| `baseten/deepseek-ai/DeepSeek-V3.1` | 164K | | | | | | $0.50 | $2 |
|
|
39
|
+
| `baseten/deepseek-ai/DeepSeek-V4-Pro` | 1.0M | | | | | | $2 | $3 |
|
|
39
40
|
| `baseten/MiniMaxAI/MiniMax-M2.5` | 204K | | | | | | $0.30 | $1 |
|
|
40
41
|
| `baseten/moonshotai/Kimi-K2.5` | 262K | | | | | | $0.60 | $3 |
|
|
41
42
|
| `baseten/moonshotai/Kimi-K2.6` | 262K | | | | | | $0.95 | $4 |
|