1
00:00:00,000 --> 00:00:00,000
Hello guys.

2
00:00:00,000 --> 00:00:08,000
So in this video we are going to develop a multi-agent generative AI application using line graph uh,

3
00:00:08,000 --> 00:00:10,000
wherein we will try to create a chatbot.

4
00:00:10,000 --> 00:00:16,000
Along with the chatbot, we will also be integrating with some third party tool so that whenever we

5
00:00:16,000 --> 00:00:22,000
ask a query with the chatbot, if the query is being able to handle by the chatbot, uh, which is specifically

6
00:00:22,000 --> 00:00:26,000
being using some llms, then we will directly get the response.

7
00:00:26,000 --> 00:00:32,000
But if it does not has the answer, it will go ahead and ask this specific external tool.

8
00:00:32,000 --> 00:00:37,000
So, uh, the entire flow or the architecture looks something like this.

9
00:00:37,000 --> 00:00:41,000
Here we will go ahead and start this process here.

10
00:00:41,000 --> 00:00:46,000
Any user if if any user is specifically asking any query, first of all the query will go to the chat

11
00:00:46,000 --> 00:00:47,000
bot.

12
00:00:47,000 --> 00:00:52,000
Then the chat bot will decide whether it should specifically provide the answer, or should it.

13
00:00:52,000 --> 00:00:56,000
Probably go ahead and ask some third party tool.

14
00:00:56,000 --> 00:00:56,000
Right?

15
00:00:56,000 --> 00:00:59,000
The third party tool can be, uh, Wikipedia.

16
00:00:59,000 --> 00:01:01,000
It can be Google Search anything.

17
00:01:01,000 --> 00:01:01,000
It can be right.

18
00:01:01,000 --> 00:01:08,000
And this chatbot that you will be seeing, it will also be interacting with some open source LLM models.

19
00:01:08,000 --> 00:01:10,000
And this open source LLM model.

20
00:01:10,000 --> 00:01:13,000
We will be accessing it from the grok API.

21
00:01:14,000 --> 00:01:20,000
So now we are going to go ahead with respect to one additional step with respect to land graph like

22
00:01:20,000 --> 00:01:22,000
how we can integrate some tools.

23
00:01:22,000 --> 00:01:26,000
You know here I will be going showing an example with respect to one tool like this.

24
00:01:26,000 --> 00:01:28,000
You can add any number of tool.

25
00:01:28,000 --> 00:01:31,000
And when the interaction is done with the tool you get the response.

26
00:01:31,000 --> 00:01:33,000
And then you finally end this entire flow okay.

27
00:01:33,000 --> 00:01:37,000
So let's go ahead and implement this step by step.

28
00:01:37,000 --> 00:01:42,000
Now first of all, what we really need to do is that we need to go ahead and install all these libraries.

29
00:01:42,000 --> 00:01:47,000
That is uh, land graph lang smith lang chain lang chain underscore grok.

30
00:01:47,000 --> 00:01:52,000
You know why lang chain underscore grok is specifically used so that you can actually communicate with

31
00:01:52,000 --> 00:01:53,000
the grok API.

32
00:01:53,000 --> 00:01:55,000
Then you have Lang chain community.

33
00:01:55,000 --> 00:01:55,000
Right.

34
00:01:55,000 --> 00:01:58,000
So I will go ahead and execute this.

35
00:01:58,000 --> 00:02:02,000
So once you specifically execute this here line graph is going to get this.

36
00:02:02,000 --> 00:02:04,000
All these libraries will be installed.

37
00:02:04,000 --> 00:02:05,000
Okay.

38
00:02:05,000 --> 00:02:10,000
Now uh, after installing this we will go ahead and import two more libraries.

39
00:02:10,000 --> 00:02:12,000
One is annotated and type dict.

40
00:02:12,000 --> 00:02:14,000
The reason is very simple.

41
00:02:14,000 --> 00:02:20,000
Uh, if you have already seen my previous video, we are going to use this two libraries in our state

42
00:02:20,000 --> 00:02:23,000
class which will be managing the state of the line graph.

43
00:02:23,000 --> 00:02:24,000
Right.

44
00:02:24,000 --> 00:02:25,000
So let's go ahead and execute this.

45
00:02:25,000 --> 00:02:31,000
So once we have executed this I will go ahead and start writing my code right now.

46
00:02:31,000 --> 00:02:32,000
First thing first.

47
00:02:32,000 --> 00:02:38,000
What we really need to do is that I will also go ahead and install some tools, you know, and Lang

48
00:02:38,000 --> 00:02:44,000
already provides you some amazing tools and tools here that we are going to use is specifically like

49
00:02:44,000 --> 00:02:46,000
Wikipedia or RCF, you know.

50
00:02:46,000 --> 00:02:52,000
So if you have already explored Lang, so already there are a lot of third party tools specifically

51
00:02:52,000 --> 00:02:53,000
available, right?

52
00:02:53,000 --> 00:02:56,000
So for that, I will go ahead and write a comment here.

53
00:02:56,000 --> 00:03:00,000
We are going to work working with tools or external tools.

54
00:03:00,000 --> 00:03:12,000
So first of all, I will go ahead and write from long chain underscore community dot utilities dot utilities.

55
00:03:12,000 --> 00:03:16,000
I'm going to go ahead and import two tools I can actually use.

56
00:03:16,000 --> 00:03:19,000
But right now I will just show you an example with respect to one tool.

57
00:03:19,000 --> 00:03:21,000
One is rc API wrapper.

58
00:03:21,000 --> 00:03:25,000
And the second tool that I'm actually going to use is something like Wikipedia API wrapper.

59
00:03:25,000 --> 00:03:31,000
Right now RCF is basically if you are looking for any research papers, you can basically go ahead and

60
00:03:31,000 --> 00:03:34,000
interact with this particular wrapper instead.

61
00:03:34,000 --> 00:03:38,000
If you just want to get the search from Wikipedia, you can go ahead and take it from this particular

62
00:03:38,000 --> 00:03:39,000
library.

63
00:03:39,000 --> 00:03:39,000
Okay.

64
00:03:39,000 --> 00:03:49,000
Then the next step will be that from Lang chain underscore community dot tools import rc query run.

65
00:03:49,000 --> 00:03:52,000
This will be responsible in running any queries that you specifically give.

66
00:03:52,000 --> 00:03:55,000
And then you have this Wikipedia query run okay.

67
00:03:56,000 --> 00:03:59,000
So this is for the RC tool.

68
00:03:59,000 --> 00:04:02,000
This is specifically for the Wikipedia tool.

69
00:04:02,000 --> 00:04:09,000
Okay, then, uh, after this, I'm just going to go ahead and call my RCF, uh, and Wikipedia tools.

70
00:04:09,000 --> 00:04:12,000
So let's say Wikipedia tools okay.

71
00:04:12,000 --> 00:04:23,000
Then here I'm going to write my RCF underscore wrapper is equal to RCF, rcf API wrapper here.

72
00:04:23,000 --> 00:04:29,000
Uh, let's say in this API wrapper how many results I want, I will go ahead and provide a parameter

73
00:04:29,000 --> 00:04:31,000
that is top-k results.

74
00:04:31,000 --> 00:04:32,000
Let's say top-k results.

75
00:04:32,000 --> 00:04:38,000
I just want one result and I will go ahead and write my document content character Max.

76
00:04:38,000 --> 00:04:40,000
Like how many characters I specifically want.

77
00:04:40,000 --> 00:04:42,000
Let's say I will go ahead and write 300.

78
00:04:42,000 --> 00:04:42,000
Okay.

79
00:04:42,000 --> 00:04:48,000
Then uh, with the help of this RCF, what I'm actually going to do, I'll go ahead and create this

80
00:04:48,000 --> 00:04:49,000
specific tool.

81
00:04:49,000 --> 00:04:54,000
I will use this R safe query run, and I will give the wrapper as a parameter over here.

82
00:04:55,000 --> 00:04:55,000
Right.

83
00:04:55,000 --> 00:04:59,000
One amazing thing about Google Colab is that it is now providing you code suggestion, which will be

84
00:04:59,000 --> 00:05:02,000
very helpful whenever you are writing any code.

85
00:05:02,000 --> 00:05:07,000
Similarly, if I go ahead and write my API underscore wrapper, I will go ahead and use my Wikipedia

86
00:05:07,000 --> 00:05:08,000
wrapper.

87
00:05:08,000 --> 00:05:13,000
Here also, I will go ahead and write my top k results and document content characters.

88
00:05:13,000 --> 00:05:14,000
Max characters.

89
00:05:14,000 --> 00:05:16,000
I really want 300, right?

90
00:05:16,000 --> 00:05:21,000
That basically means whenever we are interacting with Wikipedia, I'm going to get the response as one

91
00:05:21,000 --> 00:05:23,000
document at a time.

92
00:05:23,000 --> 00:05:26,000
And inside that document, the maximum number of characters will be 300.

93
00:05:26,000 --> 00:05:31,000
So finally, I will go ahead and also write about Wikipedia tool where I'm going to use this Wikipedia

94
00:05:31,000 --> 00:05:32,000
run query run.

95
00:05:32,000 --> 00:05:34,000
And we are going to run this particular API wrapper.

96
00:05:34,000 --> 00:05:36,000
So two things I have actually imported it.

97
00:05:36,000 --> 00:05:39,000
Now let's say let's go ahead and just uh okay.

98
00:05:39,000 --> 00:05:42,000
One uh error is basically there.

99
00:05:42,000 --> 00:05:45,000
Let's say okay, I have not installed.

100
00:05:46,000 --> 00:05:54,000
So we need to install RCF and Wikipedia okay.

101
00:05:54,000 --> 00:05:57,000
So without this this will not work okay.

102
00:05:57,000 --> 00:06:00,000
So let's go ahead and execute this quickly.

103
00:06:00,000 --> 00:06:02,000
So this is going to get installed.

104
00:06:02,000 --> 00:06:05,000
Here you can see that it is getting installed.

105
00:06:05,000 --> 00:06:09,000
Because without this particular packages we will not be able to execute this code.

106
00:06:09,000 --> 00:06:15,000
Right now it should basically run up here I'm getting an error saying that base tool underscore unit

107
00:06:15,000 --> 00:06:19,000
okay RC tools takes RC wrapper okay.

108
00:06:19,000 --> 00:06:21,000
This is my RC wrapper.

109
00:06:21,000 --> 00:06:26,000
I need to provide the parameter because over here I will go ahead and give my API underscore wrapper

110
00:06:26,000 --> 00:06:26,000
as my parameter.

111
00:06:26,000 --> 00:06:27,000
Okay.

112
00:06:27,000 --> 00:06:30,000
So I'm not going to edit any of this particular errors.

113
00:06:30,000 --> 00:06:35,000
So please make sure that and this is the key that is specifically used.

114
00:06:35,000 --> 00:06:36,000
That is the reason it was giving an error.

115
00:06:36,000 --> 00:06:38,000
Now it should run okay.

116
00:06:38,000 --> 00:06:39,000
Now this is run perfectly.

117
00:06:39,000 --> 00:06:41,000
Now let's go ahead and run any of this.

118
00:06:41,000 --> 00:06:50,000
So I will go ahead and write Wikipedia dot tool and let me go ahead and ask who is who is.

119
00:06:50,000 --> 00:06:54,000
I'll ask any question who is a famous actor?

120
00:06:54,000 --> 00:06:56,000
Let's say Shahrukh Khan.

121
00:06:56,000 --> 00:06:56,000
Okay.

122
00:06:57,000 --> 00:07:02,000
So here I'm going to write Wiki wiki wiki underscore two.

123
00:07:02,000 --> 00:07:04,000
It should be dot invoke.

124
00:07:04,000 --> 00:07:11,000
Okay, so if I really want to invoke any of this invoke and let me go ahead and execute it now, it

125
00:07:11,000 --> 00:07:13,000
should probably go ahead and search from Wikipedia.

126
00:07:13,000 --> 00:07:15,000
And I'm getting the response over here.

127
00:07:15,000 --> 00:07:17,000
The maximum number of characters will be 300.

128
00:07:17,000 --> 00:07:21,000
Similarly if you can go ahead and use this RCF tool also.

129
00:07:21,000 --> 00:07:28,000
So if I go ahead and write RCF underscore tool dot invoke okay.

130
00:07:29,000 --> 00:07:32,000
Attention is all you need.

131
00:07:32,000 --> 00:07:36,000
So this is one of the research paper related to Transformers.

132
00:07:36,000 --> 00:07:38,000
So here you can see I'm getting all the information.

133
00:07:38,000 --> 00:07:40,000
You do not need all the information.

134
00:07:40,000 --> 00:07:44,000
So this is basically coming from the RCF itself right.

135
00:07:44,000 --> 00:07:48,000
And all the author research paper names everything is basically available over here.

136
00:07:48,000 --> 00:07:49,000
So perfect.

137
00:07:49,000 --> 00:07:53,000
That basically means my external tools are working absolutely fine.

138
00:07:53,000 --> 00:07:54,000
Right.

139
00:07:54,000 --> 00:07:57,000
But since I'm just going to use one tool, you can also use any number of tools.

140
00:07:57,000 --> 00:08:01,000
So I'll just go ahead and write this as wiki over here or wiki underscore tool.

141
00:08:01,000 --> 00:08:03,000
So this will basically be my tool.

142
00:08:03,000 --> 00:08:07,000
Uh, afterwards let's say if you want to go ahead and add any number of tool, just go ahead and write

143
00:08:07,000 --> 00:08:09,000
comma and keep on adding all the tool.

144
00:08:09,000 --> 00:08:10,000
Right.

145
00:08:10,000 --> 00:08:13,000
So now my third party tool is done.

146
00:08:13,000 --> 00:08:17,000
Now I'm going to create my line graph application okay.

147
00:08:17,000 --> 00:08:20,000
Line graph applications.

148
00:08:20,000 --> 00:08:25,000
Now in order to start line graph application already in our previous video we have seen I'm going to

149
00:08:25,000 --> 00:08:26,000
create class state.

150
00:08:26,000 --> 00:08:28,000
And here I'm going to use my type dict.

151
00:08:28,000 --> 00:08:29,000
Okay.

152
00:08:29,000 --> 00:08:35,000
The reason why I'm using this because I'm going to create this messages variable which will be a list

153
00:08:35,000 --> 00:08:36,000
of variables okay.

154
00:08:36,000 --> 00:08:38,000
And I'm going to use the annotated.

155
00:08:38,000 --> 00:08:46,000
And I have to make sure that whenever the execution of a specific node gets completed, I'm going to

156
00:08:46,000 --> 00:08:50,000
go ahead and just make sure to update this messages variable.

157
00:08:50,000 --> 00:08:52,000
So here I'm going to get my list.

158
00:08:52,000 --> 00:08:55,000
And here I'm going to get my add underscore messages okay.

159
00:08:55,000 --> 00:08:59,000
So once this is done I add underscore messages.

160
00:08:59,000 --> 00:09:03,000
Also I need to import and this add underscore messages.

161
00:09:03,000 --> 00:09:07,000
If you remember from my previous video already it is already available in the line graph.

162
00:09:07,000 --> 00:09:14,000
So let me just go ahead and import this okay line graph dot message import add message.

163
00:09:14,000 --> 00:09:17,000
And here I'm going to basically use this specific state.

164
00:09:17,000 --> 00:09:18,000
Right.

165
00:09:18,000 --> 00:09:20,000
So all these are completed.

166
00:09:20,000 --> 00:09:25,000
And we have this particular add messages and we are good to go okay great.

167
00:09:25,000 --> 00:09:34,000
Now the next thing uh along with this that we really need to import is three important things from line

168
00:09:34,000 --> 00:09:34,000
graph.

169
00:09:34,000 --> 00:09:42,000
That is your state graph start and end I need to import all these things so that I get all the information

170
00:09:42,000 --> 00:09:43,000
that I really want okay.

171
00:09:44,000 --> 00:09:45,000
Uh, with respect to this.

172
00:09:45,000 --> 00:09:46,000
So this is done.

173
00:09:46,000 --> 00:09:50,000
Now let me go ahead and first of all create my chatbot.

174
00:09:50,000 --> 00:09:51,000
Okay.

175
00:09:51,000 --> 00:09:55,000
Uh, because uh, already we have created this particular state class.

176
00:09:55,000 --> 00:09:58,000
Now we need to probably design our entire workflow Right.

177
00:09:58,000 --> 00:10:00,000
So here I'm going to go ahead and execute this.

178
00:10:01,000 --> 00:10:09,000
Now let me just go ahead and right quickly I will go ahead and create my graph builder okay is equal

179
00:10:09,000 --> 00:10:12,000
to graph Builder I will create this specific variable.

180
00:10:12,000 --> 00:10:18,000
And here I'm going to go ahead and write state graph or state graph.

181
00:10:18,000 --> 00:10:21,000
And here we are specifically going to take this state.

182
00:10:21,000 --> 00:10:24,000
Now this state graph is nothing but it is imported from here.

183
00:10:24,000 --> 00:10:26,000
This state is nothing but my class.

184
00:10:26,000 --> 00:10:32,000
The state is going to maintain all the all the all those different different states in this particular

185
00:10:32,000 --> 00:10:33,000
messages variable.

186
00:10:33,000 --> 00:10:33,000
Okay.

187
00:10:33,000 --> 00:10:36,000
So this will basically be my graph builder.

188
00:10:36,000 --> 00:10:39,000
Now it's time to probably call my LM model.

189
00:10:39,000 --> 00:10:39,000
Right.

190
00:10:39,000 --> 00:10:45,000
Because at the end of the day we if we really want to create any chatbot, we really need to use a specific

191
00:10:45,000 --> 00:10:45,000
LM model.

192
00:10:45,000 --> 00:10:51,000
Now, I have already shown you in our previous video how we can actually go ahead and use LM models,

193
00:10:51,000 --> 00:10:51,000
right?

194
00:10:51,000 --> 00:10:55,000
Or how you can use or how you can call the LM model from Chad Brock.

195
00:10:55,000 --> 00:10:55,000
Right.

196
00:10:55,000 --> 00:10:59,000
So here I will go ahead and right from Lange Lang chain.

197
00:10:59,000 --> 00:11:00,000
Underscore.

198
00:11:00,000 --> 00:11:03,000
Grok import chart.

199
00:11:03,000 --> 00:11:04,000
Grok okay.

200
00:11:04,000 --> 00:11:05,000
Chart.

201
00:11:05,000 --> 00:11:05,000
Grok.

202
00:11:05,000 --> 00:11:09,000
And inside this chart grok I'm just going to go ahead and execute this.

203
00:11:09,000 --> 00:11:15,000
And then I'm going to create my LM variable which is nothing but which is my chart grok.

204
00:11:15,000 --> 00:11:21,000
And here you can actually go ahead and see my grok underscore API underscore key.

205
00:11:21,000 --> 00:11:27,000
This API key I should be getting from my uh, secret keys.

206
00:11:27,000 --> 00:11:27,000
Right?

207
00:11:27,000 --> 00:11:31,000
I have already added the secret keys, and I've already shown you how you can basically add it in the

208
00:11:31,000 --> 00:11:32,000
previous video.

209
00:11:32,000 --> 00:11:32,000
Right.

210
00:11:32,000 --> 00:11:36,000
So in order to add this, I will go ahead and write one more code.

211
00:11:36,000 --> 00:11:47,000
I will go ahead and write from Google Dot Colab, import user data, and then we will go ahead and write

212
00:11:47,000 --> 00:11:49,000
grok underscore API.

213
00:11:49,000 --> 00:11:55,000
Underscore key is equal to user data dot.

214
00:11:55,000 --> 00:12:03,000
Get And here I'm going to specifically use my grok underscore API underscore key, which is the key

215
00:12:03,000 --> 00:12:05,000
name that I've written it over here in my secret keys.

216
00:12:05,000 --> 00:12:06,000
Right.

217
00:12:06,000 --> 00:12:07,000
Grok underscore API underscore key.

218
00:12:07,000 --> 00:12:08,000
Perfect.

219
00:12:08,000 --> 00:12:09,000
So this is fine.

220
00:12:09,000 --> 00:12:13,000
Now once I get my grok underscore API underscore key I will just go and click on grant access.

221
00:12:13,000 --> 00:12:17,000
And finally I will keep the value over here.

222
00:12:17,000 --> 00:12:20,000
So this should be grok underscore API underscore key.

223
00:12:20,000 --> 00:12:23,000
And here finally this is my LLM model.

224
00:12:24,000 --> 00:12:28,000
And this LLM model by default is using no no models.

225
00:12:28,000 --> 00:12:30,000
So I have to provide my model name.

226
00:12:30,000 --> 00:12:32,000
So the model name will be nothing.

227
00:12:32,000 --> 00:12:36,000
But I will go ahead and write model name is equal to gamma.

228
00:12:36,000 --> 00:12:37,000
I can use gamma.

229
00:12:38,000 --> 00:12:40,000
So let's go ahead and use gamma.

230
00:12:41,000 --> 00:12:45,000
Gamma two nine be it.

231
00:12:45,000 --> 00:12:46,000
Okay.

232
00:12:47,000 --> 00:12:49,000
So I've specifically used this particular model.

233
00:12:49,000 --> 00:12:51,000
And let's go ahead and execute this.

234
00:12:51,000 --> 00:12:52,000
Perfect.

235
00:12:53,000 --> 00:12:54,000
This is done.

236
00:12:54,000 --> 00:12:56,000
My graph builder is also ready.

237
00:12:56,000 --> 00:13:00,000
Now it's time that we go ahead and create our chat bots, right?

238
00:13:00,000 --> 00:13:02,000
So we need to go ahead and define our chat bot.

239
00:13:03,000 --> 00:13:09,000
Now with the help of this LLM, we can basically call or we can call with our chat bot itself, whatever

240
00:13:09,000 --> 00:13:11,000
nodes we are specifically creating.

241
00:13:11,000 --> 00:13:11,000
Right.

242
00:13:11,000 --> 00:13:17,000
So let's go ahead and go to go with the next step wherein we will go ahead and create our chat bot,

