1
00:00:06,000 --> 00:00:12,680
LangChain and LangGraph are both open source frameworks designed to help developers build

2
00:00:12,680 --> 00:00:15,800
applications with large language models.

3
00:00:15,800 --> 00:00:19,280
So what are the differences and why use one over the other?

4
00:00:19,280 --> 00:00:23,559
Well, I think a good place to start is to define what these two things are.

5
00:00:23,559 --> 00:00:26,520
And let's begin with LangChain.

6
00:00:26,520 --> 00:00:31,319
Now we've done a dedicated video on LangChain, and my guess is there's probably a pop-up

7
00:00:31,319 --> 00:00:35,319
somewhere over my head right now encouraging you to watch that video.

8
00:00:35,319 --> 00:00:37,400
But don't click, not yet.

9
00:00:37,400 --> 00:00:39,840
Give me a moment to summarize LangChain.

10
00:00:39,840 --> 00:00:43,680
Then at the end of this video, if you want to know more, you can go back and check that

11
00:00:43,680 --> 00:00:44,680
one out.

12
00:00:44,680 --> 00:00:45,680
Okay.

13
00:00:45,680 --> 00:00:51,959
Now at its core, LangChain is a way for building LLM powered applications by executing a sequence

14
00:00:51,959 --> 00:00:54,360
of functions in a chain.

15
00:00:54,360 --> 00:01:00,119
So let's say we're building an application, and the first thing it needs to do is it needs

16
00:01:00,119 --> 00:01:06,519
to retrieve some data from a website.

17
00:01:06,519 --> 00:01:10,000
Once we've done that, we move on to stage two.

18
00:01:10,000 --> 00:01:17,879
And stage two is to summarize that data that we retrieved.

19
00:01:17,879 --> 00:01:22,120
And then finally, we're going to use this summary to do something.

20
00:01:22,120 --> 00:01:27,959
Specifically, we're going to have it answer user questions.

21
00:01:27,959 --> 00:01:33,239
So the workflow here is retrieve, summarize, and answer.

22
00:01:33,239 --> 00:01:36,440
Now we can use the LangChain to help us do this.

23
00:01:36,440 --> 00:01:39,040
So let's start with the retrieve component.

24
00:01:39,040 --> 00:01:48,040
Now the retrieve component might consist of a LangChain component called a document loader.

25
00:01:48,040 --> 00:01:53,080
Now a document loader is used to fetch and load content from various data sources.

26
00:01:53,080 --> 00:02:00,120
And if some of those documents are large, we might choose to use a text splitter, which

27
00:02:00,120 --> 00:02:07,239
is another LangChain component, to split text up into smaller, semantically meaningful chunks.

28
00:02:07,239 --> 00:02:09,720
Okay, that's retrieve.

29
00:02:09,720 --> 00:02:15,320
Now to summarize, we would use a chain.

30
00:02:15,320 --> 00:02:18,199
And the chain will orchestrate the summarization process.

31
00:02:18,199 --> 00:02:26,199
Now that might include constructing a prompt component to instruct an LLM to perform the

32
00:02:26,199 --> 00:02:27,479
summarization.

33
00:02:27,479 --> 00:02:33,479
And it might also contain an LLM component to pass that request to the large language

34
00:02:33,479 --> 00:02:35,000
model of our choosing.

35
00:02:35,000 --> 00:02:36,000
Okay.

36
00:02:36,000 --> 00:02:41,720
And then for answer, well, we would build another chain.

37
00:02:41,960 --> 00:02:46,679
This chain might include a memory component.

38
00:02:46,679 --> 00:02:51,160
So this is another component of LangChain, and that's used to store conversation history

39
00:02:51,160 --> 00:02:52,679
in context.

40
00:02:52,679 --> 00:02:59,320
And we'd throw in another prompt component and another LLM component to generate the

41
00:02:59,320 --> 00:03:03,000
answer based on the summary and the record context.

42
00:03:03,000 --> 00:03:10,039
And the cool thing here is that the LLM that we use for the answer component may be a completely

43
00:03:10,119 --> 00:03:14,839
different large language model to the one we use in the summarize component.

