The TypeScript Agent Framework
From the team that brought you Gatsby: prototype and productionize AI features with a modern Javascript stack.
1const chefAgent = new Agent({2name: 'Chef Agent',3instructions:4"You are Michel, a practical and experienced home chef" +5"who helps people cook great meals."6model: openai('gpt-4o-mini'),7memory,8workflow: { chefWorkflow }9});
/workflows
*ops
/agents
/rag
Loved by builders
/agents
Build intelligent agents that execute tasks, access knowledge bases, and maintain
memory persistently within threads.
1const chefAgent = new Agent({2name: 'Chef Agent',3instructions:4"You are Michel, a practical and experienced home chef" +5"who helps people cook great meals."6model: openai('gpt-4o-mini'),7memory,8workflow: { chefWorkflow }9});
Switch between AI providers by changing a single line of code using the AI SDK
Combine long-term memory with recent messages for more robust agent recall
Bootstrap, iterate, and eval prompts in a local playground with LLM assistance.
Allow agents to call your functions, interact with other systems, and trigger real-world actions
/workflows
Durable graph-based state machines with built-in tracing, designed to execute complex
sequences of LLM operations.
1workflow2.step(llm)3.then(decider)4.after(decider)5.step(success)6.step(retry)7.after([8success,9retry10])11.step(finalize)12.commit();
.step()
llm
.then()
decider
when:
.then()
success
when:
.then()
retry
.after()
finalize

Simple semantics for branching, chaining, merging, and conditional execution, built on XState.
Pause execution at any step, persist state, and continue when triggered by a human-in-the-loop.
Stream step completion events to users for visibility into long-running tasks.
Create flexible architectures: embed your agents in a workflow; pass workflows as tools to your agents.
*rag
Equip agents with the right context. Sync data from SaaS tools. Scrape the web.
Pipe it into a knowledge base and embed, query, and rerank.
*ops
Track inputs and outputs for every step of every workflow run. See each agent tool call
and decision. Measure context, output, and accuracy in evals, or write your own.
Measure and track accuracy, relevance, token costs, latency, and other metrics.
Test agent and workflow outputs using rule-based and statistical evaluation methods.
Agents emit OpenTelemetry traces for faster debugging and application performance monitoring.
Dive deeper, build smarter
Building a Web Browsing Agent with Mastra and Stagehand
See how we built a web browsing agent using Mastra and Stagehand. Learn about the tools needed to allow your agents to control a browser.Shane Thomas
Apr 23, 2025
Announcing MCP Server Support in Mastra
Create and share your AI tools with the Model Context Protocol (MCP) - now available in our latest canary release.Nik Aiyer
Apr 21, 2025
AI Engineering with JavaScript in 2025
A dive into four leading open-source JS AI libraries: Vercel's AI SDK for model routing, Mastra for agents and workflows, Langfuse for observability, and Stagehand for web automation.Sam Bhagwat
Apr 20, 2025
Choosing a JavaScript Agent Framework
When choosing a JavaScript agent framework, consider the needs of your project and the team's expertise. Mastra and LangGraph.js are two leading options.Sam Bhagwat
Apr 20, 2025
Building a Personal Assistant with Mastra and MCP
How we built a personal assistant that can manage emails, monitor GitHub activity, schedule social media posts, and more - all through a Telegram interface.Shane Thomas
Apr 18, 2025