Mastra と LangChain Deep Agents は agents、tools、memory、streaming をサポートする。本当の違いは各 framework が boundary をどこに引くかである。
Mastra は AI applications 向け integrated TypeScript framework。agents、workflows、memory、RAG、evaluation、observability、local Studio、server、deployment adapters が 1 つの programming model を共有する。
Deep Agents は LangChain と LangGraph 上に構築された opinionated autonomous-agent harness。files、context offloading、subagents、memory、middleware を提供し、retrieval は LangChain、explicit workflows と persistence は LangGraph、operations は LangSmith に依存する。
短い結論:
- deterministic workflows を含む wider application では Mastra。
- files、subagents、context management 中心の autonomous research、coding、operations agents では Deep Agents。
- どちらかに commit する前に durability と deployment model を validate。
1. Core Difference
Deep Agents は LangChain の replacement ではない。deepagents package は LangChain と LangGraph を prebuilt agent harness に assemble する:
- virtual filesystem
- automatic context summarization
- subagent delegation
- file-based skills と memory
- retries、approvals、guardrails 用 middleware
Mastra は wider application boundary から start。その Agent は tools、workflows、storage、vector stores、scorers、API routes、deployment configuration と並ぶ primitive の 1 つ。
| Area | Mastra | Deep Agents |
|---|---|---|
| Primary abstraction | AI application framework | Autonomous agent harness |
| Deterministic workflows | First-class | Built with LangGraph |
| Multi-agent model | Agents and workflows exposed as tools | Supervisor delegates to subagents |
| RAG | Mastra packages and integrations | LangChain retrieval ecosystem |
| Persistence | Mastra memory and durable execution | LangGraph checkpointers and stores |
| File context | Workspaces, skills, and file-based agents | Foundational virtual filesystem |
| Managed runtime | Mastra Platform | Managed Deep Agents or LangSmith |
Mastra は package level で broader。Deep Agents は surrounding LangChain ecosystem を含めると broader になる。
2. Agent の構築
両 framework は TypeScript、Zod-validated tools、model streaming をサポートする。
Mastra
import { Agent } from "@mastra/core/agent"
import { createTool } from "@mastra/core/tools"
import { z } from "zod"
const searchDocs = createTool({
id: "search-docs",
description: "Search product documentation",
inputSchema: z.object({ query: z.string() }),
execute: async ({ query }) => searchProductDocs(query),
})
export const supportAgent = new Agent({
id: "support-agent",
name: "Support Agent",
instructions: "Answer from the documentation and cite the evidence.",
model: process.env.AGENT_MODEL!,
tools: { searchDocs },
})Deep Agents
import { createDeepAgent } from "deepagents"
import { tool } from "langchain"
import { z } from "zod"
const searchDocs = tool(({ query }) => searchProductDocs(query), {
name: "search_docs",
description: "Search product documentation",
schema: z.object({ query: z.string() }),
})
export const supportAgent = createDeepAgent({
model: process.env.AGENT_MODEL!,
systemPrompt: "Answer from the documentation and cite the evidence.",
tools: [searchDocs],
})違いは type safety ではない。Mastra の registries と shared resource model は application framework の feel。Deep Agents は graph-backed runtime の configure の feel。
Mastra の local server と Studio は agents、workflows、traces、datasets、scorers を expose。complete Deep Agents application は通常複数 layer にまたがる:
Deep Agents → LangChain → LangGraph → LangSmith
agent harness tools state operationsMastra は intended path で conceptual jumps を減らす。Deep Agents は more control が必要なとき LangGraph への direct escape hatch を提供する。
3. Deterministic Workflows
agent は model に next step を選ばせる。workflow は important transitions を code で explicit にする。
sequence が business rule のとき workflow を使う:validate input、collect data、request approval、publish、record result。
Mastra workflows
Mastra workflows は first-class typed primitives。steps は input と output schemas を declare し、sequentially、parallel、branches、loops で compose。
const articleWorkflow = createWorkflow({
id: "article-workflow",
inputSchema: z.object({ topic: z.string() }),
outputSchema: z.object({ article: z.string() }),
})
.then(research)
.then(write)
.then(approve)
.commit()steps は human approval のために suspend し typed payload で resume できる。model は step 内では flexible のまま entire process を control しない。
Deep Agents with LangGraph
subagent delegation は model-directed で deterministic workflow ではない。explicit state と transitions には Deep Agents を LangGraph と compose:
const graph = new StateGraph(WorkflowState)
.addNode("research", runResearchAgent)
.addNode("review", reviewDraft)
.addEdge(START, "research")
.addEdge("research", "review")
.addConditionalEdges("review", ({ approved }) =>
approved ? END : "research"
)
.compile()LangGraph は checkpoints、interrupts、streaming、subgraphs、durable execution をサポート。cost は graph state、reducers、nodes、transitions の管理。
workflow-heavy products では Mastra が通常 shorter path。既に LangGraph を使う team では Deep Agent を custom state machine 内の capable node の 1 つにできる。
4. Durability と Memory
「Memory」は often 複数の separate requirements を隠す:
- Message history — conversation を coherent に保つ。
- Working memory — preferences、goals、task state を store。
- Long-term memory — conversations 間で knowledge を share。
- Durable execution — interrupted work を resume。
- Resumable streaming — client を running task に reconnect。
persisted messages だけでは arbitrary code は durable にならない。
Mastra
Mastra の Memory は conversation thread を user または tenant resource に associate:
const memory = new Memory({
storage: new PostgresStore({
id: "support-memory",
connectionString: process.env.DATABASE_URL!,
}),
options: {
lastMessages: 20,
workingMemory: { enabled: true },
},
})
await agent.stream("Continue the migration plan", {
memory: {
thread: "conversation-42",
resource: "user-123",
},
})Mastra は recent messages、semantic recall、structured working memory、observational memory を combine できる。durable-agent APIs で clients は run ID で long streams に reconnect。process crash を survive すべき work は durable または workflow-backed execution に属する。
Deep Agents and LangGraph
LangGraph checkpointer は thread-scoped graph state を persist:
const checkpointer = PostgresSaver.fromConnString(process.env.DATABASE_URL!)
const agent = createDeepAgent({
model: process.env.AGENT_MODEL!,
checkpointer,
})
await agent.invoke(
{ messages: [{ role: "user", content: "Continue the analysis." }] },
{ configurable: { thread_id: "conversation-42" } }
)checkpointer は conversation state、interrupts、resume points を store。LangGraph store は threads 間で share する data。
Deep Agents は long-term memory を files で表現。StateBackend は scratch files を thread state に、StoreBackend は /memories/ や /skills/ など paths を threads 間 persist できる。
Mastra は more built-in memory strategies。Deep Agents は inspectable editable filesystem model。durable memory には identifiers と namespaces を authenticated context から、retention、correction、deletion policies が必要。
5. RAG
production RAG system には separate ingestion と query paths がある:
ingestion → load → chunk → embed → index
query → retrieve → filter/rerank → answer with citationsingestion は every agent request 中に run すべきではない。successful vector lookup だけでは answer grounded とは証明しない。
Mastra RAG
Mastra は document chunking、AI SDK model interface 経由 embedding support、vector-store integrations、agent に直接 attach できる vector query tool を提供。
conventional RAG inside TypeScript application 向け cohesive path。authenticated request context から tenant index を選ぶ dynamic vector-store resolution が特に有用。
Deep Agents with LangChain
Deep Agents は LangChain loaders、text splitters、embeddings、retrievers、vector stores を使う。ecosystem breadth は specialized document formats や retrieval strategies が必要な application で matter。
Deep Agents には large results 向け context-management advantage もある:tool が retrieved content を backend に write し file paths を return。agent は relevant sections のみ inspect し every token を main conversation に置かない。
どちらの framework でも evaluate:
- retrieval recall と precision
- answer groundedness
- citation correctness
- end-to-end answer quality
6. Files、Subagents、Sandboxes
Deep Agents は files と delegation を central にする。supervisor は isolated context の subagents に work を send し、各 specialist が many tool calls して compact result を return。
backend は virtual filesystem を提供。sandbox backend は command execution を extend:
StateBackend— thread-scoped virtual files。FilesystemBackend— host directory を expose。LocalShellBackend— host shell access を add。- provider-backed sandboxes — files と processes を remotely isolate。
Mastra は routing agent に agents と workflows を expose し、Workspace に filesystem と optional sandbox を attach。file access が many capabilities の 1 つである applications に fit。
workspace path は security boundary ではない。either framework の local shell execution は trusted development のみ。production execution には:
- fresh または correctly namespaced sandbox
- CPU、memory、disk、time limits
- controlled network egress
- explicit file-transfer rules
- narrowly scoped credentials
isolation は host を protect するが prompt injection、secret exfiltration、runaway cost、cross-user leakage だけでは prevent しない。
Deep Agents は file-heavy autonomous work で stronger center of gravity。Mastra は broader application へ files と execution を more naturally integrate。
7. Observability、Evaluation、Safety
agent を operate するには final answer の背後の path が必要:model calls、tools、retrieval、subagents、workflow transitions、retries、latency、token usage、cost、errors。
Mastra は primitives を instrument し traces を Studio、Mastra Platform、OpenTelemetry backends に export。scorers、datasets、experiments も same framework model。
Deep Agents は LangChain と LangGraph tracing を inherit。LangSmith は dashboards、alerts、datasets、offline/online evaluators、annotation queues、deployment monitoring を add。
Mastra observability は framework primitive の feel。LangSmith は broader operations product。both は existing OpenTelemetry pipeline に participate できる。
either stack では 5 levels で test:
- model calls なし tool contracts
- controlled responses で workflows または graphs
- quality と groundedness 用 dataset evaluations
- performance と failure paths 用 traces
- deployed behavior:streaming、persistence、authentication、limits
human approval は suspended workflow steps、tool approval、LangGraph interrupts の両方で available。approval は runtime isolation の replacement ではない。
agent traces には user messages、retrieved documents、tool arguments、generated code が含まれうる。application data と同じ access controls、redaction、retention、deletion rules を apply。
8. Deployment
first agent demo は easy。production には durable state、background execution、authentication、secrets、observability、real infrastructure を survive する streaming が必要。
Mastra
most integrated path は Mastra Platform:
mastra deployMastra は Node server を build し Cloudflare など platform を target できる。portability は state に依存:local SQLite files、vectors、memory、workflow data は runtime compatible stores に replace する必要。
Deep Agents
Deep Agents には 3 main paths:
- Managed Deep Agents — opinionated hosted runtime(availability は verify すべき)。
- LangSmith Deployment — persistent state、background execution、authentication hooks、webhooks、cron jobs、tracing、Agent Protocol APIs。
- Application-hosted deployment — Next.js など framework または Cloudflare で Agent Streaming Protocol。
application hosting は team に more responsibility:
- durable checkpointer と store を configure
- every thread を authenticate と authorize
- tenant namespaces を isolate
- host timeouts と background work を handle
- code execution を web server から sandbox away
| Requirement | Mastra | Deep Agents |
|---|---|---|
| Simplest hosted path | Mastra Platform | Managed Deep Agents |
| Established managed runtime | Mastra Platform | LangSmith Deployment |
| Custom hosting | Built server or adapter | Agent Protocol routes or Agent Server |
| Self-hosted durability | Mastra storage providers | LangGraph checkpointer, store, and infrastructure |
| Enterprise topology | Platform-dependent | Cloud, hybrid, or self-hosted LangSmith |
Mastra は greenfield TypeScript team 向け cleaner integrated path。LangSmith は LangChain invested teams または hybrid infrastructure が必要な team 向け more runtime topologies。
How I Would Choose
practical defaults:
| Need | Default |
|---|---|
| Deterministic workflows | Mastra, unless the team already knows LangGraph |
| Conventional application memory | Mastra |
| Filesystem-native memory | Deep Agents |
| Straightforward RAG | Mastra |
| Specialized retrieval | Deep Agents with LangChain |
| Coding or research agent | Deep Agents |
| Managed operations | Deep Agents with LangSmith |
| Existing OpenTelemetry pipeline | Either |
universal winner はない。Mastra は AI application を optimize。Deep Agents は autonomous agent harness を optimize し wider LangChain stack に connect。
choose 前に hardest production requirement を prototype。approval workflows 向け suspend/resume、long-running research への reconnect、realistic documents で RAG measure、code execution 向け sandbox と credential boundaries verify。
fewest hidden assumptions でその test を pass する framework が better choice。
current details は official Mastra agents、workflows、memory、RAG、workspaces、observability、deployment。LangChain 向け Deep Agents、memory、RAG、sandboxes、LangGraph persistence、LangSmith observability、production deployment。