AI engineering · · 4 min read
LangChain vs LangGraph: When Your AI Workflow Actually Needs an Agent
How to choose between a simple LLM chain, a deterministic workflow, and a LangGraph agent, with practical patterns for state, tool calling, retries, and human approval.
"Agent" is the most overused word in AI right now. Many projects that are described as agents would be cheaper, faster, and more reliable as a plain sequence of steps. Others really do need an agent's ability to loop, branch, and recover. Choosing correctly early on saves weeks.
This post explains how we decide, and how LangChain and LangGraph fit in.
The three levels of LLM application
Level 1: a single call or a chain. Input goes in, one or a few LLM calls run in a fixed order, and output comes out. Examples: summarizing a document, classifying a support ticket, extracting fields from an invoice. LangChain (or just the model provider's SDK) is plenty.
Level 2: a deterministic workflow. Several steps with branching that you define in code. "If the ticket is about billing, look up the account, then draft a reply; otherwise route to a human." The LLM makes decisions inside steps, but your code controls the flow.
Level 3: an agent. The model decides which tool to call next, looks at the result, and decides again, until the task is done. Examples: researching a question across several systems, or fixing a failing data import by inspecting and retrying.
The rule of thumb: use the lowest level that solves the problem. Every step up adds latency, cost, and new ways to fail.
Where LangGraph fits
LangGraph models an application as a graph: nodes are steps, edges decide what runs next, and a shared state object flows through it. That makes it useful for both level 2 and level 3. You can build a fully deterministic workflow, a free-roaming agent, or, most usefully, something in between.
Its main advantages over hand-written loops:
- Explicit state. Everything the workflow knows lives in one typed object, which makes it easy to inspect and debug.
- Checkpointing. State is saved after each step, so a long-running workflow can pause, resume, or recover after a failure.
- Human-in-the-loop interrupts. The graph can stop before a sensitive step, wait for a person to approve it, and continue.
- Cycles with limits. Loops such as "try, check, retry" are first-class, with a cap on iterations.
A practical pattern: a bounded agent inside a workflow
Most of our production systems look like this: a deterministic outer workflow, with a small, bounded agent only where flexibility is actually needed.
from typing import TypedDict
from langgraph.graph import StateGraph, END
class TicketState(TypedDict):
ticket: str
category: str
context: list[str]
draft: str
approved: bool
graph = StateGraph(TicketState)
graph.add_node("classify", classify_ticket) # one LLM call
graph.add_node("research", research_agent) # bounded tool-calling agent
graph.add_node("draft", draft_reply) # one LLM call
graph.add_node("review", wait_for_human_approval) # interrupt
graph.add_node("send", send_reply)
graph.set_entry_point("classify")
graph.add_conditional_edges(
"classify",
lambda s: "research" if s["category"] != "spam" else END,
)
graph.add_edge("research", "draft")
graph.add_edge("draft", "review")
graph.add_conditional_edges("review", lambda s: "send" if s["approved"] else END)
graph.add_edge("send", END)
app = graph.compile(checkpointer=checkpointer, interrupt_before=["send"])The only open-ended part is research, which can call a fixed set of read-only tools (order lookup, knowledge base search) for a limited number of steps. Everything else is predictable.
Tool design matters more than prompts
When an agent misbehaves, the cause is usually the tools, not the model.
- Keep tools few and specific. Five well-named tools beat twenty overlapping ones.
- Write tool descriptions for the model. Say when to use the tool, when not to, and what it returns.
- Return compact, structured results. Don't dump a 5,000-row API response into the context.
- Separate read and write tools. Read-only tools can run freely. Anything that sends, deletes, charges, or updates should require approval or go through strict validation.
- Make errors useful. "Order not found. Check the order ID format: 8 digits" lets the agent recover. A stack trace does not.
Reliability checklist
Before an agent goes to production, we check:
- A maximum number of steps and a timeout.
- Structured, validated outputs at every step that feeds code.
- Retries with backoff for model and API errors.
- Human approval before irreversible actions.
- Tracing of every step (LangSmith or OpenTelemetry), so failures can be replayed.
- An evaluation set of real tasks, run on every prompt or model change.
- Cost tracking per run, since agent loops can quietly get expensive.
So, which should you use?
- Fixed steps, one or two LLM calls: plain SDK or LangChain.
- Multiple steps with branches, retries, or approvals: LangGraph as a workflow.
- Genuinely open-ended tasks across several tools: a bounded LangGraph agent, ideally inside a workflow.
If you are unsure which level your project needs, that is exactly the kind of question we answer in a free discovery call. See our LangChain and LangGraph services or get in touch.
Topics: LangGraph, LangChain, AI agents, LLM workflows, tool calling