WEBVTT

1
00:00:00.300 --> 00:00:03.360
<v ->Cool, so let's check out what we get</v>

2
00:00:03.360 --> 00:00:05.280
and then you'll understand what's happening.

3
00:00:05.280 --> 00:00:09.420
Alright, so here we can see that we have here the answer.

4
00:00:09.420 --> 00:00:11.220
Now let me show you now the result,

5
00:00:11.220 --> 00:00:14.340
which is going to be the result of the agent execution.

6
00:00:14.340 --> 00:00:18.720
So in the result here, we have here an answer

7
00:00:18.720 --> 00:00:20.850
and we have here the context.

8
00:00:20.850 --> 00:00:23.370
So you can see the context here are a bunch of documents

9
00:00:23.370 --> 00:00:25.200
and we can see their IDs

10
00:00:25.200 --> 00:00:28.380
and we can see what are their sources,

11
00:00:28.380 --> 00:00:32.490
this metadata and those are going to be the documents

12
00:00:32.490 --> 00:00:34.590
which help us come up with the answer.

13
00:00:34.590 --> 00:00:36.510
Here we can see the answer.

14
00:00:36.510 --> 00:00:40.770
Now let me show you where everything came from, alright?

15
00:00:40.770 --> 00:00:43.470
Alright, so let's go and debug this.

16
00:00:43.470 --> 00:00:45.990
So I'm going to put a break point.

17
00:00:45.990 --> 00:00:49.470
Let's go and put a break point here

18
00:00:49.470 --> 00:00:53.010
and let me go and run it in debug mode.

19
00:00:53.010 --> 00:00:56.580
Cool, so we got here, and let's go and check out

20
00:00:56.580 --> 00:00:59.430
what happened after we invoked here, this agent.

21
00:00:59.430 --> 00:01:02.543
So let's go and check this response variable here

22
00:01:02.543 --> 00:01:05.790
because this is going to be holding the entire information,

23
00:01:05.790 --> 00:01:07.260
all of the information we need.

24
00:01:07.260 --> 00:01:11.670
Alright, so let's go and check out the response object.

25
00:01:11.670 --> 00:01:15.000
And here we're going to have a list of messages.

26
00:01:15.000 --> 00:01:17.490
The first message is going to be our input,

27
00:01:17.490 --> 00:01:21.000
which was "What are deep agents?"

28
00:01:21.000 --> 00:01:23.310
And you can see we reacted as a human message.

29
00:01:23.310 --> 00:01:26.250
LangChain, I remind you, it's converted it into

30
00:01:26.250 --> 00:01:29.280
a human message object by itself.

31
00:01:29.280 --> 00:01:32.040
Then it had a tool call.

32
00:01:32.040 --> 00:01:34.860
We can see now this AI message is a tool call

33
00:01:34.860 --> 00:01:38.610
which wants to invoke the retrieve context tool.

34
00:01:38.610 --> 00:01:40.890
So we can see here this is a tool call

35
00:01:40.890 --> 00:01:44.820
which want to use the retrieve context tool

36
00:01:44.820 --> 00:01:47.880
and this is the query it's going to send it

37
00:01:47.880 --> 00:01:50.760
and we have the ID and everything.

38
00:01:50.760 --> 00:01:54.510
And now LangChain is going to be executing this tool call.

39
00:01:54.510 --> 00:01:58.440
So after the tool call, we are getting a tool message.

40
00:01:58.440 --> 00:02:00.300
So this tool message is going

41
00:02:00.300 --> 00:02:03.120
to contain this tool response here.

42
00:02:03.120 --> 00:02:05.340
So the result of the tool execution.

43
00:02:05.340 --> 00:02:09.210
Now because we used the response format of content

44
00:02:09.210 --> 00:02:12.060
and artifact, we are returning here two values.

45
00:02:12.060 --> 00:02:14.100
This is going to be the content

46
00:02:14.100 --> 00:02:17.400
and this is going to be the artifact.

47
00:02:17.400 --> 00:02:20.550
So right here in the tool message here,

48
00:02:20.550 --> 00:02:24.360
if I'm going to go to the content attribute,

49
00:02:24.360 --> 00:02:26.640
we can see here this string here

50
00:02:26.640 --> 00:02:29.040
and we can see it starts with source,

51
00:02:29.040 --> 00:02:31.140
then it's going to have the sources

52
00:02:31.140 --> 00:02:33.060
and then it's going to have the content

53
00:02:33.060 --> 00:02:34.110
of the pages themselves.

54
00:02:34.110 --> 00:02:37.770
So this is this serialized string we formatted nicely

55
00:02:37.770 --> 00:02:42.630
which this we want to downstream into the LLM.

