@mastra/mcp-docs-server 0.13.26 → 0.13.27

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.
Files changed (104) hide show
  1. package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +9 -9
  2. package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +2 -0
  3. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +13 -13
  4. package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +11 -0
  5. package/.docs/organized/changelogs/%40mastra%2Fastra.md +11 -11
  6. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +10 -10
  7. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +10 -10
  8. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +23 -23
  9. package/.docs/organized/changelogs/%40mastra%2Fcloud.md +10 -10
  10. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +10 -10
  11. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +11 -11
  12. package/.docs/organized/changelogs/%40mastra%2Fcore.md +61 -61
  13. package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +10 -10
  14. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +24 -24
  15. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +20 -20
  16. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +20 -20
  17. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +22 -22
  18. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +45 -45
  19. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +17 -17
  20. package/.docs/organized/changelogs/%40mastra%2Fevals.md +10 -10
  21. package/.docs/organized/changelogs/%40mastra%2Flance.md +11 -11
  22. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +10 -10
  23. package/.docs/organized/changelogs/%40mastra%2Floggers.md +10 -10
  24. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +16 -16
  25. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +10 -10
  26. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +12 -12
  27. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +10 -10
  28. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +11 -11
  29. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +11 -11
  30. package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +10 -10
  31. package/.docs/organized/changelogs/%40mastra%2Fpg.md +10 -10
  32. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +11 -11
  33. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +65 -65
  34. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +10 -10
  35. package/.docs/organized/changelogs/%40mastra%2Frag.md +12 -12
  36. package/.docs/organized/changelogs/%40mastra%2Freact.md +18 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +12 -0
  38. package/.docs/organized/changelogs/%40mastra%2Fserver.md +27 -27
  39. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +11 -11
  40. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +11 -11
  41. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +10 -10
  42. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +10 -10
  43. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +11 -11
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +11 -11
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +11 -11
  46. package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +11 -11
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +9 -0
  48. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +14 -14
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +10 -10
  50. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +10 -10
  51. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +10 -10
  52. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +11 -11
  53. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +11 -11
  54. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +10 -10
  55. package/.docs/organized/changelogs/create-mastra.md +47 -47
  56. package/.docs/organized/changelogs/mastra.md +63 -63
  57. package/.docs/organized/code-examples/agent.md +19 -14
  58. package/.docs/organized/code-examples/heads-up-game.md +5 -5
  59. package/.docs/raw/agents/agent-memory.mdx +86 -125
  60. package/.docs/raw/agents/input-processors.mdx +3 -3
  61. package/.docs/raw/agents/output-processors.mdx +4 -4
  62. package/.docs/raw/agents/overview.mdx +11 -52
  63. package/.docs/raw/agents/using-tools-and-mcp.mdx +34 -29
  64. package/.docs/raw/deployment/serverless-platforms/vercel-deployer.mdx +18 -0
  65. package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +4 -8
  66. package/.docs/raw/getting-started/installation.mdx +2 -3
  67. package/.docs/raw/getting-started/model-providers.mdx +28 -123
  68. package/.docs/raw/memory/semantic-recall.mdx +1 -1
  69. package/.docs/raw/reference/agents/agent.mdx +1 -1
  70. package/.docs/raw/reference/agents/generate.mdx +255 -218
  71. package/.docs/raw/reference/agents/generateLegacy.mdx +528 -0
  72. package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +3 -4
  73. package/.docs/raw/reference/agents/migration-guide.mdx +291 -0
  74. package/.docs/raw/reference/client-js/agents.mdx +14 -8
  75. package/.docs/raw/reference/deployer/vercel.mdx +26 -0
  76. package/.docs/raw/reference/streaming/ChunkType.mdx +4 -4
  77. package/.docs/raw/reference/streaming/agents/MastraModelOutput.mdx +13 -13
  78. package/.docs/raw/reference/streaming/agents/stream.mdx +351 -178
  79. package/.docs/raw/reference/streaming/agents/streamLegacy.mdx +515 -0
  80. package/.docs/raw/reference/{rag → vectors}/astra.mdx +2 -2
  81. package/.docs/raw/reference/{rag → vectors}/chroma.mdx +2 -2
  82. package/.docs/raw/reference/{rag → vectors}/couchbase.mdx +2 -2
  83. package/.docs/raw/reference/{rag → vectors}/lance.mdx +2 -2
  84. package/.docs/raw/reference/{rag → vectors}/libsql.mdx +2 -4
  85. package/.docs/raw/reference/{rag → vectors}/mongodb.mdx +2 -2
  86. package/.docs/raw/reference/{rag → vectors}/opensearch.mdx +2 -2
  87. package/.docs/raw/reference/{rag → vectors}/pg.mdx +2 -2
  88. package/.docs/raw/reference/{rag → vectors}/pinecone.mdx +2 -2
  89. package/.docs/raw/reference/{rag → vectors}/qdrant.mdx +2 -2
  90. package/.docs/raw/reference/{rag → vectors}/s3vectors.mdx +2 -2
  91. package/.docs/raw/reference/{rag → vectors}/turbopuffer.mdx +2 -2
  92. package/.docs/raw/reference/{rag → vectors}/upstash.mdx +2 -2
  93. package/.docs/raw/reference/{rag → vectors}/vectorize.mdx +2 -2
  94. package/.docs/raw/streaming/events.mdx +4 -4
  95. package/.docs/raw/streaming/overview.mdx +9 -11
  96. package/.docs/raw/streaming/tool-streaming.mdx +3 -3
  97. package/.docs/raw/streaming/workflow-streaming.mdx +3 -3
  98. package/CHANGELOG.md +16 -0
  99. package/package.json +5 -5
  100. package/.docs/organized/code-examples/agent-network.md +0 -322
  101. package/.docs/raw/getting-started/model-capability.mdx +0 -11
  102. package/.docs/raw/reference/agents/generateVNext.mdx +0 -557
  103. package/.docs/raw/reference/agents/getDefaultVNextStreamOptions.mdx +0 -67
  104. package/.docs/raw/reference/streaming/agents/streamVNext.mdx +0 -673
