@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.
- 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%2Fagent-builder.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +11 -0
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +23 -23
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +61 -61
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +24 -24
- 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 +22 -22
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Flance.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +65 -65
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Frag.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Freact.md +18 -0
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +12 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +10 -10
- package/.docs/organized/changelogs/create-mastra.md +47 -47
- package/.docs/organized/changelogs/mastra.md +63 -63
- package/.docs/organized/code-examples/agent.md +19 -14
- package/.docs/organized/code-examples/heads-up-game.md +5 -5
- package/.docs/raw/agents/agent-memory.mdx +86 -125
- package/.docs/raw/agents/input-processors.mdx +3 -3
- package/.docs/raw/agents/output-processors.mdx +4 -4
- package/.docs/raw/agents/overview.mdx +11 -52
- package/.docs/raw/agents/using-tools-and-mcp.mdx +34 -29
- package/.docs/raw/deployment/serverless-platforms/vercel-deployer.mdx +18 -0
- package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +4 -8
- package/.docs/raw/getting-started/installation.mdx +2 -3
- package/.docs/raw/getting-started/model-providers.mdx +28 -123
- package/.docs/raw/memory/semantic-recall.mdx +1 -1
- package/.docs/raw/reference/agents/agent.mdx +1 -1
- package/.docs/raw/reference/agents/generate.mdx +255 -218
- package/.docs/raw/reference/agents/generateLegacy.mdx +528 -0
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +3 -4
- package/.docs/raw/reference/agents/migration-guide.mdx +291 -0
- package/.docs/raw/reference/client-js/agents.mdx +14 -8
- package/.docs/raw/reference/deployer/vercel.mdx +26 -0
- package/.docs/raw/reference/streaming/ChunkType.mdx +4 -4
- package/.docs/raw/reference/streaming/agents/MastraModelOutput.mdx +13 -13
- package/.docs/raw/reference/streaming/agents/stream.mdx +351 -178
- package/.docs/raw/reference/streaming/agents/streamLegacy.mdx +515 -0
- package/.docs/raw/reference/{rag → vectors}/astra.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/chroma.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/couchbase.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/lance.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/libsql.mdx +2 -4
- package/.docs/raw/reference/{rag → vectors}/mongodb.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/opensearch.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/pg.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/pinecone.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/qdrant.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/s3vectors.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/turbopuffer.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/upstash.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/vectorize.mdx +2 -2
- package/.docs/raw/streaming/events.mdx +4 -4
- package/.docs/raw/streaming/overview.mdx +9 -11
- package/.docs/raw/streaming/tool-streaming.mdx +3 -3
- package/.docs/raw/streaming/workflow-streaming.mdx +3 -3
- package/CHANGELOG.md +16 -0
- package/package.json +5 -5
- package/.docs/organized/code-examples/agent-network.md +0 -322
- package/.docs/raw/getting-started/model-capability.mdx +0 -11
- package/.docs/raw/reference/agents/generateVNext.mdx +0 -557
- package/.docs/raw/reference/agents/getDefaultVNextStreamOptions.mdx +0 -67
- package/.docs/raw/reference/streaming/agents/streamVNext.mdx +0 -673
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Reference: Agent.generate() | Agents | Mastra Docs"
|
|
3
|
-
description: "Documentation for the `Agent.generate()` method in Mastra agents, which
|
|
3
|
+
description: "Documentation for the `Agent.generate()` method in Mastra agents, which enables non-streaming generation of responses with enhanced capabilities."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
import { Callout } from 'nextra/components';
|
|
7
|
+
|
|
6
8
|
# Agent.generate()
|
|
7
9
|
|
|
8
|
-
The `.generate()` method
|
|
10
|
+
The `.generate()` method enables non-streaming response generation from an agent, with enhanced capabilities and flexible output formats. It accepts messages and optional generation options, supporting both Mastra’s native format and AI SDK v5 compatibility.
|
|
9
11
|
|
|
10
12
|
## Usage example
|
|
11
13
|
|
|
12
14
|
```typescript copy
|
|
13
|
-
|
|
15
|
+
// Default Mastra format
|
|
16
|
+
const mastraResult = await agent.generate("message for agent");
|
|
17
|
+
|
|
18
|
+
// AI SDK v5 compatible format
|
|
19
|
+
const aiSdkResult = await agent.generate("message for agent", {
|
|
20
|
+
format: 'aisdk'
|
|
21
|
+
});
|
|
14
22
|
```
|
|
15
23
|
|
|
24
|
+
<Callout type="info">
|
|
25
|
+
**Model Compatibility**: This method is designed for V2 models. V1 models should use the [`.generateLegacy()`](./generateLegacy.mdx) method. The framework automatically detects your model version and will throw an error if there's a mismatch.
|
|
26
|
+
</Callout>
|
|
27
|
+
|
|
28
|
+
|
|
16
29
|
## Parameters
|
|
17
30
|
|
|
18
31
|
<PropertiesTable
|
|
@@ -20,31 +33,129 @@ await agent.generate("message for agent");
|
|
|
20
33
|
{
|
|
21
34
|
name: "messages",
|
|
22
35
|
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
|
|
36
|
+
description: "The messages to send to the agent. Can be a single string, array of strings, or structured message objects.",
|
|
24
37
|
},
|
|
25
38
|
{
|
|
26
39
|
name: "options",
|
|
27
|
-
type: "
|
|
40
|
+
type: "AgentExecutionOptions<Output, StructuredOutput, Format>",
|
|
28
41
|
isOptional: true,
|
|
29
42
|
description: "Optional configuration for the generation process.",
|
|
30
43
|
},
|
|
31
44
|
]}
|
|
32
45
|
/>
|
|
33
46
|
|
|
34
|
-
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### Options
|
|
35
50
|
|
|
36
51
|
<PropertiesTable
|
|
37
52
|
content={[
|
|
53
|
+
{
|
|
54
|
+
name: "format",
|
|
55
|
+
type: "'mastra' | 'aisdk'",
|
|
56
|
+
isOptional: true,
|
|
57
|
+
defaultValue: "'mastra'",
|
|
58
|
+
description: "Determines the output format. Use 'mastra' for Mastra's native format (default) or 'aisdk' for AI SDK v5 compatibility.",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "maxSteps",
|
|
62
|
+
type: "number",
|
|
63
|
+
isOptional: true,
|
|
64
|
+
description: "Maximum number of steps to run during execution.",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "scorers",
|
|
68
|
+
type: "MastraScorers | Record<string, { scorer: MastraScorer['name']; sampling?: ScoringSamplingConfig }>",
|
|
69
|
+
isOptional: true,
|
|
70
|
+
description: "Evaluation scorers to run on the execution results.",
|
|
71
|
+
properties: [
|
|
72
|
+
{
|
|
73
|
+
parameters: [{
|
|
74
|
+
name: "scorer",
|
|
75
|
+
type: "string",
|
|
76
|
+
isOptional: false,
|
|
77
|
+
description: "Name of the scorer to use."
|
|
78
|
+
}]
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
parameters: [{
|
|
82
|
+
name: "sampling",
|
|
83
|
+
type: "ScoringSamplingConfig",
|
|
84
|
+
isOptional: true,
|
|
85
|
+
description: "Sampling configuration for the scorer.",
|
|
86
|
+
properties: [
|
|
87
|
+
{
|
|
88
|
+
parameters: [{
|
|
89
|
+
name: "type",
|
|
90
|
+
type: "'none' | 'ratio'",
|
|
91
|
+
isOptional: false,
|
|
92
|
+
description: "Type of sampling strategy. Use 'none' to disable sampling or 'ratio' for percentage-based sampling."
|
|
93
|
+
}]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
parameters: [{
|
|
97
|
+
name: "rate",
|
|
98
|
+
type: "number",
|
|
99
|
+
isOptional: true,
|
|
100
|
+
description: "Sampling rate (0-1). Required when type is 'ratio'."
|
|
101
|
+
}]
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
}]
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "tracingContext",
|
|
110
|
+
type: "TracingContext",
|
|
111
|
+
isOptional: true,
|
|
112
|
+
description: "AI tracing context for span hierarchy and metadata.",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: "returnScorerData",
|
|
116
|
+
type: "boolean",
|
|
117
|
+
isOptional: true,
|
|
118
|
+
description: "Whether to return detailed scoring data in the response.",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "onChunk",
|
|
122
|
+
type: "(chunk: ChunkType) => Promise<void> | void",
|
|
123
|
+
isOptional: true,
|
|
124
|
+
description: "Callback function called for each chunk during generation.",
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: "onError",
|
|
128
|
+
type: "({ error }: { error: Error | string }) => Promise<void> | void",
|
|
129
|
+
isOptional: true,
|
|
130
|
+
description: "Callback function called when an error occurs during generation.",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: "onAbort",
|
|
134
|
+
type: "(event: any) => Promise<void> | void",
|
|
135
|
+
isOptional: true,
|
|
136
|
+
description: "Callback function called when the generation is aborted.",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "activeTools",
|
|
140
|
+
type: "Array<keyof ToolSet> | undefined",
|
|
141
|
+
isOptional: true,
|
|
142
|
+
description: "Array of tool names that should be active during execution. If undefined, all available tools are active.",
|
|
143
|
+
},
|
|
38
144
|
{
|
|
39
145
|
name: "abortSignal",
|
|
40
146
|
type: "AbortSignal",
|
|
41
147
|
isOptional: true,
|
|
42
|
-
description:
|
|
43
|
-
|
|
148
|
+
description: "Signal object that allows you to abort the agent's execution. When the signal is aborted, all ongoing operations will be terminated.",
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: "prepareStep",
|
|
152
|
+
type: "PrepareStepFunction<any>",
|
|
153
|
+
isOptional: true,
|
|
154
|
+
description: "Callback function called before each step of multi-step execution.",
|
|
44
155
|
},
|
|
45
156
|
{
|
|
46
157
|
name: "context",
|
|
47
|
-
type: "
|
|
158
|
+
type: "ModelMessage[]",
|
|
48
159
|
isOptional: true,
|
|
49
160
|
description: "Additional context messages to provide to the agent.",
|
|
50
161
|
},
|
|
@@ -59,15 +170,15 @@ await agent.generate("message for agent");
|
|
|
59
170
|
name: "schema",
|
|
60
171
|
type: "z.ZodSchema<S>",
|
|
61
172
|
isOptional: false,
|
|
62
|
-
description: "Zod schema
|
|
173
|
+
description: "Zod schema defining the expected output structure."
|
|
63
174
|
}]
|
|
64
175
|
},
|
|
65
176
|
{
|
|
66
177
|
parameters: [{
|
|
67
178
|
name: "model",
|
|
68
179
|
type: "MastraLanguageModel",
|
|
69
|
-
isOptional:
|
|
70
|
-
description: "
|
|
180
|
+
isOptional: true,
|
|
181
|
+
description: "Language model to use for structured output generation. If not provided, uses the agent's default model."
|
|
71
182
|
}]
|
|
72
183
|
},
|
|
73
184
|
{
|
|
@@ -75,7 +186,7 @@ await agent.generate("message for agent");
|
|
|
75
186
|
name: "errorStrategy",
|
|
76
187
|
type: "'strict' | 'warn' | 'fallback'",
|
|
77
188
|
isOptional: true,
|
|
78
|
-
description: "Strategy
|
|
189
|
+
description: "Strategy for handling schema validation errors. 'strict' throws errors, 'warn' logs warnings, 'fallback' uses fallback values."
|
|
79
190
|
}]
|
|
80
191
|
},
|
|
81
192
|
{
|
|
@@ -83,7 +194,7 @@ await agent.generate("message for agent");
|
|
|
83
194
|
name: "fallbackValue",
|
|
84
195
|
type: "<S extends ZodTypeAny>",
|
|
85
196
|
isOptional: true,
|
|
86
|
-
description: "Fallback value when errorStrategy is 'fallback'."
|
|
197
|
+
description: "Fallback value to use when schema validation fails and errorStrategy is 'fallback'."
|
|
87
198
|
}]
|
|
88
199
|
},
|
|
89
200
|
{
|
|
@@ -91,102 +202,90 @@ await agent.generate("message for agent");
|
|
|
91
202
|
name: "instructions",
|
|
92
203
|
type: "string",
|
|
93
204
|
isOptional: true,
|
|
94
|
-
description: "
|
|
205
|
+
description: "Additional instructions for structured output generation."
|
|
95
206
|
}]
|
|
96
|
-
}
|
|
207
|
+
}
|
|
97
208
|
]
|
|
98
209
|
},
|
|
99
210
|
{
|
|
100
211
|
name: "outputProcessors",
|
|
101
212
|
type: "Processor[]",
|
|
102
213
|
isOptional: true,
|
|
103
|
-
description: "
|
|
214
|
+
description: "Output processors to use for this execution (overrides agent's default).",
|
|
104
215
|
},
|
|
105
216
|
{
|
|
106
217
|
name: "inputProcessors",
|
|
107
218
|
type: "Processor[]",
|
|
108
219
|
isOptional: true,
|
|
109
|
-
description: "
|
|
220
|
+
description: "Input processors to use for this execution (overrides agent's default).",
|
|
110
221
|
},
|
|
111
222
|
{
|
|
112
|
-
name: "
|
|
113
|
-
type: "
|
|
223
|
+
name: "instructions",
|
|
224
|
+
type: "string",
|
|
114
225
|
isOptional: true,
|
|
115
|
-
description:
|
|
116
|
-
"Note, the preferred route is to use the `structuredOutput` property. Enables structured output generation alongside text generation and tool calls. The model will generate responses that conform to the provided schema.",
|
|
226
|
+
description: "Custom instructions that override the agent's default instructions for this execution.",
|
|
117
227
|
},
|
|
118
228
|
{
|
|
119
|
-
name: "
|
|
120
|
-
type: "string",
|
|
229
|
+
name: "system",
|
|
230
|
+
type: "string | string[] | CoreSystemMessage | SystemModelMessage | CoreSystemMessage[] | SystemModelMessage[]",
|
|
121
231
|
isOptional: true,
|
|
122
|
-
description:
|
|
123
|
-
"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.",
|
|
232
|
+
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.",
|
|
124
233
|
},
|
|
125
234
|
{
|
|
126
235
|
name: "output",
|
|
127
236
|
type: "Zod schema | JsonSchema7",
|
|
128
237
|
isOptional: true,
|
|
129
|
-
description:
|
|
130
|
-
"Defines the expected structure of the output. Can be a JSON Schema object or a Zod schema.",
|
|
238
|
+
description: "**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.",
|
|
131
239
|
},
|
|
132
240
|
{
|
|
133
241
|
name: "memory",
|
|
134
242
|
type: "object",
|
|
135
243
|
isOptional: true,
|
|
136
|
-
description: "
|
|
244
|
+
description: "Memory configuration for conversation persistence and retrieval.",
|
|
137
245
|
properties: [
|
|
138
246
|
{
|
|
139
247
|
parameters: [{
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
248
|
+
name: "thread",
|
|
249
|
+
type: "string | { id: string; metadata?: Record<string, any>, title?: string }",
|
|
250
|
+
isOptional: false,
|
|
251
|
+
description: "Thread identifier for conversation continuity. Can be a string ID or an object with ID and optional metadata/title."
|
|
144
252
|
}]
|
|
145
253
|
},
|
|
146
254
|
{
|
|
147
255
|
parameters: [{
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
256
|
+
name: "resource",
|
|
257
|
+
type: "string",
|
|
258
|
+
isOptional: false,
|
|
259
|
+
description: "Resource identifier for organizing conversations by user, session, or context."
|
|
152
260
|
}]
|
|
153
261
|
},
|
|
154
262
|
{
|
|
155
263
|
parameters: [{
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
264
|
+
name: "options",
|
|
265
|
+
type: "MemoryConfig",
|
|
266
|
+
isOptional: true,
|
|
267
|
+
description: "Additional memory configuration options for conversation management."
|
|
160
268
|
}]
|
|
161
269
|
}
|
|
162
270
|
]
|
|
163
271
|
},
|
|
164
272
|
{
|
|
165
|
-
name: "
|
|
166
|
-
type: "
|
|
167
|
-
isOptional: true,
|
|
168
|
-
defaultValue: "5",
|
|
169
|
-
description: "Maximum number of execution steps allowed.",
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
name: "maxRetries",
|
|
173
|
-
type: "number",
|
|
273
|
+
name: "onFinish",
|
|
274
|
+
type: "StreamTextOnFinishCallback<any> | StreamObjectOnFinishCallback<OUTPUT>",
|
|
174
275
|
isOptional: true,
|
|
175
|
-
|
|
176
|
-
description: "Maximum number of retries. Set to 0 to disable retries.",
|
|
276
|
+
description: "Callback fired when generation completes. Type varies by format.",
|
|
177
277
|
},
|
|
178
278
|
{
|
|
179
279
|
name: "onStepFinish",
|
|
180
|
-
type: "
|
|
280
|
+
type: "StreamTextOnStepFinishCallback<any> | never",
|
|
181
281
|
isOptional: true,
|
|
182
|
-
description:
|
|
183
|
-
"Callback function called after each execution step. Receives step details as a JSON string. Unavailable for structured output",
|
|
282
|
+
description: "Callback fired after each generation step. Type varies by format.",
|
|
184
283
|
},
|
|
185
284
|
{
|
|
186
|
-
name: "
|
|
285
|
+
name: "resourceId",
|
|
187
286
|
type: "string",
|
|
188
287
|
isOptional: true,
|
|
189
|
-
description: "
|
|
288
|
+
description: "Deprecated. Use memory.resource instead. Identifier for the resource/user.",
|
|
190
289
|
},
|
|
191
290
|
{
|
|
192
291
|
name: "telemetry",
|
|
@@ -200,7 +299,7 @@ await agent.generate("message for agent");
|
|
|
200
299
|
name: "isEnabled",
|
|
201
300
|
type: "boolean",
|
|
202
301
|
isOptional: true,
|
|
203
|
-
description: "
|
|
302
|
+
description: "Whether telemetry collection is enabled."
|
|
204
303
|
}]
|
|
205
304
|
},
|
|
206
305
|
{
|
|
@@ -208,7 +307,7 @@ await agent.generate("message for agent");
|
|
|
208
307
|
name: "recordInputs",
|
|
209
308
|
type: "boolean",
|
|
210
309
|
isOptional: true,
|
|
211
|
-
description: "
|
|
310
|
+
description: "Whether to record input data in telemetry."
|
|
212
311
|
}]
|
|
213
312
|
},
|
|
214
313
|
{
|
|
@@ -216,7 +315,7 @@ await agent.generate("message for agent");
|
|
|
216
315
|
name: "recordOutputs",
|
|
217
316
|
type: "boolean",
|
|
218
317
|
isOptional: true,
|
|
219
|
-
description: "
|
|
318
|
+
description: "Whether to record output data in telemetry."
|
|
220
319
|
}]
|
|
221
320
|
},
|
|
222
321
|
{
|
|
@@ -224,51 +323,117 @@ await agent.generate("message for agent");
|
|
|
224
323
|
name: "functionId",
|
|
225
324
|
type: "string",
|
|
226
325
|
isOptional: true,
|
|
227
|
-
description: "Identifier for
|
|
326
|
+
description: "Identifier for the function being executed."
|
|
228
327
|
}]
|
|
229
328
|
}
|
|
230
329
|
]
|
|
231
330
|
},
|
|
232
331
|
{
|
|
233
|
-
name: "
|
|
234
|
-
type: "
|
|
332
|
+
name: "modelSettings",
|
|
333
|
+
type: "CallSettings",
|
|
235
334
|
isOptional: true,
|
|
236
|
-
description:
|
|
237
|
-
|
|
335
|
+
description: "Model-specific settings like temperature, topP, etc.",
|
|
336
|
+
properties: [
|
|
337
|
+
{
|
|
338
|
+
parameters: [{
|
|
339
|
+
name: "temperature",
|
|
340
|
+
type: "number",
|
|
341
|
+
isOptional: true,
|
|
342
|
+
description: "Controls randomness in generation (0-2). Higher values make output more random."
|
|
343
|
+
}]
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
parameters: [{
|
|
347
|
+
name: "maxRetries",
|
|
348
|
+
type: "number",
|
|
349
|
+
isOptional: true,
|
|
350
|
+
description: "Maximum number of retry attempts for failed requests."
|
|
351
|
+
}]
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
parameters: [{
|
|
355
|
+
name: "topP",
|
|
356
|
+
type: "number",
|
|
357
|
+
isOptional: true,
|
|
358
|
+
description: "Nucleus sampling parameter (0-1). Controls diversity of generated text."
|
|
359
|
+
}]
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
parameters: [{
|
|
363
|
+
name: "topK",
|
|
364
|
+
type: "number",
|
|
365
|
+
isOptional: true,
|
|
366
|
+
description: "Top-k sampling parameter. Limits vocabulary to k most likely tokens."
|
|
367
|
+
}]
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
parameters: [{
|
|
371
|
+
name: "presencePenalty",
|
|
372
|
+
type: "number",
|
|
373
|
+
isOptional: true,
|
|
374
|
+
description: "Penalty for token presence (-2 to 2). Reduces repetition."
|
|
375
|
+
}]
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
parameters: [{
|
|
379
|
+
name: "frequencyPenalty",
|
|
380
|
+
type: "number",
|
|
381
|
+
isOptional: true,
|
|
382
|
+
description: "Penalty for token frequency (-2 to 2). Reduces repetition of frequent tokens."
|
|
383
|
+
}]
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
parameters: [{
|
|
387
|
+
name: "stopSequences",
|
|
388
|
+
type: "string[]",
|
|
389
|
+
isOptional: true,
|
|
390
|
+
description: "Array of strings that will stop generation when encountered."
|
|
391
|
+
}]
|
|
392
|
+
}
|
|
393
|
+
]
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
name: "threadId",
|
|
397
|
+
type: "string",
|
|
398
|
+
isOptional: true,
|
|
399
|
+
description: "Deprecated. Use memory.thread instead. Thread identifier for conversation continuity.",
|
|
238
400
|
},
|
|
239
401
|
{
|
|
240
402
|
name: "toolChoice",
|
|
241
403
|
type: "'auto' | 'none' | 'required' | { type: 'tool'; toolName: string }",
|
|
242
404
|
isOptional: true,
|
|
243
|
-
|
|
244
|
-
description: "Controls how the agent uses tools during generation.",
|
|
405
|
+
description: "Controls how tools are selected during generation.",
|
|
245
406
|
properties: [
|
|
246
407
|
{
|
|
247
408
|
parameters: [{
|
|
248
409
|
name: "'auto'",
|
|
249
410
|
type: "string",
|
|
250
|
-
|
|
411
|
+
isOptional: false,
|
|
412
|
+
description: "Let the model decide when to use tools (default)."
|
|
251
413
|
}]
|
|
252
414
|
},
|
|
253
415
|
{
|
|
254
416
|
parameters: [{
|
|
255
417
|
name: "'none'",
|
|
256
418
|
type: "string",
|
|
257
|
-
|
|
419
|
+
isOptional: false,
|
|
420
|
+
description: "Disable tool usage entirely."
|
|
258
421
|
}]
|
|
259
422
|
},
|
|
260
423
|
{
|
|
261
424
|
parameters: [{
|
|
262
425
|
name: "'required'",
|
|
263
426
|
type: "string",
|
|
264
|
-
|
|
427
|
+
isOptional: false,
|
|
428
|
+
description: "Force the model to use at least one tool."
|
|
265
429
|
}]
|
|
266
430
|
},
|
|
267
431
|
{
|
|
268
432
|
parameters: [{
|
|
269
433
|
name: "{ type: 'tool'; toolName: string }",
|
|
270
434
|
type: "object",
|
|
271
|
-
|
|
435
|
+
isOptional: false,
|
|
436
|
+
description: "Force the model to use a specific tool."
|
|
272
437
|
}]
|
|
273
438
|
}
|
|
274
439
|
]
|
|
@@ -277,34 +442,32 @@ await agent.generate("message for agent");
|
|
|
277
442
|
name: "toolsets",
|
|
278
443
|
type: "ToolsetsInput",
|
|
279
444
|
isOptional: true,
|
|
280
|
-
description:
|
|
281
|
-
"Additional toolsets to make available to the agent during generation.",
|
|
445
|
+
description: "Additional tool sets that can be used for this execution.",
|
|
282
446
|
},
|
|
283
447
|
{
|
|
284
448
|
name: "clientTools",
|
|
285
449
|
type: "ToolsInput",
|
|
286
450
|
isOptional: true,
|
|
287
|
-
description:
|
|
288
|
-
"Tools that are executed on the 'client' side of the request. These tools do not have execute functions in the definition.",
|
|
451
|
+
description: "Client-side tools available during execution.",
|
|
289
452
|
},
|
|
290
453
|
{
|
|
291
454
|
name: "savePerStep",
|
|
292
455
|
type: "boolean",
|
|
293
456
|
isOptional: true,
|
|
294
|
-
description: "Save messages incrementally after each
|
|
457
|
+
description: "Save messages incrementally after each generation step completes (default: false).",
|
|
295
458
|
},
|
|
296
459
|
{
|
|
297
460
|
name: "providerOptions",
|
|
298
461
|
type: "Record<string, Record<string, JSONValue>>",
|
|
299
462
|
isOptional: true,
|
|
300
|
-
description: "
|
|
463
|
+
description: "Provider-specific options passed to the language model.",
|
|
301
464
|
properties: [
|
|
302
465
|
{
|
|
303
466
|
parameters: [{
|
|
304
467
|
name: "openai",
|
|
305
468
|
type: "Record<string, JSONValue>",
|
|
306
469
|
isOptional: true,
|
|
307
|
-
description: "OpenAI-specific options
|
|
470
|
+
description: "OpenAI-specific options like reasoningEffort, responseFormat, etc."
|
|
308
471
|
}]
|
|
309
472
|
},
|
|
310
473
|
{
|
|
@@ -312,7 +475,7 @@ await agent.generate("message for agent");
|
|
|
312
475
|
name: "anthropic",
|
|
313
476
|
type: "Record<string, JSONValue>",
|
|
314
477
|
isOptional: true,
|
|
315
|
-
description: "Anthropic-specific options
|
|
478
|
+
description: "Anthropic-specific options like maxTokens, etc."
|
|
316
479
|
}]
|
|
317
480
|
},
|
|
318
481
|
{
|
|
@@ -320,7 +483,7 @@ await agent.generate("message for agent");
|
|
|
320
483
|
name: "google",
|
|
321
484
|
type: "Record<string, JSONValue>",
|
|
322
485
|
isOptional: true,
|
|
323
|
-
description: "Google-specific options.
|
|
486
|
+
description: "Google-specific options."
|
|
324
487
|
}]
|
|
325
488
|
},
|
|
326
489
|
{
|
|
@@ -328,16 +491,22 @@ await agent.generate("message for agent");
|
|
|
328
491
|
name: "[providerName]",
|
|
329
492
|
type: "Record<string, JSONValue>",
|
|
330
493
|
isOptional: true,
|
|
331
|
-
description: "
|
|
494
|
+
description: "Any provider-specific options."
|
|
332
495
|
}]
|
|
333
496
|
}
|
|
334
497
|
]
|
|
335
498
|
},
|
|
499
|
+
{
|
|
500
|
+
name: "runId",
|
|
501
|
+
type: "string",
|
|
502
|
+
isOptional: true,
|
|
503
|
+
description: "Unique identifier for this execution run.",
|
|
504
|
+
},
|
|
336
505
|
{
|
|
337
506
|
name: "runtimeContext",
|
|
338
507
|
type: "RuntimeContext",
|
|
339
508
|
isOptional: true,
|
|
340
|
-
description: "Runtime context
|
|
509
|
+
description: "Runtime context containing dynamic configuration and state.",
|
|
341
510
|
},
|
|
342
511
|
{
|
|
343
512
|
name: "tracingContext",
|
|
@@ -375,50 +544,8 @@ await agent.generate("message for agent");
|
|
|
375
544
|
name: "maxTokens",
|
|
376
545
|
type: "number",
|
|
377
546
|
isOptional: true,
|
|
378
|
-
description: "
|
|
379
|
-
},
|
|
380
|
-
{
|
|
381
|
-
name: "topP",
|
|
382
|
-
type: "number",
|
|
383
|
-
isOptional: true,
|
|
384
|
-
description: "Nucleus sampling. This is a number between 0 and 1. It is recommended to set either `temperature` or `topP`, but not both.",
|
|
385
|
-
},
|
|
386
|
-
{
|
|
387
|
-
name: "topK",
|
|
388
|
-
type: "number",
|
|
389
|
-
isOptional: true,
|
|
390
|
-
description: "Only sample from the top K options for each subsequent token. Used to remove 'long tail' low probability responses.",
|
|
391
|
-
},
|
|
392
|
-
{
|
|
393
|
-
name: "presencePenalty",
|
|
394
|
-
type: "number",
|
|
395
|
-
isOptional: true,
|
|
396
|
-
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).",
|
|
397
|
-
},
|
|
398
|
-
{
|
|
399
|
-
name: "frequencyPenalty",
|
|
400
|
-
type: "number",
|
|
401
|
-
isOptional: true,
|
|
402
|
-
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).",
|
|
403
|
-
},
|
|
404
|
-
{
|
|
405
|
-
name: "stopSequences",
|
|
406
|
-
type: "string[]",
|
|
407
|
-
isOptional: true,
|
|
408
|
-
description: "Stop sequences. If set, the model will stop generating text when one of the stop sequences is generated.",
|
|
409
|
-
},
|
|
410
|
-
{
|
|
411
|
-
name: "seed",
|
|
412
|
-
type: "number",
|
|
413
|
-
isOptional: true,
|
|
414
|
-
description: "The seed (integer) to use for random sampling. If set and supported by the model, calls will generate deterministic results.",
|
|
547
|
+
description: "Conditions for stopping execution (e.g., step count, token limit).",
|
|
415
548
|
},
|
|
416
|
-
{
|
|
417
|
-
name: "headers",
|
|
418
|
-
type: "Record<string, string | undefined>",
|
|
419
|
-
isOptional: true,
|
|
420
|
-
description: "Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.",
|
|
421
|
-
}
|
|
422
549
|
]}
|
|
423
550
|
/>
|
|
424
551
|
|
|
@@ -427,40 +554,9 @@ await agent.generate("message for agent");
|
|
|
427
554
|
<PropertiesTable
|
|
428
555
|
content={[
|
|
429
556
|
{
|
|
430
|
-
name: "
|
|
431
|
-
type: "
|
|
432
|
-
|
|
433
|
-
description: "The generated text response. Present when output is 'text' (no schema provided).",
|
|
434
|
-
},
|
|
435
|
-
{
|
|
436
|
-
name: "object",
|
|
437
|
-
type: "object",
|
|
438
|
-
isOptional: true,
|
|
439
|
-
description: "The generated structured response. Present when a schema is provided via `output`, `structuredOutput`, or `experimental_output`.",
|
|
440
|
-
},
|
|
441
|
-
{
|
|
442
|
-
name: "toolCalls",
|
|
443
|
-
type: "Array<ToolCall>",
|
|
444
|
-
isOptional: true,
|
|
445
|
-
description: "The tool calls made during the generation process. Present in both text and object modes.",
|
|
446
|
-
properties: [
|
|
447
|
-
{
|
|
448
|
-
parameters: [{
|
|
449
|
-
name: "toolName",
|
|
450
|
-
type: "string",
|
|
451
|
-
required: true,
|
|
452
|
-
description: "The name of the tool invoked."
|
|
453
|
-
}]
|
|
454
|
-
},
|
|
455
|
-
{
|
|
456
|
-
parameters: [{
|
|
457
|
-
name: "args",
|
|
458
|
-
type: "any",
|
|
459
|
-
required: true,
|
|
460
|
-
description: "The arguments passed to the tool."
|
|
461
|
-
}]
|
|
462
|
-
}
|
|
463
|
-
]
|
|
557
|
+
name: "result",
|
|
558
|
+
type: "Awaited<ReturnType<MastraModelOutput<Output>['getFullOutput']>> | Awaited<ReturnType<AISDKV5OutputStream<Output>['getFullOutput']>>",
|
|
559
|
+
description: "Returns the full output of the generation process. When format is 'mastra' (default), returns MastraModelOutput result. When format is 'aisdk', returns AISDKV5OutputStream result for AI SDK v5 compatibility.",
|
|
464
560
|
},
|
|
465
561
|
{
|
|
466
562
|
name: "traceId",
|
|
@@ -471,62 +567,3 @@ await agent.generate("message for agent");
|
|
|
471
567
|
]}
|
|
472
568
|
/>
|
|
473
569
|
|
|
474
|
-
## Extended usage example
|
|
475
|
-
|
|
476
|
-
```typescript showLineNumbers copy
|
|
477
|
-
import { z } from "zod";
|
|
478
|
-
import { ModerationProcessor, TokenLimiterProcessor } from "@mastra/core/processors";
|
|
479
|
-
|
|
480
|
-
await agent.generate(
|
|
481
|
-
[
|
|
482
|
-
{ role: "user", content: "message for agent" },
|
|
483
|
-
{
|
|
484
|
-
role: "user",
|
|
485
|
-
content: [
|
|
486
|
-
{
|
|
487
|
-
type: "text",
|
|
488
|
-
text: "message for agent"
|
|
489
|
-
},
|
|
490
|
-
{
|
|
491
|
-
type: "image",
|
|
492
|
-
imageUrl: "https://example.com/image.jpg",
|
|
493
|
-
mimeType: "image/jpeg"
|
|
494
|
-
}
|
|
495
|
-
]
|
|
496
|
-
}
|
|
497
|
-
],
|
|
498
|
-
{
|
|
499
|
-
temperature: 0.7,
|
|
500
|
-
maxSteps: 3,
|
|
501
|
-
memory: {
|
|
502
|
-
thread: "user-123",
|
|
503
|
-
resource: "test-app"
|
|
504
|
-
},
|
|
505
|
-
toolChoice: "auto",
|
|
506
|
-
providerOptions: {
|
|
507
|
-
openai: {
|
|
508
|
-
reasoningEffort: "high"
|
|
509
|
-
}
|
|
510
|
-
},
|
|
511
|
-
// Structured output with better DX
|
|
512
|
-
structuredOutput: {
|
|
513
|
-
schema: z.object({
|
|
514
|
-
sentiment: z.enum(['positive', 'negative', 'neutral']),
|
|
515
|
-
confidence: z.number(),
|
|
516
|
-
}),
|
|
517
|
-
model: openai("gpt-4o-mini"),
|
|
518
|
-
errorStrategy: 'warn',
|
|
519
|
-
},
|
|
520
|
-
// Output processors for response validation
|
|
521
|
-
outputProcessors: [
|
|
522
|
-
new ModerationProcessor({ model: openai("gpt-4.1-nano") }),
|
|
523
|
-
new TokenLimiterProcessor({ maxTokens: 1000 }),
|
|
524
|
-
],
|
|
525
|
-
}
|
|
526
|
-
);
|
|
527
|
-
```
|
|
528
|
-
|
|
529
|
-
## Related
|
|
530
|
-
|
|
531
|
-
- [Generating responses](../../docs/agents/overview.mdx#generating-responses)
|
|
532
|
-
- [Streaming responses](../../docs/agents/overview.mdx#streaming-responses)
|