Mastra — TypeScript Agent Framework

The TypeScript-native agent framework with a novel “Observational Memory” system — two background agents compress conversation history into dense observation logs (5-40x smaller, no vector DB needed). 22K+ stars, 300K+ weekly npm downloads. 94.87% on LongMemEval.

Why Mastra Matters

Fills a critical gap: most agent frameworks are Python-first (LangGraph, CrewAI, AutoGen, Letta). Mastra is TypeScript-native, designed for the Next.js / Vercel / Node.js ecosystem.

Observational Memory (Key Innovation)

Traditional memory: store raw messages → embed → vector search → retrieve. Mastra’s approach: two background agents compress old messages into dense observation logs.

Architecture

Messages accumulate during conversation
        ↓ (threshold reached)
┌─────────────────────────┐
│ Observer Agent           │
│ Compresses messages into │
│ dense observation logs   │
│ (5-40x smaller)          │
└──────────┬──────────────┘
           ↓
┌─────────────────────────┐
│ Reflector Agent          │
│ Condenses observations   │
│ into higher-level        │
│ reflections              │
└──────────┬──────────────┘
           ↓
  Observations + Reflections
  injected into system prompt
  (prompt-cacheable!)

Key Design Decisions

DecisionWhy
No vector DBObservations are text, injected directly into prompt. Simpler infrastructure
Cache-friendlyFull cache hits on every turn until next observation run. Major cost savings
Two-stage compressionObserver (raw → observations) + Reflector (observations → reflections). Progressive abstraction
5-40x compressionA 50-message conversation becomes 2-3 observation paragraphs

Benchmark

94.87% on LongMemEval — competitive with Mem0 and Letta while requiring zero additional infrastructure (no vector DB, no graph DB).

Comparison with Other Memory Approaches

MastraMem0LettaClaude Code
ApproachBackground agent compressionLLM extraction → vector + graphThree-tier (Core/Recall/Archival)7-layer + autoDream
InfrastructureNone (text in prompt)Vector DB + optional graph DBVector DB + agent runtimeFile-based (MEMORY.md)
LongMemEval94.87%~90%~92%N/A
LanguageTypeScriptPython + JSPythonTypeScript (internal)
Cache-friendlyYes (designed for it)NoNoPartially (MEMORY.md)

When to Use Mastra

ScenarioUse Mastra?
TypeScript / Next.js stackYes — native ecosystem
Need memory without extra infrastructureYes — no vector DB needed
Python stackNo → use LangGraph or Letta
Need graph-based memory (entity relationships)No → use Mem0
Need maximum framework flexibilityMaybe → LangGraph is more flexible
Building a product on VercelYes — natural fit

Sources