Skip to content
prod e051e98
Browse

Mastra

AI Engine · Handbook

Mastra is an open-source TypeScript framework for building AI agents and agentic applications. It gives you batteries-included primitives — agents, tools, workflows, memory, RAG, evals, and observability — on top of the Vercel AI SDK, so you get a consistent, provider-agnostic way to ship AI features without re-inventing the runtime each time.

The Mastra handbook path

The Mastra handbook path 1. Concepts (the vocabulary) → 2. Architecture (how it fits) → 3. Agents (build one) → 4. Workflows (orchestrate) → 5. Deployment (ship it) Concepts the vocabulary Architecture how it fits Agents build one Workflows orchestrate Deployment ship it
Vocabulary first (Concepts), then how it fits together (Architecture), then hands-on (Agents → Workflows), then shipping it (Deployment).

Mastra centers on one runtime — a single Mastra instance that you register your agents, tools, and workflows on. Your app (a server route, a job, a CLI) talks to that runtime; the runtime owns execution, memory, and telemetry. The golden rule that the architecture enforces:

Routes call the runtime. The runtime calls everything else. A route should never import a workflow step or a tool directly — it asks the Mastra instance, which owns the wiring.

Mastra runtime ownership

Runtime ownership diagram Server routes call a single runtime. The runtime coordinates workflows, agents, tools, storage, and observability. A red dashed line shows the anti-pattern where routes bypass the runtime and import step functions directly. User Prompt editor · chat · live cards Server Route auth · workspace · credits Runtime Registry brain: knows every part runManager commands Workflows steps · checkpoints Agents orchestrator + workers Tools search · image · validate Storage + DB snapshots · events · ledger Observability Langfuse · logs · cost
Press Play flow to walk a prompt from the server route, through the central Mastra runtime, out to the agent / workflow / tools / storage, and back. Runtime authority Anti-pattern — bypasses the runtime
PrimitiveWhat it isWhy it exists
Mastra instanceThe central runtime + registry.One place owns config, agents, workflows, storage, telemetry.
AgentsAn LLM + instructions + tools + memory.The unit that reasons and decides which tools to call.
ToolsTyped functions an agent (or workflow) can call.Give the model real capabilities, with schema-validated I/O.
WorkflowsGraph of steps with branching, parallelism, suspend/resume.Deterministic, durable orchestration around the non-deterministic model.
MemoryWorking + recall (semantic) memory across threads.Agents remember context within and across conversations.
RAGChunk → embed → store → retrieve pipeline.Ground answers in your own documents.
VoiceUnified TTS / STT / speech-to-speech.Let agents speak and listen, provider-agnostic.
Scorers / EvalsAutomated quality checks on agent output.Measure quality instead of vibe-checking.
ObservabilityOpenTelemetry traces + integrations.See every model call, tool call, and step in production.
Multi-agentSupervisor agent delegating to specialists.Split big problems across coordinated agents.
MCPClient + server for the Model Context Protocol.Consume external tools, or expose yours to other agents.

Each primitive is named on the Concepts page and gets a hands-on deep-dive of its own — follow the links above or the path below.

Good fit

  • You’re in the TypeScript/Node ecosystem and want one framework instead of gluing libraries together.
  • You need agents + deterministic workflows (multi-step, branching, human-in-the-loop), not just one-shot completions.
  • You want memory, RAG, eval, and tracing to come from the same place, provider-agnostic.

Maybe not

  • A single, stateless model call with no tools — the Vercel AI SDK alone may be enough.
  • A Python-first stack where the team is already invested in another framework.

Foundations

  • Concepts — define every primitive (the vocabulary).
  • Architecture — how a request flows and why the runtime owns it.

Build

  • Building agents — the minimal end-to-end agent.
  • Tools — the typed contract behind every action.
  • Workflows — steps, branching, and suspend/resume.

Deep dives

  • Memory — continuity within and across conversations.
  • RAG — ground answers in your own documents.
  • Multi-agent systems — supervisor + specialists.
  • Evals & scorers — measure quality, not vibes.
  • Observability — trace every call in production.
  • MCP — interoperate with the wider ecosystem.

Ship