Three layers, not three rivals
LangChain’s own documentation draws the line. LangChain is the agent framework: abstractions and integrations for models, tools, and agent loops. LangGraph is the orchestration runtime underneath it: durable execution, streaming, human-in-the-loop, and persistence. LangChain agents are built on LangGraph, so an agent from create_agent gets LangGraph’s checkpointer and interrupts. You can also use LangGraph without LangChain.
Temporal works at a different layer. It runs your code as a Durable Execution: once a Workflow starts, it runs to completion, and if the process running it crashes, the Temporal Service hands the work to another Worker, which rebuilds the state and resumes where it stopped. Its building blocks are Workflows and Activities, not prompts or tools.
So “Temporal vs LangChain” and “Temporal vs LangGraph” are one decision: where the durability of an agent run lives. Either in LangGraph checkpoints in your database, or in Temporal’s event history and Workers, with LangChain or LangGraph doing the reasoning inside.
Quick answer table
| Situation | Pick | Why |
|---|---|---|
| Short, read-only agent; rerunning the request after a failure is fine | LangChain (create_agent) | Least infrastructure. Add a checkpointer when you need memory or approvals. |
| Custom control flow, approval pauses, resume inside one service | LangGraph with a Postgres checkpointer | Checkpoints per super-step, interrupt(), and resume by thread_id cover it without another platform. |
| Run must outlive a worker crash, coordinate several services, or wait for days | Temporal, with LangChain or LangGraph inside Activities | The Temporal Service hands work to another Worker and replays history; Activities get timeouts and retries. |
| Existing LangGraph app that needs Temporal's guarantees | Temporal's LangGraph plugin | Nodes marked as Activities get Temporal timeouts and retries, and Temporal replaces the external checkpointer. Public Preview. |
| Any action with production side effects: deploy, delete, payment, customer message | Add a pre-dispatch policy gate | Durability makes an action complete. It does not decide whether the action may run. |
Side-by-side comparison
| Dimension | LangChain | LangGraph | Temporal |
|---|---|---|---|
| What it is | Agent framework: create_agent, integrations, middleware | Orchestration runtime: StateGraph, or @entrypoint and @task | Durable execution platform: Workflows, Activities, Workers |
| Unit of work | Agent loop: the model calls tools until the task is done | Node or task, checkpointed at each super-step | Workflow plus Activities, recorded in an Event History |
| State after a crash | Through LangGraph's checkpointer | Last checkpoint per thread_id; something must invoke the thread again | Another Worker replays the history and continues |
| Retries and timeouts | Middleware such as ToolRetryMiddleware | retry_policy and timeout per node, inside the running process | Activities retry by default; a Start-To-Close or Schedule-To-Close timeout is required |
| Human approval | HumanInTheLoopMiddleware with interrupt_on | interrupt() and Command(resume=...); waits indefinitely | Signals or Updates plus wait_condition; durable timers can run for months |
| Determinism rules | None for your code | Side effects belong in tasks or separate nodes; interrupted nodes re-run | Workflow code must be deterministic; I/O and LLM calls go in Activities |
| Long-run limits | Same as LangGraph | Checkpoint storage grows per thread; prune old checkpoints | 51,200 events or 50 MB per execution; use Continue-As-New |
| What you operate | Your application | A checkpoint database, or LangSmith's Agent Server | Temporal Service (self-hosted or Temporal Cloud) plus your Workers |
Durable execution: LangGraph checkpoints vs Temporal event history
LangGraph: a checkpoint at every super-step
A checkpointer saves a snapshot of graph state at each super-step, keyed by thread_id. If a node fails partway through a super-step, LangGraph keeps the writes of the nodes that already finished in that step as pending writes, so resuming does not run them again. InMemorySaver is for experiments; production uses a persistent backend such as PostgresSaver from langgraph-checkpoint-postgres.
How often state reaches the database is a per-call choice. durability="exit" writes only when the run exits, so a process crash mid-run loses the intermediate state. "async" writes while the next step runs, with a small window in which a crash can lose a checkpoint. "sync" writes every checkpoint before the next step starts.
Recovery is driven by the caller. A crashed run stays at its last checkpoint until something invokes the same thread_id again, for example graph.invoke(None, config). Your service owns that loop, unless you deploy on LangSmith’s Agent Server, which adds a durable task queue and Postgres-backed checkpoints so an interrupted run can resume from its last checkpoint.
The Functional API uses a replay model close to Temporal’s: on resume, LangGraph re-enters the @entrypoint from the top and restores completed @task results from the checkpoint. Side effects and non-deterministic calls therefore belong in tasks, and a task that started but did not finish can run again.
Temporal: event history and replay
Temporal records every step of a Workflow in an Event History. When a Worker dies, another Worker replays the Workflow code against that history to rebuild local state, then continues. Completed Activities do not run again during replay; their recorded results are reused.
Replay is why Workflow code must be deterministic: no network I/O, threads, randomness, or system time (the Python SDK provides workflow.now() and workflow.random() instead). LLM calls, tool calls, and database writes go in Activities. Changing Workflow code while executions are in flight can break replay with a non-determinism error, which is what Workflow Versioning is for.
Activities retry by default: a 1-second initial interval, a 2.0 backoff coefficient, intervals capped at 100 seconds, and unlimited attempts. Each Activity must set a Start-To-Close or Schedule-To-Close timeout. Workflows themselves do not retry by default. One execution’s history is capped at 51,200 events or 50 MB, so long agent loops use Continue-As-New.
The rule both share: idempotent side effects
Both models re-run work. LangGraph re-runs an interrupted node from its first line and may re-run an unfinished task. Temporal retries an Activity that fails or never reports back, and recommends that Activities be idempotent. Give every external write an idempotency key, and keep side effects after the interrupt() call or in their own node.
Human-in-the-loop: interrupt() vs Signals and Updates
In LangGraph, interrupt(payload) saves state through the checkpointer and pauses. The graph waits indefinitely until you invoke it again with Command(resume=value) on the same thread_id, and that value becomes the return value of interrupt(). It needs a checkpointer and a JSON-serializable payload. Two rules cause most bugs: the node restarts from its first line on resume, so code before interrupt() runs twice, and wrapping interrupt() in a bare try/except catches the exception that implements the pause.
LangChain exposes the same mechanism per tool. HumanInTheLoopMiddleware takes an interrupt_on mapping, pauses before the tools you list with allowed decisions such as approve, edit, or reject, and also requires a checkpointer.
A Temporal Workflow receives Signals (asynchronous writes), Updates (synchronous, tracked writes that a validator can reject before they reach history), and Queries (reads). An approval is a Signal or Update handler that sets state, plus workflow.wait_condition(...) in the run method. Give it a timeout and the wait is backed by a durable timer that survives Worker restarts; a Workflow can wait for months.
Neither mechanism decides who may approve, or whether the action needed approval at all. That is policy, covered below.
Code patterns
1) LangGraph alone: Postgres checkpoints and an approval interrupt
Runs inside your service. The approval can arrive hours later in another process, as long as it reaches the same database and thread_id.
from typing import TypedDict
from langgraph.checkpoint.postgres import PostgresSaver
from langgraph.graph import END, START, StateGraph
from langgraph.types import Command, interrupt
class State(TypedDict):
incident_id: str
plan: str
approved: bool
def propose(state: State):
# Model or retrieval call. Once this node finishes, its output is checkpointed.
return {"plan": f"rollout restart payments-api for {state['incident_id']}"}
def review(state: State):
# Saves state and pauses. On resume this node runs again from the top,
# so nothing before interrupt() may have side effects.
decision = interrupt({"plan": state["plan"]})
return {"approved": decision == "approve"}
def execute(state: State):
if state["approved"]:
... # the side effect lives in its own node, after the approval
return {}
builder = StateGraph(State)
builder.add_node("propose", propose)
builder.add_node("review", review)
builder.add_node("execute", execute)
builder.add_edge(START, "propose")
builder.add_edge("propose", "review")
builder.add_edge("review", "execute")
builder.add_edge("execute", END)
with PostgresSaver.from_conn_string(DB_URI) as checkpointer:
checkpointer.setup() # creates the checkpoint tables on first use
graph = builder.compile(checkpointer=checkpointer)
config = {"configurable": {"thread_id": "INC-441"}}
result = graph.invoke({"incident_id": "INC-441"}, config, durability="sync")
print(result["__interrupt__"]) # the payload passed to interrupt()
# Later, from any process that reaches the same database:
graph.invoke(Command(resume="approve"), config, durability="sync")2) Temporal with a LangChain agent inside an Activity
Model and tool calls are I/O, so the LangChain agent runs in an Activity. The Workflow keeps the deterministic parts: the retry policy, the approval wait, and its timeout.
# activities.py: LangChain makes model and tool calls, so it runs in an Activity
from langchain.agents import create_agent
from langchain.tools import tool
from temporalio import activity
@tool
def search_runbooks(query: str) -> str:
"""Search incident runbooks."""
return f"Runbook results for: {query}"
agent = create_agent(model="openai:gpt-5.5", tools=[search_runbooks])
@activity.defn
async def plan_fix(incident_id: str) -> str:
result = await agent.ainvoke(
{"messages": [{"role": "user", "content": f"Propose a fix for {incident_id}"}]}
)
return result["messages"][-1].content
# workflows.py: deterministic orchestration only
import asyncio
from datetime import timedelta
from temporalio import workflow
from temporalio.common import RetryPolicy
with workflow.unsafe.imports_passed_through():
from activities import plan_fix
@workflow.defn
class IncidentWorkflow:
def __init__(self) -> None:
self.approved: bool | None = None
@workflow.signal
def review(self, approved: bool) -> None:
self.approved = approved
@workflow.run
async def run(self, incident_id: str) -> str:
plan = await workflow.execute_activity(
plan_fix,
incident_id,
start_to_close_timeout=timedelta(minutes=5),
retry_policy=RetryPolicy(maximum_attempts=3),
)
try:
# Durable wait: a Temporal timer, not a sleeping process.
await workflow.wait_condition(
lambda: self.approved is not None, timeout=timedelta(days=2)
)
except asyncio.TimeoutError:
return "expired"
return plan if self.approved else "rejected"One Activity per agent run is the simplest boundary, but a retry re-runs the whole agent loop. For finer recovery, make each model call and tool call its own Activity. Temporal’s Deep Agents plugin does this for LangChain Deep Agents, and the LangGraph plugin runs each graph node as an Activity.
3) Temporal’s LangGraph plugin
The LangGraph plugin (Public Preview) runs LangGraph nodes and tasks as Temporal Activities. Every node declares execute_in as "activity" or "workflow". Activity nodes take Temporal timeouts and a Temporal RetryPolicy; passing LangGraph’s own retry_policy raises an error. interrupt() works inside Activity nodes and resumes from Workflow code, so approvals can use Signals and Queries. Install it with pip install temporalio-langgraph; earlier SDK releases bundled it as temporalio.contrib.langgraph.
# pip install temporalio-langgraph (Public Preview)
from datetime import timedelta
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import START, StateGraph
from langgraph.types import Command, interrupt
from temporalio import workflow
from temporalio.common import RetryPolicy
from temporalio.langgraph import graph
from typing_extensions import TypedDict
class State(TypedDict):
incident_id: str
plan: str
async def propose_fix(state: State) -> dict[str, str]:
# Model call: runs as an Activity with Temporal's timeout and retries.
return {"plan": f"rollout restart payments-api for {state['incident_id']}"}
async def review(state: State) -> dict[str, str]:
decision = interrupt(state["plan"]) # propagated back to the Workflow
return {"plan": state["plan"] if decision == "approve" else ""}
def build_graph() -> StateGraph:
as_activity = {
"execute_in": "activity",
"start_to_close_timeout": timedelta(minutes=2),
"retry_policy": RetryPolicy(maximum_attempts=3),
}
g = StateGraph(State)
g.add_node("propose_fix", propose_fix, metadata=as_activity)
g.add_node("review", review, metadata=as_activity)
g.add_edge(START, "propose_fix")
g.add_edge("propose_fix", "review")
return g
@workflow.defn
class IncidentGraphWorkflow:
def __init__(self) -> None:
self.plan: str | None = None
self.decision: str | None = None
@workflow.query
def pending_plan(self) -> str | None:
return self.plan
@workflow.signal
def decide(self, decision: str) -> None:
self.decision = decision
@workflow.run
async def run(self, incident_id: str) -> str:
app = graph("incident").compile(checkpointer=InMemorySaver())
config = {"configurable": {"thread_id": workflow.info().workflow_id}}
first = await app.ainvoke(
{"incident_id": incident_id, "plan": ""}, config, version="v2"
)
self.plan = first.interrupts[0].value
await workflow.wait_condition(lambda: self.decision is not None)
resumed = await app.ainvoke(Command(resume=self.decision), config, version="v2")
return resumed.value["plan"]
# Worker: Worker(client, task_queue="incidents", workflows=[IncidentGraphWorkflow],
# plugins=[LangGraphPlugin(graphs={"incident": build_graph()})])Temporal handles durability here, so the graph uses InMemorySaver only to support interrupt(); a Postgres or Redis checkpointer is not needed. LangGraph Stores are not available inside Activity nodes, and with the plugin, interrupt() and the Functional API require Python 3.11 or newer.
When to combine them
- - LangChain or LangGraph alone when a run is short, a failed request can simply be retried, and nothing irreversible happens mid-run.
- - LangGraph with a persistent checkpointer when you need pause and resume, approvals, or multi-turn state inside one service, and your team can own the resume loop or deploy on Agent Server.
- - Add Temporal when the run must survive worker loss without a custom resume loop, coordinates several services with per-step retries and timeouts, or waits on people or timers for days.
- - Pick one owner for run state. With the plugin, Temporal owns durability and the checkpointer stays in memory. If you call a LangGraph app from an Activity instead, the Activity is the retry boundary: decide whether a retry starts a fresh run or resumes the
thread_idfrom its last checkpoint. - - Set one retry layer per step. A LangGraph
RetryPolicyinside an Activity that Temporal also retries multiplies the attempts.
Where policy and approvals fit
Durable execution guarantees that an action completes. It does not decide whether the action should run. Temporal will retry a destructive Activity as reliably as a safe one, and a LangGraph checkpoint records what the graph did, not why it was allowed. Approval branches written as interrupt() calls or Signal handlers live in application code, so changing what needs approval means changing and redeploying the graph or Workflow.
Cordum is the action firewall for AI-agent actions. Edge covers Claude Code shell and file actions, MCP governance covers MCP tool calls, and for agents you build yourself the Platform’s Safety Kernel evaluates policy before a governed job is dispatched. It returns ALLOW, DENY, REQUIRE_APPROVAL, or ALLOW_WITH_CONSTRAINTS. A required approval holds the job in APPROVAL_REQUIRED, tied to the policy snapshot and a hash of the job request; if either changes before someone approves, the approve call fails as stale instead of approving something else.
From a Temporal Activity or a LangGraph tool node, submit the side effect as a Cordum job with POST /api/v1/jobs and pass an idempotency_key. When Temporal retries the Activity, the gateway returns the existing job instead of creating a second one. A denial returns HTTP 403, and a retry with the same key replays that 403, so raise it as a non-retryable ApplicationError rather than letting Temporal retry it.
# safety.yaml: input rules the Safety Kernel evaluates before dispatch.
# Rules run top to bottom; the first match wins.
rules:
- id: deny-prod-delete
match:
topics: ["job.infra.delete"]
labels:
env: prod
decision: deny
reason: Agents may not delete production resources.
- id: approve-high-risk-prod-remediation
match:
topics: ["job.incident.remediate"]
risk_tags: ["high"]
labels:
env: prod
decision: require_approval
reason: High-risk production remediation needs a human approver.
- id: constrain-remediation
match:
topics: ["job.incident.remediate"]
decision: allow_with_constraints
reason: Bounded runtime, one retry, restart-only commands.
constraints:
budgets:
max_runtime_ms: 180000
max_retries: 1
toolchain:
allowed_commands: ["kubectl rollout restart"]A job that matches no rule gets default_decision, which is deny unless you set it to allow. Rules can also match on tenants, capabilities, actor IDs, and MCP server or tool names. For the full Temporal-plus-Cordum architecture, including retry and rollback semantics, read Temporal vs Cordum. Framework setup: how to govern LangGraph agents and the LangChain integration.
Limitations and tradeoffs
- - Temporal adds a service to run (or Temporal Cloud), Workers to deploy, and determinism discipline: Workflow code changes need versioning.
- - LangGraph alone keeps infrastructure small, but resuming stalled threads is your code unless you deploy on Agent Server.
- - The LangGraph plugin is in Public Preview and its package has already moved once, from
temporalio.contrib.langgraphtotemporalio-langgraph. Pin versions. - - Retrying in two layers multiplies attempts and duplicate side effects. Pick one per step.
- - Policy gates add approval latency to high-risk actions. That friction is the point; scope it to the actions that need it.
Frequently asked questions
What is the difference between Temporal and LangChain?
They work at different layers. LangChain is an agent framework: create_agent, model and tool integrations, and middleware decide what an agent does. Temporal is a durable execution platform: it records each Workflow step in an event history, replays Workflow code after a crash, and retries Activities under timeouts. LangChain builds the agent; Temporal keeps a multi-step run alive through worker crashes and long waits.
Temporal vs LangGraph: which one should I use?
Use LangGraph alone when you need graph control flow, checkpoints, and interrupt()-based approvals inside one service, and you can own resuming stalled threads (or deploy on LangSmith's Agent Server). Use Temporal when runs must survive worker loss without custom recovery code, coordinate several services with per-step retries, or wait for days. You can also use both: LangGraph for agent logic, Temporal for execution.
Can I use LangChain or LangGraph with Temporal?
Yes. Temporal publishes a LangGraph plugin (Public Preview, package temporalio-langgraph) that runs LangGraph nodes and tasks as Temporal Activities with Temporal timeouts and retry policies. For LangChain's Deep Agents there is a pre-release Deep Agents plugin. A plain LangChain create_agent agent can run inside an Activity, or you can make each model call and tool call its own Activity for finer-grained retries.
Does LangGraph already have durable execution?
Yes, through checkpointers. LangGraph saves state at every super-step, keeps pending writes from nodes that finished when another node in the same step fails, and resumes a thread from its last checkpoint. The durability argument (exit, async, or sync) controls how often state is written. The difference from Temporal is who drives recovery: with LangGraph alone, your service or LangSmith's Agent Server has to invoke the thread again.
Do I need a LangGraph checkpointer if I run LangGraph on Temporal?
With Temporal's LangGraph plugin you only need an InMemorySaver, and only if the graph uses interrupts. Temporal's documentation says Temporal handles durability, so PostgreSQL or Redis checkpointers are not needed. LangGraph Stores are not available inside Activity nodes.
How do human approvals differ between LangGraph and Temporal?
LangGraph's interrupt() saves state and waits indefinitely until you resume the thread with Command(resume=...); the interrupted node then re-runs from its first line. Temporal uses Signals or Updates plus workflow.wait_condition, optionally with a timeout backed by a durable timer. In both, the approval logic is application code that you write and deploy.
When is LangChain enough without Temporal?
When runs are short, a failure can be handled by retrying the whole request, and nothing irreversible happens mid-run, for example a read-only assistant that answers from internal docs. Add a checkpointer for memory or approvals, and move to Temporal when runs must survive crashes or wait on people for hours or days.
Do Temporal, LangChain, or LangGraph decide whether an agent action is allowed?
No. Durable execution makes an action complete; it does not decide whether the action should run, and Temporal will retry a destructive Activity as reliably as a safe one. Production side effects need a policy gate before dispatch. Cordum's Safety Kernel evaluates policy before a governed job is dispatched and returns ALLOW, DENY, REQUIRE_APPROVAL, or ALLOW_WITH_CONSTRAINTS.
Sources
- - LangChain overview (LangChain agents are built on LangGraph)
- - LangGraph checkpointers: super-steps, pending writes, durability modes
- - LangGraph interrupts
- - LangGraph Functional API: determinism and tasks
- - LangChain human-in-the-loop middleware
- - LangSmith Agent Server: persistence and task queue
- - Understanding Temporal: Durable Execution
- - Temporal Workflow definition: deterministic constraints
- - Temporal retry policies
- - Temporal Signals, Queries, and Updates
- - Temporal Workflow Execution limits
- - Temporal LangGraph integration
- - Cordum Safety Kernel