AI AgentsLangChain
How do LangChain, LangGraph, and Deep Agents differ?
Question 282 of 324 · Updated
On this page
- Direct answer
- 1. Understand the relationship between the layers
- LangChain: choose a model, tools and instructions
- LangGraph: design the execution process
- Deep Agents: provide an opinionated harness for larger tasks
- 2. Side-by-side comparison
- 3. Same business problem, three approaches
- Approach A: LangChain
- Approach B: LangGraph
- Approach C: Deep Agents
- 4. Minimal implementation patterns
- A. LangChain high-level agent
- B. LangGraph explicit state and routing
- C. Deep Agents task-oriented harness
- 5. Locally tested selection and commit-policy example
- 6. Numerical example: measure work rather than assume an abstraction is faster
- 7. Choose the abstraction based on the task
- 8. Production failure modes and engineering controls
- 9. Testing and migration strategy
- Interview-ready answer
- References and verification status
Direct answer#
LangChain is a high-level framework for building LLM applications and tool-using agents; LangGraph is a lower-level orchestration runtime for explicitly controlling stateful, potentially cyclic workflows; Deep Agents is a higher-level agent harness designed for extended, open-ended tasks that benefit from planning, workspace tools, delegation and context management.
They are complementary layers, not three mutually exclusive competing products. Modern LangChain agents use LangGraph for orchestration, and Deep Agents builds on the LangChain/LangGraph ecosystem to provide more task-management conventions out of the box. Developers can start with the highest-level abstraction that fits their requirements and introduce explicit graph control where needed. Installing a higher-level package does not mean every task should use all its capabilities.
This comparison focuses on architectural responsibility and selection trade-offs. The preceding LangChain lesson covers installation and the first agent; the separate graph curriculum covers individual graph APIs in greater depth.
1. Understand the relationship between the layers#
This diagram shows conceptual dependencies and responsibilities, not a fixed module-import graph for every release.
LangChain: choose a model, tools and instructions#
The high-level agent abstraction is convenient when a model should decide which tools to call and when to stop. A typical application supplies a model, descriptions of callable tools, instructions and optional middleware. The runtime coordinates model requests and tool results.
Examples: an FAQ assistant with a product lookup tool, a support agent that retrieves order status, or a lightweight internal assistant that calls a few APIs. You do not need to design every transition in the model-tool loop yourself.
LangChain is broader than agents: its model interfaces, messages, tool abstractions and integrations can also be used in non-agent applications and as components of graph nodes.
LangGraph: design the execution process#
LangGraph makes the control flow an explicit engineering artifact. You define state, nodes that update it, edges that determine the next step, and conditional routing where required. A graph can contain model calls, tools, deterministic functions, branching, parallel work and bounded cycles. Checkpointing, interruptions and resumability are capabilities that require appropriate configuration and persistence choices.
A graph is not inherently agentic. A graph of deterministic functions can implement a normal workflow; a graph that lets a model choose actions implements an agentic workflow. LangGraph is useful when the distinction matters because you can decide exactly where model discretion is allowed.
Examples: an order-return process with fixed authorization and approval stages; a research workflow with explicit evidence validation; a multi-stage document processing pipeline with failure recovery.
Deep Agents: provide an opinionated harness for larger tasks#
Deep Agents is intended for tasks that may require a substantial number of steps, evolving plans, intermediate artifacts and delegated work. Its characteristic abstractions include planning or task-list tools, filesystem or workspace-style operations, specialist subagents, and context management. A particular release may expose different tools, backends and configuration interfaces; inspect the installed version.
For example, an agent investigating a software repository may plan its investigation, read relevant files, save intermediate findings, delegate a narrowly scoped investigation and synthesize a report. Keeping large artifacts outside the immediate model context can reduce repeated context growth, although relevant material still needs to be retrieved when required.
The harness is not a guarantee of competence, unlimited context, durable storage or safe autonomy. The application must choose and configure appropriate workspace backends, permission boundaries, model budgets, termination rules and recovery mechanisms.
2. Side-by-side comparison#
| Dimension | LangChain | LangGraph | Deep Agents |
|---|---|---|---|
| Primary role | Application and agent abstractions | Explicit workflow orchestration | Long-task agent harness |
| Typical entry point | High-level agent builder such as create_agent | StateGraph and graph compilation | High-level deep-agent builder such as create_deep_agent |
| Control flow | Prebuilt model/tool loop with customization | Developer defines nodes, transitions and routing | Preconfigured task-oriented agent loop with extension points |
| State | Agent messages and configurable state | Explicit state schema, reducers and updates | Agent state plus task/workspace conventions |
| Persistence | Via runtime configuration | Checkpointer and store configured as needed | Depends on runtime configuration and chosen backends |
| Planning | Add when needed | Model explicitly as nodes/state | Task planning conventions are a central feature |
| Multi-agent work | Tools, delegation and integrations | Explicit supervisor, worker, subgraph or routing patterns | Built-in delegation-oriented abstractions where supported |
| Human review | Middleware and runtime integration | Explicit interrupt/resume points | Harness permission and approval configuration |
| Best fit | Conventional tool-using agents | Controlled, stateful, auditable processes | Extended exploratory work with intermediate artifacts |
| Main trade-off | Less direct control over the default loop | More design, state and testing responsibility | More moving parts and a wider potential tool surface |
Capabilities are not exclusive. For example, LangChain can use persistent state, LangGraph can implement planning, and Deep Agents can be used within a controlled application. The difference is what each abstraction makes convenient or explicit.
3. Same business problem, three approaches#
Suppose a company wants an assistant to investigate a failed customer order.
Approach A: LangChain#
The request is narrow: identify the failed order and explain its current status. Provide two read-only tools, one for retrieving order information and one for retrieving payment status. The model chooses the appropriate tools, receives their results, and produces a grounded explanation. Application code verifies the user's access to that order before returning data.
Approach B: LangGraph#
The company also permits refunds, which require deterministic validation and potentially human approval. Model judgment can classify the issue, but it cannot authorize the refund. Encode the policy as explicit nodes, conditional edges and a separate commit action. Persist the approval state if the process can pause.
An approval response must be bound to the exact intended action, amount, order, user and policy version. Resume must not accidentally repeat a side effect.
Approach C: Deep Agents#
Now the task is to investigate fifty related incidents across documentation, logs and approved repositories, identify patterns and produce a report with evidence. A deep-agent harness can maintain a task list, store intermediate evidence in a controlled workspace and delegate independent investigations to specialists. Each delegated task receives only its necessary context. A coordinator reviews the collected evidence before generating the report.
The arrows illustrate a possible architecture rather than a promise that the SDK executes these branches in parallel automatically.
4. Minimal implementation patterns#
The following snippets illustrate the expected abstraction boundary using familiar APIs from the LangChain ecosystem. Exact signatures, dependencies, model identifiers and middleware support are version-dependent. These SDK snippets were not executed here because the packages and model credentials were unavailable; confirm them against the installed package and official documentation before production use.
A. LangChain high-level agent#
PYTHONfrom langchain.agents import create_agent def lookup_order(order_id: str) -> str: """Read a synthetic order status for the tutorial.""" return {"A123": "payment failed"}.get(order_id, "not found") agent = create_agent( model="openai:gpt-4o-mini", tools=[lookup_order], system_prompt="Explain order status using the lookup tool." ) result = agent.invoke({ "messages": [{"role": "user", "content": "What happened to order A123?"}] }) print(result["messages"][-1].content)
Use a supported model identifier and configure provider credentials externally. This lookup contains synthetic data only; a real tool must enforce authenticated ownership and access limits. The desired outcome is an explanation grounded in the tool result, not a guaranteed exact model-generated sentence.
B. LangGraph explicit state and routing#
PYTHONfrom typing import TypedDict from langgraph.graph import StateGraph, START, END class State(TypedDict): status: str resolution: str def inspect(state: State) -> dict: return {"resolution": "escalate" if state["status"] == "payment failed" else "explain"} def route(state: State) -> str: return state["resolution"] def escalate(state: State) -> dict: return {"resolution": "manual review required"} def explain(state: State) -> dict: return {"resolution": "provide order status"} builder = StateGraph(State) builder.add_node("inspect", inspect) builder.add_node("escalate", escalate) builder.add_node("explain", explain) builder.add_edge(START, "inspect") builder.add_conditional_edges("inspect", route, { "escalate": "escalate", "explain": "explain" }) builder.add_edge("escalate", END) builder.add_edge("explain", END) graph = builder.compile() print(graph.invoke({"status": "payment failed", "resolution": ""})["resolution"])
Expected logical result: manual review required. This graph is intentionally deterministic to demonstrate explicit control. A model call can be added to a node when classification genuinely requires it. The example does not configure a checkpointer, so it does not demonstrate persistent recovery.
C. Deep Agents task-oriented harness#
PYTHONfrom deepagents import create_deep_agent def read_incident(incident_id: str) -> str: """Return a synthetic incident record for a tutorial.""" records = {"I1": "payment timeout", "I2": "payment timeout"} return records.get(incident_id, "not found") agent = create_deep_agent( model="openai:gpt-4o-mini", tools=[read_incident], system_prompt=( "Investigate synthetic incident records, identify shared " "patterns, and distinguish evidence from hypotheses." ) ) result = agent.invoke({ "messages": [{"role": "user", "content": "Compare incidents I1 and I2."}] }) print(result["messages"][-1].content)
The desired output identifies the common timeout while not inferring a root cause from insufficient evidence. This illustrates the builder, not a production workspace or a claim that delegation or file access occurred. Configure supported backends and restrict their permissions explicitly before granting access to real files.
5. Locally tested selection and commit-policy example#
The following standard-library example expresses a decision heuristic separately from the frameworks and tests the critical distinction between selecting an orchestration abstraction and authorizing an external action. It is executable without model calls.
PYTHONfrom dataclasses import dataclass from typing import Literal Choice = Literal['LangChain', 'LangGraph', 'Deep Agents', 'Plain workflow'] @dataclass(frozen=True) class Requirements: needs_model_decisions: bool = True explicit_process: bool = False long_open_ended_workspace_task: bool = False def choose(req: Requirements) -> Choice: if not req.needs_model_decisions: return 'Plain workflow' if req.explicit_process: return 'LangGraph' if req.long_open_ended_workspace_task: return 'Deep Agents' return 'LangChain' def can_commit(*, authorized: bool, evidence_ok: bool, approval_required: bool, approved: bool) -> bool: return authorized and evidence_ok and (not approval_required or approved) assert choose(Requirements()) == 'LangChain' assert choose(Requirements(explicit_process=True)) == 'LangGraph' assert choose(Requirements(long_open_ended_workspace_task=True)) == 'Deep Agents' assert choose(Requirements(explicit_process=True, long_open_ended_workspace_task=True)) == 'LangGraph' assert choose(Requirements(needs_model_decisions=False)) == 'Plain workflow' assert can_commit(authorized=True, evidence_ok=True, approval_required=True, approved=True) assert not can_commit(authorized=False, evidence_ok=True, approval_required=False, approved=True) assert not can_commit(authorized=True, evidence_ok=False, approval_required=False, approved=True) assert not can_commit(authorized=True, evidence_ok=True, approval_required=True, approved=False) print('9 assertions passed')
Actual local result on Python 3.13.5: 9 assertions passed. This verifies the illustrative selection policy and Boolean commit gate, not the SDKs, external authentication, or real-world financial transactions. In production, derive these flags from trusted services; do not accept a model's assertion that authorization or approval exists.
6. Numerical example: measure work rather than assume an abstraction is faster#
Imagine the following three runs on synthetic tasks. These are illustrative calculations, not measured framework benchmarks.
| Run | Model input tokens | Model output tokens | Tool calls | Elapsed time |
|---|---|---|---|---|
| Small lookup agent | 4,000 | 800 | 2 | 4 s |
| Controlled refund workflow | 6,000 | 1,000 | 4 | 7 s excluding human wait |
| Extended investigation | 60,000 | 8,000 | 30 | 100 s |
At hypothetical model prices of $2 per million input tokens and $8 per million output tokens, the model charges are:
- Small lookup: 4,000 × $2/1,000,000 + 800 × $8/1,000,000 = $0.0144.
- Refund: 6,000 × $2/1,000,000 + 1,000 × $8/1,000,000 = $0.0200.
- Investigation: 60,000 × $2/1,000,000 + 8,000 × $8/1,000,000 = $0.1840.
These tasks differ in complexity; comparing their costs does not establish that one framework is intrinsically faster or cheaper. Compare candidate implementations on the same task set, same model and comparable tool permissions, accounting for caching, provider pricing, retries, infrastructure and human review. Measure cost per successful task, outcome correctness, latency percentiles, unnecessary actions and failure recovery.
7. Choose the abstraction based on the task#
This is a starting heuristic, not a universal rule. A controlled outer graph can invoke a high-level agent for a bounded research subtask. A plain workflow may call a model for extraction without introducing an agent loop. Prefer the simplest design that achieves the required quality and operational controls.
8. Production failure modes and engineering controls#
| Failure | Engineering response |
|---|---|
| The tool loop repeats an unsuccessful action | Bound model calls and steps, classify errors, require new evidence before retry |
| A graph gets stuck in a cycle | Set explicit termination and test every routing branch |
| A resumed node repeats a write | Use durable idempotency keys and reconcile uncertain outcomes |
| A subagent receives unnecessary sensitive context | Scope tools and data per task; redact and authorize before delegation |
| A workspace contains malicious instructions | Treat files and tool output as untrusted data; enforce policy outside model prompts |
| Long tasks exceed time or token limits | Set per-run and delegated budgets; return a useful partial result |
| A checkpoint is restored under incompatible code | Version schemas, tools and routing logic; test migration or pin active runs |
| A claimed result lacks evidence | Independently validate against authoritative systems and record provenance |
| A framework upgrade changes behavior | Pin versions, use fixture-based regression tests, compare traces and deploy gradually |
Checkpointing is not equivalent to exactly-once external execution. Workspace storage is not equivalent to a secure sandbox. Delegation is not equivalent to permission transfer. Even a high-level harness requires application-side identity, least privilege, tenant isolation, audit logs and explicit approval for sensitive actions.
9. Testing and migration strategy#
- Unit-test deterministic nodes, tool contracts, output validators and authorization decisions.
- Use deterministic model substitutes for expected tool sequences and malformed outputs.
- Test checkpoints, resumed runs, repeated events, failed tools, timeout and cancellation paths.
- Evaluate final outcomes and intermediate actions separately using representative tasks.
- When moving from a high-level agent to a custom graph, preserve tool signatures and business policies first, then compare traces and observable outcomes.
- When introducing a deeper harness, grant workspace or delegation capabilities incrementally and measure whether they improve success on the same tasks.
Do not choose a framework by feature count alone. Team familiarity, operational requirements, model/provider support, dependency stability and the cost of owning orchestration code all matter.
Interview-ready answer#
LangChain provides convenient abstractions for models, tools and ordinary agent loops. LangGraph provides explicit stateful orchestration, making graph topology, routing, persistence and interruption controllable. Deep Agents adds an opinionated harness for extended tasks involving planning, artifacts and delegated agents. Modern LangChain agents build on LangGraph, and Deep Agents uses the same ecosystem, so these approaches can be combined. I start with the simplest abstraction that satisfies the task, use explicit graph transitions when process control matters, and consider a deep-agent harness when extended exploratory work justifies it. In every case, security and side-effect authorization remain deterministic application responsibilities.
References and verification status#
Official documentation entry points for further research (not live-accessed in this session):
Research used the authorized offline exception and existing MachinoAI framework conventions. The local standard-library example passed nine assertions. The SDK-specific snippets are illustrative and unexecuted: LangChain, LangGraph and deepagents were not installed, and live documentation and provider credentials were unavailable. Verify supported APIs and exact package versions before integration. Mermaid diagrams are stored as standard fenced blocks; live renderer validation was unavailable. No performance measurements are claimed.
References
- 1.LangChain overviewdocs.langchain.com
- 2.LangChain agentsdocs.langchain.com
- 3.LangGraph overviewdocs.langchain.com
- 4.Deep Agents overviewdocs.langchain.com
- 5.LangChain API referencereference.langchain.com
Related questions
Explore other topics:Forward Deployed EngineeringLarge Language ModelsRetrieval-Augmented GenerationMLOps