@mastra/mcp-docs-server 0.13.7-alpha.5 → 0.13.8-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +30 -30
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +60 -60
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +44 -44
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +34 -34
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +33 -33
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +72 -72
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +56 -56
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +52 -52
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +52 -52
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +73 -73
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +33 -33
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +36 -36
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +47 -47
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Flance.md +30 -0
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +50 -50
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +44 -44
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +43 -43
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +33 -33
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +51 -51
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +48 -48
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +32 -0
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +58 -58
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +58 -58
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Frag.md +46 -46
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +58 -58
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +49 -49
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +33 -33
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +33 -33
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +33 -33
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +43 -43
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +35 -35
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +31 -31
- package/.docs/organized/changelogs/create-mastra.md +10 -10
- package/.docs/organized/changelogs/mastra.md +70 -70
- package/.docs/raw/agents/streaming.mdx +118 -0
- package/.docs/raw/community/contributing-templates.mdx +1 -0
- package/.docs/raw/memory/overview.mdx +3 -1
- package/.docs/raw/memory/working-memory.mdx +67 -0
- package/.docs/raw/observability/logging.mdx +94 -19
- package/.docs/raw/reference/agents/streamVNext.mdx +598 -0
- package/.docs/raw/reference/observability/logger.mdx +69 -50
- package/.docs/raw/reference/observability/providers/langfuse.mdx +47 -14
- package/.docs/raw/reference/workflows/dountil.mdx +1 -2
- package/.docs/raw/reference/workflows/dowhile.mdx +1 -2
- package/.docs/raw/reference/workflows/resume.mdx +13 -3
- package/.docs/raw/reference/workflows/step.mdx +0 -1
- package/.docs/raw/reference/workflows/streamVNext.mdx +215 -0
- package/.docs/raw/workflows/streaming.mdx +115 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +13 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/logger.d.ts +11 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/prepare-docs/code-examples.d.ts +5 -0
- package/dist/prepare-docs/code-examples.d.ts.map +1 -0
- package/dist/prepare-docs/copy-raw.d.ts +2 -0
- package/dist/prepare-docs/copy-raw.d.ts.map +1 -0
- package/dist/prepare-docs/package-changes.d.ts +5 -0
- package/dist/prepare-docs/package-changes.d.ts.map +1 -0
- package/dist/prepare-docs/prepare.d.ts +2 -1
- package/dist/prepare-docs/prepare.d.ts.map +1 -0
- package/dist/stdio.d.ts +2 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/tools/__tests__/test-setup.d.ts +5 -0
- package/dist/tools/__tests__/test-setup.d.ts.map +1 -0
- package/dist/tools/blog.d.ts +22 -0
- package/dist/tools/blog.d.ts.map +1 -0
- package/dist/tools/changes.d.ts +22 -0
- package/dist/tools/changes.d.ts.map +1 -0
- package/dist/tools/course.d.ts +85 -0
- package/dist/tools/course.d.ts.map +1 -0
- package/dist/tools/docs.d.ts +28 -0
- package/dist/tools/docs.d.ts.map +1 -0
- package/dist/tools/examples.d.ts +28 -0
- package/dist/tools/examples.d.ts.map +1 -0
- package/dist/utils.d.ts +62 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +6 -6
- package/dist/_tsup-dts-rollup.d.ts +0 -304
|
@@ -1,5 +1,74 @@
|
|
|
1
1
|
# mastra
|
|
2
2
|
|
|
3
|
+
## 0.10.17-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 33dcb07: dependencies updates:
|
|
8
|
+
- Updated dependency [`@opentelemetry/instrumentation@^0.203.0` ↗︎](https://www.npmjs.com/package/@opentelemetry/instrumentation/v/0.203.0) (from `^0.202.0`, in `dependencies`)
|
|
9
|
+
- Updated dependency [`@opentelemetry/auto-instrumentations-node@^0.62.0` ↗︎](https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node/v/0.62.0) (from `^0.60.1`, in `dependencies`)
|
|
10
|
+
- Updated dependency [`@opentelemetry/exporter-trace-otlp-grpc@^0.203.0` ↗︎](https://www.npmjs.com/package/@opentelemetry/exporter-trace-otlp-grpc/v/0.203.0) (from `^0.202.0`, in `dependencies`)
|
|
11
|
+
- Updated dependency [`@opentelemetry/exporter-trace-otlp-http@^0.203.0` ↗︎](https://www.npmjs.com/package/@opentelemetry/exporter-trace-otlp-http/v/0.203.0) (from `^0.202.0`, in `dependencies`)
|
|
12
|
+
- Updated dependency [`@opentelemetry/sdk-node@^0.203.0` ↗︎](https://www.npmjs.com/package/@opentelemetry/sdk-node/v/0.203.0) (from `^0.202.0`, in `dependencies`)
|
|
13
|
+
- Updated dependency [`@opentelemetry/semantic-conventions@^1.36.0` ↗︎](https://www.npmjs.com/package/@opentelemetry/semantic-conventions/v/1.36.0) (from `^1.34.0`, in `dependencies`)
|
|
14
|
+
- Updated dependencies [33dcb07]
|
|
15
|
+
- Updated dependencies [f90797b]
|
|
16
|
+
- Updated dependencies [d30b1a0]
|
|
17
|
+
- Updated dependencies [bff87f7]
|
|
18
|
+
- Updated dependencies [07fe7a2]
|
|
19
|
+
- Updated dependencies [b4a8df0]
|
|
20
|
+
- @mastra/core@0.12.1-alpha.0
|
|
21
|
+
- @mastra/mcp@0.10.9-alpha.0
|
|
22
|
+
- @mastra/deployer@0.12.1-alpha.0
|
|
23
|
+
|
|
24
|
+
## 0.10.16
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- bc6b44a: Extract tools import from `createHonoServer`; the function now receives tools via a prop on the `options` parameter.
|
|
29
|
+
- f442224: speech to text using voice config
|
|
30
|
+
- 7a7754f: Fast follow scorers fixing input types, improve llm scorer reliability, fix ui to display scores that are 0
|
|
31
|
+
- d8dec5e: add a cta to invite to deploy to cloud
|
|
32
|
+
- 6336993: Fix workflow input form overflow
|
|
33
|
+
- d5cc460: This change implements a fix to sourcemap mappings being off due to `removeDeployer` Babel plugin missing source map config.
|
|
34
|
+
- f42c4c2: update peer deps for packages to latest core range
|
|
35
|
+
- a5681f2: fix: pagination breaks trace grouping
|
|
36
|
+
- 89d2f4e: add TTS to the playground
|
|
37
|
+
- Updated dependencies [510e2c8]
|
|
38
|
+
- Updated dependencies [2f72fb2]
|
|
39
|
+
- Updated dependencies [27cc97a]
|
|
40
|
+
- Updated dependencies [832691b]
|
|
41
|
+
- Updated dependencies [557bb9d]
|
|
42
|
+
- Updated dependencies [27cc97a]
|
|
43
|
+
- Updated dependencies [3f89307]
|
|
44
|
+
- Updated dependencies [9eda7d4]
|
|
45
|
+
- Updated dependencies [9d49408]
|
|
46
|
+
- Updated dependencies [bc6b44a]
|
|
47
|
+
- Updated dependencies [41daa63]
|
|
48
|
+
- Updated dependencies [ad0a58b]
|
|
49
|
+
- Updated dependencies [254a36b]
|
|
50
|
+
- Updated dependencies [2ecf658]
|
|
51
|
+
- Updated dependencies [7a7754f]
|
|
52
|
+
- Updated dependencies [fc92d80]
|
|
53
|
+
- Updated dependencies [e0f73c6]
|
|
54
|
+
- Updated dependencies [0b89602]
|
|
55
|
+
- Updated dependencies [4d37822]
|
|
56
|
+
- Updated dependencies [23a6a7c]
|
|
57
|
+
- Updated dependencies [cda801d]
|
|
58
|
+
- Updated dependencies [a77c823]
|
|
59
|
+
- Updated dependencies [ff9c125]
|
|
60
|
+
- Updated dependencies [09bca64]
|
|
61
|
+
- Updated dependencies [9802f42]
|
|
62
|
+
- Updated dependencies [d5cc460]
|
|
63
|
+
- Updated dependencies [f42c4c2]
|
|
64
|
+
- Updated dependencies [b8efbb9]
|
|
65
|
+
- Updated dependencies [71466e7]
|
|
66
|
+
- Updated dependencies [0c99fbe]
|
|
67
|
+
- @mastra/core@0.12.0
|
|
68
|
+
- @mastra/deployer@0.12.0
|
|
69
|
+
- @mastra/loggers@0.10.5
|
|
70
|
+
- @mastra/mcp@0.10.8
|
|
71
|
+
|
|
3
72
|
## 0.10.16-alpha.3
|
|
4
73
|
|
|
5
74
|
### Patch Changes
|
|
@@ -229,74 +298,5 @@
|
|
|
229
298
|
- f9b1508: add the same agent table as in cloud and export it from the playground
|
|
230
299
|
- dfbeec6: Fix navigation to vnext AgentNetwork agents
|
|
231
300
|
- Updated dependencies [7776324]
|
|
232
|
-
- Updated dependencies [0b56518]
|
|
233
|
-
- Updated dependencies [db5cc15]
|
|
234
|
-
- Updated dependencies [2ba5b76]
|
|
235
|
-
- Updated dependencies [7b57e2c]
|
|
236
|
-
- Updated dependencies [5237998]
|
|
237
|
-
- Updated dependencies [c3a30de]
|
|
238
|
-
- Updated dependencies [37c1acd]
|
|
239
|
-
- Updated dependencies [1aa60b1]
|
|
240
|
-
- Updated dependencies [89ec9d4]
|
|
241
|
-
- Updated dependencies [cf3a184]
|
|
242
|
-
- Updated dependencies [fe4bbd4]
|
|
243
|
-
- Updated dependencies [d6bfd60]
|
|
244
|
-
- Updated dependencies [626b0f4]
|
|
245
|
-
- Updated dependencies [c22a91f]
|
|
246
|
-
- Updated dependencies [f7403ab]
|
|
247
|
-
- Updated dependencies [6c89d7f]
|
|
248
|
-
- @mastra/deployer@0.10.15
|
|
249
|
-
- @mastra/core@0.10.15
|
|
250
|
-
|
|
251
|
-
## 0.10.13-alpha.2
|
|
252
|
-
|
|
253
|
-
### Patch Changes
|
|
254
|
-
|
|
255
|
-
- 794d9f3: Fix thread creation in playground
|
|
256
|
-
- dfbeec6: Fix navigation to vnext AgentNetwork agents
|
|
257
|
-
|
|
258
|
-
## 0.10.13-alpha.1
|
|
259
|
-
|
|
260
|
-
### Patch Changes
|
|
261
|
-
|
|
262
|
-
- d49334d: export tool list for usage in cloud
|
|
263
|
-
- 9cdfcb5: fix infinite rerenders on agents table + share runtime context for cloud
|
|
264
|
-
- 45174f3: share network list between core and cloud
|
|
265
|
-
- 48f5532: export workflow list for usage in cloud
|
|
266
|
-
- 3e484be: Added CLI template option
|
|
267
|
-
- Updated dependencies [0b56518]
|
|
268
|
-
- Updated dependencies [2ba5b76]
|
|
269
|
-
- Updated dependencies [c3a30de]
|
|
270
|
-
- Updated dependencies [cf3a184]
|
|
271
|
-
- Updated dependencies [fe4bbd4]
|
|
272
|
-
- Updated dependencies [d6bfd60]
|
|
273
|
-
- @mastra/core@0.10.15-alpha.1
|
|
274
|
-
- @mastra/deployer@0.10.15-alpha.1
|
|
275
301
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
### Patch Changes
|
|
279
|
-
|
|
280
|
-
- 593631d: allow to pass ref to the link abstraction
|
|
281
|
-
- 5237998: Fix foreach output
|
|
282
|
-
- 1aa60b1: Pipe runtimeContext to vNext network agent stream and generate steps, wire up runtimeContext for vNext Networks in cliet SDK & playground
|
|
283
|
-
- 5130bcb: dependencies updates:
|
|
284
|
-
- Updated dependency [`swr@^2.3.4` ↗︎](https://www.npmjs.com/package/swr/v/2.3.4) (from `^2.3.3`, in `dependencies`)
|
|
285
|
-
- 984887a: dependencies updates:
|
|
286
|
-
- Updated dependency [`prettier@^3.6.2` ↗︎](https://www.npmjs.com/package/prettier/v/3.6.2) (from `^3.5.3`, in `dependencies`)
|
|
287
|
-
- aa9528a: Display reasoning in playground
|
|
288
|
-
- 626b0f4: [Cloud-126] Working Memory Playground - Added working memory to playground to allow users to view/edit working memory
|
|
289
|
-
- e1d0080: abstract Link component between cloud and core
|
|
290
|
-
- f9b1508: add the same agent table as in cloud and export it from the playground
|
|
291
|
-
- Updated dependencies [7776324]
|
|
292
|
-
- Updated dependencies [db5cc15]
|
|
293
|
-
- Updated dependencies [7b57e2c]
|
|
294
|
-
- Updated dependencies [5237998]
|
|
295
|
-
- Updated dependencies [37c1acd]
|
|
296
|
-
- Updated dependencies [1aa60b1]
|
|
297
|
-
- Updated dependencies [89ec9d4]
|
|
298
|
-
- Updated dependencies [626b0f4]
|
|
299
|
-
- Updated dependencies [c22a91f]
|
|
300
|
-
- Updated dependencies [f7403ab]
|
|
301
|
-
|
|
302
|
-
... 4605 more lines hidden. See full changelog in package directory.
|
|
302
|
+
... 4674 more lines hidden. See full changelog in package directory.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Using Agent Streaming | Agents | Mastra Docs"
|
|
3
|
+
description: Documentation on how to stream agents
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Agent Streaming
|
|
7
|
+
|
|
8
|
+
Agents in Mastra have access to a powerful streaming protocol! With seamless integration into tools or agents as a tool, you can stream responses directly back to your clients, creating a more interactive and engaging experience.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
To use the new protocol, you can use the `streamVNext` method on an agent. This method will return a custom MastraAgentStream. This stream extends a ReadableStream, so all basic stream methods are available.
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
const stream = await agent.streamVNext({ role: "user", content: "Tell me a story." });
|
|
16
|
+
|
|
17
|
+
for await (const chunk of stream) {
|
|
18
|
+
console.log(chunk);
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Each chunk is a JSON object with the following properties:
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
type: string;
|
|
27
|
+
runId: string;
|
|
28
|
+
from: string;
|
|
29
|
+
payload: Record<string, any>;
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
We have a couple of utility functions on the stream to help you with the streaming process.
|
|
34
|
+
|
|
35
|
+
- `stream.finishReason` - The reason the agent stopped streaming.
|
|
36
|
+
- `stream.toolCalls` - The tool calls made by the agent.
|
|
37
|
+
- `stream.toolResults` - The tool results returned by the agent.
|
|
38
|
+
- `stream.usage` - The total token usage of the agent, including agents/workflows as a tool.
|
|
39
|
+
- `stream.text` - The full text of the agent's response.
|
|
40
|
+
- `stream.object` - The object of the agent's response, if you use output or experimental output.
|
|
41
|
+
- `stream.textStream` - A readable stream that will emit the text of the agent's response.
|
|
42
|
+
|
|
43
|
+
### How to use the stream in a tool
|
|
44
|
+
|
|
45
|
+
Each tool gets a `writer` argument, which is a writable stream with a custom write function. This write function is used to write the tool's response to the stream.
|
|
46
|
+
|
|
47
|
+
```typescript filename="src/mastra/tools/test-tool.ts" showLineNumbers copy
|
|
48
|
+
import { createTool } from "@mastra/core/tools";
|
|
49
|
+
import { z } from "zod";
|
|
50
|
+
|
|
51
|
+
export const weatherInfo = createTool({
|
|
52
|
+
id: "Get Weather Information",
|
|
53
|
+
inputSchema: z.object({
|
|
54
|
+
city: z.string(),
|
|
55
|
+
}),
|
|
56
|
+
outputSchema: z.object({
|
|
57
|
+
conditions: z.string(),
|
|
58
|
+
temperature: z.number(),
|
|
59
|
+
}),
|
|
60
|
+
description: `Fetches the current weather information for a given city`,
|
|
61
|
+
execute: async ({ context: { city }, writer }) => {
|
|
62
|
+
writer.write({
|
|
63
|
+
type: "weather-data",
|
|
64
|
+
args: {
|
|
65
|
+
city
|
|
66
|
+
},
|
|
67
|
+
status: "pending"
|
|
68
|
+
})
|
|
69
|
+
// Tool logic here (e.g., API call)
|
|
70
|
+
console.log("Using tool to fetch weather information for", city);
|
|
71
|
+
|
|
72
|
+
writer.write({
|
|
73
|
+
type: "weather-data",
|
|
74
|
+
args: {
|
|
75
|
+
city
|
|
76
|
+
},
|
|
77
|
+
status: "success",
|
|
78
|
+
result: {
|
|
79
|
+
temperature: 20,
|
|
80
|
+
conditions: "Sunny"
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
return { temperature: 20, conditions: "Sunny" }; // Example return
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
If you want to use the stream in an agent, you can use the `streamVNext` method on the agent and pipe it to the agent's input stream.
|
|
90
|
+
|
|
91
|
+
```typescript filename="src/mastra/tools/test-tool.ts" showLineNumbers copy
|
|
92
|
+
import { createTool } from "@mastra/core/tools";
|
|
93
|
+
import { z } from "zod";
|
|
94
|
+
|
|
95
|
+
export const weatherInfo = createTool({
|
|
96
|
+
id: "Get Weather Information",
|
|
97
|
+
description: `Fetches the current weather information for a given city`,
|
|
98
|
+
inputSchema: z.object({
|
|
99
|
+
city: z.string(),
|
|
100
|
+
}),
|
|
101
|
+
outputSchema: z.object({
|
|
102
|
+
text: z.string(),
|
|
103
|
+
}),
|
|
104
|
+
execute: async ({ context: { city }, writer, mastra }) => {
|
|
105
|
+
const agent = mastra.getAgent('weatherAgent')
|
|
106
|
+
const stream = await agent.streamVNext(`What is the weather in ${city}?`);
|
|
107
|
+
|
|
108
|
+
await stream.pipeTo(writer);
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
text: await stream.text,
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Piping the stream to the agent's input stream will allow us to automatically sum up the usage of the agent so the total usage count can be calculated.
|
|
118
|
+
|
|
@@ -27,6 +27,7 @@ Create your template following the established patterns:
|
|
|
27
27
|
- Include comprehensive documentation
|
|
28
28
|
- Test thoroughly with fresh installations
|
|
29
29
|
- Follow all technical requirements
|
|
30
|
+
- Ensure the github repo is a template repo. [How to create a template repo](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-template-repository)
|
|
30
31
|
|
|
31
32
|
### 3. Submit for Review
|
|
32
33
|
|
|
@@ -68,7 +68,7 @@ Send a few messages and notice that it remembers information across turns:
|
|
|
68
68
|
|
|
69
69
|
Mastra organizes memory into threads, which are records that identify specific conversation histories, using two identifiers:
|
|
70
70
|
|
|
71
|
-
1. **`threadId`**: A
|
|
71
|
+
1. **`threadId`**: A globally unique conversation id (e.g., `support_123`). Thread IDs must be unique across all resources.
|
|
72
72
|
2. **`resourceId`**: The user or entity id that owns each thread (e.g., `user_123`, `org_456`).
|
|
73
73
|
|
|
74
74
|
The `resourceId` is particularly important for [resource-scoped working memory](./working-memory.mdx#resource-scoped-memory), which allows memory to persist across all conversation threads for the same user.
|
|
@@ -82,6 +82,8 @@ const response = await myMemoryAgent.stream("Hello, my name is Alice.", {
|
|
|
82
82
|
|
|
83
83
|
**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.
|
|
84
84
|
|
|
85
|
+
> **Thread ID Uniqueness:** Each thread ID must be globally unique across all resources. A thread is permanently associated with the resource that created it. If you need to have similar thread names for different resources (e.g., a "general" thread for multiple users), include the resource ID in the thread ID: `${resourceId}-general` or `user_alice_general`.
|
|
86
|
+
|
|
85
87
|
### Thread Title Generation
|
|
86
88
|
|
|
87
89
|
Mastra can automatically generate meaningful titles for conversation threads based on the user's first message. This helps organize and identify conversations in your application UI.
|
|
@@ -298,6 +298,73 @@ again because it has been stored in working memory.
|
|
|
298
298
|
If your agent is not properly updating working memory when you expect it to, you can add system
|
|
299
299
|
instructions on _how_ and _when_ to use this template in your agent's `instructions` setting.
|
|
300
300
|
|
|
301
|
+
## Setting Initial Working Memory
|
|
302
|
+
|
|
303
|
+
While agents typically update working memory through the `updateWorkingMemory` tool, you can also set initial working memory programmatically when creating or updating threads. This is useful for injecting user data (like their name, preferences, or other info) that you want available to the agent without passing it in every request.
|
|
304
|
+
|
|
305
|
+
### Setting Working Memory via Thread Metadata
|
|
306
|
+
|
|
307
|
+
When creating a thread, you can provide initial working memory through the metadata's `workingMemory` key:
|
|
308
|
+
|
|
309
|
+
```typescript filename="src/app/medical-consultation.ts" showLineNumbers copy
|
|
310
|
+
// Create a thread with initial working memory
|
|
311
|
+
const thread = await memory.createThread({
|
|
312
|
+
threadId: "thread-123",
|
|
313
|
+
resourceId: "user-456",
|
|
314
|
+
title: "Medical Consultation",
|
|
315
|
+
metadata: {
|
|
316
|
+
workingMemory: `# Patient Profile
|
|
317
|
+
- Name: John Doe
|
|
318
|
+
- Blood Type: O+
|
|
319
|
+
- Allergies: Penicillin
|
|
320
|
+
- Current Medications: None
|
|
321
|
+
- Medical History: Hypertension (controlled)
|
|
322
|
+
`
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// The agent will now have access to this information in all messages
|
|
327
|
+
await agent.generate("What's my blood type?", {
|
|
328
|
+
threadId: thread.id,
|
|
329
|
+
resourceId: "user-456"
|
|
330
|
+
});
|
|
331
|
+
// Response: "Your blood type is O+."
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Updating Working Memory Programmatically
|
|
335
|
+
|
|
336
|
+
You can also update an existing thread's working memory:
|
|
337
|
+
|
|
338
|
+
```typescript filename="src/app/medical-consultation.ts" showLineNumbers copy
|
|
339
|
+
// Update thread metadata to add/modify working memory
|
|
340
|
+
await memory.updateThread({
|
|
341
|
+
id: "thread-123",
|
|
342
|
+
title: thread.title,
|
|
343
|
+
metadata: {
|
|
344
|
+
...thread.metadata,
|
|
345
|
+
workingMemory: `# Patient Profile
|
|
346
|
+
- Name: John Doe
|
|
347
|
+
- Blood Type: O+
|
|
348
|
+
- Allergies: Penicillin, Ibuprofen // Updated
|
|
349
|
+
- Current Medications: Lisinopril 10mg daily // Added
|
|
350
|
+
- Medical History: Hypertension (controlled)
|
|
351
|
+
`
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### Direct Memory Update
|
|
357
|
+
|
|
358
|
+
Alternatively, use the `updateWorkingMemory` method directly:
|
|
359
|
+
|
|
360
|
+
```typescript filename="src/app/medical-consultation.ts" showLineNumbers copy
|
|
361
|
+
await memory.updateWorkingMemory({
|
|
362
|
+
threadId: "thread-123",
|
|
363
|
+
resourceId: "user-456", // Required for resource-scoped memory
|
|
364
|
+
workingMemory: "Updated memory content..."
|
|
365
|
+
});
|
|
366
|
+
```
|
|
367
|
+
|
|
301
368
|
## Examples
|
|
302
369
|
|
|
303
370
|
- [Streaming working memory](/examples/memory/streaming-working-memory)
|
|
@@ -1,38 +1,113 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Logging | Mastra Observability Documentation"
|
|
3
|
-
description:
|
|
3
|
+
description: Learn how to use logging in Mastra to monitor execution, capture application behavior, and improve the accuracy of AI applications.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
import Image from "next/image";
|
|
7
|
-
|
|
8
6
|
# Logging
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
Mastra's logging system captures function execution, input data, and output responses in a structured format.
|
|
9
|
+
|
|
10
|
+
When deploying to Mastra Cloud, logs are shown on the [Logs](../mastra-cloud/observability.mdx) page. In self-hosted or custom environments, logs can be directed to files or external services depending on the configured transports.
|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## PinoLogger
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
When [initializing a new Mastra project](../getting-started/installation.mdx) using the CLI, `PinoLogger` is included by default.
|
|
15
15
|
|
|
16
|
-
```typescript filename="mastra.
|
|
17
|
-
import { Mastra } from
|
|
18
|
-
import { PinoLogger } from
|
|
16
|
+
```typescript filename="src/mastra/index.ts" showLineNumbers copy
|
|
17
|
+
import { Mastra } from '@mastra/core/mastra';
|
|
18
|
+
import { PinoLogger } from '@mastra/loggers';
|
|
19
19
|
|
|
20
20
|
export const mastra = new Mastra({
|
|
21
|
-
//
|
|
21
|
+
// ...
|
|
22
22
|
logger: new PinoLogger({
|
|
23
|
-
name:
|
|
24
|
-
level:
|
|
23
|
+
name: 'Mastra',
|
|
24
|
+
level: 'info',
|
|
25
25
|
}),
|
|
26
26
|
});
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
> See the [PinoLogger](../../reference/observability/logger.mdx) API reference for all available configuration options.
|
|
30
|
+
|
|
31
|
+
## Logging from workflows and tools
|
|
32
|
+
|
|
33
|
+
Mastra provides access to a logger instance via the `mastra.getLogger()` method, available inside both workflow steps and tools. The logger supports standard severity levels: `debug`, `info`, `warn`, and `error`.
|
|
34
|
+
|
|
35
|
+
### Logging from workflow steps
|
|
36
|
+
|
|
37
|
+
Within a workflow step, access the logger via the `mastra` parameter inside the `execute` function. This allows you to log messages relevant to the step’s execution.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
```typescript {8-9} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
41
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
42
|
+
import { z } from "zod";
|
|
43
|
+
|
|
44
|
+
const step1 = createStep({
|
|
45
|
+
//...
|
|
46
|
+
execute: async ({ mastra }) => {
|
|
47
|
+
|
|
48
|
+
const logger = mastra.getLogger();
|
|
49
|
+
logger.info("workflow info log");
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
output: ""
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export const testWorkflow = createWorkflow({...})
|
|
58
|
+
.then(step1)
|
|
59
|
+
.commit();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Logging from tools
|
|
63
|
+
|
|
64
|
+
Similarly, tools have access to the logger instance via the `mastra` parameter. Use this to log tool specific activity during execution.
|
|
30
65
|
|
|
31
|
-
-
|
|
32
|
-
|
|
66
|
+
```typescript {8-9} filename="src/mastra/tools/test-tool.ts" showLineNumbers copy
|
|
67
|
+
import { createTool } from "@mastra/core/tools";
|
|
68
|
+
import { z } from "zod";
|
|
33
69
|
|
|
34
|
-
|
|
70
|
+
export const testTool = createTool({
|
|
71
|
+
// ...
|
|
72
|
+
execute: async ({ mastra }) => {
|
|
35
73
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
74
|
+
const logger = mastra?.getLogger();
|
|
75
|
+
logger?.info("tool info log");
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
output: ""
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
## Logging with additional data
|
|
86
|
+
|
|
87
|
+
Logger methods accept an optional second argument for additional data. This can be any value, such as an object, string, or number.
|
|
88
|
+
|
|
89
|
+
In this example, the log message includes an object with a key of `agent` and a value of the `testAgent` instance.
|
|
90
|
+
|
|
91
|
+
```typescript {11} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
92
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
93
|
+
import { z } from "zod";
|
|
94
|
+
|
|
95
|
+
const step1 = createStep({
|
|
96
|
+
//...
|
|
97
|
+
execute: async ({ mastra }) => {
|
|
98
|
+
|
|
99
|
+
const testAgent = mastra.getAgent("testAgent");
|
|
100
|
+
|
|
101
|
+
const logger = mastra.getLogger();
|
|
102
|
+
logger.info("workflow info log", { agent: testAgent });
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
output: ""
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
export const testWorkflow = createWorkflow({...})
|
|
111
|
+
.then(step1)
|
|
112
|
+
.commit();
|
|
113
|
+
```
|