DocsStorageOverview

MastraStorage

MastraStorage provides a unified interface for managing

  • Workflow Tracking, allowing users to suspend and resume workflow runs.
  • Memory, threads and messages per resourceId in your application
  • Traces - OpenTelemetry traces from all components of Mastra
  • Evaluation Datasets - as evaluations are run, the scores and reasons are stored in datasets.
Diagram showing storage in Mastra

Mastra provides different storage providers, but you can treat them as interchangeable. Eg, you could use libsql in development but postgres in production, and your code will work the same both ways.

Data Schema

Memory

Messages

Stores conversation messages and their metadata. Each message belongs to a thread and contains the actual content along with metadata about the sender role and message type.

id
text
Unique identifier for the message
PRIMARYKEY
CAN NOT BE NULL
thread_id
text
Reference to the parent thread
FK → threads.id
CAN NOT BE NULL
content
text
The actual message content
CAN NOT BE NULL
role
text
Message sender role (user/assistant/system)
CAN NOT BE NULL
type
text
Message type identifier
CAN NOT BE NULL
createdAt
timestamp
When the message was created
CAN NOT BE NULL

Threads

Groups related messages together and associates them with a resource. Contains metadata about the conversation.

id
text
Unique identifier for the thread
PRIMARYKEY
CAN NOT BE NULL
resourceId
text
Identifier for the associated resource
CAN NOT BE NULL
title
text
Title of the conversation thread
CAN NOT BE NULL
metadata
text
Additional custom metadata for the thread
createdAt
timestamp
When the thread was created
CAN NOT BE NULL
updatedAt
timestamp
When the thread was last modified
CAN NOT BE NULL

Workflows

Preserves workflow execution states and enables resuming workflows:

workflow_name
text
Name of the workflow
run_id
text
Unique identifier for this workflow run
snapshot
text
Serialized workflow state data
createdAt
timestamp
When the workflow state was first saved
updatedAt
timestamp
When the workflow state was last modified

Evaluation Datasets

Stores evaluation results from running metrics against agent outputs:

input
text
Input provided to the agent
output
text
Output generated by the agent
result
jsonb
Metric evaluation result data (score and details)
agent_name
text
Name of the evaluated agent
metric_name
text
Name of the evaluation metric
instructions
text
Agent instructions used during evaluation
test_info
jsonb
Additional test metadata and configuration
global_run_id
text
Identifier for the global evaluation run
run_id
text
Identifier for this specific evaluation
created_at
timestamp
When the evaluation was performed

Traces

Captures OpenTelemetry traces for monitoring and debugging:

id
text
Primary key - Unique identifier for the trace
CAN NOT BE NULL
PRIMARYKEY
parentSpanId
text
ID of the parent span if this is a child span
name
text
Name of the traced operation
CAN NOT BE NULL
traceId
text
ID of the full trace this span belongs to
CAN NOT BE NULL
scope
text
Scope of the traced operation
CAN NOT BE NULL
kind
integer
Type of span (e.g., client, server)
CAN NOT BE NULL
attributes
jsonb
Key-value pairs with span metadata
status
jsonb
Status information about the span
events
jsonb
Time-stamped events that occurred during the span
links
jsonb
Links to other related spans
other
text
Additional span data
startTime
bigint
When the span started (nanoseconds)
CAN NOT BE NULL
endTime
bigint
When the span ended (nanoseconds)
CAN NOT BE NULL
createdAt
timestamp
When this trace record was created
CAN NOT BE NULL

Configuration

Mastra can be configured with a default storage option:

import { Mastra } from '@mastra/core/mastra';
import { DefaultStorage } from '@mastra/core/storage/libsql';
 
const mastra = new Mastra({
  storage: new DefaultStorage({
    config: {
      url: "file:storage.db",
    }
  }),
});

Other Storage Providers

If you want to use other storage, check out the following providers: