メインコンテンツへスキップ

MastraLangChain 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 は LangChainLangGraph 上に構築された 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 つ。

AreaMastraDeep Agents
Primary abstractionAI application frameworkAutonomous agent harness
Deterministic workflowsFirst-classBuilt with LangGraph
Multi-agent modelAgents and workflows exposed as toolsSupervisor delegates to subagents
RAGMastra packages and integrationsLangChain retrieval ecosystem
PersistenceMastra memory and durable executionLangGraph checkpointers and stores
File contextWorkspaces, skills, and file-based agentsFoundational virtual filesystem
Managed runtimeMastra PlatformManaged 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       operations

Mastra は 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 を隠す:

  1. Message history — conversation を coherent に保つ。
  2. Working memory — preferences、goals、task state を store。
  3. Long-term memory — conversations 間で knowledge を share。
  4. Durable execution — interrupted work を resume。
  5. 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 citations

ingestion は 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:

  1. model calls なし tool contracts
  2. controlled responses で workflows または graphs
  3. quality と groundedness 用 dataset evaluations
  4. performance と failure paths 用 traces
  5. 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 deploy

Mastra は 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:

  1. Managed Deep Agents — opinionated hosted runtime(availability は verify すべき)。
  2. LangSmith Deployment — persistent state、background execution、authentication hooks、webhooks、cron jobs、tracing、Agent Protocol APIs。
  3. 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
RequirementMastraDeep Agents
Simplest hosted pathMastra PlatformManaged Deep Agents
Established managed runtimeMastra PlatformLangSmith Deployment
Custom hostingBuilt server or adapterAgent Protocol routes or Agent Server
Self-hosted durabilityMastra storage providersLangGraph checkpointer, store, and infrastructure
Enterprise topologyPlatform-dependentCloud, 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:

NeedDefault
Deterministic workflowsMastra, unless the team already knows LangGraph
Conventional application memoryMastra
Filesystem-native memoryDeep Agents
Straightforward RAGMastra
Specialized retrievalDeep Agents with LangChain
Coding or research agentDeep Agents
Managed operationsDeep Agents with LangSmith
Existing OpenTelemetry pipelineEither

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 agentsworkflowsmemoryRAGworkspacesobservabilitydeployment。LangChain 向け Deep AgentsmemoryRAGsandboxesLangGraph persistenceLangSmith observabilityproduction deployment

次のノートを読む
React 19 の新機能