@mastra/libsql 0.0.0-error-handler-fix-20251020202607 → 0.0.0-esbuild-bundle-worker-20260807182016

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.
Files changed (104) hide show
  1. package/CHANGELOG.md +4789 -3
  2. package/LICENSE.md +15 -0
  3. package/README.md +30 -20
  4. package/dist/docs/SKILL.md +52 -0
  5. package/dist/docs/assets/SOURCE_MAP.json +6 -0
  6. package/dist/docs/references/docs-agents-agent-approval.md +664 -0
  7. package/dist/docs/references/docs-agents-networks.md +184 -0
  8. package/dist/docs/references/docs-deployment-workers.md +137 -0
  9. package/dist/docs/references/docs-editor-overview.md +349 -0
  10. package/dist/docs/references/docs-memory-memory-processors.md +385 -0
  11. package/dist/docs/references/docs-memory-message-history.md +348 -0
  12. package/dist/docs/references/docs-memory-multi-user-threads.md +208 -0
  13. package/dist/docs/references/docs-memory-overview.md +266 -0
  14. package/dist/docs/references/docs-memory-semantic-recall.md +401 -0
  15. package/dist/docs/references/docs-memory-working-memory.md +431 -0
  16. package/dist/docs/references/docs-storage-overview.md +214 -0
  17. package/dist/docs/references/docs-workflows-snapshots.md +240 -0
  18. package/dist/docs/references/guides-agent-frameworks-ai-sdk.md +142 -0
  19. package/dist/docs/references/guides-rag-retrieval.md +520 -0
  20. package/dist/docs/references/reference-core-getMemory.md +51 -0
  21. package/dist/docs/references/reference-core-listMemory.md +57 -0
  22. package/dist/docs/references/reference-core-mastra-class.md +153 -0
  23. package/dist/docs/references/reference-file-based-agents-memory.md +58 -0
  24. package/dist/docs/references/reference-file-based-agents-storage.md +30 -0
  25. package/dist/docs/references/reference-memory-memory-class.md +148 -0
  26. package/dist/docs/references/reference-storage-composite.md +397 -0
  27. package/dist/docs/references/reference-storage-dynamodb.md +284 -0
  28. package/dist/docs/references/reference-storage-libsql.md +143 -0
  29. package/dist/docs/references/reference-storage-retention.md +248 -0
  30. package/dist/docs/references/reference-vectors-libsql.md +307 -0
  31. package/dist/index.cjs +13164 -3390
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.js +13134 -3383
  34. package/dist/index.js.map +1 -1
  35. package/dist/storage/db/index.d.ts +389 -0
  36. package/dist/storage/db/index.d.ts.map +1 -0
  37. package/dist/storage/db/utils.d.ts +84 -0
  38. package/dist/storage/db/utils.d.ts.map +1 -0
  39. package/dist/storage/db/write-lock.d.ts +8 -0
  40. package/dist/storage/db/write-lock.d.ts.map +1 -0
  41. package/dist/storage/domains/agents/index.d.ts +30 -0
  42. package/dist/storage/domains/agents/index.d.ts.map +1 -0
  43. package/dist/storage/domains/background-tasks/index.d.ts +27 -0
  44. package/dist/storage/domains/background-tasks/index.d.ts.map +1 -0
  45. package/dist/storage/domains/blobs/index.d.ts +17 -0
  46. package/dist/storage/domains/blobs/index.d.ts.map +1 -0
  47. package/dist/storage/domains/channels/index.d.ts +20 -0
  48. package/dist/storage/domains/channels/index.d.ts.map +1 -0
  49. package/dist/storage/domains/datasets/index.d.ts +43 -0
  50. package/dist/storage/domains/datasets/index.d.ts.map +1 -0
  51. package/dist/storage/domains/experiments/index.d.ts +54 -0
  52. package/dist/storage/domains/experiments/index.d.ts.map +1 -0
  53. package/dist/storage/domains/favorites/index.d.ts +17 -0
  54. package/dist/storage/domains/favorites/index.d.ts.map +1 -0
  55. package/dist/storage/domains/harness/index.d.ts +17 -0
  56. package/dist/storage/domains/harness/index.d.ts.map +1 -0
  57. package/dist/storage/domains/mcp-clients/index.d.ts +26 -0
  58. package/dist/storage/domains/mcp-clients/index.d.ts.map +1 -0
  59. package/dist/storage/domains/mcp-servers/index.d.ts +26 -0
  60. package/dist/storage/domains/mcp-servers/index.d.ts.map +1 -0
  61. package/dist/storage/domains/memory/index.d.ts +58 -54
  62. package/dist/storage/domains/memory/index.d.ts.map +1 -1
  63. package/dist/storage/domains/notifications/index.d.ts +23 -0
  64. package/dist/storage/domains/notifications/index.d.ts.map +1 -0
  65. package/dist/storage/domains/observability/index.d.ts +49 -29
  66. package/dist/storage/domains/observability/index.d.ts.map +1 -1
  67. package/dist/storage/domains/prompt-blocks/index.d.ts +25 -0
  68. package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -0
  69. package/dist/storage/domains/schedules/index.d.ts +27 -0
  70. package/dist/storage/domains/schedules/index.d.ts.map +1 -0
  71. package/dist/storage/domains/scorer-definitions/index.d.ts +26 -0
  72. package/dist/storage/domains/scorer-definitions/index.d.ts.map +1 -0
  73. package/dist/storage/domains/scores/index.d.ts +29 -31
  74. package/dist/storage/domains/scores/index.d.ts.map +1 -1
  75. package/dist/storage/domains/skills/index.d.ts +26 -0
  76. package/dist/storage/domains/skills/index.d.ts.map +1 -0
  77. package/dist/storage/domains/thread-state/index.d.ts +38 -0
  78. package/dist/storage/domains/thread-state/index.d.ts.map +1 -0
  79. package/dist/storage/domains/tool-provider-connections/index.d.ts +14 -0
  80. package/dist/storage/domains/tool-provider-connections/index.d.ts.map +1 -0
  81. package/dist/storage/domains/utils.d.ts +28 -54
  82. package/dist/storage/domains/utils.d.ts.map +1 -1
  83. package/dist/storage/domains/workflow-definitions/index.d.ts +14 -0
  84. package/dist/storage/domains/workflow-definitions/index.d.ts.map +1 -0
  85. package/dist/storage/domains/workflows/index.d.ts +27 -32
  86. package/dist/storage/domains/workflows/index.d.ts.map +1 -1
  87. package/dist/storage/domains/workspaces/index.d.ts +26 -0
  88. package/dist/storage/domains/workspaces/index.d.ts.map +1 -0
  89. package/dist/storage/factory-storage.d.ts +28 -0
  90. package/dist/storage/factory-storage.d.ts.map +1 -0
  91. package/dist/storage/index.d.ts +128 -255
  92. package/dist/storage/index.d.ts.map +1 -1
  93. package/dist/storage/retention.d.ts +77 -0
  94. package/dist/storage/retention.d.ts.map +1 -0
  95. package/dist/vector/index.d.ts +31 -4
  96. package/dist/vector/index.d.ts.map +1 -1
  97. package/dist/vector/sql-builder.d.ts.map +1 -1
  98. package/package.json +22 -16
  99. package/dist/storage/domains/legacy-evals/index.d.ts +0 -18
  100. package/dist/storage/domains/legacy-evals/index.d.ts.map +0 -1
  101. package/dist/storage/domains/operations/index.d.ts +0 -110
  102. package/dist/storage/domains/operations/index.d.ts.map +0 -1
  103. package/dist/storage/domains/traces/index.d.ts +0 -21
  104. package/dist/storage/domains/traces/index.d.ts.map +0 -1