44
00:03:14,839 --> 00:03:21,559
LangChain's modular architecture lets us build complex workflows by combining these high

45
00:03:21,559 --> 00:03:22,520
level components.

46
00:03:23,399 --> 00:03:25,800
Okay, now let's introduce LangGraph.

47
00:03:25,800 --> 00:03:31,080
LangGraph is a specialized library within the LangChain ecosystem, specifically designed

48
00:03:31,080 --> 00:03:33,960
for building stateful multi-agent systems.

49
00:03:33,960 --> 00:03:37,720
It can handle complex, non-linear workflows.

50
00:03:37,720 --> 00:03:42,119
So let's consider a task management assistant agent.

51
00:03:42,119 --> 00:03:46,199
Now, the workflow here involves processing user input.

52
00:03:46,199 --> 00:03:51,000
So let's start there, process input.

53
00:03:51,720 --> 00:03:58,520
And then to this workflow, we are going to allow to add tasks.

54
00:03:59,160 --> 00:04:09,720
We're going to be able to complete tasks, and we're also going to be able to summarize

55
00:04:10,520 --> 00:04:11,000
tasks.

56
00:04:11,800 --> 00:04:16,200
So this is the kind of the architecture of what we're trying to build here.

57
00:04:16,760 --> 00:04:23,079
Now, LangGraph helps us create this as a graph structure where each one of these actions

58
00:04:23,079 --> 00:04:26,279
is considered as a node.

59
00:04:27,239 --> 00:04:31,160
So add tasks, complete tasks, summarize, they're all nodes.

60
00:04:31,160 --> 00:04:35,079
And then the transitions between these things, that's known as edges.

61
00:04:35,720 --> 00:04:38,279
Now, the central node is the process input node.

62
00:04:38,279 --> 00:04:40,359
So that's where the user input comes in.

63
00:04:40,359 --> 00:04:44,920
And that's going to use an LLM component to understand the user intent and to route to

64
00:04:44,920 --> 00:04:46,839
the appropriate action node.

65
00:04:47,399 --> 00:04:54,200
Now, there's another component here that's quite central to this called state, the state

66
00:04:54,200 --> 00:04:54,839
component.

67
00:04:55,480 --> 00:05:00,760
And the state component is used to maintain the task list, cross all the interaction.

68
00:05:01,480 --> 00:05:07,079
So the add task node adds new tasks to the state.

69
00:05:07,079 --> 00:05:11,640
The complete task node marks tasks as finished.

70
00:05:11,640 --> 00:05:17,720
And then the summarize node uses an LLM to generate an overview of current tasks.

71
00:05:18,359 --> 00:05:24,760
All nodes can access and modify the state, allowing for contextual stateful interactions.

72
00:05:25,559 --> 00:05:30,839
The graph structure allows the assistant to handle various user requests in any order,

73
00:05:31,399 --> 00:05:38,839
always returning back to the process input node after the action is complete.

74
00:05:39,720 --> 00:05:45,320
LangGraph's architecture lets us create flexible, stateful agents that can maintain context

75
00:05:45,320 --> 00:05:47,079
over extended interactions.

76
00:05:48,359 --> 00:05:52,679
So let's directly compare LangChain and LangGraph across a number of dimensions.

77
00:05:52,679 --> 00:05:55,559
Let's start with the primary focus.

78
00:05:55,559 --> 00:06:04,600
Now, the primary focus of LangGraph is to create and manage what is known as multi-agent

79
00:06:05,320 --> 00:06:07,640
systems and workflows.

80
00:06:08,279 --> 00:06:16,359
The focus of LangChain is to provide an abstraction layer for chaining LLM operations into large

81
00:06:16,359 --> 00:06:19,320
language model applications.

82
00:06:19,320 --> 00:06:21,000
That's the difference between the two.

83
00:06:21,880 --> 00:06:30,760
Now, as for structure, LangChain adopts, no surprise here, a chain structure, and that

84
00:06:30,760 --> 00:06:32,519
acts as a DAG.

85
00:06:32,519 --> 00:06:38,839
DAG is an acronym for directed acyclic graph, which means that tasks are executed in a specific