56
00:02:42.630 --> 00:02:47.250
And then we have now the retrieved docs here

57
00:02:47.250 --> 00:02:49.710
and this is going to be the artifact.

58
00:02:49.710 --> 00:02:53.490
So here we are going to have an artifact.

59
00:02:53.490 --> 00:02:56.870
Let's go and look for the artifact. Here you go.

60
00:02:56.870 --> 00:03:00.840
An artifact here is going to be a list of the documents.

61
00:03:00.840 --> 00:03:04.650
So this is the document, this is the page content

62
00:03:04.650 --> 00:03:08.730
about deep agents and why this is important

63
00:03:08.730 --> 00:03:10.470
and why did we do it.

64
00:03:10.470 --> 00:03:15.470
Because you see this list of messages over here?

65
00:03:15.600 --> 00:03:20.040
So when we actually go and send it to the LLM,

66
00:03:20.040 --> 00:03:23.730
the artifact is something we are not

67
00:03:23.730 --> 00:03:26.070
sending to the LLM.

68
00:03:26.070 --> 00:03:28.590
This is something for us to use in the application

69
00:03:28.590 --> 00:03:30.090
we're going to be building

70
00:03:30.090 --> 00:03:34.080
as another place to keep results here.

71
00:03:34.080 --> 00:03:35.520
So this is why it's convenient.

72
00:03:35.520 --> 00:03:38.040
So it's not going to pollute the context

73
00:03:38.040 --> 00:03:40.920
because we have already the sources,

74
00:03:40.920 --> 00:03:43.350
we have already documents, we don't really need them.

75
00:03:43.350 --> 00:03:48.350
But if we want to have a pythonic object we can work with

76
00:03:48.810 --> 00:03:52.893
to do later in the application maybe to render it nicely.

77
00:03:53.790 --> 00:03:55.530
So this is why it's used for.

78
00:03:55.530 --> 00:03:59.040
So just to reiterate on this, this tool message here,

79
00:03:59.040 --> 00:04:01.680
when we make a call to the LLM,

80
00:04:01.680 --> 00:04:03.930
the artifact is not being sent.

81
00:04:03.930 --> 00:04:07.260
So here this artifact, which is a list of documents,

82
00:04:07.260 --> 00:04:09.870
it's not going to be sent to the LLM.

83
00:04:09.870 --> 00:04:12.780
Cool, so we got to this breakpoint over here

84
00:04:12.780 --> 00:04:15.870
and here we simply formatting it nicely.

85
00:04:15.870 --> 00:04:19.530
We're taking the answer from the last place of the messages,

86
00:04:19.530 --> 00:04:21.030
you can see it right over here,

87
00:04:21.030 --> 00:04:24.720
and sending the context key with context doc

88
00:04:24.720 --> 00:04:27.000
and this is later, we can go

89
00:04:27.000 --> 00:04:30.720
and use it in our frontend maybe to render it nicely here.

90
00:04:30.720 --> 00:04:33.840
And let me go and finish here this execution.

91
00:04:33.840 --> 00:04:38.840
And here we can see all of the documents which are printed

92
00:04:39.750 --> 00:04:41.220
and here we can see the answer.

93
00:04:41.220 --> 00:04:44.520
Deep agent is a term LangChain coined for agents

94
00:04:44.520 --> 00:04:47.850
that can handle a complex open-ended tasks

95
00:04:47.850 --> 00:04:51.090
over longer time horizons.

96
00:04:51.090 --> 00:04:56.090
So now let me go and open LangSmith

97
00:04:56.460 --> 00:04:58.110
and let's see the trace.

98
00:04:58.110 --> 00:05:00.900
So when we're going to be seeing the trace here,

99
00:05:00.900 --> 00:05:04.320
it's going to be much more readable.

100
00:05:04.320 --> 00:05:08.190
So here I can open here this trace

101
00:05:08.190 --> 00:05:11.400
and we can see this ran under LangGraph

102
00:05:11.400 --> 00:05:14.190
because eventually it's going to be a LangGraph graph.

103
00:05:14.190 --> 00:05:18.600
This is the human input, "What are deep agents?"

104
00:05:18.600 --> 00:05:20.400
Then we went to the model.

105
00:05:20.400 --> 00:05:24.750
The model decided that we want to make a tool call.

106
00:05:24.750 --> 00:05:26.910
Okay, here is the system message.

107
00:05:26.910 --> 00:05:30.000
So the tool call was to retrieve context with the query

108
00:05:30.000 --> 00:05:32.490
of LangChain's deep agent's definition.

109
00:05:32.490 --> 00:05:35.550
This is cool. So it actually rephrased my question.

110
00:05:35.550 --> 00:05:38.490
So it searched in the vector store

