Last updated October 24, 2026. We installed all three frameworks that day, ran the same TypeScript agent job in each with every model request captured, and checked releases, downloads, docs, and pricing on GitHub, npm, and each vendor’s site.
Mastra vs Vercel AI SDK vs LangGraph is a choice between three layers of the same stack: a lean toolkit, a batteries included framework, and a durable graph runtime. All three run agents in TypeScript and all three are free and open source, so the real differences show up in defaults, memory, approvals, and what survives a restart.
This comparison sits in our agent frameworks hub, and our guide to the 12 best AI agent frameworks covers Python options such as CrewAI and Pydantic AI. Here we stay in TypeScript and show what each framework does when a model misbehaves, when a user comes back for a second turn, and when a tool call waits for a human.
On October 24, 2026 we installed each framework on Node.js 22 and ran one identical job five times per setting against a scripted local model, saving every request body. No vendor paid for placement or reviewed this page, per our editorial standards and disclosure policy.
TL;DR
- Pick the Vercel AI SDK for lean agents inside web apps. It was the smallest install at 12 packages and 29 MB, imported in 69 ms, and has 19.8 million weekly npm downloads.
- Pick Mastra for a full TypeScript agent stack. Memory, storage, workflows, evals, and a dev studio come in one framework, and memory with LibSQL kept tool history across turns in our test.
- Pick LangGraph.js for long running, approval heavy agents. Its checkpointers let a paused tool call resume in a new process, as long as you use a durable saver.
- Runaway loops end very differently. The AI SDK stopped after 20 model calls, LangGraph threw an error after 13, and Mastra stopped silently after 5.
- None of the three remembers by default. Every framework forgot turn one until we passed messages, added Mastra Memory, or added a LangGraph checkpointer.
- MemorySaver is a trap in production. After a restart, LangGraph resumed with an empty state and no error, and the approved tool never ran.
Mastra vs Vercel AI SDK vs LangGraph.js at a Glance
The Vercel AI SDK gives you primitives, Mastra gives you a framework built on those primitives, and LangGraph.js gives you a stateful graph runtime with checkpoints. The table compares fit, defaults, footprint, and adoption, using each project’s repository, npm, docs, and our own test on October 24, 2026.
| Framework | Best for | Runaway loop default | Memory and resume | Install, our test | Weekly npm downloads |
|---|---|---|---|---|---|
| Vercel AI SDK | Agents inside Next.js, React, and Node apps | Stops at 20 steps with a warning | You store messages yourself | 12 packages, 29 MB | 19,759,232 (ai) |
| Mastra | Full agent apps with memory, workflows, and a studio | Stops at 5 steps, no warning | Memory plus a storage adapter | 149 packages, 158 MB (core) | 1,442,185 (@mastra/core) |
| LangGraph.js | Durable agents with human approval and long runs | Throws at 25 graph steps | Checkpointer per thread_id | 25 packages, 115 MB (with langchain) | 2,326,897 (@langchain/langgraph) |
Verdict: Start with the AI SDK when the agent lives inside a web app and you want full control. Choose Mastra when you want memory, workflows, and tooling decided for you, and choose LangGraph.js when an agent must pause for people and pick up exactly where it stopped.

