@mastra/mcp-docs-server 0.13.10 → 0.13.11-alpha.1
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/organized/changelogs/%40internal%2Fstorage-test-utils.md +9 -9
- package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +2 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +30 -30
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +30 -30
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Frag.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +7 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +26 -26
- package/.docs/organized/changelogs/create-mastra.md +11 -11
- package/.docs/organized/changelogs/mastra.md +31 -31
- package/.docs/organized/code-examples/agent-network.md +4 -3
- package/.docs/organized/code-examples/agent.md +33 -2
- package/.docs/raw/agents/overview.mdx +21 -1
- package/.docs/raw/getting-started/mcp-docs-server.mdx +2 -2
- package/.docs/raw/rag/chunking-and-embedding.mdx +11 -0
- package/.docs/raw/reference/agents/agent.mdx +64 -38
- package/.docs/raw/reference/agents/generate.mdx +206 -202
- package/.docs/raw/reference/agents/getAgent.mdx +23 -38
- package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +62 -0
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +62 -0
- package/.docs/raw/reference/agents/getDefaultVNextStreamOptions.mdx +62 -0
- package/.docs/raw/reference/agents/getDescription.mdx +30 -0
- package/.docs/raw/reference/agents/getInstructions.mdx +36 -73
- package/.docs/raw/reference/agents/getLLM.mdx +69 -0
- package/.docs/raw/reference/agents/getMemory.mdx +42 -119
- package/.docs/raw/reference/agents/getModel.mdx +36 -75
- package/.docs/raw/reference/agents/getScorers.mdx +62 -0
- package/.docs/raw/reference/agents/getTools.mdx +36 -128
- package/.docs/raw/reference/agents/getVoice.mdx +36 -83
- package/.docs/raw/reference/agents/getWorkflows.mdx +37 -74
- package/.docs/raw/reference/agents/stream.mdx +263 -226
- package/.docs/raw/reference/agents/streamVNext.mdx +208 -402
- package/.docs/raw/reference/cli/build.mdx +1 -0
- package/.docs/raw/reference/rag/chunk.mdx +51 -2
- package/.docs/raw/reference/scorers/answer-relevancy.mdx +6 -6
- package/.docs/raw/reference/scorers/bias.mdx +6 -6
- package/.docs/raw/reference/scorers/completeness.mdx +2 -2
- package/.docs/raw/reference/scorers/content-similarity.mdx +1 -1
- package/.docs/raw/reference/scorers/create-scorer.mdx +445 -0
- package/.docs/raw/reference/scorers/faithfulness.mdx +6 -6
- package/.docs/raw/reference/scorers/hallucination.mdx +6 -6
- package/.docs/raw/reference/scorers/keyword-coverage.mdx +2 -2
- package/.docs/raw/reference/scorers/mastra-scorer.mdx +116 -158
- package/.docs/raw/reference/scorers/toxicity.mdx +2 -2
- package/.docs/raw/scorers/custom-scorers.mdx +166 -268
- package/.docs/raw/scorers/overview.mdx +21 -13
- package/.docs/raw/server-db/local-dev-playground.mdx +3 -3
- package/package.json +5 -5
- package/.docs/raw/reference/agents/createTool.mdx +0 -241
- package/.docs/raw/reference/scorers/custom-code-scorer.mdx +0 -155
- package/.docs/raw/reference/scorers/llm-scorer.mdx +0 -210
|
@@ -1,34 +1,51 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "Reference:
|
|
3
|
-
description: Documentation for the `.streamVNext()` method in Mastra agents, which enables real-time streaming of responses.
|
|
2
|
+
title: "Reference: streamVNext() | Agents | Mastra Docs"
|
|
3
|
+
description: "Documentation for the `.streamVNext()` method in Mastra agents, which enables real-time streaming of responses with enhanced capabilities."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# streamVNext()
|
|
7
7
|
|
|
8
|
-
The
|
|
8
|
+
The `.streamVNext()` method enables real-time streaming of responses from an agent with enhanced capabilities. This method accepts messages and optional streaming options, providing a next-generation streaming experience.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Usage example
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const response = await agent.streamVNext("message for agent");
|
|
14
|
+
```
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
## Parameters
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
<PropertiesTable
|
|
19
|
+
content={[
|
|
20
|
+
{
|
|
21
|
+
name: "messages",
|
|
22
|
+
type: "string | string[] | CoreMessage[] | AiMessageType[] | UIMessageWithMetadata[]",
|
|
23
|
+
description: "The messages to send to the agent. Can be a single string, array of strings, or structured message objects.",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "options",
|
|
27
|
+
type: "AgentVNextStreamOptions<Output, StructuredOutput>",
|
|
28
|
+
isOptional: true,
|
|
29
|
+
description: "Optional configuration for the streaming process.",
|
|
30
|
+
},
|
|
31
|
+
]}
|
|
32
|
+
/>
|
|
19
33
|
|
|
20
|
-
|
|
34
|
+
## Extended usage example
|
|
21
35
|
|
|
22
|
-
```typescript
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
```typescript showLineNumbers copy
|
|
37
|
+
const response = await agent.streamVNext("message for agent", {
|
|
38
|
+
temperature: 0.7,
|
|
39
|
+
maxSteps: 3,
|
|
40
|
+
memory: {
|
|
41
|
+
thread: "user-123",
|
|
42
|
+
resource: "test-app"
|
|
43
|
+
},
|
|
44
|
+
toolChoice: "auto"
|
|
45
|
+
});
|
|
27
46
|
```
|
|
28
47
|
|
|
29
|
-
###
|
|
30
|
-
|
|
31
|
-
An optional object that can include configuration for output structure, memory management, tool usage, telemetry, and more.
|
|
48
|
+
### Options parameters
|
|
32
49
|
|
|
33
50
|
<PropertiesTable
|
|
34
51
|
content={[
|
|
@@ -59,6 +76,13 @@ An optional object that can include configuration for output structure, memory m
|
|
|
59
76
|
description:
|
|
60
77
|
"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.",
|
|
61
78
|
},
|
|
79
|
+
{
|
|
80
|
+
name: "output",
|
|
81
|
+
type: "Zod schema | JsonSchema7",
|
|
82
|
+
isOptional: true,
|
|
83
|
+
description:
|
|
84
|
+
"Defines the expected structure of the output. Can be a JSON Schema object or a Zod schema.",
|
|
85
|
+
},
|
|
62
86
|
{
|
|
63
87
|
name: "memory",
|
|
64
88
|
type: "object",
|
|
@@ -86,7 +110,7 @@ An optional object that can include configuration for output structure, memory m
|
|
|
86
110
|
name: "options",
|
|
87
111
|
type: "MemoryConfig",
|
|
88
112
|
isOptional: true,
|
|
89
|
-
description: "Configuration for memory behavior, like message history and semantic recall.
|
|
113
|
+
description: "Configuration for memory behavior, like message history and semantic recall."
|
|
90
114
|
}]
|
|
91
115
|
}
|
|
92
116
|
]
|
|
@@ -96,7 +120,7 @@ An optional object that can include configuration for output structure, memory m
|
|
|
96
120
|
type: "number",
|
|
97
121
|
isOptional: true,
|
|
98
122
|
defaultValue: "5",
|
|
99
|
-
description: "Maximum number of steps allowed
|
|
123
|
+
description: "Maximum number of execution steps allowed.",
|
|
100
124
|
},
|
|
101
125
|
{
|
|
102
126
|
name: "maxRetries",
|
|
@@ -110,34 +134,69 @@ An optional object that can include configuration for output structure, memory m
|
|
|
110
134
|
type: "MemoryConfig",
|
|
111
135
|
isOptional: true,
|
|
112
136
|
description:
|
|
113
|
-
"**Deprecated.** Use `memory.options` instead. Configuration options for memory management.
|
|
137
|
+
"**Deprecated.** Use `memory.options` instead. Configuration options for memory management.",
|
|
114
138
|
},
|
|
115
139
|
{
|
|
116
140
|
name: "onFinish",
|
|
117
|
-
type: "StreamTextOnFinishCallback | StreamObjectOnFinishCallback",
|
|
141
|
+
type: "StreamTextOnFinishCallback<any> | StreamObjectOnFinishCallback<OUTPUT>",
|
|
118
142
|
isOptional: true,
|
|
119
|
-
description:
|
|
143
|
+
description:
|
|
144
|
+
"Callback function called when streaming completes. Receives the final result.",
|
|
120
145
|
},
|
|
121
146
|
{
|
|
122
147
|
name: "onStepFinish",
|
|
123
|
-
type: "
|
|
148
|
+
type: "StreamTextOnStepFinishCallback<any> | never",
|
|
124
149
|
isOptional: true,
|
|
125
150
|
description:
|
|
126
|
-
"Callback function called after each step
|
|
151
|
+
"Callback function called after each execution step. Receives step details as a JSON string. Unavailable for structured output",
|
|
127
152
|
},
|
|
128
153
|
{
|
|
129
|
-
name: "
|
|
130
|
-
type: "
|
|
154
|
+
name: "resourceId",
|
|
155
|
+
type: "string",
|
|
131
156
|
isOptional: true,
|
|
132
157
|
description:
|
|
133
|
-
"
|
|
158
|
+
"**Deprecated.** Use `memory.resource` instead. Identifier for the user or resource interacting with the agent. Must be provided if threadId is provided.",
|
|
134
159
|
},
|
|
135
160
|
{
|
|
136
161
|
name: "telemetry",
|
|
137
162
|
type: "TelemetrySettings",
|
|
138
163
|
isOptional: true,
|
|
139
164
|
description:
|
|
140
|
-
"Settings for telemetry collection during streaming.
|
|
165
|
+
"Settings for telemetry collection during streaming.",
|
|
166
|
+
properties: [
|
|
167
|
+
{
|
|
168
|
+
parameters: [{
|
|
169
|
+
name: "isEnabled",
|
|
170
|
+
type: "boolean",
|
|
171
|
+
isOptional: true,
|
|
172
|
+
description: "Enable or disable telemetry. Disabled by default while experimental."
|
|
173
|
+
}]
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
parameters: [{
|
|
177
|
+
name: "recordInputs",
|
|
178
|
+
type: "boolean",
|
|
179
|
+
isOptional: true,
|
|
180
|
+
description: "Enable or disable input recording. Enabled by default. You might want to disable input recording to avoid recording sensitive information."
|
|
181
|
+
}]
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
parameters: [{
|
|
185
|
+
name: "recordOutputs",
|
|
186
|
+
type: "boolean",
|
|
187
|
+
isOptional: true,
|
|
188
|
+
description: "Enable or disable output recording. Enabled by default. You might want to disable output recording to avoid recording sensitive information."
|
|
189
|
+
}]
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
parameters: [{
|
|
193
|
+
name: "functionId",
|
|
194
|
+
type: "string",
|
|
195
|
+
isOptional: true,
|
|
196
|
+
description: "Identifier for this function. Used to group telemetry data by function."
|
|
197
|
+
}]
|
|
198
|
+
}
|
|
199
|
+
]
|
|
141
200
|
},
|
|
142
201
|
{
|
|
143
202
|
name: "temperature",
|
|
@@ -146,19 +205,56 @@ An optional object that can include configuration for output structure, memory m
|
|
|
146
205
|
description:
|
|
147
206
|
"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.",
|
|
148
207
|
},
|
|
208
|
+
{
|
|
209
|
+
name: "threadId",
|
|
210
|
+
type: "string",
|
|
211
|
+
isOptional: true,
|
|
212
|
+
description:
|
|
213
|
+
"**Deprecated.** Use `memory.thread` instead. Identifier for the conversation thread. Allows for maintaining context across multiple interactions. Must be provided if resourceId is provided.",
|
|
214
|
+
},
|
|
149
215
|
{
|
|
150
216
|
name: "toolChoice",
|
|
151
217
|
type: "'auto' | 'none' | 'required' | { type: 'tool'; toolName: string }",
|
|
152
218
|
isOptional: true,
|
|
153
219
|
defaultValue: "'auto'",
|
|
154
220
|
description: "Controls how the agent uses tools during streaming.",
|
|
221
|
+
properties: [
|
|
222
|
+
{
|
|
223
|
+
parameters: [{
|
|
224
|
+
name: "'auto'",
|
|
225
|
+
type: "string",
|
|
226
|
+
description: "Let the model decide whether to use tools (default)."
|
|
227
|
+
}]
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
parameters: [{
|
|
231
|
+
name: "'none'",
|
|
232
|
+
type: "string",
|
|
233
|
+
description: "Do not use any tools."
|
|
234
|
+
}]
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
parameters: [{
|
|
238
|
+
name: "'required'",
|
|
239
|
+
type: "string",
|
|
240
|
+
description: "Require the model to use at least one tool."
|
|
241
|
+
}]
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
parameters: [{
|
|
245
|
+
name: "{ type: 'tool'; toolName: string }",
|
|
246
|
+
type: "object",
|
|
247
|
+
description: "Require the model to use a specific tool by name."
|
|
248
|
+
}]
|
|
249
|
+
}
|
|
250
|
+
]
|
|
155
251
|
},
|
|
156
252
|
{
|
|
157
253
|
name: "toolsets",
|
|
158
254
|
type: "ToolsetsInput",
|
|
159
255
|
isOptional: true,
|
|
160
256
|
description:
|
|
161
|
-
"Additional toolsets to make available to the agent during
|
|
257
|
+
"Additional toolsets to make available to the agent during streaming.",
|
|
162
258
|
},
|
|
163
259
|
{
|
|
164
260
|
name: "clientTools",
|
|
@@ -167,432 +263,142 @@ An optional object that can include configuration for output structure, memory m
|
|
|
167
263
|
description:
|
|
168
264
|
"Tools that are executed on the 'client' side of the request. These tools do not have execute functions in the definition.",
|
|
169
265
|
},
|
|
170
|
-
]}
|
|
171
|
-
/>
|
|
172
|
-
|
|
173
|
-
#### MemoryConfig
|
|
174
|
-
|
|
175
|
-
Configuration options for memory management:
|
|
176
|
-
|
|
177
|
-
<PropertiesTable
|
|
178
|
-
content={[
|
|
179
266
|
{
|
|
180
|
-
name: "
|
|
181
|
-
type: "
|
|
267
|
+
name: "savePerStep",
|
|
268
|
+
type: "boolean",
|
|
182
269
|
isOptional: true,
|
|
183
|
-
description:
|
|
184
|
-
"Number of most recent messages to include in context. Set to false to disable.",
|
|
270
|
+
description: "Save messages incrementally after each stream step completes (default: false).",
|
|
185
271
|
},
|
|
186
272
|
{
|
|
187
|
-
name: "
|
|
188
|
-
type: "
|
|
273
|
+
name: "providerOptions",
|
|
274
|
+
type: "Record<string, Record<string, JSONValue>>",
|
|
189
275
|
isOptional: true,
|
|
190
|
-
description:
|
|
191
|
-
"Configuration for semantic memory recall. Can be boolean or detailed config.",
|
|
276
|
+
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 } }`.",
|
|
192
277
|
properties: [
|
|
193
278
|
{
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
description:
|
|
201
|
-
"Number of most semantically similar messages to retrieve.",
|
|
202
|
-
},
|
|
203
|
-
],
|
|
279
|
+
parameters: [{
|
|
280
|
+
name: "openai",
|
|
281
|
+
type: "Record<string, JSONValue>",
|
|
282
|
+
isOptional: true,
|
|
283
|
+
description: "OpenAI-specific options. Example: `{ reasoningEffort: 'high' }`"
|
|
284
|
+
}]
|
|
204
285
|
},
|
|
205
286
|
{
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
description:
|
|
213
|
-
"Range of messages to consider for semantic search. Can be a single number or before/after configuration.",
|
|
214
|
-
},
|
|
215
|
-
],
|
|
287
|
+
parameters: [{
|
|
288
|
+
name: "anthropic",
|
|
289
|
+
type: "Record<string, JSONValue>",
|
|
290
|
+
isOptional: true,
|
|
291
|
+
description: "Anthropic-specific options. Example: `{ maxTokens: 1000 }`"
|
|
292
|
+
}]
|
|
216
293
|
},
|
|
217
|
-
],
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
name: "workingMemory",
|
|
221
|
-
type: "object",
|
|
222
|
-
isOptional: true,
|
|
223
|
-
description: "Configuration for working memory.",
|
|
224
|
-
properties: [
|
|
225
294
|
{
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
description: "Whether to enable working memory.",
|
|
233
|
-
},
|
|
234
|
-
],
|
|
295
|
+
parameters: [{
|
|
296
|
+
name: "google",
|
|
297
|
+
type: "Record<string, JSONValue>",
|
|
298
|
+
isOptional: true,
|
|
299
|
+
description: "Google-specific options. Example: `{ safetySettings: [...] }`"
|
|
300
|
+
}]
|
|
235
301
|
},
|
|
236
302
|
{
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
],
|
|
246
|
-
},
|
|
247
|
-
],
|
|
303
|
+
parameters: [{
|
|
304
|
+
name: "[providerName]",
|
|
305
|
+
type: "Record<string, JSONValue>",
|
|
306
|
+
isOptional: true,
|
|
307
|
+
description: "Other provider-specific options. The key is the provider name and the value is a record of provider-specific options."
|
|
308
|
+
}]
|
|
309
|
+
}
|
|
310
|
+
]
|
|
248
311
|
},
|
|
249
312
|
{
|
|
250
|
-
name: "
|
|
251
|
-
type: "
|
|
313
|
+
name: "runId",
|
|
314
|
+
type: "string",
|
|
252
315
|
isOptional: true,
|
|
253
|
-
description: "
|
|
254
|
-
properties: [
|
|
255
|
-
{
|
|
256
|
-
type: "boolean | object",
|
|
257
|
-
parameters: [
|
|
258
|
-
{
|
|
259
|
-
name: "generateTitle",
|
|
260
|
-
type: "boolean | { model: LanguageModelV1 | ((ctx: RuntimeContext) => LanguageModelV1 | Promise<LanguageModelV1>), instructions: string | ((ctx: RuntimeContext) => string | Promise<string>) }",
|
|
261
|
-
isOptional: true,
|
|
262
|
-
description:
|
|
263
|
-
`Controls automatic thread title generation from the user's first message. Can be a boolean to enable/disable using the agent's model, or an object specifying a custom model and/or custom instructions for title generation (useful for cost optimization or title customization).
|
|
264
|
-
Example: { model: openai('gpt-4.1-nano'), instructions: 'Generate a concise title based on the initial user message.' }`,
|
|
265
|
-
},
|
|
266
|
-
],
|
|
267
|
-
},
|
|
268
|
-
],
|
|
316
|
+
description: "Unique ID for this generation run. Useful for tracking and debugging purposes.",
|
|
269
317
|
},
|
|
270
|
-
]}
|
|
271
|
-
/>
|
|
272
|
-
|
|
273
|
-
#### TelemetrySettings
|
|
274
|
-
|
|
275
|
-
Settings for telemetry collection during streaming:
|
|
276
|
-
|
|
277
|
-
<PropertiesTable
|
|
278
|
-
content={[
|
|
279
318
|
{
|
|
280
|
-
name: "
|
|
281
|
-
type: "
|
|
319
|
+
name: "runtimeContext",
|
|
320
|
+
type: "RuntimeContext",
|
|
282
321
|
isOptional: true,
|
|
283
|
-
|
|
284
|
-
description:
|
|
285
|
-
"Enable or disable telemetry. Disabled by default while experimental.",
|
|
322
|
+
description: "Runtime context for dependency injection and contextual information.",
|
|
286
323
|
},
|
|
287
324
|
{
|
|
288
|
-
name: "
|
|
289
|
-
type: "
|
|
325
|
+
name: "experimental_generateMessageId",
|
|
326
|
+
type: "IDGenerator",
|
|
290
327
|
isOptional: true,
|
|
291
|
-
|
|
292
|
-
description:
|
|
293
|
-
"Enable or disable input recording. You might want to disable this to avoid recording sensitive information, reduce data transfers, or increase performance.",
|
|
328
|
+
description: "Generate a unique ID for each message.",
|
|
294
329
|
},
|
|
295
330
|
{
|
|
296
|
-
name: "
|
|
297
|
-
type: "
|
|
331
|
+
name: "maxTokens",
|
|
332
|
+
type: "number",
|
|
298
333
|
isOptional: true,
|
|
299
|
-
|
|
300
|
-
description:
|
|
301
|
-
"Enable or disable output recording. You might want to disable this to avoid recording sensitive information, reduce data transfers, or increase performance.",
|
|
334
|
+
description: "Maximum number of tokens to generate.",
|
|
302
335
|
},
|
|
303
336
|
{
|
|
304
|
-
name: "
|
|
305
|
-
type: "
|
|
337
|
+
name: "topP",
|
|
338
|
+
type: "number",
|
|
306
339
|
isOptional: true,
|
|
307
|
-
description:
|
|
308
|
-
"Identifier for this function. Used to group telemetry data by function.",
|
|
340
|
+
description: "Nucleus sampling. This is a number between 0 and 1. It is recommended to set either `temperature` or `topP`, but not both.",
|
|
309
341
|
},
|
|
310
342
|
{
|
|
311
|
-
name: "
|
|
312
|
-
type: "
|
|
343
|
+
name: "topK",
|
|
344
|
+
type: "number",
|
|
313
345
|
isOptional: true,
|
|
314
|
-
description:
|
|
315
|
-
"Additional information to include in the telemetry data. AttributeValue can be string, number, boolean, array of these types, or null.",
|
|
346
|
+
description: "Only sample from the top K options for each subsequent token. Used to remove 'long tail' low probability responses.",
|
|
316
347
|
},
|
|
317
348
|
{
|
|
318
|
-
name: "
|
|
319
|
-
type: "
|
|
349
|
+
name: "presencePenalty",
|
|
350
|
+
type: "number",
|
|
320
351
|
isOptional: true,
|
|
321
|
-
description:
|
|
322
|
-
"A custom OpenTelemetry tracer instance to use for the telemetry data. See OpenTelemetry documentation for details.",
|
|
323
|
-
},
|
|
324
|
-
]}
|
|
325
|
-
/>
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
## Protocol
|
|
330
|
-
|
|
331
|
-
<PropertiesTable
|
|
332
|
-
content={[
|
|
333
|
-
{
|
|
334
|
-
name: "start",
|
|
335
|
-
type: "object",
|
|
336
|
-
description: "The agent starts",
|
|
337
|
-
isOptional: false,
|
|
338
|
-
properties: [
|
|
339
|
-
{
|
|
340
|
-
type: "object",
|
|
341
|
-
parameters: [
|
|
342
|
-
{
|
|
343
|
-
name: "example",
|
|
344
|
-
type: "{ type: 'start', runId: '1', from: 'AGENT', payload: {} }",
|
|
345
|
-
description: "Example message structure",
|
|
346
|
-
isOptional: false,
|
|
347
|
-
},
|
|
348
|
-
],
|
|
349
|
-
},
|
|
350
|
-
],
|
|
352
|
+
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).",
|
|
351
353
|
},
|
|
352
354
|
{
|
|
353
|
-
name: "
|
|
354
|
-
type: "
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
properties: [
|
|
358
|
-
{
|
|
359
|
-
type: "object",
|
|
360
|
-
parameters: [
|
|
361
|
-
{
|
|
362
|
-
name: "example",
|
|
363
|
-
type: "{ type: 'step-start', runId: '1', from: 'AGENT', payload: { messageId: 'uuid', request: { /* Raw request object */ }, warnings: [] } }",
|
|
364
|
-
description: "Example message structure",
|
|
365
|
-
isOptional: false,
|
|
366
|
-
},
|
|
367
|
-
],
|
|
368
|
-
},
|
|
369
|
-
],
|
|
355
|
+
name: "frequencyPenalty",
|
|
356
|
+
type: "number",
|
|
357
|
+
isOptional: true,
|
|
358
|
+
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).",
|
|
370
359
|
},
|
|
371
360
|
{
|
|
372
|
-
name: "
|
|
373
|
-
type: "
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
properties: [
|
|
377
|
-
{
|
|
378
|
-
type: "object",
|
|
379
|
-
parameters: [
|
|
380
|
-
{
|
|
381
|
-
name: "example",
|
|
382
|
-
type: "{ type: 'tool-call', runId: '1', from: 'AGENT', payload: { toolCallId: 'uuid', args: { ... }, toolName: 'my tool' } }",
|
|
383
|
-
description: "Example message structure",
|
|
384
|
-
isOptional: false,
|
|
385
|
-
},
|
|
386
|
-
],
|
|
387
|
-
},
|
|
388
|
-
],
|
|
361
|
+
name: "stopSequences",
|
|
362
|
+
type: "string[]",
|
|
363
|
+
isOptional: true,
|
|
364
|
+
description: "Stop sequences. If set, the model will stop generating text when one of the stop sequences is generated.",
|
|
389
365
|
},
|
|
390
366
|
{
|
|
391
|
-
name: "
|
|
392
|
-
type: "
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
properties: [
|
|
396
|
-
{
|
|
397
|
-
type: "object",
|
|
398
|
-
parameters: [
|
|
399
|
-
{
|
|
400
|
-
name: "example",
|
|
401
|
-
type: "{ type: 'tool-output', runId: '1', from: 'AGENT', payload: { toolName: 'my step', output: { ... }, toolCallId: 'uuid' } }",
|
|
402
|
-
description: "Example message structure",
|
|
403
|
-
isOptional: false,
|
|
404
|
-
},
|
|
405
|
-
],
|
|
406
|
-
},
|
|
407
|
-
],
|
|
367
|
+
name: "seed",
|
|
368
|
+
type: "number",
|
|
369
|
+
isOptional: true,
|
|
370
|
+
description: "The seed (integer) to use for random sampling. If set and supported by the model, calls will generate deterministic results.",
|
|
408
371
|
},
|
|
409
372
|
{
|
|
410
|
-
name: "
|
|
411
|
-
type: "
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
properties: [
|
|
415
|
-
{
|
|
416
|
-
type: "object",
|
|
417
|
-
parameters: [
|
|
418
|
-
{
|
|
419
|
-
name: "example",
|
|
420
|
-
type: "{ type: 'tool-result', runId: '1', from: 'AGENT', payload: { toolCallId: 'uuid', result: { ... }, toolName: 'my tool' } }",
|
|
421
|
-
description: "Example message structure",
|
|
422
|
-
isOptional: false,
|
|
423
|
-
},
|
|
424
|
-
],
|
|
425
|
-
},
|
|
426
|
-
],
|
|
373
|
+
name: "headers",
|
|
374
|
+
type: "Record<string, string | undefined>",
|
|
375
|
+
isOptional: true,
|
|
376
|
+
description: "Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.",
|
|
427
377
|
},
|
|
428
378
|
{
|
|
429
|
-
name: "
|
|
430
|
-
type: "
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
properties: [
|
|
434
|
-
{
|
|
435
|
-
type: "object",
|
|
436
|
-
parameters: [
|
|
437
|
-
{
|
|
438
|
-
name: "example",
|
|
439
|
-
type: "{ type: 'step-finish', runId: '1', from: 'AGENT', payload: { reason: 'stop', usage: { promptTokens: 100, completionTokens: 100, totalTokens: 200 }, response: Response, messageId: 'uuid', providerMetadata: { ... } } }",
|
|
440
|
-
description: "Example message structure",
|
|
441
|
-
isOptional: false,
|
|
442
|
-
},
|
|
443
|
-
],
|
|
444
|
-
},
|
|
445
|
-
],
|
|
379
|
+
name: "system",
|
|
380
|
+
type: "string",
|
|
381
|
+
isOptional: true,
|
|
382
|
+
description: "System message to include in the prompt. Can be used with `prompt` or `messages`.",
|
|
446
383
|
},
|
|
447
384
|
{
|
|
448
|
-
name: "
|
|
449
|
-
type: "
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
{
|
|
454
|
-
type: "object",
|
|
455
|
-
parameters: [
|
|
456
|
-
{
|
|
457
|
-
name: "example",
|
|
458
|
-
type: "{ type: 'finish', runId: '1', from: 'AGENT', payload: { totalUsage: { promptTokens: 100, completionTokens: 100, totalTokens: 200 } } }",
|
|
459
|
-
description: "Example message structure",
|
|
460
|
-
isOptional: false,
|
|
461
|
-
},
|
|
462
|
-
],
|
|
463
|
-
},
|
|
464
|
-
],
|
|
465
|
-
},
|
|
385
|
+
name: "prompt",
|
|
386
|
+
type: "string",
|
|
387
|
+
isOptional: true,
|
|
388
|
+
description: "A simple text prompt. You can either use `prompt` or `messages` but not both.",
|
|
389
|
+
}
|
|
466
390
|
]}
|
|
467
391
|
/>
|
|
468
392
|
|
|
469
393
|
## Returns
|
|
470
394
|
|
|
471
|
-
The return value of the `streamVNext()` method is a custom MatraAgentStream. This stream extends a ReadableStream, so all basic stream methods are available.
|
|
472
|
-
|
|
473
|
-
### PropertiesTable for Return Values
|
|
474
|
-
|
|
475
395
|
<PropertiesTable
|
|
476
396
|
content={[
|
|
477
397
|
{
|
|
478
|
-
name: "
|
|
479
|
-
type: "
|
|
480
|
-
|
|
481
|
-
description:
|
|
482
|
-
"Stream of text chunks. Present when output is 'text' (no schema provided) or when using `experimental_output`.",
|
|
483
|
-
},
|
|
484
|
-
{
|
|
485
|
-
name: "usage",
|
|
486
|
-
type: "Promise<object>",
|
|
487
|
-
isOptional: true,
|
|
488
|
-
description:
|
|
489
|
-
"Total usage of the agent, including agents/workflows as a tool.",
|
|
490
|
-
properties: [
|
|
491
|
-
{
|
|
492
|
-
type: "number",
|
|
493
|
-
parameters: [
|
|
494
|
-
{
|
|
495
|
-
name: "promptTokens",
|
|
496
|
-
type: "number",
|
|
497
|
-
isOptional: true,
|
|
498
|
-
description: "The number of prompt tokens used by the agent.",
|
|
499
|
-
},
|
|
500
|
-
],
|
|
501
|
-
},
|
|
502
|
-
{
|
|
503
|
-
type: "number",
|
|
504
|
-
parameters: [
|
|
505
|
-
{
|
|
506
|
-
name: "completionTokens",
|
|
507
|
-
type: "number",
|
|
508
|
-
isOptional: true,
|
|
509
|
-
description: "The number of completion tokens used by the agent.",
|
|
510
|
-
},
|
|
511
|
-
],
|
|
512
|
-
},
|
|
513
|
-
{
|
|
514
|
-
type: "number",
|
|
515
|
-
parameters: [
|
|
516
|
-
{
|
|
517
|
-
name: "totalTokens",
|
|
518
|
-
type: "number",
|
|
519
|
-
isOptional: true,
|
|
520
|
-
description: "The total number of tokens used by the agent.",
|
|
521
|
-
},
|
|
522
|
-
],
|
|
523
|
-
},
|
|
524
|
-
],
|
|
525
|
-
},
|
|
526
|
-
{
|
|
527
|
-
name: "finishReason",
|
|
528
|
-
type: "Promise<string>",
|
|
529
|
-
isOptional: true,
|
|
530
|
-
description:
|
|
531
|
-
"The reason the agent stopped streaming.",
|
|
532
|
-
},
|
|
533
|
-
{
|
|
534
|
-
name: "toolCalls",
|
|
535
|
-
type: "Promise<object>",
|
|
536
|
-
isOptional: true,
|
|
537
|
-
description:
|
|
538
|
-
"The tool calls made by the agent.",
|
|
539
|
-
},
|
|
540
|
-
{
|
|
541
|
-
name: "toolResults",
|
|
542
|
-
type: "Promise<object>",
|
|
543
|
-
isOptional: true,
|
|
544
|
-
description:
|
|
545
|
-
"The tool results returned by the agent.",
|
|
546
|
-
},
|
|
547
|
-
{
|
|
548
|
-
name: "text",
|
|
549
|
-
type: "Promise<string>",
|
|
550
|
-
isOptional: true,
|
|
551
|
-
description:
|
|
552
|
-
"The full text of the agent's response.",
|
|
553
|
-
},
|
|
554
|
-
{
|
|
555
|
-
name: "object",
|
|
556
|
-
type: "Promise<object>",
|
|
557
|
-
isOptional: true,
|
|
558
|
-
description:
|
|
559
|
-
"The object of the agent's response, if you use output or experimental output.",
|
|
398
|
+
name: "stream",
|
|
399
|
+
type: "MastraAgentStream<Output extends ZodSchema ? z.infer<Output> : StructuredOutput extends ZodSchema ? z.infer<StructuredOutput> : unknown>",
|
|
400
|
+
description: "A streaming interface that provides enhanced streaming capabilities for text and structured output.",
|
|
560
401
|
},
|
|
561
402
|
]}
|
|
562
403
|
/>
|
|
563
404
|
|
|
564
|
-
## Examples
|
|
565
|
-
|
|
566
|
-
### Basic Text Streaming
|
|
567
|
-
|
|
568
|
-
```typescript
|
|
569
|
-
const stream = await myAgent.streamVNext([
|
|
570
|
-
{ role: "user", content: "Tell me a story." },
|
|
571
|
-
]);
|
|
572
|
-
|
|
573
|
-
for await (const chunk of stream.textStream) {
|
|
574
|
-
process.stdout.write(chunk);
|
|
575
|
-
}
|
|
576
|
-
```
|
|
577
|
-
|
|
578
|
-
### Structured Output Streaming with Thread Context
|
|
579
|
-
|
|
580
|
-
```typescript
|
|
581
|
-
import { z } from "zod";
|
|
582
|
-
|
|
583
|
-
const schema = z.object({
|
|
584
|
-
summary: z.string(),
|
|
585
|
-
nextSteps: z.array(z.string()),
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
const response = await myAgent.streamVNext("What should we do next?", {
|
|
589
|
-
output: schema,
|
|
590
|
-
memory: {
|
|
591
|
-
thread: "project-123",
|
|
592
|
-
},
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
const result = await response.object;
|
|
596
|
-
console.log("Final structured result:", result);
|
|
597
|
-
```
|
|
598
|
-
|