243
00:13:17,000 --> 00:13:22,000
which will be doing a functionality of managing the state and also interacting with the LLM model.

244
00:13:22,000 --> 00:13:30,000
So let me go ahead and create my definition chat bot because see uh, if, if I show you over here right.

245
00:13:30,000 --> 00:13:32,000
We need to create this first.

246
00:13:32,000 --> 00:13:32,000
Right.

247
00:13:32,000 --> 00:13:33,000
My LLM is ready.

248
00:13:33,000 --> 00:13:35,000
It is interacting with the grok API.

249
00:13:35,000 --> 00:13:37,000
Now I'll create my chat bot.

250
00:13:37,000 --> 00:13:38,000
I will be interacting with this.

251
00:13:38,000 --> 00:13:43,000
But I will also be adding one very important thing that is nothing but my tools, right?

252
00:13:43,000 --> 00:13:45,000
My LLM should also be integrated with the tools.

253
00:13:45,000 --> 00:13:48,000
So let's see how to probably do that.

254
00:13:48,000 --> 00:13:51,000
So first of all, uh I will go ahead and create a cell over here.

255
00:13:51,000 --> 00:13:54,000
I've created my graph builder.

256
00:13:54,000 --> 00:13:55,000
Everything is ready.

257
00:13:55,000 --> 00:14:02,000
I will take this LLM and I will say hey, go ahead and bind underscore tools, whatever tools I'm going

258
00:14:02,000 --> 00:14:03,000
to use.

259
00:14:03,000 --> 00:14:05,000
So this will be my tools is equal to tools.

260
00:14:05,000 --> 00:14:10,000
And if you remember this tools has specifically what does it has a binding as Wikipedia tool.

261
00:14:10,000 --> 00:14:11,000
Right.

262
00:14:11,000 --> 00:14:14,000
So I'm going to basically bind this particular tool itself.

263
00:14:14,000 --> 00:14:17,000
And after binding I will store this in a variable.

264
00:14:17,000 --> 00:14:25,000
This is just giving a additional functionality to the LM that it has this particular tool access also.

265
00:14:25,000 --> 00:14:25,000
Right.

266
00:14:25,000 --> 00:14:28,000
So this LM with underscore tools will be used.

267
00:14:28,000 --> 00:14:34,000
Now once I'm creating this particular functionality I will first of all derive my uh, I will inherit

268
00:14:34,000 --> 00:14:40,000
this particular state inside this chatbot so that it has all the information related to the message.

269
00:14:40,000 --> 00:14:46,000
And here I'm going to probably return my output with, with the help of this messages variable, which

270
00:14:46,000 --> 00:14:50,000
is the key that is present inside the state colon.

271
00:14:50,000 --> 00:14:55,000
And here I'm going to probably call or invoke with the help of my LM model.

272
00:14:55,000 --> 00:15:01,000
But this time my LM model will also have the functionalities from the tools, right?

273
00:15:01,000 --> 00:15:05,000
Because it also has the tools functionality which is nothing but the Wikipedia tool.

274
00:15:05,000 --> 00:15:07,000
And here I will go and write Dot invoke.

275
00:15:07,000 --> 00:15:12,000
And I'm going to probably take this particular state, this state which I'm inheriting, which is coming

276
00:15:12,000 --> 00:15:13,000
from this and inside this state.

277
00:15:13,000 --> 00:15:16,000
You know, what exactly is present messages variable is present.

278
00:15:16,000 --> 00:15:22,000
And if I take the state of messages, this is basically going to have the query of the user.

279
00:15:22,000 --> 00:15:22,000
Right.

280
00:15:22,000 --> 00:15:25,000
So once I execute this this is what it is basically going to return.

281
00:15:25,000 --> 00:15:26,000
Right.

282
00:15:26,000 --> 00:15:28,000
So my chatbot functionality is ready okay.

283
00:15:28,000 --> 00:15:30,000
This chatbot functionality is ready.

284
00:15:30,000 --> 00:15:33,000
This LM is being integrated with the LM tool.

285
00:15:33,000 --> 00:15:34,000
So it is basically going to interact.

286
00:15:34,000 --> 00:15:40,000
So whatever query comes, if this chatbot is able to probably provide the response from the LM, then

287
00:15:40,000 --> 00:15:41,000
it is going to get the output.

288
00:15:41,000 --> 00:15:44,000
Otherwise it is going to interact with this particular tool.

289
00:15:44,000 --> 00:15:44,000
Right.

290
00:15:44,000 --> 00:15:46,000
And finally we are just going to end this.

291
00:15:46,000 --> 00:15:50,000
Now we need to create this entire flow the flow of the execution.

292
00:15:50,000 --> 00:15:51,000
Right.

293
00:15:51,000 --> 00:15:55,000
So in order to create the flow of the execution I will again take my graph builder.

294
00:15:55,000 --> 00:16:03,000
So let me go ahead and write Graph builder dot add underscore node.

295
00:16:03,000 --> 00:16:04,000
Okay.

296
00:16:04,000 --> 00:16:07,000
And then we are basically going to write chatbot.

297
00:16:07,000 --> 00:16:10,000
So this will basically be my node name chatbot.

298
00:16:10,000 --> 00:16:14,000
And finally you will also be able to see this chatbot.

299
00:16:14,000 --> 00:16:14,000
Right.

300
00:16:14,000 --> 00:16:16,000
So this is my node.

301
00:16:16,000 --> 00:16:19,000
I will add the start with this chatbot node.

302
00:16:19,000 --> 00:16:20,000
Right.

303
00:16:20,000 --> 00:16:26,000
I will add that particular edge because we need this specific edge right from start to the chatbot.

304
00:16:26,000 --> 00:16:26,000
Perfect.