111
00:05:38.490 --> 00:05:41.760
deep agent definition, not what are deep agents.

112
00:05:41.760 --> 00:05:44.640
So this is also nice to see.

113
00:05:44.640 --> 00:05:49.440
Then LangChain went and ran the tool

114
00:05:49.440 --> 00:05:52.440
and here you can see we used the retrieve context tool.

115
00:05:52.440 --> 00:05:55.530
So here we can see that we are using the retriever

116
00:05:55.530 --> 00:05:57.600
and we find the relevant documents

117
00:05:57.600 --> 00:05:59.037
to answer the question here.

118
00:05:59.037 --> 00:06:01.290
You can see this is the documents content,

119
00:06:01.290 --> 00:06:04.380
this is the source attribute which we made sure

120
00:06:04.380 --> 00:06:06.900
is going to be valid when we indexed the documents

121
00:06:06.900 --> 00:06:08.280
from before.

122
00:06:08.280 --> 00:06:10.230
And I want to show you something.

123
00:06:10.230 --> 00:06:14.880
If we go to the LangChain RAG agent documentation.

124
00:06:14.880 --> 00:06:19.260
Let's go here and let's look for the snippets

125
00:06:19.260 --> 00:06:20.670
right over here.

126
00:06:20.670 --> 00:06:21.870
Here we go.

127
00:06:21.870 --> 00:06:26.550
So here you can see what in the docs they're doing,

128
00:06:26.550 --> 00:06:28.830
they're using the vector store as is

129
00:06:28.830 --> 00:06:32.790
and they're using its raw similarity search tool, okay?

130
00:06:32.790 --> 00:06:35.580
Now we use the as retriever.

131
00:06:35.580 --> 00:06:40.230
Now this difference, and I urge you,

132
00:06:40.230 --> 00:06:43.170
go and try to see for yourself the difference

133
00:06:43.170 --> 00:06:45.900
why I used here the as retriever is because

134
00:06:45.900 --> 00:06:49.650
it's going to render much more nicely in LangSmith.

135
00:06:49.650 --> 00:06:52.620
Because if we were to simply use the vector store

136
00:06:52.620 --> 00:06:56.250
similarity search, then this won't be indexed

137
00:06:56.250 --> 00:06:58.890
as nicely in LangSmith in the tracing.

138
00:06:58.890 --> 00:07:01.620
So eventually we got here after the tool execution,

139
00:07:01.620 --> 00:07:03.690
we got here the docs.

140
00:07:03.690 --> 00:07:07.560
And if we'll go and check out this view over here,

141
00:07:07.560 --> 00:07:10.740
we can even see our LangGraph state under the hood.

142
00:07:10.740 --> 00:07:12.960
I know we haven't learned about LangGraph,

143
00:07:12.960 --> 00:07:15.300
but this is in case you want to see it.

144
00:07:15.300 --> 00:07:18.090
And don't worry we're going to be covering

145
00:07:18.090 --> 00:07:19.380
later in the course.

146
00:07:19.380 --> 00:07:22.590
Here we made the final LLM call.

147
00:07:22.590 --> 00:07:25.710
So this was the original prompt.

148
00:07:25.710 --> 00:07:28.380
It had now the history that we used

149
00:07:28.380 --> 00:07:30.060
the retrieve context tool,

150
00:07:30.060 --> 00:07:32.820
then we have the tool information here,

151
00:07:32.820 --> 00:07:34.710
the tool execution results.

152
00:07:34.710 --> 00:07:38.430
And finally it used this to render the answer.

153
00:07:38.430 --> 00:07:41.100
And here we have the answer here.

154
00:07:41.100 --> 00:07:44.910
And let's go and check out what are deep agents.

155
00:07:44.910 --> 00:07:47.790
And here we can see the blog on deep agents

156
00:07:47.790 --> 00:07:50.130
which we're going to be covering in the course as well.

157
00:07:50.130 --> 00:07:54.570
Alright, so let me go and commit this to the repo.

158
00:07:54.570 --> 00:07:59.570
So let me go and write, "updated retrieval

159
00:07:59.730 --> 00:08:03.960
to latest LangChain code."

160
00:08:03.960 --> 00:08:06.030
and let me go and push it.

161
00:08:06.030 --> 00:08:08.400
Alright, and if you want to check out the code

162
00:08:08.400 --> 00:08:11.970
for this video, you can go to the branch

163
00:08:11.970 --> 00:08:14.610
2-retrieval-qa-finish.

164
00:08:14.610 --> 00:08:18.810
And you can see here if you'll go to backend/core.py,

165
00:08:18.810 --> 00:08:21.483
this is what we did right now.