How We Tested the Three Frameworks
To compare the frameworks on equal terms, we built the same job in each: a pricing assistant calls one get_price tool with a Zod schema, then answers in one line. Every framework pointed at a local server that played the model’s part with fixed replies, so runs were offline, free, and repeatable, and every request body was saved.
- Same agent API where possible:
ToolLoopAgentfromai7.0.152,Agentfrom@mastra/core1.79.0, andcreateAgentfromlangchain1.5.19, which runs on@langchain/langgraph1.5.2. - Five scenarios, five runs each: a normal tool job, a runaway loop where the model never stops calling the tool, a two turn memory check, a tool that needs human approval, and an approval that waits across a process restart.
- Network check: a Node.js preload logged every outbound connection and refused anything that was not local, and no run tried to reach an outside host.
- Install and health: package counts from
package-lock.json, disk size ofnode_modules, median cold import time,npm audit, and release, download, and star counts checked the same day.
What Our October 24 Hands-On Test Found
All three frameworks finished the normal tool job in 2 model calls in 5 of 5 runs, so the differences only appeared when something went wrong. The AI SDK and Mastra sent 1,447 request bytes in total and LangGraph sent 1,527. Median wall time was 0.16 seconds for the AI SDK, 0.43 for LangGraph, and 0.59 for Mastra.
- Runaway loop: the AI SDK made 20 model calls and 60,350 request bytes, then returned empty text with a console warning about its default
isStepCount(20)stop condition. - Runaway loop, Mastra: 5 model calls and 5,525 bytes, then empty text with a
tool-callsfinish reason and no warning at all. - Runaway loop, LangGraph: 13 model calls and 12 tool runs, then a thrown
GraphRecursionErroronce the run hit the default limit of 25 graph steps. - Plain
generateText: withoutstopWhen, the AI SDK stopped after 1 step, ran the tool, and returned no text, so useToolLoopAgentor set a stop condition for agents. - Network: 0 outside connections across every run of every framework.
A silent stop is the hardest failure to catch, because the caller gets an empty answer that looks like a normal result. Check finishReason on every Mastra and AI SDK result, and catch GraphRecursionError in LangGraph, then log both to one of the AI agent observability tools we tested.

Memory was the second big difference. With defaults, all three sent only 2 messages on the second turn and could not recall the customer reference from turn one. With memory switched on, all three recalled it, but they carried different amounts of history.
- Vercel AI SDK: we appended
response.messagesfrom turn one and sent 4 messages and 752 bytes. In our run those response messages held only the final text, so the tool call history was dropped. - Mastra:
Memorywith aLibSQLStorefile, a thread, and a resource sent 6 messages and 1,007 bytes, including the earlier tool call and result. - LangGraph.js: a
MemorySavercheckpointer with athread_idsent 6 messages and 1,078 bytes, also with the full tool history.
1. Vercel AI SDK: Best for Lean Agents Inside Web Apps

The Vercel AI SDK is a provider agnostic TypeScript toolkit for AI apps and agents, and it is the most downloaded of the three by a wide margin. Version 7.0.152 of the ai package shipped on October 23, 2026, after 650 stable releases in 12 months. The repository has 27,490 stars and npm counted 19,759,232 downloads in the week of October 16 to 22.
The agent docs center on ToolLoopAgent, which calls the model, runs tools, and loops until a stop condition. The loop control docs say it stops after 20 steps by default using isStepCount(20), which matched our test exactly. UI hooks for React, Svelte, and Vue make it the natural fit for chat inside a Next.js app.

The AI SDK leaves state to you: there is no built in memory store or checkpointer, so persistence is your code and your database. Tool approvals worked in our test with the needsApproval flag, and the tools docs now mark that flag deprecated in favor of a toolApproval setting on ToolLoopAgent. Its README also notes that plain model strings route through the Vercel AI Gateway by default, so pass a provider object if you want direct calls.
- Best for: TypeScript teams building agents into Next.js, React, or Node apps who want small dependencies and full control.
- Pricing (October 2026): free under Apache 2.0. You pay for model usage and any Vercel hosting or AI Gateway usage you choose.
- Watch out for: a very fast release pace, and memory, persistence, and approval storage that you must build and test yourself.
2. Mastra: Best for a Full TypeScript Agent Framework

Mastra is an open source TypeScript framework for agents and workflows that bundles memory, storage, evals, tracing, and a local studio in one package family. Version 1.79.0 of @mastra/core shipped on October 21, 2026, after 106 stable releases in 12 months. The repository has 29,041 stars, the most of the three, and npm counted 1,442,185 weekly downloads.
Mastra builds on AI SDK provider packages, so in our test the same @ai-sdk/openai model object worked in both frameworks. That makes moving from the AI SDK to Mastra a small step when an app outgrows plain primitives. The code is Apache 2.0, except for folders named ee that fall under the Mastra enterprise license.

