TL;DR:
- Mastra is a TypeScript-native AI agent framework built by the Gatsby.js creators, with memory, tool integration, and workflow orchestration as first-class primitives rather than bolted-on extras
- It’s opinionated in ways that reduce boilerplate: agents have structured memory by default, workflows are typed, and integrations with common services come pre-built
- Worth evaluating if you’re building TypeScript/Node.js applications with agents and find yourself writing the same orchestration scaffolding repeatedly
There are a lot of agent frameworks right now. LangChain, LangGraph, AutoGen, CrewAI, Temporal — each has a different model for how agents should work, and each trades off expressiveness against complexity in different ways. Mastra is newer and takes a specific position: it’s for TypeScript developers building production applications, and it ships with memory and orchestration as part of the framework rather than leaving you to assemble them.
The Gatsby connection is worth noting, not for brand reasons, but because it signals something about the team’s priorities. Gatsby built its reputation on opinionated developer experience — strong conventions, good tooling, batteries included. Mastra reads like the same instinct applied to agent infrastructure.
What Mastra Actually Includes
The core of Mastra is an agent abstraction with a few things you’d otherwise build yourself.
Memory is structured. An agent in Mastra has a memory layer that persists across conversations and across time. This isn’t just “pass the conversation history as context” — Mastra maintains semantic memory (things the agent has learned, distilled from past interactions) alongside episodic memory (the conversation log). The memory layer uses embeddings and vector search to surface relevant past context without blowing out your token budget.
Workflows are typed. Mastra’s workflow system is step-based and TypeScript-typed end to end. You define a workflow as a sequence of steps, each with typed inputs and outputs. Steps can branch based on conditions, run in parallel, or await external events. The type safety means TypeScript catches shape mismatches at compile time rather than at runtime when the agent is live.
Tool integration is first-class. Mastra uses OpenAPI specs to auto-generate typed tool definitions from any API that exposes a spec. If you’re integrating with Stripe, Notion, GitHub, or any OpenAPI-documented service, Mastra can generate the tool bindings directly from the spec. You define what the agent is allowed to call; the framework handles serialisation and error handling.
Evals are included. This is the part that gets less attention in the demos but matters in production. Mastra includes an evaluation framework for testing agent behaviour against defined criteria. You write eval cases the way you’d write unit tests; Mastra runs them and scores outputs. It’s not a complete substitute for manual review, but it gives you a feedback loop that’s faster than “deploy and see what happens.”
What the Code Looks Like
import { Mastra, Agent } from "@mastra/core";
const agent = new Agent({
name: "support-agent",
instructions: `You are a customer support agent for Acme Corp.
Answer questions about orders, returns, and product availability.
If you cannot answer, escalate to a human.`,
model: {
provider: "ANTHROPIC",
name: "claude-sonnet-4-6",
},
tools: {
getOrderStatus,
createReturnRequest,
lookupInventory,
},
});
const mastra = new Mastra({ agents: { "support-agent": agent } });
The agent definition is clean. The framework handles connecting the LLM, routing tool calls, managing conversation context, and persisting memory. You’re not wiring together HTTP clients, retry logic, and JSON parsing manually.
A workflow looks similar:
const orderWorkflow = createWorkflow({
name: "order-resolution",
steps: [
checkOrderStatus,
determineResolution,
{
step: processRefund,
condition: ({ data }) => data.resolution === "refund",
},
{
step: scheduleReplacement,
condition: ({ data }) => data.resolution === "replacement",
},
notifyCustomer,
],
});
Each step is a typed function. The workflow engine handles the branching, retries, and state persistence. If the process fails midway, it can resume from the last successful step.
Memory in Practice
Here’s the thing about memory that becomes obvious once you’re building real agent applications: the naive “include the whole conversation” approach doesn’t scale. Long conversations bloat your context window, cost more per call, and add latency. But if you truncate the history, the agent loses relevant context.
Mastra’s approach is to treat memory as a retrieval problem rather than a context window problem. The agent stores a running summary of what it’s learned, distilled at regular intervals. When a new message comes in, it retrieves semantically relevant memories using embedding similarity rather than time-ordering. This means an agent can “remember” something from six months ago if it’s relevant, without carrying all of the intervening conversation in the current context.
For customer-facing agents, this means an agent can recall that a customer had a specific complaint last quarter without you building a custom retrieval system on top of a vector database.
Where Mastra Fits (and Where It Doesn’t)
Mastra is a good fit if you’re already in TypeScript/Node.js and want to build agents for customer-facing or internal tooling workflows. The opinionated structure works well when your use case maps to the framework’s model — agents that persist, workflows with definable steps, tools from APIs.
It’s less suited to research-style agents where you need full control over the orchestration loop, or to multi-agent systems with complex coordination patterns that don’t fit the workflow step model. For those use cases, something like LangGraph (which gives you a graph-based orchestration primitive) or building directly on the model provider SDKs might give you more flexibility.
The TypeScript-native design also means Python-first shops will want to evaluate alternatives — Mastra has no Python equivalent, and the team doesn’t appear to be building one.
Getting Started
npm install @mastra/core @mastra/memory
Mastra’s documentation is good for a framework this young. The quickstart gets you to a functioning agent in about fifteen minutes. The concepts around memory and workflows take longer to fully understand, but the mental model is consistent once it clicks.
If you’ve been assembling agent infrastructure from primitives — calling the API directly, building your own memory persistence, hand-rolling workflow state — Mastra is worth an afternoon’s evaluation. For a class of TypeScript agent applications, it removes a meaningful amount of scaffolding work.