← Back to all agents
Framework Open Source
Mastra
TypeScript-native framework for building agents that reason, remember, and act.
Our take
The best pick for TypeScript developers — batteries-included (memory, tools, MCP, observability) with great DX.
What it is
Mastra is a TypeScript-native agent framework that ships with everything you need out of the box: agent memory, tool use, MCP integration, RAG pipelines, structured output, observability, and multi-agent orchestration. It is purpose-built for TS and follows established AI patterns, which makes it a favorite among full-stack JS/TS teams.
Best for
- Build production agents in a TypeScript codebase
- Add memory + tools + RAG without stitching many libraries
- Ship agents with built-in observability
Pros
- TypeScript-native with excellent type safety and DX
- Batteries included: memory, tools, MCP, RAG, evals
- Fast-growing community and weekly releases
Cons
- Younger ecosystem than LangChain/CrewAI
- JS/TS only — no first-class Python
Quick start
- Install: `npm create mastra@latest` then follow the CLI; or `pnpm add @mastra/core @mastra/agents`.
- Set one provider key in `.env`: `ANTHROPIC_API_KEY` or `OPENAI_API_KEY` (or `GOOGLE_GENERATIVE_AI_API_KEY` — Gemini has a generous free tier).
- Run `npm run dev` → opens Mastra Playground in your browser to design agents visually.
- Define an Agent: `new Agent({ name: "assistant", instructions: "...", model: anthropic("claude-3-5-sonnet"), tools: [...] })`.
- Compose Workflows (durable state machines with loops/branching) and Evals (model-graded unit tests on agent output).
Sample input / output
Input
Code:
import { Agent } from "@mastra/core"
import { anthropic } from "@ai-sdk/anthropic"
const supportAgent = new Agent({
name: "support-bot",
instructions: "You answer questions about our product. Cite the linked docs page.",
model: anthropic("claude-3-5-sonnet-latest"),
tools: [],
})
const result = await supportAgent.generate("How do I reset my password?")
console.log(result.text) Output
Agent response with citation: "To reset your password, open Settings → Security → Password → Reset. Reference: docs.example.com/security#reset [Source 1]."
Tool calls visible in Playground. Execution time logged via OpenTelemetry. Easily swapped to evals.csv for regression tracking. Benchmarks
GitHub stars 19,000+ — github.com/mastra-ai/mastra
Backed by YC W25; founded by the Gatsby team — Toutiao article
Codebase 99.8% TypeScript
Primitives Agents / Tools / Workflows (durable graphs) / RAG / Evals / Integrations (auto-generated type-safe clients)
Pricing
Free library; Mastra Cloud paid
Underlying models
Self-hosting
Yes — Mastra can be self-hosted under the MIT license. This gives you full control over data and deployment.
Should you pick this?
Pick it if You're a TypeScript / Next.js team and want the batteries-included DX — memory, MCP, RAG, evals, and observability in one typed package.
Skip it if You prefer Python — LangGraph, CrewAI, or AutoGen are stronger there. For pure graph control over cycles and retries with no extra opinions, LangGraph beats Mastra.