Mastra stops an agent after 5 steps by default, and in our runaway test it returned empty text with no warning. The generate reference documents that default, so set maxSteps for agents that need longer tool chains and check finishReason on every call. The cap kept our runaway job to 5,525 bytes, the cheapest failure of the three.

Approvals use requireApproval: true on a tool, which returns a suspended finish reason, and approveToolCallGenerate resumes the run. The human in the loop docs warn that snapshots need a storage provider on the Mastra instance. Our restart test confirmed it: with a LibSQL file the approval resumed in a new process, and without storage it threw a MastraError saying it could not find the suspended run.
- Best for: TypeScript teams that want memory, workflows, evals, and a dev studio decided for them in one framework.
- Pricing (October 2026): free under Apache 2.0 outside the enterprise folders. Mastra Platform Starter is $0 with metered usage, Teams is $250 per month, and Enterprise is custom.
- Watch out for: the heaviest install in our test at 158 MB for core and 202 MB with memory and LibSQL, plus a silent stop at 5 steps.
3. LangGraph.js: Best for Durable, Approval Heavy Agents

LangGraph.js is a low level orchestration framework for stateful agents, with checkpoints, interrupts, and durable execution at its core. Version 1.5.2 of @langchain/langgraph shipped on October 21, 2026, after 59 stable releases in 12 months. The repository has 3,370 stars, far fewer than the Python project, but npm counted 2,326,897 weekly downloads.
Most teams start with createAgent from the langchain package, covered in the agent docs, and it builds a LangGraph graph under the hood. Drop to StateGraph when you need custom nodes, branches, or several agents in one graph. The default recursion limit of 25 graph steps covers both, and hitting it throws an error that the caller sees.

LangGraph had the best restart story and the worst trap: SqliteSaver resumed a paused approval in a new process, while MemorySaver returned an empty state with no error. The persistence docs say MemorySaver keeps checkpoints in RAM and loses them on restart, and recommend PostgresSaver or SqliteSaver. Approvals come from humanInTheLoopMiddleware in the human in the loop docs, which returns an __interrupt__ and resumes on a Command with the same thread_id.
- Best for: teams building long running agents that pause for people, retry after crashes, or need time travel over past states.
- Pricing (October 2026): free under MIT. LangSmith Developer is $0 for 1 seat, Plus is $39 per seat per month, and Enterprise is custom.
- Watch out for: a two package setup with
langchainon top of LangGraph, and in memory checkpointers that fail silently after a restart.
Human Approval and Restarts Compared
In all three frameworks the tool ran 0 times before approval, so the approval gate itself held in every run. The difference is where the pending state lives. We started each approval, ended the Node.js process, then approved it from a fresh process, five times per setup.

