Best npm Packages for Building AI Agents 2026
TypeScript officially surpassed Python in GitHub's 2025 language report — and the JavaScript AI agent ecosystem has responded. In 2024, building a production AI agent in JavaScript meant stitching together low-level API calls. In 2026, there are at least five mature frameworks specifically designed for this use case, each with distinct architectural philosophies.
TL;DR
For most teams building AI agents in JavaScript or TypeScript, Mastra or Vercel AI SDK with tools is the right starting point in 2026. For complex multi-step agent orchestration with observability, LangGraph.js remains the most powerful option. @openai/agents is excellent if you're committed to the OpenAI ecosystem.
Key Takeaways
- Mastra (YC W25, Jan 2025) is the fastest-growing TypeScript-native agent framework with built-in RAG, tools, and observability
- Vercel AI SDK's
generateTextwithtoolsoption handles 80% of agent use cases with minimal setup - LangGraph.js powers enterprise-scale multi-agent workflows with persistent state and human-in-the-loop
- @openai/agents (OpenAI's official TypeScript SDK) supports Swarm-style handoffs, guardrails, and voice agents
- Microsoft retired AutoGen in favor of the unified Microsoft Agent Framework (GA Q1 2026)
- LangGraph handles 34.5M monthly downloads across its ecosystem
- TypeScript-first frameworks offer full type inference from tool definitions to return types
The Agent Framework Landscape in 2026
The definition of an "AI agent" has standardized: it's an LLM that can use tools, maintain state across steps, call other agents, and (optionally) pause for human review. The npm ecosystem now has mature solutions for each part of this definition.
What's changed since 2024: the frameworks have converged on a common pattern (define tools, define agent, run loop), but diverged sharply on orchestration complexity, observability, and framework integration.
1. Vercel AI SDK — Tools and Agents
Package: ai + @ai-sdk/openai (or any provider)
Weekly downloads: ~2.8M
GitHub stars: ~38K
Best for: Agents that need tight React/Next.js integration
AI SDK doesn't market itself as an "agent framework" but its generateText with the tools option is genuinely capable of agentic behavior:
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';
import { tool } from 'ai';
const result = await generateText({
model: openai('gpt-4o'),
tools: {
getWeather: tool({
description: 'Get weather for a location',
parameters: z.object({ location: z.string() }),
execute: async ({ location }) => {
return await fetchWeather(location);
},
}),
searchWeb: tool({
description: 'Search the web',
parameters: z.object({ query: z.string() }),
execute: async ({ query }) => searchWeb(query),
}),
},
maxSteps: 10, // Allow multi-step reasoning
prompt: 'What is the weather in NYC and find me 3 recent news articles about it?',
});
maxSteps is the key: it lets the model call tools, observe results, and decide next steps — a basic agent loop with no extra framework needed.
Limitations: No persistent state between calls, no built-in observability, no multi-agent handoffs.
2. Mastra — TypeScript-Native Agent Framework
Package: @mastra/core
GitHub stars: ~12K
Backed by: YC W25 (from the team behind Gatsby)
Best for: Full production agent systems with observability
Mastra is the most exciting newcomer. It launched in January 2025 and rapidly became the go-to for teams that want a batteries-included TypeScript agent framework:
import { Mastra, Agent } from '@mastra/core';
import { OpenAI } from '@mastra/openai';
const mastra = new Mastra({
llm: new OpenAI({ model: 'gpt-4o' }),
});
const agent = mastra.createAgent({
name: 'Research Assistant',
instructions: 'You are a thorough research assistant.',
tools: {
webSearch: webSearchTool,
readFile: readFileTool,
saveNote: saveNoteTool,
},
});
const result = await agent.generate('Research the current state of quantum computing');
Mastra includes:
- Built-in RAG: Document ingestion, chunking, embedding, and retrieval out of the box
- Workflows: Durable, resumable multi-step workflows with branching
- Memory: Persistent agent memory across sessions
- Observability: OpenTelemetry tracing built in
- Evals: Automated evaluation of agent outputs
This is close to a full agent platform, not just a library.
3. LangGraph.js — Stateful Multi-Agent Orchestration
Package: @langchain/langgraph
Monthly downloads (ecosystem): 34.5M
GitHub stars: 8K+ (JS repo)
Best for: Complex, stateful, multi-agent workflows
LangGraph is the most powerful option for sophisticated agent architectures. It models agents as state machines — nodes are functions, edges are transitions, and the graph can cycle (unlike a simple chain):
import { StateGraph, END } from '@langchain/langgraph';
import { Annotation } from '@langchain/langgraph';
const AgentState = Annotation.Root({
messages: Annotation<BaseMessage[]>({
reducer: (x, y) => x.concat(y),
}),
plan: Annotation<string | null>(),
documents: Annotation<Document[]>(),
});
const workflow = new StateGraph(AgentState)
.addNode('planner', plannerNode)
.addNode('researcher', researcherNode)
.addNode('writer', writerNode)
.addNode('reviewer', reviewerNode)
.addConditionalEdges('reviewer', shouldRevise, {
revise: 'writer',
done: END,
})
.setEntryPoint('planner');
// Persistent checkpointing
const app = workflow.compile({
checkpointer: new SqliteSaver(db),
});
Key LangGraph features:
- Cycles: Agents can loop until a condition is met
- Parallel branches: Multiple agents run simultaneously
- Checkpointing: Pause and resume workflows
- Human-in-the-loop: Interrupt for human approval mid-workflow
- Multi-agent: Supervisor agents that delegate to subagents
LangSmith (LangChain's observability platform) integrates natively.
4. @openai/agents — OpenAI's Official TypeScript Agent SDK
Package: @openai/agents
GitHub: openai/openai-agents-js
Best for: OpenAI-committed teams, voice agents, Swarm-style handoffs
OpenAI released their official TypeScript Agents SDK (the production successor to the Swarm experiment) in 2025:
import { Agent, run } from '@openai/agents';
const triageAgent = new Agent({
name: 'Triage Agent',
instructions: 'Determine which specialist should handle the request',
handoffs: [billingAgent, technicalAgent, generalAgent],
});
const result = await run(triageAgent, 'My invoice shows a wrong amount');
// Automatically hands off to billingAgent based on context
Notable features:
- Handoffs: Agents delegate to other agents with full context transfer
- Guardrails: Input/output validation as first-class primitives
- Voice agents: Built-in support for real-time voice with interruption detection
- Tracing: OpenAI's built-in tracing dashboard
The SDK is deliberately minimal — less magic, more control. It's a good fit for teams already using the OpenAI SDK and wanting structured multi-agent patterns without a full framework.
5. Google GenAI SDK — Gemini Agents
Package: @google/genai
GitHub stars: 5K+
Best for: Gemini models, Google Cloud workloads
Google's unified GenAI SDK (released 2025, replacing @google/generative-ai) supports agent patterns with Gemini:
import { GoogleGenAI } from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const response = await ai.models.generateContent({
model: 'gemini-2.0-flash',
contents: 'What is the weather in London?',
tools: [{ googleSearch: {} }, { codeExecution: {} }],
});
Gemini's built-in Google Search grounding is unique — no custom search tool setup required.
6. Microsoft Agent Framework (formerly AutoGen)
Package: @microsoft/agents (preview)
Status: GA targeted Q1 2026
Note: AutoGen is now maintenance-only
Microsoft merged AutoGen and Semantic Kernel into a unified framework in October 2025. The new Microsoft Agent Framework emphasizes enterprise concerns: Azure integration, compliance, and multi-model support. Still in preview as of March 2026.
Comparison Table
| Framework | Focus | Complexity | Observability | Edge Support | Persistent State |
|---|---|---|---|---|---|
| Vercel AI SDK | UI-first | Low | None | Yes | No |
| Mastra | Full platform | Medium | Built-in | Partial | Yes |
| LangGraph.js | Orchestration | High | LangSmith | No | Yes |
| @openai/agents | Handoffs | Low-Medium | OpenAI Traces | No | No |
| Google GenAI | Gemini-first | Low | Google Cloud | Partial | No |
| Microsoft Agent | Enterprise | High | Azure Monitor | Partial | Yes |
Architectural Patterns
Pattern 1: ReAct Loop (Reason + Act)
Best implemented with: Vercel AI SDK (maxSteps), @openai/agents
Think → Act (call tool) → Observe → Think → ... → Respond
Pattern 2: Plan and Execute
Best implemented with: Mastra workflows, LangGraph
Plan → Step 1 → Step 2 → Step 3 → Synthesize → Respond
Pattern 3: Multi-Agent Supervisor
Best implemented with: LangGraph (supervisor pattern), @openai/agents (handoffs)
Supervisor → Route to Specialist A or B → Collect results → Synthesize
Pattern 4: Retrieval-Augmented Generation (RAG)
Best implemented with: Mastra (built-in), LangChain.js
Query → Embed → Retrieve → Augment prompt → Generate
Choosing the Right Package
Choose Vercel AI SDK tools if:
- You're in a React/Next.js app
- Your agent logic is relatively simple (< 5 tools, < 10 steps)
- You don't need persistent state between calls
- Edge runtime support is required
Choose Mastra if:
- You want a batteries-included TypeScript agent platform
- You need built-in RAG, memory, and observability
- You're building a production system and don't want to assemble pieces yourself
- Your team is new to agent development
Choose LangGraph.js if:
- You need complex state machines with cycles
- Human-in-the-loop is a hard requirement
- Multi-agent coordination with parallel branches is needed
- You want LangSmith observability
Choose @openai/agents if:
- You're already on the OpenAI SDK
- Swarm-style agent handoffs match your architecture
- Voice agent support is needed
- You want minimal abstraction
Essential Supporting Packages
No matter which framework you choose, these packages are almost always needed:
# Vector stores for RAG
npm install @pinecone-database/pinecone # Cloud vector store
npm install chromadb # Local vector store
# Embeddings
npm install @xenova/transformers # Local embeddings
# Document processing
npm install @langchain/community # 50+ document loaders
# Observability
npm install @opentelemetry/sdk-node # OpenTelemetry
npm install langsmith # LangChain observability
The Future of JavaScript Agents
The trend in 2026 is toward model-native tools (models that can search, execute code, browse the web without external tool setup) and durable workflows (agents that can pause, sleep, and resume). Mastra and LangGraph are ahead on durability; Google Gemini and OpenAI GPT-4o are ahead on built-in tools.
Watch for: TypeScript-first evaluation frameworks, standardized agent protocols (A2A — Agent-to-Agent), and tighter MCP (Model Context Protocol) integration across all frameworks.
Explore More on PkgPulse
Compare download trends, bundle sizes, and release frequency for all these packages on PkgPulse.
See the live comparison
View best npm packages ai agents on PkgPulse →