305
00:16:26,000 --> 00:16:28,000
This node is basically added.

306
00:16:28,000 --> 00:16:35,000
Now I have to also make sure that I need to add uh the tool node okay.

307
00:16:35,000 --> 00:16:41,000
So see whenever a tool is basically needed to add because here we will be adding this tool over here.

308
00:16:41,000 --> 00:16:42,000
Right.

309
00:16:42,000 --> 00:16:44,000
So this tool needs to be added to the chatbot.

310
00:16:44,000 --> 00:16:46,000
Then only the LM will be able to interact with the tool.

311
00:16:46,000 --> 00:16:52,000
So for that we basically use another library over here which is called as tool node.

312
00:16:52,000 --> 00:16:52,000
Okay.

313
00:16:52,000 --> 00:16:55,000
So let me just go ahead and import one more library.

314
00:16:55,000 --> 00:16:58,000
So I will go ahead and right from Landgraaf.

315
00:16:58,000 --> 00:17:04,000
In order to add any third party tools or any custom tools, you can also create this custom tools.

316
00:17:04,000 --> 00:17:11,000
I will go ahead and import one tool node and then along with this I will also give one tool condition.

317
00:17:11,000 --> 00:17:17,000
Like for this particular tool node there should be some kind of conditions we need to add right now.

318
00:17:17,000 --> 00:17:24,000
Now let's see what is the error tool node prebuilt from tool node okay.

319
00:17:24,000 --> 00:17:26,000
It should be tool conditions tools condition okay.

320
00:17:26,000 --> 00:17:29,000
No worries I will just go ahead and import this.

321
00:17:29,000 --> 00:17:29,000
Perfect.

322
00:17:29,000 --> 00:17:30,000
So this is done.

323
00:17:30,000 --> 00:17:31,000
Now what I have done.

324
00:17:31,000 --> 00:17:32,000
I have created a chat bot.

325
00:17:32,000 --> 00:17:36,000
I have connected from start node to the chat bot node.

326
00:17:36,000 --> 00:17:39,000
Then I will go ahead and call this tool node.

327
00:17:39,000 --> 00:17:41,000
So let me just go ahead and write tool node.

328
00:17:41,000 --> 00:17:45,000
And this tool node will basically have my tools.

329
00:17:45,000 --> 00:17:47,000
My tools is nothing.

330
00:17:47,000 --> 00:17:50,000
But whatever tools I am going to use that is nothing but Wikipedia.

331
00:17:50,000 --> 00:17:53,000
And I'll create a variable which is called as tool node.

332
00:17:53,000 --> 00:17:53,000
Okay.

333
00:17:53,000 --> 00:17:58,000
So this tool node is also created that basically means this tool node is also created.

334
00:17:58,000 --> 00:18:01,000
Now we need to connect from this chatbot.

335
00:18:01,000 --> 00:18:01,000
To the tool nodes.

336
00:18:01,000 --> 00:18:03,000
How do I connect it?

337
00:18:03,000 --> 00:18:04,000
It is very simple.

338
00:18:04,000 --> 00:18:05,000
I will go ahead and write.

339
00:18:05,000 --> 00:18:12,000
Graph graph builder dot add underscore node.

340
00:18:12,000 --> 00:18:14,000
And here I'm going to basically go.

341
00:18:14,000 --> 00:18:17,000
Ahead and create a node which is called as tools.

342
00:18:17,000 --> 00:18:19,000
And this tools is going to get connected.

343
00:18:19,000 --> 00:18:22,000
To tool underscore node right.

344
00:18:23,000 --> 00:18:26,000
So this way what we have done this entire node is getting.

345
00:18:26,000 --> 00:18:27,000
Getting created.

346
00:18:27,000 --> 00:18:28,000
Right.

347
00:18:28,000 --> 00:18:28,000
Right.

348
00:18:28,000 --> 00:18:31,000
So here this entire tool node is basically getting connected.

349
00:18:31,000 --> 00:18:37,000
Now we need to probably connect this tool to our chatbot now in order to connect it.

350
00:18:37,000 --> 00:18:40,000
Obviously we need to write some conditions.

351
00:18:40,000 --> 00:18:43,000
That basically means what does this basically mean.

352
00:18:43,000 --> 00:18:47,000
Like if I'm getting a query, this chatbot may either interact with the tools or it may.

353
00:18:48,000 --> 00:18:49,000
Interact with the LM and give you the output.

354
00:18:49,000 --> 00:18:50,000
Right.

355
00:18:50,000 --> 00:18:53,000
So this kind of edges if there is a.

356
00:18:53,000 --> 00:18:58,000
Bidirectional edge like this, we really need to use something called as add conditional edges.

357
00:18:58,000 --> 00:18:58,000
Right.

358
00:18:58,000 --> 00:19:09,000
So here what we are going to use is that I will write graph builder dot add add conditional edges.

359
00:19:09,000 --> 00:19:11,000
See add conditional edges.

360
00:19:11,000 --> 00:19:14,000
That is the reason we had imported somewhere.

361
00:19:14,000 --> 00:19:15,000
Let's see where we have imported it.

362
00:19:15,000 --> 00:19:17,000
Have we not imported this?

363
00:19:17,000 --> 00:19:18,000
Let's see.

364
00:19:19,000 --> 00:19:21,000
Add conditional edges.

365
00:19:22,000 --> 00:19:23,000
Okay, we have not imported it.

366
00:19:23,000 --> 00:19:26,000
So first of all we really need to import it.

367
00:19:26,000 --> 00:19:30,000
But no no need to import it because this is an inbuilt function inside Graph Builder.

368
00:19:30,000 --> 00:19:31,000
Okay.

