@mastra/mcp-docs-server 1.2.1-alpha.1 → 1.2.1-alpha.4
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 +89 -14
- package/.docs/docs/agents/durable-agents.md +231 -0
- package/.docs/docs/agents/using-tools.md +52 -0
- package/.docs/docs/getting-started/build-with-ai.md +273 -8
- package/.docs/docs/server/pubsub.md +2 -2
- package/.docs/docs/workflows/overview.md +71 -0
- package/.docs/guides/build-your-ui/ai-sdk-ui.md +3 -3
- package/.docs/guides/concepts/streaming.md +317 -0
- package/.docs/guides/getting-started/quickstart.md +1 -1
- package/.docs/models/gateways/openrouter.md +1 -2
- package/.docs/models/gateways/vercel.md +2 -1
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/baseten.md +1 -1
- package/.docs/models/providers/huggingface.md +27 -5
- package/.docs/models/providers/novita-ai.md +3 -2
- package/.docs/models/providers/opencode.md +2 -1
- package/.docs/reference/agents/durable-agent.md +30 -1
- package/.docs/reference/agents/getDefaultOptions.md +1 -1
- package/.docs/reference/agents/getDefaultStreamOptions.md +1 -1
- package/.docs/reference/agents/inngest-agent.md +339 -0
- package/.docs/reference/ai-sdk/handle-workflow-stream.md +1 -1
- package/.docs/reference/ai-sdk/workflow-route.md +1 -1
- package/.docs/reference/index.md +1 -0
- package/.docs/reference/streaming/workflows/timeTravelStream.md +1 -1
- package/.docs/reference/tools/create-tool.md +1 -1
- package/.docs/reference/workflows/run.md +1 -1
- package/CHANGELOG.md +14 -0
- package/package.json +5 -5
- package/.docs/docs/build-with-ai/mcp-docs-server.md +0 -238
- package/.docs/docs/build-with-ai/skills.md +0 -63
- package/.docs/docs/streaming/background-task-streaming.md +0 -80
- package/.docs/docs/streaming/events.md +0 -148
- package/.docs/docs/streaming/overview.md +0 -136
- package/.docs/docs/streaming/tool-streaming.md +0 -189
- package/.docs/docs/streaming/workflow-streaming.md +0 -109
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
# Streaming
|
|
2
|
+
|
|
3
|
+
Mastra supports real-time, incremental responses from agents and workflows, allowing users to see output as it’s generated instead of waiting for completion. This is useful for chat, long-form content, multi-step workflows, or any scenario where immediate feedback matters.
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
Mastra's streaming API adapts based on your model version:
|
|
8
|
+
|
|
9
|
+
- **`.stream()`**: For V2 models, supports **AI SDK v5** and later (`LanguageModelV2`).
|
|
10
|
+
- **`.streamLegacy()`**: For V1 models, supports **AI SDK v4** (`LanguageModelV1`).
|
|
11
|
+
|
|
12
|
+
## Streaming with agents
|
|
13
|
+
|
|
14
|
+
You can pass a single string for basic prompts, an array of strings when providing multiple pieces of context, or an array of message objects with `role` and `content` for precise control over roles and conversational flows.
|
|
15
|
+
|
|
16
|
+
### Using `Agent.stream()`
|
|
17
|
+
|
|
18
|
+
A `textStream` breaks the response into chunks as it's generated, allowing output to stream progressively instead of arriving all at once. Iterate over the `textStream` using a `for await` loop to inspect each stream chunk.
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
const testAgent = mastra.getAgent('testAgent')
|
|
22
|
+
|
|
23
|
+
const stream = await testAgent.stream([{ role: 'user', content: 'Help me organize my day' }])
|
|
24
|
+
|
|
25
|
+
for await (const chunk of stream.textStream) {
|
|
26
|
+
process.stdout.write(chunk)
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
> **Info:** Visit [Agent.stream()](https://mastra.ai/reference/streaming/agents/stream) for more information.
|
|
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
|
+
|
|
34
|
+
### Output from `Agent.stream()`
|
|
35
|
+
|
|
36
|
+
The output streams the generated response from the agent.
|
|
37
|
+
|
|
38
|
+
```text
|
|
39
|
+
Of course!
|
|
40
|
+
To help you organize your day effectively, I need a bit more information.
|
|
41
|
+
Here are some questions to consider:
|
|
42
|
+
...
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Agent stream properties
|
|
46
|
+
|
|
47
|
+
An agent stream provides access to various response properties:
|
|
48
|
+
|
|
49
|
+
- **`stream.textStream`**: A readable stream that emits text chunks.
|
|
50
|
+
- **`stream.text`**: Promise that resolves to the full text response.
|
|
51
|
+
- **`stream.finishReason`**: The reason the agent stopped streaming.
|
|
52
|
+
- **`stream.usage`**: Token usage information.
|
|
53
|
+
|
|
54
|
+
### AI SDK v5+ Compatibility
|
|
55
|
+
|
|
56
|
+
AI SDK v5 (and later) uses `LanguageModelV2` for the model providers. If you are getting an error that you are using an AI SDK v4 model you will need to upgrade your model package to the next major version.
|
|
57
|
+
|
|
58
|
+
For integration with AI SDK v5+, use the `toAISdkV5Stream()` utility from `@mastra/ai-sdk` to convert Mastra streams to AI SDK-compatible format:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { toAISdkV5Stream } from '@mastra/ai-sdk'
|
|
62
|
+
|
|
63
|
+
const testAgent = mastra.getAgent('testAgent')
|
|
64
|
+
|
|
65
|
+
const stream = await testAgent.stream([{ role: 'user', content: 'Help me organize my day' }])
|
|
66
|
+
|
|
67
|
+
// Convert to AI SDK v5+ compatible stream
|
|
68
|
+
const aiSDKStream = toAISdkV5Stream(stream, { from: 'agent' })
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
For converting messages to AI SDK v5+ format, use the `toAISdkV5Messages()` utility from `@mastra/ai-sdk/ui`:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { toAISdkV5Messages } from '@mastra/ai-sdk/ui'
|
|
75
|
+
|
|
76
|
+
const messages = [{ role: 'user', content: 'Hello' }]
|
|
77
|
+
const aiSDKMessages = toAISdkV5Messages(messages)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Streaming with workflows
|
|
81
|
+
|
|
82
|
+
Streaming from a workflow returns a sequence of structured events describing the run lifecycle, rather than incremental text chunks. This event-based format makes it possible to track and respond to workflow progress in real time once a run is created using `.createRun()`.
|
|
83
|
+
|
|
84
|
+
### Using `Run.stream()`
|
|
85
|
+
|
|
86
|
+
The `stream()` method returns a `ReadableStream` of events directly.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const run = await testWorkflow.createRun()
|
|
90
|
+
|
|
91
|
+
const stream = await run.stream({
|
|
92
|
+
inputData: {
|
|
93
|
+
value: 'initial data',
|
|
94
|
+
},
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
for await (const chunk of stream) {
|
|
98
|
+
console.log(chunk)
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
> **Info:** Visit [Run.stream()](https://mastra.ai/reference/streaming/workflows/stream) for more information.
|
|
103
|
+
|
|
104
|
+
### Output from `Run.stream()`
|
|
105
|
+
|
|
106
|
+
The event structure includes `runId` and `from` at the top level, making it easier to identify and track workflow runs without digging into the payload.
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
{
|
|
110
|
+
type: 'workflow-start',
|
|
111
|
+
runId: '1eeaf01a-d2bf-4e3f-8d1b-027795ccd3df',
|
|
112
|
+
from: 'WORKFLOW',
|
|
113
|
+
payload: {
|
|
114
|
+
stepName: 'step-1',
|
|
115
|
+
args: { value: 'initial data' },
|
|
116
|
+
stepCallId: '8e15e618-be0e-4215-a5d6-08e58c152068',
|
|
117
|
+
startedAt: 1755121710066,
|
|
118
|
+
status: 'running'
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Workflow stream properties
|
|
124
|
+
|
|
125
|
+
A workflow stream provides access to various response properties:
|
|
126
|
+
|
|
127
|
+
- **`stream.status`**: The status of the workflow run.
|
|
128
|
+
- **`stream.result`**: The result of the workflow run.
|
|
129
|
+
- **`stream.usage`**: The total token usage of the workflow run.
|
|
130
|
+
|
|
131
|
+
Streaming from agents or workflows provides real-time visibility into either the LLM’s output or the status of a workflow run. This feedback can be passed directly to the user, or used within applications to handle workflow status more effectively, creating a smoother and more responsive experience.
|
|
132
|
+
|
|
133
|
+
Events emitted from agents or workflows represent different stages of generation and execution, such as when a run starts, when text is produced, or when a tool is invoked.
|
|
134
|
+
|
|
135
|
+
## Event types
|
|
136
|
+
|
|
137
|
+
Below is a complete list of events emitted from `.stream()`. Depending on whether you’re streaming from an **agent** or a **workflow**, only a subset of these events will occur:
|
|
138
|
+
|
|
139
|
+
- **start**: Marks the beginning of an agent or workflow run.
|
|
140
|
+
- **step-start**: Indicates a workflow step has begun execution.
|
|
141
|
+
- **text-delta**: Incremental text chunks as they're generated by the LLM.
|
|
142
|
+
- **tool-call**: When the agent decides to use a tool, including the tool name and arguments.
|
|
143
|
+
- **tool-result**: The result returned from tool execution.
|
|
144
|
+
- **step-finish**: Confirms that a specific step has fully finalized, and may include metadata like the finish reason for that step.
|
|
145
|
+
- **finish**: When the agent or workflow completes, including usage statistics.
|
|
146
|
+
|
|
147
|
+
## Inspecting agent streams
|
|
148
|
+
|
|
149
|
+
Iterate over the `stream` with a `for await` loop to inspect all emitted event chunks.
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
const testAgent = mastra.getAgent('testAgent')
|
|
153
|
+
|
|
154
|
+
const stream = await testAgent.stream([{ role: 'user', content: 'Help me organize my day' }])
|
|
155
|
+
|
|
156
|
+
for await (const chunk of stream) {
|
|
157
|
+
console.log(chunk)
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
> **Info:** Visit [Agent.stream()](https://mastra.ai/reference/streaming/agents/stream) for more information.
|
|
162
|
+
|
|
163
|
+
### Example agent output
|
|
164
|
+
|
|
165
|
+
Below is an example of events that may be emitted. Each event always includes a `type` and can include additional fields like `from` and `payload`.
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
{
|
|
169
|
+
type: 'start',
|
|
170
|
+
from: 'AGENT',
|
|
171
|
+
// ..
|
|
172
|
+
}
|
|
173
|
+
{
|
|
174
|
+
type: 'step-start',
|
|
175
|
+
from: 'AGENT',
|
|
176
|
+
payload: {
|
|
177
|
+
messageId: 'msg-cdUrkirvXw8A6oE4t5lzDuxi',
|
|
178
|
+
// ...
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
{
|
|
182
|
+
type: 'tool-call',
|
|
183
|
+
from: 'AGENT',
|
|
184
|
+
payload: {
|
|
185
|
+
toolCallId: 'call_jbhi3s1qvR6Aqt9axCfTBMsA',
|
|
186
|
+
toolName: 'testTool'
|
|
187
|
+
// ..
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Writer API
|
|
193
|
+
|
|
194
|
+
The `writer` API is shared by tools and workflow steps — see the Tools and Workflows docs for feature-specific examples.
|
|
195
|
+
|
|
196
|
+
## Agent using tool
|
|
197
|
+
|
|
198
|
+
Agent streaming can be combined with tool calls, allowing tool outputs to be written directly into the agent’s streaming response. This makes it possible to surface tool activity as part of the overall interaction.
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import { Agent } from '@mastra/core/agent'
|
|
202
|
+
import { testTool } from '../tools/test-tool'
|
|
203
|
+
|
|
204
|
+
export const testAgent = new Agent({
|
|
205
|
+
id: 'test-agent',
|
|
206
|
+
name: 'Test Agent',
|
|
207
|
+
instructions: 'You are a weather agent.',
|
|
208
|
+
model: 'openai/gpt-5.5',
|
|
209
|
+
tools: { testTool },
|
|
210
|
+
})
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Using `context.writer`
|
|
214
|
+
|
|
215
|
+
The `context.writer` object is available in a tool's `execute()` function and can be used to emit custom events, data, or values into the active stream. This enables tools to provide intermediate results or status updates while execution is still in progress.
|
|
216
|
+
|
|
217
|
+
> **Warning:** You must `await` the call to `writer.write()` or else you will lock the stream and get a `WritableStream is locked` error.
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
import { createTool } from '@mastra/core/tools'
|
|
221
|
+
|
|
222
|
+
export const testTool = createTool({
|
|
223
|
+
execute: async (inputData, context) => {
|
|
224
|
+
const { value } = inputData
|
|
225
|
+
|
|
226
|
+
await context?.writer?.write({
|
|
227
|
+
type: 'custom-event',
|
|
228
|
+
status: 'pending',
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
const response = await fetch()
|
|
232
|
+
|
|
233
|
+
await context?.writer?.write({
|
|
234
|
+
type: 'custom-event',
|
|
235
|
+
status: 'success',
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
return {
|
|
239
|
+
value: '',
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
})
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
You can also use `writer.custom()` to emit top-level stream chunks. This is useful when integrating with UI frameworks.
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
import { createTool } from '@mastra/core/tools'
|
|
249
|
+
|
|
250
|
+
export const testTool = createTool({
|
|
251
|
+
execute: async (inputData, context) => {
|
|
252
|
+
const { value } = inputData
|
|
253
|
+
|
|
254
|
+
await context?.writer?.custom({
|
|
255
|
+
type: 'data-tool-progress',
|
|
256
|
+
status: 'pending',
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
const response = await fetch()
|
|
260
|
+
|
|
261
|
+
await context?.writer?.custom({
|
|
262
|
+
type: 'data-tool-progress',
|
|
263
|
+
status: 'success',
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
return {
|
|
267
|
+
value: '',
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
})
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Transient data chunks
|
|
274
|
+
|
|
275
|
+
By default, `data-*` chunks emitted with `writer.custom()` are persisted to storage as part of the message history. For chunks that are only needed during live streaming — such as progress updates or verbose log output — set `transient: true` to skip storage persistence. Transient chunks are still streamed to the client in real time but aren't saved to the database.
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
await context?.writer?.custom({
|
|
279
|
+
type: 'data-build-log',
|
|
280
|
+
data: { line: 'Compiling module 3 of 12...' },
|
|
281
|
+
transient: true,
|
|
282
|
+
})
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Use transient chunks when the data is large or high-frequency and only relevant during the live session. After a page refresh, transient chunks are no longer available — only the tool's return value and any non-transient chunks are loaded from storage.
|
|
286
|
+
|
|
287
|
+
## Using the `writer` argument
|
|
288
|
+
|
|
289
|
+
The `writer` argument is passed to a workflow step's `execute` function and can be used to emit custom events, data, or values into the active stream. This enables workflow steps to provide intermediate results or status updates while execution is still in progress.
|
|
290
|
+
|
|
291
|
+
> **Warning:** You must `await` the call to `writer.write(...)` or else you will lock the stream and get a `WritableStream is locked` error.
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
import { createStep } from "@mastra/core/workflows";
|
|
295
|
+
|
|
296
|
+
export const testStep = createStep({
|
|
297
|
+
execute: async ({ inputData, writer }) => {
|
|
298
|
+
const { value } = inputData;
|
|
299
|
+
|
|
300
|
+
await writer?.write({
|
|
301
|
+
type: "custom-event",
|
|
302
|
+
status: "pending"
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
const response = await fetch(...);
|
|
306
|
+
|
|
307
|
+
await writer?.write({
|
|
308
|
+
type: "custom-event",
|
|
309
|
+
status: "success"
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
return {
|
|
313
|
+
value: ""
|
|
314
|
+
};
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
```
|
|
@@ -46,7 +46,7 @@ The wizard creates a new directory for your project with a `src/mastra` folder c
|
|
|
46
46
|
- `workflows/weather-workflow.ts`: A workflow that runs the weather agent
|
|
47
47
|
- `scorers/weather-scorer.ts`: A scorer to evaluate the weather agent's responses
|
|
48
48
|
|
|
49
|
-
Depending on your choices, you'll also end up with [Mastra Skills](https://mastra.ai/docs/build-with-ai
|
|
49
|
+
Depending on your choices, you'll also end up with [Mastra Skills](https://mastra.ai/docs/getting-started/build-with-ai) or the [MCP Docs Server](https://mastra.ai/docs/getting-started/build-with-ai) installed.
|
|
50
50
|
|
|
51
51
|
> **Tip:** You can use [flags](https://mastra.ai/reference/cli/create-mastra) with `create mastra` like `--no-example` to skip the example weather agent or `--template` to start from a specific [template](https://mastra.ai/templates).
|
|
52
52
|
|
|
@@ -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 337 models through Mastra's model router.
|
|
4
4
|
|
|
5
5
|
Learn more in the [OpenRouter documentation](https://openrouter.ai/models).
|
|
6
6
|
|
|
@@ -190,7 +190,6 @@ ANTHROPIC_API_KEY=ant-...
|
|
|
190
190
|
| `morph/morph-v3-fast` |
|
|
191
191
|
| `morph/morph-v3-large` |
|
|
192
192
|
| `nex-agi/nex-n2-pro` |
|
|
193
|
-
| `nex-agi/nex-n2-pro:free` |
|
|
194
193
|
| `nousresearch/hermes-3-llama-3.1-405b` |
|
|
195
194
|
| `nousresearch/hermes-3-llama-3.1-405b:free` |
|
|
196
195
|
| `nousresearch/hermes-3-llama-3.1-70b` |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Vercel
|
|
2
2
|
|
|
3
|
-
Vercel aggregates models from multiple providers with enhanced features like rate limiting and failover. Access
|
|
3
|
+
Vercel aggregates models from multiple providers with enhanced features like rate limiting and failover. Access 279 models through Mastra's model router.
|
|
4
4
|
|
|
5
5
|
Learn more in the [Vercel documentation](https://ai-sdk.dev/providers/ai-sdk-providers).
|
|
6
6
|
|
|
@@ -267,6 +267,7 @@ ANTHROPIC_API_KEY=ant-...
|
|
|
267
267
|
| `recraft/recraft-v4.1-pro` |
|
|
268
268
|
| `recraft/recraft-v4.1-utility` |
|
|
269
269
|
| `recraft/recraft-v4.1-utility-pro` |
|
|
270
|
+
| `sakana/fugu-ultra` |
|
|
270
271
|
| `stepfun/step-3.5-flash` |
|
|
271
272
|
| `stepfun/step-3.7-flash` |
|
|
272
273
|
| `voyage/rerank-2.5` |
|
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 4563 models from 133 providers through a single API.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
@@ -44,7 +44,7 @@ for await (const chunk of stream) {
|
|
|
44
44
|
| `baseten/zai-org/GLM-4.7` | 200K | | | | | | $0.60 | $2 |
|
|
45
45
|
| `baseten/zai-org/GLM-5` | 203K | | | | | | $0.95 | $3 |
|
|
46
46
|
| `baseten/zai-org/GLM-5.1` | 203K | | | | | | $1 | $4 |
|
|
47
|
-
| `baseten/zai-org/GLM-5.2` | 131K | | | | | | $
|
|
47
|
+
| `baseten/zai-org/GLM-5.2` | 131K | | | | | | $1 | $4 |
|
|
48
48
|
|
|
49
49
|
## Advanced configuration
|
|
50
50
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Hugging Face
|
|
2
2
|
|
|
3
|
-
Access
|
|
3
|
+
Access 46 Hugging Face models through Mastra's model router. Authentication is handled automatically using the `HF_TOKEN` environment variable.
|
|
4
4
|
|
|
5
5
|
Learn more in the [Hugging Face documentation](https://huggingface.co).
|
|
6
6
|
|
|
@@ -15,7 +15,7 @@ const agent = new Agent({
|
|
|
15
15
|
id: "my-agent",
|
|
16
16
|
name: "My Agent",
|
|
17
17
|
instructions: "You are a helpful assistant",
|
|
18
|
-
model: "huggingface/MiniMaxAI/MiniMax-M2
|
|
18
|
+
model: "huggingface/MiniMaxAI/MiniMax-M2"
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
// Generate a response
|
|
@@ -34,30 +34,52 @@ for await (const chunk of stream) {
|
|
|
34
34
|
|
|
35
35
|
| Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
|
|
36
36
|
| ------------------------------------------------- | ------- | ----- | --------- | ----- | ----- | ----- | ---------- | ----------- |
|
|
37
|
+
| `huggingface/deepseek-ai/DeepSeek-R1` | 64K | | | | | | $0.70 | $3 |
|
|
37
38
|
| `huggingface/deepseek-ai/DeepSeek-R1-0528` | 164K | | | | | | $3 | $5 |
|
|
38
39
|
| `huggingface/deepseek-ai/DeepSeek-V3.2` | 164K | | | | | | $0.28 | $0.40 |
|
|
40
|
+
| `huggingface/deepseek-ai/DeepSeek-V4-Flash` | 1.0M | | | | | | $0.14 | $0.28 |
|
|
39
41
|
| `huggingface/deepseek-ai/DeepSeek-V4-Pro` | 1.0M | | | | | | $0.43 | $0.87 |
|
|
42
|
+
| `huggingface/google/gemma-4-26B-A4B-it` | 262K | | | | | | $0.13 | $0.40 |
|
|
43
|
+
| `huggingface/google/gemma-4-31B-it` | 262K | | | | | | $0.14 | $0.40 |
|
|
44
|
+
| `huggingface/meta-llama/Llama-3.3-70B-Instruct` | 131K | | | | | | $0.59 | $0.79 |
|
|
45
|
+
| `huggingface/MiniMaxAI/MiniMax-M2` | 205K | | | | | | $0.30 | $1 |
|
|
40
46
|
| `huggingface/MiniMaxAI/MiniMax-M2.1` | 205K | | | | | | $0.30 | $1 |
|
|
41
47
|
| `huggingface/MiniMaxAI/MiniMax-M2.5` | 205K | | | | | | $0.30 | $1 |
|
|
42
48
|
| `huggingface/MiniMaxAI/MiniMax-M2.7` | 205K | | | | | | $0.30 | $1 |
|
|
49
|
+
| `huggingface/MiniMaxAI/MiniMax-M3` | 524K | | | | | | $0.30 | $1 |
|
|
43
50
|
| `huggingface/moonshotai/Kimi-K2-Instruct` | 131K | | | | | | $1 | $3 |
|
|
44
51
|
| `huggingface/moonshotai/Kimi-K2-Instruct-0905` | 262K | | | | | | $1 | $3 |
|
|
45
52
|
| `huggingface/moonshotai/Kimi-K2-Thinking` | 262K | | | | | | $0.60 | $3 |
|
|
46
53
|
| `huggingface/moonshotai/Kimi-K2.5` | 262K | | | | | | $0.60 | $3 |
|
|
47
54
|
| `huggingface/moonshotai/Kimi-K2.6` | 262K | | | | | | $0.95 | $4 |
|
|
55
|
+
| `huggingface/moonshotai/Kimi-K2.7-Code` | 262K | | | | | | $0.95 | $4 |
|
|
56
|
+
| `huggingface/Qwen/Qwen3-235B-A22B` | 41K | | | | | | $0.20 | $0.80 |
|
|
48
57
|
| `huggingface/Qwen/Qwen3-235B-A22B-Thinking-2507` | 262K | | | | | | $0.30 | $3 |
|
|
58
|
+
| `huggingface/Qwen/Qwen3-32B` | 131K | | | | | | $0.29 | $0.59 |
|
|
59
|
+
| `huggingface/Qwen/Qwen3-Coder-30B-A3B-Instruct` | 262K | | | | | | $0.07 | $0.26 |
|
|
49
60
|
| `huggingface/Qwen/Qwen3-Coder-480B-A35B-Instruct` | 262K | | | | | | $2 | $2 |
|
|
50
61
|
| `huggingface/Qwen/Qwen3-Coder-Next` | 262K | | | | | | $0.20 | $2 |
|
|
51
62
|
| `huggingface/Qwen/Qwen3-Embedding-4B` | 32K | | | | | | $0.01 | — |
|
|
52
63
|
| `huggingface/Qwen/Qwen3-Embedding-8B` | 32K | | | | | | $0.01 | — |
|
|
53
64
|
| `huggingface/Qwen/Qwen3-Next-80B-A3B-Instruct` | 262K | | | | | | $0.25 | $1 |
|
|
54
65
|
| `huggingface/Qwen/Qwen3-Next-80B-A3B-Thinking` | 262K | | | | | | $0.30 | $2 |
|
|
66
|
+
| `huggingface/Qwen/Qwen3.5-122B-A10B` | 262K | | | | | | $0.40 | $3 |
|
|
67
|
+
| `huggingface/Qwen/Qwen3.5-27B` | 262K | | | | | | $0.30 | $2 |
|
|
68
|
+
| `huggingface/Qwen/Qwen3.5-35B-A3B` | 262K | | | | | | $0.25 | $2 |
|
|
55
69
|
| `huggingface/Qwen/Qwen3.5-397B-A17B` | 262K | | | | | | $0.60 | $4 |
|
|
70
|
+
| `huggingface/Qwen/Qwen3.5-9B` | 262K | | | | | | $0.17 | $0.25 |
|
|
71
|
+
| `huggingface/Qwen/Qwen3.6-35B-A3B` | 262K | | | | | | $0.15 | $0.95 |
|
|
72
|
+
| `huggingface/stepfun-ai/Step-3.5-Flash` | 262K | | | | | | $0.10 | $0.30 |
|
|
56
73
|
| `huggingface/XiaomiMiMo/MiMo-V2-Flash` | 262K | | | | | | $0.10 | $0.30 |
|
|
74
|
+
| `huggingface/zai-org/GLM-4.5` | 131K | | | | | | $0.60 | $2 |
|
|
75
|
+
| `huggingface/zai-org/GLM-4.5-Air` | 131K | | | | | | $0.13 | $0.85 |
|
|
76
|
+
| `huggingface/zai-org/GLM-4.5V` | 66K | | | | | | $0.60 | $2 |
|
|
77
|
+
| `huggingface/zai-org/GLM-4.6` | 205K | | | | | | $0.55 | $2 |
|
|
57
78
|
| `huggingface/zai-org/GLM-4.7` | 205K | | | | | | $0.60 | $2 |
|
|
58
79
|
| `huggingface/zai-org/GLM-4.7-Flash` | 200K | | | | | | — | — |
|
|
59
80
|
| `huggingface/zai-org/GLM-5` | 203K | | | | | | $1 | $3 |
|
|
60
81
|
| `huggingface/zai-org/GLM-5.1` | 203K | | | | | | $1 | $3 |
|
|
82
|
+
| `huggingface/zai-org/GLM-5.2` | 262K | | | | | | $1 | $4 |
|
|
61
83
|
|
|
62
84
|
## Advanced configuration
|
|
63
85
|
|
|
@@ -69,7 +91,7 @@ const agent = new Agent({
|
|
|
69
91
|
name: "custom-agent",
|
|
70
92
|
model: {
|
|
71
93
|
url: "https://router.huggingface.co/v1",
|
|
72
|
-
id: "huggingface/MiniMaxAI/MiniMax-M2
|
|
94
|
+
id: "huggingface/MiniMaxAI/MiniMax-M2",
|
|
73
95
|
apiKey: process.env.HF_TOKEN,
|
|
74
96
|
headers: {
|
|
75
97
|
"X-Custom-Header": "value"
|
|
@@ -87,8 +109,8 @@ const agent = new Agent({
|
|
|
87
109
|
model: ({ requestContext }) => {
|
|
88
110
|
const useAdvanced = requestContext.task === "complex";
|
|
89
111
|
return useAdvanced
|
|
90
|
-
? "huggingface/zai-org/GLM-5.
|
|
91
|
-
: "huggingface/MiniMaxAI/MiniMax-M2
|
|
112
|
+
? "huggingface/zai-org/GLM-5.2"
|
|
113
|
+
: "huggingface/MiniMaxAI/MiniMax-M2";
|
|
92
114
|
}
|
|
93
115
|
});
|
|
94
116
|
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# NovitaAI
|
|
2
2
|
|
|
3
|
-
Access
|
|
3
|
+
Access 105 NovitaAI models through Mastra's model router. Authentication is handled automatically using the `NOVITA_API_KEY` environment variable.
|
|
4
4
|
|
|
5
5
|
Learn more in the [NovitaAI documentation](https://novita.ai/docs/guides/introduction).
|
|
6
6
|
|
|
@@ -138,6 +138,7 @@ for await (const chunk of stream) {
|
|
|
138
138
|
| `novita-ai/zai-org/glm-4.7-flash` | 200K | | | | | | $0.07 | $0.40 |
|
|
139
139
|
| `novita-ai/zai-org/glm-5` | 203K | | | | | | $1 | $3 |
|
|
140
140
|
| `novita-ai/zai-org/glm-5.1` | 205K | | | | | | $1 | $4 |
|
|
141
|
+
| `novita-ai/zai-org/glm-5.2` | 1.0M | | | | | | $1 | $4 |
|
|
141
142
|
|
|
142
143
|
## Advanced configuration
|
|
143
144
|
|
|
@@ -167,7 +168,7 @@ const agent = new Agent({
|
|
|
167
168
|
model: ({ requestContext }) => {
|
|
168
169
|
const useAdvanced = requestContext.task === "complex";
|
|
169
170
|
return useAdvanced
|
|
170
|
-
? "novita-ai/zai-org/glm-5.
|
|
171
|
+
? "novita-ai/zai-org/glm-5.2"
|
|
171
172
|
: "novita-ai/baichuan/baichuan-m2-32b";
|
|
172
173
|
}
|
|
173
174
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# OpenCode Zen
|
|
2
2
|
|
|
3
|
-
Access
|
|
3
|
+
Access 46 OpenCode Zen models through Mastra's model router. Authentication is handled automatically using the `OPENCODE_API_KEY` environment variable.
|
|
4
4
|
|
|
5
5
|
Learn more in the [OpenCode Zen documentation](https://opencode.ai/docs/zen).
|
|
6
6
|
|
|
@@ -52,6 +52,7 @@ for await (const chunk of stream) {
|
|
|
52
52
|
| `opencode/gemini-3.5-flash` | 1.0M | | | | | | $2 | $9 |
|
|
53
53
|
| `opencode/glm-5` | 205K | | | | | | $1 | $3 |
|
|
54
54
|
| `opencode/glm-5.1` | 205K | | | | | | $1 | $4 |
|
|
55
|
+
| `opencode/glm-5.2` | 1.0M | | | | | | $1 | $4 |
|
|
55
56
|
| `opencode/gpt-5` | 400K | | | | | | $1 | $9 |
|
|
56
57
|
| `opencode/gpt-5-codex` | 400K | | | | | | $1 | $9 |
|
|
57
58
|
| `opencode/gpt-5-nano` | 400K | | | | | | $0.05 | $0.40 |
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
`DurableAgent` wraps an existing [`Agent`](https://mastra.ai/reference/agents/agent) with durable execution and resumable streams. It runs the agentic loop so that a client can disconnect and reconnect without missing events, and it streams those events over [PubSub](https://mastra.ai/docs/server/pubsub). Use it when a run must outlive a single request or survive a dropped connection.
|
|
4
4
|
|
|
5
|
-
Create one with the [`createDurableAgent`](#createdurableagentoptions) factory, or use [`createEventedAgent`](#createeventedagentoptions) for fire-and-forget execution on the built-in workflow engine. For Inngest-powered execution, use `createInngestAgent` from `@mastra/inngest`.
|
|
5
|
+
Create one with the [`createDurableAgent`](#createdurableagentoptions) factory, or use [`createEventedAgent`](#createeventedagentoptions) for fire-and-forget execution on the built-in workflow engine. For Inngest-powered execution, use [`createInngestAgent`](https://mastra.ai/reference/agents/inngest-agent) from `@mastra/inngest`.
|
|
6
6
|
|
|
7
7
|
## Usage example
|
|
8
8
|
|
|
@@ -153,6 +153,32 @@ Returns: `Promise<DurableAgentStreamResult>`
|
|
|
153
153
|
|
|
154
154
|
> **Warning:** The `cleanup()` returned by `observe()` destroys the run's registry entries and cached events. Only call it when you are done with the run. If the run is suspended and you intend to resume later, don't call `cleanup()` — let the auto-cleanup timer handle it after the run finishes or errors. Auto-cleanup doesn't fire on suspended events.
|
|
155
155
|
|
|
156
|
+
#### `prepare(messages, options?)`
|
|
157
|
+
|
|
158
|
+
Prepares a run for durable execution without starting it. Registers the run in the internal registry and returns the serialized workflow input. Use this when you need to control when and how the workflow is triggered.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
const { runId, messageId, workflowInput, threadId, resourceId } = await durableAgent.prepare(
|
|
162
|
+
'Summarize the document',
|
|
163
|
+
{
|
|
164
|
+
memory: { threadId: 'thread-1', resourceId: 'user-1' },
|
|
165
|
+
},
|
|
166
|
+
)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Returns:
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
interface PrepareResult {
|
|
173
|
+
runId: string
|
|
174
|
+
messageId: string
|
|
175
|
+
workflowInput: any
|
|
176
|
+
registryEntry: object
|
|
177
|
+
threadId?: string
|
|
178
|
+
resourceId?: string
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
156
182
|
## Stream options
|
|
157
183
|
|
|
158
184
|
`stream()` accepts a `DurableAgentStreamOptions` object. It supports the agent execution options below, plus lifecycle callbacks.
|
|
@@ -191,6 +217,8 @@ Returns: `Promise<DurableAgentStreamResult>`
|
|
|
191
217
|
|
|
192
218
|
**structuredOutput** (`object`): Structured output configuration.
|
|
193
219
|
|
|
220
|
+
**untilIdle** (`boolean | { maxIdleMs?: number }`): When set, keeps the stream open across background-task continuations until the agent is idle. Pass \`true\` for the default 5-minute idle timeout, or \`{ maxIdleMs }\` to customise. Equivalent to the deprecated \`streamUntilIdle()\` method.
|
|
221
|
+
|
|
194
222
|
**versions** (`object`): Version overrides for sub-agent delegation.
|
|
195
223
|
|
|
196
224
|
**onChunk** (`(chunk: ChunkType) => void | Promise<void>`): Called for each streamed chunk.
|
|
@@ -234,6 +262,7 @@ interface DurableAgentStreamResult<OUTPUT = undefined> {
|
|
|
234
262
|
|
|
235
263
|
## Related
|
|
236
264
|
|
|
265
|
+
- [`createInngestAgent()`](https://mastra.ai/reference/agents/inngest-agent)
|
|
237
266
|
- [Agent class](https://mastra.ai/reference/agents/agent)
|
|
238
267
|
- [PubSub](https://mastra.ai/docs/server/pubsub)
|
|
239
268
|
- [`.getMemory()`](https://mastra.ai/reference/agents/getMemory)
|
|
@@ -28,5 +28,5 @@ await agent.getDefaultOptions({
|
|
|
28
28
|
|
|
29
29
|
## Related
|
|
30
30
|
|
|
31
|
-
- [Streaming with agents](https://mastra.ai/
|
|
31
|
+
- [Streaming with agents](https://mastra.ai/guides/concepts/streaming)
|
|
32
32
|
- [Request Context](https://mastra.ai/docs/server/request-context)
|
|
@@ -30,5 +30,5 @@ await agent.getDefaultStreamOptionsLegacy({
|
|
|
30
30
|
|
|
31
31
|
## Related
|
|
32
32
|
|
|
33
|
-
- [Streaming with agents](https://mastra.ai/
|
|
33
|
+
- [Streaming with agents](https://mastra.ai/guides/concepts/streaming)
|
|
34
34
|
- [Request Context](https://mastra.ai/docs/server/request-context)
|