| Framework | How to pause | How to resume | Restart with persistence | Restart without it |
|---|---|---|---|---|
| Vercel AI SDK | needsApproval or toolApproval returns a tool-approval-request | Send messages back with a tool-approval-response part | Resumed, using messages we saved to JSON | Nothing to resume unless your code saved it |
| Mastra | requireApproval: true returns suspended | approveToolCallGenerate({ runId, toolCallId }) | Resumed with LibSQL file storage | Threw MastraError |
| LangGraph.js | humanInTheLoopMiddleware returns __interrupt__ | Command with an approve decision on the same thread_id | Resumed with SqliteSaver | Empty state, 0 messages, no error |
This is the LangGraph.js version of our restart test, the pattern we would ship. Swap the SQLite file for PostgresSaver when several servers share approvals.
import { createAgent, tool, humanInTheLoopMiddleware } from "langchain";
import { Command } from "@langchain/langgraph";
import { SqliteSaver } from "@langchain/langgraph-checkpoint-sqlite";
import { z } from "zod";
const getPrice = tool(async ({ sku }) => `${sku}: 42 dollars`, {
name: "get_price",
description: "Look up the price of a product by SKU.",
schema: z.object({ sku: z.string() }),
});
const agent = createAgent({
model: "openai:gpt-5-mini",
tools: [getPrice],
checkpointer: SqliteSaver.fromConnString("./approvals.db"),
middleware: [humanInTheLoopMiddleware({ interruptOn: { get_price: true } })],
});
const config = { configurable: { thread_id: "order-qx61" } };
await agent.invoke({ messages: [{ role: "user", content: "Price for ACME-1?" }] }, config);
// Later, even from a new process:
await agent.invoke(new Command({ resume: { decisions: [{ type: "approve" }] } }), config);
The Mastra version needs one line of setup: register the agent on a Mastra instance with a storage adapter, then keep the runId and toolCallId from the suspended result. Put approvals for sensitive tools behind the controls in our AI agent security tools guide.
import { Mastra } from "@mastra/core";
import { LibSQLStore } from "@mastra/libsql";
new Mastra({ agents: { pricing: agent }, storage: new LibSQLStore({ id: "approvals", url: "file:./approvals.db" }) });
const first = await agent.generate("Price for ACME-1?");
if (first.finishReason === "suspended") {
const pending = { runId: first.runId, toolCallId: first.suspendPayload?.toolCallId };
// Save pending, then after approval:
await agent.approveToolCallGenerate(pending);
}
Install Size, Speed, and Adoption Compared
The AI SDK is the lightest by far, while Mastra brings the most code because it ships the most features. The chart shows node_modules size and package count after clean installs on October 24, 2026, and the table adds import time, downloads, and release pace.