369
00:19:31,000 --> 00:19:36,000
So here I'm going to basically go ahead and write add graph add conditional edges.

370
00:19:36,000 --> 00:19:47,000
And inside this particular edges here what edges will specifically add from chat bot to to tools underscore

371
00:19:47,000 --> 00:19:48,000
condition.

372
00:19:48,000 --> 00:19:49,000
Right.

373
00:19:49,000 --> 00:19:51,000
And this tools underscore condition is nothing.

374
00:19:51,000 --> 00:19:53,000
But it is basically coming from here.

375
00:19:53,000 --> 00:19:59,000
Now understand over here why we are adding this conditional edges because just from the diagram you

376
00:19:59,000 --> 00:20:00,000
can see that from the chatbot.

377
00:20:00,000 --> 00:20:02,000
I need to interact with the tool and again get it back.

378
00:20:02,000 --> 00:20:08,000
So whenever we have this kind of bidirectional we really need to add this particular edge which is called

379
00:20:08,000 --> 00:20:09,000
as conditional edges.

380
00:20:09,000 --> 00:20:15,000
I need to give my node name and the tool conditions are the default conditions that is available over

381
00:20:15,000 --> 00:20:15,000
here.

382
00:20:15,000 --> 00:20:20,000
This tools condition is going to make that bidirectional directions itself right from the chatbot.

383
00:20:20,000 --> 00:20:25,000
Now after that, uh, you know that my tools also needs to get connected to the chatbot.

384
00:20:26,000 --> 00:20:31,000
See this tools when I'm using this, add conditional edges, the chatbot, tilde tools, the communication

385
00:20:31,000 --> 00:20:34,000
will happen, but I need to reconnect it back.

386
00:20:34,000 --> 00:20:40,000
So for in order to reconnect it back I will just go ahead and write graph underscore builder dot.

387
00:20:40,000 --> 00:20:45,000
Add edge from tools to chatbot see from tools to chatbot.

388
00:20:45,000 --> 00:20:49,000
And finally we are going to add an edge which is from chatbot till the end.

389
00:20:49,000 --> 00:20:51,000
That is what we really want this end.

390
00:20:51,000 --> 00:20:53,000
So it is very simple.

391
00:20:53,000 --> 00:20:57,000
First of all we went this is the entire flow.

392
00:20:57,000 --> 00:20:58,000
And this is really important.

393
00:20:58,000 --> 00:21:01,000
Inside this flow we use three important things.

394
00:21:01,000 --> 00:21:09,000
One is add edges, add edges, add edges, add node.

395
00:21:10,000 --> 00:21:11,000
Right.

396
00:21:11,000 --> 00:21:14,000
And then you also had conditional edges.

397
00:21:16,000 --> 00:21:16,000
Right.

398
00:21:16,000 --> 00:21:18,000
All these three nodes we had.

399
00:21:18,000 --> 00:21:18,000
Right.

400
00:21:18,000 --> 00:21:21,000
So first of all we connected start to chatbot.

401
00:21:22,000 --> 00:21:25,000
So we created uh we created a node for chatbot.

402
00:21:25,000 --> 00:21:27,000
And we add this edge from start to chatbot.

403
00:21:27,000 --> 00:21:31,000
Then we created this LM tool integration.

404
00:21:31,000 --> 00:21:34,000
Then from chatbot to tools we specifically went right.

405
00:21:34,000 --> 00:21:40,000
So if we go ahead and just revise this step by step, see first of all we added a node chatbot which

406
00:21:40,000 --> 00:21:42,000
is having this particular functionality.

407
00:21:42,000 --> 00:21:46,000
And this functionality is nothing, but it is using this LM underscore with tools dot invoke.

408
00:21:46,000 --> 00:21:50,000
It is just trying to get the output from this particular message right.

409
00:21:50,000 --> 00:21:54,000
Whatever message is there, LM will either give the response or the tool will give the response.

410
00:21:54,000 --> 00:21:55,000
Perfect.

411
00:21:55,000 --> 00:21:59,000
Then we added the edges with start to chatbot at this specific node.

412
00:21:59,000 --> 00:22:01,000
Then we created our tool node.

413
00:22:01,000 --> 00:22:04,000
Then this tool node got added as a node in the graph builder.

414
00:22:04,000 --> 00:22:10,000
Then we added conditional edges between chatbot and we applied a tools condition.

415
00:22:10,000 --> 00:22:13,000
Then we added the edges back from tools to chatbot.

416
00:22:13,000 --> 00:22:19,000
And then finally we have this graph builder dot add edge where we connected the chatbot with the end

417
00:22:19,000 --> 00:22:19,000
right.

418
00:22:19,000 --> 00:22:21,000
So all these things were executed perfectly.

419
00:22:22,000 --> 00:22:24,000
Now let's go ahead and compile this.

420
00:22:24,000 --> 00:22:30,000
I'm going to basically use graph underscore builder dot compile.

421
00:22:30,000 --> 00:22:31,000
Okay.

422
00:22:31,000 --> 00:22:32,000
Compile.

423
00:22:32,000 --> 00:22:36,000
And then this will basically be my graph graph.

424
00:22:36,000 --> 00:22:38,000
And we will just go ahead and execute this.

425
00:22:38,000 --> 00:22:39,000
Okay.

426
00:22:39,000 --> 00:22:45,000
Now finally in order to display this graph I can go ahead and use the same thing which we have used

427
00:22:45,000 --> 00:22:48,000
earlier in our videos with respect to IPython dot display.

428
00:22:48,000 --> 00:22:50,000
This is just from the documentation.

429
00:22:50,000 --> 00:22:51,000
Now we can see the entire flow.