@@ -0,0 +1,184 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Agent networks
4
+
5
+ > **Deprecated:** Agent networks are deprecated and will be removed in a future major release. [Supervisor agents](https://mastra.ai/docs/capabilities/subagents) using `agent.stream()` or `agent.generate()` are now the recommended approach. It provides the same multi-agent coordination with better control, a simpler API, and easier debugging.
6
+ >
7
+ > See the [migration guide](https://mastra.ai/guides/migrations/network-to-supervisor) to upgrade.
8
+
9
+ A **routing agent** uses an LLM to interpret a request and decide which primitives (subagents, workflows, or tools) to call, in what order, and with what data.
10
+
11
+ ## Create an agent network
12
+
13
+ Configure a routing agent with `agents`, `workflows`, and `tools`. Memory is required as `.network()` uses it to store task history and determine when a task is complete.
14
+
15
+ Each primitive needs a clear `description` so the routing agent can decide which to use. For workflows and tools, `inputSchema` and `outputSchema` also help the router determine the right inputs.
16
+
17
+ ```typescript
18
+ import { Agent } from '@mastra/core/agent'
19
+ import { Memory } from '@mastra/memory'
20
+ import { LibSQLStore } from '@mastra/libsql'
21
+
22
+ import { researchAgent } from './research-agent'
23
+ import { writingAgent } from './writing-agent'
24
+ import { cityWorkflow } from '../workflows/city-workflow'
25
+ import { weatherTool } from '../tools/weather-tool'
26
+
27
+ export const routingAgent = new Agent({
28
+ id: 'routing-agent',
29
+ name: 'Routing Agent',
30
+ instructions: `
31
+ You are a network of writers and researchers. The user will ask you to research a topic. Always respond with a complete report—no bullet points. Write in full paragraphs, like a blog post. Do not answer with incomplete or uncertain information.`,
32
+ model: 'openai/gpt-5.6-sol',
33
+ agents: {
34
+ researchAgent,
35
+ writingAgent,
36
+ },
37
+ workflows: {
38
+ cityWorkflow,
39
+ },
40
+ tools: {
41
+ weatherTool,
42
+ },
43
+ memory: new Memory({
44
+ storage: new LibSQLStore({
45
+ id: 'mastra-storage',
46
+ url: 'file:../mastra.db',
47
+ }),
48
+ }),
49
+ })
50
+ ```
51
+
52
+ > **Note:** Subagents need a `description` on the `Agent` instance. Workflows and tools need a `description` plus `inputSchema` and `outputSchema` on `createWorkflow()` or `createTool()`.
53
+
54
+ ## Call the network
55
+
56
+ Call `.network()` with a user message. The method returns a stream of events you can iterate over.
57
+
58
+ ```typescript
59
+ const result = await routingAgent.network('Tell me three cool ways to use Mastra')
60
+
61
+ for await (const chunk of result) {
62
+ console.log(chunk.type)
63
+ if (chunk.type === 'network-execution-event-step-finish') {
64
+ console.log(chunk.payload.result)
65
+ }
66
+ }
67
+ ```
68
+
69
+ ## Structured output
70
+
71
+ Pass `structuredOutput` to get typed, validated results. Use `objectStream` for partial objects as they generate.
72
+
73
+ ```typescript
74
+ import { z } from 'zod'
75
+
76
+ const resultSchema = z.object({
77
+ summary: z.string().describe('A brief summary of the findings'),
78
+ recommendations: z.array(z.string()).describe('List of recommendations'),
79
+ confidence: z.number().min(0).max(1).describe('Confidence score'),
80
+ })
81
+
82
+ const stream = await routingAgent.network('Research AI trends', {
83
+ structuredOutput: { schema: resultSchema },
84
+ })
85
+
86
+ for await (const partial of stream.objectStream) {
87
+ console.log('Building result:', partial)
88
+ }
89
+
90
+ const final = await stream.object
91
+ console.log(final?.summary)
92
+ ```
93
+
94
+ ## Approve and decline tool calls
95
+
96
+ When a primitive requires approval, the stream emits an `agent-execution-approval` or `tool-execution-approval` chunk. Use `approveNetworkToolCall()` or `declineNetworkToolCall()` to respond.
97
+
98
+ Network approval uses snapshots to capture execution state. Ensure a [storage provider](https://mastra.ai/docs/storage/overview) is enabled in your Mastra instance.
99
+
100
+ ```typescript
101
+ const stream = await routingAgent.network('Perform some sensitive action', {
102
+ memory: {
103
+ thread: 'user-123',
104
+ resource: 'my-app',
105
+ },
106
+ })
107
+
108
+ for await (const chunk of stream) {
109
+ if (chunk.type === 'agent-execution-approval' || chunk.type === 'tool-execution-approval') {
110
+ // Approve
111
+ const approvedStream = await routingAgent.approveNetworkToolCall(chunk.payload.toolCallId, {
112
+ runId: stream.runId,
113
+ memory: { thread: 'user-123', resource: 'my-app' },
114
+ })
115
+
116
+ for await (const c of approvedStream) {
117
+ if (c.type === 'network-execution-event-step-finish') {
118
+ console.log(c.payload.result)
119
+ }
120
+ }
121
+ }
122
+ }
123
+ ```
124
+
125
+ To decline instead, call `declineNetworkToolCall()` with the same arguments.
126
+
127
+ ## Suspend and resume
128
+
129
+ When a primitive calls `suspend()`, the stream emits a suspension chunk (e.g., `tool-execution-suspended`). Use `resumeNetwork()` to provide the requested data and continue execution.
130
+
131
+ ```typescript
132
+ const stream = await routingAgent.network('Delete the old records', {
133
+ memory: { thread: 'user-123', resource: 'my-app' },
134
+ })
135
+
136
+ for await (const chunk of stream) {
137
+ if (chunk.type === 'workflow-execution-suspended') {
138
+ console.log(chunk.payload.suspendPayload)
139
+ }
140
+ }
141
+
142
+ // Resume with user confirmation
143
+ const resumedStream = await routingAgent.resumeNetwork(
144
+ { confirmed: true },
145
+ {
146
+ runId: stream.runId,
147
+ memory: { thread: 'user-123', resource: 'my-app' },
148
+ },
149
+ )
150
+
151
+ for await (const chunk of resumedStream) {
152
+ if (chunk.type === 'network-execution-event-step-finish') {
153
+ console.log(chunk.payload.result)
154
+ }
155
+ }
156
+ ```
157
+
158
+ ### Automatic resumption
159
+
160
+ Set `autoResumeSuspendedTools` to `true` so the network resumes suspended primitives based on the user's next message. This creates a conversational flow where users provide the required information naturally.
161
+
162
+ ```typescript
163
+ const stream = await routingAgent.network('Delete the old records', {
164
+ autoResumeSuspendedTools: true,
165
+ memory: { thread: 'user-123', resource: 'my-app' },
166
+ })
167
+ ```
168
+
169
+ Requirements for automatic resumption:
170
+
171
+ - **Memory configured**: The agent needs memory to track suspended tools across messages.
172
+ - **Same thread**: The follow-up message must use the same `thread` and `resource` identifiers.
173
+ - **`resumeSchema` defined**: The tool must define a `resumeSchema` so the network can extract data from the user's message.
174
+
175
+ | | Manual (`resumeNetwork`) | Automatic (`autoResumeSuspendedTools`) |
176
+ | -------- | ---------------------------------------------- | ----------------------------------------- |
177
+ | Best for | Custom UIs with approval buttons | Chat-style interfaces |
178
+ | Control | Full control over resume timing and data | Network extracts data from user's message |
179
+ | Setup | Handle suspension chunks, call `resumeNetwork` | Set flag, define `resumeSchema` on tools |
180
+
181
+ ## Related
182
+
183
+ - [Supervisor agents](https://mastra.ai/docs/capabilities/subagents)
184
+ - [Migration: `.network()` to supervisor agents](https://mastra.ai/guides/migrations/network-to-supervisor)
@@ -0,0 +1,137 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Workers
4
+
5
+ > **Beta:** This feature is in beta. The API is stable enough for production use, but some details may change. See [known limitations](#known-limitations) for current gaps.
6
+
7
+ Workers handle background processing outside the request-response cycle. Workflow step execution, cron-based scheduling, and long-running tool calls all run in workers, keeping the API responsive.
8
+
9
+ By default, workers run in the same process as the API. For production workloads, you can split them into separate processes or containers and scale each one independently.
10
+
11
+ ## When to use workers
12
+
13
+ Workers matter when any of these apply:
14
+
15
+ - Workflow steps take more than a few seconds and shouldn't block API responses
16
+ - You need event durability so in-flight work survives process restarts
17
+ - Different parts of the system need to scale independently (e.g., more orchestration capacity without more API instances)
18
+ - Background tool calls should run on dedicated compute
19
+
20
+ If your application handles light traffic and workflows complete fast, the default in-process setup works fine. Skip the worker infrastructure until you need it.
21
+
22
+ ## Worker types
23
+
24
+ Mastra has three built-in worker types. Each handles a specific kind of background processing.
25
+
26
+ ### Orchestration worker
27
+
28
+ Subscribes to workflow events on the [PubSub](https://mastra.ai/docs/server/pubsub) bus and executes workflow steps. Every `workflow.start`, step transition, and lifecycle event flows through this worker.
29
+
30
+ In a split deployment, the orchestration worker pulls events from a distributed PubSub backend and delegates step execution back to the API over HTTP. In-process, it runs steps directly.
31
+
32
+ The orchestration worker requires a PubSub backend that supports pull mode (e.g., [`RedisStreamsPubSub`](https://mastra.ai/reference/pubsub/redis-streams) or [`GoogleCloudPubSub`](https://mastra.ai/reference/pubsub/google-cloud-pubsub)).
33
+
34
+ ### Scheduler worker
35
+
36
+ Polls storage for due cron schedules and publishes `workflow.start` events. It's a producer only, meaning it creates work for the orchestration worker to pick up.
37
+
38
+ The scheduler reads declarative `schedule` fields from your workflow definitions automatically. See [Scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows) for how to declare schedules.
39
+
40
+ **Don't run more than one scheduler instance.** Multiple schedulers polling the same storage would fire duplicate events for the same schedule.
41
+
42
+ ### Background task worker
43
+
44
+ Executes agent tool calls marked with `background: { enabled: true }`. When an agent invokes a background tool, the API dispatches the task to this worker instead of blocking the response stream.
45
+
46
+ The background task worker manages concurrency limits, task lifecycle, and result delivery through the PubSub bus.
47
+
48
+ ## How workers run
49
+
50
+ ### In-process mode (default)
51
+
52
+ With no configuration, Mastra creates and starts workers inside the API process. Events flow through an in-memory PubSub, and everything shares a single Node.js runtime.
53
+
54
+ ```typescript
55
+ import { Mastra } from '@mastra/core/mastra'
56
+
57
+ export const mastra = new Mastra({
58
+ // Workers run in-process by default.
59
+ // No pubsub or worker config needed.
60
+ })
61
+ ```
62
+
63
+ This setup needs no external infrastructure beyond your storage adapter. It doesn't survive process crashes, and you can't scale individual components.
64
+
65
+ ### Split processes
66
+
67
+ To run workers in their own processes, configure a distributed [PubSub](https://mastra.ai/docs/server/pubsub) backend and use the `MASTRA_WORKERS` environment variable to control which workers start in each process.
68
+
69
+ **Redis Streams + PostgreSQL**:
70
+
71
+ ```typescript
72
+ import { Mastra } from '@mastra/core/mastra'
73
+ import { RedisStreamsPubSub } from '@mastra/redis-streams'
74
+ import { PostgresStore } from '@mastra/pg'
75
+
76
+ export const mastra = new Mastra({
77
+ storage: new PostgresStore({
78
+ connectionString: process.env.DATABASE_URL!,
79
+ }),
80
+ pubsub: new RedisStreamsPubSub({
81
+ url: process.env.REDIS_URL!,
82
+ }),
83
+ })
84
+ ```
85
+
86
+ **Google Cloud Pub/Sub + LibSQL**:
87
+
88
+ ```typescript
89
+ import { Mastra } from '@mastra/core/mastra'
90
+ import { GoogleCloudPubSub } from '@mastra/google-cloud-pubsub'
91
+ import { LibSQLStore } from '@mastra/libsql'
92
+
93
+ export const mastra = new Mastra({
94
+ storage: new LibSQLStore({
95
+ url: process.env.DATABASE_URL!,
96
+ }),
97
+ pubsub: new GoogleCloudPubSub({
98
+ projectId: process.env.GCP_PROJECT_ID!,
99
+ }),
100
+ })
101
+ ```
102
+
103
+ Any [supported storage backend](https://mastra.ai/reference/workers/overview) works. Swap the storage adapter for your preferred database.
104
+
105
+ Run the same build artifact in multiple containers, each with a different [`MASTRA_WORKERS`](https://mastra.ai/reference/workers/overview) value to control which worker starts in each process.
106
+
107
+ Split deployments require a distributed PubSub backend ([`RedisStreamsPubSub`](https://mastra.ai/reference/pubsub/redis-streams) or [`GoogleCloudPubSub`](https://mastra.ai/reference/pubsub/google-cloud-pubsub)), a shared [storage backend](https://mastra.ai/reference/workers/overview), and network connectivity between the orchestration worker and the API.
108
+
109
+ The [worker deployment guide](https://mastra.ai/guides/deployment/mastra-workers) walks through this setup with Docker Compose and Kubernetes examples.
110
+
111
+ ## Network architecture
112
+
113
+ Workers are internal infrastructure. They're not exposed to end users and don't need their own subdomain, public URL, or inbound HTTP route.
114
+
115
+ In a split deployment:
116
+
117
+ - **The API server is the only public-facing process**: It serves all client HTTP requests, including REST endpoints, agent interactions, workflow triggers, and any custom routes.
118
+ - **Workers connect outbound only**: They pull events from the distributed PubSub backend and read/write to the shared storage database. They don't accept inbound traffic from clients.
119
+ - **The orchestration worker calls the API internally**: It sends step execution requests to the API over the container network using `MASTRA_STEP_EXECUTION_URL`. This is internal service-to-service communication, not a public endpoint.
120
+
121
+ All three worker types (orchestration, scheduler, background task) sit behind the API on a private network. They share access to the PubSub backend and storage database but never receive traffic directly from clients. If a worker-related feature needs an HTTP route (for example, token minting for a voice integration), that route runs on the API server, not on the worker process.
122
+
123
+ ## Known limitations
124
+
125
+ - **No dead-letter queue**: Failed events are nacked and retried, but there's no DLQ for events that fail after all retries.
126
+ - **No built-in health endpoint**: Workers don't expose an HTTP health check. Use container-level liveness probes or process monitoring.
127
+ - **Scheduler is single-instance**: Running multiple scheduler processes causes duplicate schedule fires.
128
+ - **Runs stuck in "running" after API crash**: If the API process crashes while executing a workflow step, the run remains in `running` status with no automatic retry. For [durable agents](https://mastra.ai/docs/long-running-agents/durable-agents), set `recovery.durableAgents` to `'auto'` in the Mastra config to automatically re-drive orphaned runs on server restart. See [Crash recovery](https://mastra.ai/docs/long-running-agents/durable-agents) for details.
129
+
130
+ ## Related
131
+
132
+ - [Worker deployment guide](https://mastra.ai/guides/deployment/mastra-workers): Docker Compose and Kubernetes examples
133
+ - [Worker authentication](https://mastra.ai/docs/server/auth/workers): Secure worker-to-API communication
134
+ - [Workers reference](https://mastra.ai/reference/workers/overview): Details about worker environment variables and types, with a list of supported storage backends
135
+ - [CLI reference](https://mastra.ai/reference/cli/mastra): `mastra worker build` and `mastra worker start`
136
+ - [PubSub](https://mastra.ai/docs/server/pubsub): Event delivery backends
137
+ - [Scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows): Declare cron schedules on workflows
@@ -0,0 +1,349 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Editor
4
+
5
+ Editor works like a CMS for Mastra agents. Collaborators can change an agent's instructions and tools in Studio without accessing the codebase or writing code. They can test changes before making them live.
6
+
7
+ TypeScript defines the agent's default values. Editor saves changes separately instead of updating the source code, so collaborators can improve the agent while developers retain control over its model, identity, and runtime.
8
+
9
+ A [deployed Studio](https://mastra.ai/docs/studio/deployment) makes Editor available to collaborators outside local development.
10
+
11
+ > **📹 Watch:** Watch the [Mastra Editor workshop](https://www.youtube.com/watch?v=XTjuRoI7t_k\&pp=ygUWbWFzdHJhIGVkaXRvciB3b3Jrc2hvcA%3D%3D) for a guided walkthrough.
12
+
13
+ ## When to use Editor
14
+
15
+ Use Editor when an agent is defined in code but the people responsible for its behavior shouldn't edit the codebase. It works well when instructions or tools change often and need testing before they reach users. If developers own every change and release agent configuration with the application, keep the [agent configuration in code](https://mastra.ai/docs/agents/overview) instead.
16
+
17
+ ## Quickstart
18
+
19
+ Install `@mastra/editor`. This quickstart uses LibSQL to store Editor changes:
20
+
21
+ **npm**:
22
+
23
+ ```bash
24
+ npm install @mastra/editor @mastra/libsql
25
+ ```
26
+
27
+ **pnpm**:
28
+
29
+ ```bash
30
+ pnpm add @mastra/editor @mastra/libsql
31
+ ```
32
+
33
+ **Yarn**:
34
+
35
+ ```bash
36
+ yarn add @mastra/editor @mastra/libsql
37
+ ```
38
+
39
+ **Bun**:
40
+
41
+ ```bash
42
+ bun add @mastra/editor @mastra/libsql
43
+ ```
44
+
45
+ Add `MastraEditor` and storage to the `Mastra` instance. Existing storage can be reused instead of adding the LibSQL store shown here.
46
+
47
+ ```typescript
48
+ import { Mastra } from '@mastra/core'
49
+ import { MastraEditor } from '@mastra/editor'
50
+ import { LibSQLStore } from '@mastra/libsql'
51
+
52
+ export const mastra = new Mastra({
53
+ agents: {/* existing agents */},
54
+ storage: new LibSQLStore({
55
+ id: 'mastra-storage',
56
+ url: 'file:./mastra.db',
57
+ }),
58
+ editor: new MastraEditor(),
59
+ })
60
+ ```
61
+
62
+ ## Use Editor in Studio
63
+
64
+ In [Studio](https://mastra.ai/docs/studio/overview), open **Agents**, select an agent, then select **Editor**. Collaborators can update the agent's instructions and tools based on its Editor permissions.
65
+
66
+ With database storage, save changes as a draft to test them without affecting the live agent. Publish the draft when it's ready to use.
67
+
68
+ ## Instructions
69
+
70
+ The **Instructions** section shows the agent's system prompt defined in code. Collaborators can override it or add instruction blocks.
71
+
72
+ An instruction block can include values from the current request. For example, `{{userName}}` inserts a name supplied through [request context](https://mastra.ai/docs/server/request-context). A [display condition](https://mastra.ai/reference/editor/prompt-blocks) can show a block only for a customer, role, or feature flag.
73
+
74
+ ### Prompt blocks
75
+
76
+ A prompt block is a saved piece of instruction text that can be used by more than one agent. Create one under **Prompts**, publish it, then open an agent's **Instructions** section and select **Add block**.
77
+
78
+ For example, agents for support, returns, and order status may all need the same refund policy. Save the policy as a prompt block and add it to each agent. When the policy changes, update and publish the block once instead of editing three agents.
79
+
80
+ When a prompt block changes, every agent that references its published version receives the update. Draft changes are used only while previewing, so they don't affect the live agents until the block is published.
81
+
82
+ See the [prompt blocks reference](https://mastra.ai/reference/editor/prompt-blocks) for template syntax, conditions, versions, and APIs.
83
+
84
+ ## Tools
85
+
86
+ Tools let an agent take actions. Collaborators choose from the tools available to Editor, but they can't implement new tools in Studio. How tools become available depends on their source:
87
+
88
+ - **Project tools** must be implemented and registered in the Mastra project by a developer.
89
+ - **Integration tools** become available after a developer registers a provider such as Composio or Arcade. Collaborators can then browse the provider's catalog and add tools without each tool being added in code first.
90
+ - **MCP tools** become available when an MCP client is configured. A collaborator with access can create the client in Studio, then choose from the tools exposed by its servers.
91
+
92
+ In the agent's **Tools** section, collaborators can add the tools it needs or rewrite a tool's description for that agent. A more specific description helps the agent understand when to use the tool without changing the tool itself.
93
+
94
+ ### Project tools
95
+
96
+ Developers can register a project tool on the `Mastra` instance to make it available in Editor:
97
+
98
+ ```typescript
99
+ import { Mastra } from '@mastra/core'
100
+ import { MastraEditor } from '@mastra/editor'
101
+ import { searchOrders } from './tools/search-orders'
102
+
103
+ export const mastra = new Mastra({
104
+ tools: {
105
+ searchOrders,
106
+ },
107
+ agents: {/* agents */},
108
+ editor: new MastraEditor(),
109
+ })
110
+ ```
111
+
112
+ The Studio tool picker lists the tool. A collaborator can add it to an agent when that agent allows tool editing. The agent's Editor view also lists tools attached in code.
113
+
114
+ ### Composio
115
+
116
+ [Composio](https://composio.dev) provides tools for services such as GitHub, Slack, and Gmail. Register the provider with a Composio API key to make its tool catalog available in Editor:
117
+
118
+ ```typescript
119
+ import { Mastra } from '@mastra/core'
120
+ import { MastraEditor } from '@mastra/editor'
121
+ import { ComposioToolProvider } from '@mastra/editor/composio'
122
+
123
+ export const mastra = new Mastra({
124
+ agents: {/* agents */},
125
+ editor: new MastraEditor({
126
+ toolProviders: {
127
+ composio: new ComposioToolProvider({
128
+ apiKey: process.env.COMPOSIO_API_KEY!,
129
+ }),
130
+ },
131
+ }),
132
+ })
133
+ ```
134
+
135
+ Composio tool IDs look like `GITHUB_CREATE_ISSUE`. By default, a selected tool uses the connection associated with the agent's author. See [connection scope](https://agent-builder.mastra.ai/tool-providers#connection-scope) to use each caller's connection instead.
136
+
137
+ ### Arcade
138
+
139
+ [Arcade](https://arcade.dev) provides another catalog of tools with built-in authentication. Register it with an Arcade API key:
140
+
141
+ ```typescript
142
+ import { Mastra } from '@mastra/core'
143
+ import { MastraEditor } from '@mastra/editor'
144
+ import { ArcadeToolProvider } from '@mastra/editor/arcade'
145
+
146
+ export const mastra = new Mastra({
147
+ agents: {/* agents */},
148
+ editor: new MastraEditor({
149
+ toolProviders: {
150
+ arcade: new ArcadeToolProvider({
151
+ apiKey: process.env.ARCADE_API_KEY!,
152
+ }),
153
+ },
154
+ }),
155
+ })
156
+ ```
157
+
158
+ Arcade tool IDs use `Toolkit.ToolName` format, such as `Github.GetRepository`.
159
+
160
+ ### MCP clients
161
+
162
+ Collaborators can also create a reusable MCP client in Studio and add its tools to an agent. Stored clients can start a local `stdio` server or connect to a remote HTTP server. Tool filters let each agent use only the tools it needs from that server.
163
+
164
+ See the [Editor tools reference](https://mastra.ai/reference/editor/tools) for MCP configuration, conditions, filtering, and resolution order. See [`ToolProvider`](https://mastra.ai/reference/editor/tool-provider) for provider options.
165
+
166
+ ## Decide what collaborators can edit
167
+
168
+ By default, collaborators can change an agent's instructions and manage its tools, including their descriptions. The agent's `id`, `name`, and `model` always come from code.
169
+
170
+ Use the agent's `editor` field to limit what can be changed:
171
+
172
+ ```typescript
173
+ import { Agent } from '@mastra/core/agent'
174
+
175
+ export const supportAgent = new Agent({
176
+ id: 'support-agent',
177
+ name: 'Support agent',
178
+ instructions: 'Help customers with Acme products.',
179
+ model: 'openai/gpt-5.6-sol',
180
+ editor: {
181
+ instructions: true,
182
+ tools: {
183
+ description: true,
184
+ },
185
+ },
186
+ })
187
+ ```
188
+
189
+ This agent lets collaborators change its instructions and improve the descriptions of tools already attached to it. They can't add or remove tools.
190
+
191
+ | `editor` value | What collaborators can change |
192
+ | ---------------------------------- | ------------------------------------------- |
193
+ | Omitted | Instructions, tools, and tool descriptions |
194
+ | `false` | Nothing |
195
+ | `{ instructions: true }` | Instructions |
196
+ | `{ tools: true }` | Tools and tool descriptions |
197
+ | `{ tools: { description: true } }` | Descriptions of tools already added in code |
198
+
199
+ Studio shows everything else as read-only. See [editor overrides](https://mastra.ai/reference/agents/agent) for the complete configuration.
200
+
201
+ ## Choose where changes are stored
202
+
203
+ Editor can save changes in the configured database or as files in the repository.
204
+
205
+ ### Database storage
206
+
207
+ The database option is the default. Editor uses the storage configured on the `Mastra` instance, so the application and Editor can share the same backend.
208
+
209
+ To use a separate backend for Editor data, set the `editor` option on [`MastraCompositeStore`](https://mastra.ai/reference/storage/composite). Storage domains without an explicit route continue to use its `default` store.
210
+
211
+ The following example keeps application and Editor data in separate LibSQL files:
212
+
213
+ ```typescript
214
+ import { Mastra } from '@mastra/core'
215
+ import { MastraCompositeStore } from '@mastra/core/storage'
216
+ import { MastraEditor } from '@mastra/editor'
217
+ import { LibSQLStore } from '@mastra/libsql'
218
+
219
+ export const mastra = new Mastra({
220
+ agents: {/* existing agents */},
221
+ storage: new MastraCompositeStore({
222
+ id: 'mastra-storage',
223
+ default: new LibSQLStore({
224
+ id: 'app-storage',
225
+ url: 'file:./mastra.db',
226
+ }),
227
+ editor: new LibSQLStore({
228
+ id: 'editor-storage',
229
+ url: 'file:./editor.db',
230
+ }),
231
+ }),
232
+ editor: new MastraEditor(),
233
+ })
234
+ ```
235
+
236
+ ### Repository files
237
+
238
+ Use the code source to keep overrides alongside application code. Developers can review the files in pull requests and deploy them with the application:
239
+
240
+ ```typescript
241
+ import { Mastra } from '@mastra/core'
242
+ import { MastraEditor } from '@mastra/editor'
243
+
244
+ export const mastra = new Mastra({
245
+ agents: {/* existing agents */},
246
+ editor: new MastraEditor({
247
+ source: 'code',
248
+ codePath: './mastra/editor',
249
+ }),
250
+ })
251
+ ```
252
+
253
+ In this mode, each edited agent has one JSON override file. Editor doesn't generate TypeScript or change the file where the agent was created. By default, an agent with the ID `support-agent` gets this file:
254
+
255
+ ```text
256
+ mastra/editor/agents/support-agent.json
257
+ ```
258
+
259
+ The file contains only the parts managed by Editor. For example:
260
+
261
+ ```json
262
+ {
263
+ "instructions": "Help customers with Acme products and answer in their language.",
264
+ "tools": {
265
+ "searchOrders": {
266
+ "description": "Look up an order by its number"
267
+ }
268
+ }
269
+ }
270
+ ```
271
+
272
+ The agent's model, name, and other code-owned fields stay in its TypeScript file. Mastra reads the JSON and applies these values when the agent runs.
273
+
274
+ When a collaborator saves in Studio, they can write the file to the local filesystem or download it. With a source-control integration, Studio can open a pull request instead. Git then provides the review and version history.
275
+
276
+ See [`MastraEditor`](https://mastra.ai/reference/editor/mastra-editor) for file locations and source options.
277
+
278
+ ## Versioning
279
+
280
+ Database-backed agents and prompt blocks use draft and published versions. Saving creates a draft while the live agent continues using the published version. Publishing makes the draft live. Restoring an older version creates a draft that collaborators can test before publishing.
281
+
282
+ Code-backed agent overrides use JSON files and Git history.
283
+
284
+ ### Select a version
285
+
286
+ An application can choose a stored version for each request by passing a status (`published` or `draft`) or an exact version ID:
287
+
288
+ ```typescript
289
+ const publishedAgent = await mastra.getAgentById('support-agent', {
290
+ status: 'published',
291
+ })
292
+
293
+ const draftAgent = await mastra.getAgentById('support-agent', {
294
+ status: 'draft',
295
+ })
296
+
297
+ const versionedAgent = await mastra.getAgentById('support-agent', {
298
+ versionId: 'abc-123',
299
+ })
300
+ ```
301
+
302
+ Version selection supports:
303
+
304
+ - Compare two versions in an A/B test.
305
+ - Give a draft to a small group before publishing it for everyone.
306
+ - Keep production on the published version while staging uses the latest draft.
307
+ - Pin a customer to a particular version.
308
+
309
+ The same version controls work when a supervisor calls sub-agents. Developers can test a draft sub-agent without changing the rest of the system.
310
+
311
+ See the [Editor versioning reference](https://mastra.ai/reference/editor/versioning) for version selection, sub-agent behavior, REST endpoints, and SDK methods.
312
+
313
+ ## Programmatic access
314
+
315
+ Everything available in Studio is also available programmatically through [`mastra.getEditor()`](https://mastra.ai/reference/core/getEditor), the REST API, or the Client SDK. Use it to script bulk updates or seed stored configurations from code. It can also power automation that tunes agents based on [evaluation results](https://mastra.ai/docs/datasets/running-experiments).
316
+
317
+ Call `mastra.getEditor()` when application code has access to the Mastra instance:
318
+
319
+ ```typescript
320
+ import { mastra } from '../mastra'
321
+
322
+ const editor = mastra.getEditor()!
323
+
324
+ await editor.agent.update({
325
+ id: 'support-agent',
326
+ instructions: 'Help customers with Acme products. Reply in their language.',
327
+ })
328
+ ```
329
+
330
+ The direct `editor.agent.update()` method activates the new version immediately. To create a draft without changing the live agent, use the stored-agent REST API or Client SDK instead:
331
+
332
+ ```bash
333
+ curl -X PATCH http://localhost:4111/api/stored/agents/support-agent \
334
+ -H "Content-Type: application/json" \
335
+ -d '{
336
+ "instructions": "Help customers with Acme products. Reply in their language."
337
+ }'
338
+ ```
339
+
340
+ The default server prefix is `/api`. Developers can set a custom prefix in the server configuration.
341
+
342
+ See the [`MastraEditor` namespaces](https://mastra.ai/reference/editor/mastra-editor) and [Client SDK agents API](https://mastra.ai/reference/client-js/agents) for available operations.
343
+
344
+ ## Next steps
345
+
346
+ - [MastraEditor reference](https://mastra.ai/reference/editor/mastra-editor)
347
+ - [Prompt blocks reference](https://mastra.ai/reference/editor/prompt-blocks)
348
+ - [Editor tools reference](https://mastra.ai/reference/editor/tools)
349
+ - [Editor versioning reference](https://mastra.ai/reference/editor/versioning)