@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
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: getScorers() | Agents | Mastra Docs"
|
|
3
|
+
description: "Documentation for the `.getScorers()` method in Mastra agents, which retrieves the scoring configuration."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# getScorers()
|
|
7
|
+
|
|
8
|
+
The `.getScorers()` method retrieves the scoring configuration configured for an agent, resolving it if it's a function. This method provides access to the scoring system used for evaluating agent responses and performance.
|
|
9
|
+
|
|
10
|
+
## Usage example
|
|
11
|
+
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const scorers = await agent.getScorers();
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Parameters
|
|
17
|
+
|
|
18
|
+
<PropertiesTable
|
|
19
|
+
content={[
|
|
20
|
+
{
|
|
21
|
+
name: "options",
|
|
22
|
+
type: "{ runtimeContext?: RuntimeContext }",
|
|
23
|
+
isOptional: true,
|
|
24
|
+
defaultValue: "{}",
|
|
25
|
+
description: "Optional configuration object containing runtime context.",
|
|
26
|
+
},
|
|
27
|
+
]}
|
|
28
|
+
/>
|
|
29
|
+
|
|
30
|
+
## Extended usage example
|
|
31
|
+
|
|
32
|
+
```typescript showLineNumbers copy
|
|
33
|
+
const scorers = await agent.getScorers({
|
|
34
|
+
runtimeContext: new RuntimeContext()
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Options parameters
|
|
39
|
+
|
|
40
|
+
<PropertiesTable
|
|
41
|
+
content={[
|
|
42
|
+
{
|
|
43
|
+
name: "runtimeContext",
|
|
44
|
+
type: "RuntimeContext",
|
|
45
|
+
isOptional: true,
|
|
46
|
+
defaultValue: "new RuntimeContext()",
|
|
47
|
+
description: "Runtime context for dependency injection and contextual information.",
|
|
48
|
+
},
|
|
49
|
+
]}
|
|
50
|
+
/>
|
|
51
|
+
|
|
52
|
+
## Returns
|
|
53
|
+
|
|
54
|
+
<PropertiesTable
|
|
55
|
+
content={[
|
|
56
|
+
{
|
|
57
|
+
name: "scorers",
|
|
58
|
+
type: "MastraScorers | Promise<MastraScorers>",
|
|
59
|
+
description: "The scoring configuration configured for the agent, either as a direct object or a promise that resolves to the scorers.",
|
|
60
|
+
},
|
|
61
|
+
]}
|
|
62
|
+
/>
|
|
@@ -1,154 +1,62 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "Reference:
|
|
2
|
+
title: "Reference: getTools() | Agents | Mastra Docs"
|
|
3
3
|
description: "Documentation for the `.getTools()` method in Mastra agents, which retrieves the tools that the agent can use."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# getTools()
|
|
7
7
|
|
|
8
|
-
The
|
|
8
|
+
The `.getTools()` method retrieves the tools configured for an agent, resolving them if they're a function. These tools extend the agent's capabilities, allowing it to perform specific actions or access external systems.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Usage example
|
|
11
11
|
|
|
12
|
-
```typescript
|
|
13
|
-
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const tools = await agent.getTools();
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Parameters
|
|
17
17
|
|
|
18
|
-
<br />
|
|
19
18
|
<PropertiesTable
|
|
20
19
|
content={[
|
|
21
20
|
{
|
|
22
|
-
name: "
|
|
23
|
-
type: "RuntimeContext",
|
|
21
|
+
name: "options",
|
|
22
|
+
type: "{ runtimeContext?: RuntimeContext }",
|
|
24
23
|
isOptional: true,
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
defaultValue: "{}",
|
|
25
|
+
description: "Optional configuration object containing runtime context.",
|
|
27
26
|
},
|
|
28
27
|
]}
|
|
29
28
|
/>
|
|
30
29
|
|
|
31
|
-
##
|
|
32
|
-
|
|
33
|
-
Returns a `ToolsInput` object or a Promise that resolves to a `ToolsInput` object containing the agent's tools.
|
|
34
|
-
|
|
35
|
-
## Description
|
|
36
|
-
|
|
37
|
-
The `getTools()` method is used to access the tools that an agent can use. It resolves the tools, which can be either directly provided as an object or returned from a function.
|
|
38
|
-
|
|
39
|
-
Tools are a key component of an agent's capabilities, allowing it to:
|
|
40
|
-
|
|
41
|
-
- Perform specific actions (like fetching data or making calculations)
|
|
42
|
-
- Access external systems and APIs
|
|
43
|
-
- Execute code or commands
|
|
44
|
-
- Interact with databases or other services
|
|
45
|
-
|
|
46
|
-
## Examples
|
|
47
|
-
|
|
48
|
-
### Basic Usage
|
|
30
|
+
## Extended usage example
|
|
49
31
|
|
|
50
|
-
```typescript
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
import { openai } from "@ai-sdk/openai";
|
|
54
|
-
import { z } from "zod";
|
|
55
|
-
|
|
56
|
-
// Create tools using createTool
|
|
57
|
-
const addTool = createTool({
|
|
58
|
-
id: "add",
|
|
59
|
-
description: "Add two numbers",
|
|
60
|
-
inputSchema: z.object({
|
|
61
|
-
a: z.number().describe("First number"),
|
|
62
|
-
b: z.number().describe("Second number"),
|
|
63
|
-
}),
|
|
64
|
-
outputSchema: z.number(),
|
|
65
|
-
execute: async ({ context }) => {
|
|
66
|
-
return context.a + context.b;
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const multiplyTool = createTool({
|
|
71
|
-
id: "multiply",
|
|
72
|
-
description: "Multiply two numbers",
|
|
73
|
-
inputSchema: z.object({
|
|
74
|
-
a: z.number().describe("First number"),
|
|
75
|
-
b: z.number().describe("Second number"),
|
|
76
|
-
}),
|
|
77
|
-
outputSchema: z.number(),
|
|
78
|
-
execute: async ({ context }) => {
|
|
79
|
-
return context.a * context.b;
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// Create an agent with the tools
|
|
84
|
-
const agent = new Agent({
|
|
85
|
-
name: "calculator",
|
|
86
|
-
instructions:
|
|
87
|
-
"You are a calculator assistant that can perform mathematical operations.",
|
|
88
|
-
model: openai("gpt-4o"),
|
|
89
|
-
tools: {
|
|
90
|
-
add: addTool,
|
|
91
|
-
multiply: multiplyTool,
|
|
92
|
-
},
|
|
32
|
+
```typescript showLineNumbers copy
|
|
33
|
+
const tools = await agent.getTools({
|
|
34
|
+
runtimeContext: new RuntimeContext()
|
|
93
35
|
});
|
|
94
|
-
|
|
95
|
-
// Get the tools
|
|
96
|
-
const tools = await agent.getTools();
|
|
97
|
-
console.log(Object.keys(tools)); // ["add", "multiply"]
|
|
98
36
|
```
|
|
99
37
|
|
|
100
|
-
###
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
import { Agent } from "@mastra/core/agent";
|
|
104
|
-
import { createTool } from "@mastra/core/tools";
|
|
105
|
-
import { RuntimeContext } from "@mastra/core/runtime-context";
|
|
106
|
-
import { openai } from "@ai-sdk/openai";
|
|
107
|
-
import { z } from "zod";
|
|
108
|
-
|
|
109
|
-
// Create an agent with dynamic tools
|
|
110
|
-
const agent = new Agent({
|
|
111
|
-
name: "weather-assistant",
|
|
112
|
-
instructions:
|
|
113
|
-
"You are a weather assistant that can provide weather information.",
|
|
114
|
-
model: openai("gpt-4o"),
|
|
115
|
-
tools: ({ runtimeContext }) => {
|
|
116
|
-
// Get API key from runtime context
|
|
117
|
-
const apiKey = runtimeContext.get("weatherApiKey");
|
|
38
|
+
### Options parameters
|
|
118
39
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
windSpeed: z.number(),
|
|
131
|
-
}),
|
|
132
|
-
execute: async ({ context }) => {
|
|
133
|
-
// Use the API key from runtime context
|
|
134
|
-
const response = await fetch(
|
|
135
|
-
`https://api.weather.com/current?location=${context.location}&apiKey=${apiKey}`,
|
|
136
|
-
);
|
|
137
|
-
return response.json();
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
getWeather: weatherTool,
|
|
143
|
-
};
|
|
144
|
-
},
|
|
145
|
-
});
|
|
40
|
+
<PropertiesTable
|
|
41
|
+
content={[
|
|
42
|
+
{
|
|
43
|
+
name: "runtimeContext",
|
|
44
|
+
type: "RuntimeContext",
|
|
45
|
+
isOptional: true,
|
|
46
|
+
defaultValue: "new RuntimeContext()",
|
|
47
|
+
description: "Runtime context for dependency injection and contextual information.",
|
|
48
|
+
},
|
|
49
|
+
]}
|
|
50
|
+
/>
|
|
146
51
|
|
|
147
|
-
|
|
148
|
-
const context = new RuntimeContext();
|
|
149
|
-
context.set("weatherApiKey", "your-api-key");
|
|
52
|
+
## Returns
|
|
150
53
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
54
|
+
<PropertiesTable
|
|
55
|
+
content={[
|
|
56
|
+
{
|
|
57
|
+
name: "tools",
|
|
58
|
+
type: "TTools | Promise<TTools>",
|
|
59
|
+
description: "The tools configured for the agent, either as a direct object or a promise that resolves to the tools.",
|
|
60
|
+
},
|
|
61
|
+
]}
|
|
62
|
+
/>
|
|
@@ -1,109 +1,62 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "Reference:
|
|
2
|
+
title: "Reference: getVoice() | Agents | Mastra Docs"
|
|
3
3
|
description: "Documentation for the `.getVoice()` method in Mastra agents, which retrieves the voice provider for speech capabilities."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# getVoice()
|
|
7
7
|
|
|
8
|
-
The
|
|
8
|
+
The `.getVoice()` method retrieves the voice provider configured for an agent, resolving it if it's a function. This method is used to access the agent's speech capabilities for text-to-speech and speech-to-text functionality.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Usage example
|
|
11
11
|
|
|
12
|
-
```typescript
|
|
13
|
-
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const voice = await agent.getVoice();
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Parameters
|
|
17
17
|
|
|
18
|
-
<br />
|
|
19
18
|
<PropertiesTable
|
|
20
19
|
content={[
|
|
21
20
|
{
|
|
22
|
-
name: "
|
|
23
|
-
type: "RuntimeContext",
|
|
21
|
+
name: "options",
|
|
22
|
+
type: "{ runtimeContext?: RuntimeContext }",
|
|
24
23
|
isOptional: true,
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
defaultValue: "{}",
|
|
25
|
+
description: "Optional configuration object containing runtime context.",
|
|
27
26
|
},
|
|
28
27
|
]}
|
|
29
28
|
/>
|
|
30
29
|
|
|
31
|
-
##
|
|
32
|
-
|
|
33
|
-
Returns a `CompositeVoice` instance or a Promise that resolves to a `CompositeVoice` instance. If no voice provider was configured for the agent, it returns a default voice provider.
|
|
34
|
-
|
|
35
|
-
## Description
|
|
36
|
-
|
|
37
|
-
The `getVoice()` method is used to access the voice capabilities of an agent. It resolves the voice provider, which can be either directly provided or returned from a function.
|
|
38
|
-
|
|
39
|
-
The voice provider enables:
|
|
40
|
-
|
|
41
|
-
- Text-to-speech conversion (speaking)
|
|
42
|
-
- Speech-to-text conversion (listening)
|
|
43
|
-
- Retrieving available speakers/voices
|
|
44
|
-
|
|
45
|
-
## Examples
|
|
30
|
+
## Extended usage example
|
|
46
31
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
import { Agent } from "@mastra/core/agent";
|
|
51
|
-
import { ElevenLabsVoice } from "@mastra/voice-elevenlabs";
|
|
52
|
-
import { openai } from "@ai-sdk/openai";
|
|
53
|
-
|
|
54
|
-
// Create an agent with a voice provider
|
|
55
|
-
const agent = new Agent({
|
|
56
|
-
name: "voice-assistant",
|
|
57
|
-
instructions: "You are a helpful voice assistant.",
|
|
58
|
-
model: openai("gpt-4o"),
|
|
59
|
-
voice: new ElevenLabsVoice({
|
|
60
|
-
apiKey: process.env.ELEVENLABS_API_KEY,
|
|
61
|
-
}),
|
|
32
|
+
```typescript showLineNumbers copy
|
|
33
|
+
const voice = await agent.getVoice({
|
|
34
|
+
runtimeContext: new RuntimeContext()
|
|
62
35
|
});
|
|
63
|
-
|
|
64
|
-
// Get the voice provider
|
|
65
|
-
const voice = await agent.getVoice();
|
|
66
|
-
|
|
67
|
-
// Use the voice provider for text-to-speech
|
|
68
|
-
const audioStream = await voice.speak("Hello, how can I help you today?");
|
|
69
|
-
|
|
70
|
-
// Use the voice provider for speech-to-text
|
|
71
|
-
const transcription = await voice.listen(audioStream);
|
|
72
|
-
|
|
73
|
-
// Get available speakers
|
|
74
|
-
const speakers = await voice.getSpeakers();
|
|
75
|
-
console.log(speakers);
|
|
76
36
|
```
|
|
77
37
|
|
|
78
|
-
###
|
|
38
|
+
### Options parameters
|
|
79
39
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const instructions = runtimeContext.get("preferredVoiceInstructions");
|
|
92
|
-
return instructions || "You are a helpful voice assistant.";
|
|
93
|
-
},
|
|
94
|
-
model: openai("gpt-4o"),
|
|
95
|
-
voice: new ElevenLabsVoice({
|
|
96
|
-
apiKey: process.env.ELEVENLABS_API_KEY,
|
|
97
|
-
}),
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// Create a runtime context with preferences
|
|
101
|
-
const context = new RuntimeContext();
|
|
102
|
-
context.set("preferredVoiceInstructions", "You are an evil voice assistant");
|
|
40
|
+
<PropertiesTable
|
|
41
|
+
content={[
|
|
42
|
+
{
|
|
43
|
+
name: "runtimeContext",
|
|
44
|
+
type: "RuntimeContext",
|
|
45
|
+
isOptional: true,
|
|
46
|
+
defaultValue: "new RuntimeContext()",
|
|
47
|
+
description: "Runtime context for dependency injection and contextual information.",
|
|
48
|
+
},
|
|
49
|
+
]}
|
|
50
|
+
/>
|
|
103
51
|
|
|
104
|
-
|
|
105
|
-
const voice = await agent.getVoice({ runtimeContext: context });
|
|
52
|
+
## Returns
|
|
106
53
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
54
|
+
<PropertiesTable
|
|
55
|
+
content={[
|
|
56
|
+
{
|
|
57
|
+
name: "voice",
|
|
58
|
+
type: "Promise<MastraVoice>",
|
|
59
|
+
description: "A promise that resolves to the voice provider configured for the agent, or a default voice provider if none was configured.",
|
|
60
|
+
},
|
|
61
|
+
]}
|
|
62
|
+
/>
|
|
@@ -1,99 +1,62 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "Reference:
|
|
2
|
+
title: "Reference: getWorkflows() | Agents | Mastra Docs"
|
|
3
3
|
description: "Documentation for the `.getWorkflows()` method in Mastra agents, which retrieves the workflows that the agent can execute."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# getWorkflows()
|
|
7
7
|
|
|
8
|
-
The
|
|
8
|
+
The `.getWorkflows()` method retrieves the workflows configured for an agent, resolving them if they're a function. These workflows enable the agent to execute complex, multi-step processes with defined execution paths.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Usage example
|
|
11
11
|
|
|
12
|
-
```typescript
|
|
13
|
-
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const workflows = await agent.getWorkflows();
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Parameters
|
|
17
17
|
|
|
18
|
-
<br />
|
|
19
18
|
<PropertiesTable
|
|
20
19
|
content={[
|
|
21
20
|
{
|
|
22
|
-
name: "
|
|
23
|
-
type: "RuntimeContext",
|
|
21
|
+
name: "options",
|
|
22
|
+
type: "{ runtimeContext?: RuntimeContext }",
|
|
24
23
|
isOptional: true,
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
defaultValue: "{}",
|
|
25
|
+
description: "Optional configuration object containing runtime context.",
|
|
27
26
|
},
|
|
28
27
|
]}
|
|
29
28
|
/>
|
|
30
29
|
|
|
31
|
-
##
|
|
32
|
-
|
|
33
|
-
Returns a `Record<string, NewWorkflow>` object or a Promise that resolves to a `Record<string, NewWorkflow>` object containing the agent's workflows.
|
|
34
|
-
|
|
35
|
-
## Description
|
|
36
|
-
|
|
37
|
-
The `getWorkflows()` method is used to access the workflows that an agent can execute. It resolves the workflows, which can be either directly provided as an object or returned from a function that receives runtime context.
|
|
38
|
-
|
|
39
|
-
## Examples
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
import { Agent } from "@mastra/core/agent";
|
|
43
|
-
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
44
|
-
import { openai } from "@ai-sdk/openai";
|
|
45
|
-
import { z } from "zod";
|
|
46
|
-
|
|
47
|
-
const generateSuggestionsStep = createStep({
|
|
48
|
-
id: "generate-suggestions",
|
|
49
|
-
inputSchema: z.object({
|
|
50
|
-
topic: z.string().describe("The topic to research"),
|
|
51
|
-
}),
|
|
52
|
-
outputSchema: z.object({
|
|
53
|
-
summary: z.string(),
|
|
54
|
-
}),
|
|
55
|
-
execute: async ({ inputData, mastra }) => {
|
|
56
|
-
const researchAgent = mastra?.getAgent("researchAgent");
|
|
30
|
+
## Extended usage example
|
|
57
31
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const { topic } = inputData;
|
|
63
|
-
|
|
64
|
-
const result = await researchAgent.generate([
|
|
65
|
-
{ role: "assistant", content: topic },
|
|
66
|
-
]);
|
|
67
|
-
|
|
68
|
-
return { summary: result.text };
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const researchWorkflow = createWorkflow({
|
|
73
|
-
id: "research-workflow",
|
|
74
|
-
inputSchema: z.object({
|
|
75
|
-
topic: z.string().describe("The topic to research"),
|
|
76
|
-
}),
|
|
77
|
-
outputSchema: z.object({
|
|
78
|
-
summary: z.string(),
|
|
79
|
-
}),
|
|
32
|
+
```typescript showLineNumbers copy
|
|
33
|
+
const workflows = await agent.getWorkflows({
|
|
34
|
+
runtimeContext: new RuntimeContext()
|
|
80
35
|
});
|
|
36
|
+
```
|
|
81
37
|
|
|
82
|
-
|
|
38
|
+
### Options parameters
|
|
83
39
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
40
|
+
<PropertiesTable
|
|
41
|
+
content={[
|
|
42
|
+
{
|
|
43
|
+
name: "runtimeContext",
|
|
44
|
+
type: "RuntimeContext",
|
|
45
|
+
isOptional: true,
|
|
46
|
+
defaultValue: "new RuntimeContext()",
|
|
47
|
+
description: "Runtime context for dependency injection and contextual information.",
|
|
48
|
+
},
|
|
49
|
+
]}
|
|
50
|
+
/>
|
|
94
51
|
|
|
95
|
-
|
|
96
|
-
const workflows = await agent.getWorkflows();
|
|
52
|
+
## Returns
|
|
97
53
|
|
|
98
|
-
|
|
99
|
-
|
|
54
|
+
<PropertiesTable
|
|
55
|
+
content={[
|
|
56
|
+
{
|
|
57
|
+
name: "workflows",
|
|
58
|
+
type: "Promise<Record<string, Workflow>>",
|
|
59
|
+
description: "A promise that resolves to a record of workflow names to their corresponding Workflow instances.",
|
|
60
|
+
},
|
|
61
|
+
]}
|
|
62
|
+
/>
|