OpenAI Agents SDK vs. LangGraph vs. Mastra
All three frameworks run the same model-and-tool loop. They differ in language, in how a run pauses and resumes, and in where its state lives, so test those before choosing.
5 min read / Updated / Last checked
- Format
- Comparison · Advanced
- Who it is for
- Builders and technical founders
- You leave with
- Choose an agent framework after a two-day bake-off that pauses, restarts and resumes the same approval-gated task in each candidate.
The problem
On October 22, 2025, LangChain released LangGraph 1.0 and committed to no breaking changes until version 2.0 [7]. Mastra shipped its own 1.0 on January 20, 2026 [10]. The OpenAI Agents SDK, the third common choice, is documented in Python and TypeScript with tracing, sessions, guardrails and human approval built in [1][4]. By late 2026 the question is no longer which of them works. All three do.
The question is fit, and founders usually answer it with the wrong evidence. A demo agent that answers one question and calls one tool looks about the same in all three. The differences show up when a run has to stop: a refund waits two hours for a manager, the server restarts in between, a tool times out halfway through, or a security review asks where prompts and tool arguments were sent. A production agent spends much of its life in those moments. Switching frameworks after the first customers arrive means rewriting the agent layer and migrating any paused runs.
This comparison describes each framework only as its own documentation describes it in November 2026, and ends with a bake-off a team can run in two days to see the differences on its own task.
How it works
All three frameworks wrap the same loop. The model reads instructions and messages and asks for a tool call. The framework runs the tool, feeds the result back, and repeats until the model gives a final answer. What differs is the unit you program in and what happens when the loop has to pause for a person.
OpenAI Agents SDK. You program agents: a model with instructions and tools. The documented primitives are few: agents, agents as tools or handoffs (one agent passing work to another), and guardrails that validate inputs and outputs [1]. A runner drives the loop. To pause, mark a tool needs_approval. The run then returns a list of interruptions. You convert the result to a RunState, approve or reject each item, and run again. The state serializes to a string so the decision can arrive hours later, and the documentation warns to load it only from trusted storage [2]. Tracing is on by default and records model calls, tool calls, handoffs and guardrails. Sensitive data is included in traces unless you switch it off, and tracing is unavailable to organizations under OpenAI's Zero Data Retention policy [3].
LangGraph. You program a graph: a typed state object, nodes that are plain functions, and edges between them. It calls itself a low-level orchestration framework and runtime for long-running, stateful agents, and it does not require LangChain [5]. A node calls interrupt() to pause. That needs a checkpointer (the component that saves state after each step) and a thread_id that names the run. You resume with Command(resume=...). The paused node then runs again from its first line, so any side effect before the interrupt must be safe to repeat [6].
Mastra. You program TypeScript agents, tools and workflows. A tool defined with requireApproval: true pauses the agent, the stream emits a tool-call-approval chunk, and your code answers with approveToolCall or declineToolCall. A storage provider is required, because the paused request is saved as a snapshot [8]. Workflows pause with suspend() and continue with resume(), and their snapshots persist across deployments and restarts [9].
The pause that separates the three frameworks
Fig. 01- Model asks for toolrefund, delete, send
- Run pausesinterruption, interrupt(), approval chunk
- State savedRunState, checkpointer, snapshot
- Person decidesminutes or hours later
- Run resumesthe tool runs once
By the numbers
- LangGraph 1.0 ships with a commitment to no breaking changes until 2.0 [7]
- Oct 2025
- monthly downloads across LangChain and LangGraph, as LangChain reported at 1.0 [7]
- 90 million
- weekly npm downloads Mastra reported at its 1.0 release in January 2026 [10]
- 300,000+
- core primitives in the OpenAI Agents SDK: agents, handoffs or agents as tools, guardrails [1]
- 3
| Question | OpenAI Agents SDK | LangGraph | Mastra |
|---|---|---|---|
| Languages | Python [1], TypeScript [4] | Python [6], JavaScript [5] | TypeScript [8][9] |
| What you program | Agents, handoffs, guardrails | A graph of nodes over typed state | Agents, tools, workflows |
| How a run pauses | needs_approval on a tool | interrupt() inside a node | requireApproval on a tool, suspend() in a step |
| Where paused state lives | A serialized RunState you store | A checkpointer, keyed by thread_id | A snapshot in configured storage |
| What resume re-runs | The run continues from the approval | The paused node, from its first line | The approved tool call or suspended step |
The download figures measure adoption. Adoption matters for hiring and for finding answers to error messages, but it says nothing about fit for a given workload, and each number comes from the vendor's own announcement [7][10].
The table holds the differences that cause production bugs. Each framework pauses at a different level, so the same approval rule lands in different places in the code. Each stores paused state differently, so a team needs a durable store before the first approval-gated feature ships. And LangGraph's resume rule means code above an interrupt() runs twice [6]: a charge or an email placed there happens twice unless it is idempotent. The tracing default deserves a policy decision of its own, because a support agent's traces contain customer messages unless sensitive-data capture is turned off [3].
Implementation
Run a bake-off instead of reading more comparisons. Give each candidate the same narrow task: a support agent looks up an order and proposes a refund, which a person must approve before money moves. Build it in each framework, then run the checks in the next section. The first two blocks show the approval-gated tool in the OpenAI Agents SDK and in Mastra.
"""Refund tool that pauses for a person, using the OpenAI Agents SDK."""
from agents import Agent, RunState, Runner, function_tool
@function_tool(needs_approval=True)
def issue_refund(order_id: str, amount_cents: int) -> str:
"""Refund an order. Moves money, so a person must approve it."""
return f"refunded {amount_cents} cents on {order_id}" # call the payment API here
agent = Agent(name="Support", instructions="Handle refund requests.", tools=[issue_refund])
async def start(message: str) -> dict:
result = await Runner.run(agent, message)
if not result.interruptions:
return {"status": "done", "reply": result.final_output}
pending = [{"tool": i.name, "args": i.arguments} for i in result.interruptions]
# Store the state string in your database and show `pending` to a reviewer.
return {"status": "waiting", "pending": pending, "state": result.to_state().to_string()}
async def resume(saved_state: str, approved: bool) -> str:
state = await RunState.from_string(agent, saved_state) # load only from trusted storage
for item in state.get_interruptions():
if approved:
state.approve(item)
else:
state.reject(item)
result = await Runner.run(agent, state)
return result.final_outputThe pause is a return value: start either finishes or hands back a state string, and your application decides where that string lives and who sees the pending call. With a model mocked out, both the approve and the reject path complete, and the tool body runs only after approval.
import { Agent } from '@mastra/core/agent'
import { createTool } from '@mastra/core/tools'
import { z } from 'zod'
export const issueRefund = createTool({
id: 'issue-refund',
description: 'Refund an order. Moves money, so a person must approve it.',
inputSchema: z.object({ orderId: z.string(), amountCents: z.number().int().positive() }),
requireApproval: true,
execute: async ({ orderId, amountCents }) => {
return { refunded: amountCents, orderId } // call the payment API here
},
})
export const supportAgent = new Agent({
id: 'support-agent',
name: 'Support Agent',
instructions: 'Handle refund requests for orders the customer owns.',
model: 'openai/gpt-6.1-terra',
tools: { issueRefund },
})
export async function handle(message: string) {
const stream = await supportAgent.stream(message)
for await (const chunk of stream.fullStream) {
if (chunk.type === 'tool-call-approval') {
// In production: store stream.runId, notify a reviewer, resume in a later request.
const approved = await supportAgent.approveToolCall({ runId: stream.runId })
for await (const text of approved.textStream) process.stdout.write(text)
}
}
}In Mastra the pause arrives as an event in the stream, and the run is identified by runId. The example approves inline to stay short. A real handler stores the runId, ends the request, and calls approveToolCall or declineToolCall when the reviewer answers, which works only if the Mastra instance has storage configured [8]. This file type-checks against @mastra/core 1.x.
Test it
LangGraph puts the same flow in an explicit graph, which makes it easy to test without a model. This test pauses the run, resumes it, and then sends a duplicate approval, as a double click or a retried webhook would.
"""The same refund flow as an explicit LangGraph graph, tested without a model."""
from typing import TypedDict
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import END, START, StateGraph
from langgraph.types import Command, interrupt
REFUNDS: list = [] # stands in for the payment provider
class Refund(TypedDict, total=False):
order_id: str
amount_cents: int
approved: bool
def ask_human(state: Refund) -> dict:
# Saves state and pauses. On resume this node runs again from its first line.
decision = interrupt({"order_id": state["order_id"], "amount_cents": state["amount_cents"]})
return {"approved": decision == "approve"}
def issue_refund(state: Refund) -> dict:
if state["approved"]:
REFUNDS.append((state["order_id"], state["amount_cents"]))
return {}
builder = StateGraph(Refund)
builder.add_node("ask_human", ask_human)
builder.add_node("issue_refund", issue_refund)
builder.add_edge(START, "ask_human")
builder.add_edge("ask_human", "issue_refund")
builder.add_edge("issue_refund", END)
graph = builder.compile(checkpointer=InMemorySaver()) # PostgresSaver in production
def test_refund_waits_for_a_person_then_runs_once():
config = {"configurable": {"thread_id": "ticket-4812"}}
paused = graph.invoke({"order_id": "A-1", "amount_cents": 4900}, config)
assert "__interrupt__" in paused and REFUNDS == []
graph.invoke(Command(resume="approve"), config)
graph.invoke(Command(resume="approve"), config) # a duplicate click
assert REFUNDS == [("A-1", 4900)]Expected: one passing test with LangGraph 1.x. Then run the same four checks against each candidate and write the results in one table:
- Restart between pause and approval. Stop the process after the pause, start a new one, resume from stored state. Expected: the refund runs once. An in-memory store fails this check by design, which is the point of running it.
- Rejection. Decline the call. Expected: no refund, and the model receives the rejection and replies to the customer.
- Tool failure. Make the payment call time out once. Expected: the run reports the error and does not retry the refund on its own.
- Trace review. Open one full run in your tracing backend. Expected: the model call, tool call and approval appear, and customer data appears only where your policy allows it [3].
Count the lines of glue code each candidate needed to pass all four. That number predicts maintenance cost better than any feature list.
Decision
Pick by team language first, then by how long runs live.
- A TypeScript product team building inside a Next.js or Node backend: start with Mastra, and configure storage before the first approval-gated tool [8].
- A Python team using mostly OpenAI models that wants the smallest API: start with the OpenAI Agents SDK, and set the tracing and sensitive-data policy on day one [3].
- Long, branching processes that must survive restarts and show explicit state, on any model provider: start with LangGraph, and keep side effects after the
interrupt()[6]. - The cost is about two engineer-days for the bake-off plus a durable store for paused runs. Settle where approvals belong first: see Human Approval Gates for AI Actions, and read Do You Actually Need Multiple AI Agents? before reaching for handoffs.
Sources
- [1]OpenAI Agents SDK (opens in a new tab)OpenAI, November 2026
- [2]Human-in-the-loop (opens in a new tab)OpenAI Agents SDK, November 2026
- [3]Tracing (opens in a new tab)OpenAI Agents SDK, November 2026
- [4]OpenAI Agents SDK TypeScript (opens in a new tab)OpenAI, November 2026
- [5]LangGraph overview (JavaScript) (opens in a new tab)LangChain Docs, November 2026
- [6]Interrupts (opens in a new tab)LangChain Docs, November 2026
- [7]LangChain and LangGraph Agent Frameworks Reach v1.0 Milestones (opens in a new tab)LangChain, October 2025
- [8]Human-in-the-loop (opens in a new tab)Mastra Docs, November 2026
- [9]Suspend and resume (opens in a new tab)Mastra Docs, November 2026
- [10]Announcing Mastra 1.0! (opens in a new tab)Sam Bhagwat, Mastra, January 2026
Technical guidance, not legal or security certification.
Related resources
Need a technical review of an AI-built MVP?
Discuss your build