@mastra/mcp-docs-server 0.0.0-default-storage-virtual-file-20250410035748
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%2Fastra.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +131 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +80 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +166 -0
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +220 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +220 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +299 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
- package/.docs/organized/changelogs/create-mastra.md +302 -0
- package/.docs/organized/changelogs/mastra.md +302 -0
- package/.docs/organized/code-examples/agent-network.md +282 -0
- package/.docs/organized/code-examples/agent.md +390 -0
- package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
- package/.docs/organized/code-examples/assistant-ui.md +37 -0
- package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
- package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
- package/.docs/organized/code-examples/fireworks-r1.md +159 -0
- package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
- package/.docs/organized/code-examples/memory-with-context.md +167 -0
- package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
- package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
- package/.docs/organized/code-examples/memory-with-pg.md +224 -0
- package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
- package/.docs/organized/code-examples/quick-start.md +129 -0
- package/.docs/organized/code-examples/stock-price-tool.md +124 -0
- package/.docs/organized/code-examples/weather-agent.md +353 -0
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
- package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
- package/.docs/raw/agents/adding-tools.mdx +239 -0
- package/.docs/raw/agents/adding-voice.mdx +175 -0
- package/.docs/raw/agents/agent-memory.mdx +62 -0
- package/.docs/raw/agents/mcp-guide.mdx +192 -0
- package/.docs/raw/agents/overview.mdx +303 -0
- package/.docs/raw/community/discord.mdx +12 -0
- package/.docs/raw/community/licensing.mdx +63 -0
- package/.docs/raw/deployment/client.mdx +120 -0
- package/.docs/raw/deployment/deployment.mdx +119 -0
- package/.docs/raw/deployment/server.mdx +276 -0
- package/.docs/raw/evals/custom-eval.mdx +22 -0
- package/.docs/raw/evals/overview.mdx +95 -0
- package/.docs/raw/evals/running-in-ci.mdx +81 -0
- package/.docs/raw/evals/textual-evals.mdx +54 -0
- package/.docs/raw/faq/index.mdx +63 -0
- package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
- package/.docs/raw/frameworks/next-js.mdx +238 -0
- package/.docs/raw/getting-started/installation.mdx +436 -0
- package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
- package/.docs/raw/getting-started/project-structure.mdx +80 -0
- package/.docs/raw/index.mdx +22 -0
- package/.docs/raw/integrations/index.mdx +213 -0
- package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
- package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
- package/.docs/raw/local-dev/mastra-dev.mdx +108 -0
- package/.docs/raw/memory/memory-processors.mdx +131 -0
- package/.docs/raw/memory/overview.mdx +119 -0
- package/.docs/raw/memory/semantic-recall.mdx +122 -0
- package/.docs/raw/memory/working-memory.mdx +87 -0
- package/.docs/raw/observability/logging.mdx +38 -0
- package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
- package/.docs/raw/observability/tracing.mdx +115 -0
- package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
- package/.docs/raw/rag/overview.mdx +85 -0
- package/.docs/raw/rag/retrieval.mdx +365 -0
- package/.docs/raw/rag/vector-databases.mdx +340 -0
- package/.docs/raw/reference/agents/createTool.mdx +229 -0
- package/.docs/raw/reference/agents/generate.mdx +327 -0
- package/.docs/raw/reference/agents/getAgent.mdx +54 -0
- package/.docs/raw/reference/agents/stream.mdx +362 -0
- package/.docs/raw/reference/cli/build.mdx +48 -0
- package/.docs/raw/reference/cli/deploy.mdx +22 -0
- package/.docs/raw/reference/cli/dev.mdx +134 -0
- package/.docs/raw/reference/cli/init.mdx +43 -0
- package/.docs/raw/reference/client-js/agents.mdx +107 -0
- package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
- package/.docs/raw/reference/client-js/logs.mdx +24 -0
- package/.docs/raw/reference/client-js/memory.mdx +97 -0
- package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
- package/.docs/raw/reference/client-js/tools.mdx +44 -0
- package/.docs/raw/reference/client-js/vectors.mdx +79 -0
- package/.docs/raw/reference/client-js/workflows.mdx +136 -0
- package/.docs/raw/reference/core/mastra-class.mdx +232 -0
- package/.docs/raw/reference/deployer/cloudflare.mdx +176 -0
- package/.docs/raw/reference/deployer/deployer.mdx +159 -0
- package/.docs/raw/reference/deployer/netlify.mdx +88 -0
- package/.docs/raw/reference/deployer/vercel.mdx +97 -0
- package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
- package/.docs/raw/reference/evals/bias.mdx +186 -0
- package/.docs/raw/reference/evals/completeness.mdx +174 -0
- package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
- package/.docs/raw/reference/evals/context-position.mdx +190 -0
- package/.docs/raw/reference/evals/context-precision.mdx +189 -0
- package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
- package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
- package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
- package/.docs/raw/reference/evals/hallucination.mdx +219 -0
- package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
- package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
- package/.docs/raw/reference/evals/summarization.mdx +205 -0
- package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
- package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
- package/.docs/raw/reference/evals/toxicity.mdx +165 -0
- package/.docs/raw/reference/index.mdx +8 -0
- package/.docs/raw/reference/memory/Memory.mdx +212 -0
- package/.docs/raw/reference/memory/createThread.mdx +95 -0
- package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
- package/.docs/raw/reference/memory/query.mdx +167 -0
- package/.docs/raw/reference/networks/agent-network.mdx +159 -0
- package/.docs/raw/reference/observability/create-logger.mdx +106 -0
- package/.docs/raw/reference/observability/logger.mdx +55 -0
- package/.docs/raw/reference/observability/otel-config.mdx +120 -0
- package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
- package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
- package/.docs/raw/reference/observability/providers/index.mdx +16 -0
- package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
- package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
- package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
- package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
- package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
- package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
- package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
- package/.docs/raw/reference/rag/astra.mdx +258 -0
- package/.docs/raw/reference/rag/chroma.mdx +281 -0
- package/.docs/raw/reference/rag/chunk.mdx +235 -0
- package/.docs/raw/reference/rag/document.mdx +127 -0
- package/.docs/raw/reference/rag/embeddings.mdx +160 -0
- package/.docs/raw/reference/rag/extract-params.mdx +226 -0
- package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
- package/.docs/raw/reference/rag/libsql.mdx +357 -0
- package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
- package/.docs/raw/reference/rag/pg.mdx +477 -0
- package/.docs/raw/reference/rag/pinecone.mdx +281 -0
- package/.docs/raw/reference/rag/qdrant.mdx +236 -0
- package/.docs/raw/reference/rag/rerank.mdx +212 -0
- package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
- package/.docs/raw/reference/rag/upstash.mdx +247 -0
- package/.docs/raw/reference/rag/vectorize.mdx +298 -0
- package/.docs/raw/reference/storage/libsql.mdx +74 -0
- package/.docs/raw/reference/storage/postgresql.mdx +48 -0
- package/.docs/raw/reference/storage/upstash.mdx +86 -0
- package/.docs/raw/reference/tools/client.mdx +188 -0
- package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
- package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
- package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
- package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
- package/.docs/raw/reference/voice/deepgram.mdx +164 -0
- package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
- package/.docs/raw/reference/voice/google.mdx +198 -0
- package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
- package/.docs/raw/reference/voice/murf.mdx +251 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
- package/.docs/raw/reference/voice/openai.mdx +168 -0
- package/.docs/raw/reference/voice/playai.mdx +159 -0
- package/.docs/raw/reference/voice/sarvam.mdx +260 -0
- package/.docs/raw/reference/voice/speechify.mdx +145 -0
- package/.docs/raw/reference/voice/voice.answer.mdx +122 -0
- package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
- package/.docs/raw/reference/voice/voice.listen.mdx +195 -0
- package/.docs/raw/reference/voice/voice.on.mdx +189 -0
- package/.docs/raw/reference/voice/voice.send.mdx +118 -0
- package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
- package/.docs/raw/reference/workflows/after.mdx +88 -0
- package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
- package/.docs/raw/reference/workflows/commit.mdx +37 -0
- package/.docs/raw/reference/workflows/createRun.mdx +77 -0
- package/.docs/raw/reference/workflows/else.mdx +72 -0
- package/.docs/raw/reference/workflows/events.mdx +305 -0
- package/.docs/raw/reference/workflows/execute.mdx +110 -0
- package/.docs/raw/reference/workflows/if.mdx +107 -0
- package/.docs/raw/reference/workflows/resume.mdx +155 -0
- package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
- package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
- package/.docs/raw/reference/workflows/start.mdx +84 -0
- package/.docs/raw/reference/workflows/step-class.mdx +100 -0
- package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
- package/.docs/raw/reference/workflows/step-function.mdx +92 -0
- package/.docs/raw/reference/workflows/step-options.mdx +69 -0
- package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
- package/.docs/raw/reference/workflows/suspend.mdx +70 -0
- package/.docs/raw/reference/workflows/then.mdx +74 -0
- package/.docs/raw/reference/workflows/until.mdx +165 -0
- package/.docs/raw/reference/workflows/watch.mdx +118 -0
- package/.docs/raw/reference/workflows/while.mdx +168 -0
- package/.docs/raw/reference/workflows/workflow.mdx +233 -0
- package/.docs/raw/storage/overview.mdx +378 -0
- package/.docs/raw/voice/overview.mdx +135 -0
- package/.docs/raw/voice/speech-to-text.mdx +45 -0
- package/.docs/raw/voice/text-to-speech.mdx +52 -0
- package/.docs/raw/voice/voice-to-voice.mdx +310 -0
- package/.docs/raw/workflows/control-flow.mdx +778 -0
- package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
- package/.docs/raw/workflows/error-handling.mdx +183 -0
- package/.docs/raw/workflows/nested-workflows.mdx +352 -0
- package/.docs/raw/workflows/overview.mdx +167 -0
- package/.docs/raw/workflows/steps.mdx +108 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
- package/.docs/raw/workflows/variables.mdx +313 -0
- package/LICENSE +44 -0
- package/README.md +129 -0
- package/dist/_tsup-dts-rollup.d.ts +149 -0
- package/dist/chunk-QWYMT5LP.js +194 -0
- package/dist/prepare-docs/prepare.d.ts +1 -0
- package/dist/prepare-docs/prepare.js +1 -0
- package/dist/stdio.d.ts +1 -0
- package/dist/stdio.js +518 -0
- package/package.json +60 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Using Mastra Integrations | Mastra Local Development Docs"
|
|
3
|
+
description: Documentation for Mastra integrations, which are auto-generated, type-safe API clients for third-party services.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Using Mastra Integrations
|
|
7
|
+
|
|
8
|
+
Integrations in Mastra are auto-generated, type-safe API clients for third-party services. They can be used as tools for agents or as steps in workflows.
|
|
9
|
+
|
|
10
|
+
## Installing an Integration
|
|
11
|
+
|
|
12
|
+
Mastra's default integrations are packaged as individually installable npm modules. You can add an integration to your project by installing it via npm and importing it into your Mastra configuration.
|
|
13
|
+
|
|
14
|
+
### Example: Adding the GitHub Integration
|
|
15
|
+
|
|
16
|
+
1. **Install the Integration Package**
|
|
17
|
+
|
|
18
|
+
To install the GitHub integration, run:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @mastra/github
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
2. **Add the Integration to Your Project**
|
|
25
|
+
|
|
26
|
+
Create a new file for your integrations (e.g., `src/mastra/integrations/index.ts`) and import the integration:
|
|
27
|
+
|
|
28
|
+
```typescript filename="src/mastra/integrations/index.ts" showLineNumbers copy
|
|
29
|
+
import { GithubIntegration } from "@mastra/github";
|
|
30
|
+
|
|
31
|
+
export const github = new GithubIntegration({
|
|
32
|
+
config: {
|
|
33
|
+
PERSONAL_ACCESS_TOKEN: process.env.GITHUB_PAT!,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Make sure to replace `process.env.GITHUB_PAT!` with your actual GitHub Personal Access Token or ensure that the environment variable is properly set.
|
|
39
|
+
|
|
40
|
+
3. **Use the Integration in Tools or Workflows**
|
|
41
|
+
|
|
42
|
+
You can now use the integration when defining tools for your agents or in workflows.
|
|
43
|
+
|
|
44
|
+
```typescript filename="src/mastra/tools/index.ts" showLineNumbers copy
|
|
45
|
+
import { createTool } from "@mastra/core";
|
|
46
|
+
import { z } from "zod";
|
|
47
|
+
import { github } from "../integrations";
|
|
48
|
+
|
|
49
|
+
export const getMainBranchRef = createTool({
|
|
50
|
+
id: "getMainBranchRef",
|
|
51
|
+
description: "Fetch the main branch reference from a GitHub repository",
|
|
52
|
+
inputSchema: z.object({
|
|
53
|
+
owner: z.string(),
|
|
54
|
+
repo: z.string(),
|
|
55
|
+
}),
|
|
56
|
+
outputSchema: z.object({
|
|
57
|
+
ref: z.string().optional(),
|
|
58
|
+
}),
|
|
59
|
+
execute: async ({ context }) => {
|
|
60
|
+
const client = await github.getApiClient();
|
|
61
|
+
|
|
62
|
+
const mainRef = await client.gitGetRef({
|
|
63
|
+
path: {
|
|
64
|
+
owner: context.owner,
|
|
65
|
+
repo: context.repo,
|
|
66
|
+
ref: "heads/main",
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return { ref: mainRef.data?.ref };
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
In the example above:
|
|
76
|
+
|
|
77
|
+
- We import the `github` integration.
|
|
78
|
+
- We define a tool called `getMainBranchRef` that uses the GitHub API client to fetch the reference of the main branch of a repository.
|
|
79
|
+
- The tool accepts `owner` and `repo` as inputs and returns the reference string.
|
|
80
|
+
|
|
81
|
+
## Using Integrations in Agents
|
|
82
|
+
|
|
83
|
+
Once you've defined tools that utilize integrations, you can include these tools in your agents.
|
|
84
|
+
|
|
85
|
+
```typescript filename="src/mastra/agents/index.ts" showLineNumbers copy
|
|
86
|
+
import { openai } from "@ai-sdk/openai";
|
|
87
|
+
import { Agent } from "@mastra/core";
|
|
88
|
+
import { getMainBranchRef } from "../tools";
|
|
89
|
+
|
|
90
|
+
export const codeReviewAgent = new Agent({
|
|
91
|
+
name: "Code Review Agent",
|
|
92
|
+
instructions:
|
|
93
|
+
"An agent that reviews code repositories and provides feedback.",
|
|
94
|
+
model: openai("gpt-4o-mini"),
|
|
95
|
+
tools: {
|
|
96
|
+
getMainBranchRef,
|
|
97
|
+
// other tools...
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
In this setup:
|
|
103
|
+
|
|
104
|
+
- We create an agent named `Code Review Agent`.
|
|
105
|
+
- We include the `getMainBranchRef` tool in the agent's available tools.
|
|
106
|
+
- The agent can now use this tool to interact with GitHub repositories during conversations.
|
|
107
|
+
|
|
108
|
+
## Environment Configuration
|
|
109
|
+
|
|
110
|
+
Ensure that any required API keys or tokens for your integrations are properly set in your environment variables. For example, with the GitHub integration, you need to set your GitHub Personal Access Token:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
GITHUB_PAT=your_personal_access_token
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Consider using a `.env` file or another secure method to manage sensitive credentials.
|
|
117
|
+
|
|
118
|
+
### Example: Adding the Mem0 Integration
|
|
119
|
+
|
|
120
|
+
In this example you'll learn how to use the [Mem0](https://mem0.ai) platform to add long-term memory capabilities to an agent via tool-use.
|
|
121
|
+
This memory integration can work alongside Mastra's own [agent memory features](https://mastra.ai/docs/agents/agent-memory).
|
|
122
|
+
Mem0 enables your agent to memorize and later remember facts per-user across all interactions with that user, while Mastra's memory works per-thread. Using the two in conjunction will allow Mem0 to store long term memories across conversations/interactions, while Mastra's memory will maintain linear conversation history in individual conversations.
|
|
123
|
+
|
|
124
|
+
1. **Install the Integration Package**
|
|
125
|
+
|
|
126
|
+
To install the Mem0 integration, run:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npm install @mastra/mem0
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
2. **Add the Integration to Your Project**
|
|
133
|
+
|
|
134
|
+
Create a new file for your integrations (e.g., `src/mastra/integrations/index.ts`) and import the integration:
|
|
135
|
+
|
|
136
|
+
```typescript filename="src/mastra/integrations/index.ts" showLineNumbers copy
|
|
137
|
+
import { Mem0Integration } from "@mastra/mem0";
|
|
138
|
+
|
|
139
|
+
export const mem0 = new Mem0Integration({
|
|
140
|
+
config: {
|
|
141
|
+
apiKey: process.env.MEM0_API_KEY!,
|
|
142
|
+
userId: "alice",
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
3. **Use the Integration in Tools or Workflows**
|
|
148
|
+
|
|
149
|
+
You can now use the integration when defining tools for your agents or in workflows.
|
|
150
|
+
|
|
151
|
+
```typescript filename="src/mastra/tools/index.ts" showLineNumbers copy
|
|
152
|
+
import { createTool } from "@mastra/core";
|
|
153
|
+
import { z } from "zod";
|
|
154
|
+
import { mem0 } from "../integrations";
|
|
155
|
+
|
|
156
|
+
export const mem0RememberTool = createTool({
|
|
157
|
+
id: "Mem0-remember",
|
|
158
|
+
description:
|
|
159
|
+
"Remember your agent memories that you've previously saved using the Mem0-memorize tool.",
|
|
160
|
+
inputSchema: z.object({
|
|
161
|
+
question: z
|
|
162
|
+
.string()
|
|
163
|
+
.describe("Question used to look up the answer in saved memories."),
|
|
164
|
+
}),
|
|
165
|
+
outputSchema: z.object({
|
|
166
|
+
answer: z.string().describe("Remembered answer"),
|
|
167
|
+
}),
|
|
168
|
+
execute: async ({ context }) => {
|
|
169
|
+
console.log(`Searching memory "${context.question}"`);
|
|
170
|
+
const memory = await mem0.searchMemory(context.question);
|
|
171
|
+
console.log(`\nFound memory "${memory}"\n`);
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
answer: memory,
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
export const mem0MemorizeTool = createTool({
|
|
180
|
+
id: "Mem0-memorize",
|
|
181
|
+
description:
|
|
182
|
+
"Save information to mem0 so you can remember it later using the Mem0-remember tool.",
|
|
183
|
+
inputSchema: z.object({
|
|
184
|
+
statement: z.string().describe("A statement to save into memory"),
|
|
185
|
+
}),
|
|
186
|
+
execute: async ({ context }) => {
|
|
187
|
+
console.log(`\nCreating memory "${context.statement}"\n`);
|
|
188
|
+
// to reduce latency memories can be saved async without blocking tool execution
|
|
189
|
+
void mem0.createMemory(context.statement).then(() => {
|
|
190
|
+
console.log(`\nMemory "${context.statement}" saved.\n`);
|
|
191
|
+
});
|
|
192
|
+
return { success: true };
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
In the example above:
|
|
198
|
+
|
|
199
|
+
- We import the `@mastra/mem0` integration.
|
|
200
|
+
- We define two tools that uses the Mem0 API client to create new memories and recall previously saved memories.
|
|
201
|
+
- The tool accepts `question` as an input and returns the memory as a string.
|
|
202
|
+
|
|
203
|
+
## Available Integrations
|
|
204
|
+
|
|
205
|
+
Mastra provides several built-in integrations; primarily API-key based integrations that do not require OAuth. Some available integrations including Github, Stripe, Resend, Firecrawl, and more.
|
|
206
|
+
|
|
207
|
+
Check [Mastra's codebase](https://github.com/mastra-ai/mastra/tree/main/integrations) or [npm packages](https://www.npmjs.com/search?q=%22%40mastra%22) for a full list of available integrations.
|
|
208
|
+
|
|
209
|
+
## Conclusion
|
|
210
|
+
|
|
211
|
+
Integrations in Mastra enable your AI agents and workflows to interact with external services seamlessly. By installing and configuring integrations, you can extend the capabilities of your application to include operations such as fetching data from APIs, sending messages, or managing resources in third-party systems.
|
|
212
|
+
|
|
213
|
+
Remember to consult the documentation of each integration for specific usage details and to adhere to best practices for security and type safety.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Adding to an Existing Project | Mastra Local Development Docs"
|
|
3
|
+
description: "Add Mastra to your existing Node.js applications"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Adding to an Existing Project
|
|
7
|
+
|
|
8
|
+
You can add Mastra to an existing project using the CLI:
|
|
9
|
+
|
|
10
|
+
```bash npm2yarn copy
|
|
11
|
+
npm install -g mastra@latest
|
|
12
|
+
mastra init
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Changes made to project:
|
|
16
|
+
1. Creates `src/mastra` directory with entry point
|
|
17
|
+
2. Adds required dependencies
|
|
18
|
+
3. Configures TypeScript compiler options
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Interactive Setup
|
|
22
|
+
|
|
23
|
+
Running commands without arguments starts a CLI prompt for:
|
|
24
|
+
|
|
25
|
+
1. Component selection
|
|
26
|
+
2. LLM provider configuration
|
|
27
|
+
3. API key setup
|
|
28
|
+
4. Example code inclusion
|
|
29
|
+
|
|
30
|
+
## Non-Interactive Setup
|
|
31
|
+
|
|
32
|
+
To initialize mastra in non-interactive mode use the following command arguments:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
Arguments:
|
|
36
|
+
--components Specify components: agents, tools, workflows
|
|
37
|
+
--llm-provider LLM provider: openai, anthropic, or groq
|
|
38
|
+
--add-example Include example implementation
|
|
39
|
+
--llm-api-key Provider API key
|
|
40
|
+
--dir Directory for Mastra files (defaults to src/)
|
|
41
|
+
```
|
|
42
|
+
For more details, refer to the [mastra init CLI documentation](/docs/reference/cli/init).
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Creating a new Project | Mastra Local Development Docs"
|
|
3
|
+
description: "Create new Mastra projects or add Mastra to existing Node.js applications using the CLI"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Creating a new project
|
|
7
|
+
|
|
8
|
+
You can create a new project using the `create-mastra` package:
|
|
9
|
+
|
|
10
|
+
```bash npm2yarn copy
|
|
11
|
+
npm create mastra@latest
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
You can also create a new project by using the `mastra` CLI directly:
|
|
15
|
+
|
|
16
|
+
```bash npm2yarn copy
|
|
17
|
+
npm install -g mastra@latest
|
|
18
|
+
mastra create
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Interactive Setup
|
|
22
|
+
|
|
23
|
+
Running commands without arguments starts a CLI prompt for:
|
|
24
|
+
|
|
25
|
+
1. Project name
|
|
26
|
+
1. Component selection
|
|
27
|
+
2. LLM provider configuration
|
|
28
|
+
3. API key setup
|
|
29
|
+
4. Example code inclusion
|
|
30
|
+
|
|
31
|
+
## Non-Interactive Setup
|
|
32
|
+
|
|
33
|
+
To initialize mastra in non-interactive mode use the following command arguments:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
Arguments:
|
|
37
|
+
--components Specify components: agents, tools, workflows
|
|
38
|
+
--llm-provider LLM provider: openai, anthropic, groq, google, or cerebras
|
|
39
|
+
--add-example Include example implementation
|
|
40
|
+
--llm-api-key Provider API key
|
|
41
|
+
--project-name Project name that will be used in package.json and as the project directory name
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
Generated project structure:
|
|
47
|
+
```
|
|
48
|
+
my-project/
|
|
49
|
+
├── src/
|
|
50
|
+
│ └── mastra/
|
|
51
|
+
│ └── index.ts # Mastra entry point
|
|
52
|
+
├── package.json
|
|
53
|
+
└── tsconfig.json
|
|
54
|
+
```
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Inspecting Agents with `mastra dev` | Mastra Local Dev Docs"
|
|
3
|
+
description: Documentation for the Mastra local development environment for Mastra applications.
|
|
4
|
+
---
|
|
5
|
+
import YouTube from "../../../components/youtube";
|
|
6
|
+
|
|
7
|
+
# Local Development Environment
|
|
8
|
+
|
|
9
|
+
Mastra provides a local development environment where you can test your agents, workflows, and tools while developing locally.
|
|
10
|
+
|
|
11
|
+
<YouTube id="spGlcTEjuXY" />
|
|
12
|
+
|
|
13
|
+
## Launch Development Server
|
|
14
|
+
|
|
15
|
+
You can launch the Mastra development environment using the Mastra CLI by running:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
mastra dev
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
By default, the server runs at http://localhost:4111, but you can change the port with the `--port` flag.
|
|
22
|
+
|
|
23
|
+
## Dev Playground
|
|
24
|
+
|
|
25
|
+
`mastra dev` serves a playground UI for interacting with your agents, workflows, and tools. The playground provides dedicated interfaces for testing each component of your Mastra application during development.
|
|
26
|
+
|
|
27
|
+
### Agent Playground
|
|
28
|
+
|
|
29
|
+
The Agent playground provides an interactive chat interface where you can test and debug your agents during development. Key features include:
|
|
30
|
+
|
|
31
|
+
- **Chat Interface**: Directly interact with your agents to test their responses and behavior.
|
|
32
|
+
- **Prompt CMS**: Experiment with different system instructions for your agent:
|
|
33
|
+
- A/B test different prompt versions.
|
|
34
|
+
- Track performance metrics for each variant.
|
|
35
|
+
- Select and deploy the most effective prompt version.
|
|
36
|
+
- **Agent Traces**: View detailed execution traces to understand how your agent processes requests, including:
|
|
37
|
+
- Prompt construction.
|
|
38
|
+
- Tool usage.
|
|
39
|
+
- Decision-making steps.
|
|
40
|
+
- Response generation.
|
|
41
|
+
- **Agent Evals**: When you've set up [Agent evaluation metrics](/docs/evals/overview), you can:
|
|
42
|
+
- Run evaluations directly from the playground.
|
|
43
|
+
- View evaluation results and metrics.
|
|
44
|
+
- Compare agent performance across different test cases.
|
|
45
|
+
|
|
46
|
+
### Workflow Playground
|
|
47
|
+
|
|
48
|
+
The Workflow playground helps you visualize and test your workflow implementations:
|
|
49
|
+
|
|
50
|
+
- **Workflow Visualization**: Workflow graph visualization.
|
|
51
|
+
|
|
52
|
+
- **Run Workflows**:
|
|
53
|
+
- Trigger test workflow runs with custom input data.
|
|
54
|
+
- Debug workflow logic and conditions.
|
|
55
|
+
- Simulate different execution paths.
|
|
56
|
+
- View detailed execution logs for each step.
|
|
57
|
+
|
|
58
|
+
- **Workflow Traces**: Examine detailed execution traces that show:
|
|
59
|
+
- Step-by-step workflow progression.
|
|
60
|
+
- State transitions and data flow.
|
|
61
|
+
- Tool invocations and their results.
|
|
62
|
+
- Decision points and branching logic.
|
|
63
|
+
- Error handling and recovery paths.
|
|
64
|
+
|
|
65
|
+
### Tools Playground
|
|
66
|
+
|
|
67
|
+
The Tools playground allows you to test your custom tools in isolation:
|
|
68
|
+
|
|
69
|
+
- Test individual tools without running a full agent or workflow.
|
|
70
|
+
- Input test data and view tool responses.
|
|
71
|
+
- Debug tool implementation and error handling.
|
|
72
|
+
- Verify tool input/output schemas.
|
|
73
|
+
- Monitor tool performance and execution time.
|
|
74
|
+
|
|
75
|
+
## REST API Endpoints
|
|
76
|
+
|
|
77
|
+
`mastra dev` also spins up REST API routes for your agents and workflows via the local [Mastra Server](/docs/deployment/server). This allows you to test your API endpoints before deployment. See [Mastra Dev reference](/docs/reference/cli/dev#routes) for more details about all endpoints.
|
|
78
|
+
|
|
79
|
+
You can then leverage the [Mastra Client](/docs/deployment/client) SDK to interact with your served REST API routes seamlessly.
|
|
80
|
+
|
|
81
|
+
## OpenAPI Specification
|
|
82
|
+
|
|
83
|
+
`mastra dev` provides an OpenAPI spec at http://localhost:4111/openapi.json
|
|
84
|
+
|
|
85
|
+
## Local Dev Architecture
|
|
86
|
+
|
|
87
|
+
The local development server is designed to run without any external dependencies or containerization. This is achieved through:
|
|
88
|
+
|
|
89
|
+
- **Dev Server**: Uses [Hono](https://hono.dev) as the underlying framework to power the [Mastra Server](/docs/deployment/server).
|
|
90
|
+
|
|
91
|
+
- **In-Memory Storage**: Uses [LibSQL](https://libsql.org/) memory adapters for:
|
|
92
|
+
- Agent memory management.
|
|
93
|
+
- Trace storage.
|
|
94
|
+
- Evals storage.
|
|
95
|
+
- Workflow snapshots.
|
|
96
|
+
|
|
97
|
+
- **Vector Storage**: Uses [FastEmbed](https://github.com/qdrant/fastembed) for:
|
|
98
|
+
- Default embedding generation.
|
|
99
|
+
- Vector storage and retrieval.
|
|
100
|
+
- Semantic search capabilities.
|
|
101
|
+
|
|
102
|
+
This architecture allows you to start developing immediately without setting up databases or vector stores, while still maintaining production-like behavior in your local environment.
|
|
103
|
+
|
|
104
|
+
## Summary
|
|
105
|
+
|
|
106
|
+
`mastra dev` makes it easy to develop, debug, and iterate on your AI logic in a self-contained environment before deploying to production.
|
|
107
|
+
|
|
108
|
+
- [Mastra Dev reference](../reference/cli/dev.mdx)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Memory Processors
|
|
2
|
+
|
|
3
|
+
Memory Processors allow you to modify the list of messages retrieved from memory _before_ they are added to the agent's context window and sent to the LLM. This is useful for managing context size, filtering content, and optimizing performance.
|
|
4
|
+
|
|
5
|
+
Processors operate on the messages retrieved based on your memory configuration (e.g., `lastMessages`, `semanticRecall`). They do **not** affect the new incoming user message.
|
|
6
|
+
|
|
7
|
+
## Built-in Processors
|
|
8
|
+
|
|
9
|
+
Mastra provides built-in processors:
|
|
10
|
+
|
|
11
|
+
### `TokenLimiter`
|
|
12
|
+
|
|
13
|
+
This processor is used to prevent errors caused by exceeding the LLM's context window limit. It counts the tokens in the retrieved memory messages and removes the oldest messages until the total count is below the specified `limit`.
|
|
14
|
+
|
|
15
|
+
```typescript copy showLineNumbers {9-12}
|
|
16
|
+
import { Memory } from "@mastra/memory";
|
|
17
|
+
import { TokenLimiter } from "@mastra/memory/processors";
|
|
18
|
+
import { Agent } from "@mastra/core";
|
|
19
|
+
import { openai } from "@ai-sdk/openai";
|
|
20
|
+
|
|
21
|
+
const agent = new Agent({
|
|
22
|
+
model: openai("gpt-4o"),
|
|
23
|
+
memory: new Memory({
|
|
24
|
+
processors: [
|
|
25
|
+
// Ensure the total tokens from memory don't exceed ~127k
|
|
26
|
+
new TokenLimiter(127000),
|
|
27
|
+
],
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The `TokenLimiter` uses the `o200k_base` encoding by default (suitable for GPT-4o). You can specify other encodings if needed for different models:
|
|
33
|
+
|
|
34
|
+
```typescript copy showLineNumbers {6-9}
|
|
35
|
+
// Import the encoding you need (e.g., for older OpenAI models)
|
|
36
|
+
import cl100k_base from "js-tiktoken/ranks/cl100k_base";
|
|
37
|
+
|
|
38
|
+
const memoryForOlderModel = new Memory({
|
|
39
|
+
processors: [
|
|
40
|
+
new TokenLimiter({
|
|
41
|
+
limit: 16000, // Example limit for a 16k context model
|
|
42
|
+
encoding: cl100k_base,
|
|
43
|
+
}),
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
See the [OpenAI cookbook](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken#encodings) or [`js-tiktoken` repo](https://github.com/dqbd/tiktoken) for more on encodings.
|
|
49
|
+
|
|
50
|
+
### `ToolCallFilter`
|
|
51
|
+
|
|
52
|
+
This processor removes tool calls from the memory messages sent to the LLM. It saves tokens by excluding potentially verbose tool interactions from the context, which is useful if the details aren't needed for future interactions. It's also useful if you always want your agent to call a specific tool again and not rely on previous tool results in memory.
|
|
53
|
+
|
|
54
|
+
```typescript copy showLineNumbers {5-14}
|
|
55
|
+
import { Memory } from "@mastra/memory";
|
|
56
|
+
import { ToolCallFilter, TokenLimiter } from "@mastra/memory/processors";
|
|
57
|
+
|
|
58
|
+
const memoryFilteringTools = new Memory({
|
|
59
|
+
processors: [
|
|
60
|
+
// Example 1: Remove all tool calls/results
|
|
61
|
+
new ToolCallFilter(),
|
|
62
|
+
|
|
63
|
+
// Example 2: Remove only noisy image generation tool calls/results
|
|
64
|
+
new ToolCallFilter({ exclude: ["generateImageTool"] }),
|
|
65
|
+
|
|
66
|
+
// Always place TokenLimiter last
|
|
67
|
+
new TokenLimiter(127000),
|
|
68
|
+
],
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Applying Multiple Processors
|
|
73
|
+
|
|
74
|
+
You can chain multiple processors. They execute in the order they appear in the `processors` array. The output of one processor becomes the input for the next.
|
|
75
|
+
|
|
76
|
+
**Order matters!** It's generally best practice to place `TokenLimiter` **last** in the chain. This ensures it operates on the final set of messages after other filtering has occurred, providing the most accurate token limit enforcement.
|
|
77
|
+
|
|
78
|
+
```typescript copy showLineNumbers {7-14}
|
|
79
|
+
import { Memory } from "@mastra/memory";
|
|
80
|
+
import { ToolCallFilter, TokenLimiter } from "@mastra/memory/processors";
|
|
81
|
+
// Assume a hypothetical 'PIIFilter' custom processor exists
|
|
82
|
+
// import { PIIFilter } from './custom-processors';
|
|
83
|
+
|
|
84
|
+
const memoryWithMultipleProcessors = new Memory({
|
|
85
|
+
processors: [
|
|
86
|
+
// 1. Filter specific tool calls first
|
|
87
|
+
new ToolCallFilter({ exclude: ["verboseDebugTool"] }),
|
|
88
|
+
// 2. Apply custom filtering (e.g., remove hypothetical PII - use with caution)
|
|
89
|
+
// new PIIFilter(),
|
|
90
|
+
// 3. Apply token limiting as the final step
|
|
91
|
+
new TokenLimiter(127000),
|
|
92
|
+
],
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Creating Custom Processors
|
|
97
|
+
|
|
98
|
+
You can create custom logic by extending the base `MemoryProcessor` class.
|
|
99
|
+
|
|
100
|
+
```typescript copy showLineNumbers {4-19,23-26}
|
|
101
|
+
import { Memory, CoreMessage } from "@mastra/memory";
|
|
102
|
+
import { MemoryProcessor, MemoryProcessorOpts } from "@mastra/core/memory";
|
|
103
|
+
|
|
104
|
+
class ConversationOnlyFilter extends MemoryProcessor {
|
|
105
|
+
constructor() {
|
|
106
|
+
// Provide a name for easier debugging if needed
|
|
107
|
+
super({ name: "ConversationOnlyFilter" });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
process(
|
|
111
|
+
messages: CoreMessage[],
|
|
112
|
+
_opts: MemoryProcessorOpts = {}, // Options passed during memory retrieval, rarely needed here
|
|
113
|
+
): CoreMessage[] {
|
|
114
|
+
// Filter messages based on role
|
|
115
|
+
return messages.filter(
|
|
116
|
+
(msg) => msg.role === "user" || msg.role === "assistant",
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Use the custom processor
|
|
122
|
+
const memoryWithCustomFilter = new Memory({
|
|
123
|
+
processors: [
|
|
124
|
+
new ConversationOnlyFilter(),
|
|
125
|
+
new TokenLimiter(127000), // Still apply token limiting
|
|
126
|
+
],
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
When creating custom processors avoid mutating the input `messages` array or its objects directly.
|
|
131
|
+
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
|
|
3
|
+
Memory is how agents manage the context that's available to them, it's a condensation of all chat messages into their context window.
|
|
4
|
+
|
|
5
|
+
## The Context Window
|
|
6
|
+
|
|
7
|
+
The context window is the total information visible to the language model at any given time.
|
|
8
|
+
|
|
9
|
+
In Mastra, context is broken up into three parts: system instructions and information about the user ([working memory](./working-memory.mdx)), recent messages ([message history](#conversation-history)), and older messages that are relevant to the user’s query ([semantic recall](./semantic-recall.mdx)).
|
|
10
|
+
|
|
11
|
+
In addition, we provide [memory processors](./memory-processors.mdx) to trim context or remove information if the context is too long.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
The fastest way to see memory in action is using the built-in development playground.
|
|
16
|
+
|
|
17
|
+
If you haven't already, create a new Mastra project following the main [Getting Started guide](/docs/getting-started/installation).
|
|
18
|
+
|
|
19
|
+
**1. Install the memory package:**
|
|
20
|
+
|
|
21
|
+
```bash npm2yarn copy
|
|
22
|
+
npm install @mastra/memory
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**2. Create an agent and attach a `Memory` instance:**
|
|
26
|
+
|
|
27
|
+
```typescript filename="src/mastra/agents/index.ts" {10}
|
|
28
|
+
import { Agent } from "@mastra/core/agent";
|
|
29
|
+
import { Memory } from "@mastra/memory";
|
|
30
|
+
import { openai } from "@ai-sdk/openai";
|
|
31
|
+
|
|
32
|
+
export const myMemoryAgent = new Agent({
|
|
33
|
+
name: "MemoryAgent",
|
|
34
|
+
instructions: "...",
|
|
35
|
+
model: openai("gpt-4o"),
|
|
36
|
+
|
|
37
|
+
memory: new Memory(),
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**3. Start the Development Server:**
|
|
42
|
+
|
|
43
|
+
```bash npm2yarn copy
|
|
44
|
+
npm run dev
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**4. Open the playground (http://localhost:4111) and select your `MemoryAgent`:**
|
|
48
|
+
|
|
49
|
+
Send a few messages and notice that it remembers information across turns:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
➡️ You: My favorite color is blue.
|
|
53
|
+
⬅️ Agent: Got it! I'll remember that your favorite color is blue.
|
|
54
|
+
➡️ You: What is my favorite color?
|
|
55
|
+
⬅️ Agent: Your favorite color is blue.
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Memory Threads
|
|
59
|
+
|
|
60
|
+
Mastra organizes memory into threads, which are records that identify specific conversation histories, using two identifiers:
|
|
61
|
+
|
|
62
|
+
1. **`threadId`**: A specific conversation id (e.g., `support_123`).
|
|
63
|
+
2. **`resourceId`**: The user or entity id that owns each thread (e.g., `user_123`, `org_456`).
|
|
64
|
+
|
|
65
|
+
```typescript {2,3}
|
|
66
|
+
const response = await myMemoryAgent.stream("Hello, my name is Alice.", {
|
|
67
|
+
resourceId: "user_alice",
|
|
68
|
+
threadId: "conversation_123",
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Important:** without these ID's your agent will not use memory, even if memory is properly configured. The playground handles this for you, but you need to add ID's yourself when using memory in your application.
|
|
73
|
+
|
|
74
|
+
## Conversation History
|
|
75
|
+
|
|
76
|
+
By default, the `Memory` instance includes the [last 40 messages](../reference/memory/Memory.mdx) from the current Memory thread in each new request. This provides the agent with immediate conversational context.
|
|
77
|
+
|
|
78
|
+
```ts {3}
|
|
79
|
+
const memory = new Memory({
|
|
80
|
+
options: {
|
|
81
|
+
lastMessages: 10,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Important:** Only send the newest user message in each agent call. Mastra handles retrieving and injecting the necessary history. Sending the full history yourself will cause duplication. See the [AI SDK Memory Example](../../examples/memory/use-chat.mdx) for how to handle this with when using the `useChat` frontend hooks.
|
|
87
|
+
|
|
88
|
+
### Storage Configuration
|
|
89
|
+
|
|
90
|
+
Conversation history relies on a [storage adapter](/docs/reference/memory/Memory#parameters) to store messages.
|
|
91
|
+
|
|
92
|
+
```ts {7-12}
|
|
93
|
+
import { Memory } from "@mastra/memory";
|
|
94
|
+
import { Agent } from "@mastra/core/agent";
|
|
95
|
+
import { LibSQLStore } from "@mastra/core/storage/libsql";
|
|
96
|
+
|
|
97
|
+
const agent = new Agent({
|
|
98
|
+
memory: new Memory({
|
|
99
|
+
// this is the default storage db if omitted
|
|
100
|
+
storage: new LibSQLStore({
|
|
101
|
+
config: {
|
|
102
|
+
url: "file:local.db",
|
|
103
|
+
},
|
|
104
|
+
}),
|
|
105
|
+
}),
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Storage code Examples**:
|
|
110
|
+
|
|
111
|
+
- [LibSQL](/examples/memory/memory-with-libsql)
|
|
112
|
+
- [Postgres](/examples/memory/memory-with-pg)
|
|
113
|
+
- [Upstash](/examples/memory/memory-with-upstash)
|
|
114
|
+
|
|
115
|
+
## Next Steps
|
|
116
|
+
|
|
117
|
+
Now that you understand the core concepts, continue to [semantic recall](./semantic-recall.mdx) to learn how to add RAG memory to your Mastra agents.
|
|
118
|
+
|
|
119
|
+
Alternatively you can visit the [configuration reference](../../reference/memory/Memory.mdx) for available options, or browse [usage examples](../../examples/memory/use-chat.mdx).
|