86
00:06:38,839 --> 00:06:41,239
order, always moving forward.

87
00:06:41,239 --> 00:06:47,239
So for example, we start with task number one, then we'd have a branch for maybe task

88
00:06:47,239 --> 00:06:54,040
number two and task three, and then we'd come back to the central task number four.

89
00:06:54,040 --> 00:06:59,959
And this process is great where you know the exact sequence of steps that are needed.

90
00:07:00,839 --> 00:07:07,559
Now, LangGraph's graph structure, on the other hand, is a little bit different because it

91
00:07:07,559 --> 00:07:11,320
allows for loops and revisiting previous states.

92
00:07:11,320 --> 00:07:18,760
So we might have state A, which can go backwards and forwards with state B, and state C.

93
00:07:18,760 --> 00:07:23,959
And this is beneficial for interactive systems where the next step might depend on evolving

94
00:07:23,959 --> 00:07:25,320
conditions or user input.

95
00:07:25,880 --> 00:07:32,279
Now, when it comes to components, LangChain uses a bunch, and we've mentioned many of

96
00:07:32,279 --> 00:07:33,559
these already.

97
00:07:33,559 --> 00:07:35,239
That includes memory.

98
00:07:35,959 --> 00:07:39,399
There's the prompt component as well.

99
00:07:39,880 --> 00:07:44,600
There's also the LLM component, which is how we actually pass things to the large language

100
00:07:44,600 --> 00:07:45,320
model.

101
00:07:45,320 --> 00:07:51,720
And there's the agent component as well, that forms chains between all of these things.

102
00:07:52,519 --> 00:07:55,640
Now, LangGraph uses a bunch of different components.

103
00:07:55,640 --> 00:08:03,160
So we have nodes, we also have edges, and we have states.

104
00:08:04,920 --> 00:08:07,559
And these are all part of a graph.

105
00:08:08,440 --> 00:08:13,239
And speaking of state, that brings us nicely to state management.

106
00:08:13,239 --> 00:08:21,079
And I think we can say that LangChain has somewhat limited state management capabilities.

107
00:08:21,079 --> 00:08:26,440
It can pass information forward through the chain, but it doesn't easily maintain a persistent

108
00:08:26,440 --> 00:08:27,720
state across multiple runs.

109
00:08:28,279 --> 00:08:33,960
That said, LangChain does have these memory components that can maintain some state across

110
00:08:33,960 --> 00:08:34,599
interactions.

111
00:08:35,400 --> 00:08:41,159
LangGraph's state management, I'm going to say, is more robust.

112
00:08:42,280 --> 00:08:48,840
And that's because state is a core component that all nodes can access and modify, allowing

113
00:08:48,840 --> 00:08:51,719
for more complex, context-aware behaviors.

114
00:08:52,359 --> 00:08:54,119
Let's think use cases.

115
00:08:54,119 --> 00:09:01,880
Well, LangChain really excels particularly at sequential tasks, like a process that retrieves

116
00:09:01,880 --> 00:09:04,440
data and then processes it and then outputs a result.

117
00:09:05,000 --> 00:09:10,679
Again, that said, LangChain is able to handle non-sequential tasks to some extent with its

118
00:09:10,679 --> 00:09:12,440
own agents feature.

119
00:09:13,000 --> 00:09:20,679
But LangGraph's wheelhouse, that really is scenarios that have a much more complex nature

120
00:09:20,679 --> 00:09:21,479
to them.

121
00:09:21,479 --> 00:09:25,960
Complex systems requiring ongoing interaction and adaptation.

122
00:09:25,960 --> 00:09:30,599
For example, a virtual assistant that needs to maintain context over long conversations

123
00:09:30,599 --> 00:09:32,919
and handle varying types of requests.

124
00:09:33,479 --> 00:09:40,919
So that's LangChain and LangGraph, two powerful frameworks for building applications that

125
00:09:40,919 --> 00:09:43,320
make use of large language models.

126
00:09:44,520 --> 00:09:46,679
All right, that's all I got.

127
00:09:46,679 --> 00:09:51,400
You can go watch that LangChain video now.