@mastra/mcp-docs-server 1.0.0-beta.13 → 1.0.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +98 -98
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +30 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +171 -171
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Frag.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Freact.md +9 -2
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +94 -94
- package/.docs/organized/changelogs/create-mastra.md +3 -3
- package/.docs/organized/changelogs/mastra.md +17 -17
- package/.docs/organized/code-examples/agent-v6.md +151 -0
- package/.docs/organized/code-examples/ai-elements.md +1 -1
- package/.docs/raw/agents/adding-voice.mdx +2 -3
- package/.docs/raw/agents/agent-approval.mdx +5 -6
- package/.docs/raw/agents/agent-memory.mdx +22 -30
- package/.docs/raw/agents/guardrails.mdx +60 -50
- package/.docs/raw/agents/networks.mdx +8 -12
- package/.docs/raw/agents/overview.mdx +39 -23
- package/.docs/raw/agents/processors.mdx +20 -19
- package/.docs/raw/agents/structured-output.mdx +11 -7
- package/.docs/raw/agents/using-tools.mdx +4 -5
- package/.docs/raw/deployment/mastra-server.mdx +3 -3
- package/.docs/raw/deployment/overview.mdx +7 -0
- package/.docs/raw/deployment/web-framework.mdx +4 -6
- package/.docs/raw/evals/custom-scorers.mdx +9 -6
- package/.docs/raw/evals/overview.mdx +3 -6
- package/.docs/raw/evals/running-in-ci.mdx +2 -2
- package/.docs/raw/getting-started/manual-install.mdx +20 -20
- package/.docs/raw/getting-started/mcp-docs-server.mdx +2 -2
- package/.docs/raw/guides/agent-frameworks/ai-sdk.mdx +4 -4
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +30 -30
- package/.docs/raw/guides/build-your-ui/assistant-ui.mdx +8 -8
- package/.docs/raw/guides/build-your-ui/copilotkit.mdx +11 -11
- package/.docs/raw/guides/deployment/amazon-ec2.mdx +9 -9
- package/.docs/raw/guides/deployment/aws-lambda.mdx +11 -11
- package/.docs/raw/guides/deployment/azure-app-services.mdx +2 -2
- package/.docs/raw/guides/deployment/cloudflare-deployer.mdx +5 -6
- package/.docs/raw/guides/deployment/digital-ocean.mdx +10 -10
- package/.docs/raw/guides/deployment/index.mdx +1 -1
- package/.docs/raw/guides/deployment/inngest.mdx +386 -0
- package/.docs/raw/guides/deployment/netlify-deployer.mdx +4 -4
- package/.docs/raw/guides/deployment/vercel-deployer.mdx +5 -6
- package/.docs/raw/guides/getting-started/astro.mdx +292 -451
- package/.docs/raw/guides/getting-started/express.mdx +7 -7
- package/.docs/raw/guides/getting-started/hono.mdx +18 -18
- package/.docs/raw/guides/getting-started/next-js.mdx +19 -20
- package/.docs/raw/guides/getting-started/quickstart.mdx +4 -4
- package/.docs/raw/guides/getting-started/sveltekit.mdx +238 -409
- package/.docs/raw/guides/getting-started/vite-react.mdx +21 -21
- package/.docs/raw/guides/guide/ai-recruiter.mdx +10 -10
- package/.docs/raw/guides/guide/chef-michel.mdx +9 -11
- package/.docs/raw/guides/guide/notes-mcp-server.mdx +15 -15
- package/.docs/raw/guides/guide/research-assistant.mdx +13 -13
- package/.docs/raw/guides/guide/stock-agent.mdx +5 -5
- package/.docs/raw/guides/guide/web-search.mdx +8 -8
- package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +7 -7
- package/.docs/raw/guides/migrations/ai-sdk-v4-to-v5.mdx +2 -2
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +1 -1
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +0 -2
- package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +21 -23
- package/.docs/raw/index.mdx +2 -2
- package/.docs/raw/mastra-cloud/setting-up.mdx +6 -2
- package/.docs/raw/mcp/overview.mdx +31 -13
- package/.docs/raw/mcp/publishing-mcp-server.mdx +2 -2
- package/.docs/raw/memory/memory-processors.mdx +9 -9
- package/.docs/raw/memory/message-history.mdx +69 -0
- package/.docs/raw/memory/overview.mdx +34 -76
- package/.docs/raw/memory/semantic-recall.mdx +58 -49
- package/.docs/raw/memory/storage.mdx +188 -0
- package/.docs/raw/memory/working-memory.mdx +7 -7
- package/.docs/raw/observability/logging.mdx +9 -10
- package/.docs/raw/observability/overview.mdx +0 -1
- package/.docs/raw/observability/tracing/bridges/otel.mdx +2 -2
- package/.docs/raw/observability/tracing/exporters/default.mdx +3 -3
- package/.docs/raw/observability/tracing/exporters/langfuse.mdx +1 -2
- package/.docs/raw/observability/tracing/overview.mdx +23 -25
- package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +3 -3
- package/.docs/raw/rag/chunking-and-embedding.mdx +6 -6
- package/.docs/raw/rag/graph-rag.mdx +7 -7
- package/.docs/raw/rag/overview.mdx +1 -1
- package/.docs/raw/rag/retrieval.mdx +21 -22
- package/.docs/raw/rag/vector-databases.mdx +22 -22
- package/.docs/raw/reference/agents/agent.mdx +3 -3
- package/.docs/raw/reference/agents/generate.mdx +1 -1
- package/.docs/raw/reference/agents/generateLegacy.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultOptions.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +2 -2
- package/.docs/raw/reference/agents/getDescription.mdx +1 -1
- package/.docs/raw/reference/agents/getInstructions.mdx +2 -2
- package/.docs/raw/reference/agents/getLLM.mdx +2 -2
- package/.docs/raw/reference/agents/getMemory.mdx +2 -2
- package/.docs/raw/reference/agents/getModel.mdx +2 -2
- package/.docs/raw/reference/agents/getTools.mdx +2 -2
- package/.docs/raw/reference/agents/getVoice.mdx +2 -2
- package/.docs/raw/reference/agents/listAgents.mdx +2 -2
- package/.docs/raw/reference/agents/listScorers.mdx +2 -2
- package/.docs/raw/reference/agents/listTools.mdx +2 -2
- package/.docs/raw/reference/agents/listWorkflows.mdx +2 -2
- package/.docs/raw/reference/agents/network.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/chat-route.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/network-route.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-stream.mdx +6 -6
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v4-messages.mdx +3 -3
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v5-messages.mdx +3 -3
- package/.docs/raw/reference/ai-sdk/with-mastra.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/workflow-route.mdx +2 -2
- package/.docs/raw/reference/auth/auth0.mdx +1 -2
- package/.docs/raw/reference/auth/clerk.mdx +1 -2
- package/.docs/raw/reference/auth/firebase.mdx +2 -4
- package/.docs/raw/reference/auth/jwt.mdx +1 -2
- package/.docs/raw/reference/auth/supabase.mdx +1 -2
- package/.docs/raw/reference/auth/workos.mdx +1 -2
- package/.docs/raw/reference/cli/create-mastra.mdx +10 -10
- package/.docs/raw/reference/cli/mastra.mdx +9 -9
- package/.docs/raw/reference/client-js/agents.mdx +1 -2
- package/.docs/raw/reference/client-js/mastra-client.mdx +1 -1
- package/.docs/raw/reference/core/getAgent.mdx +1 -1
- package/.docs/raw/reference/core/getAgentById.mdx +1 -1
- package/.docs/raw/reference/core/getDeployer.mdx +1 -1
- package/.docs/raw/reference/core/getLogger.mdx +1 -1
- package/.docs/raw/reference/core/getMCPServer.mdx +1 -1
- package/.docs/raw/reference/core/getMCPServerById.mdx +1 -1
- package/.docs/raw/reference/core/getMemory.mdx +2 -2
- package/.docs/raw/reference/core/getServer.mdx +1 -1
- package/.docs/raw/reference/core/getStorage.mdx +2 -2
- package/.docs/raw/reference/core/getStoredAgentById.mdx +3 -3
- package/.docs/raw/reference/core/getTelemetry.mdx +1 -1
- package/.docs/raw/reference/core/getVector.mdx +1 -1
- package/.docs/raw/reference/core/getWorkflow.mdx +1 -1
- package/.docs/raw/reference/core/listAgents.mdx +1 -1
- package/.docs/raw/reference/core/listLogs.mdx +1 -1
- package/.docs/raw/reference/core/listLogsByRunId.mdx +1 -1
- package/.docs/raw/reference/core/listMCPServers.mdx +1 -1
- package/.docs/raw/reference/core/listMemory.mdx +2 -2
- package/.docs/raw/reference/core/listStoredAgents.mdx +4 -4
- package/.docs/raw/reference/core/listVectors.mdx +1 -1
- package/.docs/raw/reference/core/listWorkflows.mdx +1 -1
- package/.docs/raw/reference/core/setLogger.mdx +1 -1
- package/.docs/raw/reference/core/setStorage.mdx +2 -2
- package/.docs/raw/reference/core/setTelemetry.mdx +1 -1
- package/.docs/raw/reference/deployer/cloudflare.mdx +1 -2
- package/.docs/raw/reference/deployer/deployer.mdx +0 -1
- package/.docs/raw/reference/deployer/netlify.mdx +1 -1
- package/.docs/raw/reference/deployer/vercel.mdx +2 -4
- package/.docs/raw/reference/evals/answer-relevancy.mdx +1 -1
- package/.docs/raw/reference/evals/answer-similarity.mdx +1 -1
- package/.docs/raw/reference/evals/bias.mdx +1 -1
- package/.docs/raw/reference/evals/completeness.mdx +1 -1
- package/.docs/raw/reference/evals/content-similarity.mdx +1 -1
- package/.docs/raw/reference/evals/context-precision.mdx +1 -1
- package/.docs/raw/reference/evals/faithfulness.mdx +1 -1
- package/.docs/raw/reference/evals/hallucination.mdx +1 -1
- package/.docs/raw/reference/evals/keyword-coverage.mdx +1 -1
- package/.docs/raw/reference/evals/prompt-alignment.mdx +7 -7
- package/.docs/raw/reference/evals/textual-difference.mdx +1 -1
- package/.docs/raw/reference/evals/tone-consistency.mdx +1 -1
- package/.docs/raw/reference/evals/tool-call-accuracy.mdx +10 -10
- package/.docs/raw/reference/evals/toxicity.mdx +1 -1
- package/.docs/raw/reference/logging/pino-logger.mdx +6 -7
- package/.docs/raw/reference/memory/createThread.mdx +2 -2
- package/.docs/raw/reference/memory/deleteMessages.mdx +2 -2
- package/.docs/raw/reference/memory/listThreadsByResourceId.mdx +2 -2
- package/.docs/raw/reference/memory/memory-class.mdx +3 -3
- package/.docs/raw/reference/memory/query.mdx +2 -2
- package/.docs/raw/reference/memory/recall.mdx +2 -2
- package/.docs/raw/reference/observability/tracing/exporters/langfuse.mdx +1 -1
- package/.docs/raw/reference/processors/batch-parts-processor.mdx +2 -2
- package/.docs/raw/reference/processors/language-detector.mdx +2 -2
- package/.docs/raw/reference/processors/message-history-processor.mdx +2 -2
- package/.docs/raw/reference/processors/moderation-processor.mdx +3 -3
- package/.docs/raw/reference/processors/pii-detector.mdx +3 -3
- package/.docs/raw/reference/processors/processor-interface.mdx +13 -13
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +2 -2
- package/.docs/raw/reference/processors/semantic-recall-processor.mdx +2 -2
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -2
- package/.docs/raw/reference/processors/token-limiter-processor.mdx +2 -2
- package/.docs/raw/reference/processors/tool-call-filter.mdx +3 -3
- package/.docs/raw/reference/processors/unicode-normalizer.mdx +2 -2
- package/.docs/raw/reference/processors/working-memory-processor.mdx +3 -3
- package/.docs/raw/reference/rag/chunk.mdx +1 -1
- package/.docs/raw/reference/rag/extract-params.mdx +2 -2
- package/.docs/raw/reference/rag/metadata-filters.mdx +7 -7
- package/.docs/raw/reference/server/create-route.mdx +13 -13
- package/.docs/raw/reference/server/express-adapter.mdx +6 -7
- package/.docs/raw/reference/server/hono-adapter.mdx +6 -7
- package/.docs/raw/reference/server/mastra-server.mdx +20 -20
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +3 -3
- package/.docs/raw/reference/storage/cloudflare.mdx +2 -2
- package/.docs/raw/reference/storage/convex.mdx +6 -6
- package/.docs/raw/reference/storage/dynamodb.mdx +4 -4
- package/.docs/raw/reference/storage/lance.mdx +3 -3
- package/.docs/raw/reference/storage/libsql.mdx +69 -54
- package/.docs/raw/reference/storage/mongodb.mdx +80 -7
- package/.docs/raw/reference/storage/mssql.mdx +4 -4
- package/.docs/raw/{memory → reference}/storage/overview.mdx +12 -110
- package/.docs/raw/reference/storage/postgresql.mdx +78 -7
- package/.docs/raw/reference/storage/upstash.mdx +74 -2
- package/.docs/raw/reference/streaming/agents/stream.mdx +5 -5
- package/.docs/raw/reference/streaming/agents/streamLegacy.mdx +2 -2
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +1 -1
- package/.docs/raw/reference/streaming/workflows/resumeStream.mdx +1 -1
- package/.docs/raw/reference/streaming/workflows/stream.mdx +2 -2
- package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +4 -4
- package/.docs/raw/reference/templates/overview.mdx +1 -2
- package/.docs/raw/reference/tools/create-tool.mdx +1 -4
- package/.docs/raw/reference/tools/vector-query-tool.mdx +1 -1
- package/.docs/raw/reference/vectors/astra.mdx +3 -3
- package/.docs/raw/reference/vectors/chroma.mdx +3 -3
- package/.docs/raw/reference/vectors/convex.mdx +12 -12
- package/.docs/raw/reference/vectors/couchbase.mdx +5 -5
- package/.docs/raw/reference/vectors/duckdb.mdx +10 -10
- package/.docs/raw/reference/vectors/elasticsearch.mdx +4 -4
- package/.docs/raw/reference/vectors/lance.mdx +4 -4
- package/.docs/raw/reference/vectors/libsql.mdx +61 -11
- package/.docs/raw/reference/vectors/mongodb.mdx +58 -5
- package/.docs/raw/reference/vectors/pg.mdx +53 -6
- package/.docs/raw/reference/vectors/pinecone.mdx +3 -3
- package/.docs/raw/reference/vectors/qdrant.mdx +3 -3
- package/.docs/raw/reference/vectors/s3vectors.mdx +6 -6
- package/.docs/raw/reference/vectors/turbopuffer.mdx +4 -4
- package/.docs/raw/reference/vectors/upstash.mdx +55 -6
- package/.docs/raw/reference/vectors/vectorize.mdx +3 -3
- package/.docs/raw/reference/workflows/run-methods/cancel.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/restart.mdx +1 -3
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/start.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/startAsync.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +5 -5
- package/.docs/raw/reference/workflows/run.mdx +1 -1
- package/.docs/raw/reference/workflows/step.mdx +3 -3
- package/.docs/raw/reference/workflows/workflow-methods/branch.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/commit.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/create-run.mdx +3 -3
- package/.docs/raw/reference/workflows/workflow-methods/dountil.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/dowhile.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/foreach.mdx +6 -6
- package/.docs/raw/reference/workflows/workflow-methods/map.mdx +7 -7
- package/.docs/raw/reference/workflows/workflow-methods/parallel.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/sendEvent.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/sleep.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/sleepUntil.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/then.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/waitForEvent.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow.mdx +3 -3
- package/.docs/raw/server/auth/auth0.mdx +20 -14
- package/.docs/raw/server/auth/clerk.mdx +16 -9
- package/.docs/raw/server/auth/firebase.mdx +21 -15
- package/.docs/raw/server/auth/jwt.mdx +14 -7
- package/.docs/raw/server/auth/supabase.mdx +16 -9
- package/.docs/raw/server/auth/workos.mdx +19 -13
- package/.docs/raw/server/custom-adapters.mdx +10 -10
- package/.docs/raw/server/custom-api-routes.mdx +2 -4
- package/.docs/raw/server/mastra-client.mdx +24 -13
- package/.docs/raw/server/mastra-server.mdx +3 -3
- package/.docs/raw/server/middleware.mdx +7 -7
- package/.docs/raw/server/request-context.mdx +31 -30
- package/.docs/raw/server/server-adapters.mdx +6 -6
- package/.docs/raw/streaming/events.mdx +14 -7
- package/.docs/raw/streaming/overview.mdx +21 -10
- package/.docs/raw/streaming/tool-streaming.mdx +6 -6
- package/.docs/raw/streaming/workflow-streaming.mdx +6 -8
- package/.docs/raw/tools-mcp/advanced-usage.mdx +2 -2
- package/.docs/raw/tools-mcp/mcp-overview.mdx +31 -12
- package/.docs/raw/tools-mcp/overview.mdx +9 -10
- package/.docs/raw/voice/overview.mdx +1 -1
- package/.docs/raw/workflows/agents-and-tools.mdx +28 -19
- package/.docs/raw/workflows/control-flow.mdx +27 -40
- package/.docs/raw/workflows/error-handling.mdx +15 -22
- package/.docs/raw/workflows/human-in-the-loop.mdx +6 -7
- package/.docs/raw/workflows/inngest-workflow.mdx +8 -9
- package/.docs/raw/workflows/input-data-mapping.mdx +7 -7
- package/.docs/raw/workflows/overview.mdx +33 -22
- package/.docs/raw/workflows/snapshots.mdx +14 -44
- package/.docs/raw/workflows/suspend-and-resume.mdx +7 -7
- package/.docs/raw/workflows/time-travel.mdx +16 -16
- package/.docs/raw/workflows/workflow-state.mdx +5 -8
- package/CHANGELOG.md +9 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/stdio.js +53 -0
- package/package.json +4 -4
- package/.docs/raw/memory/conversation-history.mdx +0 -24
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +0 -140
- package/.docs/raw/memory/storage/memory-with-mongodb.mdx +0 -150
- package/.docs/raw/memory/storage/memory-with-pg.mdx +0 -138
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +0 -146
- package/.docs/raw/memory/threads-and-resources.mdx +0 -95
|
@@ -39,7 +39,7 @@ npm install @mastra/core@beta
|
|
|
39
39
|
|
|
40
40
|
Mastra's model router auto-detects environment variables for your chosen provider. For OpenAI, set `OPENAI_API_KEY`:
|
|
41
41
|
|
|
42
|
-
```bash title=".env"
|
|
42
|
+
```bash title=".env"
|
|
43
43
|
OPENAI_API_KEY=<your-api-key>
|
|
44
44
|
```
|
|
45
45
|
|
|
@@ -55,7 +55,7 @@ Mastra supports more than 600 models. Choose from the [full list](/models/v1).
|
|
|
55
55
|
|
|
56
56
|
Create an agent by instantiating the `Agent` class with system `instructions` and a `model`:
|
|
57
57
|
|
|
58
|
-
```typescript title="src/mastra/agents/test-agent.ts"
|
|
58
|
+
```typescript title="src/mastra/agents/test-agent.ts"
|
|
59
59
|
import { Agent } from "@mastra/core/agent";
|
|
60
60
|
|
|
61
61
|
export const testAgent = new Agent({
|
|
@@ -77,7 +77,7 @@ They are system-level prompts that establish the agent's core identity and exper
|
|
|
77
77
|
|
|
78
78
|
Instructions can be provided in multiple formats for greater flexibility. The examples below illustrate the supported shapes:
|
|
79
79
|
|
|
80
|
-
```typescript
|
|
80
|
+
```typescript
|
|
81
81
|
// String (most common)
|
|
82
82
|
instructions: "You are a helpful assistant.";
|
|
83
83
|
|
|
@@ -99,7 +99,7 @@ instructions: [
|
|
|
99
99
|
|
|
100
100
|
Each model provider also enables a few different options, including prompt caching and configuring reasoning. We provide a `providerOptions` flag to manage these. You can set `providerOptions` on the instruction level to set different caching strategy per system instruction/prompt.
|
|
101
101
|
|
|
102
|
-
```typescript
|
|
102
|
+
```typescript
|
|
103
103
|
// With provider-specific options (e.g., caching, reasoning)
|
|
104
104
|
instructions: {
|
|
105
105
|
role: "system",
|
|
@@ -112,18 +112,21 @@ instructions: {
|
|
|
112
112
|
}
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
:::info
|
|
116
|
+
|
|
117
|
+
Visit [Agent reference](/reference/v1/agents/agent) for more information.
|
|
118
|
+
|
|
119
|
+
:::
|
|
116
120
|
|
|
117
121
|
### Registering an agent
|
|
118
122
|
|
|
119
123
|
Register your agent in the Mastra instance to make it available throughout your application. Once registered, it can be called from workflows, tools, or other agents, and has access to shared resources such as memory, logging, and observability features:
|
|
120
124
|
|
|
121
|
-
```typescript {
|
|
125
|
+
```typescript {5} title="src/mastra/index.ts"
|
|
122
126
|
import { Mastra } from "@mastra/core";
|
|
123
127
|
import { testAgent } from "./agents/test-agent";
|
|
124
128
|
|
|
125
129
|
export const mastra = new Mastra({
|
|
126
|
-
// ...
|
|
127
130
|
agents: { testAgent },
|
|
128
131
|
});
|
|
129
132
|
```
|
|
@@ -132,7 +135,7 @@ export const mastra = new Mastra({
|
|
|
132
135
|
|
|
133
136
|
You can call agents from workflow steps, tools, the Mastra Client, or the command line. Get a reference by calling `.getAgent()` on your `mastra` or `mastraClient` instance, depending on your setup:
|
|
134
137
|
|
|
135
|
-
```typescript
|
|
138
|
+
```typescript
|
|
136
139
|
const testAgent = mastra.getAgent("testAgent");
|
|
137
140
|
```
|
|
138
141
|
|
|
@@ -152,7 +155,7 @@ Pass a single string for simple prompts, an array of strings when providing mult
|
|
|
152
155
|
|
|
153
156
|
(The `role` defines the speaker for each message. Typical roles are `user` for human input, `assistant` for agent responses, and `system` for instructions.)
|
|
154
157
|
|
|
155
|
-
```typescript
|
|
158
|
+
```typescript
|
|
156
159
|
const response = await testAgent.generate([
|
|
157
160
|
{ role: "user", content: "Help me organize my day" },
|
|
158
161
|
{ role: "user", content: "My day starts at 9am and finishes at 5.30pm" },
|
|
@@ -172,7 +175,7 @@ Pass a single string for simple prompts, an array of strings when providing mult
|
|
|
172
175
|
|
|
173
176
|
(The `role` defines the speaker for each message. Typical roles are `user` for human input, `assistant` for agent responses, and `system` for instructions.)
|
|
174
177
|
|
|
175
|
-
```typescript
|
|
178
|
+
```typescript
|
|
176
179
|
const stream = await testAgent.stream([
|
|
177
180
|
{ role: "user", content: "Help me organize my day" },
|
|
178
181
|
{ role: "user", content: "My day starts at 9am and finishes at 5.30pm" },
|
|
@@ -193,7 +196,7 @@ for await (const chunk of stream.textStream) {
|
|
|
193
196
|
When streaming responses, the `onFinish()` callback runs after the LLM finishes generating its response and all tool executions are complete.
|
|
194
197
|
It provides the final `text`, execution `steps`, `finishReason`, token `usage` statistics, and other metadata useful for monitoring or logging.
|
|
195
198
|
|
|
196
|
-
```typescript
|
|
199
|
+
```typescript
|
|
197
200
|
const stream = await testAgent.stream("Help me organize my day", {
|
|
198
201
|
onFinish: ({ steps, text, finishReason, usage }) => {
|
|
199
202
|
console.log({ steps, text, finishReason, usage });
|
|
@@ -208,19 +211,27 @@ for await (const chunk of stream.textStream) {
|
|
|
208
211
|
</TabItem>
|
|
209
212
|
</Tabs>
|
|
210
213
|
|
|
211
|
-
|
|
214
|
+
:::info
|
|
215
|
+
|
|
216
|
+
Visit [.generate()](/reference/v1/agents/generate) or [.stream()](/reference/v1/streaming/agents/stream) for more information.
|
|
217
|
+
|
|
218
|
+
:::
|
|
212
219
|
|
|
213
220
|
## Structured output
|
|
214
221
|
|
|
215
222
|
Agents can return structured, type-safe data using Zod or JSON Schema. The parsed result is available on `response.object`.
|
|
216
223
|
|
|
217
|
-
|
|
224
|
+
:::info
|
|
225
|
+
|
|
226
|
+
Visit [Structured Output](/docs/v1/agents/structured-output) for more information.
|
|
227
|
+
|
|
228
|
+
:::
|
|
218
229
|
|
|
219
230
|
## Analyzing images
|
|
220
231
|
|
|
221
232
|
Agents can analyze and describe images by processing both the visual content and any text within them. To enable image analysis, pass an object with `type: 'image'` and the image URL in the `content` array. You can combine image content with text prompts to guide the agent's analysis.
|
|
222
233
|
|
|
223
|
-
```typescript
|
|
234
|
+
```typescript
|
|
224
235
|
const response = await testAgent.generate([
|
|
225
236
|
{
|
|
226
237
|
role: "user",
|
|
@@ -241,12 +252,11 @@ const response = await testAgent.generate([
|
|
|
241
252
|
console.log(response.text);
|
|
242
253
|
```
|
|
243
254
|
|
|
244
|
-
|
|
245
255
|
## Using `maxSteps`
|
|
246
256
|
|
|
247
257
|
The `maxSteps` parameter controls the maximum number of sequential LLM calls an agent can make. Each step includes generating a response, executing any tool calls, and processing the result. Limiting steps helps prevent infinite loops, reduce latency, and control token usage for agents that use tools. The default is 1, but can be increased:
|
|
248
258
|
|
|
249
|
-
```typescript
|
|
259
|
+
```typescript
|
|
250
260
|
const response = await testAgent.generate("Help me organize my day", {
|
|
251
261
|
maxSteps: 10,
|
|
252
262
|
});
|
|
@@ -260,7 +270,7 @@ You can monitor the progress of multi-step operations using the `onStepFinish` c
|
|
|
260
270
|
|
|
261
271
|
`onStepFinish` is only available when streaming or generating text without structured output.
|
|
262
272
|
|
|
263
|
-
```typescript
|
|
273
|
+
```typescript
|
|
264
274
|
const response = await testAgent.generate("Help me organize my day", {
|
|
265
275
|
onStepFinish: ({ text, toolCalls, toolResults, finishReason, usage }) => {
|
|
266
276
|
console.log({ text, toolCalls, toolResults, finishReason, usage });
|
|
@@ -272,22 +282,25 @@ const response = await testAgent.generate("Help me organize my day", {
|
|
|
272
282
|
|
|
273
283
|
Agents can use tools to go beyond language generation, enabling structured interactions with external APIs and services. Tools allow agents to access data and perform clearly defined operations in a reliable, repeatable way.
|
|
274
284
|
|
|
275
|
-
```typescript title="src/mastra/agents/test-agent.ts"
|
|
285
|
+
```typescript title="src/mastra/agents/test-agent.ts"
|
|
276
286
|
export const testAgent = new Agent({
|
|
277
287
|
id: "test-agent",
|
|
278
288
|
name: "Test Agent",
|
|
279
|
-
// ...
|
|
280
289
|
tools: { testTool },
|
|
281
290
|
});
|
|
282
291
|
```
|
|
283
292
|
|
|
284
|
-
|
|
293
|
+
:::info
|
|
294
|
+
|
|
295
|
+
Visit [Using Tools](/docs/v1/agents/using-tools) for more information.
|
|
296
|
+
|
|
297
|
+
:::
|
|
285
298
|
|
|
286
299
|
## Using `RequestContext`
|
|
287
300
|
|
|
288
301
|
Use `RequestContext` to access request-specific values. This lets you conditionally adjust behavior based on the context of the request.
|
|
289
302
|
|
|
290
|
-
```typescript title="src/mastra/agents/test-agent.ts"
|
|
303
|
+
```typescript title="src/mastra/agents/test-agent.ts"
|
|
291
304
|
export type UserTier = {
|
|
292
305
|
"user-tier": "enterprise" | "pro";
|
|
293
306
|
};
|
|
@@ -295,7 +308,6 @@ export type UserTier = {
|
|
|
295
308
|
export const testAgent = new Agent({
|
|
296
309
|
id: "test-agent",
|
|
297
310
|
name: "Test Agent",
|
|
298
|
-
// ...
|
|
299
311
|
model: ({ requestContext }) => {
|
|
300
312
|
const userTier = requestContext.get("user-tier") as UserTier["user-tier"];
|
|
301
313
|
|
|
@@ -306,7 +318,11 @@ export const testAgent = new Agent({
|
|
|
306
318
|
});
|
|
307
319
|
```
|
|
308
320
|
|
|
309
|
-
|
|
321
|
+
:::info
|
|
322
|
+
|
|
323
|
+
See [Request Context](/docs/v1/server/request-context) for more information.
|
|
324
|
+
|
|
325
|
+
:::
|
|
310
326
|
|
|
311
327
|
## Testing with Studio
|
|
312
328
|
|
|
@@ -35,18 +35,17 @@ Mastra includes several processors for common use cases. You can also create cus
|
|
|
35
35
|
|
|
36
36
|
Import and instantiate the processor, then pass it to the agent's `inputProcessors` or `outputProcessors` array:
|
|
37
37
|
|
|
38
|
-
```typescript {
|
|
39
|
-
import { openai } from "@ai-sdk/openai";
|
|
38
|
+
```typescript {2,8-14} title="src/mastra/agents/moderated-agent.ts"
|
|
40
39
|
import { Agent } from "@mastra/core/agent";
|
|
41
40
|
import { ModerationProcessor } from "@mastra/core/processors";
|
|
42
41
|
|
|
43
42
|
export const moderatedAgent = new Agent({
|
|
44
43
|
name: "moderated-agent",
|
|
45
44
|
instructions: "You are a helpful assistant",
|
|
46
|
-
model: openai
|
|
45
|
+
model: "openai/gpt-4o-mini",
|
|
47
46
|
inputProcessors: [
|
|
48
47
|
new ModerationProcessor({
|
|
49
|
-
model: openai
|
|
48
|
+
model: "openai/gpt-4.1-nano",
|
|
50
49
|
categories: ["hate", "harassment", "violence"],
|
|
51
50
|
threshold: 0.7,
|
|
52
51
|
strategy: "block",
|
|
@@ -77,7 +76,7 @@ When memory is enabled on an agent, memory processors are automatically added to
|
|
|
77
76
|
```
|
|
78
77
|
[Memory Processors] → [Your inputProcessors]
|
|
79
78
|
```
|
|
80
|
-
Memory loads
|
|
79
|
+
Memory loads message history first, then your processors run.
|
|
81
80
|
|
|
82
81
|
**Output processors:**
|
|
83
82
|
```
|
|
@@ -93,7 +92,7 @@ Custom processors implement the `Processor` interface:
|
|
|
93
92
|
|
|
94
93
|
### Custom input processor
|
|
95
94
|
|
|
96
|
-
```typescript title="src/mastra/processors/custom-input.ts"
|
|
95
|
+
```typescript title="src/mastra/processors/custom-input.ts"
|
|
97
96
|
import type {
|
|
98
97
|
Processor,
|
|
99
98
|
MastraDBMessage,
|
|
@@ -141,7 +140,7 @@ The framework handles both return formats, so modifying system messages is optio
|
|
|
141
140
|
|
|
142
141
|
To modify system messages (e.g., trim verbose prompts for smaller models), return an object with both `messages` and `systemMessages`:
|
|
143
142
|
|
|
144
|
-
```typescript title="src/mastra/processors/system-trimmer.ts"
|
|
143
|
+
```typescript title="src/mastra/processors/system-trimmer.ts"
|
|
145
144
|
import type { Processor, CoreMessage, MastraDBMessage } from "@mastra/core";
|
|
146
145
|
|
|
147
146
|
export class SystemTrimmer implements Processor {
|
|
@@ -174,7 +173,7 @@ This is useful for:
|
|
|
174
173
|
|
|
175
174
|
While `processInput` runs once at the start of agent execution, `processInputStep` runs at **each step** of the agentic loop (including tool call continuations). This enables per-step configuration changes like dynamic model switching or tool choice modifications.
|
|
176
175
|
|
|
177
|
-
```typescript title="src/mastra/processors/step-processor.ts"
|
|
176
|
+
```typescript title="src/mastra/processors/step-processor.ts"
|
|
178
177
|
import type { Processor, ProcessInputStepArgs, ProcessInputStepResult } from "@mastra/core";
|
|
179
178
|
|
|
180
179
|
export class DynamicModelProcessor implements Processor {
|
|
@@ -247,7 +246,7 @@ await agent.generate({
|
|
|
247
246
|
|
|
248
247
|
### Custom output processor
|
|
249
248
|
|
|
250
|
-
```typescript title="src/mastra/processors/custom-output.ts"
|
|
249
|
+
```typescript title="src/mastra/processors/custom-output.ts"
|
|
251
250
|
import type {
|
|
252
251
|
Processor,
|
|
253
252
|
MastraDBMessage,
|
|
@@ -292,14 +291,13 @@ Mastra provides utility processors for common tasks:
|
|
|
292
291
|
|
|
293
292
|
Prevents context window overflow by removing older messages when the total token count exceeds a specified limit.
|
|
294
293
|
|
|
295
|
-
```typescript
|
|
294
|
+
```typescript {7-10}
|
|
296
295
|
import { Agent } from "@mastra/core/agent";
|
|
297
296
|
import { TokenLimiter } from "@mastra/core/processors";
|
|
298
|
-
import { openai } from "@ai-sdk/openai";
|
|
299
297
|
|
|
300
298
|
const agent = new Agent({
|
|
301
299
|
name: "my-agent",
|
|
302
|
-
model: openai
|
|
300
|
+
model: "openai/gpt-4o",
|
|
303
301
|
inputProcessors: [
|
|
304
302
|
// Ensure the total tokens don't exceed ~127k
|
|
305
303
|
new TokenLimiter(127000),
|
|
@@ -309,7 +307,7 @@ const agent = new Agent({
|
|
|
309
307
|
|
|
310
308
|
The `TokenLimiter` uses the `o200k_base` encoding by default (suitable for GPT-4o). You can specify other encodings for different models:
|
|
311
309
|
|
|
312
|
-
```typescript
|
|
310
|
+
```typescript {6-9}
|
|
313
311
|
import cl100k_base from "js-tiktoken/ranks/cl100k_base";
|
|
314
312
|
|
|
315
313
|
const agent = new Agent({
|
|
@@ -327,14 +325,13 @@ const agent = new Agent({
|
|
|
327
325
|
|
|
328
326
|
Removes tool calls from messages sent to the LLM, saving tokens by excluding potentially verbose tool interactions.
|
|
329
327
|
|
|
330
|
-
```typescript
|
|
328
|
+
```typescript {7-16}
|
|
331
329
|
import { Agent } from "@mastra/core/agent";
|
|
332
330
|
import { ToolCallFilter, TokenLimiter } from "@mastra/core/processors";
|
|
333
|
-
import { openai } from "@ai-sdk/openai";
|
|
334
331
|
|
|
335
332
|
const agent = new Agent({
|
|
336
333
|
name: "my-agent",
|
|
337
|
-
model: openai
|
|
334
|
+
model: "openai/gpt-4o",
|
|
338
335
|
inputProcessors: [
|
|
339
336
|
// Example 1: Remove all tool calls/results
|
|
340
337
|
new ToolCallFilter(),
|
|
@@ -348,13 +345,17 @@ const agent = new Agent({
|
|
|
348
345
|
});
|
|
349
346
|
```
|
|
350
347
|
|
|
351
|
-
|
|
348
|
+
:::note
|
|
349
|
+
|
|
350
|
+
The example above filters tool calls and limits tokens for the LLM, but these filtered messages will still be saved to memory. To also filter messages before they're saved to memory, manually add memory processors before utility processors. See [Memory Processors](/docs/v1/memory/memory-processors#manual-control-and-deduplication) for details.
|
|
351
|
+
|
|
352
|
+
:::
|
|
352
353
|
|
|
353
354
|
## Using workflows as processors
|
|
354
355
|
|
|
355
356
|
You can use Mastra workflows as processors to create complex processing pipelines with parallel execution, conditional branching, and error handling:
|
|
356
357
|
|
|
357
|
-
```typescript title="src/mastra/processors/moderation-workflow.ts"
|
|
358
|
+
```typescript title="src/mastra/processors/moderation-workflow.ts"
|
|
358
359
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
359
360
|
import { ProcessorStepSchema } from "@mastra/core/processors";
|
|
360
361
|
import { Agent } from "@mastra/core/agent";
|
|
@@ -387,7 +388,7 @@ When an agent is registered with Mastra, processor workflows are automatically r
|
|
|
387
388
|
|
|
388
389
|
Processors can request that the LLM retry its response with feedback. This is useful for implementing quality checks, output validation, or iterative refinement:
|
|
389
390
|
|
|
390
|
-
```typescript title="src/mastra/processors/quality-checker.ts"
|
|
391
|
+
```typescript title="src/mastra/processors/quality-checker.ts"
|
|
391
392
|
import type { Processor } from "@mastra/core";
|
|
392
393
|
|
|
393
394
|
export class QualityChecker implements Processor {
|
|
@@ -23,7 +23,7 @@ Agents can return structured data by defining the expected output with either [Z
|
|
|
23
23
|
|
|
24
24
|
Define the `output` shape using [Zod](https://zod.dev/):
|
|
25
25
|
|
|
26
|
-
```typescript
|
|
26
|
+
```typescript
|
|
27
27
|
import { z } from "zod";
|
|
28
28
|
|
|
29
29
|
const response = await testAgent.generate("Help me plan my day.", {
|
|
@@ -45,7 +45,7 @@ console.log(response.object);
|
|
|
45
45
|
|
|
46
46
|
You can also use JSON Schema to define your output structure:
|
|
47
47
|
|
|
48
|
-
```typescript
|
|
48
|
+
```typescript
|
|
49
49
|
const response = await testAgent.generate("Help me plan my day.", {
|
|
50
50
|
structuredOutput: {
|
|
51
51
|
schema: {
|
|
@@ -72,7 +72,11 @@ console.log(response.object);
|
|
|
72
72
|
</Tabs>
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
:::info
|
|
76
|
+
|
|
77
|
+
Visit [.generate()](/reference/v1/agents/generate#structuredoutput) for a full list of configuration options.
|
|
78
|
+
|
|
79
|
+
:::
|
|
76
80
|
|
|
77
81
|
### Example output
|
|
78
82
|
|
|
@@ -99,7 +103,7 @@ The `response.object` will contain the structured data as defined by the schema.
|
|
|
99
103
|
|
|
100
104
|
Streaming also supports structured output. The final structured object is available on `stream.fullStream` and after the stream completes on `stream.object`. Text stream chunks are still emitted, but they contain natural language text rather than structured data.
|
|
101
105
|
|
|
102
|
-
```typescript
|
|
106
|
+
```typescript
|
|
103
107
|
import { z } from "zod";
|
|
104
108
|
|
|
105
109
|
const stream = await testAgent.stream("Help me plan my day.", {
|
|
@@ -131,7 +135,7 @@ for await (const chunk of stream.textStream) {
|
|
|
131
135
|
|
|
132
136
|
When your main agent isn't proficient at creating structured output you can provide a `model` to `structuredOutput`. In this case, Mastra uses a second agent under the hood to extract structured data from the main agent's natural language response. This makes two LLM calls, one to generate the response and another to turn that response into the structured object, which adds some latency and cost but can improve accuracy for complex structuring tasks.
|
|
133
137
|
|
|
134
|
-
```typescript
|
|
138
|
+
```typescript
|
|
135
139
|
import { z } from "zod";
|
|
136
140
|
|
|
137
141
|
const response = await testAgent.generate("Analyze the TypeScript programming language.", {
|
|
@@ -162,7 +166,7 @@ By default, Mastra passes the schema to the model provider using the `response_f
|
|
|
162
166
|
|
|
163
167
|
If your model provider doesn't support `response_format`, you'll get an error from the API. When this happens, set `jsonPromptInjection: true`. This adds the schema to the system prompt instead, instructing the model to output JSON. This is less reliable than the API parameter approach.
|
|
164
168
|
|
|
165
|
-
```typescript
|
|
169
|
+
```typescript
|
|
166
170
|
import { z } from "zod";
|
|
167
171
|
|
|
168
172
|
const response = await testAgent.generate("Help me plan my day.", {
|
|
@@ -198,7 +202,7 @@ const response = await agentWithTools.generate("Your prompt", {
|
|
|
198
202
|
|
|
199
203
|
When schema validation fails, you can control how errors are handled using `errorStrategy`. The default `strict` strategy throws an error, while `warn` logs a warning and continues. The `fallback` strategy returns the values provided using `fallbackValue`.
|
|
200
204
|
|
|
201
|
-
```typescript
|
|
205
|
+
```typescript
|
|
202
206
|
import { z } from "zod";
|
|
203
207
|
|
|
204
208
|
const response = await testAgent.generate("Tell me about TypeScript.", {
|
|
@@ -17,7 +17,7 @@ When creating tools, keep descriptions simple and focused on what the tool does,
|
|
|
17
17
|
|
|
18
18
|
This example shows how to create a tool that fetches weather data from an API. When the agent calls the tool, it provides the required input as defined by the tool's `inputSchema`. The tool accesses this data through its `inputData` parameter, which in this example includes the `location` used in the weather API query.
|
|
19
19
|
|
|
20
|
-
```typescript
|
|
20
|
+
```typescript title="src/mastra/tools/weather-tool.ts"
|
|
21
21
|
import { createTool } from "@mastra/core/tools";
|
|
22
22
|
import { z } from "zod";
|
|
23
23
|
|
|
@@ -47,7 +47,7 @@ To make a tool available to an agent, add it to `tools`. Mentioning available to
|
|
|
47
47
|
|
|
48
48
|
An agent can use multiple tools to handle more complex tasks by delegating specific parts to individual tools. The agent decides which tools to use based on the user's message, the agent's instructions, and the tool descriptions and schemas.
|
|
49
49
|
|
|
50
|
-
```typescript {
|
|
50
|
+
```typescript {11} title="src/mastra/agents/weather-agent.ts"
|
|
51
51
|
import { Agent } from "@mastra/core/agent";
|
|
52
52
|
import { weatherTool } from "../tools/weather-tool";
|
|
53
53
|
|
|
@@ -66,7 +66,7 @@ export const weatherAgent = new Agent({
|
|
|
66
66
|
|
|
67
67
|
The agent uses the tool's `inputSchema` to infer what data the tool expects. In this case, it extracts `London` as the `location` from the message and passes it to the tool's inputData parameter.
|
|
68
68
|
|
|
69
|
-
```typescript title="src/test-tool.ts"
|
|
69
|
+
```typescript title="src/test-tool.ts"
|
|
70
70
|
import { mastra } from "./mastra";
|
|
71
71
|
|
|
72
72
|
const agent = mastra.getAgent("weatherAgent");
|
|
@@ -78,14 +78,13 @@ const result = await agent.generate("What's the weather in London?");
|
|
|
78
78
|
|
|
79
79
|
When multiple tools are available, the agent may choose to use one, several, or none, depending on what's needed to answer the query.
|
|
80
80
|
|
|
81
|
-
```typescript {
|
|
81
|
+
```typescript {7} title="src/mastra/agents/weather-agent.ts"
|
|
82
82
|
import { weatherTool } from "../tools/weather-tool";
|
|
83
83
|
import { activitiesTool } from "../tools/activities-tool";
|
|
84
84
|
|
|
85
85
|
export const weatherAgent = new Agent({
|
|
86
86
|
id: "weather-agent",
|
|
87
87
|
name: "Weather Agent",
|
|
88
|
-
// ..
|
|
89
88
|
tools: { weatherTool, activitiesTool },
|
|
90
89
|
});
|
|
91
90
|
```
|
|
@@ -26,7 +26,7 @@ tsconfig.json
|
|
|
26
26
|
|
|
27
27
|
The `mastra build` command starts the build process:
|
|
28
28
|
|
|
29
|
-
```bash
|
|
29
|
+
```bash
|
|
30
30
|
mastra build
|
|
31
31
|
```
|
|
32
32
|
|
|
@@ -34,7 +34,7 @@ mastra build
|
|
|
34
34
|
|
|
35
35
|
If your Mastra files are located elsewhere, use the `--dir` flag to specify the custom location. The `--dir` flag tells Mastra where to find your entry point file (`index.ts` or `index.js`) and related directories.
|
|
36
36
|
|
|
37
|
-
```bash
|
|
37
|
+
```bash
|
|
38
38
|
mastra build --dir ./my-project/mastra
|
|
39
39
|
```
|
|
40
40
|
|
|
@@ -68,6 +68,6 @@ If a `public` folder exists in `src/mastra`, its contents are copied into the `.
|
|
|
68
68
|
|
|
69
69
|
Start the HTTP server:
|
|
70
70
|
|
|
71
|
-
```bash
|
|
71
|
+
```bash
|
|
72
72
|
node .mastra/output/index.mjs
|
|
73
73
|
```
|
|
@@ -55,3 +55,10 @@ When Mastra is integrated with a web framework, it deploys alongside your applic
|
|
|
55
55
|
We're building Mastra Cloud to be the easiest place to deploy and observe your Mastra agents. It's currently in beta.
|
|
56
56
|
|
|
57
57
|
Learn more in the [Mastra Cloud docs](/docs/v1/mastra-cloud/overview).
|
|
58
|
+
|
|
59
|
+
## Workflow Runners
|
|
60
|
+
|
|
61
|
+
Mastra supports deploying workflows to specialized workflow execution platforms that handle orchestration, monitoring, and reliability. [Inngest](https://www.inngest.com) is a developer platform for running background workflows without managing infrastructure. Mastra workflows can be deployed to Inngest, which provides step memoization, automatic retries, real-time monitoring, and suspend/resume capabilities.
|
|
62
|
+
|
|
63
|
+
- [Inngest deployment guide](/guides/v1/deployment/inngest)
|
|
64
|
+
- [Inngest workflow example](https://github.com/mastra-ai/mastra/tree/main/examples/inngest)
|
|
@@ -8,7 +8,7 @@ description: "Learn how Mastra can be deployed when integrated with a Web Framew
|
|
|
8
8
|
When Mastra is integrated with a web framework, it deploys alongside your application using the framework's standard deployment process. Follow the instructions below to ensure your Mastra integration deploys correctly.
|
|
9
9
|
|
|
10
10
|
:::warning
|
|
11
|
-
If you're deploying to a cloud provider, remove any usage of [LibSQLStore](/
|
|
11
|
+
If you're deploying to a cloud provider, remove any usage of [LibSQLStore](/reference/v1/storage/libsql) from your Mastra configuration. LibSQLStore requires filesystem access and is not compatible with serverless platforms.
|
|
12
12
|
:::
|
|
13
13
|
|
|
14
14
|
Integration guides:
|
|
@@ -20,7 +20,7 @@ Integration guides:
|
|
|
20
20
|
|
|
21
21
|
If you've integrated Mastra with Next.js [by following our guide](/guides/v1/getting-started/next-js) and plan to deploy to Vercel, add `serverExternalPackages: ["@mastra/*"]` to your `next.config.ts`:
|
|
22
22
|
|
|
23
|
-
```typescript {4} title="next.config.ts"
|
|
23
|
+
```typescript {4} title="next.config.ts"
|
|
24
24
|
import type { NextConfig } from "next";
|
|
25
25
|
|
|
26
26
|
const nextConfig: NextConfig = {
|
|
@@ -34,12 +34,11 @@ export default nextConfig;
|
|
|
34
34
|
|
|
35
35
|
If you've integrated Mastra with Astro [by following our guide](/guides/v1/getting-started/astro) and plan to deploy to Vercel, add the Vercel adapter and server output to your `astro.config.mjs`:
|
|
36
36
|
|
|
37
|
-
```javascript {2,6
|
|
37
|
+
```javascript {2,5-6} title="astro.config.mjs"
|
|
38
38
|
import { defineConfig } from "astro/config";
|
|
39
39
|
import vercel from "@astrojs/vercel";
|
|
40
40
|
|
|
41
41
|
export default defineConfig({
|
|
42
|
-
// ...
|
|
43
42
|
adapter: vercel(),
|
|
44
43
|
output: "server",
|
|
45
44
|
});
|
|
@@ -49,12 +48,11 @@ export default defineConfig({
|
|
|
49
48
|
|
|
50
49
|
If you've integrated Mastra with Astro [by following our guide](/guides/v1/getting-started/astro) and plan to deploy to Netlify, add the Netlify adapter and server output to your `astro.config.mjs`:
|
|
51
50
|
|
|
52
|
-
```javascript {2,6
|
|
51
|
+
```javascript {2,5-6} title="astro.config.mjs"
|
|
53
52
|
import { defineConfig } from "astro/config";
|
|
54
53
|
import netlify from "@astrojs/netlify";
|
|
55
54
|
|
|
56
55
|
export default defineConfig({
|
|
57
|
-
// ...
|
|
58
56
|
adapter: netlify(),
|
|
59
57
|
output: "server",
|
|
60
58
|
});
|
|
@@ -65,7 +65,6 @@ For type safety and compatibility with both live agent scoring and trace scoring
|
|
|
65
65
|
|
|
66
66
|
```typescript
|
|
67
67
|
const myScorer = createScorer({
|
|
68
|
-
// ...
|
|
69
68
|
type: "agent", // Automatically handles agent input/output types
|
|
70
69
|
}).generateScore(({ run, results }) => {
|
|
71
70
|
// run.output is automatically typed as ScorerRunOutputForAgent
|
|
@@ -241,9 +240,13 @@ A custom scorer in Mastra uses `createScorer` with four core components:
|
|
|
241
240
|
|
|
242
241
|
Together, these components allow you to define custom evaluation logic using LLMs as judges.
|
|
243
242
|
|
|
244
|
-
|
|
243
|
+
:::info
|
|
245
244
|
|
|
246
|
-
|
|
245
|
+
Visit [createScorer](/reference/v1/evals/create-scorer) for the full API and configuration options.
|
|
246
|
+
|
|
247
|
+
:::
|
|
248
|
+
|
|
249
|
+
```typescript title="src/mastra/scorers/gluten-checker.ts"
|
|
247
250
|
import { createScorer } from "@mastra/core/evals";
|
|
248
251
|
import { z } from "zod";
|
|
249
252
|
|
|
@@ -399,7 +402,7 @@ The reason generation step creates explanations that help users understand why a
|
|
|
399
402
|
|
|
400
403
|
## High gluten-free example
|
|
401
404
|
|
|
402
|
-
```typescript title="src/example-high-gluten-free.ts"
|
|
405
|
+
```typescript title="src/example-high-gluten-free.ts"
|
|
403
406
|
const result = await glutenCheckerScorer.run({
|
|
404
407
|
input: [{ role: 'user', content: 'Mix rice, beans, and vegetables' }],
|
|
405
408
|
output: { text: 'Mix rice, beans, and vegetables' },
|
|
@@ -425,7 +428,7 @@ console.log('Reason:', result.reason);
|
|
|
425
428
|
|
|
426
429
|
## Partial gluten example
|
|
427
430
|
|
|
428
|
-
```typescript title="src/example-partial-gluten.ts"
|
|
431
|
+
```typescript title="src/example-partial-gluten.ts"
|
|
429
432
|
const result = await glutenCheckerScorer.run({
|
|
430
433
|
input: [{ role: "user", content: "Mix flour and water to make dough" }],
|
|
431
434
|
output: { text: "Mix flour and water to make dough" },
|
|
@@ -451,7 +454,7 @@ console.log("Reason:", result.reason);
|
|
|
451
454
|
|
|
452
455
|
## Low gluten-free example
|
|
453
456
|
|
|
454
|
-
```typescript title="src/example-low-gluten-free.ts"
|
|
457
|
+
```typescript title="src/example-low-gluten-free.ts"
|
|
455
458
|
const result = await glutenCheckerScorer.run({
|
|
456
459
|
input: [{ role: "user", content: "Add soy sauce and noodles" }],
|
|
457
460
|
output: { text: "Add soy sauce and noodles" },
|
|
@@ -23,7 +23,7 @@ There are different kinds of scorers, each serving a specific purpose. Here are
|
|
|
23
23
|
|
|
24
24
|
To access Mastra's scorers feature install the `@mastra/evals` package.
|
|
25
25
|
|
|
26
|
-
```bash
|
|
26
|
+
```bash
|
|
27
27
|
npm install @mastra/evals@beta
|
|
28
28
|
```
|
|
29
29
|
|
|
@@ -35,7 +35,7 @@ npm install @mastra/evals@beta
|
|
|
35
35
|
|
|
36
36
|
You can add built-in scorers to your agents to automatically evaluate their outputs. See the [full list of built-in scorers](/docs/v1/evals/built-in-scorers) for all available options.
|
|
37
37
|
|
|
38
|
-
```typescript title="src/mastra/agents/evaluated-agent.ts"
|
|
38
|
+
```typescript title="src/mastra/agents/evaluated-agent.ts"
|
|
39
39
|
import { Agent } from "@mastra/core/agent";
|
|
40
40
|
import {
|
|
41
41
|
createAnswerRelevancyScorer,
|
|
@@ -43,7 +43,6 @@ import {
|
|
|
43
43
|
} from "@mastra/evals/scorers/prebuilt";
|
|
44
44
|
|
|
45
45
|
export const evaluatedAgent = new Agent({
|
|
46
|
-
// ...
|
|
47
46
|
scorers: {
|
|
48
47
|
relevancy: {
|
|
49
48
|
scorer: createAnswerRelevancyScorer({ model: "openai/gpt-4.1-nano" }),
|
|
@@ -61,13 +60,12 @@ export const evaluatedAgent = new Agent({
|
|
|
61
60
|
|
|
62
61
|
You can also add scorers to individual workflow steps to evaluate outputs at specific points in your process:
|
|
63
62
|
|
|
64
|
-
```typescript title="src/mastra/workflows/content-generation.ts"
|
|
63
|
+
```typescript title="src/mastra/workflows/content-generation.ts"
|
|
65
64
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
66
65
|
import { z } from "zod";
|
|
67
66
|
import { customStepScorer } from "../scorers/custom-step-scorer";
|
|
68
67
|
|
|
69
68
|
const contentStep = createStep({
|
|
70
|
-
// ...
|
|
71
69
|
scorers: {
|
|
72
70
|
customStepScorer: {
|
|
73
71
|
scorer: customStepScorer(),
|
|
@@ -115,7 +113,6 @@ To score traces, you first need to register your scorers with your Mastra instan
|
|
|
115
113
|
|
|
116
114
|
```typescript
|
|
117
115
|
const mastra = new Mastra({
|
|
118
|
-
// ...
|
|
119
116
|
scorers: {
|
|
120
117
|
answerRelevancy: myAnswerRelevancyScorer,
|
|
121
118
|
responseQuality: myResponseQualityScorer,
|
|
@@ -15,7 +15,7 @@ You can use any testing framework that supports ESM modules, such as [Vitest](ht
|
|
|
15
15
|
|
|
16
16
|
Use `runEvals` to evaluate your agent against multiple test cases. The function accepts an array of data items, each containing an `input` and optional `groundTruth` for scorer validation.
|
|
17
17
|
|
|
18
|
-
```typescript
|
|
18
|
+
```typescript title="src/mastra/agents/weather-agent.test.ts"
|
|
19
19
|
import { describe, it, expect } from 'vitest';
|
|
20
20
|
import { createScorer, runEvals } from "@mastra/core/evals";
|
|
21
21
|
import { weatherAgent } from "./weather-agent";
|
|
@@ -72,7 +72,7 @@ The `runEvals` function returns an object with:
|
|
|
72
72
|
|
|
73
73
|
Create separate test cases for different evaluation scenarios:
|
|
74
74
|
|
|
75
|
-
```typescript
|
|
75
|
+
```typescript title="src/mastra/agents/weather-agent.test.ts"
|
|
76
76
|
describe('Weather Agent Tests', () => {
|
|
77
77
|
const locationScorer = createScorer({ /* ... */ });
|
|
78
78
|
|