@mastra/mcp-docs-server 1.1.37-alpha.1 → 1.1.37-alpha.5
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/docs/agents/processors.md +10 -0
- package/.docs/docs/deployment/cloud-providers.md +1 -0
- package/.docs/docs/mastra-platform/observability.md +31 -1
- package/.docs/docs/memory/observational-memory.md +34 -0
- package/.docs/docs/voice/overview.md +76 -0
- package/.docs/guides/deployment/aws-bedrock-agentcore.md +432 -0
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/nearai.md +103 -0
- package/.docs/models/providers/opencode.md +2 -3
- package/.docs/models/providers/siliconflow.md +3 -1
- package/.docs/models/providers/xpersona.md +71 -0
- package/.docs/models/providers.md +2 -0
- package/.docs/reference/agents/agent.md +2 -0
- package/.docs/reference/agents/getMetadata.md +61 -0
- package/.docs/reference/cli/mastra.md +115 -3
- package/.docs/reference/index.md +2 -0
- package/.docs/reference/processors/processor-interface.md +148 -71
- package/.docs/reference/voice/xai-realtime.md +267 -0
- package/.docs/reference/workspace/docker-sandbox.md +60 -0
- package/CHANGELOG.md +21 -0
- package/dist/stdio.js +5 -5
- package/dist/stdio.js.map +1 -1
- package/package.json +4 -4
|
@@ -227,6 +227,16 @@ The method receives `prompt`, `model`, `stepNumber`, `steps`, `state`, and the s
|
|
|
227
227
|
|
|
228
228
|
See the [`Processor` reference](https://mastra.ai/reference/processors/processor-interface) for all available arguments and return types.
|
|
229
229
|
|
|
230
|
+
### Act on the LLM response after the provider call
|
|
231
|
+
|
|
232
|
+
Use `processLLMResponse()` to act on the completed LLM response after the step finishes and stream chunks have been collected. This hook pairs with `processLLMRequest()`: stash state (such as a cache key) in the request hook, then read it back in the response hook to perform side effects like writing to a cache.
|
|
233
|
+
|
|
234
|
+
The `state` object is the same instance passed to `processLLMRequest()` for the same step. When `fromCache` is `true`, the response was replayed from a cache rather than produced by a live model call — processors that write to a cache should skip writes in this case.
|
|
235
|
+
|
|
236
|
+
The method receives `chunks`, `model`, `stepNumber`, `steps`, `state`, `fromCache`, and the shared processor context.
|
|
237
|
+
|
|
238
|
+
See the [`Processor` reference](https://mastra.ai/reference/processors/processor-interface) for all available arguments and return types.
|
|
239
|
+
|
|
230
240
|
### Use the `prepareStep()` callback
|
|
231
241
|
|
|
232
242
|
The `prepareStep()` callback on `generate()` or `stream()` is a shorthand for `processInputStep()`. Internally, Mastra wraps it in a processor that calls your function at each step. It accepts the same arguments and return type as `processInputStep()`, but doesn't require creating a class:
|
|
@@ -10,6 +10,7 @@ Mastra provides a platform to deploy your server to the cloud. Read the [Mastra
|
|
|
10
10
|
|
|
11
11
|
The following guides show how to deploy Mastra to specific cloud providers:
|
|
12
12
|
|
|
13
|
+
- [Amazon Bedrock AgentCore](https://mastra.ai/guides/deployment/aws-bedrock-agentcore)
|
|
13
14
|
- [Amazon EC2](https://mastra.ai/guides/deployment/amazon-ec2)
|
|
14
15
|
- [AWS Lambda](https://mastra.ai/guides/deployment/aws-lambda)
|
|
15
16
|
- [Azure App Services](https://mastra.ai/guides/deployment/azure-app-services)
|
|
@@ -96,4 +96,34 @@ export const mastra = new Mastra({
|
|
|
96
96
|
})
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
See [Mastra platform configuration](https://mastra.ai/docs/mastra-platform/configuration) for the environment variables used by platform observability.
|
|
99
|
+
See [Mastra platform configuration](https://mastra.ai/docs/mastra-platform/configuration) for the environment variables used by platform observability.
|
|
100
|
+
|
|
101
|
+
## Query observability data
|
|
102
|
+
|
|
103
|
+
After your project is publishing traces, logs, or scores to Mastra Platform Observability, you can query that data from your terminal with the Mastra CLI or with `curl`.
|
|
104
|
+
|
|
105
|
+
**npm**:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npx mastra api trace list --pretty
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**pnpm**:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pnpm dlx mastra api trace list --pretty
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Yarn**:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
yarn dlx mastra api trace list --pretty
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Bun**:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
bun x mastra api trace list --pretty
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
For observability commands, the CLI targets the hosted observability API and can infer credentials from your project environment. See the [`mastra api` CLI reference](https://mastra.ai/reference/cli/mastra) for available observability commands, filtering, pagination, credential resolution, and direct `curl` examples.
|
|
@@ -392,6 +392,40 @@ OM caches token estimates in message metadata to reduce repeat counting work dur
|
|
|
392
392
|
- Message and conversation overhead are still recalculated on every pass. The cache only stores payload estimates, so counting semantics stay the same.
|
|
393
393
|
- `data-*` and `reasoning` parts are still skipped and aren't cached.
|
|
394
394
|
|
|
395
|
+
### Caller-supplied token estimates for file parts
|
|
396
|
+
|
|
397
|
+
You can attach a token estimate directly to an `image` or `file` part using `providerMetadata.mastra.tokenEstimate`. The Token Counter honors this value verbatim and skips its own estimator:
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
const filePart = {
|
|
401
|
+
type: 'file',
|
|
402
|
+
data: 'storage://bucket/large-report.pdf',
|
|
403
|
+
mimeType: 'application/pdf',
|
|
404
|
+
filename: 'large-report.pdf',
|
|
405
|
+
providerMetadata: {
|
|
406
|
+
mastra: {
|
|
407
|
+
tokenEstimate: {
|
|
408
|
+
v: 0,
|
|
409
|
+
source: 'client',
|
|
410
|
+
key: 'client',
|
|
411
|
+
tokens: 100_000,
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
},
|
|
415
|
+
}
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
The `tokenEstimate` object follows the same shape the Token Counter uses internally for cached estimates:
|
|
419
|
+
|
|
420
|
+
- `v` — cache schema version. Set to `0`. Caller-supplied entries are exempt from the framework's version check, so the value isn't read.
|
|
421
|
+
- `source` — cache lineage marker. Must be `'client'`. This is what tells the Token Counter the entry is authoritative and should be honored verbatim instead of being recomputed or overwritten.
|
|
422
|
+
- `key` — content fingerprint slot. Set to `'client'`. Framework entries use a content hash here so they invalidate when the payload changes; the `'client'` sentinel keeps caller estimates stable across writes.
|
|
423
|
+
- `tokens` — the token count to use. Must be a finite non-negative number.
|
|
424
|
+
|
|
425
|
+
Additional notes:
|
|
426
|
+
|
|
427
|
+
- The estimate is only honored on `image` and `file` parts. `text` and `tool-invocation` parts are always counted normally, even if they carry a `tokenEstimate`.
|
|
428
|
+
|
|
395
429
|
## Async buffering
|
|
396
430
|
|
|
397
431
|
Without async buffering, the Observer runs synchronously when the message threshold is reached — the agent pauses mid-conversation while the Observer LLM call completes. With async buffering (enabled by default), observations are pre-computed in the background as the conversation grows. When the threshold is hit, buffered observations activate instantly with no pause.
|
|
@@ -686,6 +686,49 @@ await voiceAgent.voice.send(micStream)
|
|
|
686
686
|
|
|
687
687
|
Visit the [AWS Nova Sonic Reference](https://mastra.ai/reference/voice/aws-nova-sonic) for more information on the AWS Nova Sonic voice provider.
|
|
688
688
|
|
|
689
|
+
**xAI**:
|
|
690
|
+
|
|
691
|
+
```typescript
|
|
692
|
+
import { Agent } from '@mastra/core/agent'
|
|
693
|
+
import { playAudio, getMicrophoneStream } from '@mastra/node-audio'
|
|
694
|
+
import { XAIRealtimeVoice } from '@mastra/voice-xai-realtime'
|
|
695
|
+
|
|
696
|
+
const voiceAgent = new Agent({
|
|
697
|
+
id: 'voice-agent',
|
|
698
|
+
name: 'Voice Agent',
|
|
699
|
+
instructions: 'You are a voice assistant that can help users with their tasks.',
|
|
700
|
+
model: 'xai/grok-4.3',
|
|
701
|
+
voice: new XAIRealtimeVoice({
|
|
702
|
+
apiKey: process.env.XAI_API_KEY,
|
|
703
|
+
model: 'grok-voice-think-fast-1.0',
|
|
704
|
+
speaker: 'eve',
|
|
705
|
+
turnDetection: { type: 'server_vad' },
|
|
706
|
+
}),
|
|
707
|
+
})
|
|
708
|
+
|
|
709
|
+
// Connect before using speak/send
|
|
710
|
+
await voiceAgent.voice.connect()
|
|
711
|
+
|
|
712
|
+
// Listen for agent audio responses
|
|
713
|
+
voiceAgent.voice.on('speaker', audioStream => {
|
|
714
|
+
playAudio(audioStream)
|
|
715
|
+
})
|
|
716
|
+
|
|
717
|
+
// Listen for text responses and transcriptions
|
|
718
|
+
voiceAgent.voice.on('writing', ({ text, role }) => {
|
|
719
|
+
console.log(`${role}: ${text}`)
|
|
720
|
+
})
|
|
721
|
+
|
|
722
|
+
// Initiate the conversation
|
|
723
|
+
await voiceAgent.voice.speak('How can I help you today?')
|
|
724
|
+
|
|
725
|
+
// Send continuous audio from the microphone
|
|
726
|
+
const micStream = getMicrophoneStream()
|
|
727
|
+
await voiceAgent.voice.send(micStream)
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
Visit the [xAI Realtime Voice Reference](https://mastra.ai/reference/voice/xai-realtime) for more information on the xAI voice provider.
|
|
731
|
+
|
|
689
732
|
## Voice configuration
|
|
690
733
|
|
|
691
734
|
Each voice provider can be configured with different models and options. Below are the detailed configuration options for all supported providers:
|
|
@@ -938,6 +981,38 @@ const voice = new OpenAIRealtimeVoice({
|
|
|
938
981
|
|
|
939
982
|
For more information on the OpenAI Realtime voice provider, refer to the [OpenAI Realtime Voice Reference](https://mastra.ai/reference/voice/openai-realtime).
|
|
940
983
|
|
|
984
|
+
**xAI Realtime**:
|
|
985
|
+
|
|
986
|
+
```typescript
|
|
987
|
+
// xAI Realtime Voice Configuration
|
|
988
|
+
const voice = new XAIRealtimeVoice({
|
|
989
|
+
apiKey: process.env.XAI_API_KEY,
|
|
990
|
+
model: 'grok-voice-think-fast-1.0',
|
|
991
|
+
speaker: 'eve',
|
|
992
|
+
instructions: 'You are a concise voice assistant.',
|
|
993
|
+
turnDetection: {
|
|
994
|
+
type: 'server_vad',
|
|
995
|
+
threshold: 0.85,
|
|
996
|
+
silence_duration_ms: 1000,
|
|
997
|
+
prefix_padding_ms: 333,
|
|
998
|
+
},
|
|
999
|
+
audio: {
|
|
1000
|
+
input: { format: { type: 'audio/pcm', rate: 24000 } },
|
|
1001
|
+
output: { format: { type: 'audio/pcm', rate: 24000 } },
|
|
1002
|
+
},
|
|
1003
|
+
serverTools: [
|
|
1004
|
+
{ type: 'web_search' },
|
|
1005
|
+
{
|
|
1006
|
+
type: 'mcp',
|
|
1007
|
+
server_url: 'https://mcp.example.com/mcp',
|
|
1008
|
+
server_label: 'business-tools',
|
|
1009
|
+
},
|
|
1010
|
+
],
|
|
1011
|
+
})
|
|
1012
|
+
```
|
|
1013
|
+
|
|
1014
|
+
Visit the [xAI Realtime Voice Reference](https://mastra.ai/reference/voice/xai-realtime) for more information on the xAI realtime voice provider.
|
|
1015
|
+
|
|
941
1016
|
**Google Gemini Live**:
|
|
942
1017
|
|
|
943
1018
|
```typescript
|
|
@@ -1102,6 +1177,7 @@ For more information on the CompositeVoice, refer to the [CompositeVoice Referen
|
|
|
1102
1177
|
- [MastraVoice](https://mastra.ai/reference/voice/mastra-voice)
|
|
1103
1178
|
- [OpenAI Voice](https://mastra.ai/reference/voice/openai)
|
|
1104
1179
|
- [OpenAI Realtime Voice](https://mastra.ai/reference/voice/openai-realtime)
|
|
1180
|
+
- [xAI Realtime Voice](https://mastra.ai/reference/voice/xai-realtime)
|
|
1105
1181
|
- [Azure Voice](https://mastra.ai/reference/voice/azure)
|
|
1106
1182
|
- [Google Voice](https://mastra.ai/reference/voice/google)
|
|
1107
1183
|
- [Google Gemini Live Voice](https://mastra.ai/reference/voice/google-gemini-live)
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
# Deploy Mastra to Amazon Bedrock AgentCore
|
|
2
|
+
|
|
3
|
+
Deploy your Mastra application to [Amazon Bedrock AgentCore Runtime](https://docs.aws.amazon.com/bedrock-agentcore/) using the [AgentCore CLI](https://github.com/aws/agentcore-cli). The CLI scaffolds a bring-your-own-code (BYO) TypeScript project, builds the container with AWS CodeBuild, and provisions the runtime. A local Docker daemon is not required for deployment.
|
|
4
|
+
|
|
5
|
+
This guide follows the [official AgentCore TypeScript walkthrough](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-get-started-cli-typescript.html) and adapts it to call a Mastra agent from the invocation handler.
|
|
6
|
+
|
|
7
|
+
> **Info:** For a Lambda-based deployment of the full Mastra server, see the [AWS Lambda guide](https://mastra.ai/guides/deployment/aws-lambda). For a long-lived virtual machine, see the [Amazon EC2 guide](https://mastra.ai/guides/deployment/amazon-ec2).
|
|
8
|
+
|
|
9
|
+
## Before you begin
|
|
10
|
+
|
|
11
|
+
You'll need:
|
|
12
|
+
|
|
13
|
+
- An [AWS account](https://aws.amazon.com/) with permissions for Amazon Bedrock AgentCore, AWS CodeBuild, Amazon ECR, and AWS IAM
|
|
14
|
+
- [AWS CLI](https://aws.amazon.com/cli/) installed and authenticated (`aws configure` or `aws sso login`)
|
|
15
|
+
- Node.js `v22.13.0` or later installed
|
|
16
|
+
- [Docker](https://www.docker.com/), [Podman](https://podman.io/), or [Finch](https://runfinch.com/) for local testing with `agentcore dev` (not required for `agentcore deploy`)
|
|
17
|
+
|
|
18
|
+
Amazon Bedrock AgentCore Runtime is available in [a subset of AWS Regions](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/agentcore-regions.html). Use a region where AgentCore is available and where the foundation models you plan to call are enabled.
|
|
19
|
+
|
|
20
|
+
## Create a new AgentCore project
|
|
21
|
+
|
|
22
|
+
Run the following command to create a new AgentCore project:
|
|
23
|
+
|
|
24
|
+
**npm**:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx @aws/agentcore create --name MastraOnAgentCore --no-agent
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**pnpm**:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pnpm dlx @aws/agentcore create --name MastraOnAgentCore --no-agent
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Yarn**:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
yarn dlx @aws/agentcore create --name MastraOnAgentCore --no-agent
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Bun**:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
bun x @aws/agentcore create --name MastraOnAgentCore --no-agent
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Navigate to the newly created `MastraOnAgentCore` directory:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
cd MastraOnAgentCore
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Initialize a BYO TypeScript agent that will be created inside `app/MastraAgent`:
|
|
55
|
+
|
|
56
|
+
**npm**:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npx @aws/agentcore add agent --name MastraAgent --type byo --build Container --language TypeScript --framework Strands --model-provider Bedrock --code-location app/MastraAgent
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**pnpm**:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pnpm dlx @aws/agentcore add agent --name MastraAgent --type byo --build Container --language TypeScript --framework Strands --model-provider Bedrock --code-location app/MastraAgent
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Yarn**:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
yarn dlx @aws/agentcore add agent --name MastraAgent --type byo --build Container --language TypeScript --framework Strands --model-provider Bedrock --code-location app/MastraAgent
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Bun**:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
bun x @aws/agentcore add agent --name MastraAgent --type byo --build Container --language TypeScript --framework Strands --model-provider Bedrock --code-location app/MastraAgent
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The CLI will modify the `agentcore/agentcore.json` file and create an empty `app/MastraAgent` directory.
|
|
81
|
+
|
|
82
|
+
## Set up the agent project
|
|
83
|
+
|
|
84
|
+
Navigate to the `app/MastraAgent` directory and initialize a new Node.js project:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
cd app/MastraAgent
|
|
88
|
+
npm init --init-type=module -y
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Install the required dependencies. The `bedrock-agentcore` package provides the `BedrockAgentCoreApp` HTTP server that implements the [AgentCore Runtime service contract](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-service-contract.html). The `@ai-sdk/amazon-bedrock` and `@aws-sdk/credential-providers` packages let the Mastra agent call Bedrock through the AgentCore Runtime execution role:
|
|
92
|
+
|
|
93
|
+
**npm**:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npm install bedrock-agentcore @opentelemetry/auto-instrumentations-node @ai-sdk/amazon-bedrock @aws-sdk/credential-providers --legacy-peer-deps
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**pnpm**:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
pnpm add bedrock-agentcore @opentelemetry/auto-instrumentations-node @ai-sdk/amazon-bedrock @aws-sdk/credential-providers --legacy-peer-deps
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Yarn**:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
yarn add bedrock-agentcore @opentelemetry/auto-instrumentations-node @ai-sdk/amazon-bedrock @aws-sdk/credential-providers --legacy-peer-deps
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Bun**:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
bun add bedrock-agentcore @opentelemetry/auto-instrumentations-node @ai-sdk/amazon-bedrock @aws-sdk/credential-providers --legacy-peer-deps
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Also install TypeScript and related dev dependencies:
|
|
118
|
+
|
|
119
|
+
**npm**:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
npm install --save-dev typescript @types/node tsx
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**pnpm**:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pnpm add --save-dev typescript @types/node tsx
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Yarn**:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
yarn add --dev typescript @types/node tsx
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Bun**:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
bun add --dev typescript @types/node tsx
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Run [`mastra init`](https://mastra.ai/reference/cli/mastra) to set up a new Mastra project. The provider you choose at the prompt is overwritten in the next step, so any value works:
|
|
144
|
+
|
|
145
|
+
**npm**:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
npx mastra@latest init
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**pnpm**:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
pnpm dlx mastra@latest init
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Yarn**:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
yarn dlx mastra@latest init
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Bun**:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
bun x mastra@latest init
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Replace the generated `src/mastra/agents/weather-agent.ts` to use Amazon Bedrock. The original `memory: new Memory()` is removed because the storage layer is removed in the next step:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import { Agent } from '@mastra/core/agent'
|
|
173
|
+
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock'
|
|
174
|
+
import { fromNodeProviderChain } from '@aws-sdk/credential-providers'
|
|
175
|
+
import { weatherTool } from '../tools/weather-tool.js'
|
|
176
|
+
|
|
177
|
+
const bedrock = createAmazonBedrock({
|
|
178
|
+
credentialProvider: fromNodeProviderChain(),
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
export const weatherAgent = new Agent({
|
|
182
|
+
id: 'weather-agent',
|
|
183
|
+
name: 'Weather Agent',
|
|
184
|
+
instructions:
|
|
185
|
+
'You are a helpful weather assistant. Use the weatherTool to fetch current weather data.',
|
|
186
|
+
model: bedrock('us.anthropic.claude-sonnet-4-6'),
|
|
187
|
+
tools: { weatherTool },
|
|
188
|
+
})
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
> **Note:** `fromNodeProviderChain()` lets the agent pick up AWS credentials through the standard SDK resolution chain (environment variables, shared config files, SSO, and container or EC2 roles) instead of environment variables only.
|
|
192
|
+
|
|
193
|
+
Replace the generated `src/mastra/index.ts` to remove the default file-based storage and observability config. AgentCore Runtime containers run as a non-root user with a read-only application directory, so the default `LibSQLStore` cannot open `./mastra.db` and the runtime fails at startup:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
import { Mastra } from '@mastra/core/mastra'
|
|
197
|
+
import { PinoLogger } from '@mastra/loggers'
|
|
198
|
+
import { weatherWorkflow } from './workflows/weather-workflow.js'
|
|
199
|
+
import { weatherAgent } from './agents/weather-agent.js'
|
|
200
|
+
|
|
201
|
+
export const mastra = new Mastra({
|
|
202
|
+
workflows: { weatherWorkflow },
|
|
203
|
+
agents: { weatherAgent },
|
|
204
|
+
logger: new PinoLogger({
|
|
205
|
+
name: 'Mastra',
|
|
206
|
+
level: 'info',
|
|
207
|
+
}),
|
|
208
|
+
})
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Create a `tsconfig.json` file with the following content:
|
|
212
|
+
|
|
213
|
+
```json
|
|
214
|
+
{
|
|
215
|
+
"compilerOptions": {
|
|
216
|
+
"outDir": "./dist",
|
|
217
|
+
"rootDir": ".",
|
|
218
|
+
"strict": true,
|
|
219
|
+
"esModuleInterop": true,
|
|
220
|
+
"skipLibCheck": true,
|
|
221
|
+
"declaration": true,
|
|
222
|
+
"target": "ES2022",
|
|
223
|
+
"module": "NodeNext",
|
|
224
|
+
"moduleResolution": "NodeNext",
|
|
225
|
+
"forceConsistentCasingInFileNames": true
|
|
226
|
+
},
|
|
227
|
+
"include": ["*.ts", "src/**/*"],
|
|
228
|
+
"exclude": ["node_modules", "dist"]
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
> **Note:** After adding the `tsconfig.json` file your editor will show errors inside the generated `src/mastra` project. This is expected since the configuration now requires file extensions on imports. You can fix these by adding `.js`, for example:
|
|
233
|
+
>
|
|
234
|
+
> ```ts
|
|
235
|
+
> // Before
|
|
236
|
+
> import { weatherWorkflow } from './workflows/weather-workflow'
|
|
237
|
+
> // After
|
|
238
|
+
> import { weatherWorkflow } from './workflows/weather-workflow.js'
|
|
239
|
+
> ```
|
|
240
|
+
|
|
241
|
+
Update your `package.json` to set the entry point and build scripts. Using `npm pkg set` preserves the dependencies that `mastra init` added:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
npm pkg set main=dist/agent.js scripts.build=tsc scripts.start="node dist/agent.js" scripts.dev="npx tsx --watch agent.ts"
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Initialize the agent
|
|
248
|
+
|
|
249
|
+
Create an `agent.ts` file. This handler is called for every `POST /invocations` request. Resolve the Mastra agent and call it inside the handler:
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
import { BedrockAgentCoreApp } from 'bedrock-agentcore/runtime'
|
|
253
|
+
import { mastra } from './src/mastra/index.js'
|
|
254
|
+
|
|
255
|
+
const app = new BedrockAgentCoreApp({
|
|
256
|
+
invocationHandler: {
|
|
257
|
+
process: async (payload, context) => {
|
|
258
|
+
const { prompt } = payload as { prompt: string }
|
|
259
|
+
|
|
260
|
+
const agent = mastra.getAgentById('weather-agent')
|
|
261
|
+
const response = await agent.generate(prompt, {
|
|
262
|
+
runId: context.sessionId,
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
return response.text
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
app.run()
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Run `npm run build` to verify that your project compiles successfully.
|
|
274
|
+
|
|
275
|
+
## Create a Dockerfile
|
|
276
|
+
|
|
277
|
+
Create a `Dockerfile` in the `app/MastraAgent` directory. Container-based deployment uses a multi-stage Docker build: the builder stage compiles TypeScript to JavaScript, and the production stage runs only the compiled output. The image runs as a non-root user for security, and exposes port 8080 (HTTP), port 8000 (MCP), and port 9000 (A2A). OpenTelemetry instrumentation is included automatically at startup.
|
|
278
|
+
|
|
279
|
+
```dockerfile
|
|
280
|
+
FROM node:22-slim AS builder
|
|
281
|
+
|
|
282
|
+
WORKDIR /app
|
|
283
|
+
COPY package*.json ./
|
|
284
|
+
RUN npm ci
|
|
285
|
+
COPY . .
|
|
286
|
+
RUN npm run build
|
|
287
|
+
|
|
288
|
+
FROM node:22-slim
|
|
289
|
+
WORKDIR /app
|
|
290
|
+
ENV AWS_REGION=us-east-1
|
|
291
|
+
COPY --from=builder /app/dist ./dist
|
|
292
|
+
COPY --from=builder /app/node_modules ./node_modules
|
|
293
|
+
COPY --from=builder /app/package*.json ./
|
|
294
|
+
|
|
295
|
+
RUN useradd -m bedrock_agentcore
|
|
296
|
+
USER bedrock_agentcore
|
|
297
|
+
|
|
298
|
+
EXPOSE 8080 8000 9000
|
|
299
|
+
CMD ["node", "--require", "@opentelemetry/auto-instrumentations-node/register", "dist/agent.js"]
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
> **Note:** Pick an `AWS_REGION` that pairs with your Bedrock model ID prefix (`us.`, `jp.`, `eu.`, or `global.`).
|
|
303
|
+
|
|
304
|
+
Also create a `.dockerignore` file to exclude unnecessary files from the Docker build context:
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
node_modules
|
|
308
|
+
dist
|
|
309
|
+
.git
|
|
310
|
+
*.log
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Test your agent
|
|
314
|
+
|
|
315
|
+
Return to the project root:
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
cd ../..
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
Test your agent locally:
|
|
322
|
+
|
|
323
|
+
**npm**:
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
npx @aws/agentcore dev --runtime MastraAgent
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
**pnpm**:
|
|
330
|
+
|
|
331
|
+
```bash
|
|
332
|
+
pnpm dlx @aws/agentcore dev --runtime MastraAgent
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
**Yarn**:
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
yarn dlx @aws/agentcore dev --runtime MastraAgent
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
**Bun**:
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
bun x @aws/agentcore dev --runtime MastraAgent
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
In a separate terminal, send a test request:
|
|
348
|
+
|
|
349
|
+
**npm**:
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
npx @aws/agentcore dev "What is the weather in Tokyo?"
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
**pnpm**:
|
|
356
|
+
|
|
357
|
+
```bash
|
|
358
|
+
pnpm dlx @aws/agentcore dev "What is the weather in Tokyo?"
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
**Yarn**:
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
yarn dlx @aws/agentcore dev "What is the weather in Tokyo?"
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
**Bun**:
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
bun x @aws/agentcore dev "What is the weather in Tokyo?"
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
## Deploy your agent
|
|
374
|
+
|
|
375
|
+
Set the AWS account and region in `agentcore/aws-targets.json`:
|
|
376
|
+
|
|
377
|
+
```json
|
|
378
|
+
[
|
|
379
|
+
{
|
|
380
|
+
"name": "default",
|
|
381
|
+
"account": "123456789012",
|
|
382
|
+
"region": "us-east-1"
|
|
383
|
+
}
|
|
384
|
+
]
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Deploy to AgentCore Runtime. The CLI builds the image with AWS CodeBuild, pushes it to Amazon ECR, and creates the runtime and a `DEFAULT` endpoint:
|
|
388
|
+
|
|
389
|
+
**npm**:
|
|
390
|
+
|
|
391
|
+
```bash
|
|
392
|
+
npx @aws/agentcore deploy
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
**pnpm**:
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
pnpm dlx @aws/agentcore deploy
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
**Yarn**:
|
|
402
|
+
|
|
403
|
+
```bash
|
|
404
|
+
yarn dlx @aws/agentcore deploy
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
**Bun**:
|
|
408
|
+
|
|
409
|
+
```bash
|
|
410
|
+
bun x @aws/agentcore deploy
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
> **Note:** Set provider API keys and other secrets in `agentcore/agentcore.json` under the agent's `environmentVariables` field before deploying.
|
|
414
|
+
|
|
415
|
+
## Verify your deployment
|
|
416
|
+
|
|
417
|
+
Run `agentcore status` to view the runtime ARN, endpoint, and recent invocations. Then call the deployed agent from the CLI:
|
|
418
|
+
|
|
419
|
+
```bash
|
|
420
|
+
npx @aws/agentcore invoke "What is the weather in Tokyo?"
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
To stream tokens as they are generated, use `--stream`:
|
|
424
|
+
|
|
425
|
+
```bash
|
|
426
|
+
npx @aws/agentcore invoke --stream "Plan a 3-day trip to Tokyo"
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
## Related
|
|
430
|
+
|
|
431
|
+
- [Amazon Bedrock AgentCore documentation](https://docs.aws.amazon.com/bedrock-agentcore/)
|
|
432
|
+
- [AgentCore CLI on GitHub](https://github.com/aws/agentcore-cli)
|
package/.docs/models/index.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Model Providers
|
|
2
2
|
|
|
3
|
-
Mastra provides a unified interface for working with LLMs across multiple providers, giving you access to
|
|
3
|
+
Mastra provides a unified interface for working with LLMs across multiple providers, giving you access to 3948 models from 115 providers through a single API.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|