Mastra — TypeScript AI Agent Framework
AI agent framework for TypeScript from the Gatsby team. Build agents with tools, workflows, RAG, memory, evals, and 50+ integrations. Modern TS-native design. 22K+ stars.
Installation agent prête
Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.
npx -y tokrepo@latest install 59d6f322-d438-4ed3-ab97-ea580be76f48 --target codexÀ exécuter après confirmation du plan en dry-run.
What it is
Mastra is an open-source TypeScript framework for building AI agents. It provides a unified API for creating agents with tool use, retrieval-augmented generation (RAG), multi-step workflows, and integrations with third-party services. Unlike Python-centric agent frameworks, Mastra is designed from the ground up for the TypeScript/Node.js ecosystem.
The framework targets full-stack TypeScript developers who want to build AI-powered applications without switching to Python. It includes a CLI for project scaffolding (npx create-mastra@latest), a local development server, and built-in support for popular LLM providers (OpenAI, Anthropic, Google).
How it saves time or tokens
Mastra reduces the integration burden of building AI agents. Instead of wiring together separate libraries for LLM calls, vector search, tool execution, and workflow orchestration, Mastra provides all of these as first-class features in a single package. This eliminates dependency management overhead and ensures components work together without compatibility issues.
The built-in RAG support is particularly valuable. Mastra handles document chunking, embedding generation, vector storage, and retrieval within the same framework, so you do not need to set up a separate vector database pipeline. This saves both development time and the tokens that would be wasted on hallucinated answers without proper context retrieval.
How to use
- Create a new Mastra project:
```bash
npx create-mastra@latest my-agent
cd my-agent
npm run dev
```
- Or add to an existing project:
```bash
npm install mastra @mastra/core
```
- Define an agent with tools and start using it.
Example
A Mastra agent with a custom tool:
import { Agent, createTool } from '@mastra/core';
import { z } from 'zod';
const weatherTool = createTool({
id: 'get-weather',
description: 'Get current weather for a city',
inputSchema: z.object({
city: z.string().describe('City name'),
}),
execute: async ({ context }) => {
const resp = await fetch(
`https://wttr.in/${context.city}?format=j1`
);
const data = await resp.json();
return { temp: data.current_condition[0].temp_C };
},
});
const agent = new Agent({
name: 'WeatherBot',
instructions: 'Help users check weather conditions.',
model: { provider: 'ANTHROPIC', name: 'claude-sonnet-4-20250514' },
tools: { 'get-weather': weatherTool },
});
const response = await agent.generate(
'What is the weather in Tokyo?'
);
console.log(response.text);
Mastra core features:
| Feature | Description |
|---|---|
| Agent | LLM with instructions, tools, and memory |
| Tools | Type-safe tool definitions with Zod schemas |
| RAG | Built-in document chunking, embedding, and retrieval |
| Workflows | Multi-step agent pipelines with conditional logic |
| Integrations | Pre-built connectors for APIs and services |
| Dev Server | Local development server with playground UI |
Related on TokRepo
- AI Tools for Agents — Compare Mastra with other agent development frameworks.
- AI Tools for Coding — Browse coding tools in the TypeScript ecosystem.
Common pitfalls
- Expecting full parity with Python agent frameworks. Mastra is TypeScript-native, which means some Python-only libraries (LangChain integrations, certain vector stores) are not directly available. Check Mastra's integration list before assuming a specific service is supported.
- Not using Zod schemas for tool inputs. Mastra uses Zod for type-safe tool parameter validation. Defining tools without proper schemas leads to runtime errors when the LLM passes unexpected parameter types.
- Running the dev server in production. The
npm run devcommand starts a local development server with hot reloading and debugging features. For production, build the project and run the compiled output, or deploy to a serverless platform.
Questions fréquentes
Mastra is designed as a simpler, more opinionated framework specifically for building agents. LangChain.js is a broader toolkit with more building blocks and integration options. Mastra provides built-in RAG, tool use, and workflows in a cohesive package, while LangChain.js requires assembling these components from separate modules. Choose Mastra for a faster start; choose LangChain.js for maximum flexibility.
Mastra supports OpenAI, Anthropic (Claude), and Google (Gemini) as built-in providers. You can also configure custom providers that implement the OpenAI-compatible API format, which covers local models via Ollama or LM Studio. The provider is specified in the agent configuration.
Mastra includes built-in vector storage that works for development and small-scale production. For large-scale deployments, it integrates with external vector databases like Pinecone, Qdrant, and Chroma. The RAG pipeline (chunking, embedding, retrieval) works the same regardless of the storage backend.
Yes. Mastra is designed for the Node.js runtime and integrates well with Next.js API routes and server actions. You can define agents and tools in your Next.js backend and call them from the frontend. The framework handles server-side execution and streams responses to the client.
Yes. Mastra is designed for production use with proper error handling, streaming support, and observability. It can be deployed on any Node.js hosting platform (Vercel, Railway, AWS Lambda). The framework handles conversation state management and tool execution lifecycle for reliable production operation.
Sources citées (3)
- Mastra GitHub Repository— Mastra TypeScript AI agent framework
- Mastra Documentation— Mastra documentation and quickstart guide
- Mastra API Reference— Mastra agent and tool API reference
En lien sur TokRepo
Source et remerciements
Created by Mastra AI (from the Gatsby team). Licensed under MIT. mastra-ai/mastra — 22,000+ GitHub stars
Fil de discussion
Actifs similaires
Mastra — TypeScript AI Agent Toolkit
Production TypeScript framework for building AI agents with tool use, workflows, RAG, and memory. First-class MCP support. Deploy anywhere Node.js runs. 9,000+ GitHub stars.
Mastra Workflows — TypeScript Agent Orchestration
Mastra Workflows defines multi-step typed agent flows in TypeScript. Build pipelines with .then(), .branch(), .parallel(), .while(). End-to-end type-safe.
CAMEL — Multi-Agent Framework at Scale
CAMEL is a multi-agent framework for studying scaling laws of AI agents. 16.6K+ GitHub stars. Up to 1M agents, RAG, memory systems, data generation. Apache 2.0.
OpenAI Agents JS — TypeScript Multi-Agent SDK
OpenAI Agents JS brings multi-agent workflows to TypeScript with provider-agnostic runs, zod schemas, tracing hooks, and sandbox agent patterns.