← Back to Blog
AI / MLMarch 22, 20265 min read

Migrating from LangChain Chains to LangGraph Agents

When and how to move from LangChain linear chains to LangGraph graph-based agent orchestration.

Signs you need LangGraph

LangChain is a framework to build LLM applications. LangGraph is a framework to orchestrate complex agents built with LangChain. You need LangGraph when your chain grows conditional branches, retry loops, human approval steps, or multiple cooperating agents.

chain_vs_graph.pyPython
# LangChain: linear chain
chain = retriever | prompt | llm | parser
result = chain.invoke(query)

# LangGraph: graph with state and cycles
graph = StateGraph(AgentState)
graph.add_node("retrieve", retrieve_node)
graph.add_node("plan", plan_node)
graph.add_node("validate", validate_node)
graph.add_conditional_edges("validate", should_retry, {"retry": "plan", "done": END})
agent = graph.compile()
result = agent.invoke({"query": query})

The migration is incremental. LangGraph nodes can call existing LangChain chains internally. You do not rewrite everything. You wrap chains in graph nodes and add state management around them.