| Framework | Packages, our install | Median import time | Stable releases, last 12 months | Weekly npm downloads | GitHub stars | License |
|---|---|---|---|---|---|---|
| Vercel AI SDK | 12 | 69 ms (ai) | 650 | 19,759,232 | 27,490 | Apache 2.0 |
| Mastra | 149 core, 185 with memory | 411 ms (@mastra/core/agent) | 106 | 1,442,185 | 29,041 | Apache 2.0, enterprise folders excepted |
| LangGraph.js | 24, or 25 with langchain | 225 ms (langgraph), 259 ms (langchain) | 59 | 2,326,897 | 3,370 | MIT |
npm audit reported 0 vulnerabilities in all five installs. Download counts favor the AI SDK partly because Mastra and other tools pull its packages in as dependencies, so treat raw npm numbers as a reach signal. Track model spend across whichever you pick with our LLM cost monitoring tools picks.
What Each Option Costs in October 2026
All three frameworks are free and open source, so cost comes from models, hosting, and the optional platforms each company sells. Pricing below comes from each vendor’s pricing page on October 24, 2026, and every figure excludes the model tokens you pay your provider for.
- Vercel AI SDK: free. Costs come from your model provider, plus Vercel hosting and AI Gateway usage if you choose them, which our Cloudflare vs Vercel vs AgentCore comparison covers.
- Mastra Platform: Starter is $0 with 100K observability events and 24 CPU hours included, then $10 per 100K events and $0.35 per CPU hour. Teams is $250 per month, persistent servers are $100 per project, and the gateway bills at market rate plus 5.5%.
- LangSmith for LangGraph: Developer is $0 for 1 seat and 5K base traces. Plus is $39 per seat per month with 10K traces and one free small deployment, and Enterprise is custom.
You do not need either platform to run the frameworks in production. Our LangSmith alternatives and Langfuse vs LangSmith vs Braintrust comparisons cover tracing options that work with all three.
Mastra, Vercel AI SDK, or LangGraph.js: Which Should You Choose?
The right answer depends on where the agent runs, how long a task lasts, and whether people approve actions in the middle. Match your team to a profile below, then rerun our five scenarios on your own job with request bodies logged before you commit.
Teams adding an agent to a web app
- Start with the Vercel AI SDK and
ToolLoopAgent, and setstopWhento fit your longest tool chain. - Store messages in your own database, including tool calls, so turn two keeps full context.
- Put one of the LLM gateways we reviewed in front of model calls for keys, limits, and fallbacks.
Teams building a full agent product in TypeScript
- Pick Mastra and register every agent on a
Mastrainstance with real storage from day one. - Raise
maxStepsabove 5 for multi tool tasks and alert on empty results. - Version prompts with the prompt management tools we compared.
Teams with long running or approval heavy agents
- Pick LangGraph.js with PostgresSaver or SqliteSaver, never MemorySaver, outside local tests.
- Catch
GraphRecursionErrorand setrecursionLimitper task type. - Score agent runs with the AI agent evaluation tools and AI agent testing tools we reviewed.
Teams connecting many external tools
- Expose tools over the Model Context Protocol so they move with you if you switch frameworks.
- Pick ready made servers from our MCP servers guide and lock them down with MCP security tools.
- Require approval on any tool that writes data or spends money, in whichever framework you choose.
Frequently Asked Questions
Is Mastra built on the Vercel AI SDK?
Mastra builds on AI SDK provider packages, so model objects from packages such as @ai-sdk/openai work in Mastra agents, as they did in our test. Mastra then adds its own agent class, memory, storage, workflows, evals, and studio on top. Teams often start with the AI SDK and move to Mastra when they need those pieces.
Which is better for TypeScript agents, Mastra or LangGraph.js?
Mastra is better when you want one framework with memory, workflows, and tooling included, and it installed and ran a normal job just as reliably in our test. LangGraph.js is better for long running agents that pause for human approval, because its checkpointers resumed a paused approval in a new process with SQLite storage.
Does the Vercel AI SDK have memory?
The AI SDK has no built in memory store, so an agent forgets earlier turns unless you pass previous messages back. In our test it recalled turn one once we appended the response messages, but those held only the final text and dropped the tool history. Save full message history in your own database for production.
What happens when an agent gets stuck in a tool loop?
Each framework stops it differently by default. In our test the AI SDK stopped after 20 model calls with a console warning, Mastra stopped after 5 calls with empty text and no warning, and LangGraph.js threw a GraphRecursionError after 13 calls. Set explicit limits and check finish reasons in every framework.
Can I use LangGraph.js without LangChain?
Yes. The @langchain/langgraph package runs on its own with @langchain/core, and you can build agents directly with StateGraph, nodes, and edges. The createAgent helper and humanInTheLoopMiddleware live in the langchain package, which adds about 5 MB to the install in our test, so most teams install both for faster setup.
Related Guides
Python teams replacing CrewAI face a different shortlist from the TypeScript one above. Our CrewAI alternatives comparison tests LangGraph, the OpenAI Agents SDK, Pydantic AI and five more for production crews.
For related coverage, see our LangGraph vs CrewAI vs AutoGen comparison, OpenAI Agents SDK vs Claude Agent SDK vs Google ADK comparison, LangGraph alternatives ranking, LangChain vs LangGraph vs Deep Agents comparison, open source AI agent frameworks you can self-host, multi-agent frameworks test, TypeScript AI agent frameworks ranking and Microsoft Agent Framework vs Semantic Kernel vs AutoGen comparison.
Read the agent frameworks hub, 12 best AI agent frameworks, AgentOps hub, agent observability coverage, AI agent observability tools, open source LLM observability, AI agent evaluation tools, AI agent testing tools, prompt management tools, LLM cost monitoring tools, LLM gateways, agent security hub, AI agent security tools, MCP explained, MCP servers, and MCP security tools. Notes on how we work sit on editorial standards, disclosure, and contact.
The Bottom Line
Choose the Vercel AI SDK for lean agents in web apps, Mastra for a complete TypeScript agent framework, and LangGraph.js for durable agents that wait on people. The biggest finding in Mastra vs Vercel AI SDK vs LangGraph was failure behavior, so test runaway loops, second turns, and restarts before you ship.
All three ship new versions weekly or faster, so rerun a logged test after each upgrade and check this page for updates. Send corrections or your own results through our contact page.

