Stateful Agents — Mastra vs Cloudflare Agents SDK vs LangGraph

Three frameworks, two deployment targets: non-edge (server / self-host) stateful agents and edge-deployment stateful agents.

Deep research · May 21, 2026 · Exa semantic search + Cloudflare Agents docs (SDK v0.3.7) · swarm.ing / AI Labs

Contents 1. They're not the same layer 2. Pros & cons 3. Non-edge stateful agents 4. Edge-deployment stateful agents 5. Recommended architecture 6. Sources

1. They're not the same layer

The single most important thing to internalize before comparing: these three operate at different layers of the stack. Comparing them head-to-head only makes sense once you see what each one actually is.

Orchestration framework
LangGraph

A high-level graph/state-machine runtime for agent reasoning. Runs on servers / serverless. Owns the control flow.

Agent + workflow framework
Mastra

A high-level TypeScript framework (agents, graph workflows, memory) that deploys onto Node or edge. Portable.

Runtime & state primitive
Cloudflare Agents SDK

Durable-Objects-based state/durability layer — not a reasoning abstraction. You bring the agent loop (Vercel AI SDK / Mastra) on top.

Consequence: LangGraph and Mastra compete on orchestration; the Cloudflare Agents SDK competes on where state lives and how durably it survives. The "best" answer therefore flips entirely depending on whether you're deploying to a server or to the edge.

2. Pros & cons

LangGraph

· LangChain PythonJSOSS

Nature: directed-graph state machine; the most mature durable agent runtime. Home turf: servers & serverless, self-host or LangGraph Platform.

Pros

  • Most mature stateful runtime — durable checkpointers, time-travel replay, partial-failure recovery.
  • Best-in-class human-in-the-loop: pause, inspect, edit state, resume.
  • Highest ceiling for complex / cyclic multi-agent topologies.
  • Strongest observability in the field (LangSmith traces + evals).

Cons

  • Python-first; the JS/TS port lags.
  • Not designed for the edge — Python can't run on Workers; the JS build is heavy for edge runtimes.
  • Steepest learning curve; you assemble memory/tools/eval yourself.
  • LangSmith is a paid add-on.

Mastra

· Mastra (ex-Gatsby team) TypeScriptedge-capableOSS

Nature: TS-native agents + graph workflow engine (XState) with built-in memory. Deploys to: standalone Node server and Cloudflare Workers / Vercel.

Pros

  • TypeScript-native; durable workflows with .suspend()/.resume() HITL.
  • Built-in working + semantic memory; native MCP (consume & author).
  • Runs on both server and edge — the only one of the three that's genuinely portable across both targets.
  • Higher-level agent/workflow abstraction than raw Cloudflare primitives.

Cons

  • Durability depends on an external storage backend (libSQL / D1 / Postgres) — state isn't intrinsic to the runtime.
  • Smaller ecosystem; less battle-tested than LangGraph for very large multi-agent systems.
  • TS-only — not for Python/Java teams.
  • Workflow control flow has a lower ceiling than LangGraph's graph model.

Cloudflare Agents SDK

· Cloudflare · SDK v0.3.7 (Feb 2026) TypeScriptedge-nativeruntime

Nature: built on Durable Objects — each agent is an addressable micro-server with embedded SQLite and hibernation. Pairs with Cloudflare Workflows for durable multi-step jobs.

Pros

  • State is the runtime — DO + embedded SQLite; setState() persists per-instance automatically and syncs to connected clients.
  • Hibernation economics: millions of per-user/per-bot agents, ~zero cost when idle.
  • Durable execution: runFiber()/stash() crash recovery; Workflows give waitForApproval() HITL that can pause for up to a year.
  • Sub-agents (facets), native MCP client & server, scheduling (scheduleEvery()), resumable LLM streams, WebSockets.

Cons

  • Cloudflare-only — hard vendor lock; no self-host / multi-cloud path.
  • Lower-level — infra primitives + AI bindings, not a graph/agent reasoning abstraction. You build (or import) the loop.
  • Young SDK (v0.3.7); API surface still moving.
  • Multi-agent orchestration is DIY vs. LangGraph's graph or CrewAI's crews.

3. Non-edge stateful agents — server / self-host / complex orchestration

DimensionLangGraphMastraCF Agents SDK
Overall fit★ BestGood (TS shops)✗ N/A (CF-only)
Durable stateCheckpointers (mature)Workflow state + storage backend
Human-in-the-loopFirst-classsuspend / resume
Complex multi-agentExcellentModerate
ObservabilityLangSmith (best)Built-in evals
LanguagePython / JSTypeScript
Deploy targetServer / serverless / LG PlatformNode server / containersCF edge only
Verdict — LangGraph, decisively. It's purpose-built for durable, complex, long-horizon multi-agent off the edge — checkpointing, time-travel debugging, and partial-failure recovery are unmatched. Mastra is the pick only if the team is TypeScript-exclusive and wants one stack across tiers. The Cloudflare Agents SDK isn't a contender here — it only runs on Cloudflare's edge.

4. Edge-deployment stateful agents — Cloudflare Workers

DimensionCF Agents SDKMastraLangGraph
Overall fit★ BestStrong✗ Weak
State modelDO + SQLite, nativeApp state + backend (D1/libSQL)Not edge-designed
Idle costHibernates (~zero)Worker per request
Per-user / per-bot instancesNative (addressable DO)Manual
HITL durabilitywaitForApproval() (days–year)suspend/resume (backend-bound)
Agent abstractionDIY / bring-your-ownBuilt-in graph + memory
PortabilityCF-lockedPortable
LanguageTypeScriptTypeScriptPy (no Workers) / heavy JS
Verdict — Cloudflare Agents SDK for the state & durability spine if you're committed to Cloudflare: nothing else gives you DO-native per-instance state + hibernation + day-to-year HITL pauses. Mastra wins when you want a richer built-in agent/workflow + memory abstraction on Workers and need to stay portable across hosts. LangGraph is the wrong tool at the edge — Python doesn't run on Workers and the JS build is heavy.

5. Recommended architecture — CF Workers + Turnkey trading agents

The strongest design isn't "pick one" — it's to combine the layers: Cloudflare Agents SDK as the edge state/durability layer, with Mastra (or the Vercel AI SDK) as the agent-reasoning layer running inside it.

Edge runtimeCloudflare Agents SDK — one Durable Object per bot/user → native per-instance state, hibernation (critical for many idle trading agents), resumable LLM streams, scheduling.
Durable jobs / HITLCloudflare Workflows via runWorkflow() + waitForApproval() — maps directly onto Turnkey signing gates: pause for a human/policy decision, resume on approval, durable for days.
Agent reasoningMastra (or Vercel AI SDK) inside the Agent — supplies the agent loop, memory, and MCP tools, with the higher-level workflow abstraction the raw SDK lacks.
Control plane (opt.)LangGraph kept in reserve for a Python service doing heavy offline multi-agent orchestration — research, backtesting, strategy synthesis — never the live edge tier.
The one trade to weigh: the Cloudflare Agents SDK gives you the best edge state model in existence, but at the cost of hard CF lock-in. If portability across clouds is a hard requirement, lead with Mastra on Workers instead and treat Durable Objects as an optional backing store — you lose hibernation economics and native per-instance state, but keep an exit.

6. Sources

Compiled May 21, 2026 via Exa semantic search plus primary Cloudflare Agents documentation (Agents SDK v0.3.7, Feb 2026 changelog). Mastra and LangGraph capability data carried forward from the full 15-framework comparison (Exa + Parallel.ai, 195 cited sources).