Learning Library

← Back to Library

LangChain vs LangGraph Explained

Key Points

  • LangChain is an open‑source framework that lets developers build LLM‑powered applications by chaining modular components (e.g., document loaders, text splitters, prompts, LLMs, memory) to execute linear workflows such as retrieve → summarize → answer.
  • Its flexible architecture allows different components—and even different language models—to be combined in each step, enabling complex pipelines without hard‑coding logic.
  • LangGraph is a specialized library within the LangChain ecosystem designed for creating stateful, multi‑agent systems that can manage non‑linear, branching workflows.
  • While LangChain excels at straightforward sequential chains, LangGraph adds graph‑based control flow and persistent state, making it suitable for more intricate tasks like a task‑management assistant that coordinates multiple agents.

Full Transcript

# LangChain vs LangGraph Explained **Source:** [https://www.youtube.com/watch?v=qAF1NjEVHhY](https://www.youtube.com/watch?v=qAF1NjEVHhY) **Duration:** 00:09:42 ## Summary - LangChain is an open‑source framework that lets developers build LLM‑powered applications by chaining modular components (e.g., document loaders, text splitters, prompts, LLMs, memory) to execute linear workflows such as retrieve → summarize → answer. - Its flexible architecture allows different components—and even different language models—to be combined in each step, enabling complex pipelines without hard‑coding logic. - LangGraph is a specialized library within the LangChain ecosystem designed for creating stateful, multi‑agent systems that can manage non‑linear, branching workflows. - While LangChain excels at straightforward sequential chains, LangGraph adds graph‑based control flow and persistent state, making it suitable for more intricate tasks like a task‑management assistant that coordinates multiple agents. ## Sections - [00:00:00](https://www.youtube.com/watch?v=qAF1NjEVHhY&t=0s) **LangChain vs LangGraph Overview** - The speaker outlines LangChain’s chain‑based LLM workflow—retrieving data, summarizing it, and answering questions—to contrast it with the newer LangGraph framework. - [00:03:08](https://www.youtube.com/watch?v=qAF1NjEVHhY&t=188s) **LangGraph for Stateful Task Workflow** - The speaker explains how LangGraph extends LangChain to model a task‑management assistant as a graph of nodes (process input, add, complete, summarize) linked by edges, with a shared state component that maintains the task list across interactions. - [00:06:15](https://www.youtube.com/watch?v=qAF1NjEVHhY&t=375s) **LangChain vs LangGraph Structures** - The speaker contrasts LangChain’s DAG‑based chain, which executes tasks in a fixed forward order, with LangGraph’s flexible graph that supports loops, state revisits, and richer state management, while outlining their respective components. - [00:09:27](https://www.youtube.com/watch?v=qAF1NjEVHhY&t=567s) **Introducing LangChain and LangGraph** - The speaker briefly outlines LangChain and LangGraph as powerful frameworks for building LLM-powered applications and invites viewers to watch a related LangChain video. ## Full Transcript
0:00LangChain and LangGraph are both open source frameworks designed to help developers build applications with large language models. 0:09So what are the differences and why use one over the other? 0:13Well, I think a good place to start. Is to define what these two things are, and let's begin with LangChain. 0:20Now, we've done a dedicated video on LangChain, and my guess is there's probably a pop up somewhere over my head right now 0:27encouraging you to watch that video. 0:28But don't click, not yet. Give me a moment to summarize LangChain. 0:33Then at the end of this video, if you want any more, you can go back and check that one out. 0:38Okay. Now, at its core, LangChain is a way for building LLM powered applications by executing a sequence of functions in a chain. 0:48So let's say we're building an application and the first thing it needs to do is it needs to retrieve some data from a website. 1:00Once we've done that, we move on to stage two, 1:03And stage two is to summarize that data that we retrieved. 1:11And then finally, we're going to use this summary to do something, 1:15specifically, We're going to have it answer user questions. 1:21So the workflow here is retrieve, summarize, and answer 1:26Now we can use the LangChain to help us do this. 1:30So let's start with the retrieve component. 1:32Now, the retrieve component might consist of a LangChain component called a document loader. 1:41Now a document loader is used to fetch and load content from various data sources, 1:46and if some of those documents are large, we might choose to use a text splitter, 1:53which is another LangChain component to split takes up into smaller, semantically meaningful chunks. 2:01Okay, that's retrieve. 2:03Now To summarize, we would use a chain, and the chain will orchestrate the summarization process. 2:11Now, that might include constructing a prompt component to instruct an LLM to perform the summarization. 2:21And that might also contain an LLM component to pass that request to the large language model of our choosing. 2:29Okay, and then answer. 2:31Well, we would build another chain and this chain might include a memory component, 2:40so this is another component of LangChain, and that's used to store conversation, history and context, 2:46And we'd throw in another prompt component and another LLM component to generate the answer based on the summary and the record context. 2:56And the cool thing here is that the LLM that we use for the answer component, 3:02may be a completely different large language model to the one we use in the summarize component. 3:08LangChain modular architecture let's build complex workflows by combining these high level components. 3:17Okay, now let's introduce LangGraph. 3:19LangGraph is a specialized library within the LangChain ecosystem, 3:24specifically designed for building stateful multi-agent systems that can handle complex nonlinear workflows. 3:31So let's consider a task management assistant agent. 3:36Now, the workflow here involves processing user input. 3:40So let's start there, Process inputs, 3:45And then to this workflow we are going to allow to add tasks, we're going to be able to complete tasks, and we are also going to be able to summarize task. 4:05So this is the kind of the architecture of what we're trying to build here. 4:10Now, LangGraph helps us create this as a graph structure, 4:15where each one of these actions is considered as a node. 4:21So at tasks, complete tasks, summarize, they're all nodes. 4:25And then the transitions between these things, that's known as edges. 4:29Now the central mode is the process input node. 4:32So that's where the user input comes in, 4:34and that's going to use an LLM component to understand the user intent and to route to the appropriate action node. 4:41Now there's another component here that's quite central to this called state, the state component. 4:49And the state component is used to maintain the task list across all the interaction. 4:55So the adds task node adds new tasks to the state, 5:00the complete task node marks tasks as finished, 5:05and then the summarize node uses an LLM to generate an overview of current tasks. 5:12All nodes can access and modify the state allowing for contextual stateful interactions. 5:19The graph structure allows the assistant to handle various user requests in any order, 5:25always returning back to the process input node after the action is complete. 5:33LangGraph Architecture lets us create flexible stateful agents that can maintain context over extended interactions. 5:42So let's directly compare, LangChain and LangGraph across a number of dimensions. 5:46Let's start with the primary focus. 5:49Now the Primary focus of LangGraph Is to create and manage what is known as multi agent systems and workflows. 6:02The focus of LangChain is to provide an abstraction layer for chaining LLM operations into large language model applications. 6:13That's the difference between the two. 6:15Now, as for. Structure, LangChain adopts no surprise here a chain structure. 6:24And that acts as a Dag, 6:26that is an acronym for directed acyclic graph, 6:29Which means that tasks are executed in a specific order always moving forward. 6:35So, for example, we start with task number one then we'd have a branch for maybe tasks number two and task three, 6:43and then we'd come back to the central task number four. 6:47And this process is great where you know the exact sequence of steps that are needed. 6:54Now, LangGraph's graph structure, on the other hand, is a little bit different because it allows for loops and revisiting previous states. 7:05So we might have state A which can go backwards and forwards with state B and State C, 7:12and this is beneficial for interactive systems where the next step might depend on evolving conditions or user input. 7:19Now, when it comes to components, LangChain uses a bunch and we've mentioned many of these already, 7:27that includes memory, There's the prompt component as well, There's also the LLM component, 7:35which is how we actually pass things to the large language model, 7:39And there's the agent component as well that forms, chains between all of these things. 7:46Now, LangGraph uses a bunch of different components. 7:49So we have nodes, we also have edges, And we have states, 7:58and these are all part of a graph. 8:02And speaking of state. That brings us nicely to state management. 8:07I don't think we can say that LangChain has somewhat limited state management capabilities. 8:15It can pass information forth through the chain, 8:18but it doesn't easily maintain a persistent state across multiple runs. 8:22That said, LangChain does have these memory components that can maintain some state across interactions. 8:29LangGraph's state management, I'm going to say, is more robust, 8:36And that's because state is a core component that all nodes can access and modify, 8:42allowing for more complex, context aware behaviors. 8:46Let's say use cases. 8:48Well, LangChain really excels, particularly at sequential tasks like a process that retrieves data and then processes it and then outputs a result. 8:58Again, that said, LangChain is able to handle non sequential tasks to some extent with its own agents feature, 9:05but LangGraph's wheelhouse that really is. Scenarios that have a much more complex nature to them. 9:15Complex systems requiring ongoing interaction and adaptation. 9:19For example, a virtual assistant that needs to maintain context over long conversations and handle varying types of requests. 9:27So that LangChain and LangGraph, two powerful frameworks for building applications that make use of large language models. 9:38All right. That's all I got. 9:40You can go watch that LangChain video now.