@mastra/mcp-docs-server 0.13.7-alpha.4 → 0.13.7
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/%40mastra%2Fastra.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +7 -7
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +3 -3
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Flance.md +7 -0
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +7 -0
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Frag.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +8 -8
- package/.docs/organized/changelogs/mastra.md +12 -12
- package/.docs/raw/agents/streaming.mdx +118 -0
- package/.docs/raw/evals/custom-eval.mdx +4 -0
- package/.docs/raw/evals/overview.mdx +4 -0
- package/.docs/raw/evals/running-in-ci.mdx +4 -0
- package/.docs/raw/evals/textual-evals.mdx +4 -0
- package/.docs/raw/reference/agents/streamVNext.mdx +598 -0
- package/.docs/raw/reference/evals/answer-relevancy.mdx +4 -0
- package/.docs/raw/reference/evals/bias.mdx +4 -0
- package/.docs/raw/reference/evals/completeness.mdx +4 -0
- package/.docs/raw/reference/evals/content-similarity.mdx +4 -0
- package/.docs/raw/reference/evals/context-position.mdx +4 -0
- package/.docs/raw/reference/evals/context-precision.mdx +4 -0
- package/.docs/raw/reference/evals/context-relevancy.mdx +4 -0
- package/.docs/raw/reference/evals/contextual-recall.mdx +4 -0
- package/.docs/raw/reference/evals/faithfulness.mdx +4 -0
- package/.docs/raw/reference/evals/hallucination.mdx +4 -0
- package/.docs/raw/reference/evals/keyword-coverage.mdx +4 -0
- package/.docs/raw/reference/evals/prompt-alignment.mdx +4 -0
- package/.docs/raw/reference/evals/summarization.mdx +4 -1
- package/.docs/raw/reference/evals/textual-difference.mdx +4 -0
- package/.docs/raw/reference/evals/tone-consistency.mdx +4 -0
- package/.docs/raw/reference/evals/toxicity.mdx +4 -0
- package/.docs/raw/reference/workflows/streamVNext.mdx +215 -0
- package/.docs/raw/server-db/mastra-client.mdx +10 -6
- package/.docs/raw/workflows/control-flow.mdx +3 -3
- package/.docs/raw/workflows/streaming.mdx +115 -0
- package/package.json +5 -5
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Agent.streamVNext() | Streaming | Agents | Mastra Docs"
|
|
3
|
+
description: Documentation for the `.streamVNext()` method in Mastra agents, which enables real-time streaming of responses.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# `streamVNext()`
|
|
7
|
+
|
|
8
|
+
The `streamVNext()` method enables real-time streaming of responses from an agent. This method accepts `messages` and an optional `options` object as parameters, similar to `generate()`.
|
|
9
|
+
|
|
10
|
+
## Parameters
|
|
11
|
+
|
|
12
|
+
### `messages`
|
|
13
|
+
|
|
14
|
+
The `messages` parameter can be:
|
|
15
|
+
|
|
16
|
+
- A single string
|
|
17
|
+
- An array of strings
|
|
18
|
+
- An array of message objects with `role` and `content` properties
|
|
19
|
+
|
|
20
|
+
The message object structure:
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
interface Message {
|
|
24
|
+
role: "system" | "user" | "assistant";
|
|
25
|
+
content: string;
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### `options` (Optional)
|
|
30
|
+
|
|
31
|
+
An optional object that can include configuration for output structure, memory management, tool usage, telemetry, and more.
|
|
32
|
+
|
|
33
|
+
<PropertiesTable
|
|
34
|
+
content={[
|
|
35
|
+
{
|
|
36
|
+
name: "abortSignal",
|
|
37
|
+
type: "AbortSignal",
|
|
38
|
+
isOptional: true,
|
|
39
|
+
description:
|
|
40
|
+
"Signal object that allows you to abort the agent's execution. When the signal is aborted, all ongoing operations will be terminated.",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "context",
|
|
44
|
+
type: "CoreMessage[]",
|
|
45
|
+
isOptional: true,
|
|
46
|
+
description: "Additional context messages to provide to the agent.",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "experimental_output",
|
|
50
|
+
type: "Zod schema | JsonSchema7",
|
|
51
|
+
isOptional: true,
|
|
52
|
+
description:
|
|
53
|
+
"Enables structured output generation alongside text generation and tool calls. The model will generate responses that conform to the provided schema.",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "instructions",
|
|
57
|
+
type: "string",
|
|
58
|
+
isOptional: true,
|
|
59
|
+
description:
|
|
60
|
+
"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
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "memory",
|
|
64
|
+
type: "object",
|
|
65
|
+
isOptional: true,
|
|
66
|
+
description: "Configuration for memory. This is the preferred way to manage memory.",
|
|
67
|
+
properties: [
|
|
68
|
+
{
|
|
69
|
+
parameters: [{
|
|
70
|
+
name: "thread",
|
|
71
|
+
type: "string | { id: string; metadata?: Record<string, any>, title?: string }",
|
|
72
|
+
isOptional: false,
|
|
73
|
+
description: "The conversation thread, as a string ID or an object with an `id` and optional `metadata`."
|
|
74
|
+
}]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
parameters: [{
|
|
78
|
+
name: "resource",
|
|
79
|
+
type: "string",
|
|
80
|
+
isOptional: false,
|
|
81
|
+
description: "Identifier for the user or resource associated with the thread."
|
|
82
|
+
}]
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
parameters: [{
|
|
86
|
+
name: "options",
|
|
87
|
+
type: "MemoryConfig",
|
|
88
|
+
isOptional: true,
|
|
89
|
+
description: "Configuration for memory behavior, like message history and semantic recall. See `MemoryConfig` below."
|
|
90
|
+
}]
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "maxSteps",
|
|
96
|
+
type: "number",
|
|
97
|
+
isOptional: true,
|
|
98
|
+
defaultValue: "5",
|
|
99
|
+
description: "Maximum number of steps allowed during streaming.",
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: "maxRetries",
|
|
103
|
+
type: "number",
|
|
104
|
+
isOptional: true,
|
|
105
|
+
defaultValue: "2",
|
|
106
|
+
description: "Maximum number of retries. Set to 0 to disable retries.",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "memoryOptions",
|
|
110
|
+
type: "MemoryConfig",
|
|
111
|
+
isOptional: true,
|
|
112
|
+
description:
|
|
113
|
+
"**Deprecated.** Use `memory.options` instead. Configuration options for memory management. See MemoryConfig section below for details.",
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: "onFinish",
|
|
117
|
+
type: "StreamTextOnFinishCallback | StreamObjectOnFinishCallback",
|
|
118
|
+
isOptional: true,
|
|
119
|
+
description: "Callback function called when streaming is complete.",
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: "onStepFinish",
|
|
123
|
+
type: "GenerateTextOnStepFinishCallback<any> | never",
|
|
124
|
+
isOptional: true,
|
|
125
|
+
description:
|
|
126
|
+
"Callback function called after each step during streaming. Unavailable for structured output",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: "output",
|
|
130
|
+
type: "Zod schema | JsonSchema7",
|
|
131
|
+
isOptional: true,
|
|
132
|
+
description:
|
|
133
|
+
"Defines the expected structure of the output. Can be a JSON Schema object or a Zod schema.",
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: "telemetry",
|
|
137
|
+
type: "TelemetrySettings",
|
|
138
|
+
isOptional: true,
|
|
139
|
+
description:
|
|
140
|
+
"Settings for telemetry collection during streaming. See TelemetrySettings section below for details.",
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: "temperature",
|
|
144
|
+
type: "number",
|
|
145
|
+
isOptional: true,
|
|
146
|
+
description:
|
|
147
|
+
"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
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: "toolChoice",
|
|
151
|
+
type: "'auto' | 'none' | 'required' | { type: 'tool'; toolName: string }",
|
|
152
|
+
isOptional: true,
|
|
153
|
+
defaultValue: "'auto'",
|
|
154
|
+
description: "Controls how the agent uses tools during streaming.",
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
name: "toolsets",
|
|
158
|
+
type: "ToolsetsInput",
|
|
159
|
+
isOptional: true,
|
|
160
|
+
description:
|
|
161
|
+
"Additional toolsets to make available to the agent during this stream.",
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: "clientTools",
|
|
165
|
+
type: "ToolsInput",
|
|
166
|
+
isOptional: true,
|
|
167
|
+
description:
|
|
168
|
+
"Tools that are executed on the 'client' side of the request. These tools do not have execute functions in the definition.",
|
|
169
|
+
},
|
|
170
|
+
]}
|
|
171
|
+
/>
|
|
172
|
+
|
|
173
|
+
#### MemoryConfig
|
|
174
|
+
|
|
175
|
+
Configuration options for memory management:
|
|
176
|
+
|
|
177
|
+
<PropertiesTable
|
|
178
|
+
content={[
|
|
179
|
+
{
|
|
180
|
+
name: "lastMessages",
|
|
181
|
+
type: "number | false",
|
|
182
|
+
isOptional: true,
|
|
183
|
+
description:
|
|
184
|
+
"Number of most recent messages to include in context. Set to false to disable.",
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: "semanticRecall",
|
|
188
|
+
type: "boolean | object",
|
|
189
|
+
isOptional: true,
|
|
190
|
+
description:
|
|
191
|
+
"Configuration for semantic memory recall. Can be boolean or detailed config.",
|
|
192
|
+
properties: [
|
|
193
|
+
{
|
|
194
|
+
type: "number",
|
|
195
|
+
parameters: [
|
|
196
|
+
{
|
|
197
|
+
name: "topK",
|
|
198
|
+
type: "number",
|
|
199
|
+
isOptional: true,
|
|
200
|
+
description:
|
|
201
|
+
"Number of most semantically similar messages to retrieve.",
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
type: "number | object",
|
|
207
|
+
parameters: [
|
|
208
|
+
{
|
|
209
|
+
name: "messageRange",
|
|
210
|
+
type: "number | { before: number; after: number }",
|
|
211
|
+
isOptional: true,
|
|
212
|
+
description:
|
|
213
|
+
"Range of messages to consider for semantic search. Can be a single number or before/after configuration.",
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: "workingMemory",
|
|
221
|
+
type: "object",
|
|
222
|
+
isOptional: true,
|
|
223
|
+
description: "Configuration for working memory.",
|
|
224
|
+
properties: [
|
|
225
|
+
{
|
|
226
|
+
type: "boolean",
|
|
227
|
+
parameters: [
|
|
228
|
+
{
|
|
229
|
+
name: "enabled",
|
|
230
|
+
type: "boolean",
|
|
231
|
+
isOptional: true,
|
|
232
|
+
description: "Whether to enable working memory.",
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
type: "string",
|
|
238
|
+
parameters: [
|
|
239
|
+
{
|
|
240
|
+
name: "template",
|
|
241
|
+
type: "string",
|
|
242
|
+
isOptional: true,
|
|
243
|
+
description: "Template to use for working memory.",
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
name: "threads",
|
|
251
|
+
type: "object",
|
|
252
|
+
isOptional: true,
|
|
253
|
+
description: "Thread-specific memory configuration.",
|
|
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
|
+
],
|
|
269
|
+
},
|
|
270
|
+
]}
|
|
271
|
+
/>
|
|
272
|
+
|
|
273
|
+
#### TelemetrySettings
|
|
274
|
+
|
|
275
|
+
Settings for telemetry collection during streaming:
|
|
276
|
+
|
|
277
|
+
<PropertiesTable
|
|
278
|
+
content={[
|
|
279
|
+
{
|
|
280
|
+
name: "isEnabled",
|
|
281
|
+
type: "boolean",
|
|
282
|
+
isOptional: true,
|
|
283
|
+
defaultValue: "false",
|
|
284
|
+
description:
|
|
285
|
+
"Enable or disable telemetry. Disabled by default while experimental.",
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
name: "recordInputs",
|
|
289
|
+
type: "boolean",
|
|
290
|
+
isOptional: true,
|
|
291
|
+
defaultValue: "true",
|
|
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.",
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
name: "recordOutputs",
|
|
297
|
+
type: "boolean",
|
|
298
|
+
isOptional: true,
|
|
299
|
+
defaultValue: "true",
|
|
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.",
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
name: "functionId",
|
|
305
|
+
type: "string",
|
|
306
|
+
isOptional: true,
|
|
307
|
+
description:
|
|
308
|
+
"Identifier for this function. Used to group telemetry data by function.",
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
name: "metadata",
|
|
312
|
+
type: "Record<string, AttributeValue>",
|
|
313
|
+
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.",
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
name: "tracer",
|
|
319
|
+
type: "Tracer",
|
|
320
|
+
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
|
+
],
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
name: "step-start",
|
|
354
|
+
type: "object",
|
|
355
|
+
description: "The start of a step",
|
|
356
|
+
isOptional: false,
|
|
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
|
+
],
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
name: "tool-call",
|
|
373
|
+
type: "object",
|
|
374
|
+
description: "The start of a tool call",
|
|
375
|
+
isOptional: false,
|
|
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
|
+
],
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
name: "tool-output",
|
|
392
|
+
type: "object",
|
|
393
|
+
description: "Custom output from a step",
|
|
394
|
+
isOptional: false,
|
|
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
|
+
],
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
name: "tool-result",
|
|
411
|
+
type: "object",
|
|
412
|
+
description: "The result of a step",
|
|
413
|
+
isOptional: false,
|
|
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
|
+
],
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
name: "step-finish",
|
|
430
|
+
type: "object",
|
|
431
|
+
description: "The end of a step",
|
|
432
|
+
isOptional: false,
|
|
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
|
+
],
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
name: "finish",
|
|
449
|
+
type: "object",
|
|
450
|
+
description: "The end of the workflow",
|
|
451
|
+
isOptional: false,
|
|
452
|
+
properties: [
|
|
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
|
+
},
|
|
466
|
+
]}
|
|
467
|
+
/>
|
|
468
|
+
|
|
469
|
+
## Returns
|
|
470
|
+
|
|
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
|
+
<PropertiesTable
|
|
476
|
+
content={[
|
|
477
|
+
{
|
|
478
|
+
name: "textStream",
|
|
479
|
+
type: "ReadableStream<string>",
|
|
480
|
+
isOptional: true,
|
|
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.",
|
|
560
|
+
},
|
|
561
|
+
]}
|
|
562
|
+
/>
|
|
563
|
+
|
|
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
|
+
|
|
@@ -3,8 +3,12 @@ title: "Reference: Answer Relevancy | Metrics | Evals | Mastra Docs"
|
|
|
3
3
|
description: Documentation for the Answer Relevancy Metric in Mastra, which evaluates how well LLM outputs address the input query.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
import { ScorerCallout } from '@/components/scorer-callout'
|
|
7
|
+
|
|
6
8
|
# AnswerRelevancyMetric
|
|
7
9
|
|
|
10
|
+
<ScorerCallout />
|
|
11
|
+
|
|
8
12
|
The `AnswerRelevancyMetric` class evaluates how well an LLM's output answers or addresses the input query. It uses a judge-based system to determine relevancy and provides detailed scoring and reasoning.
|
|
9
13
|
|
|
10
14
|
## Basic Usage
|
|
@@ -3,8 +3,12 @@ title: "Reference: Bias | Output Metrics | Evals | Mastra Docs"
|
|
|
3
3
|
description: Documentation for the Bias Metric in Mastra, which evaluates LLM outputs for various forms of bias, including gender, political, racial/ethnic, or geographical bias.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
import { ScorerCallout } from '@/components/scorer-callout'
|
|
7
|
+
|
|
6
8
|
# BiasMetric
|
|
7
9
|
|
|
10
|
+
<ScorerCallout />
|
|
11
|
+
|
|
8
12
|
The `BiasMetric` class evaluates whether an LLM's output contains various forms of bias, including gender, political, racial/ethnic, or geographical bias. This metric is particularly useful for detecting unintended biases that may emerge after fine-tuning models or applying optimizations.
|
|
9
13
|
|
|
10
14
|
## Basic Usage
|
|
@@ -3,8 +3,12 @@ title: "Reference: Completeness | Metrics | Evals | Mastra Docs"
|
|
|
3
3
|
description: Documentation for the Completeness Metric in Mastra, which evaluates how thoroughly LLM outputs cover key elements present in the input.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
import { ScorerCallout } from '@/components/scorer-callout'
|
|
7
|
+
|
|
6
8
|
# CompletenessMetric
|
|
7
9
|
|
|
10
|
+
<ScorerCallout />
|
|
11
|
+
|
|
8
12
|
The `CompletenessMetric` class evaluates how thoroughly an LLM's output covers the key elements present in the input. It analyzes nouns, verbs, topics, and terms to determine coverage and provides a detailed completeness score.
|
|
9
13
|
|
|
10
14
|
## Basic Usage
|
|
@@ -3,8 +3,12 @@ title: "Reference: Content Similarity | Evals | Mastra Docs"
|
|
|
3
3
|
description: Documentation for the Content Similarity Metric in Mastra, which measures textual similarity between strings and provides a matching score.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
import { ScorerCallout } from '@/components/scorer-callout'
|
|
7
|
+
|
|
6
8
|
# ContentSimilarityMetric
|
|
7
9
|
|
|
10
|
+
<ScorerCallout />
|
|
11
|
+
|
|
8
12
|
The `ContentSimilarityMetric` class measures the textual similarity between two strings, providing a score that indicates how closely they match. It supports configurable options for case sensitivity and whitespace handling.
|
|
9
13
|
|
|
10
14
|
## Basic Usage
|
|
@@ -3,8 +3,12 @@ title: "Reference: Context Position | Metrics | Evals | Mastra Docs"
|
|
|
3
3
|
description: Documentation for the Context Position Metric in Mastra, which evaluates the ordering of context nodes based on their relevance to the query and output.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
import { ScorerCallout } from '@/components/scorer-callout'
|
|
7
|
+
|
|
6
8
|
# ContextPositionMetric
|
|
7
9
|
|
|
10
|
+
<ScorerCallout />
|
|
11
|
+
|
|
8
12
|
The `ContextPositionMetric` class evaluates how well context nodes are ordered based on their relevance to the query and output. It uses position-weighted scoring to emphasize the importance of having the most relevant context pieces appear earlier in the sequence.
|
|
9
13
|
|
|
10
14
|
## Basic Usage
|
|
@@ -3,8 +3,12 @@ title: "Reference: Context Precision | Metrics | Evals | Mastra Docs"
|
|
|
3
3
|
description: Documentation for the Context Precision Metric in Mastra, which evaluates the relevance and precision of retrieved context nodes for generating expected outputs.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
import { ScorerCallout } from '@/components/scorer-callout'
|
|
7
|
+
|
|
6
8
|
# ContextPrecisionMetric
|
|
7
9
|
|
|
10
|
+
<ScorerCallout />
|
|
11
|
+
|
|
8
12
|
The `ContextPrecisionMetric` class evaluates how relevant and precise the retrieved context nodes are for generating the expected output. It uses a judge-based system to analyze each context piece's contribution and provides weighted scoring based on position.
|
|
9
13
|
|
|
10
14
|
## Basic Usage
|
|
@@ -3,8 +3,12 @@ title: "Reference: Context Relevancy | Evals | Mastra Docs"
|
|
|
3
3
|
description: Documentation for the Context Relevancy Metric, which evaluates the relevance of retrieved context in RAG pipelines.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
import { ScorerCallout } from '@/components/scorer-callout'
|
|
7
|
+
|
|
6
8
|
# ContextRelevancyMetric
|
|
7
9
|
|
|
10
|
+
<ScorerCallout />
|
|
11
|
+
|
|
8
12
|
The `ContextRelevancyMetric` class evaluates the quality of your RAG (Retrieval-Augmented Generation) pipeline's retriever by measuring how relevant the retrieved context is to the input query. It uses an LLM-based evaluation system that first extracts statements from the context and then assesses their relevance to the input.
|
|
9
13
|
|
|
10
14
|
## Basic Usage
|