430
00:22:52,000 --> 00:22:56,000
See start chatbot tools end right.

431
00:22:56,000 --> 00:22:58,000
Everything is basically here.

432
00:22:58,000 --> 00:23:02,000
So finally you can see the flow over here after executing it.

433
00:23:02,000 --> 00:23:03,000
Let's go ahead and test it.

434
00:23:03,000 --> 00:23:05,000
So see from start to chatbot.

435
00:23:05,000 --> 00:23:08,000
If the tool is required then again it is connected back.

436
00:23:08,000 --> 00:23:10,000
And finally we go to the end.

437
00:23:10,000 --> 00:23:10,000
Right.

438
00:23:10,000 --> 00:23:16,000
So all these things are specifically connected and we are good to go with respect to this right now.

439
00:23:16,000 --> 00:23:23,000
Let's go ahead and try out some of the flow like with respect to any kind of messages okay.

440
00:23:23,000 --> 00:23:26,000
And let's see how we are going to get the output right.

441
00:23:26,000 --> 00:23:35,000
So first of all I will just go ahead and give my user underscore input is equal to I will write uh hi

442
00:23:35,000 --> 00:23:36,000
there.

443
00:23:37,000 --> 00:23:39,000
Let me just go ahead and write hi there.

444
00:23:39,000 --> 00:23:42,000
And here I'm just going to write.

445
00:23:42,000 --> 00:23:46,000
My name is Krish okay.

446
00:23:46,000 --> 00:23:51,000
I'm just going to probably provide some basic input from the user.

447
00:23:51,000 --> 00:23:51,000
Right.

448
00:23:52,000 --> 00:23:56,000
Then I'm going to go ahead and use an events variable.

449
00:23:56,000 --> 00:24:00,000
And let me go ahead and write graph dot stream.

450
00:24:00,000 --> 00:24:06,000
And here inside the stream I'm going to give my messages in this format.

451
00:24:06,000 --> 00:24:11,000
This is really important because this messages will follow in the C any user message.

452
00:24:11,000 --> 00:24:13,000
We need to probably set it up in this way.

453
00:24:13,000 --> 00:24:18,000
Write messages is equal to user user input stream mode values okay, stream mode values.

454
00:24:18,000 --> 00:24:21,000
And then we are going to probably get our response.

455
00:24:21,000 --> 00:24:25,000
So I will go ahead and write for event in events.

456
00:24:26,000 --> 00:24:41,000
Let's display the event of messages minus one dot pretty print.

457
00:24:41,000 --> 00:24:43,000
We are just trying to print it in a better way.

458
00:24:43,000 --> 00:24:49,000
So whenever I give this particular message you can see uh, by default it is probably going ahead with

459
00:24:49,000 --> 00:24:50,000
Wikipedia call.

460
00:24:50,000 --> 00:24:56,000
Okay, this should not happen because it is just connecting my name with some famous personality name.

461
00:24:56,000 --> 00:24:58,000
So it is probably giving you some information, right?

462
00:24:58,000 --> 00:24:59,000
Sangeetha.

463
00:24:59,000 --> 00:24:59,000
Krish.

464
00:24:59,000 --> 00:25:00,000
It has selected.

465
00:25:00,000 --> 00:25:01,000
No worries.

466
00:25:01,000 --> 00:25:02,000
I will just go ahead and write.

467
00:25:02,000 --> 00:25:02,000
Hey.

468
00:25:03,000 --> 00:25:03,000
Hi there.

469
00:25:03,000 --> 00:25:05,000
My name is John.

470
00:25:05,000 --> 00:25:07,000
Let's execute this now.

471
00:25:07,000 --> 00:25:08,000
Okay.

472
00:25:08,000 --> 00:25:10,000
So query John Wikipedia.

473
00:25:10,000 --> 00:25:12,000
See it is going to probably Wikipedia.

474
00:25:12,000 --> 00:25:15,000
Uh, so no good Wikipedia.

475
00:25:15,000 --> 00:25:17,000
Uh search result was found.

476
00:25:17,000 --> 00:25:18,000
So it is saying hey.

477
00:25:18,000 --> 00:25:18,000
Hello, John.

478
00:25:18,000 --> 00:25:19,000
It's nice to meet you.

479
00:25:19,000 --> 00:25:23,000
Now see it is probably going and checking the tool message.

480
00:25:23,000 --> 00:25:28,000
Also whether I'm going to find this specific message or this particular name over there.

481
00:25:28,000 --> 00:25:31,000
So it did not get a good result, then it is probably interacting with us.

482
00:25:31,000 --> 00:25:31,000
Hey.

483
00:25:31,000 --> 00:25:33,000
Saying that hello John, it's nice to meet you.

484
00:25:33,000 --> 00:25:36,000
So guys, I hope you like this particular video.

485
00:25:36,000 --> 00:25:40,000
Uh, this was about building chatbot applications with third party tools.

486
00:25:40,000 --> 00:25:42,000
Uh, with the help of line graph.

487
00:25:42,000 --> 00:25:44,000
Uh, just go ahead and try it out.

488
00:25:44,000 --> 00:25:50,000
Try it out with multiple tools and see, uh, whether it goes to RC or not, just keep on adding and

489
00:25:50,000 --> 00:25:51,000
keep on asking queries.

490
00:25:51,000 --> 00:25:54,000
You should be able to get all the solutions over there, right?

491
00:25:54,000 --> 00:25:55,000
So yes, this was it from my side.

492
00:25:55,000 --> 00:25:56,000
I will see you all in the next video.

493
00:25:56,000 --> 00:25:57,000
Thank you.

494
00:25:57,000 --> 00:25:57,000
Take care.

