@mastra/mcp-docs-server 0.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcomposio.md +302 -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 +11 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -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%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%2Fstabilityai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +59 -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-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 +24 -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 +12 -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.md +385 -0
- package/.docs/organized/code-examples/ai-sdk-useChat.md +377 -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/integrations.md +184 -0
- package/.docs/organized/code-examples/mcp-configuration.md +341 -0
- package/.docs/organized/code-examples/memory-todo-agent.md +161 -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-pg.md +224 -0
- package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
- package/.docs/organized/code-examples/quick-start.md +127 -0
- package/.docs/organized/code-examples/stock-price-tool.md +124 -0
- package/.docs/organized/code-examples/weather-agent.md +352 -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/00-overview.mdx +185 -0
- package/.docs/raw/agents/01-agent-memory.mdx +610 -0
- package/.docs/raw/agents/02-adding-tools.mdx +224 -0
- package/.docs/raw/agents/03-adding-voice.mdx +170 -0
- package/.docs/raw/deployment/deployment.mdx +156 -0
- package/.docs/raw/deployment/logging-and-tracing.mdx +242 -0
- package/.docs/raw/deployment/server.mdx +114 -0
- package/.docs/raw/evals/00-overview.mdx +106 -0
- package/.docs/raw/evals/01-supported-evals.mdx +31 -0
- package/.docs/raw/evals/02-custom-eval.mdx +187 -0
- package/.docs/raw/faq/index.mdx +63 -0
- package/.docs/raw/frameworks/01-next-js.mdx +238 -0
- package/.docs/raw/frameworks/02-ai-sdk.mdx +218 -0
- package/.docs/raw/getting-started/installation.mdx +436 -0
- package/.docs/raw/getting-started/project-structure.mdx +80 -0
- package/.docs/raw/guides/01-chef-michel.mdx +242 -0
- package/.docs/raw/guides/02-stock-agent.mdx +182 -0
- package/.docs/raw/guides/03-recruiter.mdx +187 -0
- package/.docs/raw/index.mdx +22 -0
- package/.docs/raw/local-dev/creating-projects.mdx +74 -0
- package/.docs/raw/local-dev/integrations.mdx +127 -0
- package/.docs/raw/local-dev/mastra-dev.mdx +65 -0
- package/.docs/raw/rag/chunking-and-embedding.mdx +128 -0
- package/.docs/raw/rag/overview.mdx +85 -0
- package/.docs/raw/rag/retrieval.mdx +362 -0
- package/.docs/raw/rag/vector-databases.mdx +271 -0
- package/.docs/raw/reference/agents/createTool.mdx +190 -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 +361 -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 +97 -0
- package/.docs/raw/reference/cli/init.mdx +43 -0
- package/.docs/raw/reference/client-js/agents.mdx +90 -0
- package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
- package/.docs/raw/reference/client-js/index.mdx +127 -0
- package/.docs/raw/reference/client-js/logs.mdx +24 -0
- package/.docs/raw/reference/client-js/memory.mdx +94 -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 +137 -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 +186 -0
- package/.docs/raw/reference/memory/createThread.mdx +93 -0
- package/.docs/raw/reference/memory/getThreadById.mdx +43 -0
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +45 -0
- package/.docs/raw/reference/memory/query.mdx +164 -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/index.mdx +15 -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 +46 -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 +237 -0
- package/.docs/raw/reference/rag/document.mdx +129 -0
- package/.docs/raw/reference/rag/embeddings.mdx +160 -0
- package/.docs/raw/reference/rag/extract-params.mdx +72 -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 +249 -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 +198 -0
- package/.docs/raw/reference/rag/vectorize.mdx +253 -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 +180 -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/speechify.mdx +145 -0
- package/.docs/raw/reference/workflows/after.mdx +88 -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/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/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/suspend.mdx +80 -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/workflows/00-overview.mdx +168 -0
- package/.docs/raw/workflows/control-flow.mdx +712 -0
- package/.docs/raw/workflows/dynamic-workflows.mdx +232 -0
- package/.docs/raw/workflows/steps.mdx +98 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +196 -0
- package/.docs/raw/workflows/variables.mdx +248 -0
- package/LICENSE +44 -0
- package/README.md +129 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/dist/prepare-docs/code-examples.d.ts +4 -0
- package/dist/prepare-docs/code-examples.js +91 -0
- package/dist/prepare-docs/copy-raw.d.ts +1 -0
- package/dist/prepare-docs/copy-raw.js +41 -0
- package/dist/prepare-docs/index.d.ts +1 -0
- package/dist/prepare-docs/index.js +8 -0
- package/dist/prepare-docs/package-changes.d.ts +4 -0
- package/dist/prepare-docs/package-changes.js +92 -0
- package/dist/prepare-docs/prepare.d.ts +1 -0
- package/dist/prepare-docs/prepare.js +13 -0
- package/dist/sse.d.ts +1 -0
- package/dist/sse.js +9 -0
- package/dist/stdio.d.ts +1 -0
- package/dist/stdio.js +8 -0
- package/dist/tools/__tests__/blog.test.d.ts +1 -0
- package/dist/tools/__tests__/blog.test.js +48 -0
- package/dist/tools/__tests__/changes.test.d.ts +1 -0
- package/dist/tools/__tests__/changes.test.js +36 -0
- package/dist/tools/__tests__/docs.test.d.ts +1 -0
- package/dist/tools/__tests__/docs.test.js +46 -0
- package/dist/tools/__tests__/examples.test.d.ts +1 -0
- package/dist/tools/__tests__/examples.test.js +52 -0
- package/dist/tools/blog.d.ts +15 -0
- package/dist/tools/blog.js +73 -0
- package/dist/tools/changes.d.ts +11 -0
- package/dist/tools/changes.js +69 -0
- package/dist/tools/docs.d.ts +11 -0
- package/dist/tools/docs.js +176 -0
- package/dist/tools/examples.d.ts +11 -0
- package/dist/tools/examples.js +61 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +9 -0
- package/package.json +66 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
### package.json
|
|
2
|
+
```json
|
|
3
|
+
{
|
|
4
|
+
"name": "memory-todo-agent",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "",
|
|
7
|
+
"private": true,
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"chat": "bun run src/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@ai-sdk/openai": "latest",
|
|
17
|
+
"@mastra/core": "workspace:*",
|
|
18
|
+
"@mastra/memory": "workspace:*",
|
|
19
|
+
"ai": "latest",
|
|
20
|
+
"chalk": "^5.4.1",
|
|
21
|
+
"ora": "^8.2.0"
|
|
22
|
+
},
|
|
23
|
+
"version": "0.1.6-alpha.0"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### index.ts
|
|
29
|
+
```typescript
|
|
30
|
+
import { maskStreamTags } from '@mastra/core/utils';
|
|
31
|
+
import chalk from 'chalk';
|
|
32
|
+
import { randomUUID } from 'crypto';
|
|
33
|
+
import ora from 'ora';
|
|
34
|
+
import Readline from 'readline';
|
|
35
|
+
|
|
36
|
+
import 'dotenv/config';
|
|
37
|
+
|
|
38
|
+
import { mastra } from './mastra/index';
|
|
39
|
+
|
|
40
|
+
const agent = mastra.getAgent('todoAgent');
|
|
41
|
+
|
|
42
|
+
let threadId = ``;
|
|
43
|
+
threadId = randomUUID();
|
|
44
|
+
threadId = `d4e58927-ca27-46f9-8559-0c792e76e6f6`; // long thread
|
|
45
|
+
console.log(threadId);
|
|
46
|
+
|
|
47
|
+
const resourceId = 'SOME_USER_ID';
|
|
48
|
+
|
|
49
|
+
async function logRes(res: Awaited<ReturnType<typeof agent.stream>>) {
|
|
50
|
+
console.log(`\n👨🍳 Agent:`);
|
|
51
|
+
let message = '';
|
|
52
|
+
|
|
53
|
+
const memorySpinner = ora('saving memory');
|
|
54
|
+
|
|
55
|
+
const maskedStream = maskStreamTags(res.textStream, 'working_memory', {
|
|
56
|
+
onStart: () => memorySpinner.start(),
|
|
57
|
+
onEnd: () => {
|
|
58
|
+
if (memorySpinner.isSpinning) {
|
|
59
|
+
memorySpinner.succeed();
|
|
60
|
+
process.stdin.resume();
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
for await (const chunk of maskedStream) {
|
|
66
|
+
process.stdout.write(chunk);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return message;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function main() {
|
|
73
|
+
const isFirstChat = Boolean(await agent.getMemory()?.getThreadById({ threadId })) === false;
|
|
74
|
+
|
|
75
|
+
await logRes(
|
|
76
|
+
await agent.stream(
|
|
77
|
+
[
|
|
78
|
+
{
|
|
79
|
+
role: 'system',
|
|
80
|
+
content: !isFirstChat
|
|
81
|
+
? `Chat with user started now ${new Date().toISOString()}. Don't mention this message. This means some time has passed between this message and the one before. The user left and came back again. Say something to start the conversation up again.`
|
|
82
|
+
: `Chat with user started now ${new Date().toISOString()}.`,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
{
|
|
86
|
+
threadId,
|
|
87
|
+
resourceId,
|
|
88
|
+
},
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const rl = Readline.createInterface({
|
|
93
|
+
input: process.stdin,
|
|
94
|
+
output: process.stdout,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
while (true) {
|
|
98
|
+
const answer: string = await new Promise(res => {
|
|
99
|
+
rl.question(chalk.grey('\n> '), answer => {
|
|
100
|
+
setImmediate(() => res(answer));
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
await logRes(
|
|
105
|
+
await agent.stream(answer, {
|
|
106
|
+
threadId,
|
|
107
|
+
resourceId,
|
|
108
|
+
}),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
main();
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### mastra/agents/index.ts
|
|
118
|
+
```typescript
|
|
119
|
+
import { openai } from '@ai-sdk/openai';
|
|
120
|
+
import { Agent } from '@mastra/core/agent';
|
|
121
|
+
import { Memory } from '@mastra/memory';
|
|
122
|
+
|
|
123
|
+
const memory = new Memory({
|
|
124
|
+
options: {
|
|
125
|
+
lastMessages: 1,
|
|
126
|
+
semanticRecall: false,
|
|
127
|
+
workingMemory: {
|
|
128
|
+
enabled: true,
|
|
129
|
+
template: `
|
|
130
|
+
<todolist>
|
|
131
|
+
<info>this is an example list - replace it with whatever the user needs</info>
|
|
132
|
+
<item status="ACTIVE" due="Feb 7 3028" title="Example" started="Feb 7 2025">example</item>
|
|
133
|
+
</todolist>
|
|
134
|
+
`,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
export const todoAgent = new Agent({
|
|
140
|
+
name: 'TODO Agent',
|
|
141
|
+
instructions:
|
|
142
|
+
'You are a helpful todolist AI agent. Help the user manage their todolist. If there is no list yet ask them what to add! If there is a list always print it out when the chat starts. For each item add emojis, dates, titles (with an index number starting at 1), descriptions, and statuses. For each piece of info add an emoji to the left of it. Also support subtask lists with bullet points inside a box. Help the user timebox each task by asking them how long it will take. You MUST save the todolist in every response message by printing out <working_memory> blocks. If you do not save it in working_memory you will forget - you only have access to one previous message at any time. The user is expecting you to save your memory in every interaction. If the user expresses any preference on how the list should be displayed, save that info in working_memory so you know how to format it later.',
|
|
143
|
+
|
|
144
|
+
model: openai('gpt-4o-mini'),
|
|
145
|
+
memory,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### mastra/index.ts
|
|
151
|
+
```typescript
|
|
152
|
+
import { Mastra } from '@mastra/core/mastra';
|
|
153
|
+
|
|
154
|
+
import { todoAgent } from './agents';
|
|
155
|
+
|
|
156
|
+
export const mastra = new Mastra({
|
|
157
|
+
agents: { todoAgent },
|
|
158
|
+
logger: false,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
```
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
### package.json
|
|
2
|
+
```json
|
|
3
|
+
{
|
|
4
|
+
"name": "memory-with-context",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "",
|
|
7
|
+
"private": true,
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"chat": "bun run src/chat.ts"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@ai-sdk/openai": "^1.2.1",
|
|
17
|
+
"@mastra/core": "workspace:*",
|
|
18
|
+
"@mastra/memory": "workspace:*",
|
|
19
|
+
"chalk": "^5.4.1",
|
|
20
|
+
"ora": "^8.2.0"
|
|
21
|
+
},
|
|
22
|
+
"version": "0.0.1"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### chat.ts
|
|
28
|
+
```typescript
|
|
29
|
+
import { maskStreamTags } from '@mastra/core/utils';
|
|
30
|
+
import chalk from 'chalk';
|
|
31
|
+
import { randomUUID } from 'crypto';
|
|
32
|
+
import ora from 'ora';
|
|
33
|
+
import Readline from 'readline';
|
|
34
|
+
|
|
35
|
+
import 'dotenv/config';
|
|
36
|
+
|
|
37
|
+
import { mastra } from './mastra/index';
|
|
38
|
+
|
|
39
|
+
const agent = mastra.getAgent('memoryAgent');
|
|
40
|
+
|
|
41
|
+
let threadId = ``;
|
|
42
|
+
threadId = randomUUID();
|
|
43
|
+
// threadId = `0b3faadd-7e21-49ec-b613-e519448dab81`; // long thread
|
|
44
|
+
console.log(threadId);
|
|
45
|
+
|
|
46
|
+
const resourceId = 'SOME_USER_ID';
|
|
47
|
+
|
|
48
|
+
async function logRes(res: Awaited<ReturnType<typeof agent.stream>>) {
|
|
49
|
+
console.log(`\n👨🍳 Agent:`);
|
|
50
|
+
let message = '';
|
|
51
|
+
|
|
52
|
+
const thinkSpinner = ora('thinking');
|
|
53
|
+
|
|
54
|
+
const thinkMaskedStream = maskStreamTags(res.textStream, 'think', {
|
|
55
|
+
onStart: () => thinkSpinner.start(),
|
|
56
|
+
onEnd: () => {
|
|
57
|
+
if (thinkSpinner.isSpinning) {
|
|
58
|
+
thinkSpinner.succeed();
|
|
59
|
+
process.stdin.resume();
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const memorySpinner = ora('saving memory');
|
|
65
|
+
|
|
66
|
+
const maskedStream = maskStreamTags(thinkMaskedStream, 'working_memory', {
|
|
67
|
+
onStart: () => memorySpinner.start(),
|
|
68
|
+
onEnd: () => {
|
|
69
|
+
if (memorySpinner.isSpinning) {
|
|
70
|
+
memorySpinner.succeed();
|
|
71
|
+
process.stdin.resume();
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
for await (const chunk of maskedStream) {
|
|
77
|
+
process.stdout.write(chunk);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return message;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function main() {
|
|
84
|
+
const isFirstChat = Boolean(await agent.getMemory()?.getThreadById({ threadId })) === false;
|
|
85
|
+
|
|
86
|
+
await logRes(
|
|
87
|
+
await agent.stream(
|
|
88
|
+
[
|
|
89
|
+
{
|
|
90
|
+
role: 'system',
|
|
91
|
+
content: !isFirstChat
|
|
92
|
+
? `Chat with user started now ${new Date().toISOString()}. Don't mention this message. This means some time has passed between this message and the one before. The user left and came back again. Say something to start the conversation up again.`
|
|
93
|
+
: `Chat with user started now ${new Date().toISOString()}.`,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
{
|
|
97
|
+
threadId,
|
|
98
|
+
resourceId,
|
|
99
|
+
},
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const rl = Readline.createInterface({
|
|
104
|
+
input: process.stdin,
|
|
105
|
+
output: process.stdout,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
while (true) {
|
|
109
|
+
process.stdout.write(`\n`);
|
|
110
|
+
const answer: string = await new Promise(res => {
|
|
111
|
+
rl.question(chalk.grey('\n> '), answer => {
|
|
112
|
+
setImmediate(() => res(answer));
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
await logRes(
|
|
117
|
+
await agent.stream(answer, {
|
|
118
|
+
threadId,
|
|
119
|
+
resourceId,
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
main();
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### mastra/agents/index.ts
|
|
130
|
+
```typescript
|
|
131
|
+
import { openai } from '@ai-sdk/openai';
|
|
132
|
+
import { Agent } from '@mastra/core/agent';
|
|
133
|
+
import { Memory } from '@mastra/memory';
|
|
134
|
+
|
|
135
|
+
const memory = new Memory({
|
|
136
|
+
options: {
|
|
137
|
+
lastMessages: 4,
|
|
138
|
+
semanticRecall: {
|
|
139
|
+
topK: 1,
|
|
140
|
+
messageRange: 0,
|
|
141
|
+
},
|
|
142
|
+
workingMemory: {
|
|
143
|
+
enabled: true,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
export const memoryAgent = new Agent({
|
|
149
|
+
name: 'Memory Agent',
|
|
150
|
+
instructions: 'You are a helpful AI agent, looking to assist however you can.',
|
|
151
|
+
model: openai('gpt-4o-mini'),
|
|
152
|
+
memory,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### mastra/index.ts
|
|
158
|
+
```typescript
|
|
159
|
+
import { Mastra } from '@mastra/core';
|
|
160
|
+
|
|
161
|
+
import { memoryAgent } from './agents';
|
|
162
|
+
|
|
163
|
+
export const mastra = new Mastra({
|
|
164
|
+
agents: { memoryAgent },
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
```
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
### package.json
|
|
2
|
+
```json
|
|
3
|
+
{
|
|
4
|
+
"name": "memory-with-libsql",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "",
|
|
7
|
+
"private": true,
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "bun run --watch src/index.ts",
|
|
11
|
+
"chat": "bun run --watch src/chat.ts"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@ai-sdk/openai": "^1.2.1",
|
|
18
|
+
"@mastra/core": "workspace:*",
|
|
19
|
+
"@mastra/memory": "workspace:*"
|
|
20
|
+
},
|
|
21
|
+
"version": "0.0.1"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### chat.ts
|
|
27
|
+
```typescript
|
|
28
|
+
import { randomUUID } from 'crypto';
|
|
29
|
+
import Readline from 'readline';
|
|
30
|
+
|
|
31
|
+
import 'dotenv/config';
|
|
32
|
+
|
|
33
|
+
import { mastra } from './mastra';
|
|
34
|
+
|
|
35
|
+
const agent = mastra.getAgent('memoryAgent');
|
|
36
|
+
|
|
37
|
+
let threadId = randomUUID();
|
|
38
|
+
// use this to play with a long running conversation. comment it out to get a new thread id every time
|
|
39
|
+
threadId = `f45a59b3-d9da-4a2a-8348-9386e4e621a3`;
|
|
40
|
+
console.log(threadId);
|
|
41
|
+
|
|
42
|
+
const resourceId = 'SOME_USER_ID';
|
|
43
|
+
|
|
44
|
+
async function logRes(res: Awaited<ReturnType<typeof agent.stream>>) {
|
|
45
|
+
console.log(`\n🤖 Agent:`);
|
|
46
|
+
for await (const chunk of res.textStream) {
|
|
47
|
+
process.stdout.write(chunk);
|
|
48
|
+
}
|
|
49
|
+
console.log(`\n\n`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function main() {
|
|
53
|
+
await logRes(
|
|
54
|
+
await agent.stream(
|
|
55
|
+
[
|
|
56
|
+
{
|
|
57
|
+
role: 'system',
|
|
58
|
+
content: `Chat with user started now ${new Date().toISOString()}. Don't mention this message. This means some time may have passed between this message and the one before. The user left and came back again. Say something to start the conversation up again. If there are no other messages besides this one then this is a new conversation.`,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
{ resourceId, threadId },
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const rl = Readline.createInterface({
|
|
66
|
+
input: process.stdin,
|
|
67
|
+
output: process.stdout,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
while (true) {
|
|
71
|
+
const prompt: string = await new Promise(res => {
|
|
72
|
+
rl.question('Message: ', answer => {
|
|
73
|
+
res(answer);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
await logRes(
|
|
78
|
+
await agent.stream(prompt, {
|
|
79
|
+
threadId,
|
|
80
|
+
resourceId,
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
main();
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### index.ts
|
|
91
|
+
```typescript
|
|
92
|
+
import { randomUUID } from 'crypto';
|
|
93
|
+
|
|
94
|
+
import { mastra } from './mastra';
|
|
95
|
+
|
|
96
|
+
function log(message: string) {
|
|
97
|
+
console.log(`\n>>Prompt: ${message}
|
|
98
|
+
`);
|
|
99
|
+
return message;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const agent = mastra.getAgent('chefAgent');
|
|
103
|
+
const threadId = randomUUID();
|
|
104
|
+
const resourceId = 'SOME_USER_ID';
|
|
105
|
+
|
|
106
|
+
async function logRes(res: Awaited<ReturnType<typeof agent.stream>>) {
|
|
107
|
+
console.log(`\n👨🍳 Chef:`);
|
|
108
|
+
for await (const chunk of res.textStream) {
|
|
109
|
+
process.stdout.write(chunk);
|
|
110
|
+
}
|
|
111
|
+
console.log(`\n\n`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function main() {
|
|
115
|
+
await logRes(
|
|
116
|
+
await agent.stream(
|
|
117
|
+
log(
|
|
118
|
+
'In my kitchen I have: pasta, canned tomatoes, garlic, olive oil, and some dried herbs (basil and oregano). What can I make? Please keep your answer brief, only give me the high level steps.',
|
|
119
|
+
),
|
|
120
|
+
{
|
|
121
|
+
threadId,
|
|
122
|
+
resourceId,
|
|
123
|
+
},
|
|
124
|
+
),
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
await logRes(
|
|
128
|
+
await agent.stream(
|
|
129
|
+
log(
|
|
130
|
+
"Now I'm over at my friend's house, and they have: chicken thighs, coconut milk, sweet potatoes, and some curry powder.",
|
|
131
|
+
),
|
|
132
|
+
{
|
|
133
|
+
threadId,
|
|
134
|
+
resourceId,
|
|
135
|
+
},
|
|
136
|
+
),
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
await logRes(
|
|
140
|
+
await agent.stream(log('What did we cook before I went to my friends house?'), {
|
|
141
|
+
threadId,
|
|
142
|
+
resourceId,
|
|
143
|
+
memoryOptions: {
|
|
144
|
+
lastMessages: false,
|
|
145
|
+
semanticRecall: {
|
|
146
|
+
topK: 3,
|
|
147
|
+
messageRange: 3,
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
}),
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
process.exit(0);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
main();
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### mastra/agents/index.ts
|
|
161
|
+
```typescript
|
|
162
|
+
import { openai } from '@ai-sdk/openai';
|
|
163
|
+
import { Agent } from '@mastra/core/agent';
|
|
164
|
+
import { Memory } from '@mastra/memory';
|
|
165
|
+
|
|
166
|
+
const memory = new Memory({
|
|
167
|
+
options: {
|
|
168
|
+
lastMessages: 100,
|
|
169
|
+
semanticRecall: {
|
|
170
|
+
topK: 2,
|
|
171
|
+
messageRange: 2,
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
export const chefAgent = new Agent({
|
|
177
|
+
name: 'chefAgent',
|
|
178
|
+
instructions:
|
|
179
|
+
'You are Michel, a practical and experienced home chef who helps people cook great meals with whatever ingredients they have available. Your first priority is understanding what ingredients and equipment the user has access to, then suggesting achievable recipes. You explain cooking steps clearly and offer substitutions when needed, maintaining a friendly and encouraging tone throughout.',
|
|
180
|
+
model: openai('gpt-4o'),
|
|
181
|
+
memory,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
export const memoryAgent = new Agent({
|
|
185
|
+
name: 'Memory Agent',
|
|
186
|
+
instructions:
|
|
187
|
+
"You are an AI agent with the ability to automatically recall memories from previous interactions. You may have conversations that last hours, days, months, or years. If you don't know it already you should ask for the users name and some info about them.",
|
|
188
|
+
model: openai('gpt-4o'),
|
|
189
|
+
memory,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### mastra/index.ts
|
|
195
|
+
```typescript
|
|
196
|
+
import { Mastra } from '@mastra/core';
|
|
197
|
+
|
|
198
|
+
import { chefAgent, memoryAgent } from './agents';
|
|
199
|
+
|
|
200
|
+
export const mastra = new Mastra({
|
|
201
|
+
agents: { chefAgent, memoryAgent },
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
```
|