@@ -1,673 +0,0 @@
1
- ---
2
- title: "Reference: Agent.streamVNext() (Experimental) | Agents | Mastra Docs"
3
- description: "Documentation for the `Agent.streamVNext()` method in Mastra agents, which enables real-time streaming of responses with enhanced capabilities."
4
- ---
5
-
6
- import { StreamVNextCallout } from "@/components/streamVNext-callout.tsx"
7
-
8
- # Agent.streamVNext() (Experimental)
9
-
10
- <StreamVNextCallout />
11
-
12
- The `.streamVNext()` method enables real-time streaming of responses from an agent with enhanced capabilities and format flexibility. This method accepts messages and optional streaming options, providing a next-generation streaming experience with support for both Mastra's native format and AI SDK v5 compatibility.
13
-
14
- ## Usage example
15
-
16
- ```ts filename="index.ts" copy
17
- // Default Mastra format
18
- const mastraStream = await agent.streamVNext("message for agent");
19
-
20
- // AI SDK v5 compatible format
21
- const aiSdkStream = await agent.streamVNext("message for agent", {
22
- format: 'aisdk'
23
- });
24
- ```
25
-
26
- ## Parameters
27
-
28
- <PropertiesTable
29
- content={[
30
- {
31
- name: "messages",
32
- type: "string | string[] | CoreMessage[] | AiMessageType[] | UIMessageWithMetadata[]",
33
- description: "The messages to send to the agent. Can be a single string, array of strings, or structured message objects.",
34
- },
35
- {
36
- name: "options",
37
- type: "AgentExecutionOptions<Output, StructuredOutput, Format>",
38
- isOptional: true,
39
- description: "Optional configuration for the streaming process.",
40
- },
41
- ]}
42
- />
43
-
44
- ### Options
45
-
46
- <PropertiesTable
47
- content={[
48
- {
49
- name: "format",
50
- type: "'mastra' | 'aisdk'",
51
- isOptional: true,
52
- defaultValue: "'mastra'",
53
- description: "Determines the output stream format. Use 'mastra' for Mastra's native format (default) or 'aisdk' for AI SDK v5 compatibility.",
54
- },
55
- {
56
- name: "maxSteps",
57
- type: "number",
58
- isOptional: true,
59
- description: "Maximum number of steps to run during execution.",
60
- },
61
- {
62
- name: "scorers",
63
- type: "MastraScorers | Record<string, { scorer: MastraScorer['name']; sampling?: ScoringSamplingConfig }>",
64
- isOptional: true,
65
- description: "Evaluation scorers to run on the execution results.",
66
- properties: [
67
- {
68
- parameters: [{
69
- name: "scorer",
70
- type: "string",
71
- isOptional: false,
72
- description: "Name of the scorer to use."
73
- }]
74
- },
75
- {
76
- parameters: [{
77
- name: "sampling",
78
- type: "ScoringSamplingConfig",
79
- isOptional: true,
80
- description: "Sampling configuration for the scorer.",
81
- properties: [
82
- {
83
- parameters: [{
84
- name: "type",
85
- type: "'none' | 'ratio'",
86
- isOptional: false,
87
- description: "Type of sampling strategy. Use 'none' to disable sampling or 'ratio' for percentage-based sampling."
88
- }]
89
- },
90
- {
91
- parameters: [{
92
- name: "rate",
93
- type: "number",
94
- isOptional: true,
95
- description: "Sampling rate (0-1). Required when type is 'ratio'."
96
- }]
97
- }
98
- ]
99
- }]
100
- }
101
- ]
102
- },
103
- {
104
- name: "tracingContext",
105
- type: "TracingContext",
106
- isOptional: true,
107
- description: "AI tracing context for span hierarchy and metadata.",
108
- properties: [
109
- {
110
- parameters: [{
111
- name: "currentSpan",
112
- type: "AISpan",
113
- isOptional: true,
114
- description: "Current AI span for creating child spans and adding metadata."
115
- }]
116
- }
117
- ]
118
- },
119
- {
120
- name: "tracingOptions",
121
- type: "TracingOptions",
122
- isOptional: true,
123
- description: "Options for AI tracing configuration.",
124
- properties: [
125
- {
126
- parameters: [{
127
- name: "metadata",
128
- type: "Record<string, any>",
129
- isOptional: true,
130
- description: "Metadata to add to the root trace span."
131
- }]
132
- }
133
- ]
134
- },
135
- {
136
- name: "returnScorerData",
137
- type: "boolean",
138
- isOptional: true,
139
- description: "Whether to return detailed scoring data in the response.",
140
- },
141
- {
142
- name: "onChunk",
143
- type: "(chunk: ChunkType) => Promise<void> | void",
144
- isOptional: true,
145
- description: "Callback function called for each chunk during streaming.",
146
- },
147
- {
148
- name: "onError",
149
- type: "({ error }: { error: Error | string }) => Promise<void> | void",
150
- isOptional: true,
151
- description: "Callback function called when an error occurs during streaming.",
152
- },
153
- {
154
- name: "onAbort",
155
- type: "(event: any) => Promise<void> | void",
156
- isOptional: true,
157
- description: "Callback function called when the stream is aborted.",
158
- },
159
- {
160
- name: "abortSignal",
161
- type: "AbortSignal",
162
- isOptional: true,
163
- description: "Signal object that allows you to abort the agent's execution. When the signal is aborted, all ongoing operations will be terminated.",
164
- },
165
- {
166
- name: "activeTools",
167
- type: "Array<keyof ToolSet> | undefined",
168
- isOptional: true,
169
- description: "Array of active tool names that can be used during execution.",
170
- },
171
- {
172
- name: "prepareStep",
173
- type: "PrepareStepFunction<any>",
174
- isOptional: true,
175
- description: "Callback function called before each step of multi-step execution.",
176
- },
177
- {
178
- name: "context",
179
- type: "ModelMessage[]",
180
- isOptional: true,
181
- description: "Additional context messages to provide to the agent.",
182
- },
183
- {
184
- name: "structuredOutput",
185
- type: "StructuredOutputOptions<S extends ZodTypeAny = ZodTypeAny>",
186
- isOptional: true,
187
- description: "Enables structured output generation with better developer experience. Automatically creates and uses a StructuredOutputProcessor internally.",
188
- properties: [
189
- {
190
- parameters: [{
191
- name: "schema",
192
- type: "z.ZodSchema<S>",
193
- isOptional: false,
194
- description: "Zod schema to validate the output against."
195
- }]
196
- },
197
- {
198
- parameters: [{
199
- name: "model",
200
- type: "MastraLanguageModel",
201
- isOptional: true,
202
- description: "Model to use for the internal structuring agent. If not provided, falls back to the agent's model."
203
- }]
204
- },
205
- {
206
- parameters: [{
207
- name: "errorStrategy",
208
- type: "'strict' | 'warn' | 'fallback'",
209
- isOptional: true,
210
- description: "Strategy when parsing or validation fails. Defaults to 'strict'."
211
- }]
212
- },
213
- {
214
- parameters: [{
215
- name: "fallbackValue",
216
- type: "<S extends ZodTypeAny>",
217
- isOptional: true,
218
- description: "Fallback value when errorStrategy is 'fallback'."
219
- }]
220
- },
221
- {
222
- parameters: [{
223
- name: "instructions",
224
- type: "string",
225
- isOptional: true,
226
- description: "Custom instructions for the structuring agent."
227
- }]
228
- }
229
- ]
230
- },
231
- {
232
- name: "outputProcessors",
233
- type: "Processor[]",
234
- isOptional: true,
235
- description: "Overrides the output processors set on the agent. Output processors that can modify or validate messages from the agent before they are returned to the user. Must implement either (or both) of the `processOutputResult` and `processOutputStream` functions.",
236
- },
237
- {
238
- name: "inputProcessors",
239
- type: "Processor[]",
240
- isOptional: true,
241
- description: "Overrides the input processors set on the agent. Input processors that can modify or validate messages before they are processed by the agent. Must implement the `processInput` function.",
242
- },
243
- {
244
- name: "instructions",
245
- type: "string",
246
- isOptional: true,
247
- description:
248
- "Custom instructions that override the agent's default instructions for this specific generation. Useful for dynamically modifying agent behavior without creating a new agent instance.",
249
- },
250
- {
251
- name: "system",
252
- type: "string | string[] | CoreSystemMessage | SystemModelMessage | CoreSystemMessage[] | SystemModelMessage[]",
253
- isOptional: true,
254
- description: "Custom system message(s) to include in the prompt. Can be a single string, message object, or array of either. System messages provide additional context or behavior instructions that supplement the agent's main instructions.",
255
- },
256
- {
257
- name: "output",
258
- type: "Zod schema | JsonSchema7",
259
- isOptional: true,
260
- description:
261
- "**Deprecated.** Use structuredOutput with maxSteps:1 to achieve the same thing. Defines the expected structure of the output. Can be a JSON Schema object or a Zod schema.",
262
- },
263
- {
264
- name: "memory",
265
- type: "object",
266
- isOptional: true,
267
- description: "Configuration for memory. This is the preferred way to manage memory.",
268
- properties: [
269
- {
270
- parameters: [{
271
- name: "thread",
272
- type: "string | { id: string; metadata?: Record<string, any>, title?: string }",
273
- isOptional: false,
274
- description: "The conversation thread, as a string ID or an object with an `id` and optional `metadata`."
275
- }]
276
- },
277
- {
278
- parameters: [{
279
- name: "resource",
280
- type: "string",
281
- isOptional: false,
282
- description: "Identifier for the user or resource associated with the thread."
283
- }]
284
- },
285
- {
286
- parameters: [{
287
- name: "options",
288
- type: "MemoryConfig",
289
- isOptional: true,
290
- description: "Configuration for memory behavior, like message history and semantic recall."
291
- }]
292
- }
293
- ]
294
- },
295
- {
296
- name: "onFinish",
297
- type: "StreamTextOnFinishCallback<any> | StreamObjectOnFinishCallback<OUTPUT>",
298
- isOptional: true,
299
- description:
300
- "Callback function called when streaming completes. Receives the final result.",
301
- },
302
- {
303
- name: "onStepFinish",
304
- type: "StreamTextOnStepFinishCallback<any> | never",
305
- isOptional: true,
306
- description:
307
- "Callback function called after each execution step. Receives step details as a JSON string. Unavailable for structured output",
308
- },
309
- {
310
- name: "resourceId",
311
- type: "string",
312
- isOptional: true,
313
- description:
314
- "**Deprecated.** Use `memory.resource` instead. Identifier for the user or resource interacting with the agent. Must be provided if threadId is provided.",
315
- },
316
- {
317
- name: "telemetry",
318
- type: "TelemetrySettings",
319
- isOptional: true,
320
- description:
321
- "Settings for OTLP telemetry collection during streaming (not AI tracing).",
322
- properties: [
323
- {
324
- parameters: [{
325
- name: "isEnabled",
326
- type: "boolean",
327
- isOptional: true,
328
- description: "Enable or disable telemetry. Disabled by default while experimental."
329
- }]
330
- },
331
- {
332
- parameters: [{
333
- name: "recordInputs",
334
- type: "boolean",
335
- isOptional: true,
336
- description: "Enable or disable input recording. Enabled by default. You might want to disable input recording to avoid recording sensitive information."
337
- }]
338
- },
339
- {
340
- parameters: [{
341
- name: "recordOutputs",
342
- type: "boolean",
343
- isOptional: true,
344
- description: "Enable or disable output recording. Enabled by default. You might want to disable output recording to avoid recording sensitive information."
345
- }]
346
- },
347
- {
348
- parameters: [{
349
- name: "functionId",
350
- type: "string",
351
- isOptional: true,
352
- description: "Identifier for this function. Used to group telemetry data by function."
353
- }]
354
- }
355
- ]
356
- },
357
- {
358
- name: "modelSettings",
359
- type: "CallSettings",
360
- isOptional: true,
361
- description:
362
- "Model-specific settings like temperature, maxTokens, topP, etc. These are passed to the underlying language model.",
363
- properties: [
364
- {
365
- parameters: [{
366
- name: "temperature",
367
- type: "number",
368
- isOptional: true,
369
- description: "Controls randomness in the model's output. Higher values (e.g., 0.8) make the output more random, lower values (e.g., 0.2) make it more focused and deterministic."
370
- }]
371
- },
372
- {
373
- parameters: [{
374
- name: "maxRetries",
375
- type: "number",
376
- isOptional: true,
377
- description: "Maximum number of retries for failed requests."
378
- }]
379
- },
380
- {
381
- parameters: [{
382
- name: "topP",
383
- type: "number",
384
- isOptional: true,
385
- description: "Nucleus sampling. This is a number between 0 and 1. It is recommended to set either temperature or topP, but not both."
386
- }]
387
- },
388
- {
389
- parameters: [{
390
- name: "topK",
391
- type: "number",
392
- isOptional: true,
393
- description: "Only sample from the top K options for each subsequent token. Used to remove 'long tail' low probability responses."
394
- }]
395
- },
396
- {
397
- parameters: [{
398
- name: "presencePenalty",
399
- type: "number",
400
- isOptional: true,
401
- description: "Presence penalty setting. It affects the likelihood of the model to repeat information that is already in the prompt. A number between -1 (increase repetition) and 1 (maximum penalty, decrease repetition)."
402
- }]
403
- },
404
- {
405
- parameters: [{
406
- name: "frequencyPenalty",
407
- type: "number",
408
- isOptional: true,
409
- description: "Frequency penalty setting. It affects the likelihood of the model to repeatedly use the same words or phrases. A number between -1 (increase repetition) and 1 (maximum penalty, decrease repetition)."
410
- }]
411
- },
412
- {
413
- parameters: [{
414
- name: "stopSequences",
415
- type: "string[]",
416
- isOptional: true,
417
- description: "Stop sequences. If set, the model will stop generating text when one of the stop sequences is generated."
418
- }]
419
- },
420
- ]
421
- },
422
- {
423
- name: "threadId",
424
- type: "string",
425
- isOptional: true,
426
- description:
427
- "**Deprecated.** Use `memory.thread` instead. Identifier for the conversation thread. Allows for maintaining context across multiple interactions. Must be provided if resourceId is provided.",
428
- },
429
- {
430
- name: "toolChoice",
431
- type: "'auto' | 'none' | 'required' | { type: 'tool'; toolName: string }",
432
- isOptional: true,
433
- defaultValue: "'auto'",
434
- description: "Controls how the agent uses tools during streaming.",
435
- properties: [
436
- {
437
- parameters: [{
438
- name: "'auto'",
439
- type: "string",
440
- description: "Let the model decide whether to use tools (default)."
441
- }]
442
- },
443
- {
444
- parameters: [{
445
- name: "'none'",
446
- type: "string",
447
- description: "Do not use any tools."
448
- }]
449
- },
450
- {
451
- parameters: [{
452
- name: "'required'",
453
- type: "string",
454
- description: "Require the model to use at least one tool."
455
- }]
456
- },
457
- {
458
- parameters: [{
459
- name: "{ type: 'tool'; toolName: string }",
460
- type: "object",
461
- description: "Require the model to use a specific tool by name."
462
- }]
463
- }
464
- ]
465
- },
466
- {
467
- name: "toolsets",
468
- type: "ToolsetsInput",
469
- isOptional: true,
470
- description:
471
- "Additional toolsets to make available to the agent during streaming.",
472
- },
473
- {
474
- name: "clientTools",
475
- type: "ToolsInput",
476
- isOptional: true,
477
- description:
478
- "Tools that are executed on the 'client' side of the request. These tools do not have execute functions in the definition.",
479
- },
480
- {
481
- name: "savePerStep",
482
- type: "boolean",
483
- isOptional: true,
484
- description: "Save messages incrementally after each stream step completes (default: false).",
485
- },
486
- {
487
- name: "providerOptions",
488
- type: "Record<string, Record<string, JSONValue>>",
489
- isOptional: true,
490
- description: "Additional provider-specific options that are passed through to the underlying LLM provider. The structure is `{ providerName: { optionKey: value } }`. For example: `{ openai: { reasoningEffort: 'high' }, anthropic: { maxTokens: 1000 } }`.",
491
- properties: [
492
- {
493
- parameters: [{
494
- name: "openai",
495
- type: "Record<string, JSONValue>",
496
- isOptional: true,
497
- description: "OpenAI-specific options. Example: `{ reasoningEffort: 'high' }`"
498
- }]
499
- },
500
- {
501
- parameters: [{
502
- name: "anthropic",
503
- type: "Record<string, JSONValue>",
504
- isOptional: true,
505
- description: "Anthropic-specific options. Example: `{ maxTokens: 1000 }`"
506
- }]
507
- },
508
- {
509
- parameters: [{
510
- name: "google",
511
- type: "Record<string, JSONValue>",
512
- isOptional: true,
513
- description: "Google-specific options. Example: `{ safetySettings: [...] }`"
514
- }]
515
- },
516
- {
517
- parameters: [{
518
- name: "[providerName]",
519
- type: "Record<string, JSONValue>",
520
- isOptional: true,
521
- description: "Other provider-specific options. The key is the provider name and the value is a record of provider-specific options."
522
- }]
523
- }
524
- ]
525
- },
526
- {
527
- name: "runId",
528
- type: "string",
529
- isOptional: true,
530
- description: "Unique ID for this generation run. Useful for tracking and debugging purposes.",
531
- },
532
- {
533
- name: "runtimeContext",
534
- type: "RuntimeContext",
535
- isOptional: true,
536
- description: "Runtime context for dependency injection and contextual information.",
537
- },
538
- {
539
- name: "stopWhen",
540
- type: "StopCondition | StopCondition[]",
541
- isOptional: true,
542
- description: "Condition(s) that determine when to stop the agent's execution. Can be a single condition or array of conditions.",
543
- },
544
- ]}
545
- />
546
-
547
- ## Returns
548
-
549
- <PropertiesTable
550
- content={[
551
- {
552
- name: "stream",
553
- type: "MastraModelOutput<Output> | AISDKV5OutputStream<Output>",
554
- description: "Returns a streaming interface based on the format parameter. When format is 'mastra' (default), returns MastraModelOutput with traceId property. When format is 'aisdk', returns AISDKV5OutputStream for AI SDK v5 compatibility.",
555
- },
556
- {
557
- name: "traceId",
558
- type: "string",
559
- isOptional: true,
560
- description: "The trace ID associated with this execution when AI tracing is enabled. Available via stream.traceId for Mastra format.",
561
- },
562
- ]}
563
- />
564
-
565
- ## Extended usage example
566
-
567
- ### Mastra Format (Default)
568
-
569
- ```ts filename="index.ts" showLineNumbers copy
570
- import { stepCountIs } from 'ai-v5';
571
-
572
- const stream = await agent.streamVNext("Tell me a story", {
573
- stopWhen: stepCountIs(3), // Stop after 3 steps
574
- modelSettings: {
575
- temperature: 0.7,
576
- },
577
- });
578
-
579
- // Access text stream
580
- for await (const chunk of stream.textStream) {
581
- console.log(chunk);
582
- }
583
-
584
- // Get full text after streaming
585
- const fullText = await stream.text;
586
- ```
587
-
588
- ### AI SDK v5 Format
589
-
590
- ```ts filename="index.ts" showLineNumbers copy
591
- import { stepCountIs } from 'ai-v5';
592
-
593
- const stream = await agent.streamVNext("Tell me a story", {
594
- format: 'aisdk',
595
- stopWhen: stepCountIs(3), // Stop after 3 steps
596
- modelSettings: {
597
- temperature: 0.7,
598
- },
599
- });
600
-
601
- // Use with AI SDK v5 compatible interfaces
602
- for await (const part of stream.fullStream) {
603
- if (part.type === 'text-delta') {
604
- console.log(part.text);
605
- }
606
- }
607
-
608
- // In an API route for frontend integration
609
- return stream.toUIMessageStreamResponse();
610
- ```
611
-
612
- ### Using Callbacks
613
-
614
- All callback functions are now available as top-level properties for a cleaner API experience.
615
-
616
- ```ts filename="index.ts" showLineNumbers copy
617
- const stream = await agent.streamVNext("Tell me a story", {
618
- onFinish: (result) => {
619
- console.log('Streaming finished:', result);
620
- },
621
- onStepFinish: (step) => {
622
- console.log('Step completed:', step);
623
- },
624
- onChunk: (chunk) => {
625
- console.log('Received chunk:', chunk);
626
- },
627
- onError: ({ error }) => {
628
- console.error('Streaming error:', error);
629
- },
630
- onAbort: (event) => {
631
- console.log('Stream aborted:', event);
632
- },
633
- });
634
-
635
- // Process the stream
636
- for await (const chunk of stream.textStream) {
637
- console.log(chunk);
638
- }
639
- ```
640
-
641
- ### Advanced Example with Options
642
-
643
- ```ts filename="index.ts" showLineNumbers copy
644
- import { z } from "zod";
645
- import { stepCountIs } from 'ai-v5';
646
-
647
- await agent.streamVNext("message for agent", {
648
- format: 'aisdk', // Enable AI SDK v5 compatibility
649
- stopWhen: stepCountIs(3), // Stop after 3 steps
650
- modelSettings: {
651
- temperature: 0.7,
652
- },
653
- memory: {
654
- thread: "user-123",
655
- resource: "test-app"
656
- },
657
- toolChoice: "auto",
658
- // Structured output with better DX
659
- structuredOutput: {
660
- schema: z.object({
661
- sentiment: z.enum(['positive', 'negative', 'neutral']),
662
- confidence: z.number(),
663
- }),
664
- model: openai("gpt-4o-mini"),
665
- errorStrategy: 'warn',
666
- },
667
- // Output processors for streaming response validation
668
- outputProcessors: [
669
- new ModerationProcessor({ model: openai("gpt-4.1-nano") }),
670
- new BatchPartsProcessor({ maxBatchSize: 3, maxWaitTime: 100 }),
671
- ],
672
- });
673
- ```