@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: getDefaultStreamOptions() | Agents | Mastra Docs"
|
|
3
|
+
description: "Documentation for the `.getDefaultStreamOptions()` method in Mastra agents, which retrieves the default options used for stream calls."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# getDefaultStreamOptions()
|
|
7
|
+
|
|
8
|
+
The `.getDefaultStreamOptions()` method retrieves the default streaming options configured for an agent, resolving them if they're a function. These options are used as the base configuration for all `stream()` calls unless overridden.
|
|
9
|
+
|
|
10
|
+
## Usage example
|
|
11
|
+
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const defaultOptions = await agent.getDefaultStreamOptions();
|
|
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 defaultOptions = await agent.getDefaultStreamOptions({
|
|
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: "defaultOptions",
|
|
58
|
+
type: "AgentStreamOptions | Promise<AgentStreamOptions>",
|
|
59
|
+
description: "The default streaming options configured for the agent, either as a direct object or a promise that resolves to the options.",
|
|
60
|
+
},
|
|
61
|
+
]}
|
|
62
|
+
/>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: getDefaultVNextStreamOptions() | Agents | Mastra Docs"
|
|
3
|
+
description: "Documentation for the `.getDefaultVNextStreamOptions()` method in Mastra agents, which retrieves the default options used for streamVNext calls."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# getDefaultVNextStreamOptions()
|
|
7
|
+
|
|
8
|
+
The `.getDefaultVNextStreamOptions()` method retrieves the default vNext streaming options configured for an agent, resolving them if they're a function. These options are used as the base configuration for all `streamVNext()` calls unless overridden.
|
|
9
|
+
|
|
10
|
+
## Usage example
|
|
11
|
+
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const defaultOptions = await agent.getDefaultVNextStreamOptions();
|
|
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 defaultOptions = await agent.getDefaultVNextStreamOptions({
|
|
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: "defaultOptions",
|
|
58
|
+
type: "AgentVNextStreamOptions<Output, StructuredOutput> | Promise<AgentVNextStreamOptions<Output, StructuredOutput>>",
|
|
59
|
+
description: "The default vNext streaming options configured for the agent, either as a direct object or a promise that resolves to the options.",
|
|
60
|
+
},
|
|
61
|
+
]}
|
|
62
|
+
/>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: getDescription() | Agents | Mastra Docs"
|
|
3
|
+
description: "Documentation for the `.getDescription()` method in Mastra agents, which retrieves the agent's description."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# getDescription()
|
|
7
|
+
|
|
8
|
+
The `.getDescription()` method retrieves the description configured for an agent. This method returns a simple string description that describes the agent's purpose and capabilities.
|
|
9
|
+
|
|
10
|
+
## Usage example
|
|
11
|
+
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const description = agent.getDescription();
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Parameters
|
|
17
|
+
|
|
18
|
+
This method takes no parameters.
|
|
19
|
+
|
|
20
|
+
## Returns
|
|
21
|
+
|
|
22
|
+
<PropertiesTable
|
|
23
|
+
content={[
|
|
24
|
+
{
|
|
25
|
+
name: "description",
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "The description of the agent, or an empty string if no description was configured.",
|
|
28
|
+
},
|
|
29
|
+
]}
|
|
30
|
+
/>
|
|
@@ -1,99 +1,62 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "Reference:
|
|
2
|
+
title: "Reference: getInstructions() | Agents | Mastra Docs"
|
|
3
3
|
description: "Documentation for the `.getInstructions()` method in Mastra agents, which retrieves the instructions that guide the agent's behavior."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# getInstructions()
|
|
7
7
|
|
|
8
|
-
The
|
|
8
|
+
The `.getInstructions()` method retrieves the instructions configured for an agent, resolving them if they're a function. These instructions guide the agent's behavior and define its capabilities and constraints.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Usage example
|
|
11
11
|
|
|
12
|
-
```typescript
|
|
13
|
-
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const instructions = await agent.getInstructions();
|
|
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 string or a Promise that resolves to a string containing the agent's instructions.
|
|
34
|
-
|
|
35
|
-
## Description
|
|
36
|
-
|
|
37
|
-
The `getInstructions()` method is used to access the instructions that guide an agent's behavior. It resolves the instructions, which can be either directly provided as a string or returned from a function.
|
|
38
|
-
|
|
39
|
-
Instructions are a critical component of an agent's configuration as they define:
|
|
40
|
-
|
|
41
|
-
- The agent's role and personality
|
|
42
|
-
- Task-specific guidance
|
|
43
|
-
- Constraints on the agent's behavior
|
|
44
|
-
- Context for handling user requests
|
|
45
|
-
|
|
46
|
-
## Examples
|
|
30
|
+
## Extended usage example
|
|
47
31
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
import { Agent } from "@mastra/core/agent";
|
|
52
|
-
import { openai } from "@ai-sdk/openai";
|
|
53
|
-
|
|
54
|
-
// Create an agent with static instructions
|
|
55
|
-
const agent = new Agent({
|
|
56
|
-
name: "assistant",
|
|
57
|
-
instructions:
|
|
58
|
-
"You are a helpful assistant that provides concise and accurate information.",
|
|
59
|
-
model: openai("gpt-4o"),
|
|
32
|
+
```typescript showLineNumbers copy
|
|
33
|
+
const instructions = await agent.getInstructions({
|
|
34
|
+
runtimeContext: new RuntimeContext()
|
|
60
35
|
});
|
|
61
|
-
|
|
62
|
-
// Get the instructions
|
|
63
|
-
const instructions = await agent.getInstructions();
|
|
64
|
-
console.log(instructions); // "You are a helpful assistant that provides concise and accurate information."
|
|
65
36
|
```
|
|
66
37
|
|
|
67
|
-
###
|
|
38
|
+
### Options parameters
|
|
68
39
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const expertise = runtimeContext.get("expertise") || "general";
|
|
81
|
-
|
|
82
|
-
if (userPreference === "technical") {
|
|
83
|
-
return `You are a technical assistant specializing in ${expertise}. Provide detailed technical explanations.`;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return `You are a helpful assistant providing easy-to-understand information about ${expertise}.`;
|
|
87
|
-
},
|
|
88
|
-
model: openai("gpt-4o"),
|
|
89
|
-
});
|
|
40
|
+
<PropertiesTable
|
|
41
|
+
content={[
|
|
42
|
+
{
|
|
43
|
+
name: "runtimeContext",
|
|
44
|
+
type: "RuntimeContext",
|
|
45
|
+
isOptional: true,
|
|
46
|
+
defaultValue: "undefined",
|
|
47
|
+
description: "Runtime context for dependency injection and contextual information.",
|
|
48
|
+
},
|
|
49
|
+
]}
|
|
50
|
+
/>
|
|
90
51
|
|
|
91
|
-
|
|
92
|
-
const context = new RuntimeContext();
|
|
93
|
-
context.set("userPreference", "technical");
|
|
94
|
-
context.set("expertise", "machine learning");
|
|
52
|
+
## Returns
|
|
95
53
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
54
|
+
<PropertiesTable
|
|
55
|
+
content={[
|
|
56
|
+
{
|
|
57
|
+
name: "instructions",
|
|
58
|
+
type: "string | Promise<string>",
|
|
59
|
+
description: "The instructions configured for the agent, either as a direct string or a promise that resolves to the instructions.",
|
|
60
|
+
},
|
|
61
|
+
]}
|
|
62
|
+
/>
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: getLLM() | Agents | Mastra Docs"
|
|
3
|
+
description: "Documentation for the `.getLLM()` method in Mastra agents, which retrieves the language model instance."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# getLLM()
|
|
7
|
+
|
|
8
|
+
The `.getLLM()` method retrieves the language model instance configured for an agent, resolving it if it's a function. This method provides access to the underlying LLM that powers the agent's capabilities.
|
|
9
|
+
|
|
10
|
+
## Usage example
|
|
11
|
+
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const llm = await agent.getLLM();
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Parameters
|
|
17
|
+
|
|
18
|
+
<PropertiesTable
|
|
19
|
+
content={[
|
|
20
|
+
{
|
|
21
|
+
name: "options",
|
|
22
|
+
type: "{ runtimeContext?: RuntimeContext; model?: MastraLanguageModel | DynamicArgument<MastraLanguageModel> }",
|
|
23
|
+
isOptional: true,
|
|
24
|
+
defaultValue: "{}",
|
|
25
|
+
description: "Optional configuration object containing runtime context and optional model override.",
|
|
26
|
+
},
|
|
27
|
+
]}
|
|
28
|
+
/>
|
|
29
|
+
|
|
30
|
+
## Extended usage example
|
|
31
|
+
|
|
32
|
+
```typescript showLineNumbers copy
|
|
33
|
+
const llm = await agent.getLLM({
|
|
34
|
+
runtimeContext: new RuntimeContext(),
|
|
35
|
+
model: openai('gpt-4')
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Options parameters
|
|
40
|
+
|
|
41
|
+
<PropertiesTable
|
|
42
|
+
content={[
|
|
43
|
+
{
|
|
44
|
+
name: "runtimeContext",
|
|
45
|
+
type: "RuntimeContext",
|
|
46
|
+
isOptional: true,
|
|
47
|
+
defaultValue: "new RuntimeContext()",
|
|
48
|
+
description: "Runtime context for dependency injection and contextual information.",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "model",
|
|
52
|
+
type: "MastraLanguageModel | DynamicArgument<MastraLanguageModel>",
|
|
53
|
+
isOptional: true,
|
|
54
|
+
description: "Optional model override. If provided, this model will be used instead of the agent's configured model.",
|
|
55
|
+
},
|
|
56
|
+
]}
|
|
57
|
+
/>
|
|
58
|
+
|
|
59
|
+
## Returns
|
|
60
|
+
|
|
61
|
+
<PropertiesTable
|
|
62
|
+
content={[
|
|
63
|
+
{
|
|
64
|
+
name: "llm",
|
|
65
|
+
type: "MastraLLMBase | Promise<MastraLLMBase>",
|
|
66
|
+
description: "The language model instance configured for the agent, either as a direct instance or a promise that resolves to the LLM.",
|
|
67
|
+
},
|
|
68
|
+
]}
|
|
69
|
+
/>
|
|
@@ -1,139 +1,62 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "Reference:
|
|
2
|
+
title: "Reference: getMemory() | Agents | Mastra Docs"
|
|
3
3
|
description: "Documentation for the `.getMemory()` method in Mastra agents, which retrieves the memory system associated with the agent."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# getMemory()
|
|
7
7
|
|
|
8
|
-
The
|
|
8
|
+
The `.getMemory()` method retrieves the memory system associated with an agent. This method is used to access the agent's memory capabilities for storing and retrieving information across conversations.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Usage example
|
|
11
11
|
|
|
12
|
-
```typescript
|
|
13
|
-
getMemory()
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const memory = await agent.getMemory();
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Parameters
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
- Maintain conversation history
|
|
30
|
-
- Remember user preferences and context
|
|
31
|
-
- Provide personalized responses based on past interactions
|
|
32
|
-
|
|
33
|
-
This method is often used in conjunction with `hasOwnMemory()` to check if an agent has a memory system before attempting to use it.
|
|
34
|
-
|
|
35
|
-
## Examples
|
|
36
|
-
|
|
37
|
-
### Basic Usage
|
|
38
|
-
|
|
39
|
-
```typescript
|
|
40
|
-
import { Agent } from "@mastra/core/agent";
|
|
41
|
-
import { Memory } from "@mastra/memory";
|
|
42
|
-
import { openai } from "@ai-sdk/openai";
|
|
43
|
-
|
|
44
|
-
// Create a memory system
|
|
45
|
-
const memory = new Memory();
|
|
46
|
-
|
|
47
|
-
// Create an agent with memory
|
|
48
|
-
const agent = new Agent({
|
|
49
|
-
name: "memory-assistant",
|
|
50
|
-
instructions:
|
|
51
|
-
"You are a helpful assistant that remembers previous conversations.",
|
|
52
|
-
model: openai("gpt-4o"),
|
|
53
|
-
memory,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// Get the memory system
|
|
57
|
-
const agentMemory = agent.getMemory();
|
|
58
|
-
|
|
59
|
-
if (agentMemory) {
|
|
60
|
-
// Use the memory system to retrieve thread messages
|
|
61
|
-
const thread = await agentMemory.getThreadById({
|
|
62
|
-
resourceId: "user-123",
|
|
63
|
-
threadId: "conversation-1",
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
console.log("Retrieved thread:", thread);
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Checking for Memory Before Using
|
|
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
|
+
/>
|
|
71
29
|
|
|
72
|
-
|
|
73
|
-
import { Agent } from "@mastra/core/agent";
|
|
74
|
-
import { openai } from "@ai-sdk/openai";
|
|
30
|
+
## Extended usage example
|
|
75
31
|
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
instructions: "You are a helpful assistant.",
|
|
80
|
-
model: openai("gpt-4o"),
|
|
32
|
+
```typescript showLineNumbers copy
|
|
33
|
+
const memory = await agent.getMemory({
|
|
34
|
+
runtimeContext: new RuntimeContext()
|
|
81
35
|
});
|
|
82
|
-
|
|
83
|
-
// Check if the agent has memory before using it
|
|
84
|
-
if (agent.hasOwnMemory()) {
|
|
85
|
-
const memory = agent.getMemory();
|
|
86
|
-
// Use memory...
|
|
87
|
-
} else {
|
|
88
|
-
console.log("This agent does not have a memory system.");
|
|
89
|
-
}
|
|
90
36
|
```
|
|
91
37
|
|
|
92
|
-
###
|
|
93
|
-
|
|
94
|
-
```typescript
|
|
95
|
-
import { Agent } from "@mastra/core/agent";
|
|
96
|
-
import { Memory } from "@mastra/memory";
|
|
97
|
-
import { openai } from "@ai-sdk/openai";
|
|
98
|
-
|
|
99
|
-
// Create a memory system
|
|
100
|
-
const memory = new Memory();
|
|
101
|
-
|
|
102
|
-
// Create an agent with memory
|
|
103
|
-
const agent = new Agent({
|
|
104
|
-
name: "memory-assistant",
|
|
105
|
-
instructions:
|
|
106
|
-
"You are a helpful assistant that remembers previous conversations.",
|
|
107
|
-
model: openai("gpt-4o"),
|
|
108
|
-
memory,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// First interaction - store information
|
|
112
|
-
await agent.generate("My name is Alice.", {
|
|
113
|
-
resourceId: "user-123",
|
|
114
|
-
threadId: "conversation-1",
|
|
115
|
-
});
|
|
38
|
+
### Options parameters
|
|
116
39
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
+
/>
|
|
122
51
|
|
|
123
|
-
|
|
52
|
+
## Returns
|
|
124
53
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
threadId: "conversation-1",
|
|
132
|
-
selectBy: {
|
|
133
|
-
last: 10, // Get the last 10 messages
|
|
54
|
+
<PropertiesTable
|
|
55
|
+
content={[
|
|
56
|
+
{
|
|
57
|
+
name: "memory",
|
|
58
|
+
type: "Promise<MastraMemory | undefined>",
|
|
59
|
+
description: "A promise that resolves to the memory system configured for the agent, or undefined if no memory system is configured.",
|
|
134
60
|
},
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
console.log("Retrieved messages:", messages);
|
|
138
|
-
}
|
|
139
|
-
```
|
|
61
|
+
]}
|
|
62
|
+
/>
|
|
@@ -1,101 +1,62 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "Reference:
|
|
2
|
+
title: "Reference: getModel() | Agents | Mastra Docs"
|
|
3
3
|
description: "Documentation for the `.getModel()` method in Mastra agents, which retrieves the language model that powers the agent."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# getModel()
|
|
7
7
|
|
|
8
|
-
The
|
|
8
|
+
The `.getModel()` method retrieves the language model configured for an agent, resolving it if it's a function. This method is used to access the underlying model that powers the agent's capabilities.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Usage example
|
|
11
11
|
|
|
12
|
-
```typescript
|
|
13
|
-
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const model = await agent.getModel();
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Parameters
|
|
17
17
|
|
|
18
|
-
<br />
|
|
19
18
|
<PropertiesTable
|
|
20
19
|
content={[
|
|
21
20
|
{
|
|
22
|
-
name: "runtimeContext",
|
|
23
|
-
type: "RuntimeContext",
|
|
21
|
+
name: "{ runtimeContext = new RuntimeContext() }",
|
|
22
|
+
type: "{ runtimeContext?: RuntimeContext }",
|
|
24
23
|
isOptional: true,
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
defaultValue: "new RuntimeContext()",
|
|
25
|
+
description: "Optional configuration object containing runtime context.",
|
|
27
26
|
},
|
|
28
27
|
]}
|
|
29
28
|
/>
|
|
30
29
|
|
|
31
|
-
##
|
|
32
|
-
|
|
33
|
-
Returns a `MastraLanguageModel` instance or a Promise that resolves to a `MastraLanguageModel` instance.
|
|
34
|
-
|
|
35
|
-
## Description
|
|
36
|
-
|
|
37
|
-
The `getModel()` method is used to access the language model that powers an agent. It resolves the model, which can be either directly provided or returned from a function.
|
|
38
|
-
|
|
39
|
-
The language model is a crucial component of an agent as it determines:
|
|
40
|
-
|
|
41
|
-
- The quality and capabilities of the agent's responses
|
|
42
|
-
- The available features (like function calling, structured output, etc.)
|
|
43
|
-
- The cost and performance characteristics of the agent
|
|
44
|
-
|
|
45
|
-
## Examples
|
|
30
|
+
## Extended usage example
|
|
46
31
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
import { Agent } from "@mastra/core/agent";
|
|
51
|
-
import { openai } from "@ai-sdk/openai";
|
|
52
|
-
|
|
53
|
-
// Create an agent with a static model
|
|
54
|
-
const agent = new Agent({
|
|
55
|
-
name: "assistant",
|
|
56
|
-
instructions: "You are a helpful assistant.",
|
|
57
|
-
model: openai("gpt-4o"),
|
|
32
|
+
```typescript showLineNumbers copy
|
|
33
|
+
const model = await agent.getModel({
|
|
34
|
+
runtimeContext: new RuntimeContext()
|
|
58
35
|
});
|
|
59
|
-
|
|
60
|
-
// Get the model
|
|
61
|
-
const model = await agent.getModel();
|
|
62
|
-
console.log(model.id); // "gpt-4o"
|
|
63
36
|
```
|
|
64
37
|
|
|
65
|
-
###
|
|
38
|
+
### Options parameters
|
|
66
39
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// Dynamic model selection based on runtime context
|
|
79
|
-
const preferredProvider = runtimeContext.get("preferredProvider");
|
|
80
|
-
const highQuality = runtimeContext.get("highQuality") === true;
|
|
81
|
-
|
|
82
|
-
if (preferredProvider === "anthropic") {
|
|
83
|
-
return highQuality
|
|
84
|
-
? anthropic("claude-3-opus")
|
|
85
|
-
: anthropic("claude-3-sonnet");
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Default to OpenAI
|
|
89
|
-
return highQuality ? openai("gpt-4o") : openai("gpt-4.1-nano");
|
|
90
|
-
},
|
|
91
|
-
});
|
|
40
|
+
<PropertiesTable
|
|
41
|
+
content={[
|
|
42
|
+
{
|
|
43
|
+
name: "runtimeContext",
|
|
44
|
+
type: "RuntimeContext",
|
|
45
|
+
isOptional: true,
|
|
46
|
+
defaultValue: "undefined",
|
|
47
|
+
description: "Runtime context for dependency injection and contextual information.",
|
|
48
|
+
},
|
|
49
|
+
]}
|
|
50
|
+
/>
|
|
92
51
|
|
|
93
|
-
|
|
94
|
-
const context = new RuntimeContext();
|
|
95
|
-
context.set("preferredProvider", "anthropic");
|
|
96
|
-
context.set("highQuality", true);
|
|
52
|
+
## Returns
|
|
97
53
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
54
|
+
<PropertiesTable
|
|
55
|
+
content={[
|
|
56
|
+
{
|
|
57
|
+
name: "model",
|
|
58
|
+
type: "MastraLanguageModel | Promise<MastraLanguageModel>",
|
|
59
|
+
description: "The language model configured for the agent, either as a direct instance or a promise that resolves to the model.",
|
|
60
|
+
},
|
|
61
|
+
]}
|
|
62
|
+
/>
|