Full transcript
Introduction & Planning
0:00Learn how to build productionready
0:01multi- aent systems and automate
0:04workflows using lang chain and langraph.
0:08You'll master everything from core
0:10agentic fundamentals and pideantic
0:12validation to advanced sequential
0:15parallel and conditional langraph
0:17workflows. Along the way, you'll
0:19implement chat memory, rag, and human in
0:23the loop controls and finish by
0:25deploying your applications to AWS and
0:28render through real world projects like
0:30a custom chat GPT trip planner and auto
0:34content agent. Papy created this course.
0:38Hi guys, my name is BPI and you are
0:41welcome to my course. In this course
0:44you'll try to master the complete
0:46agentic AI with the help of Lang graph.
0:49If you have seen over the internet and
0:51everywhere nowadays people are moving
0:54towards agentic AI system.
0:56Previously we used to work on the LLM
0:59based application rag based application
1:01but right now agent is getting very much
1:03important and crucial for the
1:06application development. Nowadays AI
1:08agents are becoming very much powerful
1:10because of its automated workflows. So
1:13right now you only need to provide a
1:15prompt and from your prompt itself your
1:17agents can understand your goals and
1:19these goals would be divided into
1:21multiple tasks and all of the task would
1:23be completed by using some kinds of
1:25tools. Your AI agents can decide which
1:28tool to use to perform what kinds of
1:30task. So these kinds of automated
1:33workflows your AI agents is having and
1:35with the help of that it can perform any
1:36kinds of task you'll be providing to
1:38your AI agents. So that's why this is
1:40far better than our traditional geni
1:43application development because right
1:45now with the help of agents we can
1:47automated the workflows. So in this
1:49course guys I'm going to teach you each
1:51and everything you need to master the
1:53agentic AI with the help of langraph. Uh
1:55but before that first of all we'll try
1:57to understand my course plan. This
1:59course I have divided into multiple
2:00phases. So as you can see this is my
2:03entire plan for this course uh agentic
2:05using langraph. So first of all uh in
2:08the phase one we'll try to complete the
2:10introduction to uh agentic AI. First of
2:12all we'll try to understand what is
2:15agentic AI. Okay how AI agent works.
2:17We'll try to see the difference between
2:19LLA maps and AI agents application.
2:21We'll try to see the agentic behaviors
2:23like reasoning planning memory tool.
2:25Okay decision making. Then we'll try to
2:27see some real world use case of agentic
2:29AI traditional AI versus generative AI
2:32versus agent AI system. Okay. Then uh
2:34we'll try to see the evaluation from
2:36chat bots to automated agents. Okay.
2:38We'll try to see each and everything.
2:40Then uh some other stuff we'll try to
2:42cover as you can see like limitations uh
2:45why agent why agents need memory tools
2:47workflows control logic then agent
2:50architecture prompt and system
2:51instruction tools memory planning
2:54reflection environment interaction and
2:56human feedback okay then in phase two
2:59I'll try to start with asynchronous
3:00programming and pentic because uh if you
3:04are uh if you are already working with
3:07AI agents I think you know that uh you
3:09need these kinds to asynchronous
3:11programming because all of the agents
3:12are using especially all of the agents
3:15framework are using this kinds of
3:16asynchronous programming in the back
3:17end. Okay. So in this course I'm going
3:19to focus on the langraph. So langraph
3:22internally uses asynchronous programming
3:24that means you can run your agents in
3:26parallel. Okay. We'll try to understand
3:28this asynchronous programming. Okay. Why
3:30it is required for AI agents? How we can
3:32code inside Python. Okay. Then we'll
3:35also try to see about the pyic.
3:38So, pyic is a python library and uh we
3:42use this pentic for the uh data
3:44validation okay model validation uh and
3:47uh these things you need whenever you
3:49are implementing the agents okay I'm
3:51going to tell you why it is required and
3:53why you have to learn this pidentic as
3:55well okay so each and everything we'll
3:57try to cover in the phase two then in
3:59phase three guys I will start with our
4:01first uh orchestration framework which
4:03is langen now you can ask me why we'll
4:06be learning the langin Because if you
4:08know lang graph is a product of langchen
4:10okay langchen team has developed lang
4:12graph right. So that's why to master
4:15this lang lang graph we need some
4:19knowledge on langchen first of all we
4:20have to understand uh whenever we do
4:23didn't have this kinds of langraph
4:24framework so how people used to create
4:26the agents with the help of langchen so
4:28that's why we'll try to use langen to
4:30build this kinds of agents and multi-
4:32aents workflows okay and uh still if you
4:35are using lang graph you need to use
4:36langen because from the langen uh you
4:38will be loading the large language model
4:40you will be loading the prom templates
4:42okay all of the utility related ated
4:43code you will be writing with the help
4:44of langchen and lang graph you'll be
4:47using for building your agent workflows
4:50okay that's why langchen understanding
4:51is little bit required that's why I'm
4:53going to complete this langchen inside
4:54this particular course then we'll start
4:57with the phase four which is uh lang
5:00graph so here we'll try to understand
5:02each and every component of lang graph
5:04as you can see what is lang graph why
5:06lang graph is required langchen versus
5:08lang graph then graph based aent
5:10workflows state management node and ages
5:12okay state nodes edges then conditional
5:14edges. Okay. Start and end nodes, graph
5:17compilation, state graph, checkpointer,
5:19masses state, sequential workflows,
5:21parallel workflows, conditional
5:22workflows, iterative workflows. Okay.
5:25Then um we'll try to see basic chatbot
5:28architecture, masses handling, state
5:29management, user input and we'll try to
5:32see how we can implement agentic chatbot
5:34with the help of langraph. So after that
5:36we'll start with phase five. So here
5:38we'll try to learn about the memory
5:40planning, monitoring and autonomous
5:42system. So here we'll just try to learn
5:45um why what is persistence memory, why
5:47it is required, agent memory, short-term
5:49memory, chat history, how we can stream
5:51the responses, okay, chat trading,
5:54conversation management, permanent chat
5:57persistence memory with database, okay,
5:59tool integr uh integration in Langraph,
6:01okay, inside the uh um aentki
6:04application. Then we'll try to see
6:06different different tools. Okay. Then
6:08we'll also try to learn like how we can
6:10integrate RG that means rag features
6:12inside our AI agents. Then vector
6:14database integration. Okay. Then uh
6:17we'll be learning another important
6:18concept which is human in the loop. Uh
6:20that means HITL. This is required
6:22nowadays all the agentic application are
6:24having this kinds of human in the loop
6:26integration. Then we'll try to see the
6:28monitoring our agent monitoring agent
6:30tracing with the help of Langmith. Then
6:32we'll also see how we can debug um the
6:34agent behavior.
6:36Then uh phase six guys we'll try to
6:38start with the deployment and production
6:40grade engineering. So here we'll try to
6:42dockerize the entire agents. Okay. Then
6:45we'll try to add the fast API back end
6:47database setup GitHub action CI/CD AWS
6:49deployment render deployment. Okay.
6:52Environment variable then production
6:54folder structure logging monitoring each
6:56and everything we'll try to cover. Then
6:58uh the final phase uh phase seven we'll
7:00try to start with some uh end to end
7:02real world AI agents uh project
7:04implementation. So we'll be implementing
7:07basically three major project here in
7:09this course. The first project I'll be
7:10implementing one end to end agentic
7:12chatbot with the help of lang graph
7:14database langismith tools rag htl AWS
7:17and render. And second project we'll be
7:19implementing uh uh our own chat GP agent
7:22with the help of LLM langraph fast API
7:25lang chroma uh SQL alchemy database and
7:28AWS. And third project uh project we'll
7:30be implementing uh called tripmate AI.
7:33This should be end to end multi-agent,
7:35table, planner agent with grock,
7:37langraph, postgrql and fast API. Okay.
7:40So these are the three major project
7:41we'll be implementing in this course.
7:43Then uh you can ask me what would be the
7:45course requirement uh to start this code
7:47course. What are the things I need to
7:49know? I'm expecting you are familiar
7:51with uh advanced Python programming
7:53because all of the coding I'll be doing
7:55I'll be coding in advanced Python. Then
7:57basics of generative AI knowledge is
7:59required if you're understanding about
8:01agent AI agents especially. So you need
8:03some understanding about uh generate EBI
8:05at least about the large language model.
8:07Okay, these are the thing. Then software
8:09requirement wise you should have anagon
8:11installed in your system VS code G and
8:13GitHub and docker desktop and postman.
8:15Okay, so these are the tools if you have
8:16you can start with this course. But
8:18don't worry, I will take care each and
8:19everything. If you are not familiar with
8:21this concept, I'll take care I'll try to
8:23teach in a such a way so that you will
8:25be getting all of the concept in a clear
8:27way. Okay. So yes guys uh this is the
8:29plan entire plan and throughout the
8:30entire course we'll be completing all of
8:32this concept and trust me the way I'm
Evolution from LLMs to Agentic AI
8:34going to complete all of the concept you
8:36will be loving a lot and after this you
8:38won't be having any kinds of doubt okay
8:40so if you're already familiar with
8:42agenti uh I will still tell you just try
8:44to go through the entire course I think
8:46you will be learning u some new concept
8:48here some some new implementation here
8:50okay so definitely you will be enjoying
8:53the entire course okay so yes guys this
8:55is the entire plan now let's start with
8:57the course concept. First of all, I'll
9:00uh give you the idea about the evolution
9:02of uh agentic AI how agentic AI came
9:05okay from the traditional large language
9:08model then we'll try to start with the
9:09other concept as well. So in this video
9:12first of all we'll try to understand and
9:15see the complete evolution of this
9:17agentic like how agentic came and uh
9:21what we used to do in our traditional
9:24generative application.
9:26uh first of all I will give you the
9:27entire understanding how agentic AI came
9:30what are the things they have introduced
9:32then uh I'm going to discuss about uh
9:35the detailed understanding of agentic AI
9:39uh the characteristic of agentic AI
9:41different component of agentic AI we'll
9:43try to understand with a good example so
9:46guys you can see on my screen here I
9:49have already written the definition like
9:52what is agentic AI so if you see here uh
9:56agent is nothing but uh it's a type of
9:59artificial intelligence that can take up
10:02a task or goal from a user and uh then
10:06work towards completing it on its own
10:10with minimal
10:12uh human guidance. Okay. And it plans,
10:16takes actions, adapts to change and
10:19seeks helps only when necessary. So by
10:23this definition itself I think uh you
10:26are getting little bit of understanding
10:29what I'm trying to say. Um those who are
10:32already familiar with uh chart GPT or
10:36any other uh agentic AI system uh if you
10:40have already used like u um VS code then
10:44anti-gravity cursor AI cloudy desktop
10:47right so this kinds of application if
10:49you have already used so there you will
10:51see that whenever user uh gives any
10:55kinds of uh prompt right based on the
10:58prompt uh that application decides what
11:00to you let's say if you are asking a
11:02very simple questions let's say you are
11:04asking tell me about Python so most of
11:08the large language model um have been
11:11trained with lots of data okay um
11:14especially whatever data we are having
11:17on the internet so they have used those
11:19data and they have trained those are the
11:21model and every model is having a
11:24knowledge cutoff okay every model is
11:26having a knowledge cutoff knowledge
11:27cutff means a specific date uh till they
11:31have trained the model. Let's say if I'm
11:33talking about uh chart GPT or let's say
11:36GPT uh 3.5 tour let's say GPT4 you will
11:40see that those model uh probably they
11:43have trained u uh on the year 2022
11:48or 2023 around okay uh till the date
11:52they have taken all of the data from the
11:54internet and they have trained those are
11:55the model so uh whenever I'm asking
11:58about the python so definitely uh in
12:012020 22 or 2023 this information was
12:04available on the internet and definitely
12:06our large language having this kinds of
12:09knowledge right so it will be able to
12:11give you the answer in short or directly
12:14but whenever I'm asking anything which
12:17is latest say I'm asking um I'm asking a
12:20latest information I'm asking like tell
12:23me about uh like uh the latest news of
12:27Iran and USA okay over in 2026 six. So
12:31that time definitely uh if you are using
12:34a single large language model okay uh
12:37this kinds of large language model won't
12:39be able to give you the response okay it
12:41will tell I don't have enough context
12:43okay uh after 2022 or 2003 so I I can't
12:48um answer your questions okay this kinds
12:51of I think you will uh get the answer if
12:54you have used the older chart GPT I
12:56think you are getting what I'm trying to
12:57say so but if I'm talking about uh
13:01nowadays uh whatever application we are
13:03using like clouded desktop then
13:06anti-gravity cursor id if I'm giving any
13:09kinds of uh prompt let's say I'm telling
13:12um just try to uh implement a
13:15application for me let's say implement a
13:18python game for me so what it it will do
13:20it will try to take that prompt as a
13:23command and it will automatically let's
13:25say plan for a task like what to do okay
13:28how uh it can implement the entire game
13:31for you. So to implement a game first of
13:33all it has to uh create the environment.
13:35It has to uh add the requirements. It
13:38has to uh create the user interface. It
13:41has to make the character. Okay. So one
13:43by one all of the plan would be sorted
13:45then once all the plan is ready. Okay.
13:48It will execute the plan one by one and
13:51it will complete the entire system and
13:53definitely in between it will try to
13:55test that particular let's say
13:57application. Okay. If uh it uh doesn't
14:00get any kinds of bugs, it will continue
14:02and it will complete that particular uh
14:04work for you. Okay. So that means
14:07everything is happening automatically
14:09and sometimes you will see that in
14:10between it will ask a human interaction.
14:13It will ask for a human input. Let's say
14:15whenever it will try to implement a game
14:18that time it might ask you what kinds of
14:21color you want for this particular
14:22environment. How many character you want
14:24in this particular game? what would be
14:26the let's say car color what would be
14:29the car speed okay so sometimes it will
14:32ask some kinds of questions to the human
14:34okay for the guidance and once uh we'll
14:37try to provide the feedback or let's say
14:39our input it will take that input again
14:41it will try to continue the workflow
14:44okay so that's why here you can see it
14:46is telling with minimal human guidance
14:48okay not not complete human guidance we
14:51give like very minimal human guidance
14:53here and it try to uh plans takes action
14:56okay adapt to changes let's say it has
14:59let's say it has to do one particular
15:01changes in the environment or let's say
15:03color or let's say any character it will
15:05automatically do that okay and it seeks
15:08help only when necessary so guys before
15:11I uh give you the entire discussion on
15:14this agentic AI first of all I want to
15:17walk you through the fundamental concept
15:19of generative application like so far
15:21whatever application uh we usually uh
15:25Great. Okay. And how this agentic uh AI
15:28or let's say AI agents came in the
15:29market. Then we'll try to understand uh
15:32this agent concept. So for this guys I'm
15:35going to take you on my whiteboard and
15:37then we'll try to discuss each and
15:38everything. So guys I'm inside my board.
15:41So here I'm going to write down each and
15:43everything.
15:44So see whenever I'm talking about
15:48uh AI agents right
15:52AI
15:55agent
15:57so this is the application of generative
16:00AI
16:04okay this falls into generative AI
16:07domain and uh those who are already
16:10working with generative AI so I am
16:12having a dedicated course on my channel
16:15the complete generative BI course. So
16:16there I have already discussed the
16:18foundation of generative BI. So in that
16:20course I have already taught you um all
16:23the concept regarding generative AI
16:26large language model. Okay uh retrieval
16:28augmented generations. Uh so each and
16:30everything I have already covered there.
16:32So if you are not familiar with
16:33generative AI first of all try to
16:35complete that particular course then it
16:37would be easy for you to understand.
16:39Okay. So in generative AI uh the main
16:42component we usually work with large
16:46language model. Okay large language
16:48model. So there are different different
16:50large language model nowadays. I think
16:52you know um there are some organization
16:55there are some company they have
16:58launched different different models. If
17:00I'm talking about meta okay meta AI so
17:03they have launched something called
17:05llama.
17:09Okay. Llama. Then if I'm talking about
17:14OpenAI, they have launched GPT.
17:18Okay. Then we are having Mistral.
17:25We are having
17:27Gemini.
17:29Okay. This is from Google. So that's how
17:32we are having different different large
17:34language model. Uh nowadays we usually
17:36use. So previously whenever we started
17:40generative BI that time um we used to uh
17:46only use a fine-tune uh fine-tune based
17:49or let's say uh pretend based large lang
17:51based model. Let's say here I'm having a
17:53large lang based model. So we used to
17:57provide a prompt
18:00okay prompt and it used to give a
18:03response.
18:06Okay. Response. So basically we used to
18:09use this large lang based model for text
18:11generation. Okay. For very uh good
18:14quality text generation or uh for some
18:18other task also we used to use like for
18:20language translation.
18:27Okay. Then for text summarization
18:35then definitely for chat operation how
18:39we used to ask different kinds of
18:41question and we used to get the response
18:44then definitely for
18:47like uh some other NLP task like any
18:52and so on. Okay. So initially those who
18:56have already used this chart GPT I think
18:58you are trying to relate the concept
19:00what I'm trying to say it was like a
19:03very basic application okay we used to
19:05use for this kinds of text generation
19:06task but slowly what they did uh they
19:10actually introduced uh also image
19:12generation okay image
19:17generation
19:20so image generation happens whenever
19:22they introduce something called
19:23multimodel system. So in the multimodel
19:26uh you not only generate the text there
19:28you can also generate the image. Okay
19:31but what was the problem with this kinds
19:33of application as I already told you
19:35let's say if I'm talking about any kinds
19:37of large language model it is having a
19:40knowledge cutff okay this is having a
19:45knowledge
19:47cutff
19:50so what is knowledge cutff let's try to
19:52understand. So for this let's go to the
19:54Google and here if I am searching for
19:57any kinds of model. Let's say I'm
19:58searching for open AI models. Let's open
20:02up the models.
20:05Now let's pick any kinds of model from
20:07this openi. So let's say if I'm talking
20:10about the GPT4 uh 5.4 mini or let's see
20:13if I'm taking any older model. Older
20:15model. Yeah. So I think here some models
20:19are available. Let's say if I'm talking
20:21about this um
20:25the view wall.
20:27Let's say if I'm talking about this
20:28GPT4.1. So if I click on this model, you
20:32will see that this model having a
20:34configuration. Configuration means the
20:36context window like uh how much context
20:39it can take then maximum output tokens
20:43how how much token it can generates and
20:46there is a section called knowledge
20:47cutoff. Okay. So here the knowledge
20:50cutoff you can see January 1, 2024 that
20:53means this model uh has been trained uh
20:57till January 1, 2024
21:00uh internet data. Okay. So if you're
21:02asking anything after that let's say
21:04you're asking February 1, 2024
21:07definitely um this model is not going to
21:10give you the response because this model
21:12doesn't have uh the knowledge after uh
21:15January 1, 2024. Okay, whatever let's
21:19say uh recent uh update uh we are having
21:22on the internet this this model doesn't
21:24know about that. So the main problem I
21:27think you can understand let's say if my
21:29prompt
21:30is uh before okay before this particular
21:33knowledge cutff the information I'm
21:35looking for on from my large language
21:37model definitely this model uh can give
21:40you the response but if it is after the
21:42knowledge cutff that time it will not
21:44able to give you the response okay it
21:46will tell I don't have the um context I
21:49don't have the informations okay after
21:51this particular knowledge cutff so I'm
21:52extremely sorry for that so that that is
21:55the uh things actually uh uh happened uh
21:59whenever charg came okay uh initially in
22:02the market and I think you remember okay
22:05uh charg used to give this kinds of
22:07response then uh what uh they have
22:10introduced
22:11they have introduced a concept called
22:13rag okay why they have introduced the
22:16concept called rag because now let's say
22:19if I want to add some other information
22:21let's say this is 2026
22:24so now I have to I want to add some more
22:26informations okay inside my large bank
22:29model. So what I have to do I have to
22:31finetune this model right I have to
22:35fine tune this model and finetuning
22:38means we are taking the pre-ten model
22:42okay and on top of that we are adding
22:44some new data
22:47adding new latest data and we are
22:50training few parameters here okay and
22:52whenever I'm talking about the LLM
22:54parameters it will count like from
22:56million right million to billion
23:00Okay, this is the issue. So fine-tuning
23:02is not an easy task. For this you need a
23:04good resources then um good budget.
23:07Okay, then you you should have also
23:10time. If you're having these kinds of
23:12things then you can easily fine-tune one
23:14large language model. Okay, there is no
23:17issue with that. So for the company this
23:20fine-tuning task was easy because
23:21they're having a good resources. They're
23:23having uh like very uh heavy investment.
23:26Okay, they're having lots of time. So
23:28they can do that. But what about for the
23:30developers? Let's say if I'm creating a
23:32application, okay, for my client and if
23:35any new data is coming and I want my
23:38application to be aware on top of this
23:40new data. So for me for for me as a
23:43developer, this is this is going to be
23:45like very hectic task like for
23:47fine-tuning a model because I don't have
23:49this kinds of supercomput with me. I
23:51don't have this much of budget okay so
23:54that I can purchase a good cloud for the
23:56training. I don't have that much of time
23:58time so that my client will wait for me
24:01because they has to also do the business
24:02right if I'm running my business also
24:04this should be continuously running and
24:06I should have handled all of the client
24:09with the latest informations and
24:11everything okay so that time researcher
24:14introduced something called rag concept
24:17okay this is called retrieval
24:21okay retrieval augmented
24:27generation.
24:30Okay. Reg rack component. In the rack
24:33component uh concept what we used to do
24:36let's say we are having a large language
24:37model. This is completely fine.
24:40Let's say we are having a large language
24:42model.
24:47Okay. So it will be connected to a
24:51knowledge base.
24:54So knowledge base is basically a
24:56database.
24:58Okay, it's a vector database.
25:02So this is called knowledge base. So it
25:04is having all the latest information,
25:11latest data I can say.
25:15Okay. So this data you have to store in
25:18the knowledge base and you have to
25:19connect with your large language model.
25:23Okay. And for this kind uh connection we
25:26use the orchestration framework. Some
25:27orchestration framework uh I think you
25:29know inside generate we are having lang
25:32chain we are having llama index. Okay.
25:33So this is called orchestration
25:35framework. So we use this kinds of
25:36orchestration framework uh to make the
25:39connection with our LLM.
25:41Okay. Now if user is asking anything
25:45okay let's say user is giving uh input.
25:48Okay. First of all, this input would be
25:50verified in the uh pre-ten model that
25:54means the large language model itself.
25:56First of all, it will try to check
25:57whether this information he's asking or
26:01what kinds of uh question they're
26:02asking. It is available in the LLM
26:05itself or not. It is available in this
26:07knowledge cutff or not. If it is having
26:11okay in this knowledge cutff, this will
26:13give you the response directly. This
26:15will give you the response. Okay, this
26:18will give you the response directly.
26:21But what about this information is not
26:23available that time. It will go to the
26:25knowledge base. It will go to the
26:27knowledge base. Okay, it will do
26:28something called semantic search,
26:30similarity search. This will get the
26:32relevant uh result about the questions
26:36user is asking. Then this particular
26:39relevant answer again your large
26:42language model will take it will try to
26:44analyze it will try to um it will try to
26:47clean up it will try to rearrange the uh
26:50response then it will try to send it to
26:52the
26:54user again. Okay that's how the entire R
26:57system works.
26:59Okay system works. So basically the
27:02major component we have added this
27:03knowledge base and adding data in the
27:06knowledge base. It is super easy because
27:08only you just need to uh fetch the
27:11latest informations and add in the
27:13knowledge base and uh your LM is already
27:16connected to the knowledge base. So
27:17anytime if you're asking any kinds of
27:19question it will uh bring that
27:21particular latest informations and uh it
27:23will do the refining operation then it
27:25will pass to the human. Okay. So this
27:27will work like that. Okay. And this was
27:31the like uh very famous technique uh
27:34that time even nowadays also we use the
27:37same technique we we create the rag
27:39application and this actually helps us
27:42uh from this finetuning operation
27:44because here we are not doing the
27:46finetuning okay on our LLM only we're
27:49just working on the knowledge base we
27:50are adding the data in our vector
27:52database this is the things right but
27:55there are some problem with this vector
27:57database or this RG system what is the
27:59problem. Whenever I'm talking about the
28:02real time data, realtime data means the
28:03data is continuously changing. Let's say
28:05if I'm talking about weather
28:06informations, if I'm talking about
28:08temperature, if I'm talking about uh the
28:11latest news, okay, it is continuously
28:13changing. That time it is not possible
28:16for me to sit down whole day and take
28:20all of the latest informations and like
28:22add in my knowledge base. Okay, that
28:24that kinds of things we can't ever do
28:26that. So that that is why this rack
28:30system fails. Let's see if we're asking
28:32questions to the rack system. Let's say
28:34tell me about latest news. Okay, right
28:37now in the morning. So definitely this
28:39information is not available in the
28:40knowledge base. Okay, let's say morning
28:42news you have added but what about the
28:45afternoon news? What about after 1 hour
28:47news? Okay, so these kinds of things you
28:49don't have. Okay, so that time your
28:53application won't be able to give you
28:54the response. So what you have to do
28:56that time you have to
28:59uh you have to think about a different
29:01approach. So that's why researcher
29:03thought why not we can create a agent.
29:06Okay why not we can create a agent. So
29:08that agent will be connected with some
29:11tool. Okay tool means we can use
29:13different different tool here. Uh let's
29:15say uh we can use any kinds of search
29:17tool. We can use any kinds of uh storage
29:20tool. We can use any kinds of calendar
29:22tool, Google drive tool. whatever we can
29:24use but there should be some kinds of
29:26tool. So with the help of that
29:28particular tool my AI agents will try to
29:30fetch the informations and it will give
29:33to the user. Okay. So what they
29:34introduce that time they introduce a
29:38agent system. Let's say this is your
29:41agent.
29:43Okay. Agent uh internally it is using a
29:46large language model only. Okay.
29:47Whenever user is giving any kinds of
29:49input it is connected with some kinds of
29:51tool. Okay. So let's say if I'm asking
29:54for uh any latest informations that time
29:56it is connected with a search tool okay
29:59internet search tool. So mostly this
30:01will search on the Google and Google is
30:03continuously updating okay with latest
30:05informations. So if you're asking any
30:07realtime question first of all what it
30:09will do it will um use this search tool.
30:12It will search over the internet it will
30:14get the informations okay latest
30:16informations and your agent LLM is
30:18trying to refining that and it is giving
30:20you the response again. Okay. And why
30:24I'm calling this particular system as a
30:25agent? Because your application is smart
30:28enough to understand what it needs to
30:31call this call this tool where when it
30:34doesn't need to call this tool. Okay.
30:35This kinds of uh reasoning capacity your
30:38application will be having. Okay. That's
30:40why we call it as a agentic agentic
30:42system. Okay. Here we are not deciding
30:45when to call this particular tool. You
30:47just give the prompt okay to the
30:49application. applicant uh application
30:51will decide whether I has I have to call
30:54this tool to get uh uh give the response
30:57or I have this information with me so I
31:00can give you the response okay so this
31:02kinds of capacity it was having so this
31:05was the first agent they have introduced
31:07with some realtime tool so if I uh take
31:10you to the chart GPT so let me give you
31:13the example so I'll open the chart GPT
31:17and uh here let's say
31:21I'm asking a question. Let's say I'm
31:23asking tell me
31:26about
31:28okay Python.
31:31Now see what will happen.
31:34Uh this is directly giving you the
31:37answer. Okay. It is not referring any
31:39kinds of tool search tools. It is not
31:41searching on the internet. Okay. Instead
31:43of that what it is doing? It is giving
31:45you the direct answer. Okay. because
31:48this information is already available in
31:50the knowledge bed itself. Okay,
31:52knowledge uh knowledge uh LLM knowledge
31:55itself. Okay, because it is already uh
31:58having uh before the knowledge cutoff.
32:01Get it? But whenever I'm searching for
32:04any other question, let's say I'm
32:05telling tell me
32:08the
32:10latest
32:14news
32:19News of
32:21India election.
32:26Now if I search that now see it is
32:29searching for web. Okay it is searching
32:31for web. It is using a internal search
32:34tool and with the help of that it is
32:36searching over the internet and it is
32:39referring some trusted uh let's say
32:42sources like Alajira ABC news. Okay,
32:46that's how it is searching on different
32:48different website. Okay, now if I open
32:50this website, you can see that this is a
32:52website. This is another website. Okay,
32:54and this website has already this kinds
32:56of latest news. It is bringing that
32:59particular informations. It is passing
33:01it to the LLM. LM is trying to refining
33:04LM is trying to summarizing all of these
33:07let's say uh all of this content of
33:10these kinds of sources and this is
33:13refining and giving you the
33:15answer okay refined version of answer
33:18okay so this is called actually um agent
33:22system okay it is utilizing some kinds
33:25of uh tools in the back end and this
33:28application is automatically deciding
33:30when it needs to call that tool tool
33:33when it doesn't need to call that tool.
33:36Okay, not only that, this is a simple
33:38example I have shown if you have already
33:40used uh like uh anti-gravity. Let's say
33:44if I open up my anti-gravity.
33:47So this is my anti-gravity. So here I
33:49can uh give the prompt to the agent. So
33:53let's say here I am telling
33:56um create
33:59a
34:01car racing game using Python.
34:11Okay, Python. Now here you can um select
34:14different different model because
34:16internally I told you agent uses a large
34:18language model. Okay, because this is
34:20the brain. Okay, it is having the
34:22reasoning power and it decides actually
34:25when to use the tool when uh it doesn't
34:27need to use the tool. Okay, so here you
34:30can select different different model. So
34:31anticip supports these are the model you
34:33can select any of them. Now if you give
34:36this prompt you will see that
34:37automatically first of all it will try
34:40to make the plan. Okay, what to do? Now
34:42see it is telling generating. Let's
34:44wait. Now see it is thinking. Okay, it
34:47is thinking. Now it is trying to making
34:50the entire plan for you. Okay. How it is
34:53going to uh create that particular uh
34:56racing game with the help of Python.
34:58What are the resources it need? What are
34:59the tools it needs? It will try to make
35:02the entire plan. See this is the plan.
35:05You can see this is the plan. Okay.
35:06Proposed plan. Now what it will do in
35:09the plan? First of all, it will do the
35:11initialization. Set up the pygram
35:13display front and clock. Then player
35:16card, obstacle, uh collision stone
35:18detection, score system, give over
35:22screen. Okay. Then what are the
35:24requirement? It needs verification plan.
35:26So this is the agent plan guys. That's
35:28how one agent works. First of all, it
35:30has to make a plan and based on the
35:32plan, it will start working on that.
35:36Okay. Now I told you in the definition
35:38itself uh it will seek for help when it
35:43necessary. That means little bit of
35:45human interaction is also needed. Now
35:47this plan is proposed to me. Now I can
35:50review the plan. Okay. I can make some
35:52changes. Okay. So let's say if you want
35:55to change anything. Let's say you don't
35:57need this particular step. You can
35:58change anything. Okay. You can change
36:00anything. You can edit anything. Okay.
36:02Then you can review it. You can like
36:05tell okay this plan is completely fine
36:07for me. You can continue. Now let's say
36:08if I do uh
36:12uh the plan
36:16is fine.
36:18Go ahead.
36:21Okay.
36:22Now if I give the prompt
36:25I think prompt uh you can't see because
36:27this is uh just uh beside my image but I
36:32think you can see okay uh the prompt I
36:34have given. Now see now it has started
36:37working on the plan okay one by one it
36:40will work on all of the plan okay and it
36:43will try to implement the entire game
36:45for you okay so this is called AI agents
36:49nowadays so AI agents is like uh this is
36:53not uh I mean um I mean uh restricted to
36:58the tools only okay now it can automate
37:01the workflow this is called automation
37:03right here I'm not writing the code. See
37:05my agent is writing all of the code and
37:08it is asking for the approved. Okay, if
37:10I show you, if I let's say show you, so
37:14here you can see it is telling do you
37:16want to run this pip install command. So
37:19it is asking for human interaction. Now
37:20if I give the human interaction if I
37:22give if I tell yes do it. If I tell okay
37:26I accept the code now the rest of the
37:29task it will automatically do that for
37:30me. Okay. So this is called AI agents.
37:33Now I think you have understood this
37:35particular definition. Now let me show
37:37you the definition once more time.
37:40So this is the definition guys. Okay. So
37:42here you can see agentic is a type of AI
37:45that can take up a task or goal from a
37:47user. So the here the task and goal I
37:50have given just create a car racing game
37:52with the help of Python. So then what it
37:54will do it will work towards completing
37:56uh this particular task is own with
37:58minimal human guidance. First of all it
38:00will try to plan. Okay. Then it will
38:02take action, adapt the changes. Okay,
38:04let's say whenever it requires any kinds
38:06of changes, it will automatically do
38:07that and seek help when it necessary.
38:09That means it will uh ask for my help.
38:12Okay, if I want to change anything uh so
38:15it will ask for that particular help for
38:17me, it will ask for ask uh for my
38:20feedback. Okay, if I give the feedback,
38:22it will start working on that. Okay. So
38:24I think guys you have understood uh the
38:27entire uh evaluation of this uh agentic
38:31AI how this agentic AI came okay right
38:34now in the market. Now in the next video
38:36guys what I'm going to do I'm going to
38:39uh discuss this agentic AI in detail.
38:42Okay the application working mechanism.
38:46Okay, I'm going to show you one example
38:49like how uh one aentk application works.
38:52Whenever we give any kinds of uh
38:54command, okay, we give any kinds of
38:56prompt. I think you have seen although
38:57in anti-gravity we given a prompt and it
38:59creates the plan. After creating the
39:01plan, what it will do, okay, each and
39:02everything I'm going to give you. I'm
39:04going to uh tell you the characteristic
39:07of this agent. What are the
39:08characteristic it follows? What are the
39:10component it is having? Okay. So with a
39:12good example, we'll try to understand
39:14the entire concept in the next video. So
39:16yeah, this was uh uh this was only the
39:19understanding uh like about this agenti
39:23evaluation like how this aenti came in
39:25the market and whatever traditional
39:27application we used to create in the
39:29geni. Uh nowadays people are uh actually
39:32um uh people are moving to the agentic
39:35protocol. People are moving moving to
39:36the workflow automation instead of
39:38creating the simple uh actually take
39:40generation based application because
39:42right now uh everything can be automated
39:45all the workflow can be automated. Okay.
39:47Uh instead of working on manually uh we
39:50can create a agents and that that agents
39:53will try to complete that particular
39:55task for me. That's how you can also
39:57scale up your business. You can uh you
40:00can actually uh uh create some agents
40:03for your business. So it will run
40:05automatically. It's a customer support
40:07agents you can create okay automatically
40:10uh email center agents you can create.
40:12So that's how you can minimize the uh
40:15employee in your company and you can uh
40:17save your budgets okay but let's say if
40:19you don't have this kinds of agent
40:21system that time what you have to do you
40:23have to hire someone to do that
40:24particular task. Okay, that's why
40:26companies are uh adopting this AI agents
40:29in their uh application development in
40:32their workflow automations. Okay,
40:34they're replacing some low-level
40:36employee uh which uh they feel like okay
40:39I don't need this kinds of employee and
40:40I can do this kinds of work uh automated
40:43way. Okay, people are uh thinking in
40:46that way. Okay, you have to also be
40:48smarter. Now people ask like uh whether
40:51we'll have the job or not. Okay,
40:53definitely you will have this job but
40:56you have to learn these kinds of
40:57technology. If you know these kinds of
41:00technology then tell me who will replace
41:01you. But if you don't know this
41:03technology let's say still you do the
41:05Excel uh uh let's say uh data collection
41:09autom uh data collection let's say uh
41:12strategy. Now tell me I can easily
41:14create a agents and I can do the Excel
41:16data collection.
41:18Okay. I can um easily handle the
41:21customer automation. I don't need
41:23someone to handle my customer. Let's say
41:25whatever customer uh are coming to my
Agentic AI: Core Characteristics & Components
41:28website. Okay, I don't need to like uh
41:30hire someone to sit and reply for that.
41:33So what I will do, I'll just create a
41:34agents. I'll give all of the
41:35informations about my website, all of my
41:38services. My agents will take care
41:40everything. Okay, this is the things uh
41:42nowadays people are moving. Okay, so
41:44yeah, trust me guys, this uh particular
41:46skill is having high demand in the
41:48market. So if you can master this one
41:50definitely you can um you can get lots
41:53of opportunity. Okay and I will try to
41:56complete this agentic in such a way so
41:59that uh after completing it you can
42:01create any kinds of agentic
42:03applications. So in this video I'm going
42:06to discuss about the detailed discussion
42:09about agentic AI. How uh one AI agent
42:12works how one agentic AI application
42:15works. we'll try to understand uh each
42:18and everything with a good example.
42:20Apart from that, I'm going to also
42:22discuss about the key characteristics
42:24and key component of agenti system. So
42:27this is going to be one amazing
42:29discussion guys. Make sure you watch uh
42:32till the end and if you have any kinds
42:34of doubt feel free to comments in the
42:36comment section. So instead of talking
42:39too much guys let's start with our
42:41discussion.
42:42So guys on my screen I think you have
42:44seen the definition of agentic AI. So
42:47this definition is already familiar with
42:49you. Uh in my previous video I have
42:51already given you the walk through. Let
42:53me uh again give you the walkthrough of
42:56the definition. As you can see, agentic
42:59AI is a type of AI that can take up a
43:02task or goal from a user and then work
43:06towards completing it on its own with
43:10minimal human guidance. It plans, takes
43:13action, adapt to changes
43:17and seeks helps when uh necessary. So in
43:21my previous uh video guys, I have given
43:24you the demo of a AI agents application.
43:26And I think I showed you the
43:28anti-gravity example. So there what
43:30happens? Let's say whenever I used to
43:32give a prompt. Uh there I given a prompt
43:34like just uh create a game for me, color
43:37racing game for me with the help of
43:38Python. So what it was doing? It was
43:41creating a complete plan. Okay, I think
43:43you remember it was creating a complete
43:45plan like what to do, what are the
43:47environment it should use, what are the
43:48package it should use. Okay, then uh
43:51what should be the color, what should be
43:53the uh let's say involvement. So it each
43:56and everything it was uh like making the
43:59plan. Okay. After making the plan guys
44:02what uh it started it was looking for my
44:05confirmation whether if everything is
44:07fine or not. So it was looking for a
44:10minimal human interaction. Okay minimal
44:12human guidance. uh so whenever I
44:14approved everything it started uh taking
44:17the actions that means one by one all of
44:19the plan it was starting executing right
44:22and it was uh creating that particular
44:24games for me okay so that's why uh this
44:28definition is uh I think pretty clear
44:30like how one agentic system works but if
44:33I'm talking about a simple chatbot okay
44:35uh uh so in simple chatbot what happens
44:38you just try to do some question answer
44:40okay it will give you the answer with
44:42respect to that But it doesn't have any
44:44kinds of let's say tool integration. It
44:46doesn't have any kinds of let's say
44:49reasoning capacity. So that it can
44:52automatically think like okay now I have
44:54to use the tool and now I don't have to
44:57use the tool. Okay but in aenti
44:59application it has the cap capabilities
45:04for selecting uh any kinds of tools it's
45:07required. Okay. Let's say you are uh you
45:10are uh doing some automatic coding or
45:12let's say you are creating a game right
45:14that time what kinds of tools it is
45:15required it will automatically call that
45:17tool and it will start creating that
45:19particular application for you. So let
45:22me give you one example guys uh how this
45:24agentic system works.
45:27So as you can see guys uh this is the
45:29example I have taken. So let's say uh
45:32this is our agentic uh agentic system.
45:34Okay, this is a aentic AI application.
45:37So let's say DSP with BPI uh wants to
45:41hire some backend engineer or let's say
45:44some other kinds of engineer. So what I
45:46have done I have created this agent
45:48system okay for my platform. Now uh
45:52let's say if I'm not using this kinds of
45:54platform so what I have to do maybe I
45:56have to hire someone okay so he will try
45:59to or she will try to prepare everything
46:03okay for this particular job role that
46:05means the job description then once job
46:07description is ready uh he or she will
46:10be posting over different different job
46:12platform then uh they will continuously
46:15monitoring that how many applications
46:17are coming once uh application are
46:20getting submitted Again they will try to
46:22review that if application is coming
46:24very less again they will try to update
46:26that particular job description with a
46:28different job role again try to upload
46:30that okay that's how they will be
46:33continuously monitoring and once
46:34application got submitted we'll try to
46:36review that and once reviewed everything
46:38is fine okay let's say we got some
46:40amazing candidate we'll start uhuling
46:43the interview we'll take the interview
46:44after uh taking the interview what I
46:46have to do I have to uh I have to
46:50actually
46:51prepare a offer letter for him. Then
46:54we'll be sending the offer letter and
46:56once offer letter is approved then we'll
46:58try to u u do the onboarding operation.
47:01So this is a like very long and
47:03time-taking process and here I have to
47:05definitely uh pay for that particular
47:08work right uh let's say the person I'm
47:10hiring for this one so definitely I have
47:12to pay for uh that right but let's say I
47:14don't want to pay because nowadays
47:16people are using agenti system so what
47:18I'm going to do let's say I have created
47:20this agent for me so what this agent
47:23does so this agent is already connected
47:25with my platform DS with BP so it is
47:27having all the data okay about my uh
47:30about my let's say platform and I have
47:33already told uh this particular agents
47:36like what kinds of candidate I want what
47:38kinds of job requirement they are having
47:40what is the salary okay each and
47:42everything I have given uh uh okay uh uh
47:44to this particular agent now here what
47:47I'm going to do I'm going to simply give
47:48a prompt I want to hire a backend
47:50engineer and uh they should have two to
47:54four years of experience okay let's say
47:56this is my prompt so first of all I
47:58think you remember what a agent will do,
48:01right? A agent will first of all try to
48:03make a plan. Okay, a agent will try to
48:06make a plan. But how it is going to make
48:08the plan? First of all, the command the
48:11prompt you are giving this command and
48:13prompt would be taken as a goal. So as
48:15you can see uh my agent goal is hire a
48:18remote backend engineer. Okay. Uh uh
48:21their experience should be two to four
48:22years of experience and this is the plan
48:25actually it has automatically created.
48:27Now just try to see the plan. Okay. The
48:29way actually a manual human will do
48:32that. It has done the same thing. Okay,
48:34but with a revised version. Now you can
48:37see it is giving me a plan. First of
48:40all, it will try to make a draft job
48:42description and post on best platform.
48:45Okay, let's say LinkedIn it can post.
48:48No, it can post. Okay, then some other
48:53job uh platforms are also available.
48:55Okay. So there it will try to post that
48:57particular job description. So once
49:00posted it will continuously monitor the
49:02pipeline. Okay. Monitor the pipeline
49:04means let's say I have posted a job
49:06description. It it uh it doesn't mean
49:08that I will just try to disappear right
49:11automatically application will come.
49:13It's it's not like that. You have to
49:14continuously monitor that particular
49:16applica job description like how many
49:19applications are coming uh what are the
49:21candidates are applying for? Is there
49:23any issue or not? Right? we have to
49:25continuously monitor that particular
49:26pipeline. So what we are going to do
49:28guys, we'll be continuously monitoring
49:32that pipeline. So agent is also telling
49:34will monitor the pipeline and adjust
49:36strategy if needed. Okay, so it will
49:39automatically adjust. Okay, this
49:41particular strategy if needed. Let's say
49:43you are getting very less application.
49:45Let's say your expectation is let's say
49:4850 application but you are receiving
49:50four to five application that time
49:51definitely this is not uh meets your
49:54expectation right definitely there
49:56should be some problem with the job
49:57description that's why candidate are not
49:59preferring that uh uh preferring your
50:01job description so what agent will do
50:04maybe agent will try to change the job
50:06description let's say instead of backend
50:08engineer maybe uh it will tell like
50:10fully stack engineer or let's say fully
50:13stack AI engineer okay or let's say web
50:15developer. These kinds of uh job ro
50:18again it will try to set and again it
50:20will prepare the job description. Again
50:21it will post on the platform. Okay. Then
50:24again it will continuously monitor that
50:26particular pipeline. Then let's say now
50:29this particular pipeline is working
50:31fine. Uh so people are applying for that
50:34particular job role. We are getting lots
50:35of candidate. So from the all of the
50:37candidate guys we'll try to filter out
50:39like what would be the best fit for this
50:42job. for this particular job role we'll
50:44try to select that particular candidate.
50:46So agent will try to select that
50:47candidate and maybe let's say it will
50:49take two to three candidate and it will
50:51schedule interviews for them. Right? So
50:53once interviews is scheduled then uh it
50:56will uh we'll be taking the interview
50:59then after that uh let's say we selected
51:02a candidate agent will try to draft the
51:06offer letter. So offer letter would be
51:08created and it will be sending to the
51:10candidate. Once candidate is approved
51:12then uh it will start the onboarding
51:15process. Okay. So this is the entire
51:17plan it has proposed. Okay. It has the
51:19entire plan it is proposed. Okay. Now
51:22after preparing this particular plan I
51:24think you remember it will first of all
51:28okay it will first of all ask me should
51:31I continue with that? So definitely you
51:33have to give a permission. Yes continue.
51:35Okay. Then what it will do? It will
51:37first of all see what was the first
51:39plan. First one is drafting the job job
51:42description. Okay. So it will tell now I
51:44will first start with the drafting the
51:46job description taking help from the
51:48company documents like let's say I have
51:50already given my platform access okay DS
51:53with buppy platform access. So it is
51:55having all the documents all the data
51:57okay what are the things I am having the
51:59requirement it will try to take all of
52:00the data and it will try to prepare a
52:02job description for that and now it is
52:05telling do you want me to make some
52:06changes I'll try to review the entire
52:08let's say job description if completely
52:11fine with me so I'll just try to tell no
52:13this is absolutely fine you can continue
52:15with that now let's say my agent has
52:17prepared one job description for the
52:19backend engineer let's say we are
52:20looking for a remote backend engineer
52:22with two to four years of experience in
52:24backend development ment blah blah blah.
52:26Okay. So once this particular job
52:28description is ready, now the second
52:31plant was posting the job description in
52:33a different platform. Okay. Now it will
52:35tell all right shall I go ahead and post
52:37this job description on the following
52:39platforms like LinkedIn, no etc. Uh so I
52:43will try to review again and again I'll
52:44tell the yes you can do that. Then what
52:46it will do? It will try to post that
52:48particular job description.
52:51uh uh then uh it will tell I will
52:53continuously monitor the application and
52:54keep you posted and for uh posting this
52:57particular job description on a
52:58different platform we have to connect
53:00with the API of the platform okay so
53:03this particular API we can call it as a
53:05tool okay so LinkedIn having a tool no
53:09is having a tool okay that's how there
53:11are uh thousands of like u uh I mean job
53:16posting platform they're having the tool
53:19so you just need to give the tool access
53:20to the agent. So agent will try to
53:22decide when to call what kinds of tool.
53:25Okay, maybe you can't see now I think it
53:27is visible. So just right hand side you
53:29can see uh it is calling the API okay as
53:32a tool and it is trying to access over
53:35the LinkedIn and no and it is posting
53:37that particular job description in that
53:39particular platform. Okay so that's how
53:42this kinds of agent works. Now what
53:44should be the next plan? Let me show you
53:47what should be the next plan. Next plan
53:49would be revising the job description.
53:52Okay, let's say it was continuously
53:54monitoring. Okay, it was continuously
53:56monitoring the pipeline. Then it just
53:59received uh you can see the job posting
54:01uh posting has received only two
54:03applications so far much below our
54:05expectation. Let's say my expectation
54:06was 20 application but I'm getting only
54:09two applications. So definitely there
54:11would be some problem with my job
54:13description. So my agent has suggested
54:15me some kinds of feedback. Okay, you can
54:18see it is suggested some action. So it
54:20is telling uh broaden job description to
54:23include fully stack that uh that means
54:26instead of giving the backend engineer
54:28maybe we can make it to fully stack
54:30engineer because fully stack engineer uh
54:33might have demand in the market and
54:35people are looking for this kinds of job
54:38and promote job on LinkedIn or let's say
54:41no okay so what it is trying to say it
54:44is trying to say like why not we can
54:46promote that particular
54:48job on the LinkedIn
54:50by doing the advertisement. Okay, maybe
54:53by doing the advertisement uh it will go
54:55to that particular candidate and he or
54:58she might be interested and they can
54:59apply. Now it is telling shall I proceed
55:01with that? So if I'm fine with this
55:03particular suggestion I'll do yes
55:06please. Okay, you just continue. So this
55:08is called actually
55:10what I think you can see the definition.
55:13Let me show you see adapt to changes.
55:16Okay, adapt to changes and seeks helps
55:18when necessary. Okay, my agent itself is
55:21trying to planning, taking action and it
55:24is doing the changes if it's required
55:26and it is also seeking the helps when it
55:28necessary. It is trying to wait for my
55:30confirmation and it is doing all of the
55:33work for me. Okay. Now what it will do
55:35again it will try to uh change that
55:37particular job description. Revised
55:39version of job description would be
55:40posted and also promotion marketing
55:43would be activated. Then again it will
55:45start monitoring the entire process.
55:47Okay. So here now
55:51um what it will do guys it will try to
55:53continuously monitor. Now let's say uh
55:56here we are getting our expectation
56:00right now let's say u revive job
56:03description posted promotion activated
56:05and it is continuously monitoring. Now
56:07let's say eight application received.
56:09Okay this is uh completely fine. Uh so
56:11what I can do uh I can screen them using
56:14our checklist strong candidate partial
56:18matches and weak matches. Okay that
56:19means it will try to divide all of the
56:21candidate in three category. The first
56:23category would be strong candidate let's
56:25say from eight application two are
56:26strong three are partial matches and
56:29three weak matches. Okay. So what it
56:32will do it will try to only select the
56:34strong candidate. Okay. with respect to
56:36my um let's say u company's requirement.
56:41Now it is telling shall I schedule the
56:42interviews with the top two. So if
56:45everything is goes fine I'll tell okay
56:46you can continue with that. Okay. So
56:49what it will do it will try to uh
56:51schedule the interview. But beforeuling
56:54what it will tell it will first of all
56:57try to check my availability. So for the
56:59availability what I can do maybe I can
57:01give my calendar access to my agent.
57:03Okay, I think you know that we can
57:05integrate any kinds of tool. Okay, any
57:07kinds of applications to the agents
57:09nowadays. You can connect uh connect
57:11your Slack, you can connect your
57:13calendar, you can connect your Google
57:14drive, anything you can give the access
57:17even if you have used already uh clouded
57:20desktop you will see that clouded
57:22desktop you can also provide your
57:23computer access entire computer access
57:26okay and you can control your entire
57:28computer this is also possible right so
57:30what I will do I will [clears throat]
57:31give my calendar access so my agent will
57:34try to check my availability
57:36okay now it is telling let's say sure
57:38let me check your availability for this
57:39week you are free on Friday. Let's say
57:41I'm free on Friday. Uh do you want me to
57:44schedule the interview on Friday? So
57:46here I will tell yes go ahead. Okay. I
57:50don't have any kinds of issue. I'm
57:52completely free on Friday. Now what it
57:54will do? It will try to draft an uh
57:56invitation email for the candidate.
57:59Let's say this is the inter uh email it
58:01has prepared. Hi candidate we would like
58:03to schedule a 45 minutes of interview
58:06for the back end role. Please share your
58:08availability. Okay. So this email would
58:11be sended. Now sixth step it will try to
58:14do the interview process. Okay. So fifth
58:16step it was doing theuling. Then fourth
58:18step it was doing the short listing.
58:19Okay. And third step I think you know it
58:21is doing the re revision of the job
58:23description. Step by step it is running
58:25the plan. Okay. Not randomly. Now once
58:28let's say candidate
58:31accepted the invitation uh of this
58:34interviewing. So what will happen? It
58:36will try to remind me. Uh so it will
58:39tell quick reminder you have two
58:41interviews lined up for Friday. So I'll
58:44tell okay uh thanks for reminding. Now
58:46it will tell I have mailed you a doc
58:49documents containing a list of interview
58:51question asked in previous interview for
58:53the same role. Now it is not only
58:55schedule the interview for me. It is al
58:58also preparing the interview questions
59:00okay for that particular job role and it
59:03is giving to me. Okay. So I'll tell okay
59:06I'll check that now let's say these are
59:08my interview question it has prepared
59:10okay now what I'm going to do I'm going
59:12to take the interview of the candidate
59:15okay manually I'm going to take the
59:17interview for the candidate let's say 30
59:18to 35 minutes I'll take the interview I
59:21will ask all of the question my agent
59:22has suggested and if uh he or she is
59:25completely fine with that questions he
59:27is he is able to give me all of the
59:29answer so definitely I'm going to select
59:31okay one of the candidate now let's say
59:33I told I have uh finalized one
59:36candidate. Can you draft an offer
59:37letter? My agent will tell sure here is
59:39the offer letter. Please review. I will
59:41tell okay yes uh it works. Then offer
59:43letter would be sended and cracking the
59:46acceptance. Okay. That means this let's
59:47this is my offer letter. Okay. My agent
59:49has prepared. It will send to the
59:51candidate. Okay. Let's say we are
59:52pleased to offer you the position of
59:53backend engineer. Please let us know. Um
59:56let uh please let us know if you accept.
59:58Okay. So once the candidate has accepted
1:00:01now what it will do it will do the
1:00:03onboarding process. Okay, after sending
1:00:04the offer later it will do the
1:00:05onboarding process. So here candidate
1:00:07has accepted the offer. I have initiated
1:00:09the onboarding. Welcome email sent. It
1:00:12access requested submitted. Laptop has
1:00:14been pro uh pro uh pro provisioned.
1:00:16Okay. Shall I schedule a introduction
1:00:18meeting with him? I'll tell yes. So the
1:00:20introduction meeting would be scheduled.
1:00:22Okay. So that's how guys a agent system
1:00:24works with a very minimal human
1:00:27interaction here. So you just only give
1:00:30to uh you just only need to give a task.
1:00:33You just only need to give a prompt.
1:00:35Let's say I want that or you have to do
1:00:36that particular work. It will
1:00:38automatically
1:00:40make the plan, take the actions and it
1:00:43will ask for the help when it necessary.
1:00:45Okay. So this is not possible with a
1:00:48simple chatbot or the simple RGB based
1:00:51application whatever we used to create
1:00:53previously. This is only possible in the
1:00:56agentic AI system. Okay. And this is
1:00:57called actually AI agents and every AI
1:01:00agents works in that way. Okay. First of
1:01:02all, it will try to make a plan and step
1:01:04by step all of the plan would be
1:01:06executed. This is called take actions.
1:01:09Then adapt the changes. That means
1:01:11whenever it necessary, it will do the
1:01:12changes.
1:01:14And whenever let's say uh it feels like
1:01:17okay, it needs to ask to the human for
1:01:19the confirmation, it will do that
1:01:20because I can't give full access to my
1:01:22agents to do everything because
1:01:24definitely there should be some uh
1:01:26manual human observation. Okay,
1:01:28otherwise uh some other things might be
1:01:30happen, right? That's why some minimal
1:01:32human interaction is required. If you
1:01:34take any kinds of agenti application
1:01:37whether it's clouded desktop, whether
1:01:39it's uh your anti-gravity
1:01:42cursor AI, it works in that way. Okay, I
1:01:45think I showed you the example of
1:01:47anti-gravity. Uh there I was doing the
1:01:50automatic coding, right? I was
1:01:51implementing a game. So there I gave the
1:01:53prompt. It was taking that particular
1:01:55prompt as a goal. After that, it was
1:01:57creating the plan. Okay? uh in the plan
1:02:00itself step by step all of the things it
1:02:02has suggested me then I approved
1:02:05everything it was creating step by step
1:02:07it was also executing in between if any
1:02:10changes required it was doing that and
1:02:12it is asking for my confirmation and
1:02:14once I confirm it is doing each and
1:02:16everything for me okay so I think now
1:02:19the agentic system is clear what this
1:02:21aentic system is how it works okay now
1:02:25we'll try to understand the key
1:02:26characteristic of a aentki application.
1:02:29So for this let's go to the next uh
1:02:32actually diagram. As you can see these
1:02:35are some key characteristic of AI uh AI
1:02:38agents or agenti applications. So the
1:02:40first characteristic you can see it
1:02:42should be autonomous. So definitely the
1:02:45example I have showed you this is
1:02:46completely autonomous agent. So there I
1:02:48already told I u I need to hire a
1:02:51backend engineer with two to four years
1:02:52of experience. So what it started it was
1:02:55started creating the plan taking the
1:02:58actions okay everything was auto auto
1:03:01automatically doing there right it was
1:03:03posting the job description it was
1:03:05continuously monitoring that it was u
1:03:08asking the help u uh to me if I confirm
1:03:13that it will again reconte the work so
1:03:15it was completely autonomous okay then
1:03:18it should be goal oriented so definitely
1:03:21the task you are giving it should be
1:03:24taking that particular task as a goal.
1:03:26Okay. Without goal, how it will achieve
1:03:28that particular work, right? So in in
1:03:30our life also whenever we get any kinds
1:03:32of work, whenever we get any kinds of
1:03:34task, definitely we have to take it as a
1:03:37goal. Okay. If we take it as a goal,
1:03:39then we can complete that particular
1:03:41goal by planning something, right? We'll
1:03:44do the different different planning.
1:03:46We'll execute those those plan and we'll
1:03:48try to achieve that particular goal.
1:03:49Okay? That's why the next
1:03:50characteristics the planning. So to
1:03:52achieve this goal we have to make the
1:03:54plan. That means for this particular
1:03:56example you saw that it was creating the
1:03:58plan like first of all job description
1:04:00would be created posting in the
1:04:01different platform continuously
1:04:02monitoring after that uh it will change
1:04:05if it is required then uhuling the
1:04:08interview
1:04:10sending the offer letter it was complete
1:04:12plan right then reasoning. So this is
1:04:15the most important characteristic of a
1:04:17AI agent the reasoning and here your LLM
1:04:20comes right because LLM is the only
1:04:23brain your agentic AI system is having
1:04:26with the help of this particular LLM it
1:04:28performs the reasoning operation and it
1:04:30automatically decides uh whether it
1:04:33needs to call any kinds of tool or not
1:04:35because your agents will have connected
1:04:37with different different tools right
1:04:39different different application sources
1:04:41and it will automatically decide when it
1:04:44needs to call what kinds of tool let's
1:04:45say whenever it was posting the job
1:04:48description it needs to call the
1:04:49LinkedIn or no API right this is the
1:04:53tool definitely it will not call the
1:04:55calendar API right so it is
1:04:58automatically thinking in that way this
1:05:01is called reasoning right then
1:05:02adaptability okay adaptability
1:05:06it should have it it it will
1:05:07automatically decide uh when to change
1:05:10something okay what should be the
1:05:12suggestion for that Okay. Then the
1:05:15context awareness. Context awareness
1:05:16means it should remember the previous
1:05:19context. Let's say I given um let's say
1:05:23I want to hire a backend engineer. Let's
1:05:25say today I have given this particular
1:05:26prompt and for some reason uh I just I I
1:05:30went out. Okay. Let's say for 2 days I
1:05:33went out. Then again I came to my agents
1:05:36and I told just tell me the progress
1:05:37about the back end engineer. Now it is
1:05:39if it doesn't have the context awareness
1:05:42that means the memory integration that
1:05:44time your agent will tell what kinds of
1:05:46back end engineering you are uh telling
1:05:49me right uh what is the task you are
1:05:51telling me I don't know about that but
1:05:52if it is having the context awareness
1:05:54that means the memory it can tell okay
1:05:57so this is the progress I have already
1:05:58posted the job description continuously
1:06:01monitoring and let's say 8 to nine
1:06:03application I got so far so this is
1:06:05called context awareness and every aentk
1:06:07application should have this particular
1:06:09context awareness. Okay. So guys, now
1:06:12let's try to see the detailed discussion
1:06:14of each and uh every characteristic. Uh
1:06:16so here I have already listed down each
1:06:19and everything. So first of all, let's
1:06:21try to understand this autonomy. Okay,
1:06:24this autonomy means the autonomous the
1:06:26first characteristic. So as you can see
1:06:28autonomy refers uh to the AI systems
1:06:32ability to make decisions and take
1:06:35actions on its own to achieve a given
1:06:38goal without needing step-by-step human
1:06:41interaction. That means if you have
1:06:44already seen the example of our AI
1:06:45recruiter so there it was kinds of
1:06:49autonomous okay it was uh it was
1:06:52autonomous agent and it it doesn't need
1:06:55any kinds of stepby-step human
1:06:57interaction so there I was not giving
1:06:59step-by-step human interaction I was not
1:07:01giving step-by-step prompt what to do
1:07:03right so the things is that I have only
1:07:05given my uh requirement my goal so it
1:07:10took that particular prompt as a goal
1:07:12It was creating the plan. It was
1:07:14executing step by step. That's why you
1:07:17can see it is uh proactive. That means
1:07:20continuously it is working on that
1:07:22particular goal. Then autonomy in
1:07:24multiple facts like execution. It was
1:07:26executing the plan step by step. It was
1:07:29doing the decision making. Okay. Uh by
1:07:31the decision itself it was uh thinking
1:07:34like what to do when it needs to post it
1:07:36on different different platform when it
1:07:38needs to make the changes. Then tool
1:07:40uses. Okay. Let's say when to use what
1:07:42kinds of tool let's say whenever I want
1:07:44to post the job description what kinds
1:07:46of tool I need to call definitely to
1:07:48call the LinkedIn
1:07:51and no
1:07:53right so this kinds of ability my
1:07:56autonomous agents will be having that's
1:07:57why the first characteristic the
1:07:59autonomy we can also call it as a
1:08:01autonomous right now the uh thing is
1:08:05that autonomy can be controlled
1:08:07permission scopes that means you can
1:08:09limit
1:08:10what uh what tools or actions the agents
1:08:14can perform independent uh independently
1:08:16can screen candidate but needs approval
1:08:19before rejecting anyone okay that means
1:08:21it's not like that I am given the full
1:08:23autonomous permission to my agents so
1:08:26definitely you can set the limit you can
1:08:28set the permission so let's say once uh
1:08:30one interviewer
1:08:33uh having the screening round uh so
1:08:35before approval or rejecting so
1:08:37definitely I I have to see that manually
1:08:41then I will approve that then my agents
1:08:42will do that for me. Then human in loop
1:08:45we can also call it as a HITL. So insert
1:08:48checkpoints where human input is
1:08:51required before continuing. That means
1:08:54in this case let's say my agent was
1:08:55telling can I post this particular job
1:08:57description or not. Okay, this is called
1:08:59human in loop and every agents are
1:09:02having this kinds of functionality.
1:09:03Okay, going forward we'll be
1:09:05implementing the agents right with
1:09:07different different uh framework. So
1:09:10there also you are having this kinds of
1:09:12functionality with the help of that you
1:09:13can um you can actually create this
1:09:16kinds of system whenever uh your agent
1:09:18is uh needed your human approval it will
1:09:21ask for that then you can continue and
1:09:23it will start working on that. Then
1:09:25override controls allow users to stop,
1:09:28pause or change the agents behavior at
1:09:31any time. Pause screening command to
1:09:34halt
1:09:35resume process. Okay. So what happens?
1:09:38Let's say in my agents, okay, whatever
1:09:41I'm doing, it's completely fine. But it
1:09:43should have
1:09:46uh it should have my control. Okay, my
1:09:49control means let's say I can stop this
1:09:51particular agents anytime. I can pause
1:09:53anytime. Let's say my um screening route
1:09:57is going on in between if I feel like
1:09:58okay I have to stop the screening route
1:10:00I if I give the command it should stop
1:10:02that okay it should stop the process
1:10:05that time okay so this is called
1:10:07actually override controls then
1:10:09guardrails and policies so definitely
1:10:12your agent should have guardrails and
1:10:13policies nowadays you will see that
1:10:16agent integrates different different
1:10:18guardrails okay and for this one
1:10:20framework came in the market called
1:10:21guardrails AI with the help On top of
1:10:23that you can define hard rules or
1:10:25ethical boundaries to the agent must
1:10:27follow. That means let's say if I give
1:10:29you one example it will tell never
1:10:31schedule
1:10:33interview on weekends. Let's say
1:10:35weekends I'm completely occupied. I'm
1:10:37not available. So I can give the
1:10:39restriction. I can give the rules. Never
1:10:42schedule interviews on weekends. So my
1:10:44agent will never do that. And if you see
1:10:47nowadays all the agenti application is
1:10:49having this kinds of guidels and
1:10:50policies. Let's say if you're asking any
1:10:52kinds of violating content, if you're
1:10:55asking any kinds of sexual content, if
1:10:56you're asking any kinds of let's say
1:10:59adult content, definitely it will not
1:11:00give you the response with respect to
1:11:02that because it has a guardrails and
1:11:04policies restriction in the agent
1:11:06itself. Okay. And for this we are having
1:11:09some library, we having some framework
1:11:12definitely will also see in our playlist
1:11:14itself. Okay. Then uh autonomy can be
1:11:18dangerous. The application autonomously
1:11:22send uh sends out job offers with
1:11:24incorrect salaries or terms. So if you
1:11:27completely make it automated, so what
1:11:28we'll do uh there is a possibility your
1:11:31agents will send a job uh job letter
1:11:34with incorrect salaries. Let's say your
1:11:36budget is one lakh but your agent is
1:11:38sending the expected salary 10 lakhs,
1:11:41right? So there definitely this is this
1:11:43is going to be an issue. So that time
1:11:45the applications shortlisted candidate
1:11:47by age or nationality violating anti-
1:11:51discrimination laws. Okay, this is
1:11:52another uh terms then the application uh
1:11:55spending extra
1:11:57on LinkedIn ads. Let's say sometimes
1:11:59what will happen if it is running
1:12:00autonomously although you are getting a
1:12:03good uh let's say application uh from
1:12:07your job description but still your
1:12:08agent will feel like okay I need more
1:12:10and it is spending more money on
1:12:12LinkedIn ads. Okay. So these kinds of
1:12:14things definitely you have to uh
1:12:16overcome. Okay. By uh actually doing the
1:12:20human in loop hit okay functionality
1:12:24inside your agent. Now the next uh
1:12:27things we are having which is uh this
1:12:31goal oriented.
1:12:33Okay goal oriented. Now you can see what
1:12:35is goal oriented. Being a goal oriented
1:12:37means that the AI system operates with a
1:12:40persistent objective in mind and
1:12:43continuously directs its actions to
1:12:46achieve that object rather than just
1:12:48responding to the isolated prompts.
1:12:51Okay, that means if you read here you'll
1:12:54see that
1:12:56goal acts as a com compass for a
1:12:58autonomy. Okay. So to make your agent
1:13:03autonomous definitely there should be a
1:13:05goal. In this case our goal was hire a
1:13:07backend engineer. Okay. This was the
1:13:09goal and will act as a compass for the
1:13:12autonomy. That means your autonomous
1:13:14agent should follow this particular goal
1:13:16and to achieve this goal it needs to
1:13:18execute different different plan. Okay.
1:13:20Now goal can be goal can comes with
1:13:22constraint. Definitely you can set some
1:13:24constraint. In this case, let's say my
1:13:26constraint was four to two to four years
1:13:28of experience candidate I only want.
1:13:30Okay. Then goals are stored in the core
1:13:32memory. That means goal should be stored
1:13:34in the core memory. That means in the
1:13:36context awareness memory otherwise your
1:13:39agent will forget that. What to do?
1:13:40Right? Let's say if I give you a basic
1:13:44actually template the common template
1:13:46for all the agents it stores the data in
1:13:48the memory. So this is a JSON format.
1:13:50Let's say you can store any kinds of
1:13:53database here. Uh internally agent uses
1:13:56a specific database or storage services
1:13:59and it stores this kinds of meta data so
1:14:02that it can remember. So in this case
1:14:04let's say the goal was hire a backend
1:14:06engineer. The constraint was 2 to four
1:14:09years of experience. Remote is true.
1:14:11Stack Python Django cloud. Okay. These
1:14:14are the skills I'm looking for. Start is
1:14:16active. My agent is always active. when
1:14:19I posted the job description. This
1:14:22particular date would be also saved.
1:14:23Progress job uh description is created.
1:14:26True. If not created, it should be
1:14:28false. Okay. Posted on different
1:14:31platform like LinkedIn and angel list or
1:14:34no. Yeah, it has posted. And this is the
1:14:36list. How many application received so
1:14:39far? Only eight applications. Interview
1:14:42schedules with two applications. Okay.
1:14:44So this is the storing uh I mean
1:14:47strategy for every agents. So let's say
1:14:50each and every framework is having
1:14:51different way they stores the data but
1:14:54this is the common if I tell uh one
1:14:57common let's say structure. So this is
1:14:59the common structure that's how the goal
1:15:01should be stored in the core memory.
1:15:03Okay. All the uh running instance
1:15:06metadata would be saved in the core
1:15:07memory. That's how it usually saves and
1:15:10it will take that particular data from
1:15:12the memory itself to continue the plan
1:15:15to continue the goal. Okay, that's how
1:15:17one agent remembers each and everything.
1:15:19Now I think you are getting now goals
1:15:22can be altered as well. Let's say once
1:15:25you have set one goal, you can also
1:15:26change that particular goal to another
1:15:28one. This is also possible here. Okay.
1:15:31Now the next characteristic it is the
1:15:33planning.
1:15:35Okay, planning. So you can see planning
1:15:37is is the agent's ability to break down
1:15:39a highle goal into structured sequence
1:15:42of actions or sub goals and decide the
1:15:45best path to achieve the desired
1:15:47outcome. Okay, that means let's say I
1:15:50have given a prompt I have to hire a
1:15:52backend engineer. Now to achieve this
1:15:54particular goal, what uh this agent has
1:15:57to do? Agent has to create a
1:16:00different different Okay, agent has to
1:16:02create a different different uh plan. I
1:16:05think you saw that what was the plan. So
1:16:07for that particular example, it was uh
1:16:10preparing the job description, posting
1:16:13on different different platform. Okay,
1:16:15then it was uh continuously monitoring
1:16:17that this was the plan. Now whenever it
1:16:20is planning, you'll see that generating
1:16:23multiple candidate plans. It will only
1:16:25not let's say proposed one plan. It
1:16:27might give you multiple plan. Okay,
1:16:29let's say plan A post a job description
1:16:32on LinkedIn, GitHub, jobs or angel list.
1:16:37Okay, plan B is that use internal
1:16:39referrals. Okay, and hiring agencies.
1:16:43So, it has suggested you two plans. Now,
1:16:46it is asking for your feedback. Okay,
1:16:50now based on your choice, you can select
1:16:53which plan you want to go ahead with. So
1:16:56whenever your agent
1:16:59uh agents are working it has the
1:17:01reasoning capacity that means uh it
1:17:03should also minimize my cost right and
1:17:06if it is suggesting me to plan so
1:17:10definitely if I'm taking the plan A so
1:17:12there I will I will let's say spend less
1:17:16less amount because here I directly post
1:17:18on LinkedIn GitHub jobs and handle list
1:17:20okay but if I'm taking the plan B I if
1:17:22I'm taking some hiring agency so
1:17:24definitely I have to take their
1:17:25subscription plan right so there I have
1:17:27to pay more money so get it so that's
1:17:29why it is giving you different different
1:17:32plan okay then evaluate each plan as I
1:17:36told you agents will itself evaluate the
1:17:38plan let's say plan A is perfect or plan
1:17:41B is perfect for this particular work
1:17:43based on that it will give you the
1:17:45suggestion then the efficiency which is
1:17:47faster so if I'm going with plan A or
1:17:49plan B which is faster so definitely
1:17:51plan um uh A is little bit faster
1:17:54because I can directly
1:17:56post the jobs on the platform itself and
1:17:59get the applications. Okay. Then which
1:18:01one is having less cost? Definitely plan
1:18:03A is having less cost. Then risk will it
1:18:07fail if we get no applications? Okay.
1:18:09Then alignment with constraints remote
1:18:11jobs only budget. Okay. So these are my
1:18:15uh steps inside the plan. So based on
1:18:18this particular evaluation steps it will
1:18:21select the plan. Okay. Now third step
1:18:23select the best plan with the help of
1:18:26human in loop. That means it will
1:18:28definitely ask to the human for the best
1:18:29plan which one you would like to go
1:18:31ahead. So which of these option do you
1:18:33prefer a pre-programming policy uh favor
1:18:37low cost channel first? Okay. So
1:18:39definitely whenever I will take any
1:18:41kinds of plan I'll try to check this
1:18:43particular low cost
1:18:45okay uh option in my mind. So yes uh
1:18:48this was the u I mean characteristic
1:18:52which is planning. Now the next
1:18:54characteristic the reasoning. Now let's
1:18:56try to understand this reasoning guys.
1:18:59So what is reasoning? First of all let's
1:19:01try to understand. As you can see
1:19:02reasoning is the uh cognitive process
1:19:05through which an agentic system
1:19:07interprets informations draws conclusion
1:19:10and makes decisions both while planning
1:19:13ahead and while executing the actions in
1:19:15real time. Reasoning uh during planning
1:19:18goals decompositions break down abstract
1:19:21goals into cons uh concrete steps tool
1:19:25selection decide which tool will be
1:19:27needed uh for which step resource uh
1:19:30estimation estimated time dependencies
1:19:33and risk. Okay, as I already told you,
1:19:35whenever a aentic system is working,
1:19:38uh it will be working with respect to
1:19:41the reasoning because behind the
1:19:43reasoning one LLM works, right? And LLM
1:19:45has the u actually intelligence um
1:19:48capacity so that it can understand uh
1:19:51and it can automatically make the
1:19:53decision. It can automatically let's say
1:19:56break down the goals. Okay, it can
1:19:58automatically tell you what kinds of
1:19:59tools should be selected. You can also
1:20:02uh like work on the resources
1:20:04estimations like estimated time,
1:20:05dependencies and risk. Okay. So with the
1:20:08help of this reasoning guys, these
1:20:10agents would be more powerful, more
1:20:13efficient. Why? Because I told you if
1:20:17one agent is one agent doesn't have the
1:20:20reasoning capacity that means this
1:20:22should be the simple chatbot only. Okay,
1:20:24this should be the simple chatbot only.
1:20:26Why a chatbot is different from a AI
1:20:29agent? Okay. Why AI agent is powerful?
1:20:32Because of this reasoning. Okay. Let's
1:20:35say if I'm having a agent, if I'm giving
1:20:37any kinds of input and it is connected
1:20:40with different different tools, right?
1:20:42Some kinds of tools it is connected.
1:20:43Now, whenever I'm giving a input, now
1:20:46this will perform this reasoning
1:20:48operation. It will decide the question
1:20:50human is asking whether I have to
1:20:52directly give the answer. I have to
1:20:54refer the tool for that. Okay. So, this
1:20:56is called actually reasoning. So,
1:20:58reasoning is super important here. Okay.
1:21:01Now here you can see reasoning,
1:21:03duration, execution, decision making,
1:21:05choosing between option uh three
1:21:08candidate matches, schedule uh for two
1:21:10uh two uh best candidate and reject one.
1:21:14So this kinds of decision making is
1:21:15taking your uh agent okay with the help
1:21:18of this reasoning with the help of this
1:21:20LLM. Now, HITL handling
1:21:24knowing when to pause and ask for help.
1:21:27Uh unsure about the salary range. Okay,
1:21:29for an example, let's say with the help
1:21:31of this reasoning, it is automatically
1:21:33decide when it should ask for the help
1:21:36to the human when it needs to ask for
1:21:38the confirmation from the human. Okay,
1:21:40in this case, let's say uh my uh my
1:21:43recruiter agent is asking what should be
1:21:46the salary range just try to tell me.
1:21:48Then error handling, interpreting tools,
1:21:50API failure and re re uh re uh
1:21:54recovering. Okay, let's say sometimes
1:21:56some of the tool might be down right
1:21:58that time uh how this particular agent
1:22:01will handle that particular error. Let's
1:22:03say if my tool to tool A is not working
1:22:06so definitely it will try to move to
1:22:08tool B. Okay. So this kinds of ability
1:22:11this reasoning will be having. Now the
1:22:14next one adaptability. So what is
1:22:16adaptability? You can see adaptability
1:22:18is the agent's ability to modify its
1:22:21plan, strategies or action responses to
1:22:23unexpected conditions all while staying
1:22:27aligned with the goal. Okay. So that
1:22:29means I told you let's say in that
1:22:31particular case I think you remember
1:22:34uh we got very less application right
1:22:36and my agent was automatically give you
1:22:39the suggestion and it was it was telling
1:22:41like I need to change the job
1:22:43description to backend engineering to
1:22:45full stack engineer. So this is called
1:22:47adaptability. Your agent is
1:22:48automatically modifying the plans,
1:22:50modifying the strategy. Then again it is
1:22:52working with respect to that. Okay. You
1:22:54can see failures in uh then external
1:22:57feedbacks and changing the goals.
1:23:00Okay. Now what is the next next uh
1:23:05characteristic is the context awareness.
1:23:07I already told you what is context
1:23:09awareness. Context awareness is the
1:23:10agent's ability to understand, retain
1:23:13and utilize relevant information from uh
1:23:16from the ongoing task, past interaction,
1:23:19user preferences and environmental
1:23:22uh cues to make better decisions through
1:23:24the multiple steps. Okay. And if I'm
1:23:27talking about context awareness, this is
1:23:29nothing but it's a memory. Okay. You can
1:23:31see context awareness is implemented
1:23:34through memory. Here we create two kinds
1:23:36of memory. one is short memory, one is
1:23:38long me long-term memory, short-term
1:23:40memory and long-term memory. So as you
1:23:41can see
1:23:43uh if my uh agent doesn't have the
1:23:47context of my previous let's say uh
1:23:50goals or plan so then how it will
1:23:52progress the current one. So definitely
1:23:55to run the current progress it should
1:23:58have the previous context right. So
1:24:00let's say in this case I have given I
1:24:02want to hire a backend engineer with two
1:24:03to four years of experience. So it
1:24:05should have these kinds of informations
1:24:07in the context memory based on that it
1:24:09will make the decision. Okay, this is
1:24:10what actually it is explaining and what
1:24:13are the tool responses it is getting
1:24:15definitely it will also try to uh store
1:24:18that particular responses to the context
1:24:20memory so that it can give you the
1:24:22better response with respect to that.
1:24:24Now at the end this context awareness
1:24:26implemented through memory. So here we
1:24:28create short-term memory and long-term
1:24:29memory. Short-term memory we create for
1:24:31the current state. Let's say if one
1:24:33current state is running if it is
1:24:34creating some metadata we will be
1:24:36storing in the short-term memory and
1:24:37long-term memory means the whole
1:24:39conversation the whole uh user
1:24:41interaction it is doing it should have
1:24:43the u u present in the long-term memory.
1:24:46Okay. So this is the idea. So yes guys
1:24:48these are some characteristic uh we
1:24:51usually have inside any kinds of AI
1:24:53agents and how you will understand this
1:24:55particular application is a AI agents
1:24:57application or authentic application. If
1:24:59this application is having this kinds of
1:25:01characteristic definitely you can uh
1:25:04think about this is a aenti application.
1:25:06Okay. Definitely in the architecture
1:25:07itself these kinds of character uh
1:25:10characteristic should be mentioned. So
1:25:12guys uh now we'll try to see the
1:25:14components of agenti application what
1:25:17are the component one AI agent is having
1:25:20uh using uh you can see the first
1:25:21component is the brain. Okay whenever
1:25:23I'm talking about the brain so here LLM
1:25:27would be utilized. You can use any kinds
1:25:29of LLM here. So LLM has the reasoning
1:25:32capacity with the help of that it will
1:25:34make the decisions. It will try to do
1:25:37the HITL operation. It will do the uh
1:25:41tool selections. Okay. All the
1:25:42operations be happening with respect to
1:25:43this particular brain. And the second is
1:25:46the orchestrator. So what is
1:25:47orchestrator? To build a entire aenti
1:25:50system, okay, we need some orchestrator.
1:25:54Orchestrator means this is the
1:25:56framework. Okay, framework let's say it
1:25:58will do the connection with the LLM that
1:26:00means brain it will make the connection
1:26:02with tool then whenever it is uh
1:26:05required for the tool calling it will
1:26:07perform the tool calling operation
1:26:08whenever it is required let's say it
1:26:10will uh call the uh h ITL that means
1:26:14human in loop right it will ask for the
1:26:16uh approval from the human so these
1:26:18kinds of things if I want to create a
1:26:20complete aent application I need to use
1:26:22some framework I can't create with the
1:26:25help of simple python or I can't with
1:26:27the help of simple tensorflow right or
1:26:29langen this is not possible so I have to
1:26:31use some end to-end framework for that
1:26:33okay so in the market there are some
1:26:35famous framework like we are having crew
1:26:37AI
1:26:39okay we are having langraph
1:26:44we are having autogen
1:26:47some some no code platform is also
1:26:49available like n okay so a apart from
1:26:52that some other like framework are also
1:26:54available but these are framework
1:26:56actually very uh common and very popular
1:26:59and very powerful in the market nowadays
1:27:01and people use that developer use that
1:27:03to create agenti applications. Okay. So
1:27:05throughout the entire um this uh course
1:27:08guys we'll try to master these are the
1:27:10framework we'll see the entire crew AI
1:27:12framework we'll try to develop a AI
1:27:14agent with help of crew AI okay end to
1:27:16end multi- aent system we'll try to
1:27:17create then lang graph we'll try to
1:27:19explore we'll try to create end to end
1:27:20application with lang graph we'll try to
1:27:22see the autogen we'll try to understand
1:27:24the entire autogen autogen component
1:27:26we'll create the AI agents with autogen
1:27:28we'll try to see some no code platform
1:27:30as well like n we'll see how we can uh
1:27:34create the AI agents without writing any
1:27:36kinds of code by doing some drag and
1:27:38drop operation each and everything we'll
1:27:40be learning. Okay. So that's why
1:27:42orchestrator is also required and this
1:27:43is one other component of a AI agent and
1:27:46orchestrator means I AI agent building
1:27:49framework. Okay. Always remember langen
1:27:52can be also utilized with the help of
1:27:54lang also you can create some of the
1:27:56simple agents but uh later on
1:27:58[clears throat] langen published
1:27:59actually langraph so people are moving
1:28:01to the langraph for building these kinds
1:28:03of AI agents. Okay. Now [clears throat]
1:28:05the next one is the tool. So definitely
1:28:09tool should be available as a component.
1:28:11Here we can utilize any kinds of tool
1:28:13whether it's any kinds of search tool,
1:28:15whether it is any kinds of calendar tool
1:28:18or any kinds of application tool. Okay.
1:28:20If you just open the internet and if you
1:28:22search like agentic AI tools list, okay,
1:28:25you'll see that there are thousands of
1:28:26tool listers available. Okay, whether it
1:28:28is search, whether it is uh any kinds of
1:28:31application with your Google drive, with
1:28:33your calendar. So, let me show you some
1:28:35of the list.
1:28:38So guys, as you can see there is a
1:28:39GitHub called AINE tools catalog and
1:28:42there are some other website as well you
1:28:44will be getting over the internet. So if
1:28:45you open it uh open this up. So this uh
1:28:49this is having all kinds of uh tool uh
1:28:51tools and toolkit as you can see. Uh so
1:28:53we are having archives. So tools to read
1:28:56archive papers. So I think you know if
1:28:58we read any kinds of research paper we
1:29:00go to the archive website. Okay
1:29:02archive.org. So this is also a tool. Uh
1:29:05this tool is available in the framework
1:29:07itself. You can use this tool for
1:29:09reading any kinds of research paper. You
1:29:11can connect your AI aens with the
1:29:12research paper uh actually world. Okay.
1:29:15Then uh by search is there. Bing search
1:29:17is there. B search is there. These are
1:29:19my search tool. Okay. Then code doc
1:29:22search is there. CSV search is there.
1:29:23That's how you can see Google search is
1:29:25there. We are having different different
1:29:27tool. Okay. So this is for the code
1:29:29interpreter. Okay. These are the code
1:29:31interpreter. If you want to interpret
1:29:32any kinds of code, these tools you can
1:29:34use. If you want to do a productivity,
1:29:35these tools you can use. Okay. You can
1:29:37connect with your calendar, email, zoom.
1:29:39Okay. This is for regular automation.
1:29:42Now this is for web browsing. If you
1:29:43want to browse the web, these tool you
1:29:45can use. If you want to connect with the
1:29:46database, these are the database tools
1:29:48are available. If you want to do the
1:29:49file operation, these are the tools are
1:29:51available. Okay. So that's how whatever
1:29:53tool you want everything is available
1:29:56okay in the orchestrator framework in
1:29:57the AI agents you can connect with
1:29:59anyone okay
1:30:02now next we are having the memory
1:30:06memory is another component so I told
1:30:09you context uh awareness is required so
1:30:12here we use something called memory okay
1:30:15so memory should be also integrated and
1:30:17for memory development uh we use
1:30:20orchestrator framework in the
1:30:21orchestrator framework Mark itself we
1:30:22are having different different memory
1:30:23function either you can also use
1:30:25different different database for the
1:30:26memory you can do anything here then the
1:30:29supervisor so this is the
1:30:32hittl that means human in loop okay
1:30:36human in the loop so with the help of
1:30:38the supervisor what it does it try uh it
1:30:41try to interact with the human when any
1:30:44helps is uh required it will try to uh
1:30:46ask for the help it will ask for the
1:30:48human guidance or feedback and it will
1:30:51continue agents. Okay. So these six
1:30:53actually components uh sorry five
1:30:56components are available in any kinds of
1:30:58AI agents and this is the highle
1:31:00actually diagram I have shown you. Some
1:31:02other component might be available as a
1:31:05lowle but this is the main one. Okay. So
1:31:07if you find these are the components are
1:31:09available inside AI agents. uh yeah you
1:31:12can I mean select that particular
1:31:15application as aka application and
1:31:17whenever you are creating you have to um
1:31:20take care these are the component okay
1:31:22inside your application now uh let me
1:31:27show you the component explanation as I
1:31:30already told you the brain wise here
1:31:32what we do we use a large language model
1:31:34and what is the use of large language
1:31:36model the goal interpretation planning
1:31:38reasoning tool selections okay
1:31:40everything is uh everything we do with
1:31:43the help of this particular brain or
1:31:44large language model. The orchestrator
1:31:46orchestrator is a framework
1:31:49uh AI agents implementation framework
1:31:50with the help of uh we can do task
1:31:52sequencing conditional routing, ret
1:31:55logic, looping, iterations and
1:31:57delegations. Okay. Then tools we are
1:31:59having so tools with the help of tools
1:32:01we can uh connect our AI agents with
1:32:03external sources. Okay. uh and to
1:32:05knowledge base as well. That's if you're
1:32:06creating a ragbased agents that time our
1:32:09uh knowledge base should be external
1:32:10sources. Okay, this is this would be
1:32:12perform as a tool that time. Now the
1:32:14next component I told you the memory. So
1:32:16what memory does? So memory actually
1:32:19basically uh stores all of the context
1:32:22of the conversation and uh we create
1:32:25actually two kinds of memory short-term
1:32:27memory and long-term memory and it will
1:32:29uh do the state uh tracking. Okay.
1:32:33um research tracking is required. I
1:32:34already told you I already showed you
1:32:36previously, right? Uh it was uh storing
1:32:38the data in a JSON format. So this is
1:32:40also required. Then the supervisor so
1:32:43approval uh requested for HITL that
1:32:46means human in the loop. Then guardrails
1:32:48uh enforcement then age case uh
1:32:51escalation. Okay. So let's say if you
1:32:53want to block some unsafe or non uh
1:32:57complaint behavior, you can use the
1:32:58guardrails evaluation. I will also show
1:33:00you how to perform the guard's
1:33:02evaluation and uh age uh case uh
1:33:05escalation that means alert human when
1:33:07uncertainity conflict arises. Okay. And
1:33:10you already understood about this uh
1:33:12htil okay human in loop uh human in the
1:33:15loop format. So yes guys these are some
1:33:17components are available of AI agents
Asynchronous Programming for AI Agents
1:33:20and whenever we are developing our own
1:33:22AI agents we have to take care these are
1:33:24the part and every AI agents are having
1:33:26this kinds of component uh nowadays.
1:33:29Okay. So apart from that I think uh uh
1:33:32there is nothing uh inside a if you feel
1:33:34like okay if there is any new things you
1:33:36can just do let me know in the comment
1:33:38section definitely I'll try to cover
1:33:39that as well. Okay but so far my
1:33:42understanding I think these are some uh
1:33:44we have to follow whenever we are
1:33:46creating or whenever we are working on
1:33:48aentki system. So yes guys uh this is
1:33:50all about from this video. Uh I hope you
1:33:53have understood and this was helpful for
1:33:55you. I think I already told you uh in my
1:33:58previous uh video uh like there are uh
1:34:01some components are available especially
1:34:04whenever I'm talking about uh the
1:34:06agentic AI uh one of the component is
1:34:09the orchestrator right orchestrator
1:34:11means there we use some kinds of
1:34:14framework okay with the help of these
1:34:16are the framework we create we implement
1:34:18the AI agents whether it's a single
1:34:20agents whether it's a multi multiAI uh
1:34:23agent system uh we try to create these
1:34:26kinds of things right
1:34:28so there is a concept guys uh you have
1:34:32to understand before I start with this
1:34:34kinds of orchestrator framework the
1:34:36concept name is asynchronous programming
1:34:39okay so why this asynchronous
1:34:41programming is required uh because if
1:34:43you see u going forward we'll be
1:34:46creating the multi- aent system and to
1:34:49create the multi- aent system guys we'll
1:34:51be using this kinds of orchestrator
1:34:53framework and internally This
1:34:55orchestrator framework uses asynchronous
1:34:57programming. Okay, that means it will
1:34:59run your agents in parallel. Let's say
1:35:02you have created uh 20 agents. So what
1:35:06it will do instead of running u agents
1:35:09as a sequentially, it will run all of
1:35:12the agents in parallel so that your
1:35:14execution would be more fast. So this
1:35:16concept I'm going to discuss in detail
1:35:18guys. No need to worry. Uh first of all,
1:35:21let me show you one thing. actually uh I
1:35:23have just figured out
1:35:25let's say if I go to the Google so here
1:35:28if I search like is lang graph uses
1:35:31asynchronous in the back end for multi-
1:35:33aents so I think you know lang graph is
1:35:35one of the orchestrator framework with
1:35:37the help of lang graph we create agentic
1:35:40AI applications right and we'll be also
1:35:43mastering this langraph inside our codes
1:35:45so as you can see the response was yes
1:35:47lang graph is uh designed with first
1:35:50class asynchronous supports in the back
1:35:52end for multi- aent system that means uh
1:35:56it is utilizing the asynchronous
1:35:58programming asynchronous concept in the
1:35:59back end okay now if I just go below
1:36:03let's say I have asked for about the
1:36:05autogen because autogen also will be
1:36:07covering inside our course so as you can
1:36:09see autogen also utilizes asynchronous
1:36:12programming at it core but it is uh
1:36:16architecture fundamentally different
1:36:17from the langraph state uh langraph's
1:36:20state machine approach approach but
1:36:22internally it is uses asynchronous
1:36:24programming concept. Now again I asked
1:36:26like uh what about crew AI? Okay so you
1:36:30can see crewi also supports asynchronous
1:36:32execution but it approaches
1:36:34orchestration differently than langraph
1:36:36and autogen while uh langraph uses uh a
1:36:40state machine and autogen uses a actor
1:36:43model. Crew AI is built around
1:36:46role-based collaboration and
1:36:47processdriven execution model. Okay. But
1:36:51the main fun is that all of the
1:36:53orchestrator framework we are using for
1:36:55developing these kinds of multi- aents
1:36:57application internally it is uses
1:37:00asynchronous okay as synchronous
1:37:02programming. Now before I start with
1:37:05these are the orchestrator framework
1:37:06first of all I want to clarify what is
1:37:08asynchronous programming why it is
1:37:10required how asynchronous works okay
1:37:12what is parallelism what is uh let's say
1:37:16sequential execution each and everything
1:37:17I'm going to clarify then we'll start
1:37:20with the uh orchestrator framework
1:37:22understanding but after that there is
1:37:24one more topic uh we have to cover which
1:37:27is nothing but pentic pyntic validation
1:37:30this is also important because you will
1:37:31see that Whatever large language model
1:37:33we are having it will generate the
1:37:35unstructured output and to make it a
1:37:37structured even whenever we are giving
1:37:40any kinds of prompt to make our prompt
1:37:43uh more structured we use this pentic
1:37:45validation okay so this pentic
1:37:47validation will be understanding in the
1:37:49next video but in this video I will only
1:37:50focus on the asynchronous understanding
1:37:54okay so here I'm going to give you the
1:37:56detailed understanding of asynchronous
1:37:59with a theoretical understanding as well
1:38:01as the practical understanding as well.
1:38:03So let me show you guys what is this
1:38:05asynchronous. After that your
1:38:07understanding would be more clear and
1:38:10you can easily understand these are the
1:38:11framework whenever you will be doing the
1:38:13coding.
1:38:15So let me give you the definition of the
1:38:17asynchronous programming. So here is the
1:38:19definition.
1:38:20Um here is a simple definition you can
1:38:23see asynchronous programming in Python.
1:38:26Okay, you can see asynchronous
1:38:27programming in Python is a programming
1:38:30paradigm that allows code to handle okay
1:38:33multiple task uh concurrently without
1:38:36blocking the program's execution. It is
1:38:39primary used to IO bound task example
1:38:42network uh request file input and output
1:38:46operation database queries. Okay,
1:38:48allowing the program to perform other
1:38:51operations while waiting for slow
1:38:54external events to complete. That means
1:38:56this as asynchronous programming will
1:38:59help you. Okay, asynchronous programming
1:39:01will help you. Okay, asynchronous
1:39:03programming will help you to run your
1:39:05task in parallel. Okay, so you are not
1:39:08supposed to wait for the uh execution.
1:39:11Let's say we know that we use synchron
1:39:13synchronous programming so far. Yes or
1:39:15no guys, we use synchronous programming
1:39:18so far. In synchronous programming, what
1:39:20happens? Let's say if I execute a code
1:39:22block, first of all, it will complete
1:39:24that. Okay, after the execution is
1:39:28complete, okay, then it will execute the
1:39:30second part of that particular code.
1:39:32Okay, but in between, let's say if you
1:39:34are waiting for the execution, okay, if
1:39:36you're using asynchronous programming,
1:39:38it can run another task in parallel.
1:39:41Okay, so these are the like say
1:39:43functionality we'll be getting here. Now
1:39:45you can ask me why this is required.
1:39:47Okay, why this asynchronous programming
1:39:49is required inside AI agents
1:39:50implementation. Agentic AI, you can
1:39:53create two kinds of agent. One is the
1:39:54simple agent. Okay. One is the simple
1:39:58agent. So basically simple agents you
1:40:00create
1:40:02only one block. Okay. It can only handle
1:40:05one particular task. Okay. But whenever
1:40:10let's say you have complex problem you
1:40:12have to divide the task in smaller
1:40:13chunks. And what you will do? You will
1:40:15be creating multiple agents. Okay.
1:40:18Multiple agents you will be creating.
1:40:19Let's say this is agent one. This is
1:40:21agent two. This is agent three. Okay.
1:40:24And what will happen? You will assign
1:40:26the task for all the agents. And these
1:40:29agents will be executing either
1:40:32independently,
1:40:34independently
1:40:38or dependently.
1:40:43Okay. Dependently.
1:40:45So it's your design philosophy. If you
1:40:47are making it as a independently that
1:40:49time it will run as an independently. If
1:40:51you are making it to dependent okay it
1:40:53will run as a dependently. So basically
1:40:56what happens let's say if you run these
1:40:58are the agents okay these are the agents
1:41:01in a synchronous programming okay in a
1:41:03synchronous programming what will happen
1:41:05first of all these agents need to be
1:41:07completed these agents execution need to
1:41:09be completed once this agent uh when
1:41:12this agents will be executed then it
1:41:14will move to the next agents okay next
1:41:17code block then this agents will be
1:41:19executed okay once it is completed then
1:41:21it will go to this particular agents
1:41:23okay then it will try to run this
1:41:25particular agent. So let's say this
1:41:27agents is taking 3 minute to run. Sorry,
1:41:30let's say here I can just tell you
1:41:33let's say this agency is taking 1 minute
1:41:34to run. This agency is also taking let's
1:41:37say 1.5 minute to run. Okay. This agency
1:41:40is also taking let's say 1 minute to
1:41:41run. So what is happening? You have to
1:41:43wait for 1 minute. Again you have to
1:41:45wait for 1.5 minute. Again you have to
1:41:46wait for 1 minute. Okay. So if you like
1:41:50uh add all of the time you will see that
1:41:52at the end you are having okay 3.5
1:41:55minutes 3.5 minutes you have to wait for
1:41:58the execution but if you run this task
1:42:00in parallel okay if you run this task in
1:42:02parallel let's say this particular
1:42:04agents will do the online search
1:42:05operation so basically if you're doing
1:42:07the online search operation you'll be
1:42:09hitting some URL like right URL and to
1:42:11get the response this will take some
1:42:13time let's say sometimes this web server
1:42:16might be slow that time it will be
1:42:17giving you flow response. So instead of
1:42:19waiting for that you can execute your
1:42:22other agents. So let's say these agents
1:42:23will try to collect the uh images. These
1:42:26agents will try to collect the let's say
1:42:29any other file okay from the internet.
1:42:31So don't wait to execute any other
1:42:34agents. Just try to run them in a
1:42:36synchronous way. Okay, in a parallel
1:42:38way. So each of the agents will be
1:42:40running in a parallel way. So let's say
1:42:42this if this agent is also taking 1
1:42:44minutes. Okay. So simultaneously you are
1:42:47running something okay in the back end.
1:42:48So you are not supposed to wait for 3.5
1:42:50minutes. Get it? So that is the things I
1:42:53just wanted to tell you. So let's say
1:42:55whenever you are creating multi- aent
1:42:57system and whenever you are creating
1:42:58let's say independent connection okay
1:43:01independent let's say policy that time
1:43:03you should use this asynchronous
1:43:05programming inside um inside let's say
1:43:08Python or let's say whatever programming
1:43:09you're using you have to follow that.
1:43:11And if you see any kinds of agents code
1:43:13you will be uh seeing people are using
1:43:16this as okay uh essence
1:43:20this particular syntax people are using
1:43:22that okay so what is this essence as
1:43:24means asynchronous okay as synchronous
1:43:27functionality so in python there is a
1:43:28library called asense IO so we'll be
1:43:30following that particular library to
1:43:32implement this particular code okay so
1:43:33let me give you one example of
1:43:35asynchronous and synchronous programming
1:43:38so let's say here I can write
1:43:40synchronous Synchronous
1:43:45programming
1:43:52and this side we have asynchronous
1:43:54programming.
1:44:07So in synchronous programming what
1:44:08happens? Let's say
1:44:12what I can do I can give you one
1:44:14example. Uh let's say here
1:44:18um let's say you are you are having a
1:44:23you are having a
1:44:27gas stove. Okay. Gas stove.
1:44:31Uh in this gas stove you only have one
1:44:35uh
1:44:37one fire section. Okay. one fire
1:44:40section. So let's say you are having uh
1:44:42three dishes. Okay, you are having three
1:44:45dishes
1:44:47to cook.
1:44:50So what you will do? First of all, you
1:44:52will take the first dish and you will
1:44:54cook that. Once first dish is complete,
1:44:56then you will take the second dish. Then
1:44:58you have to complete then you will be
1:45:00taking the third dish. Then you will be
1:45:01completing. Okay, that's how you can see
1:45:03it is taking T1, it is taking T2, it is
1:45:06taking T3 time. Okay. So basically you
1:45:09have to wait for u you have to wait for
1:45:13the previous execution or let's say
1:45:14previous task to be completed then you
1:45:16can start the remaining task. But in
1:45:19asynchronous programming what happens
1:45:21let's say you are having same gas stove
1:45:24but here you are having let's say three
1:45:26fired section. You are having three fire
1:45:29section and you are having three dishes.
1:45:32Okay, let's say dish one,
1:45:34dish two and dish three. So what you
1:45:38have to do? You just need to
1:45:41run all of them simultaneously.
1:45:44Basically you are giving three dish to
1:45:46the three fire section. Okay. Now at the
1:45:49T1 time, okay, your all of the dishes
1:45:52should be completed. So you are not
1:45:54supposed to wait for the T1, T2 and T3
1:45:56to be completed. Okay. So this is the
1:45:58difference between synchronous
1:46:00programming and asynchronous
1:46:01programming. I hope you get it guys. So
1:46:03in Python we usually follow this
1:46:04synchronous programming. That means if
1:46:06you're running a function first of all
1:46:08that function would be completed then
1:46:10the remaining code would be executed.
1:46:12Now in programming we we call it as a
1:46:16sub routine. Let me just write here
1:46:19sub
1:46:21routine
1:46:24and we also call it as cool routine.
1:46:29I'll be discussing about what is this
1:46:32okay cool routine. So what is sub
1:46:34routine? So let me write a program to
1:46:36explain. Let's say here I can write a
1:46:38function.
1:46:40So I'll just write a function. Let's say
1:46:42def.
1:46:45Okay. Diff. So let's say I will
1:46:50um I'll give the function name
1:46:53fetch.
1:46:56Okay. Fetch let's say data. This is the
1:47:00function name. So it is having some code
1:47:05inside that. Okay. Now here I'm creating
1:47:08another function. Let's say def main.
1:47:13Okay. Now what I'm doing I'm calling
1:47:15this particular function. Okay, this
1:47:17function inside this particular main
1:47:19function fetch
1:47:21data.
1:47:23Okay, I'm calling inside that
1:47:29I'm calling inside that sorry yeah now
1:47:34after calling let's say in this main
1:47:36function also there are some code line.
1:47:39So what is happening here? Let's say if
1:47:41you're uh if you're using sub routine so
1:47:44that time uh whenever you are executing
1:47:47your code first of all your code will uh
1:47:51come here okay your code will come here
1:47:53and it will see you are calling a
1:47:55function inside that which function you
1:47:57are calling this particular function
1:47:59okay now what it will what will happen
1:48:02first of all it will go to this function
1:48:03and it will execute all of the code it
1:48:06will execute all of the code now let's
1:48:07say you are running fetch data that
1:48:10means let's say you are trying to fetch
1:48:12some kinds of data from the internet,
1:48:13you are using some kinds of API, some
1:48:16kinds of URL. Okay? And whenever it is
1:48:18hitting that particular API or URL, it
1:48:20is taking some kinds of time, right? So
1:48:23you have to wait for this particular
1:48:24time. So see once this time is over,
1:48:29that means this execution is over then
1:48:31you will be able to execute your
1:48:32remaining code. Okay? Till then you have
1:48:35to wait for this execution. Okay? So
1:48:39this is the idea of serve routine. That
1:48:41means you are waiting for a task to be
1:48:44completed. Then your remaining code
1:48:46would be executed. Then your remaining
1:48:48code would be executed. Although you are
1:48:50waiting here, although you are waiting
1:48:52here, you don't have any kinds of other
1:48:53task. You just need to wait for the
1:48:55execution. Okay? And once execution is
1:48:58completed, then you will be able to
1:49:00execute. You'll be able to see the other
1:49:03execution of the program. But in code
1:49:06routine, what happens? So let's say here
1:49:07I'm having a function
1:49:10here I'm having a function and uh we use
1:49:12something called asynchronous okay
1:49:14asynchronous syntax. So for this we use
1:49:16something called asins
1:49:18uh essence. Okay this is the keyword as
1:49:21so we'll write the function as def let's
1:49:23say fetch
1:49:26data this is the function let's say
1:49:29inside that you are having some kinds of
1:49:31code. Okay now again you are having a
1:49:34main function here. So I'll just write
1:49:36diff
1:49:38main. So what you are doing you are
1:49:41calling this particular
1:49:43um okay you are calling this particular
1:49:45function div sorry uh fetch
1:49:51okay fetch data
1:49:55you are calling that and inside main you
1:49:58are having some other code okay you are
1:50:00having some other code as well. Now what
1:50:02is happening? Just try to see whenever
1:50:04your Python will come here it will see
1:50:06that you are executing a function which
1:50:08function this function you are executing
1:50:10and it will see this particular keyword
1:50:13called essence. Okay, that that time
1:50:15Python will automatically understand
1:50:17that this code you have written it will
1:50:19run in a asynchronous way. That means
1:50:22let's say here you are doing a API call
1:50:24and it is taking some time t1 okay
1:50:26instead of waiting for this particular
1:50:28time again it will come here okay and
1:50:31execute the remaining code you have okay
1:50:33after this function that means at the t
1:50:36time itself this code would be executed
1:50:38and this code would be also executed so
1:50:40you are not supposed to wait for the
1:50:42previous execution so this is called co
1:50:44routine and if you're using this asins
1:50:47these are the things so it internally
1:50:48uses this concept and now we'll go for
1:50:51the practical. We'll uh try to see like
1:50:54practically everything how it works. Uh
1:50:56then I think your understanding would be
1:50:58more clear. Okay. First of all, I'm
1:51:00going to explain the synchronous
1:51:02programming.
1:51:04Okay. Now here I'm going to write two
1:51:08function. Let's say for the first
1:51:11function I'm going to write uh fetch
1:51:16DC fetch weather.
1:51:25Okay, fetch weather.
1:51:28Um and the second function I'm going to
1:51:30create def fetch news.
1:51:38P news. Okay.
1:51:41Now what I'm going to do, I'm going to
1:51:45import the time module as well just to
1:51:48see the execution time. So import time
1:51:55import time. Okay. Now inside that as of
1:51:58now I'm not going to write any logic.
1:51:59Simply I'm going to write just a print
1:52:01statement. I'm going to give let's say
1:52:03fetching weather data. Then here I'm
1:52:06going to just mention a time
1:52:09uh let's say to fetch the weather data
1:52:12you have to wait for some time. Okay. So
1:52:14this time I'm going to assign with the
1:52:15help of this time module. So here I'm
1:52:17going to give let's say I will be
1:52:20waiting for 4 seconds. Okay 4 seconds.
1:52:24So it it is for the simulate a network
1:52:27delay. Let's say if you are hitting any
1:52:29kinds of API so definitely to get the
1:52:31response you have to wait for some time.
1:52:33So let's say this time I have set 4
1:52:34seconds here. Okay. Now once uh we stop
1:52:39for four 4 seconds. Now simply I'm going
1:52:41to just print let's say weather data
1:52:43fetched. Okay. So this message I'm going
1:52:45to write. Now similar wise here also I'm
1:52:48going to write uh I'm going to write
1:52:52facing facing news data and uh again
1:52:56I'll give some time. Let's say here I
1:52:57have given 2 seconds and uh once my data
1:53:01uh news fetching is done so I'll tell
1:53:03news data fetched. Okay. So as of now
1:53:06just try to consider this is a function.
1:53:08This will fetch the weather information
1:53:11and this will fetch the news. Okay. Now
1:53:14if you see this function and this
1:53:16function doesn't have any uh dependency.
1:53:20These two functions are independent.
1:53:22Okay. These two functions are
1:53:23independent. That means if you want to
1:53:26fetch the weather, you don't need the
1:53:27news. If you want to fetch the news, you
1:53:30don't need the weather. So these are
1:53:32independent function. Okay. But once I
1:53:36will execute this code, okay, let's say
1:53:38if if I write another function here,
1:53:40I'll just write another function def
1:53:43main. Okay, in the main function, I'm
1:53:45going to call uh I'm going to call these
1:53:47two function. See first of all I'm
1:53:50starting the time just to see the time
1:53:51like how much time it takes to execute
1:53:54the two function. So that's why I
1:53:56starting the start I'm taking the start
1:53:58time then I'm calling these two function
1:54:00together fetch weather and fetch news.
1:54:02You can see fetch weather and fetch news
1:54:04I'm calling then I'm taking the end time
1:54:06then I'm doing the substract operation
1:54:08from end time to start time and this
1:54:10will be uh this will be my execution
1:54:14time of my program. But if you see here
1:54:16these two functions are independent.
1:54:19This these two functions is not
1:54:20dependent. Although it's independent
1:54:23okay it's not dependent.
1:54:25So what whenever you will call the
1:54:28function you have to wait for the you
1:54:31have to wait for the previous function
1:54:34to be completed to run the next
1:54:36function. This is the issue. Okay. So I
1:54:40can see these two functions are
1:54:41completely independent. But whenever I'm
1:54:43calling this function, first of all,
1:54:45this function will execute. So let's say
1:54:47whenever you will execute the program.
1:54:49So your interpreter will come here.
1:54:51Okay, your interpreter will come here.
1:54:53Then it will go inside this particular
1:54:55function. Then it will execute all of
1:54:57the code. And here it will wait for the
1:54:594 seconds. Okay, 4 seconds it will try
1:55:02to wait. But see in the four 4 seconds
1:55:06it doesn't have any work to do. So it
1:55:08will be waiting. Then once 4 secondond
1:55:11is over this code would be executed then
1:55:13your program will come here. Okay then
1:55:15it will be executed. That means first of
1:55:17all the previous function would be
1:55:19executed then the next function would be
1:55:20executed. So you can also check. So
1:55:22let's say if I want to show you. So I'll
1:55:25call this particular main function here.
1:55:28Okay. I'll call this main function. Now
1:55:30if I execute see facing weather it is
1:55:33waiting for 4 seconds. Now weather
1:55:35fetch. Now see facing news. Now it wait
1:55:38for 2 seconds. then news face and total
1:55:40time taken you can see 6 uh point
1:55:43something seconds. Okay. Now you can
1:55:46also take this code uh in one of the
1:55:49amazing website called python tutor.
1:55:51Python tutor.com. Here also you can
1:55:53visualize this code.
1:55:58Let me open the python tutor.
1:56:01Now I'll select the python programming.
1:56:07I'll paste my code here.
1:56:09Visualize the execution.
1:56:19Okay. Now it has started. Okay. It has
1:56:22started. Now simply time is not defined.
1:56:25Okay. So the basically I need to import
1:56:28the time here. Right. So let's edit the
1:56:30code.
1:56:34So here I'll import the time module
1:56:39for time.
1:56:41Now I'll visualize the execution
1:56:46import time. It's giving you an error.
1:56:48Time f not found or supported. Only
1:56:51these modules can be imported. Okay.
1:56:54Because this is a like a website. Okay.
1:56:56Python tutor website. So here you can
1:56:58you can't import any uh let's say these
1:57:01are the library you can't you can import
1:57:03but some other library you can't import.
1:57:05So for this what I can do I can remove
1:57:07the time as of now I just wanted to only
1:57:10just let you know that how it is
1:57:12executing. Let's say I will also remove
1:57:14the time part. Uh here also I'll remove
1:57:17the time part here also and here also.
1:57:21Uh let's say this is my message. Okay
1:57:25this is my simple message. Let's say
1:57:31executed.
1:57:34Now simply do the visualization.
1:57:39Okay. Now see um here I have the
1:57:42control. The first of all Python
1:57:44interpreter will come here. Uh it has
1:57:47seen like here I am having a function
1:57:50called fetch weather. Then it will go to
1:57:51the next line that is next function.
1:57:54then it will go to the next function
1:57:56which is main and in the main function
1:57:59you can see uh I'm calling here this
1:58:01particular main function so it will go
1:58:03into into the main function and it will
1:58:06see like I'm calling fetch weather
1:58:08function okay so it will go inside fetch
1:58:10weather and it will do all of the
1:58:12operation okay see it is doing all of
1:58:14the operation now let's say this
1:58:16function is taking some time so it will
1:58:18wait okay it will wait for 2 minutes 1
1:58:20minutes okay how much time it is taking
1:58:22it will try to wait for Right. So once
1:58:24execution is completed then again it
1:58:26will come here. Okay. Then you can see
1:58:28it will execute another function which
1:58:30is fetch news. Now again it will go
1:58:32inside fetch news and it will do all of
1:58:34the execution and try to come here. That
1:58:37means you have to wait. Okay. You have
1:58:38to wait for the previous execution to be
1:58:42complete. Then you will be able to run
1:58:43the new code. Okay. That's how you have
1:58:45to wait. Okay. You have to wait uh for
1:58:48the previous execution. And definitely
1:58:50it is taking lots of time. And now just
1:58:52try to consider if you're running a
1:58:53multiple agents together and if it is
1:58:56running synchronously. So first of all
1:58:59first agent would be completed second
1:59:00agent would be completed. So execution
1:59:02time it will take more that time we run
1:59:05it is an asynchronous way. So that we
1:59:07are not need to open we don't need to
1:59:09open for uh we don't need to wait for
1:59:11the previous execution. Okay the time it
1:59:14is taking it's completely fine. I will
1:59:16simultaneously run for all of the
1:59:19function and you'll be executing
1:59:20together. Okay. So now we'll try to see
1:59:22that particular example as well how it
1:59:24will work. Now we'll see this
1:59:26synchronous programming
1:59:29sorry asynchronous programming
1:59:34asynchronous programming. Now here to uh
1:59:39implement asynchronous function you need
1:59:42to import one library called
1:59:45import sorry import.
1:59:49Okay. Assence io okay as io this
1:59:52particular library and I'm going to also
1:59:55import time library
1:59:58let's me import all of them then here
2:00:00I'm going to again write the same
2:00:02function
2:00:04same function I will copy the code
2:00:09and simply I'm going to mention here now
2:00:11instead of giving simply this definition
2:00:14I'm going to write asins keyword okay
2:00:17before that now once I have written as
2:00:19keyword
2:00:20Okay, as since keyword at the first of
2:00:22this particular function now Python will
2:00:25automatically understand I need to run
2:00:26this function in asynchronous mode and
2:00:29here it is taking the time. So maybe I
2:00:31can use another keyword here called ait.
2:00:33Okay, a so simply I'm going to give it
2:00:37here.
2:00:39Okay, even you can also return something
2:00:41if you want. Okay, you can also return
2:00:43like uh what is the return this function
2:00:46will be returning for you. H now sim uh
2:00:50same uh similar wise I'll also do it for
2:00:53this particular function so essence
2:00:59okay now simply here I'm going to write
2:01:01a okay have it so why you are writing a
2:01:06here because here it is taking the time
2:01:09okay here it is taking the time and uh
2:01:13whenever here it is taking the time your
2:01:15python uh interpreter will come here and
2:01:17whenever it will see the ait so it will
2:01:20tell like you don't need to wait for
2:01:21this particular execution so you can
2:01:23execute your other uh code okay whatever
2:01:27you have so this code would be executing
2:01:29and at the same time you can also
2:01:31execute your other code okay I'll tell
2:01:33you okay how it will execute
2:01:36uh then uh simply in the main function
2:01:38also I'm going to make it as ess as
2:01:43okay essence and uh here
2:01:47uh instead of calling like that I'm
2:01:49going to simply call it as a
2:01:52uh as since io dot gatherthered okay
2:01:55there is a function and inside that you
2:01:57have to give the fetch weather
2:02:00fetch weather uh function and fetch news
2:02:03function both you have to provide okay
2:02:06then you can uh calculate the end time
2:02:10and simply you can print the time taken
2:02:12of this particular function now if you
2:02:15want to execute uh what you can do you
2:02:17You can simply
2:02:19uh you can simply call this main
2:02:21function. How you can use the aid
2:02:24keyword main. Now see if I execute
2:02:28see what will happen.
2:02:34Okay. Um there is a error. Oh sorry uh
2:02:38whenever you are using this average
2:02:39right you don't need to use the time
2:02:40that time uh you can use essence
2:02:46uh essence io. sleep. Okay. So you are
2:02:48not supposed to use time that time.
2:02:50Okay. You have to use essence io. Okay.
2:02:53Now same things I'll be giving it here.
2:03:00Same things I'll give it it here. Uh now
2:03:04I think it is fine. Now let's execute.
2:03:09Now see guys it has taken only 3 seconds
2:03:13and if I show my previous code it has
2:03:15taken 6 seconds. Okay. So the time
2:03:18reduced by half. Okay. The time reduced
2:03:21by half. Just try to consider. Now just
2:03:24think like this is a big program. Okay.
2:03:26This is a big program. This is a big
2:03:28agents and it is running so many stuff.
2:03:30Now if you run it run it in a
2:03:33synchronous programming. Now just try to
2:03:35consider how much time it it should
2:03:37take. Okay. But if you are using
2:03:39asynchronous programming see it will be
2:03:42reducing the time half. Okay. because it
2:03:45is running everything in parallel. It is
2:03:48running everything in parallel. Okay. So
2:03:50you are not supposed to wait for the
2:03:53previous execution to be complete. Okay.
2:03:55So all of the executions are doing
2:03:57simultaneously.
2:04:00Okay. So that's why this asynchronous
2:04:02programming okay this asense IO is
2:04:05required whenever you are implementing
2:04:07uh any kinds of AI agents uh with any
2:04:10kinds of framework whether you are using
2:04:11autogen you are using langraph you're
2:04:14using crew AI try to use this particular
2:04:17things in your development okay this is
2:04:20good practice there are two concept
2:04:23you'll be getting which is
2:04:25uh the first is para
2:04:29leism
2:04:30Okay.
2:04:32And the second thing you will be getting
2:04:36qy.
2:04:39So what is parallelism? Running
2:04:45multiple
2:04:48uh tasks
2:04:52simultaneously
2:04:58using
2:05:01multiple
2:05:06trades.
2:05:09Okay. Or process.
2:05:16And what is uh concurrency? So let me
2:05:19write it here. Um simply
2:05:23here I can write concurrency.
2:05:31Concurrency means uh managing
2:05:39multiple
2:05:41tasks
2:05:44that can
2:05:47start
2:05:50run
2:05:52and okay finish
2:05:57with
2:05:59over overlapping
2:06:03times.
2:06:05Okay. So, let me uh show you
2:06:09a graph. I think by seeing the graph you
2:06:11will be able to understand
2:06:14what is the exact meaning.
2:06:22So this is the graph.
Pydantic for AI Agents - Pydantic Data Validation
2:06:24So this is the concurrency. You can see
2:06:27uh task is running. Okay. Context
2:06:30switching to the task two. Then again
2:06:33task one is running. Again it is doing
2:06:35the context switching. Okay. But in
2:06:38parallelism you can see it is utilizing
2:06:41okay it is utilizing multi uh multiore.
2:06:44Okay. Let's say uh in the first CPU core
2:06:48it is running task one and in the second
2:06:51CPU core it is running task two but here
2:06:53it is only utilizing the same code only
2:06:55but doing um doing this uh concurrency
2:06:59operation. Okay. So guys I think you
2:07:02have seen this asynchronous concept. Uh
2:07:05the main thing is that right now all of
2:07:08the orchestrator framework uses this
2:07:10kinds of asynchronous uh functionality
2:07:13in their back end. So we don't need to
2:07:15manually uh use the asynchronous inside
2:07:18our development inside our code but if
2:07:20you want you can also use uh if you want
2:07:23you can also uh design your own pipeline
2:07:25design your own agents that time you can
2:07:28write the code from scratch but whatever
2:07:31u let's say u orchestrator framework
2:07:34we'll be using like langraph then
2:07:36autogen crew ai right so everything uh
2:07:40already having this kinds of things are
2:07:42integrated okay in the back end. So I
2:07:45don't need to take care this part. But
2:07:47in future whenever I will do some coding
2:07:49maybe these are the terminology will
2:07:50come that time um I want you to don't uh
2:07:54actually uh confuse with the syntax.
2:07:57Okay that's why I have clarified each
2:07:59and everything before I go ahead with
2:08:01the AI agents implementation. So in this
2:08:04video I'm going to discuss another very
2:08:06important topic especially whenever you
2:08:09are creating any kinds of AI agents
2:08:11application. uh the terms is pientic.
2:08:15Okay. So first of all I will give you
2:08:18the idea why this pientic is required
2:08:21and uh without pentic what would be the
2:08:23problem then we'll try to understand the
2:08:26entire pyic concept. So this is my
2:08:29promise of uh if you complete the entire
2:08:32video guys I think you should not be
2:08:35having any kinds of uh doubt related uh
2:08:39pientic whether you are working in uh AI
2:08:42agents whether you are working with any
2:08:44other let's say uh AI application
2:08:46development because everywhere nowadays
2:08:48we use this particular pentic concept
2:08:50okay for the data validation
2:08:53so I think you already know that uh in
2:08:56python all of the variable is uh dynamic
2:09:00variable. Uh basically we uh use the
2:09:03dynamic concept here that means uh here
2:09:05we don't mention any uh data type okay
2:09:09of a variable. Let's say if I'm creating
2:09:11a variable named um a and inside that if
2:09:15I'm storing uh let's say one integer
2:09:17value which is four you can u actually
2:09:21um remove that four and you can also
2:09:24store any other data type let's say
2:09:26string flo or boolean any kinds of data
2:09:29type in the same variable itself okay
2:09:31without uh actually mentioning the data
2:09:33type okay so that's how python works uh
2:09:36it works actually dynamically everything
2:09:39in short any other programming language
2:09:41uh we use the static approach. So there
2:09:44we uh first of all mention the data type
2:09:47then we uh create the variable and
2:09:49stores the data but in Python actually
2:09:52everything works uh as a dynamically. So
2:09:54here you don't need to mention the data
2:09:56types or any kinds of let's say uh hints
2:09:59related that right. So guys to make you
2:10:02understand what I'm going to do I'm
2:10:04going to open my computer screen and
2:10:06there I'm going to discuss each and
2:10:07everything related uh to this pientic.
2:10:13So guys uh here you can see um I'm
2:10:15inside my computer screen. So first of
2:10:18all I have mentioned the pyentic uh
2:10:22definition like what exactly the pyic
2:10:24is. So as you can see Pentic is the most
2:10:27widely used data validation and uh
2:10:30settings management library for Python
2:10:33utilizing type hints to ensure data
2:10:35structure integrity. As you can see it
2:10:39validates parts data at runtime to match
2:10:42specified types making it essential for
2:10:45building robust APIs and handling
2:10:48external data with it uh with its core
2:10:51logic written in Rust for high
2:10:53performance.
2:10:54So this is the definition of pientic. Um
2:10:57basically we use this pientic for the uh
2:11:00data validation. Uh I'm going to u tell
2:11:03you about more uh more about this data
2:11:05validation. What is data validation? why
2:11:07it is required and u I mean how it
2:11:11actually uh solves one amazing problem
2:11:14actually uh whenever we try to create
2:11:16any kinds of end to end application uh
2:11:18especially whenever you are working
2:11:20inside AI domain if you're working in
2:11:22machine learning deep learning uh
2:11:24generative AI agentic AI anywhere uh
2:11:27whenever you are developing the
2:11:28application uh you have to use this
2:11:30pientic okay now here I have listed down
2:11:33some key features and benefit of the
2:11:35pientic as you can see Here are some key
2:11:38features and benefit. So for data
2:11:39validation and parsing we use this
2:11:41pentic. Uh so here you can see defines
2:11:44how data should be structured using
2:11:47standard Python types automatically
2:11:48enforcing the uh these rules. uh
2:11:51basically see uh inside aentic why it is
2:11:54required because here we'll be working
2:11:56with the large language model and you
2:11:58know that large language model u always
2:12:01will give you the output in unstructured
2:12:02manner and if I want to get a structured
2:12:05output if I want to get the relevant
2:12:07response only that time this pentic data
2:12:10validation is required and whenever we
2:12:11are also passing any kinds of input
2:12:13prompt okay we have to also make it
2:12:16structured so that uh I can get uh the
2:12:19efficient response from my large lang
2:12:21based model. Okay, instead of giving
2:12:22some unstructured data as an input then
2:12:26uh for the type uh hint and integration.
2:12:28So uses Python uh type annotations to
2:12:31define schemas reducing uh the needs for
2:12:34verbose validation code. Then definitely
2:12:36for the fast performance uh we will be
2:12:38using that uh basically it is written in
2:12:41rust uh actually language that's why it
2:12:43is extremely fast. Then strict and lax
2:12:46mode is available inside this pyic.
2:12:48Okay. Basically uh here you can um uh do
2:12:52the uh enforcing strict type and you can
2:12:54also perform the um you can also
2:12:58performing this uh lax mode. Okay, for
2:13:00converting let's say uh any other data
2:13:03type to another data type. Okay, this is
2:13:05also possible here. Then uh clear error
2:13:08handling. Okay, provides detail errors
2:13:10when the data validation fails. and JSON
2:13:13schema generation. Pyntic models can
2:13:15easily generate JSON schema for
2:13:16documentations or validation uh in other
2:13:19languages. Okay. Now it is telling
2:13:21pyentic models. What is this pyentic
2:13:23model? I'm going to tell you. So this is
2:13:24nothing but a class. Okay. We create a
2:13:26class uh and we inherit with this with
2:13:30this pyic actually base model. Okay. So
2:13:32that's why we call it as a pyic models.
2:13:35So whenever I'm going to show you the
2:13:37practical that time it would be more
2:13:38clear. Okay. So first of all uh let's
2:13:41try to understand the problem okay
2:13:43problem without this pentic if I'm not
2:13:46using pyntentic so what will happen and
2:13:48what would be the issue actually we'll
2:13:50be having okay then I'll try to use the
2:13:51pidentic and uh I'm going to show you
2:13:54the benefit itself so for this I'm going
2:13:56to turn off my camera window guys so
2:13:58that you can see the entire screen uh
2:14:00you don't miss any kinds of code snippet
2:14:03okay whatever I'm going to write I think
2:14:05that would be good for you so guys
2:14:08whenever we are working with any kinds
2:14:09of application whether it's related
2:14:11MLDDL or aentki it doesn't matter uh we
2:14:15will be working with the data for sure
2:14:17right so let's say here I'm going to uh
2:14:20take one example I'm going to let's say
2:14:22create a function I'm going to name it
2:14:24as u let's say
2:14:27um let's say add
2:14:31or let's say uh add
2:14:36patient
2:14:42data.
2:14:44Okay. So this is my function. So
2:14:47basically this will take the name of the
2:14:49patient and age of the patient. Okay. Um
2:14:53now what I'm going to do let's say this
2:14:55function uh add this informations to the
2:14:58database that means the hospital
2:15:01database. But as of now uh I'm giving
2:15:03you the demo. So here I don't have any
2:15:05kinds of database. So simply what I'm
2:15:07going to do I'm going to print uh those
2:15:10uh variable here. Okay. So let's say I'm
2:15:12going to print the name and I'm also
2:15:15going to print the age. Okay. So once it
2:15:17is done maybe I can give you a message
2:15:21called um
2:15:24data
2:15:26addit successfully. Okay. So let's say
2:15:28this is my message. Okay. Once let's I
2:15:30will call this function. It will add
2:15:31this informations to the database. And
2:15:34here I will get a message. Let's say
2:15:35database um data added successfully to
2:15:40the
2:15:42database. Okay. Let's say this is my
2:15:44masses. Now let's say if I execute this
2:15:48code uh let me take some cell. So if I
2:15:52want to let's say um insert the data
2:15:55first of all I have to call this
2:15:56function add patient data. So inside
2:15:58that let's say I'm going to give the
2:16:00patient name. Let's say I'm going to
2:16:03give BP and age is 25. Okay. Now let's
2:16:06say if I just execute the code, you will
2:16:10see that BP and the age has successfully
2:16:13added to the database. That means it's
2:16:15working fine. Okay. Now let's say this
2:16:18code is written by the senior programmer
2:16:21and uh he has given this code to the
2:16:23junior programmer. He told like okay
2:16:25this is the function and this function
2:16:27you can use for adding any kinds of uh
2:16:31let's say patient informations to the
2:16:33hospital database. Okay. Now what junior
2:16:36programmer will do definitely you will
2:16:39see the like um uh function definition.
2:16:43So you can see this function definition
2:16:45is that uh this function takes uh two
2:16:47argument. One is the name and another is
2:16:50the age. And the data type is any. That
2:16:52means you can pass any kinds of data
2:16:54type here because here I haven't
2:16:55strictly mentioned you have to pass uh
2:16:58string or you have to pass integer
2:17:00float. Okay, this kinds of uh let's say
2:17:02type hinting I haven't done. So what he
2:17:04will do he will try to add any kinds of
2:17:06data here. Okay, maybe let's say um he
2:17:09has given BP here patient um let's say
2:17:12name. Now he can also give the age like
2:17:15that. Let's say instead of 25 like that
2:17:17he will write like that 25. Okay, 25 in
2:17:21string. Now if I execute this code,
2:17:25still see my data is added to the
2:17:27database. But whenever let's say senior
2:17:29programmer is trying to fetch this data.
2:17:31Okay, let's say there is another
2:17:33function. That function fetch the data.
2:17:36So whenever let's say he's fetching the
2:17:37data, let's say he wants to uh he wants
2:17:40to filter out those patient u the
2:17:43patient age is above 25. Okay. So what
2:17:46he will do? You'll let's say write a
2:17:48condition if uh patient
2:17:52okay if patient age is uh let's say
2:17:57greater than
2:18:00greater than 25
2:18:04okay 25 then he will try to
2:18:08let's say call those patient okay he has
2:18:11tried to call those patient now just try
2:18:14to see here my junior programmer has
2:18:16added the patient information like that
2:18:19in a string format 25 but again senior
2:18:23program is trying to filter out the
2:18:24patient informations by the integer data
2:18:26type okay definitely this kinds of uh I
2:18:29mean filter I can't ever perform on my
2:18:32database if you're using SQL I think you
2:18:34know that you can't do that because here
2:18:35it is a string type here you are um
2:18:38giving the integer type so definitely
2:18:40this patient will be missed that time
2:18:42okay not only this patient uh I mean
2:18:45similar kinds of if you're doing the
2:18:46same thing instead of giving the integer
2:18:48if you're giving the uh string type that
2:18:50time patient will definitely missed out
2:18:52okay for the filter operation so this is
2:18:56the like problem now you can tell okay
2:18:58then I can easily solve this problem so
2:19:00what I can do maybe uh instead of uh
2:19:04giving it like that so what I will do
2:19:07let's say I'll try to maybe add a
2:19:10condition here so simply here I'll add a
2:19:13condition so If
2:19:17type first of all I'll check the type if
2:19:20type of name
2:19:22is equal equal
2:19:27okay equal equal string str and type of
2:19:31age is integer okay then I'm going to um
2:19:34sorry then I'm going to insert the
2:19:37informations to the database okay
2:19:39otherwise in the else condition I'm
2:19:41going to
2:19:42give a error ES
2:19:45okay so I'm going to raise exception
2:19:48raise let's say
2:19:51type error
2:19:57type error so here I'm going to tell uh
2:19:59invalid data type for the name and age
2:20:01name should be string and s should be in
2:20:03the integer format okay now let's say if
2:20:05I execute this code and now let's say if
2:20:09I am trying to add right now uh these
2:20:12kinds of things. Okay. So what will
2:20:14happen? Okay. One more thing I have to
2:20:16add which is uh the hinting type
2:20:18hinting. So name variable should be
2:20:21string and age as variable should be
2:20:23integer. Now if I execute now see if
2:20:25junior programmer comes here and he uh
2:20:27if he sees see the uh let's say function
2:20:30definition he will be able to see that
2:20:32okay this function takes two argument.
2:20:34One is name should be string and s
2:20:36should be integer. Okay. So let's say if
2:20:38I give integer data right now let's say
2:20:4025
2:20:43it will work perfectly okay there should
2:20:45not be any kinds of error but if is
2:20:47trying to give like that let's say again
2:20:5025 so definitely that time one error
2:20:53would be coming here okay now it is
2:20:56working completely fine it's not like
2:20:57that uh you won't be able to do that you
2:21:00will be able to do that now your uh
2:21:02senior programmer will be able to fetch
2:21:04the information very easily because you
2:21:06are following the same data type. Okay,
2:21:08whatever data type your senior
2:21:10programmer expected okay so this is the
2:21:13thing but the problem is that let's say
2:21:17whenever you [clears throat] will be
2:21:18creating a big application it's not like
2:21:20that you will be creating a single
2:21:21function there would be lots of function
2:21:23okay so let's say you want to create
2:21:25another function uh let's say the
2:21:27function name is update information okay
2:21:30update patient information instead of
2:21:32add patients maybe I can add update
2:21:37patient data. Okay, that time again it
2:21:39will take the name and age of the
2:21:41patient. Again you have to check this
2:21:43condition. Okay, you have to check this
2:21:45condition whether name is a string and
2:21:47age type is integer. Then you will allow
2:21:49to update. Okay, let's see here I can
2:21:51tell um update uh update uh let me
2:21:57accept this uh data updated successfully
2:21:59in the database otherwise what I will do
2:22:01I'll just try to raise the invalid uh
2:22:03let's say array but uh whenever we be
2:22:06creating the real application it's not
2:22:08like that we'll be working with uh two
2:22:11to three input data there would be lots
2:22:13of data and for all the data I have to
2:22:15write this particular condition okay so
2:22:17again this is a manual task we have to
2:22:19do and how many function you'll be
2:22:20creating in every function you have to
2:22:22definitely check that okay you have to
2:22:24definitely check that let's say another
2:22:26condition comes up the condition is
2:22:30uh condition is let's say um yeah
2:22:33definitely let's say you have given your
2:22:35data type it should be name should be
2:22:37string and it should be integer it's
2:22:39completely fine but let's say your
2:22:41junior programmer insert the data like
2:22:43that let's say instead of giving uh
2:22:45positive 25 he will be giving negative -
2:22:48255 type now age can't cannot be never
2:22:52never negative right age cannot uh uh I
2:22:56mean it should not be negative but if I
2:22:58let's say add this negative number again
2:23:00it will be adding this particular number
2:23:02successfully okay but this is another
2:23:04issue definitely right now you can tell
2:23:07me okay then what I can do maybe I can
2:23:09uh add another condition here so what I
2:23:13will do let's say uh here maybe I will
2:23:16add another condition inside this in uh
2:23:19add patient data. So here I'm going to
2:23:21check another condition. If the age is
2:23:25uh
2:23:27uh if age is greater than
2:23:30okay
2:23:33um age is greater than
2:23:37equal um zero that time I will allow
2:23:41this condition.
2:23:43Okay, I'll allow this condition
2:23:45otherwise I will raise another exception
2:23:47h cannot be negative. Okay, and this uh
2:23:50um uh this uh already I'm checking this
2:23:53information whether it is a string or
2:23:55integer. Okay, so this is the else block
2:23:57for this particular if and this is the
2:23:59else block for this particular if. Okay,
2:24:02now here I have written the multi- uh
2:24:04conditional statement. So here also you
2:24:07have to do the same thing. Okay, here
2:24:08also you have to do the same thing.
2:24:11Okay. So, so I'll remove this part.
2:24:14Okay. Here also you have to add the same
2:24:16thing. Now if I execute this code now
2:24:19see now it will um check that and it
2:24:22will raise the value um value error that
2:24:24means h cannot be negative. But if I'm
2:24:26passing the positive that time it will
2:24:28be working. There should not be any
2:24:30kinds of problem. Okay. But every time
2:24:33whenever the condition is changing okay
2:24:36uh because it's it is true right
2:24:38whenever you are creating a application
2:24:40your application should handle this
2:24:42kinds of scenario because as a user I
2:24:45can pass anything right um I can pass
2:24:48anything I can pass negative number I
2:24:50can pass string number anything I can
2:24:52pass in your application but your
2:24:55application should uh handle this this
2:24:57kinds of scenario your application
2:24:59should validate the data I'm passing
2:25:00whether it is validated or not. Okay. So
2:25:03either you can do this validation by
2:25:05writing this kinds of manual conditional
2:25:07statement. Either you can use the
2:25:09pientic one. Okay. Pentic data
2:25:11validator. So how to use pyic? I'm going
2:25:13to tell you but I was just showing you
2:25:16the problem. What would be the problem
2:25:17if you're using this uh like traditional
2:25:20approach traditional conditional
2:25:22approach. So here you have to write this
2:25:24kinds of condition manually every time.
2:25:26Okay. And again if you're creating any
2:25:28other function again you have to rewrite
2:25:30the code and your code size would be
2:25:31very big that time. Okay. So this is the
2:25:33problem. Now let's try to see how to use
2:25:37this pentic to solve this problem. Now
2:25:39here I have already written how to use
2:25:41the pyic. So in pentic first of all
2:25:43we'll define a pyntic model that
2:25:45represents the ideal schema of a data.
2:25:48Now what is model? Okay model means
2:25:51model means this is a class. Okay. Here
2:25:52we'll try to define a class of pentic.
2:25:55Basically we'll try to uh inherit with
2:25:58the pidentic based model. Okay. After
2:26:01that we'll try to uh define the schema
2:26:03here. Okay. We'll try to define the
2:26:04schema. Now what is schema? I'll tell
2:26:07you. Uh then uh the second thing uh in
2:26:10uh instantiate u model with raw input uh
2:26:15usually a dictionary or JSON like
2:26:17structure. So once my uh let's say
2:26:19pentic models is pentic class is ready.
2:26:22I will prepare my data. Okay. I'll
2:26:24prepare my input data in uh in a
2:26:25dictionary. It should be uh definitely
2:26:27in a dictionary or JSON like format. Uh
2:26:30then uh we'll try to pass the validated
2:26:33u model object to the functions uh
2:26:37functions.
2:26:39Um okay here I missed one thing. Uh see
2:26:42here basically what we will do pentic
2:26:44will automatically validate the data uh
2:26:46whether it is correct format or not the
2:26:48data we are passing if does not meets
2:26:50the model requirement pentic raises the
2:26:52validation error okay then once let's
2:26:54say my uh data validation meets it is uh
2:26:57let's say validated successfully that
2:27:00time uh it will try to I will try to
2:27:02pass the validated uh model objects to
2:27:04the function the function we have
2:27:05created okay for any kinds of logic
2:27:07let's say for database insertion or
2:27:09update database insertion we can pass to
2:27:12that particular function and our code
2:27:15will be working. Okay. Now this thing
2:27:17we'll try to see in a practical manner.
2:27:19So for this uh first of all you have to
2:27:21install the pyentic inside your
2:27:23environment. So how to install pyic
2:27:25maybe in the requirement.txt txt you can
2:27:27mention the pyntic package and
2:27:29definitely you just try to take pyic uh
2:27:32like more than one that means uh it
2:27:34should be pentic two version because in
2:27:36two function there are lots of update
2:27:38came but don't use one version because
2:27:40what one version that was older and
2:27:43there you will be getting lots of issue
2:27:45okay I'll try to suggest you use uh this
2:27:47pyic two or more than two okay you can
2:27:49use this one now once you have added in
2:27:52the requirements so simply you can open
2:27:53up your terminal and just write this
2:27:55command pip install hypena
2:27:57requirement.txt. So it will be
2:27:59installing this pyantic inside your
2:28:01environment. Okay. So for me it is
2:28:03already satisfied because initially I
2:28:05already installed this pyic in my
2:28:06environment. So once it is done um this
2:28:09is the notebook guys. I'm also going to
2:28:10share you all of the source code in the
2:28:12description section. From there you can
2:28:14download and you can try in your system.
2:28:16Now here you definitely select the
2:28:18kernel the environment you are creating.
2:28:19Just try to select that. So for me I
2:28:21have created this LLM demo. I'll try to
2:28:23select this. Now here I'll be doing the
2:28:25coding example. Now first of all here
2:28:28you have to import this uh pientic based
2:28:30model from pientic. So you have to
2:28:33import like that from pientic. So I'm
2:28:35getting the code suggestion
2:28:37because here I'm using uh this Microsoft
2:28:40copilot. Um yeah so maybe I'll take the
2:28:44suggestion. So from pentic
2:28:48pentic import I'm going to import the
2:28:50base model first of all. Okay. So first
2:28:53of all I'm going to show you the simple
2:28:55example then I'm going to um show you
2:28:57the advanced example of pyic as well.
2:28:59Okay first of all let's start with the
2:29:01simple example. Now once it is imported
2:29:04now what I'm going to do guys I'm going
2:29:05to simply write a pentic class. Okay so
2:29:09let's say the class name is patient
2:29:13okay patient data. So let's say this is
2:29:15my class and definitely you have to
2:29:18inherit this particular class with base
2:29:20model. Okay. So this is called actually
2:29:22pentic model. So this becomes actually
2:29:23padentic model. Right? Now inside that
2:29:26you have to define the schema. So schema
2:29:28means like how many data you will be
2:29:31using. Okay. So here I'll be using two
2:29:33data. One is the name other is the age
2:29:35because I'm replicating the same example
2:29:37previously I have given. So here I was
2:29:38considering name and age. Okay. These
2:29:41two information only. And here I have
2:29:43mentioned the name should be in a string
2:29:45and age should be in integer. Okay. Now
2:29:49what I'm going to do, I'm going to again
2:29:51maybe copy the same uh function I
2:29:54created or or let's write that. So div
2:29:59add patient data.
2:30:01Okay, add patient data. So this was the
2:30:04function previously I written.
2:30:08Okay, but there I passed this name and
2:30:13uh name and uh directly. But here you
2:30:16don't need to give like that. So here
2:30:18what you have to do you have to
2:30:21uh you have to give the uh you have to
2:30:24give the pentic object. Okay. But before
2:30:27that uh let me show you what to do.
2:30:33So as of now let's uh just pass it. And
2:30:38now the second step we have to uh in uh
2:30:43instantiate the model with the raw
2:30:44input. Uh so we have to prepare our raw
2:30:46input. So input should be in a
2:30:48dictionary or JSON like a structure. So
2:30:50let's try to prepare the input. So input
2:30:52is basically my patient information. So
2:30:55patient
2:30:59patient data
2:31:03is equal to
2:31:06um it should be a dictionary.
2:31:10First of all I will add the name.
2:31:16Okay.
2:31:18Name NH. Okay. So, this is a dictionary
2:31:21format. Now, what I will do, I'll just
2:31:23try to
2:31:25just try to pass uh this particular data
2:31:28to my uh to my where to my pentic
2:31:32object. So, here what is the pyic
2:31:34object? Pentic object is nothing but my
2:31:37patient data. Okay. So, what I'm going
2:31:39to do, I'm going to pass it to the
2:31:40patient data. So here let's try to
2:31:43create um object of patient
2:31:52okay patient
2:31:55let's say this is the
2:31:57um this is patient is equal to
2:32:01um patient data and we'll be passing the
2:32:05data and here I have given two star
2:32:06because this is a dictionary and we have
2:32:08to unpack the value right key and value
2:32:10so that's why We are given this uh two
2:32:12uh star here. Two star means you are
2:32:14unpacking the data. Okay. Now this will
2:32:16become a pyic object. Okay. Now we have
2:32:19created a pentic object. Okay. Now this
2:32:21particular object will be passing to the
2:32:23function. All of the function will be
2:32:25creating here. Whether it's a add
2:32:27patient data, update patient data will
2:32:29be um like passing those informations
2:32:31inside the function. Now right now this
2:32:34function uh can't take the name and a
2:32:37separately. Instead of that it will take
2:32:39what? It will take the
2:32:41patient. Okay, patient object
2:32:45that means the pidentic object. So that
2:32:46means here I can uh make this particular
2:32:50input name is at patient and the type of
2:32:53the patient should be patient data. That
2:32:54means this particular class and this is
2:32:57your pentic model right? This is your
2:32:58pentic class. Now why I have given
2:33:00patient data? Because inside that I have
2:33:02prepared the schema. That means this add
2:33:05patient data function takes the data.
2:33:09Okay, take the data and the what is the
2:33:11data format? Data format should be uh
2:33:14definitely there would be a variable
2:33:15called name and name name should be
2:33:17string and there should be another
2:33:19variable called age. Edge should be
2:33:21integer type. Okay. So that's how we are
2:33:23giving the type. But initially we are
2:33:25giving the data like that. We are giving
2:33:27the name and we are mentioning okay this
2:33:29should be the string. Then we are giving
2:33:31the s this should be the integer. Okay.
2:33:33But here we're doing the manual stuff.
2:33:34But here right now we just created a
2:33:37identic class and we're passing this
2:33:38particular class object and it will
2:33:40automatically understand okay what to do
2:33:42what should be the format inside that
2:33:43what should be the structure inside
2:33:44that. This is called actually schema.
2:33:46Okay schema means the data and the date
2:33:48type of the data. Okay this is called
2:33:50actually schema. Now once it is done now
2:33:53simply here I can add the present
2:33:55information. So simply I can print
2:33:59the information. So right now see I
2:34:00don't I can't actually directly print
2:34:02the name right I can't directly print
2:34:04the name here because we are not taking
2:34:08the name as a name variable we are
2:34:10taking as a patient right so we can call
2:34:12like that patient dot name because
2:34:14inside this particular patient data
2:34:17object we'll be having the variable name
2:34:19okay now we'll do for the same we'll do
2:34:22for the age also so print patient edge
2:34:25okay now once it is done I'll tell data
2:34:27inserted successfully to the database So
2:34:30similar wise I'll create for the update.
2:34:34I'll create for the update. So let's
2:34:36make it as update.
2:34:39Okay. Now it will again take the same
2:34:42patient uh uh patient data object that
2:34:45means the pentic object
2:34:47and once it is done we'll try to tell
2:34:51data updated successfully in the
2:34:53database. Okay. And everything will
2:34:54remain same. Now let's try to see
2:34:57whether it is working or not. Now simply
2:34:59what I will do first of all let's say I
2:35:00will add the patient data
2:35:04okay add the patient data so inside this
2:35:07add patient you have to pass this
2:35:08patient information okay patient because
2:35:11this is my pentic object we already
2:35:14created with the help of this pentic
2:35:16class now we'll try to pass it there now
2:35:19see bp uh 25 data added successfully to
2:35:22the database now let's say I want to
2:35:24update the data simply I'll call the
2:35:25update patient data inside that I will
2:35:27again pass the patient object. Now see
2:35:30the patient information is already
2:35:33updated. Now let's say in updated
2:35:39okay so what I can do instead of patient
2:35:42uh I can give patient one let's say you
2:35:44can create multiple patient that time
2:35:47uh you can do that okay patient one
2:35:49patient two like that you can do so
2:35:51let's say this is the patient one
2:35:52information okay this is patient one
2:35:54information this is updated okay so
2:35:56whenever you are doing the update
2:35:58operation so make sure you are giving
2:36:01any other name so simply what I can do
2:36:06see before giving to the update function
2:36:10first of all you have to validate with
2:36:12the help of pidentic so let's say now
2:36:13name is equal to Alex
2:36:16uh let's say this is patient two we are
2:36:19um we are giving this particular raw
2:36:21data to the pentic okay pentic object
2:36:24because here I already told you inst uh
2:36:26instantiate the model with the raw input
2:36:29data so we are initiating the model okay
2:36:32the pentic model with the raw data. The
2:36:34raw data we are passing here. Okay, raw
2:36:36data we are passing here and this is uh
2:36:38doing the validation. If everything is
2:36:40fine uh it will tell okay you can
2:36:42continue then we are giving to the
2:36:45function. Now see this function is
2:36:46working fine. Okay it should be patient
2:36:49two not patient one it should be patient
2:36:51two. Now see now it's become Alex. Okay.
2:36:55Now the things I want to show you the
2:36:57benefit actually uh using this pentic
2:36:59which is that let's say uh by mistake
2:37:02you have given um let's say string 25.
2:37:06Okay you have given string 25 instead of
2:37:08giving uh 25. So now what we will do
2:37:11let's say if I execute the code see pyic
2:37:14will not give you any kinds of
2:37:16exception. Instead of that what it will
2:37:17do it will try to convert this string 25
2:37:20to integer. Okay so you don't need to do
2:37:22it manually. So by default uh actually
2:37:25internally this pyantic will handle this
2:37:27kinds of scenario. So this will try to
2:37:29convert to the um integer type. Okay,
2:37:32you don't need to manually do that. So
2:37:33here also you can do the same thing.
2:37:35Let's say if I give string 25 your data
2:37:37should be updated successfully. Okay.
2:37:39Now let's say in future you want to add
2:37:41any other information. So you don't need
2:37:43to update these at the code that time.
2:37:45Okay. Manually. So here let's say you
2:37:47want to add the weight
2:37:50uh weight for the patient. Okay. So
2:37:52let's say weight usually I can mention
2:37:54with the help of float data type because
2:37:56weight should be float. Now simply what
2:37:58I can do I can also print the weight
2:38:00here.
2:38:01Okay. Now here also I can do the same
2:38:04thing. I can update the weight. And here
2:38:07you can give the weight information
2:38:09right. Let's say weight is uh 70.5 kg.
2:38:13Now if I add the information see still
2:38:17it will be working. Okay, I'm getting
2:38:19one error because whenever I'm updating
2:38:21the information here, I haven't passed
2:38:23the weight. I have to pass the weight
2:38:24here. Now see, it will work
2:38:26successfully. Okay, so there should not
2:38:28be any kinds of problem. Okay, but in
2:38:30our previous example, you'll see that
2:38:32every time I have to handle this kinds
2:38:33of scenario manually. But in pyentic, we
2:38:36don't need to handle that. Okay, we'll
2:38:37try to just prepare a pyic class and in
2:38:41this particular class, we'll try to
2:38:42handle each and everything for me. Okay,
2:38:44but you have to make sure whenever you
2:38:45are giving your raw data, try to first
2:38:47of all validate. Okay, try to first of
2:38:50all validate with uh your pyic then try
2:38:52to pass to the main function. Now I
2:38:55think this particular concept will be
2:38:57clear enough the strict and lax mode. So
2:38:59basically what it do it attempts uh to
2:39:02uh co uh qu cos the data example
2:39:07converting uh this string one to integer
2:39:10one that means automatically try to
2:39:12convert for you. Okay. But if you want
2:39:14to raise the exception, you can also do
2:39:15that. Okay. Everything is possible here.
2:39:19And one more thing I want to show you.
2:39:21Now, let's say if you want to add um any
2:39:25other type data, let's say instead of
2:39:27giving this uh uh let's say this is this
2:39:30is a number. Okay. Now let's say you are
2:39:32not giving the number, you are giving
2:39:34like that 70.
2:39:37Okay. Say 70.
2:39:41Okay. 70. Now see if I execute it will
2:39:44throw you the error. Okay, it will tell
2:39:46input should be a valid number. Unable
2:39:49to parse the string to a number because
2:39:52we can't convert this uh this text to
2:39:55the number, right? This is not a number.
2:39:57This is a other text. This is a like
2:40:00kinds of word we are passing. Okay. But
2:40:03it should be a number. Whether you are
2:40:05giving as a string or integer doesn't
2:40:08matter. It should be as a number. So if
2:40:10you're giving as a number that time it
2:40:12will be able to convert it to the
2:40:14integer. Okay. But if you're giving
2:40:16completely text type it will not allow
2:40:17that time. Okay. So yeah that's how the
2:40:20things work. But this is a very uh basic
2:40:22type example I have given. Now we'll try
2:40:25to move to the advance of this pentic. I
2:40:27will try to see like more depth
2:40:29validation how it can be done. We can
2:40:31add so many parameters so many stuff
2:40:33here. we can add so many let's say um
2:40:36verification and we can uh make it like
2:40:38more powerful. So guys so far we have
2:40:41seen a very easy example uh of the
2:40:45pentic. Now we'll try to make it uh
2:40:48slight complex. Okay. Uh so what I'm
2:40:51going to do maybe I can copy the same
2:40:55uh same class.
2:40:58So this is the class. So I'll copy this
2:41:02or I can copy the entire
2:41:05code
2:41:08and I will paste it here. Okay. Now see
2:41:10here what I'm going to do instead of
2:41:12taking name age and weight maybe I'll
2:41:15take some more uh extra variable. Let's
2:41:18say here I'll take um
2:41:21another uh another data called married.
2:41:24Okay. Whether this patient is married or
2:41:26not.
2:41:29married. So this should be a boolean um
2:41:33data type because either patient should
2:41:36be married if married it should be yes
2:41:38either no. So if yes or no comes into
2:41:41picture so we can consider in boolean
2:41:42type data type then I can take another
2:41:46um data which is allergies. Okay whether
2:41:51patient is having allergies or not. Okay
2:41:53if he or she is having allergies. So
2:41:56what kinds of allergies uh he or she is
2:41:59having? See allergies is is it's not a
2:42:01single let's say type. Okay, there
2:42:03should be multiple types. Someone got
2:42:04allergies from let's say dust. Someone
2:42:07will be getting allergies from any kinds
2:42:09of food, right? It should be different
2:42:11different let's say type. So
2:42:12[clears throat] that's why we'll be
2:42:13taking as a list. Now you can ask me why
2:42:16I'm taking this particular things as a
2:42:19list. Okay? Because it should be list of
2:42:22allergies. Okay? uh let's say uh one
2:42:24patient will have uh might have multiple
2:42:26allergies okay type or let's say one
2:42:29patient would have only single type okay
2:42:30so instead of taking a single type maybe
2:42:32we can take a list of the type uh I mean
2:42:35list type so that if one patient is
2:42:38having multiple allergies so I can
2:42:39easily store them right but if you're
2:42:41taking list so you don't need to
2:42:44directly um I mean write this list okay
2:42:47if you are I mean writing in that way it
2:42:49should it it won't be working so for is
2:42:52what you have to do you have to import
2:42:54this list from the typing module. So you
2:42:56just need to import list from typing
2:42:58module. So there is a module called
2:42:59typing and in this typing we'll we'll be
2:43:02having all kinds of typing okay inside
2:43:04python. So we are importing the list.
2:43:06Okay, we're telling we need a list. Now
2:43:08it should be a list. Okay, so here we'll
2:43:10be telling this should be a list type.
2:43:14Okay, now I can't actually write list
2:43:17like that because see what will happen
2:43:19if I open up my blackboard.
2:43:23See patient is having allergies. Okay,
2:43:26all allergies is nothing but it's a
2:43:28list. Okay, it's a list. Now the thing
2:43:31is that inside that we have to write the
2:43:34allergist type. Let's say this is dust
2:43:36type and what is dust? Dust is a string
2:43:40right now let's say food. Okay food is
2:43:43also a string. Okay so type cannot be
2:43:47any kinds of number. Okay it should be a
2:43:49definitely a string type. That's why I'm
2:43:51telling
2:43:53u the list we are creating of the
2:43:54allergies inside the list will be
2:43:57storing a string type data. Okay.
2:44:00because allergist type should be always
2:44:01a string. So that's how whenever we are
2:44:03creating any application we have to
2:44:05think about the data type what should be
2:44:06the data type okay uh the data we are
2:44:09getting what should be the type okay you
2:44:11have to think about in that way so
2:44:13allergies should be list and inside list
2:44:16the data we'll be storing it should be
2:44:17string okay that's why we can uh write
2:44:21this particular syntax and this is
2:44:22called schema okay we are creating the
2:44:24schema right now and we are extending
2:44:26this particular pentic model I think you
2:44:29get it right now I'll add another let's
2:44:33say data which is contact
2:44:39okay contact information. So contact
2:44:41information let's say I want to keep it
2:44:43as a dictionary. Uh let's say someone
2:44:45will pass let's say um contact
2:44:47information like that. Uh let's say
2:44:52um he or she will be writing in that
2:44:53way. Let me tell you.
2:44:57So contact we want to take it in that
2:45:00way. Let's say contact info is equal to
2:45:02it should be a dictionary. So inside
2:45:04that first of all user will pass the
2:45:06email address. Okay. So let's say this
2:45:09is the email address.
2:45:16Okay. And this is my phone number.
2:45:23Okay. Phone number. Let's say this is my
2:45:25phone number like that. Okay. I think
2:45:29you are getting and this should be also
2:45:30string type data. Okay. So that's why uh
2:45:33I'll be taking this contact info as a
2:45:35dictionary. Now inside this dictionary
2:45:40uh I'm going to mention okay I'm going
2:45:42to mention what kinds of data I want to
2:45:45take
2:45:47dictionary should be
2:45:52string type okay key should be also
2:45:54string value should be also string okay
2:45:56that's why we're mentioning the data
2:45:58type and this is a dict and again I
2:46:01can't use the python uh default
2:46:03dictionary function I have to import
2:46:05from this typing Okay. So simply I'm
2:46:08going to import this dict. And now I'll
2:46:10mention it here. Okay. That's it. Now
2:46:15let's try to um execute. But before
2:46:18executing I think you have to know we
2:46:20have to prepare the raw data. Now let's
2:46:22try to prepare the raw data. So we are
2:46:24already getting the suggestion. We'll
2:46:25accept that. So here you can see we have
2:46:28added
2:46:30uh we have added uh this uh one
2:46:34married. Yeah. married. So this is we
2:46:38have added
2:46:40this is true.
2:46:42Uh you can also give it as a string. You
2:46:44can also give it as a boolean. It
2:46:46doesn't matter. It will work. Then uh
2:46:49you can uh see we are giving the
2:46:51allergies. So allergies we are giving as
2:46:54a list. As you can see we are having an
2:46:57um allergies from peanuts and selffish.
2:47:00Okay. Then uh we are giving the contact
2:47:03info. Let's say this is my email address
2:47:06and this is the phone number. Okay. Now
2:47:08let's try to execute uh whether uh it is
2:47:11able to work or not. See I'm not going
2:47:14to update uh these are the function. You
2:47:15can if you want you can also update with
2:47:17all of these variable. You can print all
2:47:18of them but uh let's do it quickly. So
2:47:21here I'm going to do I'm going to simply
2:47:23execute. Okay. Now see uh information is
2:47:26added successfully. That means it's
2:47:28working fine right now. But in some case
2:47:31let's say if I am giving instead of
2:47:34let's say uh this u allergies instead of
2:47:37giving this string if I'm giving any
2:47:38kinds of integer number let's say 23
2:47:41okay it will give you the error okay it
2:47:44will tell one validation error from this
2:47:48patient data that means the pentic model
2:47:50so allergies it is coming from the
2:47:52allergies okay allergies field input
2:47:55should be a valid string not the integer
2:47:57okay so that's how You can specify this
2:48:00one. So I'll come here again. I'll
2:48:03change it now. Execute. See it will work
2:48:06perfectly. Okay. So that's how any okay
2:48:10any kinds of type you can mention inside
2:48:12your pentic model. Okay. Any kinds of
2:48:15speak uh schema you can mention inside
2:48:17your pyic model. Everything is possible
2:48:20here. Okay. So guys uh we have seen um
2:48:23another example. uh now I'm going to
2:48:26talk about uh this required and optional
2:48:28fields. Okay, what is this required and
2:48:31op optional fields? Let's try to
2:48:32understand. See whenever we are creating
2:48:34this schema right we are creating this
2:48:36pentic model uh that time uh whatever
2:48:40data we are taking right whatever data
2:48:42we are uh let's whatever schema we are
2:48:45um writing we have to give all of this
2:48:47field right we have to give all of this
2:48:49field whenever we are preparing the raw
2:48:51data so if you skip any of them okay so
2:48:53if you skip any of them what will happen
2:48:55so let me show you the example I'll copy
2:48:57this code I'll add it here let's say
2:49:00these are my schema right let's say I I
2:49:02I will let's say um I will let's say um
2:49:07not provide this allergies. So what will
2:49:09happen? So if I remove the allergies
2:49:10from here,
2:49:13let's say I will completely delete this
2:49:15allergy field.
2:49:18Okay, I'll delete this. Now if I execute
2:49:20it will throw you an error. Okay, it
2:49:21will tell one validation error from uh
2:49:23patient data allergies field required.
2:49:26Okay, but you haven't given this
2:49:27particular data. So this is the issue.
2:49:29Okay. Now let's say uh I want to make it
2:49:32as optional. Let's say if user is not
2:49:34also giving this allergy, it's
2:49:36completely fine. It should be completely
2:49:38optional. That means my code will still
2:49:40execute. So for this what I can do? I
2:49:43can make it optional. So to make it
2:49:45optional, simply you have to import
2:49:49optional from typing. Okay, optional
2:49:51from typing. And you have to pass this
2:49:54data type inside the optional.
2:49:57Okay, inside the optional.
2:50:00And one more thing you have to define
2:50:02which is one default value which is
2:50:05none. Okay. So I'm getting one error.
2:50:08Let me check.
2:50:12Okay. The error I'm getting it should
2:50:13not be parenthesis. It should be this
2:50:15square bracket. That's why that error
2:50:18was coming. Now it's fine. Okay. Now
2:50:20this allergies uh field should be
2:50:21optional. If you are also not giving
2:50:23it's completely fine. uh um I mean it
2:50:26will still work and by default this
2:50:29allergies uh field uh will get one value
2:50:32which is none. I can show you by
2:50:33printing that. So what I can do I can
2:50:37print it.
2:50:39So just for simplicity let let's remove
2:50:41this function. Okay I'll only keep one
2:50:45function. So here I'll just try to print
2:50:48patient
2:50:50dot allergies.
2:50:53Okay. Now if I see show you my data
2:50:56there
2:50:57uh there I already removed this
2:50:59allergist field. Now if I still execute
2:51:02it will work and you can see this
2:51:04allergies parameter is getting none.
2:51:05Okay, this is getting none because the
2:51:07default uh default value I have set as
2:51:10none. Okay and it is completely
2:51:12optional. If you give also it will work.
2:51:14Okay, if you skip it, it will also work.
2:51:17Now let's say if I give this value
2:51:20so after married I think
2:51:24I'll copy from my previous example this
2:51:27special data
2:51:31and I will pass it here.
2:51:34Okay. Now here I have given this
2:51:35allergies field. Now if I execute still
2:51:38it will work but now it will take the
2:51:40value because we have given the value
2:51:42itself. Okay. But if you don't give it
2:51:46still it will work but it will take as a
2:51:48none. Okay. Now one more thing I told
2:51:50you about the default value. See you can
2:51:52also set the default value to any kinds
2:51:54of field. Let's say in the married one I
2:51:56can set any kind of default value. Okay.
2:51:58Let's say if user is not giving any
2:51:59kinds of value still it will take the
2:52:01default value. Let's say married is
2:52:03equal to by default I will be make it as
2:52:04false. Now if I let's say remove this
2:52:09married field as well still it will
2:52:12work. So that particular okay I can
2:52:15print and show you
2:52:19here I'll print it
2:52:24patient domarit
2:52:26now see by default it is coming as a
2:52:28false okay that means you can also pass
2:52:30any default value if you want. Okay. And
2:52:33you can also make any kinds of field as
2:52:34optional. Okay. This is also possible
2:52:37here. So guys, we have seen the optional
2:52:40and required field. Now I'm going to
2:52:42show you another uh example which is
2:52:45related data validation. So in Pentic, I
2:52:48told you uh we can also perform the data
2:52:51validation if you want. Uh see uh data
2:52:54validation means let's say the data you
2:52:56are giving uh you can also validate
2:52:58whether it is in same uh format or same
2:53:01let's say it follows the same uh same
2:53:04structure or not. Okay. So for an
2:53:06example, I'm going to uh let's say
2:53:12take one example.
2:53:14I'll copy the same code. So this is like
2:53:18becoming big line. So what I can do
2:53:19maybe I can just press an enter
2:53:23just to make it as a little bit shorter.
2:53:25Okay. So what I'm going to do I'm going
2:53:27to
2:53:29take another variable
2:53:32called email. Okay. As of now let's try
2:53:35to consider um I'm also
2:53:39taking one informations from the
2:53:40patient. Uh that means his email and
2:53:43here I'm going to remove the email.
2:53:45Okay. So in contact information let's
2:53:47only I'm going to take his phone number.
2:53:49Okay. This is fine for us. So email I'm
2:53:52going to take it as se separately. So
2:53:54what I can do you can tell me okay I can
2:53:57make it maybe string because email
2:53:59usually would be any kinds of string
2:54:00type data yes or no right but if I'm
2:54:03taking as a string type data so what
2:54:04will happen let me show you so let's say
2:54:06I'm taking as a string type data email
2:54:10and now uh after name I have to pass the
2:54:13email so let's say email
2:54:19okay email should be email so this
2:54:22should
2:54:27H.
2:54:29Okay. So let's say BP at the rate
2:54:31example.com or let's say B at the rate
2:54:34uh gmail.com. Okay. Let's say this is my
2:54:38email. It's completely fine. Okay. Now
2:54:40let's see if I execute it will work. See
2:54:42it is working fine. There is no error.
2:54:44Okay. But let's say if I not giving this
2:54:48at the rate sign. Now if I still let's
2:54:50execute my code, it will be working.
2:54:53Okay, although this email format is not
2:54:55good. Okay, although this email format
2:54:58is not correct but still my uh code is
2:55:02working. Okay, then what is the use of
2:55:04that? So here actually data validation
2:55:06comes into picture. So basically see if
2:55:08I am doing manually with the help of
2:55:10Python. So you can tell me okay I can
2:55:13use regular expression library and I can
2:55:14validate whether this email it is
2:55:17correct or not. Okay, I think you know
2:55:19with help of regular expression also we
2:55:20can handle this scenario but we are
2:55:22using the pyic. Okay, and definitely we
2:55:25are using it for my benefit. Right. So
2:55:27in pentic instead of giving this email
2:55:30as a string you can also give this
2:55:34particular format um to the email
2:55:37format. Okay. So inside this pyic we're
2:55:40having another function called email
2:55:43string email str. Okay. So what this
2:55:46email list here does it does the data
2:55:47validation that means it will
2:55:49automatically check whether you are what
2:55:52kinds of email you are giving it is in
2:55:53correct format or not. If it is not
2:55:55correct format that that time it will
2:55:56throw you the error. Okay. Now instead
2:55:58of giving this uh string maybe I can
2:56:00give this email list here. Now what will
2:56:02happen now? See if I execute this code
2:56:06if I execute this code it will throw you
2:56:08error. The error should be uh this
2:56:10email. Okay value is not valid email
2:56:12address. Now unless and until I'm not
2:56:14giving the valid email address. Let's
2:56:16say if I give this at the red sign right
2:56:18now now it will work perfectly. Okay,
2:56:20there should not be any kinds of issue.
2:56:22So that's how you can perform the data
2:56:23validation. Before giving the data, we
2:56:25can validate whether data we are passing
2:56:27it is it is um incorrect format or not.
2:56:30It is validated or not. Okay, I think
2:56:32you get now similar uh um similar things
2:56:36you can do with another let's say data
2:56:38validator.
2:56:40uh the name of the data validator is
2:56:41like any URL. Okay, any URL actually
2:56:44validates any kinds of u um let's say
2:56:47web URL. The web URL you are passing
2:56:49whether it is uh in correct format or
2:56:51not. So let's say uh I'm also giving the
2:56:54patient uh LinkedIn information. Okay.
2:56:57So let's say this is uh this is a IT uh
2:57:00IT patient hospital. We are only taking
2:57:03the IT IT patients. Okay. it I it
2:57:06background related patients and we are
2:57:07also taking their LinkedIn profile okay
2:57:09to our database so what I'm going to do
2:57:11maybe I can create another field here
2:57:13I'm going to name it as LinkedIn
2:57:16uh link then
2:57:19okay
2:57:21LinkedIn URL
2:57:27um yeah and the type should be any URL
2:57:30because this should be a URL format
2:57:32right any URL now here what I'm going to
2:57:34do I'm going to pass a URL, LinkedIn
2:57:37URL. So I'm already getting a
2:57:39suggestion.
2:57:42So maybe I can hit another enter.
2:57:50Okay. So here we are taking the URL as
2:57:53you can see w https uh/ww
2:57:57um dot uh or let's say I will copy my
2:58:00LinkedIn profile. So this is my LinkedIn
2:58:03profile.
2:58:05uh I will add it here.
2:58:09Okay. Now see if I execute this will
2:58:12this thing will work fine. Okay. There
2:58:13should not be any error. But let's say
2:58:15if I'm not giving this https. Okay. If
2:58:19I'm only giving this ww or let's I'm
2:58:22also removing this ww. Okay. Now if I
2:58:23execute see it will give you the error.
2:58:26It is telling input should be a valid
2:58:27URL. Okay. Otherwise it should not be
2:58:30working. So this is the work of data
2:58:31validator. Okay. That's how in ping
2:58:34pyntic there are some default validator
2:58:36um validator uh are present. Uh you can
2:58:40simply see the documentation and you can
2:58:42do the validation. Okay, if you want
2:58:44this is possible here. Now one more
2:58:46thing I will show you which is uh let's
2:58:48say uh here we used uh some of the um I
2:58:52mean already available uh data validator
2:58:56um validator like email uh email string
2:58:59then any URL okay but let's in some
2:59:02cases uh there should be some of the
2:59:04data uh and for those data this kinds of
2:59:07validator won't be available okay that
2:59:10time how you can actually validate those
2:59:12data let's say uh here what I can I can
2:59:16show you one example. Let's say here the
2:59:18name we are passing um I want to make a
2:59:21restriction and the maximum
2:59:25length of a name should not be more than
2:59:28uh 50 character. Okay. That time how I'm
2:59:30going to do this kinds of validation.
2:59:32Okay. So for this we can use the custom
2:59:35um custom validator and we can write
2:59:38this custom validator with the help of
2:59:40one uh one amazing actually function
2:59:42called field. So what you can do
2:59:46uh you can simply import this field from
2:59:49pentic.
2:59:51So you have to import this field from
2:59:52pentic.
2:59:55Just a minute. Yeah, you have to import
2:59:58this field from pentic. Now here simply
3:00:01you just need to define this. Okay,
3:00:03let's say name that should be string.
3:00:06And here I'm going to write the field.
3:00:11Okay, field. inside the field I'm going
3:00:13to tell the maximum length of a name
3:00:17should uh should be only 50 character
3:00:19okay it should not be above 50 character
3:00:22okay now let's say if I execute my code
3:00:26it will work fine completely because
3:00:28right now the name I'm using it is less
3:00:30than 50 character but if you increase it
3:00:33let's say I will add something big
3:00:40okay now if I execute ute you'll see
3:00:42that it will throw an error. The string
3:00:44should be have most um 50 character.
3:00:47Okay. So that's how you can do the data
3:00:50validation uh in your custom data if you
3:00:53want. So like that I can also let's say
3:00:55set to any another field. Let's say I
3:00:58want to restrict the age uh age field
3:01:01here. I want uh whatever age uh user is
3:01:04passing it should be it should be
3:01:07greater than zero and uh lesser than
3:01:10actually let's say 100. Okay. So for
3:01:12this what I can do? I can add another
3:01:14field here. Uh I'm going to write is
3:01:16equal to field. So there is a parameter
3:01:19called GT. Okay. GT means greater than
3:01:23greater than zero. And there is another
3:01:24parameter called uh LT. Okay. LT means
3:01:28lesser than. So here I'm going to tell
3:01:30let's say 100. Okay. Now if let's say
3:01:33user is giving the age let's say minus
3:01:3725. So this is definitely lesser than
3:01:40zero. So that time it will give you the
3:01:42error because input should be greater
3:01:44than zero. But we are giving uh lesser
3:01:47than zero. Okay. Now if you're giving
3:01:49the correct information, it is working
3:01:51fine. Okay. Like that we can also let's
3:01:53say
3:01:55add this kinds of validator inside our
3:01:57allergies. Okay. Let's say this is the
3:01:59list of the allergies we are taking and
3:02:00all all of the values should be string.
3:02:02Now we can also define the field here.
3:02:05So I'm going to write the field.
3:02:08Okay, field. Uh so here let's say the
3:02:12allergies uh we are taking uh from the
3:02:15user. So only
3:02:18uh user can pass actually let's say
3:02:20maximum five five allergies. Okay, five
3:02:23allergy list. So that time I can define
3:02:25the max length
3:02:27should be
3:02:29five. Okay. Now let's say if user is
3:02:33giving more than that
3:02:35okay allergies I make it as a optional
3:02:38so what I can do I can maybe add the
3:02:40data here previously I had the allergist
3:02:43maybe I can copy H so from here I can
3:02:46copy
3:03:01Okay. So here I can add it after
3:03:05married I can add the allergies.
3:03:09Married also removed right previously.
3:03:12Okay. Because this was optional. So here
3:03:13I can add the allergies.
3:03:17It should be a comma. Now if you're
3:03:19giving more value here,
3:03:28okay, that time it will throw you error.
3:03:31Okay, because it should be five item but
3:03:33we are giving more than five. Okay, so
3:03:36this is another issue. So let me
3:03:39Yeah, now it's working fine. Okay. So
3:03:43that's how guys we can uh set our custom
3:03:45data uh validator. Okay. We can set with
3:03:48that of this field. Now this field you
3:03:51can also use for another purpose uh to
3:03:53add some other metadata. Okay. To add
3:03:55some other informations about the schema
3:03:58about the pentic model. Okay. I'm going
3:04:00to show you.
3:04:04So guys now let's try to understand um
3:04:07apart from this um um data validation uh
3:04:11like custom data validation okay where
3:04:14we can use this field okay so see field
3:04:17we can also use for the metadata
3:04:20information let's say whenever we are
3:04:23creating the schema you can also pass
3:04:24any kinds of metadata here okay other
3:04:27informations like description okay some
3:04:30other example you can provide here so
3:04:32that whenever this code is using any
3:04:34other programmer or let's say other
3:04:36let's say uh other person they can
3:04:40easily understand what this field does
3:04:42okay they can easily understand now see
3:04:44the way we have written right now this
3:04:46is completely fine but it does it
3:04:48doesn't have any kinds of information
3:04:49about the name let's say what name does
3:04:51but if I add some other metadata like
3:04:54description and all by reading the
3:04:56description I think other person will
3:04:57easily understand what to do right so
3:04:59for this here I have uh given another
3:05:01demo I have already written this
3:05:02particular demo
3:05:03So see here if you want to write any
3:05:06kinds of metadata
3:05:08metadata um inside your um schema that
3:05:11time you can use this particular field
3:05:14uh function but with that you have to
3:05:16use another function called annotated.
3:05:18Okay so you have to import this
3:05:19annotated from typing. So now you have
3:05:22to write the syntax like that. Okay
3:05:23previously I was writing like that.
3:05:26Okay, I was directly giving the string
3:05:27field and all but right now if you want
3:05:29to write the metadata first of all you
3:05:31have to give the annotated object then
3:05:33inside that you have to define the data
3:05:35type okay the type int let's say this is
3:05:37a string then you will be giving the
3:05:39field so here my field was like maximum
3:05:42length 50 now here I can pass some other
3:05:44metadata like name or like the title
3:05:46okay so name of the patient so the uh so
3:05:49that means this particular name field is
3:05:50nothing but it's a name of the patient
3:05:52and you can also give the description
3:05:54okay what this does this give the name
3:05:56of the patient in less than 50 character
3:05:58then you can also provide some example
3:06:00okay so that by seeing this particular
3:06:02example your programmer can understand
3:06:04okay this actually works like that so
3:06:06here I have given example like bap and
3:06:08Alex so this is less than 50 characters
3:06:10okay so similar wise you can uh use this
3:06:13for all the field you are having let's
3:06:15say I have given some other example I
3:06:17have added this inside the weight okay
3:06:19the same uh see here we mentioned like
3:06:23this is flot here We have given the
3:06:26field. Okay. Right now I'm going to
3:06:28remove this trick parameter. I'm going
3:06:29to tell you why this is required. Now
3:06:32here you can also provide the
3:06:33description. Okay.
3:06:36Uh description and all everything can be
3:06:39done. Okay. So this should be mentioned
3:06:41inside field variable. So here you can
3:06:43mention like description. Okay. Weight
3:06:47of the patient in kg. Then married also
3:06:50I have given the same thing annotated.
3:06:52Then this is boolean type field. uh I
3:06:54have given the default value. So see if
3:06:56you want to give the default value. So
3:06:57previously how I was giving I was giving
3:07:00like that let's say I was just giving a
3:07:02equal sign and giving the value but
3:07:05right now you're using this field. So
3:07:07inside field itself you can give the
3:07:08default value. Let's say in default is
3:07:10equal to none. So by default it will
3:07:11take as a none. Let's say if you're
3:07:12giving any other let's say true false it
3:07:14will take as true false. Okay. Now here
3:07:17I have given the description. Okay. Now
3:07:18for allergies also you can do the same
3:07:21thing. You can mention like okay this is
3:07:24uh optional because previously this
3:07:26allergies was optional and the data type
3:07:29is list uh and inside that we are taking
3:07:31the in uh string type data field is uh
3:07:35default value we are setting as a none
3:07:37you can also give the default value if
3:07:38you want and maximum length should be
3:07:40five okay so for contact details also
3:07:42you can do the same thing but I left
3:07:43this part okay now see if I execute
3:07:47this is giving you an error the error is
3:07:52uh field required contact details.
3:07:56Okay. So the error is that here I have
3:07:58written contact details but here I have
3:08:00given contact information. So here you
3:08:03have to give the same name same name.
3:08:05Now if I execute it will be working
3:08:06fine. Okay. Now one more thing I wanted
3:08:08to show you which is this trick
3:08:10parameter. Let's say I told you um in my
3:08:13previous demo I think you remember uh
3:08:16whenever let's say we are giving let's
3:08:17say weight is equal to a string number.
3:08:20Okay. But here what is the type I have
3:08:22mentioned? Weight is equal to it should
3:08:24be a float number. So by default my
3:08:26pentic is converting this particular
3:08:28string to a float because this is the
3:08:30number. Okay. But always it is not
3:08:33necessary to convert it. Okay
3:08:35automatically convert it. Let's say you
3:08:36are creating an application there you
3:08:38only want to take this kinds of let's
3:08:41say number as a string. That time you
3:08:43should not be convert to the float data
3:08:45type. That time you can uh write one
3:08:48parameter.
3:08:49Uh so here you can write a parameter the
3:08:52parameter name is strict. Okay strict.
3:08:55So you have to make it as true. Okay. So
3:08:58if you make it as true. So what will
3:08:59happen? You have given uh float type.
3:09:02But if you are trying to give this uh
3:09:05string type it will throw you error. See
3:09:07it is throwing you error. It is telling
3:09:09weight uh should be uh input um it it
3:09:13should be a valid number float type
3:09:14number. But we are giving string type.
3:09:16Okay, that's why it's not working. So
3:09:18now if I make it as float. Okay, so it
3:09:21will be working right now. So if you're
3:09:23giving integer also again it will throw
3:09:25an error because here I make it as a
3:09:27strict. Okay, strict parameter. So
3:09:29that's how you have all kinds of
3:09:31customiz customizable option inside
3:09:33Pythic. Whatever you want, you can do
3:09:36everything here. Okay, this is possible.
3:09:39So guys uh we have seen some uh data
3:09:42validator uh validation actually
3:09:44strategy how we can do that. Now I'm
3:09:48going to uh discuss about this uh um
3:09:51validator um in advanced level. Uh we
3:09:55call it as a field validator. Okay. So
3:09:57see so far the validation we have done
3:10:00uh this was like the simple validation.
3:10:02Uh so we used some of the predefined
3:10:04validator and uh we also like uh given
3:10:08some some of the like um custom
3:10:11constraint there. Okay. But let's say uh
3:10:14you have some complex scenario where you
3:10:17have to do uh a complete field
3:10:19verification. Okay. So for an example
3:10:22let me uh let me tell you like um the
3:10:25problem statement. The problem statement
3:10:26is that let's say um the application we
3:10:30have created um let's say this is a
3:10:32hospital application. So basically this
3:10:35stores the patient information. Okay.
3:10:39Then it performs the diagnosis to the
3:10:40patients. Okay. Now just try to consider
3:10:44this hospital has also connect
3:10:45connection with some of the bank. Let's
3:10:47say uh u some of the bank it has the
3:10:50connection. Let's say HDFC bank it has
3:10:53the connection. ICICI bank it has the
3:10:56connection okay now what happens if it
3:10:59is having the connection with the banks
3:11:01let's say whatever patients are coming
3:11:03from these are the banks so they will be
3:11:05getting 50% discount okay they will be
3:11:08getting 50% discount from this
3:11:09particular hospital and if the patient
3:11:12is not from these are the banks so they
3:11:14have to pay 100% about the money so this
3:11:17kinds of let's say validation I want to
3:11:19add inside this application now how to
3:11:21do that so definitely this is little bit
3:11:23complicated created. So for this I have
3:11:25already created the code as you can see
3:11:28I just copy pasted the same code but
3:11:30what I have done I just redu uh reduced
3:11:33the u I mean some extra coded uh so that
3:11:36you can uh understand easily see what I
3:11:38have done uh the previous uh uh
3:11:40validation I showed you with the help of
3:11:42annotated I removed each and everything
3:11:44I just taken my previous example okay
3:11:46previous this clean example so here you
3:11:49can see this is the cleaned example okay
3:11:51I have taken the name email age married,
3:11:54allergies, contract. Okay, these are the
3:11:55things I have taken. Now let's say I
3:11:58want to check the email here. Okay, I
3:12:00want to check the email here because
3:12:02only I will understand whether this
3:12:05patient uh he's from any bank or not.
3:12:08How I'm going to understand? Because
3:12:10patient will give their email address,
3:12:12right? So if I'm a like a very uh I mean
3:12:16common person, so I'll give my common
3:12:18email address like at thegmail.com and
3:12:20all right. But if anyone is working in
3:12:23the bank so definitely they will be
3:12:25having uh their bank domain email
3:12:27address okay let's say hdfc.com or
3:12:30icici.com okay like that so email is the
3:12:33best u field I can uh do this kinds of
3:12:36validator so for this what you have to
3:12:38do you have to write a custom function
3:12:40okay so the function name is I have
3:12:43given email validator okay you can give
3:12:44any name but I have given email
3:12:46validator and whenever you are creating
3:12:48this function make sure you have to give
3:12:50two decorator One is the field
3:12:52validator. So field validator you have
3:12:54to import from pientic. So you can see I
3:12:56have imported from pientic. Uh field
3:12:58validator and inside that you have to
3:13:00mention which field you want to
3:13:02validate. So here I'll tell I want to
3:13:03validate this email. Make sure the
3:13:05spelling should be same. Okay. Email
3:13:07field should be validated and another
3:13:09decorator you have to get called class
3:13:10method because this is the method of
3:13:12this particular class. That's why this
3:13:14class method. Now this is my function.
3:13:16So this function takes two argument. One
3:13:18is the class class object itself. Okay.
3:13:20And this is the value. Value means uh
3:13:23let's say user is giving the email right
3:13:25email address let's say abcdgmail.com
3:13:28or sdfc.com. Okay. So this is called
3:13:31actually value. So this particular value
3:13:32will come and I have to validate this
3:13:34particular value. Okay. So for this what
3:13:36I have done I created a list uh I named
3:13:39it as valid domains. So here I just
3:13:41listed all of the bank uh let's say
3:13:43domain. Let's say sdfc.com ici.com. You
3:13:47can also give any other uh bank domain
3:13:49if you want. Then what I'm doing first
3:13:51of all the value I'm getting from the
3:13:53user let's say whatever email user is
3:13:56passing okay I'm just trying to extract
3:13:58this last part okay as you can see let's
3:14:00say if this is the email address I'm
3:14:01extracting this particular part so this
3:14:03code is doing that so I'm splitting with
3:14:05the help of this address then I'm taking
3:14:07the last value that means this
3:14:09particular part then what I'm checking
3:14:11if domain name not in our valid domain
3:14:14that means if particular this domain
3:14:15name is it is not available inside our
3:14:17valid domains that means this is not
3:14:19U uh this is not a a patient from the
3:14:21bank. Okay. This is a common people.
3:14:23Okay. So that time I'm raising exception
3:14:25not a valid domain. Okay. Otherwise we
3:14:28are returning the value. Simple. Now
3:14:30let's try uh whether it's working or
3:14:32not. See here I have given simple email
3:14:34address buppygmail.com. So definitely it
3:14:37will throw error because uh I'm not from
3:14:39the bank. Uh okay. Still it is working.
3:14:43Okay. The issue is that uh this should
3:14:45be patient data object. Okay. Not
3:14:47patient. uh this should be patient data
3:14:49object uh patient data class. Now if I
3:14:52execute now see it is giving you error.
3:14:54It's telling value error not a valid
3:14:56domain. Okay that means uh this
3:14:58particular person it is not from the
3:15:00bank. Now say if I give the bank domain
3:15:03let's say I'll give sdfc.com.
3:15:09Okay.
3:15:11Now it should be working.
3:15:15Still some error.
3:15:18build required
3:15:22merit.
3:15:27Okay. So here I haven't passed the
3:15:28merit, right? Uh so let's give the merit
3:15:32as well.
3:15:37Married
3:15:38is equal to true. Now if I execute, see
3:15:41it's working fine. Okay. Because this
3:15:43particular person uh he's from the bank
3:15:46itself. Okay. So that's how you can do
3:15:48advanced level uh uh validation. Okay.
3:15:51This is called field validator. Now you
3:15:53can also do some transformation with the
3:15:56validation as well. Now let's say I will
3:15:57be working on another example.
3:16:01So one more thing you can do uh with the
3:16:03help of this field validator you can um
3:16:06you can definitely validate but uh if
3:16:08you want you can also do do the
3:16:10transformation. Let's say the name you
3:16:12are getting from the user. Uh you want
3:16:14to store this particular name in a
3:16:17uppercase format always. Okay. If user
3:16:19is also not giving it's completely fine
3:16:20but you want to make it uppercase and
3:16:23you want to u save inside the database.
3:16:25So for this again you can write another
3:16:27validator
3:16:29uh field validator. So see this is the
3:16:32function I have created called transform
3:16:35name and I told you you have to use two
3:16:37decorator. One is field validator. Now
3:16:39you have to specify which field I'll
3:16:41tell name field and the class method
3:16:43decorator. Now it will take class object
3:16:46and the value. Now whatever value user
3:16:48is giving that means the name. I'm just
3:16:50doing the upper operation. Okay. And I'm
3:16:51returning it. Now see uh here I'm giving
3:16:54let's say lower case BP. But if I
3:16:56execute this code still you will see
3:16:58that in the database all of the uh
3:17:00character would be in upper case. Okay.
3:17:01So this is called transformation with
3:17:03the help of this field validator. That
3:17:04is also uh we can do here.
3:17:08So guys, now we'll understand one
3:17:10another important concept which is model
3:17:12validator. So previously I told you
3:17:15about this field validator. So in field
3:17:17validator uh what uh I was performing.
3:17:20So let's say if I want to do a single
3:17:22field validation that time I was using
3:17:25this field validator. Okay. But let's
3:17:27say there is a condition you have to
3:17:29verify multiple field. Okay. Multiple
3:17:31field means let's say u the system you
3:17:34have created you want to add another
3:17:35functionality which is let's say if
3:17:38patient age is greater than 60 okay that
3:17:41time in the contact details there should
3:17:43be a emergency number so this kinds of
3:17:45uh validation I want to do okay so that
3:17:48time with the help of only field
3:17:49validator I can't do that because I
3:17:51can't um I can't actually mention two
3:17:54field together in the field validator
3:17:55okay only one field can be mentioned so
3:17:57we solve this particular problem with
3:17:59the help of this model validator
3:18:01So for this this is a very simple
3:18:03concept. So let me show you how to add
3:18:05this. So here you have to add this uh
3:18:08add this code.
3:18:10So here I'll just try to define the
3:18:13indentation
3:18:14and you have to import this model
3:18:16validator from pi identical. Okay. There
3:18:19is another validator called model
3:18:21validator. You have to import and inside
3:18:23that you have to uh give this parameter
3:18:25as after mode is equal to after. And
3:18:27here you will be creating the function.
3:18:30The function name is uh validate
3:18:31emergency contract. This will take the
3:18:33class. Okay. And this will take the
3:18:35model. Model means the entire schema.
3:18:37Okay. So if you give the model that
3:18:39means you can access all of the schema.
3:18:41Okay. Uh from inside this particular
3:18:43function. So here you can see here I'm
3:18:45checking if model.hage that means I'm
3:18:47extracting the age if it is um greater
3:18:50than 60
3:18:52and uh emergency not in model. Okay,
3:18:56that means if emergency phone number is
3:18:58not available that time you're raising
3:19:00one exception value error patient older
3:19:03than six uh 60 must have a emergency
3:19:05contact. Okay, then we're retaining the
3:19:07model. Now let's try to check this
3:19:09whether it's working or not. So let's
3:19:10say right now my age is 25 that means
3:19:13this kinds of uh this condition uh will
3:19:15not match. So it will work fine. So if I
3:19:17execute see it is working fine. There is
3:19:19no error. uh but if I let's say make my
3:19:22age uh to more than 60 let's say 70 now
3:19:27this will throw you error it is telling
3:19:29uh value error patient older than 60
3:19:32must have emergency contact number now
3:19:34here I have to add the emergency contact
3:19:36number so maybe after the phone number I
3:19:39can add a emergency number now if I
3:19:41execute see it's working fine okay so
3:19:43this is called actually model uh
3:19:45validator so that means if you have
3:19:47multiple uh field verification that time
3:19:49you can use this model validator Okay,
3:19:51inside your application.
3:19:54Now let's try to understand another
3:19:56concept which is computed uh fields. Now
3:19:59with the help of computed fields, what
3:20:00we can do? Let's try to understand.
3:20:02Let's say in the same example um I want
3:20:05to do another thing. Let's say
3:20:08um here I have added another
3:20:10informations another data called height.
3:20:11Okay. Now um see what computed field
3:20:15does. It does a computation itself.
3:20:17Okay. Let's say if user is giving any
3:20:20kinds of information and it has to
3:20:23recreate or let's say generate a
3:20:25completely new information by utilizing
3:20:27the same information that time we'll be
3:20:29using computed fields. Let's say in this
3:20:31case my patient has given me weight and
3:20:33height but I want to calculate inside my
3:20:36pent uh the BMI okay BMI of the patient
3:20:40I'm not taking the BMI from the patient
3:20:42itself instead of that what I want with
3:20:45the help of weight and height I want to
3:20:46calculate the BMI. So that time I'll be
3:20:48using this computed field. So you have
3:20:51to first of all import this computed
3:20:52field from pi identic. We have already
3:20:53imported. Now you have to again uh use
3:20:57this as a decorator and you have to
3:20:59write a function here. So my function
3:21:01name is BMI and again you have to use
3:21:03another um another actually um uh
3:21:07another uh decorator which is property.
3:21:09Okay, you have to use this property. Uh
3:21:12so the property I think this is already
3:21:13available.
3:21:15uh this property is already available
3:21:17inside Python. This is default one. So
3:21:18you don't need to import from anywhere.
3:21:20Then this is the function we are writing
3:21:22BMI and we are giving the self parameter
3:21:25and this returns uh the float value.
3:21:27Okay. Because BMI should be float and
3:21:29here we are calculating the BMI. We you
3:21:31can see here we are taking the weight.
3:21:34Okay. Uh then we are dividing with the
3:21:37help of this height and we are squaring
3:21:38it. Okay. Then we are taking the uh BMI.
3:21:41Okay. We are calculating this BMI. We
3:21:43are taking the result and this result we
3:21:44are trying to returning it. Now if I
3:21:47want to print this so I I have to just
3:21:49simply write patient.bmi right now see
3:21:51BMI I haven't written here okay inside
3:21:53my schema instead of that I'm
3:21:55calculating it and I'm returning it. So
3:21:57that's why I have to call with the help
3:21:59of this particular function. Let's say
3:22:00if this function name is BMI test you
3:22:02have to also give BMI test here. Okay
3:22:04this is required. Now simply let me show
3:22:05you whether it works or not. So here I
3:22:07have already given the height. uh height
3:22:09let's say I'm considering in meter and
3:22:11weight I'm considering in kg. Okay. Now
3:22:13if I execute now see it is also giving
3:22:15you the BMI. Okay. So this is called
3:22:17actually computed field. So if you want
3:22:19to compute anything with uh with the
3:22:21existing uh schema you are having
3:22:23existing data you are having you can use
3:22:25this computed field at time.
3:22:29So guys now we'll discuss about another
3:22:31important concept inside pentic which is
3:22:33nested model. Uh so sometimes what
3:22:36happens whenever we create the fields um
3:22:39so field might be uh complex field as
3:22:42well. So let me give you one example.
3:22:44Let's say here I have this particular um
3:22:48pentic model that means the class
3:22:50patient data. So here I'm having the
3:22:52patient information like name, gender,
3:22:54age and another information I have which
3:22:57is address. Okay. Now address field
3:23:00might be complex field because address I
3:23:02can't write in a single uh let's say
3:23:05word. So inside a address there should
3:23:07be three kinds of entity. One is city,
3:23:09pin and state. Okay. Now here I'm not
3:23:14going to write uh this kinds of syntax.
3:23:16Okay. Because this is not possible here.
3:23:18So instead of that what we can do we can
3:23:21create another actually pentic um class.
3:23:24Okay pyic model and we can make it as a
3:23:27nested. Okay. Uh so how it can be done?
3:23:30So let's say here I have created my
3:23:32patient data. This is my model. And here
3:23:35I have created another model which is uh
3:23:37address. Okay. And again I inherited
3:23:38with the help of this base model. Okay.
3:23:40Now here I've given three entities,
3:23:43state and pin. Now first of all I've
3:23:46created the address uh as you can see
3:23:47address dict. So city is equal to I have
3:23:49given Google state is equal to harana.
3:23:52Pin is equal to this is the pin. Okay.
3:23:54Now this particular address you have to
3:23:56pass where to this address model. Okay.
3:23:58So we are passing it to the address
3:24:00model. We are unpacking that. Okay. Now
3:24:02this will uh this will return me one
3:24:04pentic object. Okay. Now I'm going to
3:24:06create my patient information right now.
3:24:08So you can see name uh gender age and
3:24:12now right now address is equal to see
3:24:14what I have done. I have given this
3:24:15particular object this class. Okay.
3:24:17Address should be this class. So I'm
3:24:19passing this particular object right
3:24:20now. Okay. Address is equal to this
3:24:22address. Then this patient information
3:24:24I'm passing inside my patient uh model.
3:24:26Okay. Now this is giving you the patient
3:24:28information. Now inside this patient
3:24:30information you are having all of the
3:24:32information whether it is related
3:24:34patient data, whether it is related
3:24:35address. Now let me show you. So here
3:24:37I'm importing first of all all of the
3:24:39patient uh you can see data. So inside
3:24:42patient I am having name age okay and
3:24:44the address. Okay address object is also
3:24:45available. Now if I want to uh let's say
3:24:48access the name I can do that. If I want
3:24:50to access the address I can also do
3:24:52that. Now let's if I want to only access
3:24:55the patient city. So you just need to
3:24:58write patient uh address dot city. So
3:25:01this will give you the city. Okay. So
3:25:03that's how you can write this nested
3:25:05models. This is also possible inside
3:25:07pyic. Okay. I hope you get it.
3:25:12So guys uh one more last thing I'm going
3:25:14to discuss about this pentic which is uh
3:25:17serialization. That means you can also
3:25:20um export your uh pentic object u as a
3:25:24dictionary or as JSON. For this we use
3:25:27serialization. So I have taken the same
3:25:29example. So only the last part what I
3:25:31have done. So here you can see let's say
3:25:33this is my final object uh of my u
3:25:37nested uh nested model. So what I'm
3:25:39doing I'm just doing model.dum. If you
3:25:41do model dump so what will happen? It
3:25:43will return you as a dictionary. See you
3:25:45are exporting your object as a
3:25:47dictionary. Okay, you can see this is a
3:25:49Python dictionary. Okay, but if you're
3:25:51using this uh JSON dump, okay, this
3:25:54should be uh string that means it's a
3:25:56JSON format. Now, you can use uh JSON
3:25:59library to export um I mean you can also
3:26:02export it. You can also dump it and you
3:26:04can also load it um let's say later on.
3:26:06Okay, this is required. Let's say
3:26:07whenever let's say you have created a
3:26:09pyic object okay you have done some data
3:26:12validation and all and you want to uh
3:26:14take it as a take it as a let's say file
3:26:17and uh let's say you want to load it
3:26:19later on you can do do this kinds of
3:26:21serialization okay this is also possible
3:26:23it's like a like in machine learning we
3:26:25train model right after training the
3:26:27model we save the model right we
3:26:28serialize the model so it's kind of that
3:26:30okay now guys uh with that our uh
3:26:33discussion has been end and we have
3:26:35understood all of the concept concept
3:26:37related pyntic. Okay. And I think now
3:26:40you are pretty much comfortable with
3:26:42pyic. You should not be having any kinds
3:26:44of issue with the pyic whether you are
3:26:46working in uh aentic whether you are
3:26:49working in machine learning deep
3:26:50learning anywhere you will see this
3:26:52kinds of concept will be available.
3:26:53Okay. Now one thing I want to show you.
3:26:55So if I go to Google and if I search
3:26:57like why pyentic is important for AI
3:26:59agent. As you can see uh pyntic is
3:27:01crucial for agent because it brings the
3:27:04structure relability and type safety for
3:27:06software engineering to be uh
Building End-to-End Single AI Agent System using LangChain
3:27:09traditionally unstructured and
3:27:10unpredictable word of large language
3:27:12models. Okay. By leveraging the Python
3:27:14typhoons and uh runtime data validation.
3:27:16Pyic ensures that AI agents interact uh
3:27:19realy with external docs APIs and
3:27:22databases. Okay. So here are some of the
3:27:24uh you can see uh concept they have
3:27:27given. you can go through that you'll
3:27:29see that uh at the end this particular
3:27:31concept is very much required whenever
3:27:33we're working with aentki application.
3:27:35Okay. So yes guys I think you have
3:27:37understood all of the concept. If you
3:27:39have liked it please try to subscribe to
3:27:41my channel and share this video with
3:27:43your friends and family. So in this
3:27:45video I'm going to show you how you can
3:27:47implement uh AI agents with the help of
3:27:50this langen. Okay. But if you're
3:27:53completely new to the langen, if you
3:27:55don't know about anything about the
3:27:56langen, so definitely there would be a
3:27:58prerequisite for this session uh which
3:28:01is the langen and this langen video is
3:28:03already available on my YouTube channel.
3:28:05As you can see, I am having a complete
3:28:08langen crash course on my YouTube
3:28:10channel. The uh video name is ultimate
3:28:12langen crash crash course for
3:28:14developers. Okay, so I'm going to add
3:28:16this uh uh add this video link in the
3:28:19description. If you're completely new to
3:28:21the langen guys, first of all, go ahead
3:28:23with this particular uh video then you
3:28:26will be able to understand each and
3:28:28everything about the langen then it
3:28:30would be easy for you to understand this
3:28:32langen agent's creation. Okay. But if
3:28:36you already familiar with this langen um
3:28:38you don't need to go through this
3:28:39recording. It's completely fine. You can
3:28:42continue with this particular lecture.
3:28:44But those who are completely new, I'm
3:28:46telling you guys please try to complete
3:28:47the langen then you can start with the
3:28:49phase three. So in this video I'm going
3:28:52to implement a single agent system uh
3:28:56application with the help of langen. Uh
3:28:58there I'm going to teach you um like
3:29:01what are the things you need to
3:29:02implement this kinds of single uh agents
3:29:06uh let's say workflow uh and how you can
3:29:10utilize langen okay for uh for this
3:29:12particular task. So guys uh in this
3:29:14video we are not only going to implement
3:29:18uh our AI agents after implementing it I
3:29:21will also show you how we can deploy
3:29:22these kinds of agents over the cloud
3:29:24platform. So this is going to be very
3:29:26interesting video uh and this is going
3:29:28to be our first agent. Okay the first
3:29:30agent uh uh application we'll be
3:29:33creating with the help of Langen. Uh so
3:29:35this is going to be a single agent uh
3:29:38system guys. Don't worry, I'm also going
3:29:39to show you the multi- aent system as
3:29:41well in the next video. Uh so each and
3:29:43everything I'm going to clarify. So make
3:29:45sure you watch this video till the end.
3:29:47So guys, uh before implementing this AI
3:29:50agents, first of all, let me give you
3:29:52the idea about AI agents. Although I
3:29:54have given you the detailed introduction
3:29:55of AI agents, but let's uh do some quick
3:29:59revision. As you can see, an AI agents
3:30:02is an intelligent system that receives a
3:30:04highle goal from a user and autonomously
3:30:08plans, decides and execute a sequence of
3:30:11action by using external tools, APIs or
3:30:15knowledge sources all while maintaining
3:30:17the context reasoning over multiple
3:30:20steps, adapting to new informations and
3:30:22optimizing for the intented outcome.
3:30:26Okay, that means agentic AI application
3:30:30or AI agents is having a kinds of power.
3:30:34Uh basically it uh it has lots of
3:30:38connection with uh external like tools,
3:30:41APIs or knowledges. So whenever we are
3:30:45giving any kinds of prompt okay it is
3:30:47taking it as a uh goal okay and with
3:30:50respect to the goal it is planning all
3:30:53of the uh let's say task one by one okay
3:30:58and once all of the let's say task is
3:31:01ready it will try to execute those task
3:31:03okay as sequence and whenever it
3:31:06required any kinds of external tools or
3:31:08APIs it will try to use that okay that
3:31:11means if I give you uh brief idea about
3:31:14the traditional LLM and
3:31:18uh uh and the current AI agents what
3:31:20would be the different between them so
3:31:22let's say I think you know previously we
3:31:24use only large language model right
3:31:28large language model and here we pass a
3:31:30prompt okay prompt so what will happen
3:31:33this large language model will take that
3:31:36prompt and it will give you a kinds of
3:31:38answer or response okay but this large
3:31:41language model doesn't have any external
3:31:44connection with any kinds of tool APIs
3:31:47or knowledge sources. Okay. So whenever
3:31:49you are asking something it should be
3:31:51available in the knowledge base itself
3:31:53of the LLM. That means u this
3:31:56information should be available when
3:31:58they train this particular LLM. Okay.
3:32:00But the difference of this AI agent is
3:32:02that whenever you are giving a prompt to
3:32:04the AI agents. So definitely internally
3:32:07AI agents is utilizing the large
3:32:08language model as a brain. Right? It is
3:32:11utilizing large language model as a
3:32:13brain so that it can perform the
3:32:15reasoning operation. Okay, reasoning
3:32:17operation and I I think you know why
3:32:20reasoning is required because with the
3:32:21help of this reasoning it will decide
3:32:23when to utilize what kinds of tool or
3:32:26what kinds of external sources APIs or
3:32:28knowledge sources whatever right so
3:32:30whenever we are giving a prompt to the
3:32:32AI agents so basically what it is doing
3:32:34it is trying to utilize the large
3:32:36language model it is performing the
3:32:38reasoning operation okay and when it is
3:32:40required any kinds of external tools for
3:32:43getting the informations it will try to
3:32:45use that particular tools or any kinds
3:32:47of API any kinds of let's say uh
3:32:50external knowledge sources it will try
3:32:52to utilize then this will give you the
3:32:54response okay
3:32:56uh with respect to the prompt you are
3:32:58asking okay but whenever it is doing
3:33:01this kinds of operation so basically it
3:33:04is running some of the plan right
3:33:06internally it is running some of the
3:33:07plan uh it is making the decision okay
3:33:10then it is executing these are the
3:33:12workflow one by one okay so this is
3:33:14called actually AI agents I think you
3:33:17already know that and to make this
3:33:20particular agent okay to utilize these
3:33:23LLM tools and everything we need the
3:33:25orchestration framework okay we need the
3:33:27orchestration framework so with the help
3:33:29of that particular framework we can uh
3:33:31integrate like large language model we
3:33:33can integrate like external tools APIs
3:33:35knowledge base okay then uh we'll try to
3:33:38integrate the reasoning ability so it
3:33:41happens with the help of one
3:33:42orchestration framework so in this video
3:33:44we'll be using langen orchestration
3:33:48framework. Okay, apart from langchen
3:33:51actually other orchestration frameworks
3:33:54are also available uh which is only
3:33:56designed for AI agents like langraph,
3:33:58crew AI, autogen okay we'll try to
3:34:01discuss definitely but uh I want you to
3:34:04first of all show you the first
3:34:06orchestration uh orchestration framework
3:34:09uh actually lang uh developed okay for
3:34:12the AI agents. So we not only use langen
3:34:16for agent uh generative application
3:34:18development still you can use langen to
3:34:20implement uh these kinds of AI agents
3:34:23but langen is having some like
3:34:26limitation I'll tell you about the
3:34:27limitation in the next video what is the
3:34:29limitation we are having why we have to
3:34:31use lang graph uh crew AI okay these are
3:34:33the things definitely I'm going to tell
3:34:35you each and everything so now let's try
3:34:39to see how we can implement uh these
3:34:41kinds of AI agents uh with the help of
3:34:44this langen. So for this I'm going to
3:34:46open up my uh local uh local actually
3:34:49directory and there I'm going to launch
3:34:50my VS code and all of the setup we'll be
3:34:53doing and we'll start the development.
3:34:56So guys I'm inside my local directory.
3:34:58So here what I'm going to do uh I'm
3:35:00going to open up my visual code studio
3:35:02here. So let's open up my visual studio
3:35:05code.
3:35:10So this is my Visual Studio Code. Let me
3:35:14zoom
3:35:18and I also need to open up my terminal
3:35:21here. So I'll open up my terminal.
3:35:26Okay. So the first step here will be uh
3:35:29creating a virtual environment and we'll
3:35:31do the requirement installation for this
3:35:33agent. So let's try to create a file
3:35:36here. I'm going to name it as readme.md
3:35:41and inside that I'm going to mention all
3:35:43of the command you need to execute. So
3:35:44to create a environment you have to uh
3:35:47execute this command. So contact create
3:35:49rate create n um I'll name it as lang uh
3:35:53lang agent uh that means lang chain
3:35:55agent you can give any name it's up to
3:35:57you. Then you can specify the python
3:35:59version. So, python is equal to I'll be
3:36:02taking
3:36:03uh 3.11
3:36:05and hyphen y that means I want to give
3:36:08the yes permission. Once it is done, you
3:36:10have to activate the environment and you
3:36:12have to install the requirements. Okay.
3:36:14Now, you can copy this command one by
3:36:16one and you can execute inside your
3:36:18terminal. So, for me uh this uh
3:36:20environment is already available. So,
3:36:22what I'm going to do, I'm going to
3:36:23activate directly. But if you don't have
3:36:25guys first of all try to execute the
3:36:27first command then execute the second
3:36:29command. So see guys this lang agent is
3:36:31already available. This environment is
3:36:33already available. Now I'm going to add
3:36:35the requirements. So let's create
3:36:38another file here.
3:36:40I'm going to name it as requirement.txt.
3:36:42Inside that you have to mention all of
3:36:44the requirements for this particular
3:36:47agent. So I have already listed down all
3:36:50of the requirements you need guys. So
3:36:52these are the requirements you need. So
3:36:54I need langen I need langen community I
3:36:57need langen code I need langen openi
3:37:00I need um uh this things I don't need I
3:37:04need request then tabi python and
3:37:06pythonb okay I'm going to tell you why
3:37:09this uh uh this thing are required
3:37:11actually let me tell you see langchen I
3:37:13think you know this is the main
3:37:15framework this is the main orchestration
3:37:16framework and to uh run this langchen
3:37:19you need some other dependency package
3:37:21like langchen community and langen core
3:37:23And uh here we'll be using a large
3:37:26language model because I think you so
3:37:28internally agent uses a large language
3:37:30model for the reasoning and this is the
3:37:31main brain. So for this large language
3:37:34model I'm going to use this open AI.
3:37:35Okay, open AI provider. So uh from open
3:37:38AI I'm going to use a particular model
3:37:41and uh here you can uh change with any
3:37:43kinds of model if you want. Let's say
3:37:44you can also uh use any free provider
3:37:47like open router. You can also use grock
3:37:50API. Okay, you can also use Gemini API.
3:37:52You can use anything but I have the open
3:37:54AI that's why I'm going to use the open
3:37:56AI. But whenever you are using this
3:37:57kinds of free model so there are some
3:38:00limitation definitely so you won't be
3:38:02getting any kinds of good response from
3:38:03this kinds of free model. That's why I'm
3:38:06using my open AI model so that I can uh
3:38:08show you the best response I'll be
3:38:10getting from my agent itself. Okay. But
3:38:13this course uh this model is changeable
3:38:15guys. This provider provider is
3:38:16changeable anytime you can change with
3:38:18any model any provider. So simply you
3:38:20just need to copy that uh model
3:38:23initialization code and if you give to
3:38:25the chat GP and if you ask like let's
3:38:26say I want to use open router this free
3:38:28model so definitely you'll be getting
3:38:30that. So let me first of all uh write
3:38:32the code then I think you will be able
3:38:33to understand. Then request I need let's
3:38:35say if I want to hit some of the URL
3:38:37external URL or external website
3:38:40external API that time I need this
3:38:41request module. Uh I'll tell you why
3:38:43this request module I I'll be using
3:38:44here. Then tab python. So tab is a tool
3:38:47okay search tool. So with the help of
3:38:49tably what you can do you can perform
3:38:51the internet search operation. Okay. So
3:38:54uh the agents we'll be implementing will
3:38:55try to uh add this tool so that my
3:38:57agents will be able to search any kinds
3:39:00of content over the internet and
3:39:02python.b I need for the environment
3:39:04management I'll be using open api key. I
3:39:06need dav API key. All of the API key I'm
3:39:08going to mention inside my env. Okay. So
3:39:11let me create a file called env. So
3:39:14inside that I'm going to mention all of
3:39:15the API key. But first of all you have
3:39:18to install this requirement txt. So
3:39:20let's copy this command. open up the
3:39:22terminal and simply execute that.
3:39:26So for me it is already installed. Uh it
3:39:28will tell like requirement is already
3:39:30satisfied but for you it will take some
3:39:32time. Okay. So see it has executed. Um
3:39:37okay I think everything is fine.
3:39:40H
3:39:46okay. So here another package you need
3:39:48which is langen
3:39:57langen hub
3:40:01okay langen hub is also required I'll
3:40:02tell you why langen hub is required so
3:40:05let me install again done
3:40:10okay langen
3:40:12okay spelling is not correct so let's
3:40:14copy the spelling
3:40:21Now I think
3:40:23yeah everything is fine. So for me it is
3:40:26already satisfied for for you it might
3:40:27take some time. So once installation is
3:40:29completed guys. So what I can do I can
3:40:31simply create a folder. uh I can let's
3:40:35say
3:40:38give the folder name as research
3:40:42and inside that I'm going to create a uh
3:40:45Jupyter notebook file. I'm going to name
3:40:46it as agent
3:40:49uh
3:40:50demo
3:40:52ipy nbv. Okay.
3:40:56Yeah.
3:40:59Perfect. So one more thing I I have to
3:41:02do which is this file. I will copy this
3:41:04one and I will paste it inside resource
3:41:06as well. Okay. Because uh if I want to
3:41:10execute this notebook file definitely I
3:41:12need this. So that's why I have done
3:41:14that. Uh yeah. Now guys what I'm going
3:41:18to do I'm going to first of all import
3:41:20some necessary library. But before that
3:41:22let's select our environment. So Python
3:41:24environment which is lang agent. Okay.
3:41:27I'm going to select that. So simply I'm
3:41:29going to import some required library.
3:41:33So I need operating system. Then I need
3:41:37certify.
3:41:39Okay. Why I need certify? I will tell
3:41:41you. Then I need request
3:41:44import
3:41:49request. Then I need env.
3:41:56So let me copy all of the input I need
3:41:58here. Yeah. So I need uh ENB. Uh so I
3:42:04will import load env because with the
3:42:06help of this load envoirment
3:42:08variable and whatever key we are having
3:42:10inside that we can load. Then from
3:42:12langchen openi we are importing chat
3:42:14openi. So this is the class uh we can
3:42:17use to load any kinds of large language
3:42:19model from openi provider. Then we are
3:42:22also importing this tools.
3:42:25Okay. Why this tool is required? I'll
3:42:26tell you. But as of now, let me delete
3:42:29this option and also delete this uh
3:42:32delete this library because these two
3:42:34things I want to show you later on.
3:42:35First of all, let's create a simple
3:42:36agents. Then I'm going to show you how
3:42:38we can improve this particular agent.
3:42:39Okay. Then from langen community I'm
3:42:42importing this tably search result.
3:42:45Okay, that means this tab search tool.
3:42:47As I already told you, we are also
3:42:48installing this uh tab python. So tab is
3:42:51one of the search tool. With the help of
3:42:53that you can perform the internet search
3:42:54operation. So we can import this uh tab
3:42:57from the tool and it is available in
3:42:59langen community. Okay that's why you
3:43:01also install langen community. We are
3:43:02importing tools tab search and tab
3:43:05search result. Okay so once it is done
3:43:07so simply I'm going to uh okay another
3:43:10package I need which is
3:43:13uh langen hub. Okay. So from langen
3:43:17import
3:43:19hub. So now let me import all of them.
3:43:23So it is asking uh it will install some
3:43:25required IPI kernel package. So let's
3:43:27install.
3:43:29So if you're doing it for the first time
3:43:32um let's say in VS code first time means
3:43:35in a like uh if you are creating a first
3:43:38Jupyter notebook file and if you're
3:43:40executing so initially it will install
3:43:42some dependency uh IPI related uh
3:43:45package. Okay. So it is installing.
3:43:47Let's wait once this installation is
3:43:48complete then we can execute again.
3:43:54Okay, it has executed successfully.
3:43:55There is no issue. Okay, now here guys
3:43:58what I'm going to do simply I'm going to
3:44:01um import uh some agent related
3:44:04functionality from langen. So first of
3:44:06all I need
3:44:08um two things. So from langen
3:44:14dot agent okay it is available inside
3:44:17agent module
3:44:19uh I'm going to import
3:44:22create
3:44:24uh create react agent okay so there is a
3:44:27a function we are having called create
3:44:31react agent okay so this thing I'm going
3:44:35to tell you what is this create react
3:44:37agent the full form of this uh react
3:44:39agent is reasoning
3:44:42uh reasoning and action. Okay, so the
3:44:45full form of this react is reasoning and
3:44:47action.
3:44:49Okay, we can we can call it as a react
3:44:51agent. I'll tell you how this react
3:44:53agent works. Uh what is the mechanism
3:44:55behind it? But as of now just try to
3:44:57think this is the agent uh we mostly use
3:45:01from the langen. Apart from that some
3:45:03other uh let's say agent function we are
3:45:05having in the langen but this is the
3:45:08most popular one people uses. Okay. um
3:45:11react uh sorry reasoning and action
3:45:14agent.
3:45:16Now once it is done I'm going to import
3:45:19another
3:45:20functionality which is agent exeutor.
3:45:23Okay I'm also going to tell you why this
3:45:24agent exeutor is required and how this
3:45:27works with the react agent. Okay. So
3:45:29these two library I need. Now let's try
3:45:32to import them. Yeah. So once we have
3:45:35imported now simply
3:45:38uh what we have to do guys we have to uh
3:45:41we have to load the environment
3:45:43variable. Okay we have to load the
3:45:45environment variable because in the
3:45:47environment variable itself we'll be
3:45:49mentioning all of our API key. So first
3:45:51first of all I need my open API key
3:45:53because I already told you for the large
3:45:55language model uh we'll be using openi
3:45:58right. So let's try to mention the open
3:46:00API key. So how we can get the open API
3:46:02key guys I think you know simply you
3:46:04just need to go to open AI uh API
3:46:06provider. So here you can go to the API
3:46:08platform and uh left hand side you will
3:46:11see the option called uh API key. Okay
3:46:14simply create a API key here and you
3:46:16just need to copy the API key. Okay so
3:46:19for me I already have the API key. Let
3:46:20me show you. I'll just copy
3:46:24copy this API key.
3:46:29So this is my API key guys. Don't use my
3:46:31API key. I'm going to review after this
3:46:33recording. Just try to create your own
3:46:34API key. And uh you don't need to
3:46:36necessarily create use this open API
3:46:38key. If you want, you can also use any
3:46:40other like LLM provider. Okay, it's
3:46:43completely fine. Now with that, I also
3:46:45need another API key which is the tabi.
3:46:49Okay, taby API key because uh what
3:46:52happens? Let's say whenever I will be
3:46:54initializing the search tool, okay,
3:46:56search tool of the tab. Uh so to use
3:46:58this tab, I need a API key. So how to
3:47:00get the table API key? So for this you
3:47:02have to visit tavly.com. Okay. Or you
3:47:06can search like tavly API key. So
3:47:08instead of taby there are some other
3:47:10like search tool are available like sar
3:47:12api duck duck go search uh and other
3:47:14tools are also available but I'm going
3:47:16to use this tably one. So simply click
3:47:18on tably api key.
3:47:21So you have to create a account if you
3:47:23don't have account. So I already have
3:47:24the account guys. I created with the
3:47:25help of my Gmail. So once you are inside
3:47:28the dashboard you will be seeing this
3:47:29kinds of interface. So from here you can
3:47:31create a API key. Okay. So for me I
3:47:33already have created some API key but
3:47:34let me show you how to create the API
3:47:36key. So let's say here I'm going to
3:47:37create a API key called my key. Okay.
3:47:41Once it is done just create the API key.
3:47:44Okay. Your key is created and initially
3:47:47whenever you are creating an account you
3:47:48will be getting 1,000 free credit. I
3:47:51think this is enough for learning but if
3:47:52you want to use it for the production
3:47:54that time you have to take their premium
3:47:55plan. Okay. Now let's copy this key and
3:47:58what I'm going to do I'm going to open
3:47:59up my env
3:48:03inside that I'm going to mention my tabi
3:48:09table APAK. So let's make let me copy.
3:48:12So this is my tab APK.
3:48:16Okay APK done. Now let's uh initialize
3:48:21this thing. But I have to load the
3:48:24environment first of all. load
3:48:25environment variable.
3:48:28Let's load.
3:48:35Yeah. So here we are loading the
3:48:37environment variable. But before loading
3:48:38it, so here you can see I'm setting this
3:48:41SSL uh certify file. Okay. Uh so from
3:48:46this certify uh library you can see we
3:48:48have already imported and here we are
3:48:50calling v because what happens if you're
3:48:52using windows operating system so
3:48:54sometimes it will it it might give you
3:48:56some path related issue okay because
3:48:58what happens window windows by default
3:49:00uh open some older uh path okay and uh
3:49:05that's why this issue usually raises so
3:49:08what this code does actually it will uh
3:49:10tell your windows that uh it will always
3:49:13try to use the trusted
3:49:15C uh certificate authority uh uh so that
3:49:19uh whenever it is initializing the
3:49:22uh path uh it will load the updated one.
3:49:25Okay, instead of loading the old one,
3:49:28okay, you can also search over the
3:49:29internet, you can read about this SSL
3:49:32certified file. Okay, I think you will
3:49:33be able to understand. But if you're
3:49:34using any other operating system like
3:49:36Mac OS or Linux, I think that time it is
3:49:38not required. But if you're getting the
3:49:40path related issue, that time you can
3:49:41add this code guys. Okay. Uh this is
3:49:43optional. Uh for me actually I was
3:49:45having this issue that's why I have
3:49:47added but for you if you don't have
3:49:48issue uh if you don't have issue you
3:49:50don't need to add it. Okay. It's
3:49:51completely fine. So once it is done now
3:49:53we are getting our open API key and uh
3:49:56we are loading it here in this
3:49:58particular variable and we are also
3:50:00loading our tably API key. Okay once it
3:50:02is done let's try to load them.
3:50:10Now
3:50:12uh we'll be initializing the tab search
3:50:15result uh object. So I can name it as a
3:50:20search tool.
3:50:25Search tool is equal to tably search
3:50:29result.
3:50:32And inside that there is a parameter you
3:50:35can mention like max result. Okay max
3:50:37result means how many result you want
3:50:40after doing the internet search
3:50:42operation. Let's see what searching for
3:50:45a topic. Let's see what searching give
3:50:46me some latest news. So how many search
3:50:50result you want? How many reference
3:50:51website you want? So if if it is let's
3:50:53say two, this will give me two relevant
3:50:56uh let's say um result. Okay. If you if
3:50:59it is five, it will give me five
3:51:00reference. That's how it works. Okay.
3:51:02Now let me uh show you how this thing
3:51:05will work.
3:51:07So simply what I will do, I'll just try
3:51:09to initialize it. Now let's try to test
3:51:11it.
3:51:13Search
3:51:15tool
3:51:17dot invoke
3:51:21inside that I'm going to let's say give
3:51:23what is the capital of French
3:51:30okay or let's say I'll tell
3:51:38okay now s spelling is not correct
3:51:45Now fine. Now here I can tell
3:51:50give me
3:51:54the latest news on AI. Now
3:51:58I will store it in a variable called
3:52:01result.
3:52:04Now simply I'm going to show this
3:52:07result.
3:52:10search tool is not defined. I have to
3:52:12execute this. Now re-execute this.
3:52:19Okay. Now see uh it is real time
3:52:22searching over the internet and it is
3:52:24referring some of the website. You can
3:52:26see this is the URL. So this is the
3:52:27first website it is referring for the
3:52:29latest news on AI. Uh let me show you
3:52:32this website. This is referring this uh
3:52:35blog google.com. So here is the latest
3:52:39AI news announced in March 2026 and
3:52:43there is another reference you will get
3:52:45see uh this one this is another website
3:52:48uh from here also it is getting the
3:52:50informations that means now my maximum
3:52:54result is two I'm getting two actually
3:52:57um
3:52:59internet search reference if you if you
3:53:00make it as three four you'll be getting
3:53:02four reference okay like that okay
3:53:04that's how you can use this tab Search
3:53:07for real time internet search operation
3:53:10and this is called actually search tool
3:53:12and you can use this tool with your
3:53:14agent because agent should be always
3:53:17connected with uh this kinds of external
3:53:19tool like this kinds of realtime tool
3:53:22whenever it needs any kinds of latest
3:53:24information it will be using this tool
3:53:25to get this informations okay uh with
3:53:28you and again I'm telling you I'm
3:53:30creating a single agent system here uh
3:53:33I'm not creating multi- aent system I'm
3:53:34also going to show you how we can create
3:53:36the multi agent system as well. Okay,
3:53:38each and everything I'm going to cover
3:53:39but in this video we'll be only focusing
3:53:41on the uh single agent system. Okay,
3:53:45fine. Now our search tool is ready. Now
3:53:49simply what I'm going to do, I'm going
3:53:50to initialize me my large language
3:53:53model. So let's initialize our large
3:53:55language model.
3:53:57So this is the large language model
3:53:58guys. So from chat openaii, we are
3:54:00taking this GPT 3.5 turbo model. You can
3:54:02also use GPT45. It's up to you.
3:54:04Temperature this is the creativity
3:54:05parameter. I I I just kept it with zero.
3:54:08And here you need to pass the open API
3:54:10key. Now let's initialize the LLM. So on
3:54:13it is initialized. Let me also test
3:54:14whether my LM is working or not. I'll
3:54:16just do the invoke operation. LM.infoke.
3:54:20Now here I'm telling let's say
3:54:24uh what is the year is it
3:54:28and the result we'll be getting again we
3:54:30will store
3:54:34spawns
3:54:43see uh this is is it currently uh 2022
3:54:472.
3:54:51Okay. Why it is giving you it is uh
3:54:54currently 2022 because this GBT3.5 turbo
3:54:59uh has been trained till 2022. Okay, it
3:55:01doesn't have any latest information
3:55:03after that. Okay, that's why this agent
3:55:05is required. I told you right in my
3:55:07introduction session why uh we don't use
3:55:10the large language model only. Why agent
3:55:12is required? Okay, why realtime tool is
3:55:14required? Each and everything I've
3:55:15already clarified. Now let me ask
3:55:17another question. Let's say
3:55:19tell me
3:55:22a joke about AI.
3:55:25Now see it is giving you a joke. Okay,
3:55:27that means it's working fine perfectly.
3:55:30Now I need a prompt guys. Okay. Um to
3:55:34implement the agent I need a prompt.
3:55:37And here we are using this uh
3:55:41um create react agent function. And for
3:55:43this create react agent function I need
3:55:45a relevant prompt. So this prompt either
3:55:48you can write manually either you can
3:55:50download from langen hub. So that's why
3:55:53we have already installed this langen
3:55:54hub. I think you remember. So what is
3:55:56langen hub? In the langen hub itself
3:55:58there are uh like so many prompt uh like
3:56:02pre predefined prompt are already
3:56:03available. So there are lots of uh let's
3:56:06say developer they have already
3:56:07published their prompt. So you can use
3:56:09the pre-existing prompt and you can use
3:56:11it inside your application development.
3:56:13But if you want you can also manually
3:56:14write this prompt. Okay. But why we are
3:56:16taking the predefined prompt uh because
3:56:18uh we are using this create create react
3:56:20agent functionality. Okay. And for
3:56:22create uh for this create react agent
3:56:24functionality. This prompt is like uh
3:56:27very good and this is recommended prompt
3:56:29to use that. Okay. Now let me show you
3:56:31this prompt. You can copy the name and
3:56:33if you go to Google
3:56:36uh you can search it. You can search it
3:56:39here. Let's say now you can open the
3:56:42first website.
3:56:45Okay. So you'll see this particular
3:56:48prompt guys here. See this is already
3:56:49available in the hub and you can see the
3:56:52prompt guys. Answer the following
3:56:53questions as best as you can. You have
3:56:55access to the following tools blah blah
3:56:57blah. Okay. I'm going to explain this
3:56:58prompt later on. But first of all, let
3:57:00me create the agents and then let me
3:57:03explain okay what it does. Now my prompt
3:57:05is ready. Now what I have to do guys, I
3:57:08have to prepare my tools. So I only
3:57:10created one tools which is my table
3:57:12search tool. So what I will do, I'll
3:57:14just try to add this tool. So let me
3:57:16create a list.
3:57:18Okay, inside that list I'm going to
3:57:20mention my search tool. Let's if you're
3:57:21using multiple tool, you can add inside
3:57:24this particular list. Okay, I'm going to
3:57:25tell you how we can add also. Now my
3:57:28tool is also ready. Okay, I have to also
3:57:30execute the prompt. Now see it has uh it
3:57:33has get this particular prompt from that
3:57:36length in hub itself. Now let me show
3:57:38you the prompt. Now see guys, this is
3:57:40the prompt. Okay, this is the prompt. It
3:57:42has already got this particular prompt.
3:57:44Great. Now you have to create the agent.
3:57:48Okay, you have to create the agent.
3:57:51Uh we have already got the prompt. We
3:57:53have already got the tool.
3:57:57Let me comment here.
3:57:59Okay, tool is there. Now we'll be
3:58:01creating the agent.
3:58:07Yeah. So to create the agent guys, we'll
3:58:09be using this function create react
3:58:10agent. And this create react agent takes
3:58:13actually uh three things. The first
3:58:15thing is the large language model. um
3:58:18like this is the brain of that
3:58:20particular agent and we are passing our
3:58:22large language model. The second is is
3:58:24that tool. Okay, the tool it will be
3:58:26using for uh actually external um search
3:58:31operation or external reference. And the
3:58:34third thing it needs the prompt. Okay,
3:58:36that means you are telling uh your agent
3:58:39how it should interact. Okay, how it
3:58:41should perform the jobs each and
3:58:42everything each and every instruction is
3:58:44giving inside the prompt. Okay. So
3:58:46whenever you are creating this uh uh
3:58:48react agent that time you have to pass
3:58:50this three thing. Okay. And this will
3:58:52return you one agent object object.
3:58:54Okay. Now let me execute. So I got the
3:58:57agent object right now. Now what I have
3:59:00to do I have to run this agent. Okay.
3:59:01With the help of the agent executor we
3:59:03have already imported. So as you can see
3:59:05we have already uh imported this agent
3:59:07executor. So let's use this agent
3:59:10exeutor to run this agent. And don't
3:59:12worry, I'm going to explain you why this
3:59:14uh uh I mean how this create react agent
3:59:17works, how this uh agent executor works.
3:59:20Okay, why it is required and everything
3:59:21I'm going to clarify. So now let me
3:59:24define the executor. So this is our
3:59:26executor. So as you can see we are
3:59:29calling this agent exeutor and agent
3:59:31exeutor takes another uh three argument.
3:59:33The first one is the agent. The agent we
3:59:35have created let's say here we have
3:59:37created only one agent. Okay, which is
3:59:39this one. we are passing it. Uh then we
3:59:42are giving the tool. Okay. Uh the tool
3:59:44we have initialized. Then there's
3:59:47another parameter called verbose. So
3:59:49verbose if you make it as true that
3:59:51means whatever agent will execute let's
3:59:54say whatever plan state it will execute
3:59:56you'll be able to see the in the
3:59:58terminal and if you make it as false you
4:00:00you won't be able to see the logs. Okay.
4:00:02So basically if you want to see the logs
4:00:03of your agent you can make it as true
4:00:05otherwise you can make it as false.
4:00:06Okay. So this will give you the agent
4:00:08executor object. So once you got the
4:00:10agent executor object now you are ready
4:00:12to run this agent. So to run this agent
4:00:14guys we'll be using this agent executor
4:00:18and we'll simply do the invoke operation
4:00:21and here we are giving a input. So the
4:00:23input wise we're giving find the capital
4:00:25of India and then the find its current
4:00:28weather. Okay. Uh so this thing I'm not
4:00:31going to pass it right now because uh I
4:00:34want to show you another things. Okay.
4:00:36Now simply I'm going to tell uh find the
4:00:39capital of India. Now uh it will give
4:00:42you the response
4:00:44and this response I'm going to print it.
4:00:49Okay this response. So from the response
4:00:52I I will uh print the output. Now let me
4:00:54execute.
4:00:57Now see agent is executing. So it is
4:01:00telling entering new agent exeutor
4:01:03chain. So I should use the search engine
4:01:05to find the answer. So it is using the
4:01:08search tool that means the tably search
4:01:10tool and it is finding see it is action
4:01:12is tably search tool it is util
4:01:14utilizing then it refers a website. Okay
4:01:17from the website itself it found that
4:01:19the capital of India is New Delhi and
4:01:22once it got the result okay now you can
4:01:24see the final result which is New Delhi.
4:01:26Okay. So let me uh give another input
4:01:29here. So, I'm going to just write
4:01:32um tell me the
4:01:37latest
4:01:40news about
4:01:47Iran
4:01:49and USA world. Okay. Now, let's execute.
4:01:56So it is you can see it is using this
4:01:58tably search tool. Okay. So as you can
4:02:01see my execution is done. So it is using
4:02:03this tably search tool and it is using
4:02:05different different online sources and
4:02:08it is extracting
4:02:10uh the latest information. And now let
4:02:13me show you the final output. So this is
4:02:15the final output. The latest news on
4:02:17Iran and USA war uh includes Iran
4:02:20warning of consequences if the US
4:02:23launches new attacks. Okay. blah blah
4:02:26blah that mean it is able to give you
4:02:27the real time okay the latest
4:02:30informations although we are using the
4:02:32GPT3.5 turbo
4:02:35okay which is uh trend till 2022 but it
4:02:38is able to give you the latest uh latest
4:02:41actually informations about 2026 okay
4:02:45now let me show you let's say if I'm not
4:02:47passing any kinds of tool to the agent
4:02:49so what will happen so here let's say
4:02:52what I'm going to do
4:02:54um h so let's say here I'm going to
4:02:57create a empty
4:03:00empty tool
4:03:02okay so I'm not going to pass anything
4:03:05in this tool
4:03:07now let's execute now again I will
4:03:10create the react agent again I will um
4:03:15execute the agent executor then I will
4:03:19ask this
4:03:35Now see it is continuously looking for
4:03:38the tool but it is not getting right.
4:03:40See it is not getting. So execution is
4:03:42done. If I uh print it the final
4:03:45response, you'll see that agent is
4:03:46stopped due to the iteration limit or
4:03:49time limit. Okay. What happens? Because
4:03:51whenever you are not providing any kinds
4:03:54of external tools, okay, what it is
4:03:56happening?
4:03:57Uh it is not able to get any kinds of
4:04:00tool which it can use for searching
4:04:03these kinds of latest informations and
4:04:05it is continuously running this tool a
4:04:07loop. Okay. So there are uh there are
4:04:10actually u limitation of this particular
4:04:13loop. So once let's say it is not able
4:04:15to get it. So this loop would be
4:04:17finished and you are getting uh this
4:04:19agent is stopped due to the iteration
4:04:21limit or time limit. Okay. But if we
4:04:23provide this tool, okay, if we provide
4:04:26this tool
4:04:28that time see my agent is working uh
4:04:32working perfectly fine.
4:04:37Okay, see it's working perfectly fine.
4:04:39Now it is able to get the tool and it is
4:04:42able to search the content on the
4:04:44internet and it is giving you the um
4:04:47answer. Okay, I hope you get it.
4:04:51That means what is happening? Let's say
4:04:53this [clears throat] is our agent.
4:04:56This is our agent.
4:04:59Okay. And here we are giving a prompt or
4:05:04input
4:05:06and uh what it is doing first of all
4:05:08this input is coming to the agent and it
4:05:11is utilizing LLM okay as a brain for the
4:05:15reasoning operation and LLM is uh
4:05:19deciding let's say the input we are
4:05:21giving whether it needs any kinds of
4:05:23tool or not. So the question we have
4:05:25given so definitely it needs a tool
4:05:27because here we are using very old LLM
4:05:30right which is GPT3.5 Turbo okay it
4:05:32doesn't have the informations about Iran
4:05:34and USA world right because this this
4:05:36happens actually this year that means
4:05:38the current year now LM will tell okay I
4:05:41don't have the information so what we
4:05:43have to do we have to use a external
4:05:45tool okay what we have to do we have to
4:05:47use external tool so right now let's say
4:05:49I have connected with tabuli search API
4:05:52so what it is doing it is going to tabul
4:05:56it is executing this tool. This tool is
4:05:58giving you the response like it is
4:06:00referring uh to website because there is
4:06:02a parameter called uh um search result
4:06:06uh that parameter I have like set it
4:06:08two. So it will get two relevant uh
4:06:10let's say informations about the uh USF
4:06:15word. So this is returning to the agent
4:06:17and now agent is getting that
4:06:19information and it is giving you the
4:06:21final output. Okay, it is giving you the
4:06:23final output. That's how things are
4:06:25working. And whenever you are not giving
4:06:27this tool, right, that time what is
4:06:29happening? Agent agent is continuously
4:06:31looking for the tool but it is not able
4:06:33to get it any kinds of response from the
4:06:35tool. That that's how uh it is breaking
4:06:38the loop. It is breaking the iteration
4:06:40and it is giving you I uh I didn't got
4:06:43the answer. Okay, the loop is uh
4:06:46executed uh sorry the loop loop is
4:06:50uh stopped. Okay, I think you saw this
4:06:52final message here. Uh here is the final
4:06:55message. Uh okay, I already like uh
4:06:59replace it. I think you saw the message,
4:07:01right? This loop is already closed. Uh
4:07:02we are not able to uh execute that.
4:07:05Okay, so that's how things are working.
4:07:07Now let me explain about these uh two
4:07:10things which is create react agent and
4:07:13another is agent exeutor. Okay, how this
4:07:15create create react agent works. Why why
4:07:18we call it as a uh reasoning action
4:07:21agent and why agent execute exeutor is
4:07:25required to run this particular create
4:07:27react agents. Okay, I'll try to discuss
4:07:29this part right now.
4:07:33So guys as you can see uh first of all
4:07:35let's try to understand this uh react
4:07:38agent how react agent works. So as you
4:07:40can see React is a design pattern used
4:07:43in AI agents that stands for reasoning
4:07:46and acting. Okay. Um it allows a
4:07:50language model LLM to uh inter
4:07:54interleive internal reasoning thought
4:07:56with external act actions like tool use
4:08:00in a structured multiple process. Okay,
4:08:03that means I told you if I want to
4:08:06execute a agent, so I need some external
4:08:09tools, right? And to select that
4:08:13particular external tool definitely you
4:08:14need a reasoning and that reasoning you
4:08:16are doing with the help of LLM, some
4:08:18kinds of large language model. large
4:08:20language model is deciding okay now I
4:08:22have to use this particular tool and you
4:08:24are using that tool to get the response
4:08:26and you are you uh and you are actually
4:08:29sending that particular tool response to
4:08:32the agent and agent is giving you the
4:08:33structured output okay so the whole
4:08:35system is working like that okay now we
4:08:38are using this react react agent okay
4:08:40from the langen so the react agent is
4:08:43implemented in that way okay because
4:08:44internally they have written all kinds
4:08:46of code related this kinds of
4:08:48orchestration that means It has the
4:08:50connection with LLM. It has the
4:08:52connection with lots of tool. Okay. So
4:08:54once we are giving any kinds of prompt,
4:08:56it is automatically deciding with the
4:08:58help of LLM like what tool to use. Okay.
4:09:01For the actions. So let's say once I
4:09:03executed the tool uh then what will
4:09:07happen uh this tool will give you some
4:09:09kinds of response and you will be
4:09:11structuring this particular output and
4:09:13you will show uh show to the human.
4:09:15Okay. So this is a multi-step process.
4:09:17Okay. This is a multi-step process. That
4:09:19means this is a kinds of loop. Okay. So
4:09:21you can see instead of generating an
4:09:23answer in one go the model thinks step
4:09:25by step decides uh deciding uh what it
4:09:28needs to do next and optionally calling
4:09:31tools APIs calculator web search etc to
4:09:35help it. Okay, that means not only um
4:09:37not only like tabularly search tool,
4:09:39okay, you can use any kinds of tool
4:09:40here. Either you can use any kinds of
4:09:41API, either you can use any kind
4:09:43calculator, web search and anything.
4:09:46Okay, now see this react works in three
4:09:49step. So I have already given an example
4:09:51as you can see the first step is nothing
4:09:53but the thought.
4:09:59Okay, thought. Then the second step you
4:10:02can see action.
4:10:05Okay. And the third step is nothing but
4:10:08observation.
4:10:14Observe.
4:10:16Observation. Okay. Now see here is the
4:10:19example. So what is thought? First of
4:10:21all let's try to understand whenever we
4:10:24are giving any kinds of prompt. Let's
4:10:25say we are giving a prompt. Uh let's say
4:10:28um we are giving a prompt. uh what is
4:10:31the capital of France and tell me the uh
4:10:36population
4:10:38uh tell me the population for capital of
4:10:41France. Okay, let's say this is my
4:10:42prompt. So first of all what will
4:10:44happen? We are using let's say this
4:10:46react agent. So this prompt will go to
4:10:48the react agent and react agent will try
4:10:50to make a thought first of all. So the
4:10:52what would be the first thought? First
4:10:54thought is nothing but let's say I need
4:10:55to find the capital of France. Okay. So
4:10:58first of all this would be the thought.
4:11:01Now for this particular thought it will
4:11:02perform a kinds of action. Okay. So in
4:11:05this action it will utilize external
4:11:07tool. So in this case it will utilize
4:11:09the search tool. Okay. And with the help
4:11:12of search tool what it will do? It will
4:11:14try to perform some action. Okay.
4:11:16[clears throat] So let's say it has done
4:11:18the searching operation the capital of
4:11:20France on the internet and it got some
4:11:22observation like okay the capital of
4:11:25France is nothing but Paris. Okay. So
4:11:28once it got the observation you can see
4:11:30the first loop is complete. Okay the
4:11:33first loop is complete and in the first
4:11:35loop it has performed three things
4:11:36action and observation. Now it will come
4:11:39to the second loop. Now you can see in
4:11:41the second loop again the thought will
4:11:42apply. Now let's say it has already got
4:11:45the Paris okay the capital of France.
4:11:47Now it will tell now I need to find the
4:11:49population of Paris. Okay what it will
4:11:52do again it will perform my action.
4:11:54Again it will maybe utilize a search
4:11:56tool or any other tool it is having with
4:11:58the help of this particular tool. It
4:11:59will perform the action. Okay. So now it
4:12:01will try to figure out the population of
4:12:03Paris. Now let's say observation is 2.1
4:12:06million. Uh it is the population of
4:12:08Paris. Okay. Now you can see this is the
4:12:12second loop. Okay. Second loop is
4:12:15complete. Now it will perform the third
4:12:18loop. Okay. Now you can see once it got
4:12:21the final result. Okay. Once it got the
4:12:23final result that time this loop would
4:12:26be um this loop would be stopped. Okay.
4:12:30Now how it will understand this loop
4:12:33should be stopped because there we uh in
4:12:36the prompt itself we try to set whenever
4:12:38we we get the final answer. Now let's
4:12:40say uh the uh third iteration you will
4:12:42you'll see that now I know the final
4:12:45answer. Okay. So once it knows the final
4:12:47answer okay that time this particular
4:12:51iteration should be stopped. Now you can
4:12:53see it will return with the final answer
4:12:54that time the Paris is Paris is capital
4:12:57of France and has a population around
4:13:002.1 million. Okay, that means the prompt
4:13:04I think you remember I showed you one
4:13:05prompt. Okay, we are using from langen
4:13:07hub in the prompt also these kinds of
4:13:11steps are available. Okay, and there we
4:13:13strictly mentioned that once you got the
4:13:15final answer. Okay, once you know the
4:13:17final answer just try to stop this
4:13:19particular iteration. Now let me show
4:13:20you this uh prompt again. I think now it
4:13:22would be clear to you. So guys, as you
4:13:25can see this was the prompt. Now you can
4:13:27see the prompt. Answer the following
4:13:28questions as best you can. You have
4:13:32access to the following tools. So I
4:13:34think you remember in our agents we have
4:13:35already provided the tool access. Okay.
4:13:38All the tool access we are having. Now
4:13:40we are telling use the following format.
4:13:42Question. Okay. Question should be the
4:13:44input uh questions you must answer.
4:13:47Okay. The user input questions. Now you
4:13:49can
4:13:51uh you can have three things three step.
4:13:53First of all thought. You should always
4:13:55think about what to do. Okay. And this
4:13:57thought how it will think with the help
4:13:59of LM. Okay. Now with respect to the
4:14:02thought it should perform some action.
4:14:04Okay. The action to take uh should be
4:14:06one of the tools. Okay. That means this
4:14:08action should be tell with the help of
4:14:10one of the tool. So once let's say we
4:14:13have selected the tool. Now uh what
4:14:16should be the action input? We have to
4:14:18provide the action input. Now this will
4:14:21perform the action and when whenever it
4:14:24will get the response from the tool. So
4:14:26this this is called actually observation
4:14:28the result of the action. Okay. Once you
4:14:30got the observation now this particular
4:14:32step should be running continuously. You
4:14:33can see this thought action action input
4:14:36observation can repeat end times unless
4:14:38and until thought is I know uh the final
4:14:42answer. Okay. I know the final answer.
4:14:44This particular this particular uh let's
4:14:46say
4:14:48um iteration should be continuously
4:14:50running. Okay. Once you know the final
4:14:52answer that just try to provide the
4:14:54final answer. Let's say this is the
4:14:55final answer of the original questions
4:14:58and uh what will happen? It will try to
4:15:02uh end that particular uh agent. Okay.
4:15:04So every agents works like that guys.
4:15:06Okay. I think you got it because the
4:15:09main fun is behind a agent is to run
4:15:11some of these steps. Okay. And
4:15:14continuously this will run this steps
4:15:16unless and until it found the final
4:15:18answer. Okay. Once it found the final
4:15:20answer then this particular loop would
4:15:21be break and you will be getting the
4:15:23final output. Okay. Now you can see the
4:15:26question um as a as a like say um human
4:15:30we have to give the question our
4:15:32question and agent internally will try
4:15:34to take the agent uh scrap uh scratch
4:15:37pad. Okay. What is agent scratch pad?
4:15:40Agent scratch pad is nothing but the
4:15:42that three things. Okay. this thought
4:15:45action and observation because
4:15:47continuously it has to take that okay
4:15:49continuously it has to take that to
4:15:51understand the previous question action
4:15:53and observation okay so these kinds of
4:15:55things will be continuously happening
4:15:57unless and until we're not going to
4:15:59final answer okay now I think you got it
4:16:03so that's why I told you uh we'll be
4:16:06using this predefined react prompt for
4:16:09this react agent uh you can also write
4:16:11your own prompt but if you're writing so
4:16:13you may miss down these are the option
4:16:15and whenever you miss down these are the
4:16:17let's say context or definitely your
4:16:19agent uh might not give you the correct
4:16:21response so that's why prompting is
4:16:23always important whenever you're
4:16:24creating your own agent system guys okay
4:16:28so guys now I think you have understood
4:16:31uh what is this uh create react agent
4:16:33okay how it works uh now we'll try to
4:16:36understand what is this executor is
4:16:38agent exeutor okay why we need this
4:16:40agent exeutor to run this uh react agent
4:16:43let's try to understand about this.
4:16:45uh one more thing I want to uh tell you
4:16:47which is that let's say after using this
4:16:49create react agent it takes three
4:16:51parameter lm to send prompt we get the
4:16:53agent object okay this is our final
4:16:55agent object and to run this agent we
4:16:57need this agent executor okay now let me
4:17:00show you another diagram
4:17:02so guys as you can see uh this is the
4:17:06diagram of agent and agent executor now
4:17:08we'll try to understand how this works
4:17:11okay why this agent executor is required
4:17:14so let's say we I have created a react
4:17:16agent object which is nothing but our
4:17:18agent. Okay, in the code itself I
4:17:20already told you. Now to run this agent,
4:17:22I need a agent executor. Okay, so why I
4:17:25need this agent exeutor. See to run this
4:17:28agent. Okay, I think you know internally
4:17:30agent uh runs actually three step. One
4:17:33is the first thing first thing is like
4:17:35the uh this one which is um
4:17:40um let me show you. Yeah. The first
4:17:44thing is the thought. Okay. Thought
4:17:54thought. Then second thing
4:17:58is action
4:18:00and the third thing is observation.
4:18:06Okay. So to run this three step guys we
4:18:09need this agent executor. Okay. Okay, to
4:18:11run this three step we need this agent
4:18:13executor. So without agent executor we
4:18:16can't actually run this three steps.
4:18:18Okay. So that's why whenever we have
4:18:20created our agent to execute this agent
4:18:24we need a agent executor and internally
4:18:26agent executor handle these three
4:18:28scenario. So what will happen in the
4:18:29first iteration let's say uh you can see
4:18:32this is the steps of agent executor
4:18:34orchestrate the entire uh loop. So first
4:18:36of all sends the input uh and previous
4:18:39message to the agent. Okay. So what will
4:18:42happen? This agent executor will try to
4:18:44send the input. What is the input? Input
4:18:47of nothing but the user input. Okay.
4:18:50User input. Let's say user has asked
4:18:53let's say um I think I can give you the
4:18:56same example the previous example. Uh
4:18:59what is the capital of friends? And uh I
4:19:01need the population of capital of
4:19:03friends. Let's say this is the input. So
4:19:05first of all this agent executor will
4:19:07try to send this input to the agent and
4:19:09it will also send the previous message
4:19:11to the agent. Previous message means
4:19:13these three things start action and
4:19:15observation. So initially for the first
4:19:18time whenever you are executing the
4:19:19agent definitely this three uh three
4:19:22actually block would be completely
4:19:24empty. Okay this three block complet uh
4:19:26it should be completely empty. That
4:19:27means whatever thought action and
4:19:30observation you are sending it it should
4:19:32be completely empty. So your agent will
4:19:34only receive the user input that time.
4:19:36Okay. Now once it got the user input now
4:19:40your agent will decide okay whether it
4:19:43has to use any kinds of tools or not.
4:19:45Okay. Now you can see gets the next
4:19:47action from the agent. Okay. Uh so you
4:19:50can see
4:19:52um uh yeah so sends the input and
4:19:55previous message to the agent. Once it
4:19:56is done, now uh agent will try to uh
4:20:00let's say perform the reasoning
4:20:01operation with the help of reasoning. Uh
4:20:03it will decide the question we are
4:20:05getting whether I need to use any kinds
4:20:08of tools or not because agent is already
4:20:10connected with the tools. I think I
4:20:11showed you right. It has already
4:20:12connected with tools. Okay, it has
4:20:15connected with tools. Now agent will
4:20:17decide whether it has to use any tools
4:20:19or not. Let's say it has to use a tool.
4:20:21What tool? The tabular search tool. Then
4:20:23again agent will try to tell agent
4:20:26executor they uh uh um that like I have
4:20:30to use the tably search tool to give the
4:20:33answer. Okay. Now what agent executor
4:20:35will do? It will go to the tool. What
4:20:38tool? The tably tool. Okay. Tablely tool
4:20:41and it will hit the tably tool with the
4:20:45question user is asking. Let's say the
4:20:47first question was what is the capital
4:20:49of French? Now tab will refer some
4:20:51internet website and it will give you
4:20:53the answer. Again agent will give this
4:20:56answer to the agent. Okay. Now agent got
4:20:58the answer. Let's say the capital of
4:20:59France is Paris. Okay. Now what will
4:21:02happen? This is the observation. You can
4:21:04see execute the tool with provide an
4:21:05input adds the tool observation back
4:21:08into the history. Now what will happen
4:21:10again? It will try to add uh add uh
4:21:14inside this thought action observation
4:21:16because it is already getting this
4:21:17thought.
4:21:19uh then action and observation. Now this
4:21:22these are the parameter would be filled
4:21:23up. Now what is the thought? Thought
4:21:25should be uh let's say it already got
4:21:28the um capital of friends which is Paris
4:21:31action it has already taken it has used
4:21:32the tabularly tool. Okay. And uh the
4:21:35input was what is the capital of friends
4:21:37and uh uh sorry thought should be uh it
4:21:41already got the capital of friends.
4:21:44Okay. Um and action should be it has
4:21:47let's say already executed the tab tool
4:21:49and observation should be the Paris.
4:21:51Okay, it already got the Paris. Now it
4:21:53will run the second loop. Okay, it will
4:21:55run the second loop because it does it
4:21:56didn't get the final answer yet. Okay,
4:21:58it didn't get the final answer yet. Now
4:22:01again what it will do again exe agent
4:22:02executor will run. Okay, now agent uh
4:22:06agent executor will run the thought.
4:22:08What is the thought now? Next thought
4:22:10should be this one. Next thought should
4:22:13be this one. Now I need to uh I need to
4:22:16find the population of Paris. Okay, this
4:22:18should be the next part. Again go to the
4:22:20agents. Again agents will decide whether
4:22:23it has to use a tool or not. So again it
4:22:26will tell okay I need to use the tab
4:22:27search tool. Agent executor will go to
4:22:29tab search tool. It will hit the tab
4:22:32search again get the realtime
4:22:33information pass it to the agent. Now
4:22:35agent will again fill up this
4:22:36information with thought action and
4:22:37observation. You can see thought action
4:22:40and observation. Okay let's see it got
4:22:422.1 million. Okay, now it got the final
4:22:45answer. Okay, now this agent will tell
4:22:48now I have the [clears throat] final
4:22:49answer. Now once agent executor got this
4:22:51one. Let's say now I have the final
4:22:53answer that time this agent executor
4:22:55will stop. That means this is running
4:22:56the entire loop. Okay, that means this
4:22:59is running the entire loop. So once you
4:23:00are getting the final answer, this
4:23:02particular loop would be executed uh
4:23:04exited and your application will stop
4:23:06and you will be able to see the final
4:23:08answer. Okay, so that's how things are
4:23:10working guys. That's how the langen
4:23:12agent and agent exeutor we are creating
4:23:15it is working internally like that.
4:23:17Okay. So whenever you are using this
4:23:19react agent so definitely you have to
4:23:21use this agent executor. This is very
4:23:23much required. Now I think guys you are
4:23:25pretty much clear about the langen
4:23:27create agent. Okay how it works. Sorry
4:23:31langen react agent how it works. Why we
4:23:33need this agent exeutor along with that.
4:23:36Okay. Now let me show you as a code.
4:23:39So you can see the code guys. Uh in the
4:23:41code itself we have already written this
4:23:43create react agent. It takes lm tool and
4:23:45prompt. Okay with the help of prompt it
4:23:48performs all the instruction how this
4:23:50react agent works. I think I already
4:23:51showed you the prompt and to run this
4:23:53agent I need the agent exeutor. That's
4:23:55why we are giving this agent tool we are
4:23:57also giving because I think you know
4:23:59that uh agent executor will uh invoke
4:24:02this tool. Okay that's why tool access
4:24:04also I need to give to the agent
4:24:05executor and there's another one
4:24:07verbose. Okay. Barbos is the all the
4:24:09execution is happening right internally.
4:24:11See you can see the logs but if you make
4:24:13it as false let's say I will make it as
4:24:15false. So what will happens? You won't
4:24:17be able to see any kinds of
4:24:21execution. Let me again create the react
4:24:24agent executor. Now if I run the agent
4:24:28see you won't be able to see any kinds
4:24:29of logs. See it executed but you can't
4:24:33see any kinds of log but still you will
4:24:34be able to see the output. Okay output
4:24:36is there. But whenever you make it as
4:24:38true right so you will be able to see
4:24:42the
4:24:44um log. So for this again I have to
4:24:48execute the agent.
4:24:58Now see this particular log you will be
4:25:00able to see whatever decision uh
4:25:02whatever thought actions and observation
4:25:04your agent is performing you are able to
4:25:06see that okay in live so that's why we
4:25:09make it as uh this parameter as true
4:25:11okay now I think you are clear enough
4:25:13guys okay so yes guys so that's how we
4:25:16can uh use this lang chain to develop
4:25:19this kinds of single uh single actually
4:25:23agent system and this is our first agent
4:25:26guys uh This is like a very simple
4:25:29agents we have created. Uh so don't
4:25:31worry in the next video I'm going to
4:25:33also show you how we can create the
4:25:34multi- aent system. So here only one
4:25:36agent is working right. But if you want
4:25:38we can also create multiple agent and
4:25:40that will be working together. Okay this
4:25:42is also possible. Now uh what I'm going
4:25:44to show you guys uh I'm going to show
4:25:46you how we can convert it uh this
4:25:48particular notebook in in a application
4:25:51file that means app.py and we can run
4:25:54that particular app.py Pi okay because I
4:25:56have showed you the research right now
4:25:58that means the experiment right now but
4:26:00in production definitely will you will
4:26:02not create the Jupyter notebook file
4:26:04instead of that you have to create a
4:26:05python file so let's say I'm
4:26:07[clears throat] going to name it as
4:26:08app.py Pi.
4:26:10Okay. So, simply what you can do, you
4:26:12can copy whatever code you have written
4:26:15in the notebook in this app.py. See, I
4:26:19just copy pasted the same code. Copy the
4:26:23same code. But before that, let me show
4:26:25you how we can improve this agent. Um,
4:26:29if you want to improve it, if you want
4:26:31to add some more tool, so how it can be
4:26:33done. Let's say here I want to add
4:26:35another tool and that particular tool
4:26:37will real time search the weather
4:26:39informations. Okay. Uh weather
4:26:41informations given any kinds of location
4:26:44because right now I'm using the
4:26:46tabularly search tool. It is completely
4:26:47fine. But I want my custom custom tool.
4:26:51Let's say I have created a custom
4:26:53function and that custom function I want
4:26:54to use use as a tool. Okay. How it can
4:26:57be done? Let's try to see that. So for
4:26:59this uh what I'm going to do I'm going
4:27:01to let's say import
4:27:04this langen
4:27:07dot
4:27:09tool
4:27:11okay import
4:27:14there is a function called tool you have
4:27:16to import that and I will import another
4:27:18library called request okay this two
4:27:21library I'll import once it is done now
4:27:24simply here I'm going to create a
4:27:26function so after this search tool maybe
4:27:29I can create my custom function. So this
4:27:31custom function will get the uh weather
4:27:34information. Okay.
4:27:37So I've already written a function. So
4:27:39let me show you this function how it
4:27:41works. So maybe I can show you test ip
4:27:46or let's say here itself. I'm going to
4:27:48show you how this function works.
4:27:51Yeah. So this is my function guys. So
4:27:53what this function does this function
4:27:55takes a city name. Okay. or given any
4:27:57kinds of location and it it it fetch the
4:28:00current weather informations of that
4:28:02particular city. So for this we are
4:28:03using this weather stack API. Okay,
4:28:06weatherstack API I think you know this
4:28:08is a website weatherstack.com.
4:28:10So let me show you
4:28:14uh
4:28:16this is the website
4:28:23weatherst.com. Okay. So this is the
4:28:27website guys. So here first of all you
4:28:28have to create a account. Uh just sign
4:28:30up with free. Okay. So once you sign up
4:28:33you'll be able to see your dashboard.
4:28:34Okay. So if you go to the dashboard
4:28:37uh
4:28:40so here you will be see this kinds of
4:28:41interface okay and uh we are using the
4:28:44free plan so in free plan only we can
4:28:46search the real-time weather information
4:28:48but if you're using the paid
4:28:50subscription of this weather uh stack
4:28:52that time you can perform location
4:28:53search uh astronomy data hour by hour
4:28:57okay full historical data so there been
4:28:59so many things you can perform here but
4:29:02I only need for the weather information
4:29:04That means my free plan is completely
4:29:05fine. So here you have the API key. You
4:29:07just need to copy this API key. Okay. So
4:29:10don't use my API key. I'm going to
4:29:11remove it after the recording. So here
4:29:13you have to pass this weather API key.
4:29:15Now what I can do maybe in the itself I
4:29:18can mention my
4:29:20API key. Uh so here is
4:29:24so I already collected this API key
4:29:26guys. Let me show you.
4:29:31So this is the API key. weather stack
4:29:33API key and this is the API key I have
4:29:35copy pasted from the dashboard. Okay.
4:29:38Now simply here itself you have to load
4:29:41this API key as well. So let's load it.
4:29:44Weather stack API key west.get weather
4:29:46stack API key. So you're also loading
4:29:47this. Okay. Once it is done now see this
4:29:50API key would be given here. Now how
4:29:52these things will work let me show you.
4:29:54I will copy this and uh I will paste it
4:29:57here. Now f string I'm going to just
4:30:01remove it.
4:30:03because this is I have given only for
4:30:05static variable f string I don't need
4:30:14now if you give any city here let's say
4:30:15I'll give
4:30:18I'll give home
4:30:24hit enter
4:30:26uh okay you have to pass the API key
4:30:28right so let's copy the API Okay.
4:30:43Now if I hit enter, see you will be
4:30:46getting uh response like that. Okay. So
4:30:49this is having the informations about
4:30:51the Mumbai uh the current uh weather
4:30:54information as you can see. Okay. the
4:30:56kind of weather information it is
4:30:58having. Okay. Now I have to extract the
4:31:00data from this particular JSON itself.
4:31:03So what I have done I have written a
4:31:05function here as you can see. So this
4:31:07function hit this URL with this API key
4:31:10and you can give any kinds of city name.
4:31:12I'm hitting with the help of this
4:31:13request library I have already imported
4:31:15here as you can see request. So once we
4:31:17get the response so what we are doing we
4:31:20are just converting to the JSON. Now we
4:31:22are telling if current not in data. So
4:31:25I'll tell could not find the face
4:31:26weather data because current parameter
4:31:28should be there because in the current
4:31:30one we are having the current weather
4:31:31information. Okay, this temperature
4:31:33weather it is having. Okay, so we are
4:31:35getting this current key. Now once we
4:31:37get the current key I'm taking the city
4:31:39name, temperature, weather and humidity.
4:31:41Okay, these are the information I'm
4:31:42taking. If you want you can also take
4:31:44any other information. It's completely
4:31:45up to you. So this is a function custom
4:31:47function. Now if I want to use this
4:31:49custom function as a tool. So what I
4:31:51have to do I have to write a decorator
4:31:53at the tool I have imported. Okay. So
4:31:56this tool I have imported. I have to
4:31:58just give this particular tool. Now what
4:32:00happens? This particular function
4:32:01becomes a custom tool. That means this
4:32:04tab search result this is a predefined
4:32:06tool. This is already developed by some
4:32:08other organization or other company or
4:32:10other developer. But right now this get
4:32:13weather data function we have created
4:32:14this is our tool or custom tool. Okay.
4:32:17That's how we can create our custom tool
4:32:18and we can use it inside our agent.
4:32:20Okay, this is also possible. Now let me
4:32:22execute. Now simply what you have to do
4:32:25uh here itself in the tool itself
4:32:29uh where I have mentioned the tool. Huh?
4:32:31In the tool you just need to give the
4:32:33tool name which is get weather data.
4:32:36Okay, that's it. Uh get weather data
4:32:42name.
4:32:43Yeah, now let's execute. I mean I will
4:32:45execute from the beginning.
4:33:04Okay. Now initialize the LM. Now we also
4:33:07involving the LLM for some response. Now
4:33:11facing the prompt. This is the prompt.
4:33:14Now we're initializing our tools. Okay.
4:33:16Now see you can pass list of the tools.
4:33:18You can pass hundred of tools. Okay.
4:33:20It's up to you. Now we are creating the
4:33:22agent and we are passing the list of the
4:33:24tools right now. Now my agent is having
4:33:27multiple tools. Okay. One is the search
4:33:28tool and this is the get weather tool.
4:33:31Now I'll again execute.
4:33:34Uh now uh my executor is ready. Now I
4:33:37can give a prompt. So now I'll give this
4:33:40particular prompt. Let's say
4:33:45this is the problem. Find the capital of
4:33:47India and then find the uh find its
4:33:50current weather. Now see if I execute
4:33:52you can real time see see I should first
4:33:55search the capital of India uh uses the
4:33:57weather data tool find the current
4:33:59weather. See first of all it has used
4:34:01the tably search tool to get the capital
4:34:03of India. So it is referring some
4:34:04website uh Indian website and it is
4:34:07getting uh the capital of India which is
4:34:08New Delhi. Okay. So we got the New
4:34:11Delhi. Now once it got the New Delhi now
4:34:13what it is doing guys it is utilizing it
4:34:16is utilizing my get data tools. Okay my
4:34:19get data tool and it is fetching the
4:34:21weather informations. Okay so that's how
4:34:24things are working guys. I think you got
4:34:26it. Okay that means now it is having
4:34:28multiple tools. So tably s it is
4:34:32utilizing for the search operation.
4:34:33Okay, for uh finding the capital of
4:34:35India and my get weather data tool it is
4:34:37utilizing to get the weather
4:34:38informations and how it is deciding with
4:34:41the help of this react agent. Okay,
4:34:44because it is internally using LLM and
4:34:46LLM is doing the reasoning. Okay, and it
4:34:48is deciding what tool to call and this
4:34:51kinds of tool calling and everything is
4:34:52happening with the help of this agent
4:34:53executor because it is running that
4:34:55three-step that means uh I think I
4:34:58showed you uh three-step means first of
4:35:00all thought, actions and observation.
4:35:02Okay, that's how things are working.
4:35:05Okay, I hope you get it. Now, if I want
4:35:07to uh convert everything in the app.py
4:35:09guys, so this is the final code. So, let
4:35:11me select my environment which is lang
4:35:13agent. So, this is the final code. I
4:35:15just copy pasted the same code, okay,
4:35:17from my notebook. As you can see the
4:35:19same code, nothing change. Okay, now I
4:35:23can run the app.py. Let me show you. So,
4:35:26I will open up my terminal and if I
4:35:28execute my app.py.
4:35:30So, python app.py Pi
4:35:36uh okay so it is telling table okay uh
4:35:39because I'm running the app.py and now
4:35:41app.py will refer this env because
4:35:43previously I created inside resource
4:35:44folder so what I can do I can copy all
4:35:46of the key and mention inside this
4:35:48particular variable okay now let's
4:35:51execute the terminal clear now again
4:35:53execute app.py
4:35:57Now see agent is executing.
4:36:02Now see first of all it is uh getting
4:36:04the capital of India.
4:36:07Now once is uh got that it is utilizing
4:36:10my custom tool get weather data and it
4:36:13is giving you the temperature. Okay. Now
4:36:16this is the final temperature. As you
4:36:17can see the capital of India is New
4:36:19Delhi and the current weather is 37 uh
4:36:2337°C with H. Okay, perfect. That means
4:36:26we have implemented our first agent
4:36:29guys. Congratulation with the help of
4:36:30Langen.
4:36:32Okay, and don't worry, I'm also going to
4:36:34show you how we can create the multi-
4:36:35aent system in the next video. Now let's
4:36:38say if you want to convert uh this uh
4:36:40app to a user interface, this is also
4:36:43possible. Maybe we can add uh streamlit
4:36:46user interface. So what I have done
4:36:48guys, I have uh just designed a
4:36:50streamlit user interface with the help
4:36:52of chat GPT. Uh you can also do that.
4:36:55Okay, it's like very easy. Uh you just
4:36:57go to the chat GP and tell I need a user
4:36:59interface for this code. So it will
4:37:02generate for you. Okay, so what I have
4:37:04done guys? Uh I have already generated a
4:37:09So what I can do? Let's say I'll rename
4:37:11this file. Maybe I can name it as
4:37:13main.py. pi. Now I'll create another
4:37:15file here. I'm going to name it as
4:37:16app.py.
4:37:18Okay. Inside that I'm going to paste my
4:37:20updated code.
4:37:24So this code is having the streamlit
4:37:26user interface.
4:37:28Okay guys, so this is the code. So
4:37:30nothing else. I just added the
4:37:31streamlit. Uh I think you know streaml
4:37:33is a python package with the help of we
4:37:35can uh create the user interface without
4:37:37writing any kinds of HTML and CSS code.
4:37:39So first of all we have to install this
4:37:41streamlit. Uh so I will add this in my
4:37:43requirement streamlit. So let's install
4:37:49pip install hyphen requirement.txt
4:37:51Tasty.
4:38:33Okay, installation is complete. Now if I
4:38:35go to my app.py, now this error will
4:38:38disappear. Yeah, now see only change uh
4:38:42it has done it has set a streaml page
4:38:45configuration. So there you can see it
4:38:48has done a page configuration. Uh page
4:38:50title is agentic assistant page icon. Uh
4:38:54this is centered layout. This is the
4:38:56title
4:38:58and uh we have given a markdown search
4:39:00and weather AI agents using langen. And
4:39:04everything is same. The only thing is
4:39:05that at the last uh it has added the
4:39:08user query section. So there would be a
4:39:10input box. So there I can give the query
4:39:13and there would be a button. If I run
4:39:15this button, so my agent will be
4:39:17executing. Okay, so this is a simple
4:39:19user interface code my uh chatgpt added.
4:39:22Okay, inside my this main.py. Now let's
4:39:25execute and see how this looks like. I
4:39:28will clear and run streaml
4:39:33run app.py.
4:39:37I'll give the permission
4:39:39now.
4:39:45I'll show you this agent.
4:39:52Okay. So here I'm getting an error. So
4:39:54let me see the error.
4:39:59Okay. So this error I'm getting because
4:40:00I told you uh you have to add this line
4:40:04otherwise this error might come because
4:40:06I'm using Windows.
4:40:10I will add in the app.py. I
4:40:13here itself I will add that I have to
4:40:15import certify
4:40:18okay done now if I reexecute
4:40:22it should work
4:40:27see it's working now aentk assistant you
4:40:30can see this is the user interface now
4:40:32here I can give my query so maybe I can
4:40:35pass
4:40:38find the
4:40:42capital
4:40:44of let's say French
4:40:48and uh
4:40:50the current
4:40:55weather.
4:40:56Okay.
4:40:58Now if I run my agent,
4:41:02you can see agent is thinking.
4:41:06So every agent actually thinks. Okay. If
4:41:08you use any kinds of agent guys, you
4:41:10will see that this uh thinking uh option
4:41:13is there because internally it is
4:41:15executing
4:41:17uh that uh tools and everything all of
4:41:21these obs uh I mean three steps are
4:41:22executing like thought uh then action
4:41:25and observation that's why it's taking
4:41:27some time okay if you open any kinds of
4:41:29agent uh let's say if you open VS code
4:41:31agent if you open cloud desktop if you
4:41:34open Gemini you will see that this um
4:41:36process would be there Okay. Now see uh
4:41:38response generated. The final response
4:41:40is the capital of France is Paris and
4:41:42the current weather there is 11°C with
4:41:45rain and thunderstorm. Okay. That means
4:41:48our agent is perfectly working fine.
4:41:50Okay. Amazing. Now uh what we can do if
4:41:54we want we can also deploy this over the
4:41:56cloud because right now it is running on
4:41:58local host and people can't access my
4:42:01agent. So I can if I if I want I can
4:42:03also um I mean host this. So if you want
4:42:06to host this. So what I can do uh you
4:42:09can use uh different different cloud
4:42:10provider. You can use AWS, GCP, Azure.
4:42:13But uh let me show you one amazing cloud
4:42:16provider. There you can deploy this uh
4:42:18agent as free. So the cloud name is
4:42:21rendercloud. Okay, render.com. So if I
4:42:23open render.com. So you have to first of
4:42:25all create a account if you don't have
4:42:26account. So I already have the account.
4:42:28I'll just try to click on the dashboard.
4:42:31I'll login with my Gmail.
4:42:39Okay. Now simply what you have to do
4:42:42here first of all you have to um I mean
4:42:48upload this code to the GitHub. Okay. So
4:42:51what I will do guys I'll simply upload
4:42:54but before uploading I don't need to
4:42:57upload this because if I upload my my
4:43:01API key will be exposed. So here I will
4:43:03add another file called dot get ignore.
4:43:08Okay. Inside that I will mention env
4:43:12should be ignored and in researchb
4:43:18should be ignored. Okay. Now let's uh
4:43:22create a GitHub repo. I'll open my
4:43:24GitHub.
4:43:27I'll go to the repository.
4:43:31I'll click on new.
4:43:34I can give a name. So let's say I'll
4:43:36give
4:43:38this name
4:43:43search and
4:43:47weather AI agents using langen.
4:43:50Uh I'll add a readmi file.
4:43:54Then simply create the repository.
4:43:59and make sure you keep it as public.
4:44:01Okay, you can also make it as private.
4:44:03It's up to you. Now I'll click on code,
4:44:05copy this link address. I'll open up my
4:44:09local folder and clone this repo here.
4:44:12So get clone
4:44:18done. Now what I will do, I'll just copy
4:44:21this. Git and paste it here. Okay. And
4:44:25this folder I'm going to remove it. I
4:44:27only need this. Git. Okay. Now from my
4:44:29VS code itself, I can commit the changes
4:44:32issue. Now if I show you see uh this env
4:44:36is ignored. Now simply I'll commit the
4:44:38changes.
4:44:41Now I'll just write get add space dot.
4:44:49Now get commit
4:44:53m
4:44:54uh I'll give updated.
4:45:00Now get push
4:45:03origin
4:45:06main.
4:45:10Okay. Now if I go to my GitHub
4:45:13refresh
4:45:16see all of the code are available. Okay.
4:45:18Now let's try to reply. So I'll go to my
4:45:20render
4:45:22and here what I'm going to do guys I'm
4:45:24going to just create a new web service.
4:45:30Okay. Now here I will click on public
4:45:33git repository. Now I'll copy the link
4:45:38and paste it here. Now let's connect.
4:45:43Done. Now you can give a other name also
4:45:45if you want. Uh it has automatically
4:45:48taken my um repository name. Now
4:45:51everything just keep it as same. Uh only
4:45:55here you just need to give a command.
4:45:57Okay. See it will also install the
4:45:58requirement. This requirement we are
4:46:00having. Okay. Now let's give the command
4:46:03of running streaml app. So this is the
4:46:06command. So basically this command will
4:46:08run the streaml server. Now here I will
4:46:11take the free okay free instance and
4:46:13here you'll be by default you'll be
4:46:14getting 512 MB RAM and 0.1 CPU uh which
4:46:19is a little bit slow uh but it is fine
4:46:21for the learning if you want to let's
4:46:23say professionally deploy it then you
4:46:25can take their plan okay but I think
4:46:27this is fine now here I'll try to add my
4:46:29environment variable so here I'm having
4:46:33open API key let's add it
4:46:37and I have to give the blue.
4:46:43I copy this.
4:46:50Then I will add the environment
4:46:52variable. Another one
4:46:56tab API key.
4:47:06I will add it here.
4:47:09Then add another one
4:47:12which is
4:47:14this weather stack API key
4:47:19and add the value
4:47:27done. Now simply
4:47:30um okay now simply I'll just do the
4:47:33deployment deploy web service.
4:47:41So this is the free instance. Uh it may
4:47:43take some time guys. We'll wait once uh
4:47:46this particular option is live. Okay.
4:47:49Now it is building the entire uh
4:47:51instance. Okay. Internally it will set
4:47:52up everything. Once this is live we'll
4:47:54be able to test that. Now see it's
4:47:56running.
4:48:15Now see it is installing the
4:48:17requirements one by one. Uh let's wait.
4:48:26So I will pause the video once this
4:48:27installation everything is complete.
4:48:29I'll come back.
4:48:31So guys as you can see our application
4:48:33is live right now. Uh everything is
4:48:36fine. There is no added. Now there is a
4:48:38link you can copy and you can open in
4:48:40your browser.
4:48:42So there you will be able to see your
4:48:44agent.
4:48:53So guys uh you can see this is our
4:48:55application. This is completely live. Uh
4:48:57if you're using free instance it may
4:48:59take some time. Uh now we can test it.
4:49:01So here I'll just tell find the capital
4:49:06uh of Nepal
4:49:10and
4:49:11tell me the
4:49:15weather
4:49:17of that. Now I'll run the agent.
4:49:24Now see agent is working internally.
4:49:36So guys, here is the final response. The
Building End-to-End Multi-Agent AI System with LangChain
4:49:38capital of Nepal is Kathmandu and
4:49:40current weather 20° C with drizzle and
4:49:4494% humidity. Okay, amazing. Now you can
4:49:48share this uh URL with anyone they will
4:49:50be able to use your agent. So yes guys,
4:49:53I hope you understood. I hope you have
4:49:55seen how we can utilize uh this lang
4:49:58chain to develop these kinds of AI
4:50:02agents. But uh here we have created the
4:50:04single agents. Okay, single agents
4:50:06pipeline. Uh in the next video I'm going
4:50:09to show you how we can create the multi-
4:50:10aent system. Okay. So everything would
4:50:12be covered. So guys uh we'll be
4:50:15continuing with our complete agentic AI
4:50:18course. And I think you remember in our
4:50:20previous video I have already shown you
4:50:23how we can implement uh a single AI
4:50:26agents with the help of langen. So this
4:50:28was our first AI agents implementation
4:50:30with langen. Then I told you I'm also
4:50:33going to show you how we can create
4:50:35multi- aent system with the help of
4:50:37langen. So in this video I'm going to uh
4:50:40show you the entire implementation how
4:50:42we can utilize lang chain orchestration
4:50:45framework for implementing this kinds of
4:50:47multi- aent AI system. Okay. So make
4:50:50sure you watch this video till the end.
4:50:53Uh you don't miss anything. If you
4:50:55complete this video you'll be able to
4:50:56implement u multi- aents AI system with
4:50:59the help of langen. And in this video
4:51:01I'm not only going to implement uh these
4:51:04AI agents uh even after implementation
4:51:07I'm also going to show you how we can
4:51:09add the user interface and how we can
4:51:11deploy this kinds of multi- aent system
4:51:13on the cloud platform. I implemented a
4:51:17weather AI agents with the help of
4:51:19langin. So there I created a single
4:51:22agent uh that has some tool connection
4:51:25like I given tabuli search tool and I
4:51:28created one of the custom tool. Okay. Uh
4:51:31that particular tool uh can access any
4:51:35kinds of uh realtime weather
4:51:37informations given any kinds of city or
4:51:40uh location whatever okay that means if
4:51:42I show you the architecture diagram. So
4:51:46yeah if I show you the architecture
4:51:48diagram. So there let's say I created a
4:51:50single agent. Let's say this is our
4:51:53agent.
4:51:56Okay. So this agent having some
4:52:00connection with tool.
4:52:02Let's say it is having connection with
4:52:05tabuli.
4:52:13Okay. Okay. And it is having connection
4:52:15with
4:52:16weather
4:52:18API.
4:52:25Okay. So whenever I was giving any kinds
4:52:28of prompt or let's say input. So first
4:52:31of all uh this will uh and definitely it
4:52:34was connected with the LLM. Okay.
4:52:37because LLM was the brain and with the
4:52:40LLM actually it will perform the
4:52:41reasoning operation and um whenever I
4:52:45was giving any kinds of input then LLM
4:52:47was deciding whether I need to use a
4:52:50tool or not uh with respect to the
4:52:51question let's say if I'm giving a
4:52:53prompt uh just tell me the capital of
4:52:56India and uh give me the weather
4:52:58informations of that right so what it
4:53:00will do it will first of all go to the
4:53:02agents and it will search with the help
4:53:04of tab like what is the capital of India
4:53:07India then it will get let's say the
4:53:09capital of India is Delhi. Now what it
4:53:11will do again it will tell okay now uh
4:53:14you just need to fetch the weather
4:53:16information
4:53:18of the uh Delhi. So with the help of uh
4:53:20this weather API it will real time get
4:53:23this informations and uh your agent will
4:53:26try to refine the output and it will
4:53:29show you the final output.
4:53:32Okay. So that's how the things were
4:53:33working and the whole system actually we
4:53:36have orchestrated with the help of
4:53:37langen. So there we used actually create
4:53:40uh react agent right this functionality
4:53:42we used from the langen and to execute
4:53:45this create uh react agent we used agent
4:53:47exeutor and the full form of uh react is
4:53:51reasoning and uh action or acting
4:53:54whatever you can say. So with the help
4:53:56of that we created the agent. Okay. So
4:53:58this was the previous architecture. Now
4:54:01first of all let me give you u the
4:54:03multi- aent uh we'll be implementing uh
4:54:07for uh for this video. Uh first of all
4:54:09I'm going to give you the idea what is
4:54:12the system we're going to develop. Then
4:54:14I'm also going to show you the
4:54:16architecture diagram. Okay like what
4:54:18would be the flow and how we can uh
4:54:22create the AI agents how we can make the
4:54:24connection with different different
4:54:25tool. That means the entire uh overview
4:54:27I'm going to give then we'll start with
4:54:28the development. So for this uh this is
4:54:31the uh this is the actually content I
4:54:34have prepared. So as you can see uh
4:54:36multi- aent system with the help of
4:54:38langen we'll be developing in this
4:54:40video. So a multi- aent uh research
4:54:42assistant is a fully autonomous AI
4:54:45system that thinks uh search reads and
4:54:48writes on its own. Okay that means here
4:54:50we'll be creating a multi- aent research
4:54:52assistant. Okay basically this will
4:54:54perform the research. So I think you
4:54:56have seen in chart GPT or Gemini there
4:54:58is a research option is available uh if
4:55:01you open that uh uh let's say
4:55:03application. So if you perform the
4:55:05research so what it will do it will take
4:55:06some time and it will perform the
4:55:08research operation on the internet u uh
4:55:11in a given topic right so that's how
4:55:14we'll be also implementing a research
4:55:15assistant so that research assistant
4:55:18will be having some kinds of uh let's
4:55:21say tool access and with the help of
4:55:24tool it will perform the realtime
4:55:26resource operation okay and here we are
4:55:28not going to create a single agent
4:55:30instead of that we'll be creating the
4:55:32multi- aent system here so as you can
4:55:33see mult multi- agent research assistant
4:55:34a fully autonomous AI system that
4:55:36thinks, searches, reads and writes its
4:55:38own. Okay. Instead of a single AI
4:55:41answering your question from tools, uh
4:55:44here we'll be developing a team of
4:55:46specialized intelligence agents. Okay. A
4:55:48team of intelligence agents will be
4:55:50developing here uh that collaborates
4:55:52together to produce a professional
4:55:54research report on a uh topic you give
4:55:57them. That means if you are giving a
4:55:59topic okay so what it will do it will
4:56:01per uh it will use all of the like
4:56:04specialized intelligent agents okay it
4:56:07will work together and it will try to
4:56:09give you a professional okay research
4:56:11report on that particular topic. So it
4:56:13it will not only research okay it will
4:56:15also write the report for you okay and
4:56:18you can see the search agent goes so the
4:56:21first agent should be the search agents
4:56:23with the help of search agents will be
4:56:25uh doing the real time let's say
4:56:26research operation over the internet the
4:56:29search agent goes out on the live
4:56:31internet and finds the most relevant
4:56:33recent sources okay so it will perform
4:56:36the research operation of all of the
4:56:39internet sources it is having uh then
4:56:42the reader agent then dives deep into
4:56:44the those sources and scrap the scrap
4:56:46and extracting meaningful content. That
4:56:49means here I'm going to create another
4:56:50agent. The agent name would be reader
4:56:53agent. So that region agent uh what it
4:56:55will do it will try to scrap and extract
4:56:58okay all of the content from that
4:57:00sources. Let's say the first agent will
4:57:03return you the recent
4:57:05uh recent relevant sources that mean
4:57:08some URL. Okay. Now what we will do?
4:57:10we'll just try to pass this URL to the
4:57:12reader agent. So reader agent will take
4:57:14those URL and it will open that URL and
4:57:17whatever content it is having it will
4:57:19extract a scrap then uh it will gather
4:57:22those content. Okay. Then here we'll be
4:57:25creating another actually
4:57:27agent the writer agent uh writer agents
4:57:30uh takes all that generated intelligence
4:57:33and craft a well ststructured detailed
4:57:36report. That means write uh there would
4:57:38be another agent called writer. So this
4:57:39will take all of the content and it will
4:57:42uh prepare a draft. Okay, prepare a
4:57:43draft report. And after preparing this
4:57:46draft report, we'll be sending this
4:57:47draft report to another agent called
4:57:49critic agent. You can see and finally
4:57:51the critic agent reviews the entire
4:57:53reports, scores it and gives feedback
4:57:56just like a senior researcher reviewing
4:57:57a junior's work. Okay, that means at the
4:58:00last we'll be creating another agent.
4:58:01This agent will try to review. Okay,
4:58:04whatever let's say your writer agent has
4:58:06written, it will review. it will uh give
4:58:08you the feedback. Okay, it will uh do
4:58:10some marking. Okay, just like let's say
4:58:12you are a senior researcher. Whenever
4:58:14your junior is giving any kinds of task,
4:58:16you are reviewing that and you're giving
4:58:17the feedback. So, every single agent is
4:58:19powered uh powered by a large language
4:58:22model. Okay, connected through Langen's
4:58:24modern LCAL pipeline and orchestrated
4:58:27through a shared memory system that
4:58:29makes them works uh as one unified
4:58:32brain. Okay, so here we'll be utilizing
4:58:34the modern langen guys. So previous
4:58:37agent I created with the help of the old
4:58:39lang um but in this development I'm
4:58:42going to utilize the modern langen as
4:58:44well which is lce langen uh langen
4:58:48expression language so for this
4:58:50definitely you need the understanding
4:58:52about the fundamentals of langen so
4:58:54that's why I told you langchen
4:58:56prerequisite uh I mean definitely should
4:58:58be there if you are working with this
4:59:00kinds of agent so for this langen on my
4:59:03YouTube channel I already have one
4:59:05dedicated uh video guys ultimate langen
4:59:08crash course for developers uh so it's
4:59:10uh around seven more than 7 hours of
4:59:13course 7 hours of recording so there I
4:59:15already covered this LCL and everything
4:59:18if you go to the time stamp section uh
4:59:20you can see uh here I have already
4:59:22covered this uh LCAL okay LCL okay the
4:59:27modern uh langen which is langen
4:59:30expression language okay so definitely
4:59:32you should have understanding on this
4:59:34other topic if you don't know please try
4:59:36to go ahead with my langen lecture I
4:59:38will add the link in the description
4:59:40from there you can check it out okay so
4:59:42the main fun is in this development
4:59:44we'll be using the modern langen instead
4:59:45of using the old langin uh uh I wanted
4:59:48to show you both of the langen version
4:59:50because still people uses old langen
4:59:52okay uh and people also use like model
4:59:55langen both I'm going to show you uh you
4:59:58can use any of them okay it's completely
5:00:00fine but I will recommend you to use the
5:00:02model lang chain because in model lang
5:00:05chain the updated langen so many
5:00:07functionality came and people are moving
5:00:09to that okay so instead of relying on
5:00:11old langchen maybe you can use that one
5:00:13okay so each and everything I'm going to
5:00:14clarify now I think guys uh the project
5:00:17introduction part is clear what to do
5:00:19now let me show you the architecture
5:00:22how we'll be building this kinds of
5:00:23system so guys uh this is the
5:00:25architecture I think uh you can see um
5:00:28let me show you the architecture yeah so
5:00:30this is the architecture so in this
5:00:31architecture guys as you can see uh here
5:00:34we'll be implementing multiple agents.
5:00:36So that means let's say this is the
5:00:37first agent uh we'll be developing and
5:00:40here we'll be passing given research
5:00:43topic. Let's say if I want to do a
5:00:44research I will give the research topic.
5:00:46So it will go to the first agent. Okay.
5:00:49Uh so this agent will have uh some kinds
5:00:52of tool access. So here I'm going to
5:00:54give tably API that means tably search
5:00:57tool access to this agent. So whatever
5:01:00research you are giving to this agent.
5:01:01So what it will do? It will use this
5:01:03tably API and it will uh uh do the
5:01:06realtime search operation over the
5:01:08internet and it will get the relevant
5:01:10sources. Okay. It will get the relevant
5:01:12website for that particular topic uh to
5:01:14this agent. Okay. Now what I will do
5:01:17here this particular response I'm going
5:01:19to save in a state memory. Okay. So here
5:01:21I will try to create a state memory. So
5:01:23state memory will try to save this
5:01:24particular response so that and your
5:01:27next agent can refer this particular
5:01:29response. Okay, your second agent can
5:01:32refer this kinds of response. Okay, so
5:01:34that's why we are using the shared
5:01:36memory concept. You can also improve
5:01:37this particular memory uh by utilizing
5:01:40some other technique. So this part I'm
5:01:41going to also discuss in my future
5:01:44lecture. So I think you you saw my
5:01:46entire plan there. I told you we'll be
5:01:49um I mean discussing this particular
5:01:50memory part in detail but as of now just
5:01:52try to consider we are using a state
5:01:54memory uh you can also replace the state
5:01:56memory with any other let's say uh other
5:02:00um um like memory database you can use
5:02:02that okay it's completely up to you but
5:02:04here I'm going to use a state memory um
5:02:07in Python okay I'll show you how we can
5:02:09implement that so now we'll be creating
5:02:11a second agent guys so this uh second
5:02:14agent name is reader agent so this
5:02:16reader reader agent will also have some
5:02:18kinds of tool access. So here I'm going
5:02:20to use a beautiful soup uh scrapper
5:02:22tool. So what this beautiful soup
5:02:24scrapper tool will do basically whatever
5:02:27URL you are getting from the first agent
5:02:29okay given topic. So this will take all
5:02:32of the URL and with the help of
5:02:34beautiful soup it will extract the
5:02:36content from the URL. I think you know
5:02:38with a beautiful soup we can perform the
5:02:40web scrapping. We can scrap the content
5:02:42from any kinds of given website right.
5:02:44So that's why the first agent is
5:02:46returning the web URL web uh sources and
5:02:49with the help of second agent we are
5:02:52extracting the content from the URL with
5:02:55help of beautiful soup. Then what we
5:02:58will do guys we'll try to pass this
5:02:59content to another state uh let's say
5:03:02memory uh called let's say scrapped
5:03:04content. Okay maybe I can create another
5:03:07uh another actually let's say object
5:03:09here called scrap content inside that I
5:03:10can save those informations. Okay. Now
5:03:13here we'll be creating um another two
5:03:16actually agent. You can also call it as
5:03:18chain inside modern langen. Instead of
5:03:20creating this kinds of like u agent in
5:03:23lang what you can do you can create a
5:03:25chain because at the end you got your
5:03:28final uh you got your final important
5:03:31content. Okay. If you got the final
5:03:32important content now it would be easy
5:03:34for you to generate that particular
5:03:37report and it would be easy for you to
5:03:40review that particular report. Okay. But
5:03:42the main thing is in that section. So
5:03:45basically here we are performing the
5:03:46real-time source operation on a
5:03:48different topic. After getting that
5:03:49we're extracting the content. Then if we
5:03:52have the final content guys we'll be uh
5:03:54creating a writer chain. Okay. In lang
5:03:56chain we we call it as a chain. Okay you
5:03:58can also consider it's a agent. Okay
5:04:01it's agent. It's a writer agent. So what
5:04:02this writer chain will do it will take
5:04:04that particular content. Okay your
5:04:06beautiful extracted and it will write a
5:04:09draft. Okay, it will write a draft
5:04:11report on top that on top of that
5:04:12particular
5:04:14um content. Okay, because at the end it
5:04:17has also connection with the LLM. Okay,
5:04:19it has also connection with LLM. It is
5:04:21also having connection with LLM. Okay,
5:04:23so with the help of LLM with the help of
5:04:24this uh content you got it will prepare
5:04:28a draft. So once it has prepared a draft
5:04:30what it will do guys, it will send this
5:04:33draft to the critic chain. Now what this
5:04:35critic chain will do it will try to
5:04:37review this particular draft whether is
5:04:39there any mistake or not is there any uh
5:04:41let's say improvement section or not it
5:04:43will try to review that once the review
5:04:45is complete okay once the feedback is
5:04:47complete then it will show you the final
5:04:49output okay it will show you the final
5:04:51output so you'll be able to see the
5:04:52final output even you will also see the
5:04:54feedback the ratings okay and everything
5:04:57you will be able to see from this critic
5:04:58chain that means the critic agent okay
5:05:00because it is also having a connection
5:05:02with the large language model all Right.
5:05:04So yeah, this is the entire uh actually
5:05:06architecture of this particular
5:05:07multi-agent system. So this is going to
5:05:10very interesting project guys. So make
5:05:12sure you watch till the end. So I think
5:05:13each and everything would be clear in
5:05:15your mind. Okay. Now uh here is the step
5:05:18guys we'll be following to develop the
5:05:20entire agent. So first of all at the
5:05:22first step guys we'll be setting up the
5:05:23environment. Then second step we'll be
5:05:26creating the tools. Okay. All of the
5:05:27tools we'll be creating one by one. Then
5:05:29third step we'll be creating all of the
5:05:31agents one by one. Then fourth step will
5:05:33be creating a pipeline. That means uh uh
5:05:36uh why pipeline is required? Let's say
5:05:38after creating end tools you have to
5:05:40combine them. Okay, you have to uh you
5:05:42have to add them together to work right.
5:05:45So we we can do it in the pipeline
5:05:47section. So once our pip entire agent
5:05:49pipeline is ready then we can run and
5:05:51test our agent. Okay. So this is the
5:05:52entire step we'll be following for
5:05:54developing this kinds of system. So
5:05:56guys, now I'm going to give you the idea
5:05:58why uh we have to create uh mostly
5:06:02multi- aents AI uh AI application. Uh
5:06:06what is the problem with the single
5:06:08agent? So I think you know that uh this
5:06:10is like very um I mean easy things you
5:06:13can understand. Let's say um let's say
5:06:16if there is a company okay if there is a
5:06:19company
5:06:21um let's say company uh what they does
5:06:25let's say they takes a project okay they
5:06:28takes a project
5:06:32okay after taking this project so what
5:06:34they do they just try to assign this
5:06:37project to a team right team of employee
5:06:43team of employee. So in this team uh
5:06:46what we have we have multiple employee
5:06:48let's employee one employee two
5:06:52employee three and so on. Okay. So what
5:06:56they do actually just just try to assign
5:06:59this kinds of project as a task to the
5:07:02team and definitely in the team itself
5:07:05they will try to divide the task to
5:07:07different different employee. Let's say
5:07:09here are some of uh let's say employee
5:07:11one is very good at with the front- end
5:07:14development.
5:07:16Okay, front end development. Employee 2
5:07:19is like really good with let's say AI
5:07:21development. Okay, and employee three is
5:07:26good at with backend development.
5:07:29Okay, backend development. So what they
5:07:31will do? So the project they are having
5:07:34uh so for the for the front- end
5:07:37development for this project they will
5:07:39assign the task to the employee one for
5:07:41API development uh uh sorry AI
5:07:44development for this project they will
5:07:46assign the task to employee employee two
5:07:48okay and for backend development for
5:07:51this project they will assign the task
5:07:53to the employee three okay that means
5:07:56all of the project will have these are
5:07:58the things are common right and it's not
5:08:01like that there would be a single guy
5:08:04okay single guy he can let's say handle
5:08:08each and everything I can't say he
5:08:10cannot handle he can handle definitely
5:08:13let's say if I'm hiring a full stack
5:08:15developer so definitely he will be able
5:08:17to handle this kinds of scenario he will
5:08:20be able to let's say implement the
5:08:22entire project but what would be the
5:08:24problem okay because if you see most of
5:08:26the fully stack engineer so they will
5:08:29have actually limited knowledge uh on
5:08:32this uh on this actually let's say
5:08:34individual topic. So for the end to end
5:08:38development whatever things they need to
5:08:40know they definitely will do that for
5:08:42you. But when it comes to the deep
5:08:45research, let's say I want to create
5:08:47some AI features uh for this project and
5:08:50uh I I need a deep research. Okay, I
5:08:53need a very um very good uh let's say
5:08:57good uh sources. Then after getting the
5:08:59good sources, I have to refer that
5:09:02sources and I have to build the AI
5:09:03features. Okay. So if we are only
5:09:06depending on this single let's say
5:09:08employee so he wouldn't be able to do
5:09:11that because he doesn't have actually
5:09:14that much of depth knowledge on this AI
5:09:16development okay he can only let's say
5:09:19uh use some of the framework library and
5:09:21he can implement that project for you
5:09:23but when it comes to deep deep let's say
5:09:25research let's say deep experiment he
5:09:27won't be able to do that that means with
5:09:29the help of single guy I can't perform
5:09:32actually multiple task task can be
5:09:34performed But the output the quality of
5:09:36output we'll be expecting this should
5:09:39not be good. Okay. This should not be
5:09:40good. This should be uh this should be
5:09:42kind of average output. But whenever we
5:09:46are having this kinds of project
5:09:47definitely will expect like very good
5:09:50quality output from my team. Right? And
5:09:52if we are uh if we are let's say
5:09:54assigning this kinds of task to the
5:09:56single employee so definitely single
5:09:58employee won't be able to give the
5:09:59quality output to me. So that's why
5:10:02every company having a team and in that
5:10:04particular team they they are hiring
5:10:07okay different individual those who are
5:10:10let's say expert expert in different
5:10:12different field let's say someone is
5:10:13expert in front end someone expert in AI
5:10:15development someone is expert in uh back
5:10:17end development okay and whatever
5:10:20project they are getting they're uh
5:10:21dividing their task to them so let's say
5:10:23employee one has completed front end
5:10:25employee two has completed AI
5:10:26development employee three has completed
5:10:28the backend development now they will
5:10:30combine they combine everything and they
5:10:32will prepare the project for you. Now
5:10:34when it comes for research let's say
5:10:35having a deep research on individual
5:10:38let's say topic so easily these kinds of
5:10:41employee can perform because he's only
5:10:43expert in front end he knows about the
5:10:45front end and if you give time okay if
5:10:48you give time if you tell this uh let's
5:10:50say employee just try to research and
5:10:52add some more front end feature with
5:10:54latest like framework he will be able to
5:10:56do that okay because he don't need to
5:10:58worry about the I development and back
5:11:00end development he will only focus on
5:11:01the front end development so that's
5:11:03[snorts] for AI developer guy also I can
5:11:05tell just try to explore more and add
5:11:07some other AI features as well. So
5:11:09definitely he will be able to do that
5:11:10because he doesn't uh need to worry
5:11:12about the front end and back end. Okay
5:11:14then employee 3 I'll tell just try to
5:11:17research more about the back end let's
5:11:18say I don't want to use uh flask you
5:11:20just need to use fast API just try to
5:11:22explore fast API you'll be able to do
5:11:24that okay so that's how individual
5:11:26person is working on individual task and
5:11:28the output we are getting from here this
5:11:31is like very good quality output okay
5:11:33good quality output we'll be getting
5:11:37okay that's how whenever we are creating
5:11:40kinds of agent application instead of
5:11:42creating a single agent Okay, instead of
5:11:44creating this kinds of single agent
5:11:46because in single agent if I want to
5:11:48perform all of this task okay if I want
5:11:50to perform all of these tasks so
5:11:51definitely the output should be very
5:11:53poor and if I'm using multiple agent
5:11:55okay the architecture I showed you I
5:11:57think so this is the architecture
5:12:00if I'm using multiple agent so here I'm
5:12:03assigning a uh different different task
5:12:06let's say first agent I have assigned
5:12:07your task is to only fetch the real-time
5:12:10data from the internet and give the uh
5:12:12collect the URL. Okay. Then you will try
5:12:14to save the state memory. Then second
5:12:16agent I have given another task. Your
5:12:18task is to take those URL and extract
5:12:20the content from that. Okay. So after
5:12:23extracting content agent save to the
5:12:24state memory. Then third agent I told uh
5:12:28um I mean let's say this agent just try
5:12:31to take those content and write a report
5:12:33on this particular resource. Okay. Your
5:12:36task is uh your only task is to generate
5:12:38the report. So it will try to generate
5:12:40the report. Then the uh fourth agent I
5:12:44told this agent you just need to take
5:12:46this uh draft and try to review that
5:12:49whether it is good or bad or it still it
5:12:52needs some feedback just try to read
5:12:53rate read this okay so this particular
5:12:56agent only uh is responsible for rating
5:12:59this okay or critique this particular
5:13:01task so once everything is done then we
5:13:03are getting the final output and this
5:13:05final output would be very good quality
5:13:07but if I am performing the same task
5:13:09with a single agent so definitely
5:13:10Definely the output would be very bad
5:13:12quality. Okay. So that's why this multi-
5:13:14aent things are required. Okay. That's
5:13:16why you are uh will be developing multi-
5:13:18aent system most of the time and all of
5:13:20the application you can see. Okay.
5:13:22Whatever application like cloud desktop
5:13:24or you are using VS code anti-gravity
5:13:27any anything you'll see that they're
5:13:29using multiple agents in the back end.
5:13:31They're running multiple agents. Okay.
5:13:33They're adding let's say 100 and 100
5:13:36like agents in their back end and
5:13:38they're performing one kinds of task.
5:13:40Okay. So yes, that's how guys uh we will
5:13:43be following this multiple agent
5:13:45development. And one more thing whenever
5:13:46you are creating multiple agents, so
5:13:48make sure all of the agents will have
5:13:50kinds of tool access. Okay, if it is
5:13:52required, definitely we'll give the tool
5:13:54access and all of the agents will have a
5:13:56large language model for the reasoning
5:13:57operation. Okay, I think everything is
5:14:00clear. Now we'll move on the uh
5:14:02development part, guys.
5:14:06So first of all I'm going to create a
5:14:08GitHub repo for this multi- aent. So
5:14:10let's try to create a GitHub repo. So
5:14:13here I'm going to give a name.
5:14:16Let's say
5:14:22I'll give a name here
5:14:26langen
5:14:31multi-
5:14:36multi- aent
5:14:43research
5:14:48research.
5:14:50Okay, research system.
5:14:55Uh I will make it as public repo and I
5:14:57will add the readmi file. I'll also add
5:15:00the g ignore. So here we'll be coding
5:15:02with python. So I'll select the python.
5:15:04After that you can select a license. So
5:15:06let's take this u maybe apache license.
5:15:10Okay. You can take any of the license.
5:15:11It's up to you. On it once it is done
5:15:13now let's try to create the repo.
5:15:18Okay. So repo is created. Now we have to
5:15:21clone this repo inside our local folder.
5:15:24I'll click on this code. Copy this link
5:15:26address. I'll open up my local folder.
5:15:28And here I will just try to open my
5:15:31terminal.
5:15:37Now let's clone it. So get clone
5:15:41paste this link.
5:15:45Okay. So this directory is already exist
5:15:47because previously I already created
5:15:51uh so what I can do maybe I can rename
5:15:53it.
5:15:58Okay I can rename it.
5:16:06Okay. Now just try to open your terminal
5:16:08in this directory and just write get
5:16:10clone
5:16:14and paste that URL. Okay, you have
5:16:17copied. Now if I hit enter, so you'll
5:16:19see my repo has been cloned. I will go
5:16:22inside that and I will also redirect my
5:16:24terminal inside this uh directory. So
5:16:27for this let's write cd command cd
5:16:30langin
5:16:32multi- aent
5:16:34research.
5:16:37Okay research system now I'm inside this
5:16:39particular folder. Now here I'm going to
5:16:42open up my quisel code studio
5:16:48visual code studio.
5:16:52Uh fine. Okay. Now the first thing guys
5:16:56uh I told you so let me show you the
5:16:58steps we'll be following.
5:17:01Yeah. So this is my actually um
5:17:06this is my actually note note file. So
5:17:08in this particular file you will be
5:17:10getting all the nodes and architecture
5:17:12steps everything. So this is excali uh
5:17:15like extension file. If you want to open
5:17:17it up so you have to install one
5:17:18extension from extension market called
5:17:21excali. So if you can search here Xcali
5:17:27Xcali drop okay so this particular
5:17:30extension you have to install if you
5:17:31install that you will be able to open
5:17:33this okay in your VS code itself
5:17:35uh fine so now if I show you my step
5:17:39um if I show you my step so the first
5:17:42step what I have to do uh I have to do
5:17:46the environment setup okay let's try to
5:17:48do the environment setup so for
5:17:50environment setup here I'm going to
5:17:51write all of these this step
5:17:56here let's say
5:17:58the first step you have to create the
5:18:00environment so to create the environment
5:18:02you can
5:18:03use the same command I think you used
5:18:05for the previous project
5:18:08on create-en n you can give the name
5:18:11let's say lang agent
5:18:15then you can specify the python python
5:18:18is equal to you can take 3.11
5:18:22and y okay you are giving this
5:18:24permission after that you have to
5:18:26activate that then you have to install
5:18:27the requirements okay so just try to
5:18:30create the environment so for me I think
5:18:32I already have the environment uh so I'm
5:18:35going to just activate the copy
5:18:39and activate the environment
5:18:42so see this lang engine is already um
5:18:45installed for me okay but if you don't
5:18:47have just try to create the environment
5:18:49then try to activate then after that
5:18:51Let's install the requirement.
5:18:53So here I'm going to add the
5:18:54requirement.txt and inside that I'm
5:18:57going to mention all of the requirement
5:18:58package I need.
5:19:01Um
5:19:03yeah so these are my requirement guys.
5:19:08Okay so these are my requirement uh I
5:19:10need for this particular project. So you
5:19:12can see we're installing langen. Um so I
5:19:15think you remember in previous project
5:19:17we use uh we installed actually langen
5:19:19old version. So let me show you it was
5:19:210.1 something I think. So this is the
5:19:24like uh first agent repository that
5:19:27means our single AI agent repository. So
5:19:28if I go to the requirement.txt as you
5:19:30can see we have installed langen 0.1
5:19:33here. Okay but here we're installing
5:19:35langen 0.2 that means this is the modern
5:19:38langen the latest one. So here actually
5:19:41lcl that means langen expression
5:19:43language is supported but here this is
5:19:44this was not supported. Okay. So, both I
5:19:47have showed you uh but try to use the
5:19:49latest one if you want. Okay. Uh latest
5:19:51one is always good. Uh because older one
5:19:54uh people are uh not using anymore. So
5:19:57they are trying to u moving to the new
5:19:59one. It doesn't mean older one cannot be
5:20:02used. Still you can use old one. Okay.
5:20:03There are some good functionality you
5:20:05can use. But yeah uh whenever we have
5:20:07the latest one so why not we can utilize
5:20:09this this one. Okay. Then we are
5:20:12installing this langen core community
5:20:13openi lang openai. So you can use any
5:20:16other LM provider as well. It's
5:20:18completely fine. Simply you just need to
5:20:19go to the RGP and tell let's say you
5:20:21want to use open router or Gemini. So
5:20:24you'll be able to see that they will
5:20:25suggest you the code. Okay. You can
5:20:26replace that code here. Okay. Then
5:20:28streaml I need for creating the user
5:20:30interface. Then tavly for this search
5:20:33tool. And I told you we'll be creating
5:20:35another tool which is a beautiful soup
5:20:38extracting. So here we'll install this
5:20:40beautiful to soup. And for beautiful
5:20:42soup we need these are the dependency
5:20:44package as well. Okay. Then python do uh
5:20:46env for the environment management. So
5:20:48these are the package we have to
5:20:49install. So how to install? Let's copy
5:20:51the command. So here's the command. I
5:20:53will copy this and run in my terminal.
5:20:58So for me it is already satisfied but
5:21:00for you it may take some time. Okay.
5:21:02Once it is done now we can create the
5:21:04folder structure right now. So here what
5:21:07I'm going to do I'm going to first of
5:21:08all create a folder here. I'm going to
5:21:11name it as src
5:21:13and inside that I'm going to create a
5:21:15constructor file
5:21:18init_py
5:21:24and uh inside that I'm going to create
5:21:26another folder
5:21:28uh I'm going to name it as
5:21:32tools.
5:21:35I'm going to create another folder
5:21:37called agents.
5:21:42Okay, then I need another folder
5:21:49called pipeline.
5:21:55Okay. Yeah. So once it is done then here
5:21:59I'm going to create an endpoint which
5:22:00should be my app.py.
5:22:08Okay. And I need av file
5:22:13for environment management.
5:22:16So yeah, so this is my folder structure.
5:22:18Uh
5:22:20but uh right now I'm going to create
5:22:21some of the file inside these are the
5:22:23folder. Like first of all I have to
5:22:26create a constructor file.
5:22:33So this is called modular coding. We're
5:22:35uh creating as a module each and every
5:22:37separate module. Inside that we'll be
5:22:40creating a file called agent.py.
5:22:46Then pipeline also I'm going to create a
5:22:48constructor
5:22:50init_.py
5:22:57and I'll be creating a file called
5:22:59pipeline.py.
5:23:07So for tools also we'll be doing the
5:23:09same thing.
5:23:28Okay, everything is done. Now let me
5:23:31check. Let me verify everything is fine
5:23:33or not. Uh yeah, I think everything is
5:23:35fine. So now if I show you my step
5:23:37again, uh we have prepared all of the
5:23:40folders. Okay. Like for tools, we have
5:23:43created a separate tools folder inside
5:23:45src. So inside that we'll be writing all
5:23:48of the tools in the tools.py. For agent
5:23:51also we have done the same thing agent
5:23:52and inside agents we'll be writing all
5:23:54of the agents. For pipeline we have done
5:23:56the same thing. For pipelines we'll be
5:23:57writing the pipelines. Okay. and run and
5:23:59test. We'll be using this endpoint which
5:24:01is app.py. Okay, so everything is fine.
5:24:04Um uh okay, one more thing I can do for
5:24:07running uh and testing the agent. First
5:24:09of all, let's say we'll try to test in
5:24:11the main.py. Then once uh everything is
5:24:13working fine, we can convert we can add
5:24:15the user interface to the app.py. Okay.
5:24:17Yeah. So now it's ready. Now let me
5:24:19commit the changes to my GitHub. So
5:24:21simply what I will do
5:24:24uh I'll try to
5:24:27uh commit the changes.
5:24:30So get add space dot
5:24:33get commit
5:24:36m
5:24:38um
5:24:41agent setup
5:24:43and folder structure
5:24:50created
5:24:54and get push
5:24:57origin
5:25:04done. Now if I go to my GitHub
5:25:07refresh,
5:25:09see my border structure is ready. Okay.
5:25:13Now first thing let's try to work on
5:25:15this.
5:25:17Um
5:25:19I'll open up my state. Yeah. So
5:25:21environment setup and folder creation is
5:25:23done. Now uh here what I can do maybe I
5:25:25can write another things
5:25:29folder structure.
5:25:33Okay folder struct structure.
5:25:37Yeah.
5:25:41Now first of all we'll be uh creating
5:25:43the tools. Okay let's try to create the
5:25:45tools. Uh so here I'll close all of this
5:25:53file.
5:26:00But before creating the tools uh first
5:26:01of all I have to collect uh this uh uh
5:26:06secret credential. I need my openi API
5:26:08key and I need table API key. Okay I
5:26:11already showed you in my previous
5:26:12implementation how to collect them. So I
5:26:15already collected let me show you. So
5:26:17this is my open API key and this is my
5:26:19table API key. So for openi what you
5:26:22have to do you have to visit openi API
5:26:24platform. So there simply just try to
5:26:27login with the API platform.
5:26:30Once you have logged in just try to see
5:26:33the API keys option
5:26:39and create the new access uh secret key.
5:26:42Okay. So for me I have already created.
5:26:44Now for tabuli
5:26:46you can visit tab API key tab.com
5:26:49and see here if you don't want to use
5:26:51open AI you can use Google Gemini API or
5:26:54open router or gro API key anything you
5:26:57can use. Okay only you just need to
5:26:59change that model uh initialization
5:27:01simply you can go to the chat GPT and
5:27:03you can replace that okay very easy but
5:27:05I have my openi account with me that's
5:27:07why I'm going to use openi because I am
5:27:08expecting good output from my agent.
5:27:10Okay, that's why uh because in free API
5:27:12there is some limitation. Um so after c
5:27:15certain time actually uh this limit
5:27:17would be offered. So that's why we are
5:27:18using open air here. Now table also you
5:27:21have to do the same thing. Uh here is a
5:27:24API creation option. You can uh click
5:27:26here you can create a new key. Okay for
5:27:28me I already create the key. So this is
5:27:30available. Okay. Now environment is
5:27:32ready. Now simply let's try to create
5:27:35the agent.
5:27:37Uh what I'm going to do I'm going to
5:27:39open this sorry not agent I'm going to
5:27:42create a tool. So I'm going to open this
5:27:44tools. Okay tools folder uh tools.py.
5:27:47Okay I'm going to open it. So the very
5:27:50first tools guys I have to create I
5:27:51think you remember which is uh this web
5:27:53search tool which is this web search
5:27:56tool. If I show you my diagram web
5:27:58search tool which is tab API. Okay. And
5:28:01we'll try to connect with our first
5:28:02agent. So let's try to create this table
5:28:04search uh table search tool. So for this
5:28:07let's import some library. First of all
5:28:09I'm going to select my environment.
5:28:12[clears throat] So I'm going to import
5:28:14let's say
5:28:16langen
5:28:17dot tools
5:28:21import
5:28:23tool.
5:28:25Okay.
5:28:27Then I'm going to import request.
5:28:32I'm going to import
5:28:35um I'm going to import this uh env. So
5:28:39from env
5:28:41import load env.
5:28:45Then
5:28:47I need the operating system.
5:28:51Okay, it should be import.
5:28:57And one more thing I need to import the
5:28:59table. So from
5:29:01tably
5:29:03import
5:29:06tably client.
5:29:10Yeah, you can also import tably from
5:29:12langen uh because langen inside tools it
5:29:15is tably tools is available. You can
5:29:17import either you can import from tably
5:29:21framework itself and you can create as
5:29:24your custom tool. So in my previous
5:29:26example taby I initialized from langium
5:29:29u I didn't create it as a custom tool
5:29:32but in this implementation I'm going to
5:29:33show you how we can uh create tab as
5:29:36your custom tool okay this is also
5:29:37possible uh both you see and whatever
5:29:40you like you can prefer that because in
5:29:42my requirement I already installed this
5:29:43tably python okay that's why we'll be
5:29:45able to do that so simply first of all
5:29:48load your environment variable and after
5:29:51that let's create a tably object so
5:29:54tably key
5:29:55is equal to so tably client
5:30:02here you have to pass the API key of the
5:30:04tably so I'm going to get from my
5:30:07involvement variable so west get env
5:30:09table tably API key and inside this enb
5:30:11I've already mentioned my table apak
5:30:13okay it will try to load from here so
5:30:15once I got it now I'll create a function
5:30:17here so this function will try to
5:30:19perform the web service operation with
5:30:21help of tably so maybe I can name this
5:30:23function function as web search. Okay,
5:30:26web search
5:30:33web search. So this will take a query
5:30:39or I have already created let me show
5:30:41you.
5:30:44Yeah. So this is the function guys as
5:30:47you can see. So websites this is the
5:30:49function. This takes the query and what
5:30:52[clears throat] it does it uh use tab
5:30:55and it searchs that particular query
5:30:56over the internet and max result is
5:30:58equal to five that means it will give
5:30:59you five sources okay five relevant uh
5:31:02sources uh URL from the internet and
5:31:06what we are doing
5:31:08uh let me show you what we are doing
5:31:09here let's say once we are getting all
5:31:12of the five
5:31:15uh five responses so let me just print
5:31:17them one by
5:31:21print result all of the results.
5:31:25Now let's call this function
5:31:31or we can also test inside our endpoint
5:31:33which is main.py. Let's import from src
5:31:38dot tools
5:31:42dot tool import web then
5:31:48websource
5:31:51let's say what is the capital of French
5:31:53okay I have given this one or let's say
5:31:58latest
5:32:02news on a research now if I execute
5:32:07python
5:32:09main.py.
5:32:14Now see it is giving you five response.
5:32:20Okay, five response. But this print
5:32:23statement is not clear enough. So if you
5:32:25want to make it clear enough, so what
5:32:27you can do guys, you can install one
5:32:28tool which is
5:32:32rich. Let me add inside my environment
5:32:35reach. Okay, so reach helps us to uh
5:32:39actually um see the good print statement
5:32:41and you can also use it for the login
5:32:43debugging. So let me install the rich as
5:32:46well
5:32:54clear. I'll install my
5:33:00requirements once it is done. Now let's
5:33:02try to import the rich
5:33:07in the tools. I'm going to import from
5:33:10rich.
5:33:13Okay. Import print. Now instead of this
5:33:15print I'm going to use my rich print.
5:33:18Okay. Now if I execute this will give
5:33:21you beautiful output.
5:33:26Now see this is uh clean right? This is
5:33:29understandable.
5:33:32Yeah. So you can see we are getting this
5:33:33response from tably API. So Tableau API
5:33:36what is it doing? It is going to
5:33:37internet and it is searching
5:33:41it is searching over uh different
5:33:43different website. Okay. So this is the
5:33:46first website reddit.com. So if I open
5:33:48it up so here it has already discussed
5:33:51about this uh uh latest AI research
5:33:55news. Then again you can see there is
5:33:58another website called artificial
5:34:00intelligencenews.com.
5:34:02Okay. So this is another news. So that's
5:34:04how you have see uh that's how you can
5:34:06see 1 2
5:34:08uh 3 4 5. Okay. Total five uh response
5:34:12we are getting here. Okay. Five uh URL
5:34:14we are getting here from different
5:34:16different website. Okay. Now what I can
5:34:19do see I don't need all of the
5:34:21informations because here I only need
5:34:23this result. Okay. In the result I have
5:34:25the URL. I have the title of that
5:34:28particular let's say information and I
5:34:31have a content. So in that content
5:34:33actually some uh like uh one to two
5:34:36lines headlines are there about the
5:34:38content. Okay. So if I'm able to get
5:34:40these are the three things I think this
5:34:42is more than enough uh for my agents
5:34:44because if I show you my agent
5:34:47if I show you my agent here. So let's
5:34:49say first agent what it will do it will
5:34:51uh use tab API uh for real time data
5:34:56data feting operation from different
5:34:58different website and we have to take
5:35:00there
5:35:02these are the information URL title and
5:35:04content. So this URL title and content
5:35:06will try to save in the state result and
5:35:08my second result will try to uh take
5:35:11that and from the URL itself okay from
5:35:13this URL itself it will try to extract
5:35:16it will try to extract the content
5:35:18because this is a web okay this is HTML
5:35:21web so now what it can do uh it can
5:35:23actually so extract the content and how
5:35:26it extract I think you know if I perform
5:35:27the inspect operation so there is a
5:35:31option let's say if I want to
5:35:34extract ract any text easily I can do
5:35:37that let's say I can show you let's say
5:35:40I want to extract this this particular
5:35:41part if I click here so this is the
5:35:43content of that okay I can easily
5:35:45extract the content and this operation
5:35:47we perform with alpha beautiful soap
5:35:49okay so I'll try to do that as well so
5:35:52here let me show you
5:35:54I'll open it up
5:35:57h now instead of taking all of the
5:35:59content so what I'll do I'll just try to
5:36:03Okay,
5:36:06these are the information.
5:36:09Okay, these are the information like I
5:36:11need title, I need URL and I need
5:36:14content. Okay, content I need and
5:36:16content I'm only taking 300 word just to
5:36:19make my uh let's say agent understand.
5:36:21Okay, so this is the content related
5:36:23that and it is available inside this
5:36:25URL. You have to extract that. Okay, now
5:36:27if I uh see after doing it I'm just
5:36:30running a for loop because this result
5:36:32will have a result keyword. Okay, we are
5:36:35going inside that because this is a JSON
5:36:37response. We are taking this key and
5:36:38inside that we have title um URL title
5:36:41and content. So inside that we are
5:36:44extracting title, URL and content and we
5:36:47are appending to this particular empty
5:36:49list one by one. That means the five uh
5:36:51five output should be there. Five uh
5:36:53five links response should be there
5:36:55inside that. Okay, because I'm getting
5:36:56five response. Now let me show you. So
5:36:59if I print this
5:37:03uh if I first of all I'll return it.
5:37:08I'll return it. So basically I'm
5:37:10performing the joining operation. uh so
5:37:12what the join will do it will try to
5:37:14join as a string okay so every time it
5:37:16will give a new line and it will join
5:37:18all of the content now let me show you
5:37:21how this thing will look like so maybe
5:37:23now I'll try to receive it here let's
5:37:25say
5:37:27output
5:37:32and print the output
5:37:35now if I execute my
5:37:38file
5:37:45See I'm getting five output the title
5:37:48and this is the URL of that content and
5:37:51this is a like uh short paragraph of
5:37:54that particular news. So if I go to the
5:37:56reddit.com you'll see that an AWS user
5:37:59started. Okay. So this thing is
5:38:01available.
5:38:07Yeah. Sorry from here. An entropic drops
5:38:10a uh drops a new research paper today.
5:38:13Okay. So, entropic uh drops a new
5:38:15research paper today. So, that's how it
5:38:17is taking 300 word from the entire
5:38:19content. Okay. Entire content. Now, this
5:38:22is the second one. This is the third
5:38:23one. This is the fourth one. This is the
5:38:25fifth one. That means we are getting
5:38:26fifth uh response from our tab tool.
5:38:29Okay. Which is amazing. Now, what I will
5:38:32do guys? Um my first tool is ready.
5:38:37My first tool is ready. That means this
5:38:39particular tools is ready. Okay. Now I
5:38:42have to work on this tool which is
5:38:43beautiful soup scrapper tool. Now let's
5:38:46try to also work on that. So for this I
5:38:49again need to import some other library
5:38:51like I need to import
5:38:53uh
5:38:55beautiful soup. So from
5:38:59BS4
5:39:02I import beautiful soup. Then I have to
5:39:04import from
5:39:08readability
5:39:10import documents. Then I have to import
5:39:22chart. Okay. Uh trafil uh tora. Okay.
5:39:26This is uh this thing I need uh with
5:39:28beautiful soup. Um uh that's why this is
5:39:31a dependency package. And I also need
5:39:33regular expression
5:39:36import.
5:39:38So if you have ever performed web
5:39:40scrapping I think you know these are the
5:39:41libraries useful
5:39:43H.
5:39:45So what I've done guys I have already
5:39:46generated a function with chart GPT.
5:39:56Let me show you the function.
5:40:00Yeah. So this is the function I have
5:40:02generated from chat GPT. Uh so basically
5:40:05if it takes a URL okay it takes a URL
5:40:08and what it does uh it uh ex scrap
5:40:12actually all of the content from the
5:40:13URL. Okay it perform the scrapping. So
5:40:16here you can see uh we are using request
5:40:19package. We are hitting the URL. After
5:40:21that we are getting the JSON uh HTML
5:40:23response and we are extracting the
5:40:25content. Okay. So everything is
5:40:27performing with help of beautiful soup.
5:40:29And once we got the content, we are
5:40:30returning the cleanup. And if exception
5:40:32is occurring, we're raising the
5:40:33exception. Okay, that's why exception
5:40:35handle is also important. If you're
5:40:36using any third party services,
5:40:38definitely you can use try accept block.
5:40:40Okay, this is required. So yes guys, uh
5:40:42this is the scrapper function we have
5:40:45created. You can also test it whether
5:40:46it's working or not. So maybe let's say
5:40:48here what I will do, I'll try to import
5:40:50it as well to scrap URL.
5:40:54Uh so this returns, right? This is
5:40:56returns
5:40:59H. This returns okay
5:41:04return. So what I can do I can
5:41:11I can show you let's say
5:41:14results.
5:41:17So this takes a URL. Okay. So maybe I
5:41:20can provide a URL.
5:41:23Let's say
5:41:26I'll copy this URL.
5:41:33Copy this URL and
5:41:36I'll give inside there.
5:41:41Okay. Then I will print the result.
5:41:45Now see what happens
5:41:48here.
5:41:50Python main.py
5:42:00Still we are getting this title URL.
5:42:03Why?
5:42:06Oh, okay. We using websites. I have to
5:42:08use scrapper URL. Okay, scrap URL. This
5:42:11function. Sorry, my mistake. Now, let's
5:42:13again execute.
5:42:19Okay. Now see from that HTML I'm getting
5:42:22the content. Okay. I'm getting the
5:42:24important content. Okay. So this
5:42:27function is doing that. So this function
5:42:29is going to that particular URL. Okay.
5:42:31This function is going to that
5:42:32particular URL and extracting all of the
5:42:35content. Okay. You can see extracting
5:42:37all of the content relevant content.
5:42:40Okay. And it is giving me here. Now this
5:42:42content I'll try to pass to my next
5:42:45agent here.
5:42:49next agent. So let's say my second aent
5:42:52uh second agent will try to extract uh
5:42:55this informations and it will save in
5:42:57the state memory. Now I can use my
5:42:59writer agents to use this particular
5:43:00content and prepare a draft for me.
5:43:02Okay. And my critic agent will try to
5:43:04review that. This is the work I think
5:43:06you are getting. So this is called
5:43:07actually uh team. Okay. This is called
5:43:10actually team and uh we are using
5:43:14uh we are using list of agents to
5:43:15performing for performing actually uh
5:43:18task okay multiple task we are
5:43:20performing with the of multiple agents
5:43:22one by one okay so this is the beauty of
5:43:26multi- aents instead of using the single
5:43:28agent now one more thing I want to show
5:43:30you see as of now I have created these
5:43:33are the tool as a function okay and now
5:43:37if I want to use it as a tool so what I
5:43:39have to I think you remember we have to
5:43:40give a decorator. Yesterday also we did
5:43:43the same thing. So we have already
5:43:44imported this tool from Langchen. So now
5:43:46I can give a decorator. So here just
5:43:48simply give the tool decorator.
5:43:51Whenever you are giving the tool
5:43:52decorator now you can invoke. Okay you
5:43:54can invoke this tool. Let me show you
5:43:59tool decorator. Now let's say right now
5:44:01what I'm doing uh here right now I just
5:44:04need to call this function and give the
5:44:07input like that. Right. Now we have
5:44:09converted as a tool. Now I can perform
5:44:10the invoke operation. So how to perform
5:44:12the invoke operation? Let me show you.
5:44:14So let's say this is my tool web search
5:44:16tool. Simply I'll do the invoke
5:44:18operation.
5:44:20Invoke operation.
5:44:23Now here is the question. Let's say I'll
5:44:25give what is the latest research on
5:44:28using AI for climate change migration.
5:44:31Now whatever response I'll get I'll try
5:44:33to save inside a variable. That's the
5:44:35result
5:44:37and I'm going to print it.
5:44:40Now let me show you. This will work as a
5:44:43tool.
5:44:48See now this is working as a tool. Okay.
5:44:50You can perform the invoke operation.
5:44:53All right. So similar guys you can also
5:44:54perform the invoke on the scrap URL.
5:44:57Okay. Both it will work with the help of
5:44:58invoke. So now guys our tool is ready.
5:45:02uh we have created
5:45:05uh all the tool like tabularly tool as
5:45:07well as the beautiful soap scrapper tool
5:45:10uh and it is already working. Now the
5:45:13next part we can work on the uh agents
5:45:17implementation. Okay. Now I'm going to
5:45:19show you how we can implement the
5:45:21agents. But before that let me commit
5:45:22the changes. I can also commit from my
5:45:24VS code. So here I can tell uh tools
5:45:30uh created for
5:45:34agent
5:45:35oh that's a tools created okay I'll
5:45:38commit and send the changes
5:45:43done now if I go back
5:45:46I'll close this other tab
5:45:57refresh.
5:45:59Now see tools added already. Okay. Fine.
5:46:03Now let's try to work on the next part
5:46:05which is agent implementation. Okay.
5:46:08We'll try to implement the agent.
5:46:13So guys uh to implement the agent I'm
5:46:15going to open this uh agent folder.
5:46:18Inside that I have agent.py. Let me open
5:46:20it up. Uh I can close these are the file
5:46:22as of now.
5:46:26So first of all here what I have to do
5:46:28guys I have to create my first agent
5:46:31which is uh search agent. Okay search
5:46:34agent. So basically this will have the
5:46:36connection with tab API. So let's try to
5:46:40create that. I'm going to import some
5:46:42necessary library.
5:46:45Um so these are the library I need.
5:46:49These are the library I need. So one
5:46:52more thing I think you can observe. Um
5:46:55right now I'm importing langen.agent
5:46:58import create agent. Okay. But
5:47:01previously I imported create react
5:47:04agent. Okay. There are some difference
5:47:07between them. Now see because previously
5:47:10I showed you I installed actually old
5:47:13version of the langen. So in old version
5:47:15langen they implemented create react
5:47:18agent that means uh reasoning and action
5:47:20agent. Okay but in the latest version in
5:47:24the updated version modern langen they
5:47:26have replaced with create agent. Okay
5:47:29this particular function. So for this I
5:47:33did a Google search. Let me show you the
5:47:34result. See I told is create agent and
5:47:37create react agent same in langen it's
5:47:40telling no uh they are not same um uh
5:47:44though they both serve similar purpose
5:47:47in recent langen updates create agent
5:47:49has become the standard streamline
5:47:52function while create react agent is
5:47:54older implementation. Okay. So what they
5:47:56have done they have updated the langen
5:47:58package and what they did they actually
5:48:02also worked on this create react agent
5:48:05they and they updated with this react
5:48:07agent sorry create agent right now
5:48:10because create agent is nothing but it's
5:48:12the updated version of create react
5:48:13agent and this is more stable more
5:48:15standard. Okay, that's why they're
5:48:17recommending don't use create react
5:48:18agent instead of use create agent only
5:48:20because this is more standard and stream
5:48:22light function. It's not
5:48:29it's not like that you can't use uh
5:48:31react agent you can use uh create react
5:48:34agent but um I think it's good to go
5:48:37with the updated one always. Okay. Now
5:48:40here are some um like difference between
5:48:42them. So you can see create react agent.
5:48:44This is the modern recommended method in
5:48:47core lang package. It creates an agent
5:48:49that execute a built-in loops of tools
5:48:52calling using highly flexible modern
5:48:54middleware system. And uh apart from
5:48:57that this create uh react agent is a
5:49:00older implementation b strictly on
5:49:02foundation react reasoning acting okay
5:49:04prompting uh paper. It was previously
5:49:08able uh available one older version of
5:49:10langen
5:49:12but has been deprecated in u um create
5:49:16agent. Okay, that means the latest one.
5:49:17Okay, so basically I think remember
5:49:20whenever we use this create react agent
5:49:22function we have to use another
5:49:24additional function which is agent
5:49:25executor and that has to perform three
5:49:27things. One is the thoughts then action
5:49:30then observation. I think I showed you
5:49:32the detailed discussion in my uh
5:49:34previous agent implementation. If you
5:49:36have missed out just try to check it
5:49:37out. So there we used to run three
5:49:39things thought action and observation.
5:49:42And uh for running this three step we
5:49:44used to use agent executor with this
5:49:46create react agent. But right now in
5:49:48create agent you don't need to use that
5:49:50separately. So they have integrated
5:49:52everything that means that thought
5:49:53action and observation all of the
5:49:55execution process in the loop they have
5:49:57inbuilt with this create react agent. So
5:49:59they will take care each and everything.
5:50:01You don't need to do these are the part.
5:50:03Okay. So that's why this is like more
5:50:04standard and optimized version of create
5:50:07uh create react agent. Okay. So that's
5:50:09why we'll be using this create agent
5:50:11right now. Okay. I hope it's clear guys.
5:50:13So that's why in my code you can see
5:50:14instead of importing this create react
5:50:16agent. Where's the code? Yeah react
5:50:19agent I'm importing create agent only.
5:50:21Okay. And all the code are same like
5:50:23openi chat openi. Then we are also
5:50:26importing the prompt template. If I want
5:50:27to give my custom prompt I can set my
5:50:29prompt with help of chat prompt
5:50:31template. Then output parser I need
5:50:33because I'm going to use the LCL lang
5:50:35lang expression language the
5:50:37[clears throat] modern langen uh let's
5:50:39say uh syntax. So that's why output
5:50:41parser is required and to understand
5:50:42this one definitely you have to go
5:50:44through my langen lecture guys there I
5:50:46have discussed each and everything what
5:50:47is lclput parser is required each and
5:50:50everything I have already explained then
5:50:51from tools we are importing
5:50:54uh this is not tools anymore so this
5:50:56thing I can import like that so in my
5:50:59main.py Pi I have already imported I
5:51:00will copy
5:51:02and I'll replace it here. Okay. So from
5:51:05src uh from src tools
5:51:09uh we have created web search tool and
5:51:11scrapper tool. Okay. Both we have
5:51:13created and we're importing and
5:51:15initializing the now the first thing we
5:51:17have to set up the model.
5:51:20Uh so lm is equal to
5:51:24chat openai.
5:51:26So I'm going to use this model.
5:51:29This model. So here I can comment model
5:51:36initialization.
5:51:39Okay. Model initialization. So we are
5:51:41using this GPT4 mini model. You can use
5:51:44any model GPT5 whatever you can use. And
5:51:46this is the creativity parameter I have
5:51:48given zero. So this will give you the
5:51:50LLM object. So right now I'm going to
5:51:52create my first agent which is this
5:51:54agent called search agent. Let's try to
5:51:57create it. Now see if you're using
5:51:59modern lang chain that means create
5:52:02create agent function. It's like super
5:52:04easy only you just need to create a
5:52:05function. I'm going to name it as let's
5:52:07say build
5:52:10search
5:52:12agent
5:52:18and simply you just need to return that
5:52:20okay return what return your create
5:52:23agent
5:52:25okay create agent and this will take
5:52:27actually some parameter the first
5:52:29parameter takes the model so model is
5:52:32equal to I'll pass my llm
5:52:34second parameter it takes tools. Okay,
5:52:37the tools you want to connect with this
5:52:38agent. So I want to connect this tool
5:52:41actually web search tool because my
5:52:43first agent will try to connect with my
5:52:45web search tool which is tab API. Okay,
5:52:47so what I'm going to do I'm going to
5:52:48call this web source and pass it here.
5:52:51Okay, and there is another thing you can
5:52:53perform I think which is system prompt.
5:52:54Okay, system prompt you can pass you can
5:52:57tell your agent what to do. But system
5:52:59prompt I think it is already given in
5:53:01default. Uh the same system prompt I
5:53:03think I showed you right uh yesterday.
5:53:05uh I u downloaded from langen hub. So
5:53:08basically it explains about the agent
5:53:10behavior. Okay, how to work. So I don't
5:53:12need to give it here because this is my
5:53:14um search agent. So basically it will
5:53:16take take a prompt uh so take a topic
5:53:19and it will perform the uh live search
5:53:21operation over the internet and this
5:53:23will return you the URL content. Okay,
5:53:25with respect to that. So for this uh the
5:53:27manual prompting is not required. I
5:53:29think the default prompt is fine
5:53:30completely. But if you want you can also
5:53:31change the system prompt. Okay, it's
5:53:33completely up to you. So you can
5:53:35generate a system from from chat JP and
5:53:37you can pass it here. So this is my
5:53:38first agent. So this is my
5:53:43first
5:53:45agent.
5:53:48Okay, which is s agent. Now I'm going to
5:53:51work on my second agent
5:53:56which is scrapping agent. Okay, that
5:53:58means this one uh reader agent. Okay, we
5:54:01can name it as reader reader agent.
5:54:06reader agent. So let's create it. So
5:54:09similar wise, I will create this agent
5:54:11as well. I'll copy this code. And uh
5:54:14here this is my read reader agent.
5:54:21Okay. And this will take this scrap URL
5:54:24tool because this will connected with my
5:54:27beautiful soup. That's why we're passing
5:54:29this
5:54:30scrap URL tool in this particular agent.
5:54:32And if you want you can also change the
5:54:34system prompt here. But I think default
5:54:36for prompt is fine with me. I'm not
5:54:38going to change the prompt. Okay. So my
5:54:41uh first agent and second agent is done.
5:54:44Now I'll be working with my uh I'll be
5:54:47working with my
5:54:51um third agent and fourth agent and see
5:54:53this third agent and fourth agent I'm
5:54:55not going to create in that way. Instead
5:54:56of that I can utilize the modern langen
5:54:59chain functionality. Okay this is called
5:55:00LCL chain. So I think this is enough u
5:55:03because in lang chen we can use this lcl
5:55:06chen uh uh for for this kinds of
5:55:09operation. Okay this is also possible.
5:55:11Now let me show you how it can be
5:55:13initialized. See if you haven't watched
5:55:15that my ll in my langen so try to watch
5:55:18that otherwise it would be little bit
5:55:20confusion uh for you but if you watch
5:55:22that uh session I think it would be
5:55:24clear. So I have already created let me
5:55:26show you
5:55:29this is my writer chain that means my
5:55:33writer agent
5:55:35see so first of all here you have to
5:55:38prepare a prompt okay custom prompt so
5:55:40I'm using the chat prompt template and
5:55:43what I'm doing I'm giving a system
5:55:45prompt you are expert research writer
5:55:47write a clean structure and insightful
5:55:49reports a human write a detailed uh
5:55:52research on report on the topic below
5:55:54Okay. So first of all I will give the
5:55:56topic and this topic will come from the
5:55:58human human input and this will take the
5:56:01research. Okay. And where it will get
5:56:03the research. It will get the research
5:56:05from this reader agent. Okay. Because
5:56:08reader agent will try to
5:56:10first of all uh first agent what it will
5:56:12do it will give the URL okay URL of the
5:56:15relevant uh relevant actually sources
5:56:18and the second agent will try to extract
5:56:20the content and it will save in the
5:56:22state memory and writer agent will try
5:56:24to take those content and write this uh
5:56:27draft for you. So that's why this
5:56:29research we are taking it from my reader
5:56:31agent. Okay. So this will automatically
5:56:32go to the uh go to the writer agent.
5:56:36Okay. Now here you can see structure
5:56:38report as I need these are the
5:56:39informations in that report.
5:56:40Introduction, key findings, minimum
5:56:42three world explained points,
5:56:44conclusion, okay, and sources. That
5:56:46means whatever URL you refer, just try
5:56:48to also refer the URL in the research
5:56:49topic. You can change this kinds of
5:56:52prompt uh with respect to your
5:56:53requirement. You you can generate a
5:56:55detailed report, you can generate a
5:56:56short report, you can generate more sub
5:56:59point here. You can customize it. Okay.
5:57:01Now be detailed and uh factual and
5:57:04professional. Okay. This is the entire
5:57:06palm. Now we are creating the chain. So
5:57:08writer chain is equal to writer prompt.
5:57:10First of all you have to give the
5:57:11prompt. Then you have to give the llm.
5:57:13Then you have to give the str output. So
5:57:14what will happen? This prompt will go to
5:57:16this llm. Lm will try to work on that
5:57:18because lm is expecting the topic and
5:57:20research. We are already getting from
5:57:21the topic from the user and research
5:57:23from my second agent which is uh reader
5:57:25agent. Agent reader agents will return
5:57:27the content research content and with
5:57:29the help of this research content it
5:57:31will refer and write that particular um
5:57:34report. Okay, just try to think about if
5:57:36I give you the recent let's say recent
5:57:40let's say I'm searching for tell me the
5:57:43latest AI tools. So if I give you the
5:57:47if I give you the let's say uh source
5:57:49content source content means let's say
5:57:51in from the internet I have collected
5:57:53some URL and from URL I have extracted
5:57:55some uh let's say
5:57:58um I have extracted the content of that
5:58:00particular latest information and I have
5:58:02given to you. So this is the content and
5:58:04now just try to prepare a report on
5:58:05that. So what you will do you'll just
5:58:07try to refer that and prepare the report
5:58:08for me. Okay, the same thing we are
5:58:10doing here. So that's why we don't need
5:58:12to create an individual uh agent like
5:58:14that. Okay, it can be done with the help
5:58:16of this LCL chain. Okay, very easy. Now
5:58:19same we'll try to do it for my critic
5:58:21chain as well.
5:58:23That means this one. So this one is
5:58:25done. Now we'll performing for this one.
5:58:27Let's do it.
5:58:29So this is my critic chain. So here also
5:58:32we are doing the same thing. We are
5:58:33creating the prompt template first of
5:58:34all. So you are a sharp and constructive
5:58:37s research critic. Be honest and
5:58:40specific human. Review the research on
5:58:42below and evaluate it strictly. So we
5:58:44are giving the report. Report means this
5:58:46writer agent whatever it will return
5:58:48you. We'll try to pass here. Now it will
5:58:50respond like that. First of all it will
5:58:51give you this four strength areas to
5:58:54improve one line uh verdict. Okay. Then
5:58:58uh we are preparing [clears throat] the
5:58:59chain. So critic chain is equal to
5:59:01critic prompt that means my critic
5:59:02prompt lm and st output. So this will
5:59:04become your critic chain that means this
5:59:06part is also ready. Okay. Now we have to
5:59:08combine them all together to make all of
5:59:11the agent uh work together. Okay. So
5:59:14these kinds of things we'll be
5:59:16performing in the pipeline. Now we'll
5:59:17try to create the pipeline. We'll try to
5:59:18combine this agents all together. That
5:59:21means first of all first agent will come
5:59:23whatever output we'll be getting we'll
5:59:25try to save in the state memory. Then
5:59:26second agent will try to receive that.
5:59:28Then uh we'll try to connect this
5:59:30stability tool with first agent. Then uh
5:59:33this tool with the second agent already
5:59:34this is done. Okay, I have already
5:59:36connected this tool. As you can see this
5:59:38tool is already connected. Then once it
5:59:40is done we'll try to connect the writer
5:59:41agent as well as the critic chain. Okay,
5:59:43critic agent or chain whatever you can
5:59:45say. Now let's try to see how we can uh
5:59:48create this pipeline. So my agent is
5:59:50ready
5:59:52and my tools is ready. Now I'll be
5:59:54working on the pipeline.
5:59:58So guys, our agent and tools everything
6:00:01are ready. Now we can work on the
6:00:03pipeline. So in the pipeline I told you
6:00:05we'll try to connect all of the agents
6:00:07uh together and we'll also try to uh
6:00:10connect the state memory there. So for
6:00:12this uh let's open up this pipeline.py
6:00:15file. Uh it's available inside
6:00:16pipelines. I'll open it up. Uh now let
6:00:20me show you how it can be done.
6:00:23Okay. So for this first of all we have
6:00:25to import um we have to import this
6:00:28agent. Okay the agent we have created
6:00:30that means my search agent then reader
6:00:33agent then my writer chain as well as
6:00:37the critic chain. Okay. So all these
6:00:40thing we have to import one by one. Uh
6:00:43this is the critic chain. So let's
6:00:44import in the pipeline. So I'm going to
6:00:46write from
6:00:48uh from src
6:00:50dot aagents dot agent. So I'm going to
6:00:54import first of all
6:00:58build reader
6:01:01uh build a search agent
6:01:05then build reader agent then writer
6:01:10chain then my
6:01:14critic chain
6:01:16okay critic chain now what I'm going to
6:01:19do guys I'm going to write a function
6:01:23Um already I prepared this function. Let
6:01:25me show you what it will do.
6:01:33Yeah.
6:01:35So first of all I'll try to
6:01:42add this.
6:01:49So this is the function guys. Let me
6:01:51explain. H
6:01:55yeah so you can see the function name I
6:01:57have kept run resource pipeline so this
6:02:00will take the topic whatever topic user
6:02:02will pass uh so first of all what I'm
6:02:05doing guys I'm uh taking a state
6:02:07dictionary here okay so why I'm taking a
6:02:10dictionary because I told you we'll be
6:02:11creating a state memory okay state
6:02:13memory this is a temporary memory uh
6:02:15once agent has executed uh successfully
6:02:18then this uh particular memory would be
6:02:20cleared so that's I told you later on if
6:02:22you want you can also add the permanent
6:02:24memory by adding some u memory database
6:02:27that thing I'm going to definitely
6:02:28discuss in future but as of now just try
6:02:30to consider this is our this is our
6:02:33state uh memory we are taking as a
6:02:35dictionary. So every state it will try
6:02:37to save some data inside that particular
6:02:39dictionary. So first of all I'm just
6:02:41doing a print statement uh just to see a
6:02:44beautiful logs in my terminal. Okay. So
6:02:47we are first of all telling searching
6:02:49agent is working. Then we're giving like
6:02:5150 uh this uh equal sign. Okay. Now what
6:02:54we are calling guys? We're calling now
6:02:56build s agent. Uh so we are creating an
6:02:58object of that particular agent. Then we
6:03:00are invoking it. Okay. What we are
6:03:02invoking? We are invoking without
6:03:04prompt. So user is giving a prompt. Find
6:03:06the recent realable and detailed
6:03:08information about this topic. And from
6:03:10where we are getting the topic. Topic
6:03:12will be given by the user. Okay. From
6:03:14the user interface we'll try to pass the
6:03:16topic. So this topic will come here. So
6:03:18this uh search agent what it will do it
6:03:20will use tably search API it will search
6:03:22over the internet of that particular
6:03:24topic and this will return you the
6:03:26result. Okay, this will return the
6:03:28search result. What would be the search
6:03:29result? I think you remember this will
6:03:31return you these are the search result
6:03:34that means the title, URL and snippet
6:03:37that means the content. Okay. So this is
6:03:39the work of the first agent. You can see
6:03:42and this particular state the first
6:03:44agent whatever it is returning I'm going
6:03:46to save inside state memory. So this is
6:03:48what we are doing. You can see we are
6:03:49calling this state and I'm adding a new
6:03:52key which is search result and we're
6:03:54storing this particular result in that
6:03:56particular memory. Okay, you can see
6:03:58search result. Uh we are getting the
6:04:00message and we're getting the content of
6:04:02that. Okay, content of that and we're
6:04:04stringing uh storing in the state memory
6:04:06and once it is done we're also printing
6:04:08that particular memory what is we have
6:04:11inside that particular state. Okay, so
6:04:13this is for my first agent. So we have
6:04:15completed till here. Now we will be
6:04:18creating this particular option my
6:04:20second agent. So this will connect it
6:04:22with my previous state. It will take the
6:04:24data and it will run my second state and
6:04:25whatever output we'll be getting we'll
6:04:27try to save in the state memory again.
6:04:28So let's try to work on that. So my
6:04:31second step my reader agent.
6:04:34So this is my reader agent.
6:04:38Yeah reader agent. Again I'm doing some
6:04:40print statement. Now you can see I'm
6:04:42initializing my reader agent. Again we
6:04:44are doing the invoking operation of the
6:04:45reader agent. Then we are giving the
6:04:47prompt user based on the following
6:04:49search topic. Uh so topic we are getting
6:04:51from here. Okay. Uh pick the most
6:04:54relevant URL and scrap it for deeper
6:04:57content. That means it will scrap that
6:04:59particular URL. And whatever let's say
6:05:03uh URL we are having we are also passing
6:05:05from my state. You can see we're calling
6:05:07the state and I think you remember we
6:05:09created a key called search result.
6:05:10search result we are giving that
6:05:12particular um I mean content that means
6:05:17whatever URL my first agent has
6:05:20extracted uh my first agent got from my
6:05:23tab we have stored here and my second
6:05:26agent is reading from that particular
6:05:27state you can see it is reading from
6:05:29that particular state that means all of
6:05:30the URL title it will get then it will
6:05:32perform the scrapping operation and
6:05:34whatever scrap result we'll be getting
6:05:35again we are saving in the state memory
6:05:37again I'm creating another key called
6:05:39scrap content inside this state and we
6:05:41are saving the content inside that very
6:05:44simple okay then we are printing that
6:05:46particular content so this part is also
6:05:48done second agent and second agent
6:05:50response we are saving in the state
6:05:52memory now we have to work on the writer
6:05:54and uh critic now let's do it so first
6:05:57of all I'm going to write my
6:06:00writer
6:06:03so this is the writer you can see again
6:06:05I'm doing the print statement for
6:06:06beautiful logs now we can
6:06:10We created a uh variable here. So this
6:06:12variable having two information. One is
6:06:14the source result. Okay, source result
6:06:17and one is the detail scrap content.
6:06:19Okay, the search result we are getting
6:06:20from where we're getting from uh this uh
6:06:24source result. Okay, then what we are
6:06:26doing? We are also getting the scrap
6:06:28content. Scrap content means nothing but
6:06:30uh my previous okay previous whatever
6:06:32scrap content we got, we have in the
6:06:35state memory, we are also getting that.
6:06:36Okay, we are getting the scrap content.
6:06:38Now we are writing our chain. You can
6:06:40see uh chain.invoke. We are giving the
6:06:43topic as well as the research combined.
6:06:45That means both of the example we are
6:06:46giving. Why we are giving the search
6:06:48result? Because I told you I think you
6:06:50remember here
6:06:51if I show you my writer agent.
6:06:56Writer agent. Okay. So here I uh told
6:07:01uh you have to also mention the sources.
6:07:03Okay. Sources uh list of the URL found
6:07:05in the research. Okay. And if I want to
6:07:08list down all the URL, so definitely I
6:07:09have to pass the URL as a reference. So
6:07:11this is what we are passing here. All
6:07:13the URL we are passing. And whatever
6:07:15content we got from the URL, we also
6:07:17passing that. So it will prepare a draft
6:07:19for me. And this particular draft report
6:07:20we are again saving in the state memory.
6:07:23Okay, we are saving in the state memory.
6:07:25So that my critic chain can refer and it
6:07:28can uh uh review that you can give the
6:07:30feedback then we can get the final
6:07:32output. Okay, so you can see we are
6:07:33storing in the state memory and we are
6:07:35printing that. Now the last things we
6:07:37have to write the critic report.
6:07:41Uh so this is the critic report. Again
6:07:43we're doing the print statement. After
6:07:45that uh we are calling the critics and
6:07:47invoke and we're giving this report. The
6:07:50last uh state was the report. We are
6:07:53passing the report. Okay. So this will
6:07:56basically take the feedback and again
6:07:57I'm storing in the state memory as a
6:08:00feedback and we are printing it here.
6:08:02Okay. And we're returning the state. So
6:08:04yeah this is the pipeline guys that
6:08:06means this connection we have done
6:08:07perfectly. Now let's test it whether
6:08:09it's working or not. So what I will do?
6:08:11So in the main.py I'm going to test it.
6:08:15So simply here let's try to import first
6:08:17of all this uh this function.
6:08:22This is the main function run resource
6:08:24pipeline. So here I'm going to import
6:08:26it. So from src
6:08:32dot pipelines
6:08:34dot pipeline
6:08:36import
6:08:39run resource pipeline. Okay. Now simply
6:08:42here I'm going to take a topic is equal
6:08:44to let's say the impact of AI job market
6:08:50in 2026.
6:08:52Let's say this is my topic. Now I'll
6:08:54going to pass inside my
6:08:59run resource pipeline. Okay, run
6:09:02resource pipeline. So basically what it
6:09:04will do, it will
6:09:06give you the final result. Okay, final
6:09:09result. And although we are printing so
6:09:11that's why we don't need to store it
6:09:12here. So it will print in the terminal.
6:09:15Now let me show you. I'll clear I'll run
6:09:19my main.py.
6:09:22Now see first of all research uh search
6:09:24agent is working.
6:09:37Now we got the uh source result okay
6:09:40with URL. Now my second reader agent is
6:09:43working. It is scrapping all of the
6:09:45informations from the URL
6:09:48on that topic.
6:09:51Now see we got the
6:09:54um content. Now my writer agent is
6:09:57drafting the report.
6:10:01Now it will prepare the report by
6:10:03utilizing this content as well as the
6:10:05URL. Now see my
6:10:09final report is ready and it has also
6:10:11given you the sources whatever sources
6:10:13it has referred. Now critic agent is
6:10:15also working and it has given you the
6:10:16report. It told okay you got six out of
6:10:1910 and there is some strength point here
6:10:21is the areas of improvement and here is
6:10:23the oneline verdict okay amazing that
6:10:26means all of my agents are working
6:10:28perfectly guys okay all of my agents are
6:10:30working perfectly there is no error and
6:10:32it is working together okay it is
6:10:34working together and we're getting a
6:10:36very detailed report on my given topic
6:10:38okay but this thing I have to execute
6:10:40from my terminal and it's not like uh
6:10:42readable properly and if I give it to
6:10:45like non-coder guy so definitely he
6:10:46won't be able to execute that agent. So
6:10:49what I can do maybe I can add a user
6:10:50interface here. Uh to add the user
6:10:53interface you can use uh any kinds of
6:10:55framework. If you know front end
6:10:56development you can use React NexJS.
6:10:59Okay you can do it for you. But if you
6:11:01don't know about HTML CSS React uh React
6:11:04NexJS okay completely fine. There is a
6:11:07library inside Python called streaml
6:11:08with help of streaml you can create a
6:11:10user interface. And again you don't need
6:11:11to write the code from scratch. You can
6:11:13use chat gpt. simply uh give this uh
6:11:16pipeline code to the chart GPT and tell
6:11:18just try to add a streaml UI interface
6:11:20with that. So I have done the same
6:11:21thing. So what I did guys with my chart
6:11:23GPT I have generated a user interface
6:11:26with the help of my streaml. Okay. So
6:11:28charge GPT has given me a code. Let me
6:11:30show you how this code looks like. So
6:11:32this is the code.
6:11:35This is the code. Okay. So you can see
6:11:37this is a streamlit uh development.
6:11:40Okay. I have to import this one only.
6:11:43uh instead of importing like that in the
6:11:45app.py I have to import like that. Yeah.
6:11:47SRC agent, uh, build agent, uh, reader
6:11:50agent, writer agent and prediction.
6:11:52Fine. So, first of all, you can see it
6:11:54is utilizing streaml and we have already
6:11:56installed streaml inside our requirement
6:11:58as you can see. Then we it is setting
6:12:01the page configuration. It is adding
6:12:03some custom CSS for the designing of my
6:12:07um UI. Okay. Some color, background and
6:12:10images. It has added uh some other like
6:12:13markdown it has added. Okay. some HTML
6:12:15content has added. See in streaml also
6:12:17you can add HTML and CSS but again I
6:12:20told you if you don't it's completely
6:12:21fine just open up your any kinds of uh
6:12:24assistant gemini or chat GPT or cloud
6:12:27and try to give this pipeline.py Pi and
6:12:29tell like okay I just need to add HTML
6:12:33UI it will add it whatever user
6:12:35interface you are getting just try to
6:12:36run okay nobody's actually remember HTML
6:12:39CSS nowadays okay because we have this
6:12:41kinds of uh flexibility now this is a
6:12:44simple actually uh interface we have
6:12:47created with the help of streamlit again
6:12:49you don't need to understand this code
6:12:50uh this is like uh AI generated uh user
6:12:54interface it's completely fine but there
6:12:56would be definitely uh other guy in the
6:12:58company they will be working on the
6:13:00front- end development as per the
6:13:01company requirement. Okay. But as a uh
6:13:04agent engineer we don't need to worry
6:13:05about the user interface but to run our
6:13:07agent I need a user interface so that I
6:13:10can show to my manager I can show to my
6:13:12let's say customer uh so that uh they
6:13:14can test my agent okay in the user
6:13:16interface uh background okay instead of
6:13:18giving the terminal access. So now if I
6:13:21want to execute my app.py what I have to
6:13:23do guys I have to run this app.py. So
6:13:25simply I'm going to write a streaml
6:13:28run
6:13:30app.py. Now if I execute this will run
6:13:34my app here and all of the code I'm
6:13:37going to share guys in my description
6:13:38from there you can execute. See guys
6:13:40this is the user interface. I think this
6:13:42is amazing right? My chat GPT has
6:13:44created this user interface for me and
6:13:46it has named it as research agent
6:13:48because in the prompt I told this should
6:13:50be the research uh research agent. So
6:13:52that's why it has named like researcher
6:13:54agent. Okay. Multi- aent AI system. Uh
6:13:57four specialized AI agents collaborate
6:13:59searching, scrapping, writing and
6:14:01creating to deliver a polished research
6:14:03uh report on a given topic. Amazing.
6:14:05Right? Now here you can see uh here I
6:14:08have the input option that means I can
6:14:09pass any kinds of research topic. Even
6:14:11it has also given some suggestion like
6:14:13you can try with these are the example.
6:14:15Okay, this is amazing. Now there is a
6:14:16button. If I click on the button my
6:14:19agent will be executing and these are
6:14:20the pipeline I'm having inside my agent.
6:14:22That means the first pipeline the search
6:14:24agent. Second pipeline reser agent. Uh
6:14:26third is the writer ch. Fourth is the
6:14:28critic chain. And right now the starter
6:14:30is waiting. Okay. Now let me try whether
6:14:33it's working or not. So maybe what I can
6:14:35do maybe I can uh copy the same example
6:14:38or you can also write some other thing
6:14:39if you want. Now simply run the research
6:14:42pipeline.
6:14:44Now see first of all my first agent is
6:14:47working. Search agent is working. It is
6:14:49searching with the help of tab API.
6:14:51Let's see.
6:14:58Done. Now my research agent is
6:14:59scrapping. Sorry, reader agent is
6:15:01scrapping the top resources from the
6:15:03URL.
6:15:12Now my writer agent is drafting the
6:15:14entire report.
6:15:16Okay. So step by step it is working.
6:15:18Amazing. Right. The same things you can
6:15:19also perform in your anti-gabit VS code
6:15:21or Google cloud or charge GPT. You'll
6:15:25see that it will also work step by step
6:15:27using the agent mode. Right? So the same
6:15:29thing we have developed here. Now see my
6:15:31critic agent is reviewing the report
6:15:36and that's how multi- aent system works.
6:15:37Now see it's done. Now here you can see
6:15:40the status is already done. All the
6:15:42pipeline is completed successfully.
6:15:43There is no error. That means amazing
6:15:45beautiful user interface it has created.
6:15:47Now just below you can see this is the
6:15:49result even you can see the individual
6:15:52uh actually execution let's say my
6:15:55search result my search agent has
6:15:58searched right what it has search you
6:16:00will see see that it has got the URL and
6:16:03this is the URL it has got the content
6:16:05from medium the snippet that means the
6:16:07introduction part then this is the title
6:16:11okay title URL introduction part then
6:16:13this is the title URL introduction part
6:16:15okay that's how it is having five
6:16:16information. Okay, five information.
6:16:19Now, second agent that scrap the content
6:16:21from the URL. Now, you can see this is
6:16:23the extracted content from all the five
6:16:25uh URL. Uh this is how it has extracted
6:16:29okay and refined and this is the final
6:16:32uh research report we got. Okay. On this
6:16:35AGI development in next five year
6:16:37introduction, key findings. So, it has
6:16:39written all of this thing. Then
6:16:40conclusion. Now, if you want to make it
6:16:42more detailed, you can change in the
6:16:43prompt itself. I think remember So here
6:16:45is the prompt uh here is the prompt
6:16:49in agent.py. So here you can uh increase
6:16:52that particular section. Okay. If you
6:16:54increase it will try to add that. Then
6:16:56sources whatever sources it has referred
6:16:58it also giving you the URL. You can see
6:17:00one by one all of the URL it has given
6:17:02you. Okay. Amazing. Now you can also
6:17:06download it as a MD file. Okay. U my
6:17:08chart GPT also added another button
6:17:10here. I can also download as a MD file
6:17:12if I want and I can open it up. Then
6:17:15this is the critic feedback. So you can
6:17:17see score got six out of 10. This is the
6:17:20strength that means still uh uh sorry
6:17:23this is the strength that means of this
6:17:24particular report like the report
6:17:26provides a clear timeline for a
6:17:27development blah blah blah. It address
6:17:29both technological and ethical
6:17:31consideration. Still areas to
6:17:34improvement are there you can improve.
6:17:36These are the section maybe in the next
6:17:38um prompt itself you can add these are
6:17:40the point here. Okay, these are the
6:17:42point here to improve that particular
6:17:45response and uh this is the one verdict
6:17:48uh line it has written. Okay, amazing.
6:17:51Now let me try with another prompt. So
6:17:53what I will do? So maybe I can ask like
6:17:56um all latest AI agent in 2026.
6:18:00This example run the resource pipeline.
6:18:03again. My agent is working
6:18:17now. Reader agent is tapping.
6:18:28Now my writer agent is drafting the
6:18:29report.
6:18:48Critic is reviewing the report
6:18:53and my agent has executed. Now this is
6:18:55my search result. This is the scrap
6:18:57content result. Okay, you can see here
6:19:00and uh this is the final okay final
6:19:02research report on latest AI agency
6:19:042026. This is the report. This is the
6:19:07sources you can download. Even this is
6:19:09the critic feedback. Okay. Amazing. It's
6:19:11working perfectly. Now if you want you
6:19:13can also change the title. Uh then you
6:19:15can also change this uh you can also
6:19:17change this okay this content from this
6:19:19team itself. you can go to the code and
6:19:22maybe you can find out that section
6:19:23where it has added um
6:19:29so I think there is a
6:19:32so the best part is that like you can
6:19:34search okay so let's I'll copy this
6:19:37and uh here I can search Ctrl Ftrl V
6:19:46ah so here here itself you can change it
6:19:48here okay Now
6:19:53you can also change this title. Change
6:19:56this title if you want. Let's say uh
6:19:58here I think researcher agent. So I can
6:20:01make it as
6:20:03let's say research agent. I'll save it.
6:20:08If I come here refresh now it will
6:20:10become research agent. Okay that's how
6:20:12you can change the title whatever you
6:20:14want. Okay. Everything is possible but
6:20:15I'll keep my researcher agent only.
6:20:19So you just need to figure out where to
6:20:20change this UI interface and you can
6:20:23also change the color. Even if you want
6:20:24you can also design this UI interface
6:20:26with respect to your requirement. It's
6:20:28completely fine. That means my agent is
6:20:30working fine. We have already tested.
6:20:31Now we'll commit the changes. Uh
6:20:35agents
6:20:37working and tested.
6:20:43Now we'll try to deploy this agent.
6:20:51So simply uh what I can do I can go to
6:20:54my GitHub refresh.
6:20:56Okay my agent is ready. Now if you want
6:20:59you can also update the readmi file. So
6:21:01nowadays updating readmi file is super
6:21:03easy. Just open the agent inside your VS
6:21:06code and try to mention
6:21:09update the readme file for this
6:21:16project
6:21:18like a open source
6:21:23repo.
6:21:28Mention
6:21:30how to
6:21:32install
6:21:36and
6:21:38technologies
6:21:40used here
6:21:46if
6:21:52architectures.
6:21:54So now I'll send this prompt. So
6:21:56automatically it will try to understand
6:21:57my entire code code base all the code
6:22:01all of the agents tool everything and it
6:22:02will prepare the readme file for me okay
6:22:05so you don't need to write manually
6:22:06after generating you can customize okay
6:22:08so let me quick do it quickly so that I
6:22:10can update in my repo then I will show
6:22:12you the deployment now see it is
6:22:14evaluating see it is also working step
6:22:17by step right first of all it is editing
6:22:18the file evaluating the file that's how
6:22:20it is running multiple agents in the
6:22:22back end okay things are working like
6:22:24that now see once it it needs any kinds
6:22:26of human permission it will tell me I'll
6:22:29give the permission again it will work
6:22:31you can also give this kinds of human in
6:22:33loop permission I will also show you in
6:22:34future this kinds of thing now in the
6:22:36readmi file see it has updated my readmi
6:22:39now you can uh see here you can simply
6:22:42open the preview and this is the update
6:22:44okay this is the update you can see
6:22:47amazing right now what I can do maybe I
6:22:50can commit the changes
6:22:54readme updated it
6:22:57always try to update the readmi uh
6:22:59because with the help of readmi file
6:23:01user will be able uh I mean some other
6:23:03people will be able to use your repo and
6:23:06definitely whenever you are adding
6:23:08project in your resume you have to
6:23:09update the readmi in a proper github um
6:23:12repository now see this is uh updated
6:23:15now see this is this looks cool right
6:23:17this looks like a like professional
6:23:19project okay professional opensource
6:23:21project you can see it has added all of
6:23:23the features architectures
6:23:25Okay. And then agent responsible
6:23:27technology used prerequisite
6:23:30installation process. Okay. Then uh get
6:23:33your own API keys. How to get the API
6:23:34keys? Uses streamly UI. Then project
6:23:37folder structure workflow example output
6:23:40contributing license acknowledgement and
6:23:42supports. Amazing. Right? Now let's try
6:23:44to deploy this project. So to deploy
6:23:46this project either you can use u paid
6:23:49google uh paid actually cloud services
6:23:51like AWS, GCP, Azure or you can use any
6:23:55uh other platform where you can uh
6:23:57freely deploy this project. See there is
6:24:00a platform called rendercloud. I think
6:24:01previous project also I showed you this
6:24:03render.com. So render.com also you can
6:24:06uh deploy any kinds of AI application.
6:24:08You can see first path to production for
6:24:11the workflow you can deploy it here. But
6:24:13the best part is that here you will be
6:24:15getting a free instance. Okay, there you
6:24:16can deploy the project. But although
6:24:18this instance is like very low but still
6:24:20I think for landing it is fine. But if
6:24:22you want to uh professionally deploy
6:24:24that time you have to take the
6:24:25subscription. But in AWS GCP I don't
6:24:27free I don't uh freely actually deploy.
6:24:30We can't freely deploy there right? So
6:24:31that's why we're using render. So first
6:24:33of all you have to create an account in
6:24:34render. I already have the account. So
6:24:35I'll click on my dashboard.
6:24:40Okay. So previously I already hosted
6:24:43another application as you can see. Now
6:24:45let me create a new web service.
6:24:53Okay. Now I'll click on public git
6:24:55repository and I'll just try to give my
6:24:58repository link here. Then you have to
6:25:01connect it.
6:25:08Okay. Once it is done you can change the
6:25:09name. By default it it has taken my
6:25:11repository name. Everything would be
6:25:14same. No need to change anything. Only
6:25:16you have to give a start command here.
6:25:18So to run a streaml app you have to give
6:25:21this command.
6:25:23Okay. Streamlitly run app.py server port
6:25:25server address 00 and it will
6:25:27automatically install my requirement.xt
6:25:29whatever I'm having here. Okay. Once it
6:25:31is done now I'll take the free plan. So
6:25:33initially it will get 512 MB RAM and 0.1
6:25:36CPU. This is enough for I think learning
6:25:39but whenever you want to professionally
6:25:41deploy it you can take the subscription
6:25:43plan. Now you have to set the
6:25:44environment variable because environment
6:25:46variable it's not available in my
6:25:48GitHub. So I have my open AI and uh this
6:25:51table API both I'll add it here. So pi
6:25:56give the value.
6:26:09Okay. Now I'll add my another
6:26:12environment variable which is
6:26:15tabi.
6:26:30Okay. Once it is done, now simply click
6:26:32on deploy web service.
6:26:37Now it will set up everything in that
6:26:39particular instance. Maybe it will take
6:26:41some time because we are using free
6:26:42instance. Uh we'll wait once this
6:26:45installation everything is complete. I
6:26:46will come back.
6:26:50Now see it is installing requirement
6:26:52txt.
6:26:54Let's wait get once this status is live.
6:26:56I'll come back.
6:27:41So guys, as you can see, my uh build is
6:27:44successful and application is live. Now
6:27:46I can copy this URL, open up my browser,
6:27:48paste it and hit enter. Now this will
6:27:51load your application.
6:27:59So initially it may take some time. uh
6:28:01you have to wait once this has loaded
6:28:04then you will be able to use that.
6:28:09So guys, as you can see, this is our
6:28:11application is live. Now you can share
6:28:12this URL with anyone. They can use it.
6:28:15Now let's try. Maybe I can copy this
6:28:17prompt
6:28:19and I will test it.
6:28:24See, it's working.
6:28:38My
6:28:40search agent is working right now.
6:28:45Now reader agent is working.
6:28:58Now writer agent is drafting the report.
6:29:10and critic agent is reviewing the
6:29:12report.
6:29:22Okay, all of the execution is complete.
6:29:24Now, here is the final result. You can
6:29:26expand and see this is the search
6:29:28result. This is the scrap content and
6:29:30this is our final result we got. Okay.
6:29:33Yeah. So this is the sources you can
6:29:34download also critic feedback.
6:29:36Everything is visible. So yes guys, I
6:29:38think uh it's working fine perfectly.
6:29:41There is no error. Uh we have
6:29:42successfully deployed as well.
6:29:44Congratulation. Now let me show you. If
6:29:46I want to let's say delete the instance.
6:29:48So how it can be done? So for this you
6:29:50have to go to the settings
6:29:53and just below there is option called
6:29:56delete web service. Now you have to give
6:29:58this command.
6:30:03Now delete the web service.
6:30:07Okay. Once you do that, you will see
6:30:09that your web service will be deleted.
6:30:10Okay.
6:30:16So guys, I think you have seen the
6:30:17entire uh deployment entire
6:30:20implementation of this uh AI agent. We
6:30:23have created the complete multi- aent
6:30:25pipeline uh with the help of langin. Uh
What is LangGraph & Why It’s Required? | LangChain vs LangGraph
6:30:30definitely uh I think this is going to
6:30:33be uh this is going to be actually uh
6:30:36interesting project uh to you if you're
6:30:38creating the agent for the first time.
6:30:40Uh so this was uh the first
6:30:42orchestration framework we have explored
6:30:44so far. Don't worry uh we'll be
6:30:46exploring all of the orchestration
6:30:48framework one by one. Now in the next
6:30:50video I'm going to tell you let's say
6:30:53why we have to use the actual aentk
6:30:55orchestration framework like lang graph
6:30:56crewi okay or autogen why we can't use
6:31:00uh lang chen okay what are the
6:31:02limitation lang chains are having each
6:31:04and everything I'm going to clarify so
6:31:05guys I think you know uh we have already
6:31:09uh implemented some AI agents with the
6:31:11help of lang chain uh this was our first
6:31:15orchestrator framework uh for building
6:31:18uh GNI powered application but I told
6:31:21you we can also use lang chain for
6:31:24building these kinds of AI agents. So
6:31:26there I have shown you uh single agents
6:31:30implementation as well as the multi-
6:31:32aents implementation. So if you haven't
6:31:34uh checked that uh the link is given in
6:31:36the description from there you can check
6:31:38it out. So from this video itself guys
6:31:42I'm going to start uh our actual uh
6:31:47agentic AI orchestrator framework. The
6:31:49first framework we'll be starting with
6:31:51uh which is langraph.
6:31:54So I think you have heard of about
6:31:55langraph. It's a very famous and mostly
6:31:58used framework in industry and uh
6:32:01developer are using this framework okay
6:32:04day by day in their life. So before
6:32:07starting actually langraph first of all
6:32:09I want to give you the idea behind uh
6:32:12this langraph why langraph came in the
6:32:15market and if you don't know langraph is
6:32:17a product of langchen okay so langen
6:32:20developer team has implemented this
6:32:22langraph framework for building akai
6:32:25application so first of all let's try to
6:32:27understand why they have created this
6:32:30framework for building these kinds of
6:32:32aenti application uh although they are
6:32:35having language Okay. Um I I think we
6:32:38saw we can use langen for building some
6:32:40of the agents. Okay. Some of the basic
6:32:42level agents. But why we have to use the
6:32:45langen? Okay. What was the purpose
6:32:47behind to use this particular uh let's
6:32:49say lang graph. Okay. First of all we'll
6:32:51try to understand each and everything.
6:32:54Uh then I'm going to start with our
6:32:56langraph concept. Okay. So this video
6:32:59will cover the uh detailed discussion be
6:33:02behind actually langen versus langraph.
6:33:05uh I will uh tell you I will show you
6:33:07why we can't use actually langen when it
6:33:10comes to complex actually workflow
6:33:13complex uh uh agenti let's say
6:33:16application we can't use langen uh
6:33:18instead of that actually we have to use
6:33:20langraph for that okay so I'm going to
6:33:22show you each and every example so that
6:33:24your understanding would be more clear
6:33:26so make sure you watch this video till
6:33:28the end guys now let's see what are the
6:33:31things we're going to cover from this
6:33:33video I'm going to give you the agenda
6:33:35first of all then I will start with the
6:33:37discussion. So guys as you can see uh
6:33:41these are the things uh we'll be
6:33:43discussing in this particular video. Uh
6:33:46first of all uh I'm going to discuss
6:33:48about the uh brief overview uh of
6:33:51langen. So again uh the prerequisite for
6:33:54this video is you have to know langen.
6:33:56Okay, langchen uh understanding is
6:33:59required and I already told you in my
6:34:01YouTube channel I have created langchen
6:34:04video. Uh again I'm going to add the
6:34:06link in the description from there you
6:34:08can check it out. So first of all uh
6:34:10we'll understand um what is lang chain
6:34:13how lang chain works uh what are the
6:34:16application actually we can implement
6:34:18with the help of langchen then we'll be
6:34:21discussing about the lang graph uh we'll
6:34:23understand why lang graph is required
6:34:25and what is lang graph exactly then uh
6:34:27we'll try to understand like uh the
6:34:30difference between lang chain versus
6:34:32lang graph uh what are the benefit we'll
6:34:35be getting from the langraph okay and
6:34:36what are the dis disadvantage we'll be
6:34:38getting from langen and when to use what
6:34:41kinds of framework definitely we'll try
6:34:43to understand each and everything.
6:34:45So uh guys uh here you can see guys uh
6:34:48here is the langen um langen definition.
6:34:53So if you see the langen definition uh
6:34:56here langchen is an open-source library
6:34:59uh designed to simplify the process of
6:35:01building llm based applications. uh it
6:35:04provides modular uh building blocks that
6:35:07let you create uh sophisticated LLM
6:35:10based workflows okay with this. So I
6:35:13think uh you have already used langen uh
6:35:15I mean um inside generative AI and there
6:35:19we uh work with large language model and
6:35:22mostly we implement some ALM based
6:35:24application like uh chat bots then we
6:35:28create RG system text generation system
6:35:31okay uh uh retriever system we try to
6:35:34create these are the things right so
6:35:36guys as you can see lang chain uh
6:35:38consist of multiple component the first
6:35:41component is the model component. So
6:35:43basically uh this model component gives
6:35:46us a unified u actually interface to
6:35:49interact with any kinds of large
6:35:51language model provider. Let's say if
6:35:53you want to connect with open AI LLM so
6:35:57it is having the model component for
6:35:59that. If you want to connect with
6:36:01anropic
6:36:03uh model so it has the model component
6:36:05for that. Okay. If you want to connect
6:36:07with any open source LLM like Llama,
6:36:10okay, Mistral,
6:36:13okay, everything is possible. So all
6:36:15kinds of provider basically it supports
6:36:18and it it will give you some kinds of
6:36:21functionality so that you can connect
6:36:22with. Okay. Then uh it is having
6:36:25something called prom component. So what
6:36:27is prom component exactly? So this prom
6:36:29component helps you to engineer the
6:36:31prompt. So let's say whenever we want to
6:36:34give our custom prompt. Okay, custom
6:36:36prompt, custom prompt. Then um if I want
6:36:40to write actually different different um
6:36:43prompt template. So everything is
6:36:45possible here and all kinds of uh like u
6:36:49prompting strategy prompting engineer we
6:36:51can perform inside this pro prompt
6:36:54component. Okay. So langent is having a
6:36:55prompt uh functionality. With the help
6:36:58of that we can play with the prompting
6:37:00and I think you know especially in GNI
6:37:02application prompting is super
6:37:04important. Without prompt actually we
6:37:06can't create a robust system uh because
6:37:09if you're using very uh poor prompt
6:37:12definitely whatever output you are
6:37:14getting from the application it would be
6:37:16definitely poor. But if you're using a
6:37:19good prompt with a detailed uh
6:37:21instruction that time you can get best
6:37:23output from the application itself.
6:37:25Okay. So langen provides all of them.
6:37:28Then there is another important things
6:37:29we are having inside langen which is
6:37:31this retriever component. So this
6:37:33basically helps you to fetch relevant
6:37:35documents from a vector store. So I
6:37:38think you know we use this for the RG
6:37:40application rag application. So whenever
6:37:43we create the rag application that time
6:37:45this uh retriever component is super
6:37:47important. So there we um there we use
6:37:50something called vector databases and
6:37:52inside vector databases we store all of
6:37:55the documents as a chunk chunk of
6:37:58vectors and whenever we require them so
6:38:01we use retriever component for that to
6:38:03fetch the information relevant
6:38:05informations. Okay. So, yeah, I think uh
6:38:08these are the some major components,
6:38:09multiple components we're having inside
6:38:11Langchen. Uh but the biggest offering of
6:38:14Langchen is the chain. Okay. Uh this
6:38:17this particular things chain. So without
6:38:19chain actually uh it was uh very
6:38:22difficult uh creating this kinds of um
6:38:25this kinds of actually uh production
6:38:28grade uh geni application because chain
6:38:30is kinds of uh actually workflow uh it
6:38:33it's actually sequential workflow. So
6:38:36what is this chain exactly? Chain is
6:38:38nothing but it's a um I mean workflow.
6:38:41Uh basically here we uh create uh this
6:38:45chain in a sequential order. Uh so if
6:38:48you have already used languin I think
6:38:49you know that let's say you have to
6:38:51create first of all multiple uh block
6:38:54okay let's say I have created a prompt
6:38:57block then what I will do um I will take
6:39:01another block called model okay then I
6:39:04will take another block called let's say
6:39:06output parser
6:39:10parser then we'll try to connect this
6:39:13chain together okay this chain together
6:39:16so basically ally what uh will happen uh
6:39:18first of all this prompt will go to the
6:39:20model and model will generate some kinds
6:39:22of output and this output we'll try to
6:39:24see with the help of output pareter so
6:39:26basically it's a uh it's actually
6:39:28sequential workflow and we call it as a
6:39:31chain so uh every block will give some
6:39:34kinds of output and this output will
6:39:36become the input from for the next next
6:39:39block okay then again uh this block will
6:39:42generate some kinds of output again this
6:39:43will be uh going as an input to another
6:39:46block. Okay, that's how you can create
6:39:49actually um uh as many chain as you can.
6:39:52Let's say you can create create
6:39:53thousands uh blockchain. You can create
6:39:56uh hundred of blockchain here. Okay. So
6:39:58everything is possible u inside lang
6:40:00chain. So this is the biggest benefit
6:40:02we'll be getting from the lang chain. So
6:40:04here you don't have any kinds of
6:40:06restriction that means you have to only
6:40:08create uh uh three blockchain or four
6:40:10blockchain. Uh you can create as much
6:40:12and as any as uh so here you can create
6:40:16as much as block you can okay as much as
6:40:19uh uh like um this chain you can okay
6:40:23you have the flexibility here so that's
6:40:25why this uh lang chain got like very
6:40:28popularity and uh it was uh like uh very
6:40:32easy for the developer for creating this
6:40:34kinds of geni powered application. So as
6:40:37you can see what you can build with the
6:40:38langen. Uh so I already told you we can
6:40:41implement like conversational workflow
6:40:43like chat bots, text summarization app.
6:40:46Okay. Then apart from that we can also
6:40:48create uh translation system. Okay. All
6:40:52kinds of NLP related um um I mean um uh
6:40:56problem statement we can solve with the
6:40:58help of this langen. Okay. We can
6:40:59implement with the help of langen. Then
6:41:01multi-step workflow it supports. So
6:41:03let's say whenever I want to create any
6:41:05kinds of mult um multi multi-step
6:41:09workflows that time it is also possible
6:41:11multi-step workflow means let's say um I
6:41:15can give you one example let's say here
6:41:16you given a topic okay you given a topic
6:41:20then uh what you have done let's say you
6:41:22generated a detail
6:41:25okay detail report on that topic okay
6:41:28once this detail report a topic
6:41:30generated then again you took that and
6:41:32you perform something called
6:41:33summarization
6:41:35summary okay so basically you are
6:41:37running multi-step workflow here okay so
6:41:39if I break down uh as a um let's say
6:41:43chain here so what you are doing let's
6:41:45say first of all you are taking a prompt
6:41:49prompt uh related the topic so you are
6:41:52passing it to the llm okay let's say you
6:41:54are telling uh I have uh um or let's say
6:41:58tell me about um tell me about actually
6:42:02um large language model. Okay. Um you
6:42:06just uh generate a detailed report on
6:42:08that on the large language model in
6:42:092026. So your uh this uh particular
6:42:13component will try to give you uh the
6:42:15output uh that means the detail report.
6:42:18Then what you are taking uh again uh you
6:42:21are uh creating another prompt. Okay.
6:42:23You are creating another prompt. Then
6:42:25you are telling uh now I need the
6:42:27summary of this particular detail
6:42:28report. Then again you are passing to
6:42:30another LLM. Okay, another LLM and this
6:42:33LLM is giving you some kinds of uh
6:42:36output summary. Okay, output summary. So
6:42:39basically you are running here
6:42:41multi-step workflow. So here we are not
6:42:43only using one large language model or
6:42:45one prompting you can use multiple large
6:42:47language model, multiple prompting,
6:42:49multiple output parert. Okay, so that's
6:42:51why I told you this chain can be created
6:42:54uh as many as you can. Okay, and this is
6:42:56the best uh uh things we got inside line
6:42:59chain. Then uh the next thing we have
6:43:02which is uh this RG application that
6:43:05means rag application. So inside rag
6:43:07application what we can do we can create
6:43:09a external knowledge base okay knowledge
6:43:13base for the LLM
6:43:15and we we can connect our LLM there. So
6:43:18basically if you are asking any kinds of
6:43:20question if the question uh answer is
6:43:23not available in the LLM itself. So what
6:43:26it will do it will refer kinds of
6:43:28database. Okay, we call it as a vector
6:43:30database and this is the knowledge base
6:43:32actually we try to connect the LLM
6:43:34there. So LM will fetch the informations
6:43:36from here. Uh and uh this uh process
6:43:39actually we perform with the help of
6:43:40this retr component. Okay. Then we uh
6:43:44give the answer to the user. Okay. So
6:43:46this is another things we can develop.
6:43:48Then the last thing we can do on this uh
6:43:51basic level agents creation. So we have
6:43:53already seen um how we can implement AI
6:43:56agents application with the help of
6:43:58plankin. So there I showed you we can um
6:44:01uh create a single agents as well as the
6:44:03multi- aents. But uh here the problem is
6:44:06that you can only create uh like very
6:44:10simple um I mean workflow kinds of
6:44:13agents but whenever it is having complex
6:44:16uh architecture complex workflow that
6:44:18time it would be difficult for you. I
6:44:20will show you okay how what is the
6:44:21difficult and if I want to implement
6:44:23with the help of lang chain so what
6:44:25would be what would be the biggest
6:44:26challenge for you each and everything
6:44:28I'm going to clarify so basically in the
6:44:30basic label agents what we can do maybe
6:44:33uh we can take a large language model
6:44:36and here we can uh take some kinds of
6:44:38tool okay tool access so whenever user
6:44:42is giving any kinds of things any kinds
6:44:45of input so this particular LLM will
6:44:47have the connection uh with the tool And
6:44:50it it can use the tool to get the um get
6:44:53the answer whether you can use any kinds
6:44:55of search tool or any kinds of tool you
6:44:58can use here with respect to your task.
6:45:00It will fetch the informations from the
6:45:02tool and it will show the user. So
6:45:04basically here what we have we have some
6:45:07kinds of uh system that that system
6:45:09connected with some tools. Okay. And
6:45:11that tool will provide some realtime
6:45:13informations to the agents so that it
6:45:15can perform
6:45:18it can perform some automated workflow.
6:45:20Okay. So this is the thing and in multi-
6:45:21aents we created multiple agents and uh
6:45:24we combined them together so that
6:45:26whenever I was assigning any task it was
6:45:28working together. Okay. In a sequential
6:45:30manner. So yeah guys uh these are the
6:45:32things we can um actually implement uh
6:45:34from this langen uh langen actually
6:45:37framework. So guys now uh we'll take an
6:45:40example um and we'll try to understand
6:45:44uh why uh langen cannot be used whenever
6:45:48we are building any kinds of agenti
6:45:51application. So what would be the
6:45:53biggest uh difficulties and challenges
6:45:55uh if we are using lang chain for
6:45:58building these kinds of agent
6:45:59application uh we'll try to understand
6:46:01in detail okay and why uh we have to use
6:46:04lang graph uh we'll also try to
6:46:07understand in detail okay so for this uh
6:46:10I'm going to take the same example uh
6:46:12the example I given you in my
6:46:14introduction session uh where I
6:46:17discussed about the agentic AI I think
6:46:19probably this was the second session uh
6:46:21you have to uh watch uh on my playlist.
6:46:25So uh there I told you about a um
6:46:28recruitment process uh agent. So
6:46:32basically let's say if I am having uh um
6:46:35if I'm having a job position and if I
6:46:37want to uh if I want to let's say hire
6:46:39someone so how I can utilize a agent.
6:46:42Okay, how I can utilize an agent and how
6:46:45this agent was working. Okay, I think I
6:46:47given you a detailed introduction on
6:46:50that. So what I have done uh that
6:46:52particular example I have converted in a
6:46:54flowchart. You can see this is a
6:46:56detailed flowchart. So this flowchart uh
6:46:58actually explains um uh each and
6:47:01everything about that particular
6:47:03application. Um so basically we call it
6:47:05as a workflow. So this thing we call it
6:47:08as a
6:47:11workflow.
6:47:13Okay workflow.
6:47:15So don't try to relate this workflow
6:47:17with the AI agents because there are
6:47:19some difference between this workflow
6:47:22and AI agents. So if you want to
6:47:24understand this thing so what you can do
6:47:27uh you can
6:47:29um you can visit a website uh
6:47:32entropic.com. So they have written a
6:47:35blog about the building effectic AI
6:47:37agents. So if you just go below so there
6:47:40uh they have discussed uh about the
6:47:42workflow and agents. Okay. So as you can
6:47:44see um workflow are system where LLM and
6:47:47tools are orchestrated through a
6:47:49predefined code path. Okay. So as you
6:47:52can see this workflow I showed you. So
6:47:54this is kinds of predefined path and
6:47:56every time whenever I will run my uh
6:47:59let's let's say this particular block it
6:48:01will it has to follow the same things.
6:48:03Okay. But if I'm talking about the
6:48:06agents, okay, agents as you can see,
6:48:08agents on the other hand are the system
6:48:10where LLM dynamically directs their own
6:48:13process uh and tool uses, okay,
6:48:16maintaining control over how they
6:48:18accomplish a task. So I think you have
6:48:20seen my first example I have given you
6:48:22of the same requirement process uh uh
6:48:25applic uh let's say system there my
6:48:28agent was like kind of automated. So I
6:48:31just need to give a prompt. Let's say I
6:48:33want to hire a backend engineer. So all
6:48:35the step actually it was performing
6:48:37automatically. Okay. Sometimes it was
6:48:39giving you some kinds of u uh uh let's
6:48:42say uh human in loop that means u human
6:48:46confirmation but every everything it was
6:48:48automatically working. So it was
6:48:51deciding what to do. It was
6:48:52automatically selecting the tools. Okay.
6:48:54And each and everything. But uh to make
6:48:57you understand about uh this uh lang
6:49:00chain uh langchen actually um uh agents
6:49:03implementation
6:49:05or let's say if I want to implement the
6:49:08same uh that recruitment application
6:49:10with the help of langin so what would be
6:49:12the difficulties okay for that I created
6:49:14this particular workflow so that I can
6:49:15make you understand okay how it can be
6:49:18done um so here you can see this is a
6:49:20workflow uh so workflow means this is a
6:49:23predefined path so you You can see some
6:49:26kinds of condition looping. Okay, it is
6:49:28available. Okay, as you can see but on
6:49:30the other hand agent are actually
6:49:32dynamically um changes everything
6:49:34dynamically take the decisions um and it
6:49:38actually basically dynamically controls
6:49:40each and everything. Okay. So I think
6:49:41you have understood what is workflow and
6:49:43agents. Okay. So for example guys we'll
6:49:46try to consider this particular
6:49:47workflow. Now see let's try to
6:49:50understand this workflow again. So first
6:49:52of all what uh we were doing here. So
6:49:55first of all we are starting this
6:49:57workflow and starting actually we are
6:49:59giving our first uh prompt which was
6:50:01let's say I want to hire a backend
6:50:02engineer. So what will happen that time
6:50:06this particular request will go to this
6:50:08hiring request.
6:50:10Uh so this is kind of a python function
6:50:13you can consider this is a python
6:50:14function. So this uh request will go to
6:50:17the hiring request. Uh so once it will
6:50:19go to the hiring request. So what will
6:50:21happen
6:50:23uh it will uh create a job description
6:50:25uh of that uh of that actually um um job
6:50:29you are asking for. Let's say you have
6:50:31given backend engineer. So what will
6:50:33happen uh for uh backend engineer one
6:50:36job description would be created. Okay,
6:50:38one job description will be created. Uh
6:50:41so let's say you are using some kinds of
6:50:43tool here that tool will help you to
6:50:45write that particular job description.
6:50:47Then what it will do? it will try to
6:50:49send to the next uh actually block you
6:50:52can see called JD approved. So this is
6:50:55another function. So this function let's
6:50:57say has connection with another another
6:50:58LLM. Okay. So this LLM what it will do
6:51:02it will try to let's say verify this job
6:51:04description. It will check whether this
6:51:06is fine or not for this job job role. If
6:51:08not fine so it will send no. Okay. If it
6:51:11is sending no that means again you have
6:51:13to create the job description. Okay. And
6:51:16if actually this particular job JD uh
6:51:20let's say block approved. So what will
6:51:22happen? It will go to the next block.
6:51:24Okay, it will go to the next block and
6:51:27it will post the job description. So in
6:51:29this case, let's say you are using some
6:51:31other tools like uh LinkedIn API, no
6:51:33API. Uh and with the help of this API,
6:51:36you are posting the job on that
6:51:38particular platform. Okay. Now it will
6:51:41go to the next block. Let's say here it
6:51:43will wait for 7 days. Okay. So this uh
6:51:45this particular block will wait for 7
6:51:47days. So after waiting for 7 days uh it
6:51:50will u continuously monitor like how
6:51:53many application you are receiving.
6:51:56Okay. So now again it is it is going
6:51:58through another condition. So let's say
6:52:00if you got enough application then it
6:52:02will perform the other step like short
6:52:04list uh short listinguling conduct
6:52:07interview and all. But let's say if
6:52:09you're not getting enough application
6:52:10let's say you are getting only two to
6:52:11three application what will happen? It
6:52:13will send you no and again it has to
6:52:16modify the job description. Then again
6:52:18let's say it will wait for uh 48 hours.
6:52:21Okay. Then again this loop will be uh
6:52:24jumped to back. Okay. U that means the
6:52:26previous block again uh monitoring will
6:52:29start and again it will check whether
6:52:31you got enough application or not. If
6:52:33you got enough application now let's say
6:52:34you got uh 20 application this is
6:52:36enough. That time short listing will be
6:52:38happening. Short listing means let's see
6:52:40it has some kinds of réumé parser tool.
6:52:43So it will use that uh and it will uh uh
6:52:46it will actually match the resume with
6:52:49our actual job description and uh it
6:52:52will short short list actually some of
6:52:53the candidate let's say from 20
6:52:55candidate it will it's like four to five
6:52:57candidate then we'll try to schedule the
6:52:59interview okay uh then we'll take this
6:53:02interview okay manually take this
6:53:03interview then again there there is
6:53:05another condition block will come so if
6:53:08let's say uh we selected the candidate
6:53:11uh so what we'll do we'll try to send
6:53:12offer letter and all but if we uh let's
6:53:15say don't select the candidate so what
6:53:17will happen when uh regret email will be
6:53:19sent to the candidate let's say I'm
6:53:21extremely sorry for that u actually we
6:53:24are not uh uh we are we are not actually
6:53:27hiding you because let's say you haven't
6:53:29uh performed good in in the interview
6:53:31okay this kinds of regret email we can
6:53:33send otherwise we can send the offer
6:53:35letter okay uh so in offer letter also
6:53:38there are some condition let's say if
6:53:39this offer letter is accepted that means
6:53:42definitely will performing the
6:53:43onboarding and other task but if this
6:53:46operator is not accepted then again what
6:53:48you will do you'll try to perform some
6:53:50renegotiate okay let's say maybe I can
6:53:53uh increase the uh I can increase the
6:53:56package mode let's say initially I I u
6:53:59let's say initially I offered uh uh 25
6:54:02LPA but let's say this person has
6:54:05rejected that so again I will
6:54:06renegotiate that let's say I will give
6:54:09you 30 30 LPA so that time actually this
6:54:11person may prefer this particular
6:54:14package. So it will accept he will
6:54:16accept that then I'll perform the
6:54:18onboarding process and all then we'll u
6:54:20um I mean end this particular um
6:54:23workflow. Okay. So that's how guys the
6:54:25entire workflow is working and uh this
6:54:27was the first example we have taken to
6:54:29understand the AI agents and uh right
6:54:31now we have seen as a workflow how I
6:54:34mean things are working. Okay. Now let's
6:54:36say you want to implement this uh system
6:54:40with the help of langen. So how you can
6:54:43implement this with the help of langen.
6:54:45Okay. Because lang chain doesn't have
6:54:48any kinds of conditional uh conditional
6:54:51let's say u I mean uh workflow or
6:54:53conditional related functionality or
6:54:55looping functionality. Okay. So langen
6:54:58doesn't have that. So first of all let
6:55:00me tell you the challenges you will be
6:55:02facing here if you're um if you're using
6:55:04lang chain for this this one. Uh let me
6:55:08show you. Yeah. So the see first
6:55:10challenge you will be getting here which
6:55:11is um uh conditional
6:55:19branch.
6:55:22Okay. So as you can see this particular
6:55:24workflow is having u so many conditional
6:55:27branch. Okay. So this is the first uh
6:55:30challenges we'll be facing if you're
6:55:31using langen because langen doesn't have
6:55:33any kinds of conditional branch because
6:55:35it works with respect to the chaining
6:55:37concept. Okay, it it it kinds of
6:55:40sequential chaining concept it will be
6:55:42working it doesn't have any kinds of
6:55:43conditional branch. Then the second
6:55:47second challenge you'll be getting the
6:55:49loops okay loops.
6:55:52So as you can see
6:55:54um sometimes it is performing the
6:55:56looping. So that means this particular
6:55:59things will continuously um happening.
6:56:02Okay. If let's say you you you haven't
6:56:04received enough job uh application. So
6:56:06this process will again repeat. Okay. So
6:56:08that means you are looping the
6:56:10operation. Okay. Unless and until this
6:56:12is not satisfied. So again this looping
6:56:15concept is not available inside langen.
6:56:17Okay. You can't uh create this looping
6:56:20concept inside lang. This is not
6:56:22possible. Now the third challenges
6:56:24you'll be guessing um getting called
6:56:27jump. Okay, jump. Now what is jump
6:56:30exactly? Now you can see uh whenever
6:56:32let's say I didn't get any enough
6:56:33application. So this is telling no that
6:56:36time we are modifying the job
6:56:37description waiting for 48 hours then
6:56:40again we are jumping back to my previous
6:56:42block. Okay you can see monitor
6:56:44application. Okay. So from here we are
6:56:46jumping again here. So this is called
6:56:48jump and this kinds of jump we can't do
6:56:50inside lang chain. this is not possible.
6:56:52Okay. So these are some uh biggest
6:56:54challenges guys uh we will be facing
6:56:57whenever we will be using langen for
6:56:59developing this kinds of agent system.
6:57:02Okay. Now let me show you um as a code
6:57:06actually how it can be developed. Uh
6:57:09let's say somehow you want to develop
6:57:11this uh agents with the help of this
6:57:13lang. Uh so now what would be the code
6:57:16coding strategy? Okay. What would be the
6:57:18problem in the coding? Let's try to
6:57:20understand. So here I have actually uh
6:57:24taken some code example uh and this is
6:57:26the langen implementation as you can
6:57:28see. So uh maybe I can open up my
6:57:31diagram. Let me open the diagram guys.
6:57:35H so this is the diagram. This is that
6:57:37workflow. Okay. Now we'll try to
6:57:39understand now with this code. Now as
6:57:42you can see first of all here we are
6:57:43preparing our prompt. Uh we need to hire
6:57:45a software engineer for the back end uh
6:57:47backend team. That means we are starting
6:57:50this recruitment process, we are sending
6:57:52the heading request. So as you can see
6:57:56um before u uh before starting with
6:58:00first of all I need some I need some
6:58:02let's say um I need some um um I mean
6:58:07important object like first of all I
6:58:08need the LM object. So we are taking an
6:58:11LLM as you can see um chat openai we are
6:58:14taking let's say GPT4 then we are
6:58:17creating the prompt template okay so
6:58:20create a job description based on the
6:58:22hiring request okay so whatever request
6:58:25we are getting uh so let's say this
6:58:27particular request we are getting uh we
6:58:29are preparing a job description for that
6:58:31okay this is this is a job description
6:58:33prompt okay so to create this job
6:58:35description we need a prompt so we are
6:58:36preparing here then we are creating the
6:58:39chain here as you can see JD chain is
6:58:41equal to job prompt that means first of
6:58:43all job prompt will come go to it will
6:58:45go to the LLM lm will prepare a job
6:58:47description okay job description then it
6:58:51will uh uh it will be uh go to the
6:58:54output parser and output parser will
6:58:55give you the job description okay now
6:58:58what we have to do guys we have to write
6:58:59this particular uh things as a function
6:59:02uh JD approved okay this is going to be
6:59:04a simple Python function as you can see
6:59:06so we have written a uh def uh approved
6:59:10JD. So here we'll try to pass the JD
6:59:13whatever JD we have uh prepared. Okay
6:59:16I'll try to pass in this function and
6:59:19this function will return see inside
6:59:21that I haven't written the whole code I
6:59:23just given you the highle idea let's say
6:59:25if this job description is approved
6:59:27based on some parameter then we'll try
6:59:29to return approved otherwise we'll
6:59:31reject it. Okay, as you can see we'll
6:59:32try to approved otherwise we'll try to
6:59:34send no. Okay, so here you can see um
6:59:38once this particular job description is
6:59:41approved then we have to pass to the uh
6:59:43post job description. See as of now we
6:59:46are considering
6:59:49uh till here. Okay so this is the entire
6:59:52workflow but I am not creating for the
6:59:54entire workflow. So let's try to
6:59:56consider u this part. Okay, this part we
6:59:59we are implementing as of now with the
7:00:00help of blank. Okay, I'm only
7:00:02considering this part. So you can see
7:00:06uh let me show you. Yeah. So you can see
7:00:09the next function I have written for
7:00:11post job description that means this
7:00:13particular function. So it will take the
7:00:16job description and let's say it has
7:00:18some connection with uh some job portal
7:00:21you have the API key like let's say
7:00:22LinkedIn noy and it will use that and it
7:00:25will post that particular job
7:00:27description. Okay, so we have prepared
7:00:29all of the helper and utility related
7:00:31functionality. Now we have to work on
7:00:33the actual logic building. So you can
7:00:35see sometimes we have to run the loop.
7:00:38Sometimes we have to uh go through the
7:00:40condition. So these are the things we
7:00:41have to do. But in langen this kinds of
7:00:44functionality is not available. In
7:00:45langen I think I told you this kinds of
7:00:48conditional branching, looping, jumping
7:00:49is not available. So for this what we
7:00:52have to do? We have to write some manual
7:00:54code. So let's say here we have written
7:00:56the manual code. So first of all we have
7:00:58taken two variable approved and job
7:00:59description output. Okay. By default I
7:01:01have created as a false and this is this
7:01:03one is none. Okay. Now here you can see
7:01:07in step five we are running a loop until
7:01:10job description is approved. That means
7:01:12this particular things. Okay. This
7:01:13particular loop we'll be writing. So for
7:01:15writing this loop I have taken a while
7:01:17loop. Okay. While loop and I told uh
7:01:20while not approved. Okay that means
7:01:22unless and until this particular
7:01:23approved parameter is true this loop
7:01:25will be running. Then continuously what
7:01:27we are doing we're u creating the job
7:01:30description. Okay job description with
7:01:32the help of this particular prompt user
7:01:33is giving and we're sending to approved
7:01:36job description that means this
7:01:37particular function and unless and until
7:01:40we are not getting approved from this
7:01:41function this particular loop will be
7:01:44continuously running. Okay, you can see
7:01:45if not approved job des uh job not
7:01:48approved uh regenerating again it will
7:01:51come here again it will generate another
7:01:52one again it will send to the uh this
7:01:54particular function this loop will be
7:01:56continuously running okay let's say uh
7:01:59this particular job description is fine
7:02:00we got approved then what we'll do in
7:02:03the final step if it is approved then
7:02:05we'll try to post this job description
7:02:06with the help of this post JD function
7:02:09okay so that's how we can implement this
7:02:12system okay we can implement this system
7:02:14uh And yeah, we are able to do that.
7:02:16Okay, somehow we are able to do that.
7:02:17But to implement this system, I think
7:02:20one more thing you have observed which
7:02:21is this uh extra code. Okay, which is
7:02:24this manual coding. So let's say this
7:02:26manual function we have created again.
7:02:29Um
7:02:30this uh this manual code we have
7:02:33created. Okay, this manual code we have
7:02:36created. So this is called actually blue
7:02:40code.
7:02:43Okay, glue code. So to implement this
7:02:45project, we have to write okay so many
7:02:49line of glue code. Now let's say you are
7:02:51creating the entire workflow right now.
7:02:53Let's say you are creating the entire
7:02:54workflow right now. Just try to think
7:02:56about to complete the entire recruitment
7:02:58process how much glue code you have you
7:03:00have to write here. Okay. And it's
7:03:03recommended whenever you are creating
7:03:05any kinds of production grade
7:03:06application. So you have to avoid
7:03:09writing this kinds of glue code. Okay.
7:03:12you have to avoid to write this kind of
7:03:14glue code, this kinds of manual coding.
7:03:16Okay. So that's why in the market uh
7:03:20they published different different
7:03:21framework for different different kinds
7:03:23of task. Okay. For agents also we can't
7:03:26use langen because in langen we can
7:03:30implement we can implement this kinds of
7:03:32system. It's completely fine but for
7:03:33this we have to write so many manual
7:03:36coding so many glue code and this glue
7:03:37code is not good for our application.
7:03:40Okay. And again just try to think about
7:03:42as a developer uh definitely uh it would
7:03:45be very hectic task for you to write
7:03:47that that much of glue code okay inside
7:03:49your u uh codebase and just try to think
7:03:52about how much your uh your code base
7:03:55would be it would be huge codebase right
7:03:56to manage this codebase like you have to
7:03:59I mean uh you have to uh I mean take
7:04:02care everything and we won't be do that
7:04:05right so that's why guys we won't be
7:04:08using this lang uh for building this
7:04:11kinds of uh agentic workflow because if
7:04:13you see this agentic workflow is not a
7:04:15linear one it's a complex workflow right
7:04:18it's a complex workflow when it comes
7:04:20linear workflow that time it's
7:04:22completely fine let's say there is no
7:04:23condition there is no looping that time
7:04:25easily we can use the training concept
7:04:28and we can implement these things with
7:04:30the help of langen okay but when it
7:04:32comes this kinds of conditional uh
7:04:35conditional branch looping jump that
7:04:38time this lang is not recommend
7:04:40recommended for that. Okay. So for this
7:04:42we have to use some kinds of agentic
7:04:45framework. Okay. Agentic framework it is
7:04:48only for design for building this kinds
7:04:50of complex workflow complex block. Okay.
7:04:52And it has support with this kinds of
7:04:54conditional branching looping jumping
7:04:58all the functionalities it is having.
7:04:59Okay. That's why Langchen team has
7:05:02implemented another amazing framework
7:05:05called Langraph. Okay. So they have
7:05:08created one amazing framework called
7:05:09langraph. So lang graph is a agentic AI
7:05:12framework. Okay. With the help of that
7:05:13you can create agents application. Okay.
7:05:17So how much complex it doesn't matter.
7:05:19You can implement all kinds of agents
7:05:22application. And why this kinds of
7:05:24framework is uh really good for building
7:05:27agentic application because it works
7:05:30works uh I mean with respect to the
7:05:33nodes. Okay. I think you know graph is
7:05:35all about nodes. Okay. You can create as
7:05:38much as nodes you can then you can
7:05:40connect those nodes all together. Then
7:05:42you can also add the conditional
7:05:44statement. You can add the looping in
7:05:46the nodes. Okay, that means graph data
7:05:49structure is a complex data structure.
7:05:51It's not a linear data structure. If you
7:05:53have already studied about this DSA
7:05:55concept, I think you know that. So graph
7:05:57data structure is a complex data
7:05:59structure. It's a nonlinear data
7:06:01structure. So here we can do anything.
7:06:03Okay. So that's why uh this langraph is
7:06:08got I mean this is like very uh very
7:06:10powerful and popular framework when it
7:06:13comes for building any kinds of agent
7:06:15application and that's why langen team
7:06:18has developed this kinds of system and
7:06:19internally they're using uh langen only
7:06:22okay internally they're using langen
7:06:24only they have written some robust code
7:06:26for that and with the help of that
7:06:28actually they have built this lang graph
7:06:30for us uh so that we can use this lang
7:06:33graph for building AI agents
7:06:36application. Okay,
7:06:40I hope you understood. So as I told you
7:06:43this lang graph works uh with the help
7:06:45of nodes um because it has to create a
7:06:47graph and to create a graph we have to
7:06:49create a nodes. So if I now open the
7:06:51workflow you can see uh I can clear yeah
7:06:54so if I open the workflow as you can see
7:06:56here each and every block is kinds of
7:06:59nodes. Okay Lang graph will consider
7:07:00each and every blocks uh as a node. So
7:07:03let's say this hiding request it it
7:07:05would be a node. So I can write here h.
7:07:10So let's say this hiding request it's a
7:07:13it's a node
7:07:17padding request.
7:07:31Okay. Now next we have this create job
7:07:35description
7:07:37j. So this is going to be another note.
7:07:54This is going to be another node.
7:07:58And then
7:08:01we have
7:08:04um
7:08:06job approved. Okay, that means this
7:08:08checking function.
7:08:11So I can make it as job approved.
7:08:15Now there is another node
7:08:21called uh this post job description.
7:08:28Okay, post.
7:08:30I can make it as a post. Okay, so that's
7:08:33how it will create the nodes.
7:08:42Just a minute guys, let me fix it. Yeah,
7:08:46nodes. Okay, now after creating the
7:08:48nodes guys, what it will do? It will
7:08:50draw the edges. Okay, edges means the
7:08:53flow. Let's say this hiring request will
7:08:56go to the job uh description that means
7:09:00from here to here. Okay, this is called
7:09:02ages. Okay, in langraph we call it as a
7:09:05edges. Okay, you can see in the code
7:09:07also I'll explain this code as well. U
7:09:10but I I know that uh you you haven't uh
7:09:13written any kinds of code in Langra but
7:09:15it's completely fine. I'm going to teach
7:09:16you how to write the code but as a high
7:09:18level I'm going to make you understand
7:09:20okay how things are working. Now this
7:09:23job description will go to the uh job
7:09:25approved. Okay, this block that means
7:09:28this note. So again we'll create another
7:09:30edge.
7:09:31Okay, now this uh job approved will go
7:09:34to the next uh next ed uh next actually
7:09:37nodes which is post job description.
7:09:40Post job description. Okay, so we have
7:09:42drawn the edges. Okay, now we'll be
7:09:44working on the conditional and looping.
7:09:46Okay, now we we have to work on the
7:09:48conditional and looping. Now to uh I
7:09:50mean for better understanding maybe we
7:09:52can see the code guys here. Uh so this
7:09:55is the code implementation
7:09:58uh of langraph. Let's say the same
7:10:01workflow uh we can implement with with
7:10:03the help of langraph. So you can see the
7:10:05langraph implementation. So first of all
7:10:07we are adding the nodes. Okay all of the
7:10:09nodes one by one. First of all we are
7:10:11adding hiring request this this nodes we
7:10:14are getting these nodes. Okay. And uh
7:10:16you can see uh we are giving the name as
7:10:18well as we are giving a hiring request
7:10:20object. Now you can ask what is this
7:10:21hiring request object. This is nothing
7:10:23but this is a simple python function as
7:10:25you can see hiding request. Okay. So we
7:10:28are um creating a simple Python
7:10:30function. uh we are using LLM or we are
7:10:34using some kinds of API here in that and
7:10:36we are preparing a function and once
7:10:38this function is ready we are giving the
7:10:39object of that particular function in
7:10:41the inside the nodes that means this
7:10:43particular function will be uh created
7:10:46as a node okay node inside langraph then
7:10:49the next uh uh node we are adding create
7:10:52uh job description job description again
7:10:55create job description is another
7:10:56function okay we are giving the object
7:10:59here okay then we are creating
7:11:01[clears throat] Next note which is check
7:11:02approval that means this function. Okay.
7:11:05So this is the function check approval.
7:11:08Then next we are doing uh this uh post
7:11:11job description that means this note
7:11:13this note again this is the uh post
7:11:17approval. What is post appro uh post
7:11:19right? Post job description. Okay this
7:11:20one this particular Python function.
7:11:22Okay. So with the help of that we are
7:11:24preparing all of this node one by one.
7:11:26Now once node is created now I have to
7:11:28draw the edges. Okay. Now we'll be
7:11:30drawing the edges. So as you can see we
7:11:32are drawing the edges. Uh so now see the
7:11:34workflow. First of all uh hiding uh
7:11:37request will go to the
7:11:40uh create job description. So you can
7:11:42see uh graph add age uh hiding request
7:11:47will be connected with create job
7:11:49description. That means here to here.
7:11:52Okay. So the first one then the second
7:11:55one. Okay. You want to connect this
7:11:57particular edge. Now next is would be
7:12:00create job description to check
7:12:01approval. Create job description to
7:12:04check approval. Okay. So here we have to
7:12:06draw the edges. Okay. But in between you
7:12:09can see
7:12:11uh create job description to uh job
7:12:14approval. Here we have a uh we have a
7:12:17condition. Okay. If job is not approved
7:12:21then it will again create a job
7:12:22description. If it is approved then it
7:12:25will post the job description. Okay. So
7:12:26now we have to create this conditional
7:12:28statement. It would be very easy for me
7:12:30to create a conditional statement
7:12:31because we are using this uh uh graph
7:12:34structure. Okay. In line graph. Now you
7:12:36can see in graph itself there is a
7:12:38function called add conditional ages.
7:12:40Okay. Now what would be the condition?
7:12:43Condition would be depend on this check
7:12:45approval function. That means this check
7:12:46approval we have created. That means
7:12:48this one. Okay. So if this check
7:12:50approval returns no. Okay. If it is
7:12:53returns no. Okay. not accepted again it
7:12:56will create the job job description you
7:12:57can see if it is not approved then
7:12:59create the job job description it's a
7:13:01loop back right but if it is approved
7:13:03then it will go to the directly post ID
7:13:05now you can see in next graph we are
7:13:08again adding another edges post ID that
7:13:10means from here to here from here to
7:13:12here okay so that's how guys we can
7:13:14easily implement this kinds of system
7:13:16with the upline graph okay I hope you
7:13:19got it and see like very easy it is
7:13:21right but in my previous implementation
7:13:23it was very hard for me and we have to
7:13:25write so many line of glue code here but
7:13:28here it is not required. Okay. So I hope
7:13:31guys you have understood. So this is the
7:13:33easiest example I can give um like uh
7:13:36regarding this langen versus lang graph
7:13:39and why people are using lang graph why
7:13:41um it is recommended to use lang graph
7:13:44uh like uh instead of using langen for
7:13:46building this kinds of agentic workflow
7:13:48now I think everything is clear in your
7:13:50mind so that's why in this langraph
7:13:53implementation you can either use
7:13:55looping okay looping concept either use
7:13:58branching concept this conditional
7:14:01statement concept Okay, without writing
7:14:03any kinds of glue code. Uh that's why it
7:14:05is uh uh super powerful and recommended
7:14:09and easily you can implement any kinds
7:14:12of complex application complex agent
7:14:15application with the help of this line
7:14:17graph. Okay, because internally it is
7:14:19using this nodding concept, graphing
7:14:22concept. I hope it is clear guys. So
7:14:25guys, now I'll be discussing about the
7:14:27second challenges you will be getting
7:14:29whenever you are using uh lang chain um
7:14:34for this agentic AI application. So the
7:14:36challenge name is uh handling state. So
7:14:39let's try to understand what is state
7:14:41exactly. So see state a kinds of uh meta
7:14:44data uh we use whenever we execute the
7:14:48entire workflow. So if I open the
7:14:50workflow I think you have seen um these
7:14:53are some uh important blocks we are
7:14:55having. So every blocks will generate
7:14:57some kinds of output and based on this
7:14:59output actually we are deciding for the
7:15:01next block. Let's say hiring request
7:15:04will go to the job description. Job
7:15:06description will generate job
7:15:07description. Okay. Then job approved
7:15:09will try to check whether this job
7:15:11description is fine or not. If it is
7:15:13fine. If this job description sends yes
7:15:16then job post will be happening.
7:15:18Otherwise uh if it sends no that means
7:15:20again it will create a job description.
7:15:23So in uh in every step guys you can see
7:15:26we are generating some kinds of state
7:15:28data okay state data. So if you just go
7:15:30through this block I think you will
7:15:32understand u uh why this block are
7:15:35important and why the generated uh datas
7:15:38are important because based on the data
7:15:40we are making the decision for the next
7:15:41block. So as you can see if I show you
7:15:43this state. So let's say if this is our
7:15:45goal hire a backend software engineer.
7:15:47So first of all uh uh what will happen
7:15:50these are the information will be stored
7:15:52in the state memory that means the job
7:15:54um description text would be available.
7:15:57Then job approved or not this particular
7:15:59status would be true or false. Job
7:16:01posted or not this would be true or
7:16:03false. How many applications you got?
7:16:05Number of applications you have. Okay.
7:16:08Shortlisted candidates name is offer
7:16:10letter sent or not. Interview question
7:16:12is prepared or not. Okay. So these kinds
7:16:14of data you need to run the entire
7:16:16workflow because this uh your agents
7:16:19will try to refer this state okay state
7:16:21data and it will decide okay what to do
7:16:24next. Let's say uh you have run till
7:16:26here let's say you have run till here
7:16:29you have executed till here till
7:16:30monitoring. So now right now your agent
7:16:33is having this kinds of state data.
7:16:35Let's say it know actually how many
7:16:37application uh you you you have
7:16:40currently okay it it it received
7:16:42currently and how it will understand
7:16:44because this information is available
7:16:46inside state right so it it will solve
7:16:48let's say five application came so far
7:16:50so what it again it will do again it
7:16:52will tell this is not enough just try to
7:16:54modify the job description and again try
7:16:57to monitor everything okay based on that
7:16:59particular data it is deciding right so
7:17:01this is super important so this is
7:17:03called actually state And langen is
7:17:05stateless. Okay, langshen doesn't have
7:17:07any kinds of state related functionality
7:17:10because you can see this particular
7:17:12state would be stored as a key value
7:17:14pair like a dictionary. Okay, but langen
7:17:17langen doesn't give you any kinds of
7:17:21um dictionary or key value pair storing
7:17:25concept. Okay, that means langen is
7:17:26completely stateless here. Okay, you
7:17:30can't do it with the help of langen. You
7:17:32can do it for this maybe what you have
7:17:34to do you have to let's say whenever you
7:17:36are starting the code at the very first
7:17:38time you have to take a dictionary about
7:17:40u name let's say state okay you are
7:17:42taking a dictionary and uh you have to
7:17:45manually like define these are the key
7:17:47here manually define these are the key
7:17:49and every after every execution you have
7:17:52to manually update these are the value
7:17:53here okay so that means you are again
7:17:56writing the glue code here and this is
7:17:58very trick task for you to manage all of
7:18:00the state right so If I show you all of
7:18:03the state because it's not a like a very
7:18:05uh short state we are handling. If
7:18:07you're creating the entire workflow just
7:18:09try to think about how many state uh
7:18:10that mean how many metadata will come
7:18:12and every time you have up to date that
7:18:14inside langen okay so this would be head
7:18:16trick for you but inside uh this uh lang
7:18:21graph okay if I'm using lang graph so
7:18:24inside lang graph guys uh this concept
7:18:28is available so lang graph is like
7:18:30stateful
7:18:32okay stateful if you're using lang graph
7:18:34it is stateful because in lang graph We
7:18:37create a nodes right? We create a nodes
7:18:41and nodes will be having this kinds of
7:18:47uh this kinds of actually state
7:18:49connection. State connection means see
7:18:53state connection means we can we can
7:18:54create a state object. Okay, we can
7:18:56create a state object inside langraph.
7:19:00So state object.
7:19:02So this state object can be created with
7:19:04the help of pyic.
7:19:06So I think I already taught you pyntic
7:19:08in my playlist the same playlist you can
7:19:10check that either you can create with
7:19:12the help of type dict there is another
7:19:15concept you can uh use it type dict.
7:19:18Okay. So basically what you will do
7:19:19you'll just try to define this kinds of
7:19:21structure at the very beginning of your
7:19:24application and in every nodes you will
7:19:26try to provide this state access. Okay.
7:19:29So what the node will do? So after every
7:19:32node execution automatically these kinds
7:19:35of data would be updated. Okay. These
7:19:38kinds of data would be updated inside
7:19:40the state. Okay. So let me show you
7:19:42maybe uh you'll be clear enough.
7:19:46So I think I showed you an example
7:19:48right?
7:19:51I showed you one example related this
7:19:55yeah node concept. Yeah you can see we
7:19:57are creating the node. Okay, we are
7:19:59creating a node. So whenever you are
7:20:02creating a node, it will have the access
7:20:03to the state object. Okay, so let's say
7:20:06whenever it is doing any kinds of um
7:20:09execution, let's say it is generating
7:20:10the job description. That time um in the
7:20:14state there would be a section called
7:20:15job description in a key, right? It will
7:20:18try to update the job description.
7:20:19Again, it will run to the next node job
7:20:22approved. So whether job is approved or
7:20:24not whether it is true or false again it
7:20:27will try to update that particular
7:20:28parameter because we are defining this
7:20:31particular state with the help of this
7:20:33pentic pentic or this state dict okay we
7:20:36are doing that this kinds of structure
7:20:39so that's why in the code itself if you
7:20:41see the langraph implementation so every
7:20:44time in the function itself we are
7:20:45giving this kinds of state okay you can
7:20:48see we are giving this kinds of state
7:20:50okay and output it will also return you
7:20:52some kinds of state okay because it is
7:20:54updating in that particular um state
7:20:57object okay so that's how this lang
7:20:59graph handles this kinds of scenario
7:21:01this kinds of stating scenario okay uh
7:21:04but you now you can ask me in in lang
7:21:06chain uh we have the memory concept
7:21:08definitely right in lang chain we have
7:21:10the memory
7:21:12we can use the memory but memory you can
7:21:15use for what for the conversational
7:21:18workflow converation
7:21:21okay you can store the conversation the
7:21:23conversation you are doing with your
7:21:24chatbot or whatever you can state the
7:21:28you can store the conversation okay
7:21:30conversation story but it doesn't
7:21:33support any kinds of key value pair
7:21:34storing this kind of stating concept is
7:21:36it doesn't support you can store the
7:21:38conversation you can use conversation
7:21:40buffer memory for that but this kinds of
7:21:42thing is not possible okay I hope it is
7:21:45clear guys now guys let's talk about the
7:21:48hard challenges uh we'll be facing um uh
7:21:52which is eventdriven execution. Okay. So
7:21:55what is this eventdriven execution? See
7:21:57let's try to understand this one. So the
7:22:00workflow we have uh seen here. So this
7:22:02workflow can be executed in two way. Um
7:22:05money is
7:22:08uh let's say this is the workflow.
7:22:12Okay. So this can be executed through
7:22:14sequential manner.
7:22:17Okay. And event driven
7:22:21event driven. Okay. So let's try to
7:22:24understand the sequential. So let's say
7:22:27um sequential means let's say uh you are
7:22:30implementing through the lang chain and
7:22:31I think you know lang chain works in a
7:22:33uh in a chain order that means in a
7:22:35sequential order. So what I can do maybe
7:22:40just a minute
7:22:46or let's clear H. [clears throat]
7:22:50So see in Lchen
7:22:59in Lchen
7:23:01you have created in a sequential order.
7:23:03So let's say first of all you have given
7:23:06a prompt
7:23:08then you are passing this prompt to LLM
7:23:11lm is giving a uh kinds of output again
7:23:13you are preparing another prompt again
7:23:16this output and prompt you are giving to
7:23:17another LLM
7:23:19okay LM then you are getting some kinds
7:23:21of response here
7:23:24response here right so this is called
7:23:26actually sequential left to right you
7:23:28can see left right it is happening so
7:23:29this is a sequential order
7:23:32sequential order it is following. Okay.
7:23:35So, sequential order means this will
7:23:38start and this will uh complete the
7:23:41execution then it will be completed.
7:23:42Okay. In between it is not pausing
7:23:45anywhere. Okay. In between it is not
7:23:47pausing anywhere. But if you see the
7:23:49workflow inside workflow sometimes we
7:23:52have to pause the execution. Okay. So
7:23:55let's say if I give you example
7:23:57let's say if I come here you can see so
7:24:00whenever this workflow is running right
7:24:01it is running the workflow it's
7:24:03completely fine but here you can see it
7:24:06is waiting for some manual trigger right
7:24:08let's say it will uh wait for 7 days
7:24:12after waiting for 7 days then what it
7:24:14will do after posting the job
7:24:16description it will wait for 7 days then
7:24:18your monitoring application will be
7:24:19started okay so here it is waiting for
7:24:22some kinds of trigger Okay. So this
7:24:25triggering concept is not available
7:24:26inside that sequential execution. Okay.
7:24:29It is not available inside langen.
7:24:31Langen doesn't have any kinds of uh uh
7:24:34this uh pausing option triggering
7:24:36option. Okay. You can't do that.
7:24:40Okay. But you can implement inside
7:24:42langen. So for this what you have to do
7:24:44let's say maybe you'll be creating this
7:24:47part separately. Then you will wait for
7:24:497 days. Okay. Let's say in some uh in
7:24:52Python code you will be writing a
7:24:54function that that function will try to
7:24:56wait for seven days then again you will
7:24:58run this particular uh this particular
7:25:01let's say workflow okay so that means
7:25:02you have to do it manually again you
7:25:04have to write the glue code for that but
7:25:06inside langraph okay inside lang graph
7:25:09this kinds of concept is available this
7:25:11eventdriven concept is available so
7:25:13langen what it will do so automatically
7:25:16because it has the state connection
7:25:17right it has the state connection and
7:25:19the state itself this uh metadata would
7:25:22be available. You have to wait for 3
7:25:23days. So in lang lang graph
7:25:26automatically this particular
7:25:27eventdriven option should be available.
7:25:29So it will wait for the trigger. So once
7:25:31this trigger is complete then it will
7:25:32run the remaining workflow for you.
7:25:35Okay. So this is another challenges
7:25:37you'll be getting if you're using langin
7:25:39for building this kinds of agentic
7:25:42workflow. Okay. I hope you clear guys.
7:25:45So guys uh next challenges uh you'll be
7:25:48getting called fault tolerance. So what
7:25:50is this fault tolerance? Fault tolerance
7:25:52means let's say whenever we are running
7:25:54these kinds of big workflow so
7:25:56definitely there would be some kinds of
7:25:57fault in your application. Okay, fault
7:26:00in your application. Fault means let's
7:26:02say sometimes for uh what happens? Let's
7:26:04say you are executing the workflow.
7:26:06Let's say here you are executing the
7:26:09workflow uh at this particular workflow
7:26:12is getting executed. This particular
7:26:13block is executed. That time let's say
7:26:15you are posting the job description to
7:26:16the LinkedIn. Let's say uh that time
7:26:19LinkedIn API is not working. So
7:26:21definitely your application will stop
7:26:23that time. Okay. So this is called
7:26:24fault. Uh there is another fault. um
7:26:28let's say you have deployed this
7:26:30workflow in a server let's say AWS and
7:26:33AWS got down so this is another fault so
7:26:35that means this fault can be two types
7:26:37one is small type
7:26:41small type and one is big type okay in
7:26:44small type uh what is happening you are
7:26:47getting the fault in between let's say
7:26:50in between the block let's say you are
7:26:52not able to post the job in the LinkedIn
7:26:54because LinkedIn API is down Okay,
7:26:58big fault means let's say you are you
7:27:00have hosted this workflow in AWS and AWS
7:27:02got down that time your application will
7:27:04crash. So what happens inside uh this uh
7:27:08lang chain lang chain doesn't have any
7:27:11kinds of fault tolerance functionality
7:27:13integrated with it. That means if you're
7:27:15creating a chain let's say you have
7:27:16created this kinds of chain.
7:27:19Okay. This kinds of chain. Okay. So how
7:27:22chain executed? It executed in a
7:27:23sequential order. Let's say here you you
7:27:26break the chain. Okay. Let's say for a
7:27:27reason let's say this is the post job
7:27:30description. Let's say API is not
7:27:32working. So that time it will break here
7:27:34and all of the application will be break
7:27:38okay break then whenever you will be uh
7:27:41re-executing again it will reexecute
7:27:43from the beginning okay from here it
7:27:44will execute okay but already you have
7:27:48done so many stuff before posting the
7:27:50job description let's say your JD is
7:27:51prepared everything is ready but if
7:27:53you're running from beginning again it
7:27:55will do everything then again it will
7:27:57post the job description over the
7:27:59LinkedIn that means it is not able to
7:28:01resume from here okay it is not able to
7:28:03resume from here. It is executing the
7:28:05entire workflow again.
7:28:07Okay. Inside uh lime chain, this is the
7:28:10problem. Okay. Uh and let's say if your
7:28:14server is getting down, AWS is getting
7:28:16down also again you have to execute from
7:28:18the beginning. But inside langraph uh
7:28:21this fall tolerance functionality is
7:28:23available. So basically what happens
7:28:26let's say whenever you are creating this
7:28:27kinds of workflow. Let's say this is
7:28:29your workflow. Okay, this is your
7:28:31workflow. So let's say you are coming
7:28:33here and you you got you got some kinds
7:28:37of error. Let's say your LinkedIn API is
7:28:39not working that time it will give you
7:28:42um one option called retry. Okay, retry.
7:28:46So if you do the retry operation that
7:28:48means from after some times from here
7:28:51only your execution will start that
7:28:53means it will go to the this node and
7:28:54this node. Okay, it it doesn't have uh
7:28:57has to come here from beginning and run
7:28:59the entire workflow. Okay. And let's say
7:29:02you have hosted over the AWS AWS got
7:29:04shut down. And let's say you run till
7:29:07here. There is some other workflow also
7:29:10available. Let's say you run till here.
7:29:11Okay. So whenever you again let's say uh
7:29:14your AWS server uh fixed. Okay. And uh
7:29:18it is running again. So again it will uh
7:29:21continue from here. Again it will
7:29:23continue from here. Again it doesn't
7:29:25need to run from the beginning. So this
7:29:27kinds of fall tolerance option is
7:29:28available. And again this fault
7:29:29tolerance uh how it is u I mean handling
7:29:33with the help of the state concept state
7:29:35concept because we are having the state
7:29:37informations okay all of the state
7:29:39information every time langraph will
7:29:41take this snapshot of the state and it
7:29:43will stored in a memory okay you can
7:29:44also use a physical memory here if you
7:29:47want some memory database you can use
7:29:49and this state you can save inside a
7:29:50memory so every time it will take a
7:29:52snapshot of the state let's say what is
7:29:54the current execution current execution
7:29:56let's say post job description
7:29:58Post job description. Let's say here
7:30:00your uh uh let's say you got the fault.
7:30:03Okay. So this kinds of state already
7:30:06saved. Let's say before this post job
7:30:09description everything is ready but
7:30:10during post job description this is
7:30:12failed. So what it will do again retry
7:30:13from here again retry from here. It will
7:30:16not run from the beginning. Okay. I hope
7:30:18you got it. So that's why fall tolerance
7:30:20is another challenges inside langen. So
7:30:23guys, the next challenges uh and the
7:30:26very important challenges you'll be
7:30:28facing if you're using langen called
7:30:30human in the loop or hittl
7:30:32uh hl uh I think you know what is human
7:30:35in loop uh human in the loop and why it
7:30:38is required because I have given you the
7:30:40same example and let's try to understand
7:30:43from this workflow itself. So human in
7:30:45the loop actually it depends upon the
7:30:47human input. So uh basically you are not
7:30:50giving the full access to the agent
7:30:52instead of that some of the uh
7:30:56restriction you are setting let's say
7:30:57whenever it will create the job
7:30:58description uh before posting the job
7:31:02description it will ask for the approved
7:31:04to the human let's say it is asking for
7:31:05the approve to you if you approve that
7:31:08then it will post this job description
7:31:10okay or let's say here before sending
7:31:14this uh conducting the interview it will
7:31:15ask you uh whether uh you free or not?
7:31:19Can I schedule the interview? So if you
7:31:21give the access then it will like um
7:31:24schedule the interview for you. Okay. So
7:31:26this is called human in the loop and
7:31:28this human in the loop functionality is
7:31:29not available um default inside lang. Um
7:31:33I mean you can't um take the human in uh
7:31:36I mean human input in between the chain.
7:31:39So let's say if you create a chain here.
7:31:42Let's say this is your chain.
7:31:47This is your chain right and in between
7:31:50let's say you have to take a input from
7:31:51the human okay you have to take the
7:31:53input from the human
7:31:55that time uh you can't actually uh I
7:31:58mean uh use any kinds of default
7:32:00functionality for that so maybe what you
7:32:01can do in between maybe you can take a
7:32:03input function and you can take the
7:32:05input from the human but again uh this
7:32:08will stop the chain here okay unless and
7:32:10until you are not giving the input this
7:32:11chain won't be executed or it will take
7:32:13unnecessary computation and whenever it
7:32:15is longterm Right? Long-term means uh
7:32:17this kind of aentic system is long-term.
7:32:19So user can give the input after 2 days
7:32:22as well. Right? So that time I don't
7:32:25want to necessarily compute uh I don't
7:32:27want to necessarily use my computation.
7:32:29Right? So this is another problem. So
7:32:31maybe you can create this chain
7:32:32separately this ch separately in between
7:32:33you can ask the input and whenever user
7:32:35will give the input then you can recont
7:32:38this chain from here. Okay. But again
7:32:39you have to take all of this state uh I
7:32:42mean state data manually and you have to
7:32:45copy here again. So again you have to
7:32:46write some glue code there for that
7:32:48right. But inside this uh lang graph
7:32:51this human is loop already implemented.
7:32:53Okay this is already the first class
7:32:57citizen. Okay first class citizen inside
7:33:00this lang graph. It is already uh
7:33:03already available. Okay already
7:33:05available. Even if you go to the uh
7:33:07documentation of langraph uh there is a
7:33:10separate section for that. Let me show
7:33:12you. So this is the langraph
7:33:13documentation. So you can see human in
7:33:16the loop is available. So the human in
7:33:18the loop um hittl
7:33:22middleware wire lets you and human
7:33:24oversight uh to agents to call when
7:33:28model response an action that might
7:33:30requires a review. For example, writing
7:33:32to a file or execution SQL. Uh the um
7:33:36middleware can pause execution and wait
7:33:38a decision. Okay. So you can see this
7:33:40particular option is available and they
7:33:42have already integrated in their
7:33:43functionality. Okay, human in the loop.
7:33:45Okay, this is already available. We'll
7:33:47definitely learn this in detail whenever
7:33:49we'll uh learn the langen component. Uh
7:33:51sorry, lang lang graph component. I will
7:33:53try to learn each and everything. Okay,
7:33:55I I hope this part is clear. That means
7:33:57this is another challenges you'll be
7:33:59getting uh if you're using langen. Okay,
7:34:01and this is super important guys. If
7:34:02you're is creating this kinds of
7:34:04workflow, so this uh human in loop is
7:34:06required there. Okay, I hope you clear.
7:34:09Now let's talk about the next one which
7:34:11is nested workflow. uh nested workflow
7:34:14means see inside langraph you can run
7:34:16the nested workflow. So whenever I'm
7:34:19talking about lang graph I think you
7:34:20know we can create actually complex
7:34:25nodes here right it works as a node
7:34:30okay you can create this kinds of node
7:34:32okay now let's say a nested workflow
7:34:36means the nodes you are creating
7:34:38um inside this nodes you can create
7:34:41another graph
7:34:43let's say this node represents this
7:34:45kinds of graph okay that means This node
7:34:48itself it's a graph object. This is
7:34:50called nested workflow. Okay, I I think
7:34:53you get it. We call it as a subnote. So
7:34:55there is a concept inside the
7:34:57documentation. Let me show you.
7:35:01Um this is the documentation. Uh you can
7:35:05see if you see there is a concept called
7:35:07sub sub node. So let's say this is your
7:35:10uh node. This node itself should be a uh
7:35:12another graph. Uh and you can use this
7:35:15particular graph. Okay. So this is
7:35:17called actually sub sub node concept and
7:35:19we call it as a nested workflow and this
7:35:21nested workflow is very much required
7:35:23whenever you are creating this kinds of
7:35:24system. So let's say if I'm talking
7:35:26about a use case. So let's say if I'm
7:35:29talking about this conduct interview
7:35:31okay since said conduct interview uh
7:35:33this thing is not like uh very easy to
7:35:36implement because just try to think
7:35:38about if I want to conduct the interview
7:35:40first of all I have to prepare um set of
7:35:43questions for each and every candidate
7:35:46then I have to also
7:35:49um uh take the interview let's say round
7:35:50one round two round three okay I have to
7:35:52track those informations so instead of
7:35:54creating a single uh nodes here maybe I
7:35:57and uh create it as a sub node. So this
7:35:59will be connected with another nodes and
7:36:01that uh sorry this will connected with
7:36:04another workflow another graph and this
7:36:06graph will try to uh let's say uh
7:36:08prepare the interview questions for the
7:36:09candidate or uh taken taken care by the
7:36:12round one round two round three okay and
7:36:14so on. So these kinds of complex uh
7:36:17nodes whenever it is coming you can
7:36:19simply handle with the help of this
7:36:21nested workflow and this is very much
7:36:23important whenever you are building any
7:36:25kinds of uh multi- aent system. Okay, in
7:36:29multi- aent system, this nested workflow
7:36:31is required that time. But this uh
7:36:33nested workflow functionality is not
7:36:35available inside langen. Inside lang
7:36:38actually we can't create this kinds of
7:36:40sub nodes and all this is not possible.
7:36:42Okay. So that's why uh you can call it
7:36:45uh this is as a feature inside lang
7:36:46graph as well. Now guys the last uh
7:36:50challenges will be understanding which
7:36:52is observable uh observability.
7:36:55So basically uh what is observability
7:36:59actually let's try to understand
7:37:00observability refers to how easily you
7:37:03can monitor debugs and understand what
7:37:06your workflow is doing at the runtime.
7:37:08So whenever we are running these kinds
7:37:10of runtime so definitely we have to uh
7:37:13continuously do the observation
7:37:14otherwise what will happen uh sometimes
7:37:17it will do some um let's say unexpected
7:37:20uh task right let's say you have run
7:37:23your um agents uh uh for the LinkedIn
7:37:28ads okay so let's say it is running the
7:37:30LinkedIn ads continuously and you will
7:37:33end up with lots of cost that time right
7:37:35let's say it's not necessary to run that
7:37:38much of uh LinkedIn ads or that much of
7:37:41budget right so that time uh if you're
7:37:43not doing observations so definitely you
7:37:46will end up with lots of cost uh so that
7:37:48that that's why observability is
7:37:50required but it's not like that we'll
7:37:51sit there manually observe all of the
7:37:54execution it's not like that so
7:37:56definitely we have to use some automated
7:37:57things that will continuously do the
7:38:00observation continuously do the
7:38:01monitoring uh and uh it will give me the
7:38:04report okay so fortunately in lang chain
7:38:08If I'm talking about Langshen, Langshen
7:38:11has
7:38:13um observability tool which is Langmith.
7:38:17Okay, I think you heard about Langmith.
7:38:19So, Langmith is a um like observation
7:38:23tool with the help of Lang Langsmith. We
7:38:25can continuously track the Lang Lang
7:38:28chain actually pipeline Langchen chain.
7:38:30So whatever lang chain um chain will be
7:38:32executed all of the uh all of the
7:38:35actually let's say parameter we can uh
7:38:38we can actually monitor here in the lang
7:38:40langismith will automatically monitor so
7:38:42by default lang langismith um can
7:38:44support this lang chain u monitoring
7:38:47okay and don't worry we'll try to
7:38:49understanding langismith as well
7:38:50continuously uh sorry uh going forward
7:38:53but what is the problem with the lang
7:38:56chain uh if you're using langismith with
7:38:58that uh see if you're implementing
7:38:59writing this workflow with the help of
7:39:01Langen. So definitely you have to write
7:39:02lots of glue code. I already told you
7:39:04right you have to write lots of glue
7:39:05code but glue code cannot be uh
7:39:08monitored with the help of lang.
7:39:10Langismith only can monitor your lang
7:39:12chain chain okay chain code or whatever
7:39:15you are writing inside that but if
7:39:17you're writing extra glue code you can't
7:39:19actually uh you can't actually uh track
7:39:22with the line speed this is not possible
7:39:23but if I'm talking about lang graph if
7:39:26I'm talking about lang graph okay lang
7:39:28graph is having very strong connection
7:39:31okay it is having very um strong
7:39:33connection with lang
7:39:37okay so that means whatever node
7:39:39execution you are doing one by one all
7:39:41of the node would be tracked in the lang
7:39:44smmith okay langismith and you can see
7:39:47each and everything okay so that's why
7:39:49this langu as a observ observability
7:39:52tool we'll be learning in this playlist
7:39:54as well in detail I'll tell you how to
7:39:56use the lang and all and how we can
7:39:58perform the monitoring operation of our
7:40:00agent each and everything we we'll also
7:40:02try to understand here okay this is
7:40:04super important and uh uh yeah I think
7:40:06this is a good practice to add the
7:40:08observability uh whenever you are
7:40:10creating the application because there
7:40:11you will get the enough understanding
7:40:12about your workflow execution okay at
7:40:15runtime this is super important so yes
7:40:18guys we are done with uh all of the
7:40:20challenges we have understood each and
7:40:22everything in detail now we'll try to
7:40:24conclude uh this video uh so before
7:40:27concluding let me tell you few things so
7:40:31guys so far we have understood uh about
7:40:33the langraph and difference between lang
7:40:36and lang graph um And I also uh showed
7:40:41you the challenges actually we will be
7:40:43facing. Okay. If you're using only
7:40:46langen okay if you're not using lang
7:40:48graph what would be the challenges. Now
7:40:51you have pretty much u good
7:40:53understanding about the langraph what
7:40:54exactly the lang graph is. But again I
7:40:56have given a definition you can see lang
7:40:58graph is an orchestration framework that
7:41:00enables you to build straightful
7:41:02multi-step and event-driven workflow
7:41:04using large language model. it uh it's
7:41:07deals uh ideal for uh designing both
7:41:11single agents and multi-agent
7:41:12applications. Think of a langraph as a
7:41:15flowchart engine for LLM. You define the
7:41:18uh steps nodes. Okay, we call it as a
7:41:20nodes how they are connected edges um
7:41:23and uh and the logic that um governs the
7:41:28transitions. Langraph takes care of
7:41:30state management, conditional branching,
7:41:32looping, pausing, resuming, fault
7:41:34recovery feature uh feature essential
7:41:37for building robust production grade AI
7:41:39system. Okay. So I think you have seen I
7:41:41have introduced so many um so many
7:41:43actually strong terms here like uh this
7:41:46uh edges branching looping pausing okay
7:41:49fault recovery. So now I think this uh
7:41:52these are the terms are clear because I
7:41:54have already clarified these are the
7:41:55terms then I given you the introduction.
7:41:57So at the very beginning I could have
7:41:59given you the introduction to this line
7:42:01graph okay uh this kinds of uh
7:42:03definition I can show you this uh this
7:42:05uh actually page I can show you but uh
7:42:08you won't be able to understand okay
7:42:10what the langraph is and you that time
7:42:12actually you are not familiar with these
7:42:13are the concept so what I have done
7:42:15actually I have clarified all the
7:42:17concept now I have given you the
7:42:18introduction okay I have given you uh I
7:42:20have uh told you what is line graph
7:42:22exactly okay now I think you are pretty
7:42:24much uh clear with now let's try to
7:42:26understand when to use what kinds of
7:42:29framework. So use langen when you are
7:42:31building simple linear workflow like
7:42:33prompt chaining summarization or basic
7:42:36retriever system chatbots okay these are
7:42:38the things and use langraph when you use
7:42:41case uh involves complex nonlinear
7:42:44workflow that needs conditional paths
7:42:46loops okay human in the loops concept
7:42:49and multi- aent coordination and
7:42:50asynchronous or even driven execution
7:42:52okay so now I think guys uh you have the
7:42:55understanding uh about uh this concept
7:42:58like when to use what kinds of
7:43:00framework. Uh so based on the problem
7:43:02statement you can decide whether you
7:43:04will be using the langen, whether you
7:43:05will be using the langraph for that.
7:43:07Okay. So now I think you have the enough
7:43:09understanding on that. Now one more very
7:43:12important things will be understanding
7:43:13at the last uh so see people uh people
7:43:17will uh I mean uh tell you like uh don't
7:43:20use uh lang chain lang chain is like
7:43:23deprecated and all okay so should we
7:43:25still use lang chain or not? because
7:43:27this kinds of question will definitely
7:43:28come and uh through the entire video
7:43:30actually I have given the appreciation
7:43:31to the langraph instead of giving to the
7:43:34langen okay but things is not like that
7:43:37see still we have to use this langen
7:43:40okay langen is required why because
7:43:43langraph is built on top of langen okay
7:43:46internally they're using langen only
7:43:49okay uh then they have created this
7:43:51langraph framework so it is basically
7:43:53handling the complex workflow okay the
7:43:56complex workflow uh by adding the
7:43:58nodding concept but internally it is
7:44:00using langen because if you see still
7:44:04you need langen components like if you
7:44:05want to load any kinds of llm you have
7:44:07to use chat openi or any other open uh
7:44:09let's say llm provider uh functionality
7:44:12if you want to create a prompt uh so you
7:44:14have to use the prompt template if you
7:44:15want to create a retriever system you
7:44:16have to use the retriever documents
7:44:18loader tools etc okay these are the
7:44:20things you will be only uh loading from
7:44:22the langen not from the langraph okay I
7:44:25think you get it And langraph handles
7:44:26workflow orchestration while langchen
7:44:28provides the building block for each
7:44:30steps in the workflow. That means langen
7:44:32is uh very important. Okay. But we can't
7:44:36use langen to build the entire complex
7:44:38workflow orchestration. Okay. We create
7:44:41this orchestration. We create this
7:44:42workflow orchestration with langraph.
Understanding LangGraph Core Components
7:44:44But internally langraph uses some langen
7:44:47building blocks like these are the
7:44:48building blocks to uh work on that.
7:44:50Okay. I hope this part is clear guys.
7:44:53Okay. So guys uh I think uh you have uh
7:44:57now clear and uh I mean enough amount
7:45:00understanding on this langraph lang
7:45:02chain uh you have got the detailed
7:45:05introduction to the langraph uh and uh
7:45:08don't worry I'm going to teach you the
7:45:11uh teach you all of the component of the
7:45:12langraph we'll be also building the
7:45:14agents with that okay each and
7:45:15everything we'll be covering um in this
7:45:18uh course itself okay now in this video
7:45:21I'm going to discuss uh some important
7:45:24core component of langraph because uh
7:45:27what I feel like uh before starting the
7:45:30actual langraph concept first of all
7:45:32let's try to understand the langraph
7:45:34core component so once we have
7:45:37understood the lang lang graph core
7:45:39component it would be easy for us to
7:45:42learn all of these component one by one
7:45:44then we can combine all of them together
7:45:46and we can build any kinds of agenti
7:45:49application so guys as you can see uh
7:45:52what is lang Lang graph lang graph is an
7:45:54orchestration framework for building
7:45:56intelligence stateful and multi-step L
7:45:59workflows uh it enables advanced
7:46:02features like parallelism loops
7:46:05branching memory and resumeumability
7:46:08making it ideal for agentic and
7:46:10production grade AI applications and
7:46:13lang models your logic as a graph of
7:46:15nodes basically we call it as a task and
7:46:18ages okay I think you saw there are some
7:46:21uh ages we are drawing um in my previous
7:46:24class right so uh we call it as a edges
7:46:26we also call it as a routing instead of
7:46:28a linear chain okay so in langen we used
7:46:31to create a linear chain but here uh we
7:46:34don't create the linear chain instead of
7:46:36that we try to make everything as a
7:46:38graph um and uh uh to make this graph we
7:46:42use nodes and edges okay inside line
7:46:44graph so let's say you are having a LA
7:46:46markflow so let's say this is our L
7:46:49markflow
7:46:52Okay, this is our LM workflow and this
7:46:54is called actually edges. Okay, this is
7:46:56called actually edges
7:47:00H. So let's say this is our LM workflow.
7:47:03Okay, I'll tell you more about this LM
7:47:05workflow. What is LM workflow is? LMA
7:47:07workflow is nothing but um I told you
7:47:10about the workflow, right? Workflow is
7:47:11nothing but it's a uh it's a process of
7:47:14executing a entire uh let's say
7:47:16application, entire problem statement.
7:47:18So basically we try to represent as a
7:47:20workflow and inside that we use LLM
7:47:23right. So that's why we call it as LM
7:47:25workflows. So you can see um this is the
7:47:28LM workflows. So here we pass any kinds
7:47:31of input. Okay. And all of these you can
7:47:35see node. Okay. This is called actually
7:47:36node. This is called actually node. This
7:47:39node can be called as a task. Okay. Task
7:47:43basically let's say you are having you
7:47:46are having a entire goal. Okay, entire
7:47:48goal. So to achieve this goal, what you
7:47:52have to do? We have to break down this
7:47:53goal as a task. Okay, different
7:47:55different subtask. And each of the
7:47:57subtasks can be represented as a node.
7:48:00Okay, in lang graph. So we try to
7:48:02represent as a node. So this node will
7:48:05perform all of the task. Let's say some
7:48:07of the let's say the first node is
7:48:09responsible for taking the input. Second
7:48:12node is responsible let's say preparing
7:48:14the prompt. Okay. Then third node is
7:48:16responsible for calling the LLM. Okay,
7:48:19that's how another node will be
7:48:21responsible for calling a tool. That's
7:48:22how it is defining a separate separate
7:48:25task as a node. Okay, I hope you get it.
7:48:28Now we also call it as a flowchart. We
7:48:32also call it as a flowchart. As you if
7:48:34you see this particular graph, this is
7:48:36kinds of flowchart. Okay. Now you can
7:48:39see inside lang graph we can perform
7:48:42this parallelism looping branching
7:48:45memory reasonability each and
7:48:47everything. So if I'm talking about the
7:48:48parallelism so lang graph can be also
7:48:51executed in a parallel. Okay, let's say
7:48:53here you are having
7:48:56a a node. Here also you are having a
7:48:57node. So both node can be executed
7:49:00parallelly. Okay, both node can be
7:49:02executed parallelly. Let's say you are
7:49:04preparing a prompt template and here you
7:49:06are calling the LM. Okay, so it's not
7:49:08like that after preparing the prompt
7:49:10template you will call the LM. Both you
7:49:12can execute in parallel, right? That's
7:49:13how there are so many problem statement
7:49:16you can I mean um consider here. Okay.
7:49:20Now it can also supports this looping
7:49:22concept. Looping concept means let's say
7:49:26sometimes let's say you are you are here
7:49:28in this particular node. Let's say after
7:49:30completing this node again you have to
7:49:32go back. Okay again you have to go back
7:49:35and uh again you will re-execute and
7:49:37again you will try to send to the
7:49:39another nodes. I think you remembered
7:49:41our previous uh uh previous actually um
7:49:45example I have given you that uh
7:49:47interview uh interview agent AI uh I
7:49:50think uh huh so interview uh interview
7:49:53system okay that interview system what
7:49:55happens let's say whenever u uh sorry
7:49:58not interview that was actually
7:50:00recruitment agent so that actually what
7:50:03happened let's say if uh if let's say
7:50:06your job description uh is not generated
7:50:08properly so what it will again it will
7:50:10go back and again it will regenerate. So
7:50:12this is called actually looping right?
7:50:14This is called actually looping. You're
7:50:15performing the looping here. Then you
7:50:17can also perform the branching
7:50:18operation. Branching means the
7:50:20condition. Let's say if this condition
7:50:22is not true. Okay that means if if it is
7:50:24not yes then it will go here. Okay
7:50:28that's how you are creating branch here.
7:50:29So this is called branching. Let's say
7:50:32uh if uh you didn't get uh 20
7:50:35applications again what you will do
7:50:36again you will try to um like uh change
7:50:39the job description and wait for the
7:50:41application submission. So this is
7:50:42called actually branching. So this
7:50:44branching also can be supported. Then
7:50:45memory. Memory means let's say each and
7:50:48every nodes whatever it is generating
7:50:50the output it would be stored inside a
7:50:52memory. Okay. It will remember that
7:50:54particular output and input as well.
7:50:56This is called memory. Okay. Then uh
7:50:58reasonability. Reasonability means let's
7:51:01say I told you about the um about the
7:51:03actually u problem okay problem means
7:51:06let's say somehow your one of the uh
7:51:09application got uh let's say got trouble
7:51:12that means it got stopped let's say it
7:51:14got stopped here only in this particular
7:51:15node okay in this particular node it has
7:51:17stopped so whenever you will uh
7:51:20reinitialize the instance so instead of
7:51:22running from the beginning it can resume
7:51:25from here only it can continue from here
7:51:27only this is called resumability
7:51:29Okay. So that's why uh we uh call it as
7:51:32a like a very powerful uh I mean
7:51:35framework this particular langraph
7:51:37because the way it is handling all of
7:51:39the let's say task all of the um system
7:51:43this is completely amazing right and
7:51:45that's why uh we can't use the simple
7:51:48lang chain here the linear chain here to
7:51:51solve this kinds of complex workflow
7:51:53that's why lang graph is required and
7:51:55this is what actually your lang graph is
7:51:57okay so basically here we will be
7:51:59working with the nodes and edges okay to
7:52:01make a graph okay instead of a linear
7:52:04chain I hope you understood guys okay
7:52:06now let's try to understand about the LM
7:52:09workflow um in more detail uh so you can
7:52:12see what is LM workflow first of all
7:52:15let's try to understand so LM workflows
7:52:18are step-by-step process using which we
7:52:21can build a complex LLM applications
7:52:24each steps in a workflow performs a
7:52:26distinct task such as prompting ing
7:52:29reasoning, tool calling, memory access
7:52:31or decision making. Workflows can be
7:52:33linear, parallel, branched or looped
7:52:35allowing for a complex behavior like uh
7:52:38retries, multi- aents communication or
7:52:41two augmented reasoning and we'll be
7:52:43discussing about some common workflows
7:52:45as well. So the first workflow as you
7:52:47can see this is the linear uh sequential
7:52:49workflow. We can also call it as a
7:52:51prompt chaining. So here what happens
7:52:53let's say whenever we are giving any
7:52:55kinds of input it will first of all go
7:52:57to LLM. Okay, LM call because I'm
7:53:01calling it as a LLM workflow and
7:53:02definitely inside the workflow
7:53:04definitely LLM call should be there.
7:53:06Okay, LLM should be there that time we
7:53:08can call it as LM workflows. Okay, if it
7:53:10doesn't have any kinds of LLM that time
7:53:12you can't call it as LM workflow. And
7:53:14now inside a workflow there can be one
7:53:17or multiple LM call. Okay, one or
7:53:19multiple LM call. It's not like that you
7:53:21have to only use one LM call or let's
7:53:24say 5 LM call or 100 LM call. You can
7:53:26use as many as LM you can inside a
7:53:29workflow but make sure LM call should be
7:53:32there otherwise we can't call it as LM
7:53:34workflow. Okay. So let's say this is our
7:53:36workflow. So first of all this input
7:53:38will get this particular LLM. Then here
7:53:40we are let's say doing a kinds of
7:53:42verification whatever output we are
7:53:45getting whether it is good or not. Okay.
7:53:47If it is good then we are passing it to
7:53:49the another LLM. Okay. for another task
7:53:52then uh it will uh send an again to
7:53:54another LM for another task then it will
7:53:57uh give you some kinds of output okay
7:53:59otherwise if this particular response is
7:54:01not good then it will exit the
7:54:03application okay so this is called
7:54:04actually linear workflow uh you can
7:54:06understand okay from this particular
7:54:09so here you can understand uh this
7:54:11particular concept from this uh workflow
7:54:14itself okay I hope you cleared
7:54:17now let's take an example to understand
7:54:19this prompt chaining workflow So let's
7:54:22say you are building uh you are building
7:54:24an agent that agent will take a topic
7:54:26okay topic name as an input okay so this
7:54:29input should be a topic name topic name
7:54:33and what it does it generates a complete
7:54:36report on that particular topics okay so
7:54:39I think previously you saw I created
7:54:41these kinds of agents with the help of
7:54:42langen so that I passed a topic and it
7:54:44was preparing a detail uh detail
7:54:47actually um scientific report on top of
7:54:49that Okay. So, [snorts] first of all,
7:54:51what you are doing, you are giving this
7:54:53particular topic name uh to the first
7:54:55LLM call and that means the first LLM
7:54:58and this LLM will try to uh we will try
7:55:02to generate something. Okay, we'll try
7:55:04to generate something. Let's say this
7:55:06particular LLM um has generate a draft
7:55:09from this particular topic. Okay, so
7:55:11let's say it has generated a draft.
7:55:14Okay, draft. Now here you are doing a
7:55:16verification. Let's say you are writing
7:55:18a condition if this particular draft is
7:55:21more than 5,000 word. Okay, it is more
7:55:24than 5,000 word that time you are not
7:55:26going to take. You simply uh exit the
7:55:28application. Okay, you only take less
7:55:29than 5,000 word. So if it is less than
7:55:325,000 word then again what you will do
7:55:33again you will pass to the allar LLM.
7:55:36Let's say this LLM does the u review
7:55:39operation. Okay, review operation that
7:55:42means it will perform the review
7:55:44operation. The draft you have prepared.
7:55:46If review is completely fine, if it
7:55:48pass, okay, then it will go to the next
7:55:50LLM. This LLM will try to write this
7:55:52particular draft in a file. Okay. Uh
7:55:55write
7:55:58okay write this particular draft in a
7:56:00file. Then you will get the output.
7:56:02Okay. So this is the example you can
7:56:04consider about the prom chaining. Okay.
7:56:06So inside prompt chaining what you are
7:56:07doing? You are trying to break down a
7:56:09task. Okay. Um and you are trying to
7:56:12solve it. Okay. Step by step. This is
7:56:14called prom chaining. Now let's try to
7:56:16understand about the another uh LM
7:56:19workflow which is routing. Okay. So this
7:56:22is another kinds of LM workflow. Um uh
7:56:25this is called routing. Routing means
7:56:27here you are getting an input and you
7:56:29are using a LM um definitely LLM call.
7:56:33But this LLM call we are considering as
7:56:35a router. Router means it will basically
7:56:38route uh route the route the task. Okay.
7:56:42route the task to different different
7:56:43LLM. Okay, as you can see, let's say
7:56:45this is LLM 1, this is LM2, this is LLM
7:56:473. Okay, and here we are getting the
7:56:49output. So let's say you are building a
7:56:52customer uh support application. Let's
7:56:55say for the tech company. So there you
7:56:57are getting different different let's
7:56:58say customer questions. Let's say uh you
7:57:01are getting related um let's say you are
7:57:03running an ad tech company. Uh you are
7:57:05let's say getting the question related
7:57:07about your service. Okay. The service
7:57:09you usually provide uh let's say
7:57:11whatever course you provide. Okay.
7:57:13Whatever let's say content you are
7:57:16providing this kinds of service people
7:57:18are asking about. So let's say the first
7:57:20LM we we just let's say defined this
7:57:25service task to the first LM that means
7:57:27the prompt we have written here. So this
7:57:29particular LM will try to only handle
7:57:32about our service. Okay. Service related
7:57:33query. So let's say this is the service
7:57:36uh service lm. Okay. Now the next let's
7:57:39say t uh next let's say um uh I mean um
7:57:43task which is uh about our um
7:57:47about our let's say what I can say um
7:57:52or let's try to consider about a
7:57:54technical query
7:57:56technical query
7:58:01technical query okay technical query
7:58:03means let's say people are having a
7:58:04doubt related Python or machine learning
7:58:08deep learning whatever. So this
7:58:09particular LM will try to handle that.
7:58:11Let's say this is the tech LLM. Okay.
7:58:13Now there is another LM. This LLM will
7:58:15try to give you the interview related
7:58:17help. Okay. Interview preparation
7:58:20related help. Let's say you want to
7:58:22prepare for the interview. So uh this
7:58:25particular LM will try to handle the
7:58:28interview related task. Now whenever any
7:58:31kinds of student is giving the input
7:58:33let's say student asking about the
7:58:35services okay the service we usually
7:58:37provide in the DS with BP okay D with BP
7:58:40whatever service we provide he's asking
7:58:43for now what this LM router okay LLM
7:58:46call router will do it will
7:58:47automatically understand about your
7:58:49questions and it will decide when to
7:58:51send this where to send your question
7:58:54whether it has to send to the LM call uh
7:58:57sorry uh service service LLM whether it
7:58:59has to say uh send to the tech lm or
7:59:01whether it has to send to the interview
7:59:02lm. So definitely this is kinds of
7:59:04service related query it it will send to
7:59:07the service LLM here. Okay. And service
7:59:09LM will try to give you the response and
7:59:11you will see the output. Now let's say
7:59:12someone is asking about the technical
7:59:14query. Let's say he is getting uh Python
7:59:17uh function error. So that time LM
7:59:19router will understand okay now I have
7:59:21to send to the tech lm. TechM will give
7:59:23you the output and you will be able to
7:59:24see the output. Now there is another
7:59:26let's say question you are getting
7:59:27related interview. Your LM router will
7:59:29send to the interview LLM and you will
7:59:31be getting the output. Okay. So this is
7:59:33called actually routing workflow.
7:59:34Routing LM workflow. This kinds of
7:59:37workflow we can easily create inside the
7:59:38line graph. Okay. So definitely we'll
7:59:40try to also discuss about that. Now
7:59:42let's try to understand about the next
7:59:44workflow which is uh paraly um par uh
7:59:48parallelization.
7:59:50Inside parallelization actually what we
7:59:52can do we can execute uh the task in
7:59:55parallel. So let's try to understand uh
7:59:58this particular concept as well. As you
7:59:59can see, let's say here we are getting
8:00:01the input and some multiple LM call is
8:00:04happening. Okay, let's say LM 2, LM 1,
8:00:06LMU 2 and LM3. Then we are performing
8:00:09the aggregator operation, then we're
8:00:10getting the output. Okay. So if I'm
8:00:12giving you a realtime example, let's say
8:00:15uh I'm a YouTuber definitely I just try
8:00:17to upload my content to the YouTube and
8:00:20by default YouTube also
8:00:23YouTube also use internally this uh um I
8:00:26mean AI related uh functionality. Okay.
8:00:30So with the help of AI actually it u
8:00:32what it do it it try to let's say uh do
8:00:36the verification check of your content.
8:00:38Let's say the content we're uploading to
8:00:40the YouTube. Okay. Okay, let's say I
8:00:41have recorded a video. Okay, I have
8:00:43recorded a video. So, first of all, you
8:00:45will upload that video and it's not like
8:00:47that YouTube will directly take that
8:00:49video and uh it will allow you to
8:00:51publish. First of all, it will do some
8:00:53uh verification.
8:00:55Okay, verification.
8:00:57Verification means let's say it can be
8:01:00multiple layer verification. The first
8:01:01is let's say whether it is any uh
8:01:05unappropriate content or not.
8:01:11appropriate content or not. Then it will
8:01:13check whether it is sexual content or
8:01:16not. Then it will check whether this
8:01:18content is uh having any kinds of uh any
8:01:22kinds of let's say abusive or not. Okay.
8:01:25So this kinds of let's say multiple
8:01:27layer verification it will do. Now here
8:01:29what we can do for each of the
8:01:32verification maybe we can use different
8:01:34different task different different let's
8:01:36say LLM call for that. Let's say the
8:01:38first one is responsible for checking
8:01:41unappropriate
8:01:43okay unappropriate verification. Second
8:01:46one let's say it is responsible for
8:01:49sexual verification and third one is
8:01:51responsible for let's say um abusive
8:01:55verification. Now it's not like that
8:01:57after checking this unappropriate
8:01:59verification you have to do the sexual
8:02:00verification or after checking the
8:02:01sexual sexual verification you have to
8:02:04check for abive verification. It's not
8:02:05like that. All of the checks are
8:02:08independent here. Okay. So instead of
8:02:10running sequentially, you can run in
8:02:12parallel. So parallelly all of the check
8:02:14will done. Okay. Once you will get all
8:02:16of the um let's say check check uh let's
8:02:19say ratings and answer. Then we'll try
8:02:21to aggregate them together. Okay. Let's
8:02:23say it will give you some kinds of
8:02:25rating. Let's say it has given you 9.5
8:02:27out of 10. Okay. That means this video
8:02:29is good. It it has also given you let's
8:02:31say 9.6 around 10. Okay. It has also
8:02:34given you 9.5 around 10. Then you are
8:02:36combining all of them together. You are
8:02:38making the average and let's say there
8:02:40is a condition uh there is a average
8:02:42threshold. Let's say if this threshold
8:02:43is matching that time you will try to
8:02:45accept this video otherwise you'll try
8:02:47to reject the video then you are getting
8:02:49the output here. Okay. So that's how
8:02:51this parallelization
8:02:53will be working and uh this kinds of
8:02:55workflow also we can easily create uh
8:02:57inside our langraph as well. Okay. Now
8:03:00the next uh workflow let's try to
8:03:02understand which is this orchestrator
8:03:05workflow. Okay. So this is uh this is
8:03:07the same kinds of uh I mean paralleliz
8:03:10uhization actually workflow as you can
8:03:13see we are also taking all of the result
8:03:16and we are also doing the aggregator
8:03:18operation and we're getting the output
8:03:20but the only difference is uh let's uh
8:03:23let's try to discuss about
8:03:25so in this workflow uh as you can see um
8:03:29before this uh uh before this particular
8:03:32section there is another section we have
8:03:35which is orchestrator. Okay,
8:03:36orchestrator is uh another you can say
8:03:38lm um lm uh call. So basically this is
8:03:42the main okay lead uh lead actually um
8:03:47uh lead nodes this particular nodes will
8:03:49decide uh a particular task it is
8:03:53getting uh so what to assign whether it
8:03:55will assign to the llm 1, llm 2 and lm
8:03:583. Okay, it will basically decide but if
8:04:00you see the previous one the
8:04:02parallelization one. So basically here
8:04:04we are uh uh setting the task. Let's say
8:04:07here we are assigning the task. Let's
8:04:08say LM uh one will get the task related
8:04:11unappropriate content. LM will get the
8:04:13task related uh let's say uh sexual
8:04:16content and LLM3 will try to get the
8:04:19task related abive content. We defining
8:04:21the task but here there is no task
8:04:23nature. Okay. So basically your
8:04:25orchestrator will decide where to set
8:04:27this particular task. Okay. So uh based
8:04:30on the orchestrator uh it will define
8:04:32let's say it can define to llm 1 lm 2
8:04:35and lm 33 okay it doesn't matter but it
8:04:37will decide okay which one would be
8:04:38appropriate for this particular task
8:04:40then once we are getting this we are
8:04:42again doing the synthesizer that means
8:04:44aggregating and we're getting the output
8:04:46okay so your orchestrator can also
8:04:48define this particular task to only lm1
8:04:50okay or let's say it can define the task
8:04:52to lm1 and lm3 it doesn't matter okay
8:04:55based on the task it will decide it can
8:04:57either give to the uh let's multiple LM
8:05:00either it can give it to the one LM.
8:05:01Okay. So this is called actually
8:05:02orchestrator workflow. I hope you get
8:05:04it. Okay. So this is the similar kinds
8:05:06of your parallelization. Now the next
8:05:08workflow you are having this evaluator
8:05:11optimizer.
8:05:12Okay. So what this evaluator optimizer?
8:05:15So I think by the workflow itself you
8:05:17can understand uh the uh actual uh
8:05:21example. Okay. How this will work. So
8:05:23basically it has one LM call generator.
8:05:26Okay. LM call generator. uh this
8:05:28particular uh section and it it is
8:05:31having another one called LM call
8:05:33evaluator. Okay. So basically whatever
8:05:35input you are getting giving first of
8:05:37all LM this LM call is generating this
8:05:40particular output then you are sending
8:05:42to the LM call evaluator and it is
8:05:44checking okay it is checking uh whether
8:05:47it is good or not. Okay whether it is
8:05:49good or not and if it is not good it
8:05:51will reject and with the reject it will
8:05:54also give some kinds of feedback like
8:05:55what to update next. Okay. So this will
8:05:58get again uh this particular LM call
8:06:00generator the rejection parameter as
8:06:02well as the feedback. Based on the
8:06:04feedback again it will try to based on
8:06:06the feedback again it will try to
8:06:07generate. Okay. Again it will try to
8:06:08send to the LM call evaluator. Okay.
8:06:11Then if it is good then it will accept
8:06:12and you'll see the output. Okay. And
8:06:14this particular loop will be
8:06:15continuously happening unless and until
8:06:17this LLM uh call evaluator will accept
8:06:20your content. Okay. So I think you know
8:06:22that in our uh that uh recruitment agent
8:06:26I told you about the job description
8:06:27right. So let's say one of the LM will
8:06:30generate the job description here. Let's
8:06:31say this is this is uh generating the
8:06:34job description and another LM you're
8:06:36using for verifying the job description
8:06:38whether it is perfect or not. If not
8:06:40perfect it will give you some kinds of
8:06:41rejection and the feedback. Again it
8:06:43will try to generate the job
8:06:44description. Again it will send and if
8:06:46job description is fine then it will
8:06:47accept it um that particular job
8:06:49description. Okay. I hope you get it
8:06:51guys. So guys, I have shown you I think
8:06:55uh five workflows here. 1 2 3 4 and
8:07:01five. Okay. So five different LLM
8:07:03workflows I have explained here. And
8:07:04don't worry I'm going to um I'm going to
8:07:07cover these are the workflow in this
8:07:09particular playlist itself. Okay. We'll
8:07:12try to see all of the workflow one by
8:07:13one. Now the very important concept
8:07:16we'll try to understand about the um
8:07:20langraph uh components okay we'll try to
8:07:22understand lang graph core uh components
8:07:25uh which is graph nodes and edges okay
8:07:28although I've given you the highle
8:07:30overview in my previous video what is
8:07:31graph nodes and edges but still we'll
8:07:33try to understand this particular
8:07:35concept in detail so for this here what
8:07:38I'm going to do I'm going to take an
8:07:40example I'm going to take a problem
8:07:42statement and this problem statement
8:07:44we'll try to uh define as a graph okay
8:07:47define as a workflow then we'll try to
8:07:49understand these are the concept so guys
8:07:52uh as you can see here I have taken an
8:07:54example um so let's say here we want to
8:07:57create a system uh that generate a uh SE
8:08:01topic okay I think you know about SE uh
8:08:04so whenever you are let's say going for
8:08:09any big uh universities
8:08:12uh so basically you have to submit
8:08:15there. Okay. Uh bas based on the topic.
8:08:18So let's say uh what it does it uh
8:08:20collects the student uh SE submissions
8:08:24and it evaluates in parallel on depth of
8:08:27analysis, language quality and clarity
8:08:30of thoughts based on the combined score.
8:08:33It either gives the feedback for the
8:08:35improvement or approach that I see.
8:08:37Okay. So to build this particular system
8:08:40first of all we have to uh break down
8:08:42the task okay let's say this is the
8:08:44entire goal okay this is the entire goal
8:08:46of our system now to achieve this goal
8:08:48we have to define uh a set of task okay
8:08:51the let's say first task what it would
8:08:53be so let's say this particular system
8:08:55will first of all generate a se right
8:08:57the uh first of all we have to generate
8:08:59a topic so system generate a relevant uh
8:09:03UPS style as topic and uh present in uh
8:09:08pres present it to us to the student
8:09:10let's say uh you are giving UPSC exam
8:09:13that time let's say the this particular
8:09:15essay topic you have to prepare okay
8:09:17then you have to collect the SE from the
8:09:19student so student write and submits the
8:09:21SE based on the generated topics okay
8:09:24you you will try to collect that after
8:09:26collecting uh your system will evaluate
8:09:28the SE okay parallel evaluation block
8:09:30because here we will be evaluating based
8:09:32on the analysis language quality clarity
8:09:35of thought so All of the checks we are
8:09:38doing, all of the evaluation checks we
8:09:39are doing based on the language, based
8:09:41on the um language quality, then
8:09:44analysis, okay, clarity of thought, we
8:09:46are checking each and everything. Okay.
8:09:48So after getting the evaluation report,
8:09:50we are aggregating the results. Let's
8:09:52say the combined the three scores and
8:09:53generate the total scores. Uh let's say
8:09:55we got the three scores all together.
8:09:57Then we combined them and we got one
8:09:59average score and we matched with the
8:10:01threshold. Now here there is another uh
8:10:04task you can see conditional routing. So
8:10:06based on the total score either you will
8:10:08uh accept that particular
8:10:11SC otherwise you will give the feedback
8:10:13let's say again you have to update this
8:10:15particular SC. Okay. So then then you
8:10:17can see we are uh our next is the give
8:10:20feedback based on the uh conditional
8:10:22routing that means aggregating results
8:10:24we are giving the feedback and there is
8:10:26another option we have kept. Let's say
8:10:27if user wants to uh give the uh revision
8:10:30version of that particular AC, they will
8:10:31be able to do that. Then at the last
8:10:33we'll try to show the success uh message
8:10:35to the um student. Okay. If your if
8:10:39their essay is good, then we'll try to
8:10:40congratulate them. Okay. So this is the
8:10:42entire let's say um problem. Now if I
8:10:45want to uh if I want to represent with
8:10:47the help of lang graph. So first of all
8:10:49we have to make it as a graph. Okay. I
8:10:51think you know lang graph um make every
8:10:54let's say problem statement as a graph
8:10:56as a workflow. Okay. So basically it
8:10:58will represent as a graph after
8:11:01representing as a graph then what it
8:11:04will do it will try to uh take all of
8:11:07this task as a node. Okay all of the
8:11:09task as a node then it will connect the
8:11:11edges let's say after uh which node
8:11:15another node would be executed. Okay
8:11:17this particular connection will be do
8:11:19doing with the help of edges. So for
8:11:20this I have already prepared a um graph.
8:11:23Let me show you. Let's say this is our
8:11:25uh line graph graph we have prepared.
8:11:27Okay. So you can see uh whatever problem
8:11:30statement I have showed you here. So I
8:11:31have just represent as a graph. First of
8:11:33all it will generate a topic. So this is
8:11:35the first you can see this is the first
8:11:40uh first task right. Let me just write
8:11:43here this is the first task.
8:11:46Okay. because we broken down our entire
8:11:50goal as a task and generate topic was
8:11:52one of the task and this task we
8:11:54represented as a node okay this is
8:11:56called actually node each and every
8:11:58block is a node here okay now this is
8:12:00another task as you can see right AC
8:12:02right as means you can also let's say
8:12:05take the from the student okay user will
8:12:08upload that student will upload that
8:12:10then after uploading you are doing the
8:12:12evaluation here okay so this uh this
8:12:15evaluation is also another task another
8:12:17node. So this is also node this is uh
8:12:19this is also node this is another node
8:12:21this is another node this is another
8:12:22node so here we are let's say evaluating
8:12:24with the with respect to the clarity of
8:12:26thought depth of analysis lang base then
8:12:28we're getting some kinds of score here
8:12:29okay let's say we are getting some kinds
8:12:31of score let's say this this one is
8:12:33given you 9.5 this one is given you 9.8
8:12:35need this one is giving you 8.5. Okay,
8:12:38based on that we are doing the final
8:12:39evaluation. We are aggregating the
8:12:41results. Let's say our threshold is 9.5
8:12:45and after combining all of these we are
8:12:47getting uh 9.5 or greater than 9.5 then
8:12:50that time what I will do I'll just try
8:12:52to simply give the success message to
8:12:53these students. Okay, let's say I will
8:12:56congratulate them otherwise I will give
8:12:58the feedback. Let's say this is another
8:13:00another node. In this particular node
8:13:02I'll give the feedback. So in the
8:13:03feedback itself I'll tell what to update
8:13:06otherwise they can also resubmit that
8:13:08particular hy to me. Okay. So this is
8:13:10the entire representation and you can in
8:13:12the representation itself you can see
8:13:14this is the entire graph. Okay. This is
8:13:15the entire langraph graph and each of
8:13:18the task is a node. Okay. Each of the
8:13:20task is a node and the connection you
8:13:22can see this particular connection this
8:13:23is called edge. Okay. This edge is
8:13:25represents after generate topics write a
8:13:28will execute. After write a this uh
8:13:31evaluation uh let's say nodes will
8:13:33execute. After evaluation this final
8:13:35evaluator node will execute. Okay. Then
8:13:38either it will go to this access nodes
8:13:40either it will go to the feedback nodes.
8:13:41Okay. This is called ages. This is
8:13:42called connection. Okay. So if you
8:13:44understand this thing guys it will be
8:13:46very easy for you to create any kinds of
8:13:48langraph graph for you. Okay. And you
8:13:51can represent any kinds of problem
8:13:52statement in a graph. Okay. I hope you
8:13:54clear guys. So guys, now we'll be uh
8:13:57discussing about the next uh line graph
8:13:59component which is state. So I think you
8:14:02know already about this state. I have
8:14:04given you the state overview in my
8:14:06previous video. But let's try to
8:14:07understand. So as you can see in lang
8:14:09graph state um it is the shared memory
8:14:12that follows through uh your workflows.
8:14:15It holds all the data being passed
8:14:18between nodes as your graph runs. Okay,
8:14:21as your graph runs. So as you can see uh
8:14:23this is uh how your uh state looks like.
8:14:27So this is a kinds of u like python
8:14:31object okay python uh kinds of
8:14:33dictionary object it is having the key
8:14:35key and value pair either you can create
8:14:37this with help of pentic okay pentic
8:14:41uh library with uh inside python either
8:14:43you can also create it as a type dict
8:14:46okay type dict both you can use to
8:14:49define this particular state uh memory.
8:14:51So I think you know that uh to run a LM
8:14:54workflow let's say this is our complete
8:14:56LM workflow we need this kinds of state
8:14:58that means some metadata informations
8:15:01because each of the nodes will generate
8:15:04some kinds of output and that particular
8:15:07output will take uh taken by another
8:15:09nodes okay let's say this generate topic
8:15:12will generate some kinds of topic okay
8:15:14topic name so this topic name will go to
8:15:16the next node which is this right a
8:15:19because uh on top of that your um essay
8:15:22will be written right so that means
8:15:23whatever topic uh this particular node
8:15:26is generating this should be stored in
8:15:28this state memory and the next node
8:15:31let's say this write as a we'll take
8:15:33that particular topic and it will write
8:15:34that content as well so after writing
8:15:36this content this content would be also
8:15:39saved in the state memory so you can see
8:15:40there is another section called text
8:15:42topic okay then we are uh evaluating the
8:15:45scores and all of these uh scores would
8:15:48be saved in this uh this uh uh statement
8:15:51memory. You can see they have this
8:15:52score, language score, clarity score. So
8:15:54after this score, you will perform the
8:15:55final evaluation. Okay. So totally score
8:15:57would be also saved. Then you will be
8:15:59giving the feedback. This feedback will
8:16:00be al also saved. Then evaluation round
8:16:02it will also save. Okay. So that means
8:16:05uh to execute the entire nodes to
8:16:07execute the entire workflow you need
8:16:09this particular state. And this state is
8:16:11a shared okay it's a shared memory. As
8:16:13you can see it's a shared memory. Shared
8:16:15memory means each of the nodes will take
8:16:17this particular state as an input. Okay.
8:16:20Each each of the node will take this
8:16:22particular state as an input. All of the
8:16:24node okay all of the node will take this
8:16:25particular state and after taking it
8:16:28once it will generate some output this
8:16:30output will be instantly updated in that
8:16:32particular state. Okay, that's why this
8:16:34state is mutable as well. Okay, mutable.
8:16:37Mutable means you can change it any time
8:16:39and after exe uh every execution this
8:16:43state would be uh saved. Okay, because
8:16:46this is completely dynamic and this is
8:16:49required guys. Okay, without that
8:16:51actually um you can't create any kinds
8:16:53of agent application inside line graph.
8:16:56Okay, this state is required.
8:16:58So yes, I think you have understood and
8:17:00uh whenever we'll try to um uh create
8:17:03these kinds of uh uh application
8:17:06definitely we'll uh define this state at
8:17:08the very beginning either we can use p
8:17:10identicular we can use type dict for
8:17:12that okay and we'll try to define this
8:17:14state and for your problem statement you
8:17:16have to define the state like what are
8:17:18the variable you'll be keeping here what
8:17:21data uh you you feel like okay this
8:17:24should be updated to run your entire
8:17:26agents okay this thing will try to uh
8:17:28define at the very beginning. Now let's
8:17:30try to understand the next uh component
8:17:33of lang graph which is reducer. So what
8:17:36is reducer exactly? Uh so reducer in the
8:17:39lang graph defines how updates from
8:17:41nodes are applied to the shared state.
8:17:44Each key in the state can have its own
8:17:47reducer which determines whether new
8:17:50data uh replaces, merges or adds to the
8:17:52existing value. So if you see this
8:17:55reducer is very close to your state.
8:17:57Okay, this is very close to the state.
8:17:59That means whenever you are defining the
8:18:01state that time reducer will come to the
8:18:03picture. Okay, so let me give you one
8:18:05example. Uh see as of now what we are
8:18:08doing let's say whatever we are getting
8:18:10the data from each and every nodes we
8:18:14are directly updating in the state
8:18:15memory. Okay, I think you know that and
8:18:17this state is a shared uh shared uh
8:18:20actually memory and it it is accessible
8:18:23to all of the nodes here. Let's say this
8:18:24nodes will also take this state. These
8:18:26nodes will also take this states. Okay,
8:18:27all of the nodes will take this state
8:18:28and it will update in real time. That
8:18:31means every time the value uh you are
8:18:33changing here it is replacing okay let's
8:18:35say previously you you generated a topic
8:18:38let's say topic a so again whenever you
8:18:40will second time execute that this topic
8:18:42will replace that means the previous
8:18:43topic will be removed okay that that
8:18:45means we are replacing the value that's
8:18:47how depth score language score clarity
8:18:50score acetics okay so all of the
8:18:53parameter you are changing every time
8:18:54and your previous uh information you are
8:18:56losing but let's say sometimes
8:18:59uh let me give you first of One example
8:19:01let's say you are creating an
8:19:02application okay you are uh you are
8:19:05building an application that application
8:19:07let's say um takes two number so let me
8:19:10just give you the workflow let's say
8:19:14takes two number a and b after that it
8:19:17perform the sum operation okay then
8:19:20whatever sum you get okay it perform the
8:19:24multiply operation with three okay then
8:19:27it shows the result
8:19:30result. Let's say this is your
8:19:31application. Now in this application,
8:19:32what would be the state? If you consider
8:19:34state, so state would be first of all
8:19:37the first number.
8:19:39First number,
8:19:43okay, first number should be state then
8:19:45second number
8:19:49then the result.
8:19:53Okay. So this this is this is your
8:19:55state. So what will happen? Let's say
8:19:57you are giving two number. First number
8:19:58is five, second number is six. And if
8:20:01you do the sum operation, what would be
8:20:02the result? It would be 11. Okay, 11.
8:20:06But if you see you are multiplying by
8:20:08three. Okay, if you multiply by three,
8:20:10so what will happen? This result will be
8:20:12replaced. That means previously it was
8:20:14uh previously it was 11. Now I'll rub
8:20:17this 11. Initially after summing the
8:20:20result is 11. Now you have to multiply
8:20:22by 3. So if you multiply by 3 that means
8:20:24this 11 will be replaced by 33. Okay
8:20:28that means this 11 is not there anymore.
8:20:30Okay, this is changed completely. But in
8:20:33some application, let's say uh let me
8:20:36give you another example. I will
8:20:39rub this. Now, let's say you are
8:20:41creating a chatbot.
8:20:43You're creating a chatbot.
8:20:46In the chatbot, what you are doing? You
8:20:47are doing the conversation uh to the uh
8:20:50AI uh your conversation to the uh
8:20:53application. Let's say this is your app.
8:20:56Okay, this is your app and you are doing
8:20:57the conversation. So in this uh
8:20:59application what would be the state?
8:21:01State state it would be the let's say
8:21:03message the message we are sending or
8:21:05message we are getting from the um
8:21:08application. So initially let's say you
8:21:10have given hi
8:21:13I am bi
8:21:16okay let's say this is your message. So
8:21:17this message would be saved here. Let's
8:21:19say hi,
8:21:23I am BP. Okay. Now let's say second time
8:21:25you have given uh I like
8:21:29football.
8:21:31Okay. Now this message will be replaced.
8:21:33Okay. Let's say this this will removed
8:21:35and it will replace by I like
8:21:40football.
8:21:41Okay. Football.
8:21:43Now if you ask what is my name? So that
8:21:47time um let's say your nodes won't be
8:21:50able to uh get get your name because
8:21:52this this name is already removed okay
8:21:54from the state memory. Now you only have
8:21:57I like football okay this is the
8:21:58problem. So in this case if you're using
8:22:01only state without reducer that time it
8:22:03will replace that but if you're using
8:22:05reducer okay inside reducer you can
8:22:08define whether you have to okay you have
8:22:12to replace the data or merge the data or
8:22:15add the data. So in this case maybe we
8:22:17can add the data. So that means my
8:22:18previous message would be also there.
8:22:20Let's say I am bi
8:22:24after giving a comma maybe I can add the
8:22:26second message. That's how continuously
8:22:28all of the messages would be saved here.
8:22:30Either you can merge, either you can
8:22:32replace, everything can be defined with
8:22:33the help of this reducer. Okay. So that
8:22:35means the reducer in langraph defines
8:22:37how updates from nodes are applied to
8:22:39the shared state. Okay. That means
8:22:41whenever you are creating the state that
8:22:43time you can define all of the state
8:22:46data you are preparing, right? Whether
8:22:47it should be addable, it should be
8:22:49mergible or it should be replaceable.
8:22:51Okay. So in this case let's say we have
8:22:53defined this particular state. So in the
8:22:55feedback section you can see we have
8:22:57given add. Add means instead of uh let's
8:23:00say replacing the feedback it will
8:23:03continuously add. Let's say this is our
8:23:04example I showed you. So in this example
8:23:06let's say the feedback we are getting.
8:23:08So this feedback should be definitely
8:23:09saved in the state memory. So next time
8:23:11whenever it is executing okay it will
8:23:14see that particular feedback the
8:23:15previous feedback then it will give the
8:23:16new feedback otherwise what will happen
8:23:18the same feedback continuously it might
8:23:19give right? So that's why it should be
8:23:21addable. Okay, it should be addable
8:23:23inside state memory. So this is the work
8:23:25of reducer and definitely we'll also
8:23:28learn um by a project okay uh in this
8:23:31particular playlist there I'll try to
8:23:32use this reducer concept as well with
8:23:34the state. So there this part would be
8:23:36more clear. So I think guys now you got
8:23:38it what is the reducer? So reducer only
8:23:40can be used whenever you are using the
8:23:42state concept inside the line graph.
8:23:44Okay now I think it is clear. So guys
8:23:46now we'll be understanding the last
8:23:49concept of this lang graph which is lang
8:23:51graph execution model. So what is this
8:23:53lang graph execution model means that
8:23:56means uh the way it is executing the
8:23:59graph because I think you know lang
8:24:01graph internally defines uh your problem
8:24:04statement as a graph. It creates the
8:24:06nodes then uh it creates the edges. Okay
8:24:10that's how basically it executes
8:24:12everything. So what is the execution
8:24:15process of this particular graph? Okay,
8:24:17this is called actually execution model.
8:24:19So lang graph internally follows uh one
8:24:23amazing execution uh model strategy
8:24:26which is u let me show you which is
8:24:30actually google uh pragle. Okay, pragle.
8:24:33So what is Google pragle? Google pragle
8:24:34is a system for large scale graph
8:24:36processing. Uh so basically uh they have
8:24:39published this particular research long
8:24:41uh uh long ago that time actually they
8:24:44showed if you are having a large scale
8:24:46graph okay that time how it can be
8:24:48processed okay so internally lang graph
8:24:50uses the same technique uh for executing
8:24:53this kinds of graph
8:24:56because if you see the langraph uh
8:24:58actually graph uh whenever you are
8:25:00creating very big workflow that time
8:25:02this graph would be also big and to
8:25:04process this to execute this you have to
8:25:06follow that pragle strategy. Okay. Now
8:25:09this is the strategy guys. As you can
8:25:11see here I have already defined all of
8:25:13the uh execution process. So first of
8:25:16all what happens uh if you see here
8:25:18first of all it defines uh the graph.
8:25:21Okay. So whenever you are giving any
8:25:23problem statement uh it it will define
8:25:25the graph. So whenever it will define
8:25:27the graph first of all it will define
8:25:29the state schema that I showed you
8:25:32showed you about the schema right uh
8:25:33state schema. uh either you can uh do it
8:25:36with the help of pentic with the help of
8:25:38uh type dict okay you can you you just
8:25:40need to define this schema after that
8:25:43you have to prepare the node and edges
8:25:45okay so this node and this edge
8:25:47connection okay so fun uh and what is
8:25:50node actually this node is nothing but
8:25:52it's a simple python function okay it's
8:25:55a python function only if you can write
8:25:56a python function if you can write a
8:25:58python code you can just define any
8:26:00kinds of node okay because each of the
8:26:02nodes is responsible for a specific task
8:26:04And this task you are solving inside
8:26:06this Python function only. Okay, that's
8:26:08it. And what is edges? Which node
8:26:10connects to uh which okay that means
8:26:12this particular ages will be connecting
8:26:14to another nodes. Okay, like the
8:26:16execution flow like after this node
8:26:18which node would be executed. So once
8:26:20you have defined this particular graph
8:26:23then next step you will do the
8:26:24compilation. So here we'll do the
8:26:27compile. Compile operation compile means
8:26:28let's say you have created a uh graph.
8:26:30Let's say this is your graph. Okay, this
8:26:32is your graph and this is the age
8:26:34connection and let's say you created
8:26:35another node but this node doesn't have
8:26:37any kinds of connection. Okay, so after
8:26:39doing the compilation you will be able
8:26:41to understand okay this node doesn't
8:26:43have any kinds of connection that means
8:26:45there's some problem with the graph.
8:26:46Okay, otherwise what will happen? Our
8:26:47entire agentic system will be okay uh
8:26:50terminated. So that's why after defining
8:26:52the graph we have to do the compilation
8:26:54to checks the graph structure and
8:26:56prepared prepares for the execution.
8:26:58Okay. Then the uh third thing we'll be
8:27:00doing the invocation operation. So
8:27:02invocation operation that means uh
8:27:04whatever first node we have prepared
8:27:06we'll try to do the invoke operation
8:27:07with our initial state. The state we are
8:27:10preparing we'll try to pass to this uh
8:27:12pass to this initial actually nodes and
8:27:14this initial nodes what it will do it
8:27:16will take this uh state and it will
8:27:18execute and it will generate some kinds
8:27:20of output and this output would be also
8:27:22updated in the state. Okay. So once it
8:27:25has updated to the state then this state
8:27:27will go to the another function okay
8:27:29another another nodes and this node
8:27:31would be also initialized that that
8:27:33means activated okay so after giving
8:27:35this initial state this node would be
8:27:38activated and once you get some kinds of
8:27:40output from this node then it will pass
8:27:42to the next one the next one would be
8:27:44activated okay so this is called
8:27:46actually invocation okay you can see
8:27:47langraph sends the initial state as a
8:27:50message to the entity of nodes okay then
8:27:53once it gets this particular particular
8:27:55uh let's say uh uh output and whenever
8:27:58it activates okay we call it as a super
8:28:01step begins okay execution process uh in
8:28:03rounds that means uh it's not like that
8:28:05manually you have to uh I mean initiate
8:28:08uh and invoke all of the nodes one by
8:28:10one so once you invoke the first one
8:28:13okay the remaining one will be
8:28:15automatically executed because it is
8:28:17getting the output and after getting the
8:28:18output this will go to the input to the
8:28:20next node and next node would be uh
8:28:23activated Okay, this is called actually
8:28:25super begins. Super step begins. Okay,
8:28:27lang lang graph call it as a super step
8:28:28begins. That means all of the nodes
8:28:30would be activated that time. That means
8:28:32you can see message passing and node
8:28:34activation. The messages are passed to
8:28:36the downstream nodes via edges. So that
8:28:38means whatever output you are getting
8:28:39from the first node, it will go via this
8:28:42edges to the second node. Then it will
8:28:44be activating one by one. Okay. So this
8:28:45is called super step begins. Okay. And
8:28:48with the help of that it perform the
8:28:50message parsing and node activation. And
8:28:52the last step which is nothing but uh
8:28:54nothing but the halting conditions. So
8:28:56execution stop when all uh no nodes are
8:28:59activated and no messes are in transit.
8:29:02That means if all of the node has been
8:29:03activated and no message are uh let's
8:29:06say in transit that time this particular
Build Sequential Workflows in LangGraph
8:29:08condition would be stop and your graph
8:29:11would be also stop. Yeah. So this is
8:29:13called actually the spreel a system for
8:29:15large scale graph execution process and
8:29:18langraph follow the same strategy
8:29:20whenever they execute their graph. Okay.
8:29:22So yes guys I think you have understood
8:29:24all of the concept about the uh lang
8:29:28graph all of the component about the
8:29:29langraph. Now it would be easy for you
8:29:31to uh code in langraph whenever we try
8:29:34to write the code whenever we'll create
8:29:36the agents that time you won't be having
8:29:38any kinds of confusion you won't be
8:29:40having any kinds of problem related each
8:29:42of the components we have discussed so
8:29:45guys so far we have uh discussed about
8:29:48the theoretical aspect of agentic AI uh
8:29:52as well as I have already given you the
8:29:55in-depth understanding about the uh
8:29:58langraph components and all. Now it's
8:30:01time to start the practical uh
8:30:04exploration. So from this video onward
8:30:07guys uh we'll be working on the uh
8:30:09practical part of the langraph. So uh
8:30:12first of all we'll be starting with the
8:30:14very uh basic workflow uh inside
8:30:17langraph which is uh sequential
8:30:19workflow. I think I have already told
8:30:21you about that. First actually workflow
8:30:23the workflow name is sequential
8:30:25workflow. Okay, sequential means uh this
8:30:27will run um uh in a step-by-step uh
8:30:30let's say manner. Okay, this is called
8:30:32sequent sequential workflow. So, it
8:30:34doesn't have any kinds of looping. It
8:30:36doesn't have any kinds of conditional
8:30:37branching. Okay, it doesn't have
8:30:39anything. Only uh it will be working as
8:30:42a sequence manner. Uh so we call it as a
8:30:45sequential workflow. Okay. So for this
8:30:47guys uh first of all uh we'll be
8:30:49installing the langraph. Okay. In inside
8:30:51our system. So to install the langraph
8:30:54guys you can visit this langraph
8:30:56documentation. So there uh you will be
8:30:58getting uh all kinds of actually
8:31:00tutorial how to install okay how to
8:31:03create your first agent. So each and
8:31:04everything they have already given. So
8:31:06see if you want to install this langraph
8:31:08you can use the pip command either you
8:31:10can use uv okay so let's use pep as of
8:31:13now maybe in future I will also show you
8:31:15how to use the uv package manager as
8:31:17well. So you just need to run pip
8:31:19install lang graph. So this lang graph
8:31:21would be installed inside your system.
8:31:23So for this let's open up our local
8:31:25folder and here I'm going to just open
8:31:28up my visual code studio
8:31:33h
8:31:35and I will also open up my terminal
8:31:37here.
8:31:40Okay. So the first thing guys uh here
8:31:43I'm going to create a file called readmi
8:31:47md and inside that I'm going to mention
8:31:50um all of the command you need to
8:31:53execute uh to install this uh lang graph
8:31:56to create your virtual environment and
8:31:58everything. So if you want to create the
8:32:00virtual environment you have to execute
8:32:02this command called cond createen
8:32:07n okay then you can give the name of the
8:32:10environment I will give let's say lang
8:32:12graph
8:32:16test okay python
8:32:20you can specify the python version
8:32:21python is equal to 3.11
8:32:24and hyphen y okay so this is the command
8:32:27first of all you have to execute this
8:32:28command want to create a virtual
8:32:29environment then you'll be installing
8:32:31this line graph. Okay. Now you have to
8:32:33activate this environment. After that
8:32:35you'll be installing the
8:32:38requirements. We have to install pyener
8:32:43requirement.txt.
8:32:45Okay. So these are the command guys you
8:32:47have to uh follow first of all. So let's
8:32:49create this requirement.xt
8:32:51here.
8:32:52H. So inside that let's mention our line
8:32:55graph package.
8:33:01Okay. Lang graph. So apart from lang
8:33:03graph uh you need to install some other
8:33:05library as well like you need this lang
8:33:09chain open ai. Okay. So we are using
8:33:12this langchen openai because uh I'll be
8:33:14using my openai uh large language model
8:33:18but if you want you can also use any
8:33:19other model um from any other provider.
8:33:22Let's say you can use open router, you
8:33:24can use gro API, okay, you can use
8:33:27gemini API, anything you can use. It's
8:33:29completely up to you. It's a very easy
8:33:31things. You just need to uh change this
8:33:33model provide at that time. Okay. So
8:33:35with me, I am having my open API key.
8:33:37That's why I'll be using this one. Okay.
8:33:39And if you want to use openi API, so
8:33:41that time you have to install this
8:33:43langen openi because I told you langraph
8:33:46uh doesn't work actually independently
8:33:48internally. It is uses langen. Okay. And
8:33:51uh for all the model u let's say loading
8:33:54creating the prompt template we need the
8:33:56langen okay still langen is required
8:33:58then uh I also need pythonb
8:34:02for the environment management okay now
8:34:04guys uh you have to install this
8:34:06requirement txt file but before that I
8:34:09told you you have to create the
8:34:10environment so try to copy the first
8:34:12command and execute from your terminal
8:34:15so this will create the environment okay
8:34:17for you but for me this environment is
8:34:19already available I'll activate the
8:34:21environment. So can't activate langraph
8:34:23test. Yeah. So you can see this is
8:34:26already available. But if you don't have
8:34:28just try to create it first of all then
8:34:30just execute this requirement command.
8:34:33It will install everything. So for me it
8:34:34is already satisfied because I installed
8:34:36previously. Okay. Now once it is done
8:34:39now what I'm going to do guys um let me
8:34:41just tell you about the sequential
8:34:43workflow. Okay. Uh what is the workflow
8:34:46we'll be creating here. See here I'm
8:34:48going to create a very simple uh
8:34:50workflow without using any kinds of LLM.
8:34:52Uh I'll also show you how to use uh LLM
8:34:56um how to create the LM workflow as
8:34:58well. Don't worry but this is our first
8:35:00workflow we are creating inside Lang
8:35:02graph and we don't know how to code
8:35:03inside Lang graph right so to understand
8:35:05the workflow first of all we'll be
8:35:07creating a very simple workflow without
8:35:09using any kinds of LLM. Then I'm also
8:35:12going to show you how to use the LLM as
8:35:13well. Okay. So guys uh now let's see uh
8:35:16what workflow we'll be creating first of
8:35:18all. So here you can see uh we'll be
8:35:21creating a sequential workflow uh and
8:35:23the workflow is temperature conversion
8:35:26workflow. Okay. So here it doesn't have
8:35:29any kinds of LLM. As you can see this is
8:35:31a simple workflow we have created
8:35:33without using any kinds of LLM. So
8:35:35basically this workflow what it will do
8:35:37it will
8:35:39convert actually Celsius temperature to
8:35:42Fahrenheit. Okay. This is the only work
8:35:44this workflow will do. And if we convert
8:35:48this workflow in a graph. So this will
8:35:50look like that. So as you can see we
8:35:52have taken the start node then convert
8:35:55temperature node and the end node. So
8:35:57start and end would be common for all
8:35:59the workflow you'll be creating uh with
8:36:01the help of this langraph. This is a
8:36:04dummy nodes you can say because langraph
8:36:06understands okay workflow starts from
8:36:08here and it it uh ends actually here.
8:36:11Okay. And basically it takes the input
8:36:13uh to the like other nodes as well. And
8:36:17this will also have a state right state
8:36:19is a shared memory and this is a mutable
8:36:23u let's say object you can create this
8:36:25uh state with the help of pentic either
8:36:28you can use type dict okay anything you
8:36:29can um use it. So basically the state I
8:36:33have to share to all of the node so that
8:36:35it can take the data and it can update
8:36:37the data as well in real time. So you
8:36:41can see uh in this particular workflow
8:36:44the only function I have to write this
8:36:46conversion function temperature
8:36:47conversion function. So user will give
8:36:49Celsius uh temperature and I'll try to
8:36:52convert it to the Fahrenheit. Then this
8:36:54uh uh this Fahrenheit output would be
8:36:56show uh shows shows as an output. Okay.
8:36:59So you can see for this we have created
8:37:02we have taken a node convert temperature
8:37:04and this node would be a simple Python
8:37:06function. in that particular Python
8:37:08function what I will do I'll just try to
8:37:10I'll just try to uh write u um the uh
8:37:14code related conversion uh temperature
8:37:17conversion and whatever output we'll try
8:37:19to get we'll try to update in this
8:37:21particular state so here in this
8:37:22particular variable we'll try to update
8:37:24that let's say whatever uh temperature
8:37:26user will give this is in Celsius so
8:37:28this will save inside this particular
8:37:30state uh let's object and whatever I'll
8:37:33try to convert right uh in the
8:37:35Fahrenheit this one I'll try to save it
8:37:37here. Okay. Then whenever I'll try to
8:37:39show the output. So from here I'll try
8:37:41to read and I'll show the output here.
8:37:43So this is a simple workflow guys. Uh we
8:37:45have to create and this state is a
8:37:47shared memory. So this will go to the
8:37:49all of the uh all of the nodes. Okay.
8:37:52One by one and the complete you can see
8:37:54this diagram this workflow this is
8:37:56called actually graph. Okay I hope you
8:37:58cleared. Now let's try to code inside
8:38:00lang graph. So what I'm going to do, I'm
8:38:02going to open up my uh So let's create a
8:38:06file here.
8:38:07I'm going to create a file.
8:38:14I'm going to name it as
8:38:19one temperature conversion workflow
8:38:22NB. Okay. So here I have taken the
8:38:25Jupyter notebook file guys because here
8:38:27I'm not creating any kinds of end to end
8:38:29project. I'm just explaining the
8:38:31concept. Uh that's why I think this
8:38:34notebook uh format would be uh great fit
8:38:37for that because I will also show you
8:38:39the uh workflow in a diagram. Okay. And
8:38:42this diagram I can't uh I can't actually
8:38:46uh show you inside Py file. That's why I
8:38:48have taken this file notebook file. So
8:38:51let's select our environment line test.
8:38:53Yeah. So first of all uh what you have
8:38:56to do guys you have to uh import some
8:38:58library.
8:39:00So here let me comment. First of all you
8:39:03have to import
8:39:06some library. Okay. So you have to
8:39:08import uh this line graph. So from lang
8:39:12graph
8:39:14dotg graph.
8:39:16Okay you have to import state graph.
8:39:20Okay you have to import state graph. If
8:39:22you check the documentation as well. So
8:39:25here also they are doing the same thing
8:39:26from lang graph they're importing state
8:39:28graph then start and end. Okay this is a
8:39:31dummy nodes I already told you this will
8:39:33be common for all the uh workflow you'll
8:39:36be creating with the help of this line
8:39:37graph. Okay. So let's try to import
8:39:39them.
8:39:41H so state graph then I need start
8:39:46I need start
8:39:48then I need
8:39:52end.
8:39:57So here state graph is the function with
8:39:59the help of that we create the graph.
8:40:01Okay, entire graph it will be creating
8:40:03basically uh this helps to create the
8:40:06graph as well as uh to add the state uh
8:40:08inside our graph. Okay, now let me
8:40:11import them. Yeah, so import is
8:40:13successful. Uh that means we have
8:40:15already installed this langraph and we
8:40:17are able to import uh everything. Okay,
8:40:19then I also need to import this type
8:40:22dict from typing. So from typing.
8:40:27So first of all I'm going to show you
8:40:30how we can create the state with the
8:40:31help of this type dict uh typed dict
8:40:34actually module u from python then later
8:40:37on I'm also going to show you how we can
8:40:39create this uh state with the help of
8:40:41pientic okay pientic is another uh
8:40:44python framework with the help of that
8:40:45you can also create the state so let's
8:40:47import
8:40:49typed dict
8:40:52this one now let me import all of them
8:40:56now the first thing Guys, I have to uh
8:40:58initialize the state uh state object.
8:41:01Okay, state is important. Uh without
8:41:04state actually we can't uh create the
8:41:06graph. Then after creating the state
8:41:08we'll be creating the entire graph.
8:41:10First of all, we'll be um uh creating
8:41:12the nodes all the nodes. Then after that
8:41:15uh we'll be uh we'll be creating the
8:41:17ages as well. Okay. So this is called
8:41:19ages. Ages means this is the connection.
8:41:21Let's say after uh which node uh which
8:41:24node would be executed. Okay. This is
8:41:26the connection. So this edges should be
8:41:28also created. Okay. And if we uh create
8:41:30all of them uh this will be uh this will
8:41:32become a graph. Okay. So now let's try
8:41:35to define the state here. Uh so here
8:41:38maybe I can comment
8:41:40define
8:41:43state
8:41:46H. So for this problem I told you state
8:41:49would be uh two state. Okay. uh one is
8:41:53temperature Celsius and temperature
8:41:55Fahrenheit. So let's try to define that.
8:41:57So for this I'll write a class.
8:42:01Okay, I'll write a class.
8:42:03I'm I'm going to name this class as a
8:42:06temperature
8:42:09state.
8:42:12Okay. And I'm going to inherit uh this
8:42:15uh class with this type dict uh function
8:42:18we have imported. Okay. Now basically
8:42:21you are telling this class uh um like
8:42:24this class right now can store uh any
8:42:27kinds of data as a key value pair. Okay.
8:42:30Now the first key should be the
8:42:32temperature
8:42:34temp Celsius.
8:42:37Okay. And uh you can mention the data
8:42:39type as well. What should be the data
8:42:41type for this particular u uh variable.
8:42:45So basically uh Celsius should be in a
8:42:47float uh data type. I think you know
8:42:49that it can't be integer. It should be
8:42:51float. That's why I told uh it is a
8:42:54float. Okay, float data type. Then you
8:42:57have to write another variable called
8:43:01temperature Fahrenheit. So this should
8:43:03be also a float type data. Okay. So this
8:43:06will become our state. Okay. This will
8:43:08become our state and this state we'll be
8:43:10using inside our nodes. Okay. All of the
8:43:12nodes we'll be creating. Yeah. Now this
8:43:15state is also ready. Now let's work on
8:43:17this graph. So here what I'm going to do
8:43:20uh here let's say I'm going to comment
8:43:25define
8:43:28okay define and
8:43:32compile
8:43:34graph I think you know after defining
8:43:36the graph you have to compile I told you
8:43:38the graph execution process right in my
8:43:41previous video as well
8:43:44so to define the graph I told you first
8:43:46of all you have to use this state graph
8:43:47of uh function you have to create a
8:43:50object of that. So let's uh create a
8:43:54object called graph. Then I'm going to
8:43:57initialize state graph and inside that
8:43:58you have to pass the state the state you
8:44:01have created. This is the state
8:44:02temperature state. Okay. So basically
8:44:05this will take the state. Now see what
8:44:08is happening if you're using the state
8:44:09graph object right state graph
8:44:11functionality and if you're passing the
8:44:13state inside that uh so basically this
8:44:16particular function will try to provide
8:44:18the state to all of the nodes okay
8:44:20automatically one by one you don't need
8:44:22to manually provide that okay so this is
8:44:24the main benefit here so that's why
8:44:26we're using the state graph state graph
8:44:28u basically takes this uh state object
8:44:31and it provides to all of the nodes okay
8:44:33one by one now uh we I have defined our
8:44:38graph here.
8:44:40So this is called definition
8:44:43of the graph. Define your graph.
8:44:50Define your graph. Now next I have to
8:44:54add the nodes
8:45:02nodes to your graph to the graph. So to
8:45:06add the nodes guys you just need to
8:45:08write graph dot add nodes
8:45:12okay add nodes then you have to provide
8:45:15the nodes name okay nodes name at the
8:45:18very first time you have to give the
8:45:19nodes name let's say if you see my nodes
8:45:22here okay if you see my nodes here so
8:45:28I have only one nodes which is this uh
8:45:31convert temperature right I have only
8:45:33one nodes which is convert temperature
8:45:35now I Ask me start and ed ends is also a
8:45:38node right but this is a dummy node this
8:45:40thing you don't need to create it
8:45:42separately okay so whenever you are uh
8:45:45defining the ages okay that time you
8:45:47will mention that let's say uh after
8:45:49start uh after start this convert
8:45:53temperature node would be connected okay
8:45:54this is called actually connection
8:45:56that's why we call it as a um like uh
8:45:58dummy nodes we don't need to create
8:46:00separately here okay we don't need to
8:46:02add separately here so by default your
8:46:05uh lang graph adds that and we just need
8:46:07to uh we just need to connect this
8:46:10particular nodes to our actual nodes.
8:46:12Okay, this is the fun here. Now let me
8:46:14first of all create none I'm going to
8:46:16explain okay how it works. So first of
8:46:18all here I have to add our nodes. So
8:46:20here I only have one nodes which is
8:46:22convert temperature. So maybe I can just
8:46:24give a name. I'll give let's say convert
8:46:28okay convert
8:46:31temp. You can give any name it's up to
8:46:33you. But make sure uh the name you are
8:46:35giving here the same name you use for
8:46:38creating that particular function. Okay.
8:46:40Now this will take that uh convert
8:46:43temperature function object. Okay. This
8:46:45will take this convert temperature
8:46:47function object and I told you every
8:46:48node takes a function and this function
8:46:50is nothing but it's a Python simple
8:46:52function. Okay. Now let's try to create
8:46:53this convert temperature function
8:46:55individually here. So what I'm going to
8:46:57do, I'm going to uh simply
8:47:01um come here. So basically this is our
8:47:03first node.
8:47:12So now let's write the function. So def
8:47:15convert temperature. So this will take a
8:47:18state.
8:47:19Okay, this will take a state. What is
8:47:22this state? This temperature state.
8:47:25And this will return uh also the state I
8:47:29told you every time this state would be
8:47:32the input and each and every nodes will
8:47:36return some kinds of output. This output
8:47:38should be also state okay the updated
8:47:40state. So that's why I have to uh I have
8:47:43to give this um blueprint that uh this
8:47:47function takes uh state uh state as an
8:47:50input and it also returns the state.
8:47:52Okay, this temperature state only. So
8:47:54that's how you can give the blueprint of
8:47:56a function. Okay. Now inside that first
8:47:59of all I'll take the Celsius data
8:48:01whatever data user will provide. So here
8:48:04I'll just write Celsius.
8:48:07Celsius okay is equal to this Celsius
8:48:10should be available inside state. Okay.
8:48:12So we are calling state and we are
8:48:14extracting the Celsius only because this
8:48:17is a dictionary right now and you know
8:48:19how to work with the dictionary right?
8:48:21uh so we are working in a same then
8:48:23after that we'll try to convert uh we'll
8:48:26try to convert this to the Fahrenheit so
8:48:28I've already written the code let me
8:48:29show you
8:48:31so here we are converting to the
8:48:34Fahrenheit okay you can see Celsius to
8:48:37Fahrenheit and if you want to see how to
8:48:39convert Celsius to Fahrenheit you can go
8:48:42to Google
8:48:44you can search here so you will see the
8:48:47formula okay so this is the formula so
8:48:49we are replicating the same formula here
8:48:52you can see we are replicating the self
8:48:53same formula we are first of all
8:48:55multiplying this Celsius uh with uh 9
8:48:58out of five then we are adding 32 with
8:49:01that so once we get this Fahrenheit we
8:49:03have to also we have to also update the
8:49:06state memory right we have to also
8:49:08update the state memory because we have
8:49:09taken a variable called temperature
8:49:11Fahrenheit now whatever Fahrenheit we
8:49:13got we have to update inside this
8:49:15particular state right so for this
8:49:18uh that's how we can update because this
8:49:19is a dictionary right this dictionary.
8:49:21So I'm uh just adding this particular
8:49:23new value to this variable to this key.
8:49:26Right? So here we're using round
8:49:27function because if it is a float type
8:49:30uh data so after point there would be
8:49:33too many number but I'm not taking too
8:49:35too many number. I'm only taking last
8:49:37two uh digit okay after after the point.
8:49:40Now once it is done I'm going to simply
8:49:42return this state. So return this state.
8:49:46Okay that's it. So this is our simple
8:49:48python function we have created. Okay.
8:49:50Now this function can convert any kinds
8:49:53of Celsius data to Fahrenheit and we are
8:49:55updating the state here. Okay, that's
8:49:57it. Now this particular function will
8:50:00object will come here. So that's how
8:50:02guys we have created our first node. We
8:50:04have added our first node. Now see this
8:50:06node has added. Okay. Now you have to
8:50:10create this edges. Okay. You have to
8:50:11create it create this edges that that
8:50:13means the connection the flow of
8:50:14execution. So for this let's do that. So
8:50:18here I'm going to comment add edges
8:50:23to the graph. So first of all you have
8:50:25to
8:50:28add the first edges. Now see this start
8:50:30node will come here. Okay. Now see so
8:50:33here I'll just write start and convert
8:50:36them. Just try to see this uh graph. See
8:50:39now I'm telling this start node would be
8:50:41connected to the convert them. Okay,
8:50:43that means this is the connection we are
8:50:44making right now because from here it
8:50:46will start and it will go go to the
8:50:48convert temperature. See here we're
8:50:50doing start to convert temperature.
8:50:52Okay, now I will add the second graph
8:51:00sorry second edge add is now convert
8:51:03them to end. Now you can see uh so
8:51:05basically let me just show you. See
8:51:08first of all we connect it here right
8:51:11that means this connection this
8:51:13connection we have built start to
8:51:15convert temperature now convert
8:51:17temperature to end okay that means this
8:51:19particular edge we are getting right now
8:51:21this edge is already created start to
8:51:23convert them now convert them to end
8:51:25okay particular uh this this edge we are
8:51:27getting uh this edge is already created
8:51:30now we are doing it here so you can see
8:51:32convert them to end okay I hope you
8:51:34clear guys now once this is done then
8:51:37you will compiling the graph. So compile
8:51:41the graph. So you just need to write
8:51:44uh graph
8:51:47dot compile.
8:51:49Okay. And this returns you the workflow.
8:51:52So maybe I can store inside a variable
8:51:59workflow. Okay. Now let's compile.
8:52:05So compilation is also done. Now we'll
8:52:08simply execute the graph.
8:52:17Execute the graph.
8:52:24Now guys, we'll try to execute the
8:52:26graph. So to execute the graph uh first
8:52:28of all you have to take the initial
8:52:31state that means the input uh which is
8:52:34the uh Celsius okay Celsius uh um
8:52:38temperature. So here what I can do I can
8:52:42create a variable. I'm going to name it
8:52:44as you can also call it as input state
8:52:47or initial state. Okay, it's up to you.
8:52:50But I have named it as initial state
8:52:52because this this will become my initial
8:52:53state. Okay, the first state which is
8:52:55nothing but the uh temperature Celsius,
8:52:58right? So initial state. So temperature
8:53:00Celsius I'm giving let's say 28.5.
8:53:03Now this thing we'll try to provide to
8:53:05the workflow. So I have created my
8:53:08workflow
8:53:10workflow dot invoke. Now you can perform
8:53:13the invoke operation because this is a
8:53:15lang graph object. Inside that I'm going
8:53:17to pass my initial state and this will
8:53:19uh return you the final state. Okay,
8:53:22final state that means the output.
8:53:25Final state and this final state I'm
8:53:27going to simply print it here. Okay,
8:53:30done. Now let's uh see whether it is
8:53:33working or not. Now see if I execute.
8:53:34Now see initially we have given 28.5
8:53:38this is the Celsius temperature. Now the
8:53:41final state is uh temp temperature
8:53:43Fahrenheit 83
8:53:46uh 3. Okay you can also try with Google
8:53:50let's say if I'm giving Celsius now see
8:53:54Celsius is uh 28.5
8:53:56and you are getting 83.3
8:54:00you can see 83.3 that means it's working
8:54:02fine right? So we are able to execute
8:54:04our first graph guys. Okay, we are able
8:54:07to create our first graph and this is
8:54:09completely working fine. See there is no
8:54:12problem. Now if you want to see this
8:54:14graph as a uh image you can also do
8:54:17that. That that means you can visualize
8:54:18this particular graph. This is very
8:54:20interesting things I found in langraph.
8:54:22So let me just comment here. Okay
8:54:24visualize
8:54:27graph.
8:54:28So I found this code inside this
8:54:30langraph documentation.
8:54:33Yeah. So here we are using this ipython
8:54:36display um and we are importing this
8:54:38image function. Inside that we are just
8:54:41giving workflow.get graph. Okay.
8:54:43Basically this will get the graph and we
8:54:45are drawing this particular graph as a
8:54:46mar mermaid png. Okay. So mermaid is a
8:54:50kinds of uh you can talk about it's a
8:54:53flowchart. Okay flowchart style. You can
8:54:55search on Google mermaid flowchart or
8:54:58simply search for mermaid. You will see
8:55:00that. Uh okay. Mermaid flowchart.
8:55:06Yeah. See, so this will give you this
8:55:07kinds of flowchart. Okay. Now let me
8:55:09show you.
8:55:11If I execute,
8:55:14see guys, you are getting the flowchart.
8:55:16Now see this flowchart and this
8:55:18flowchart. Just try to tell me whether
8:55:21you are able to see this is same or not.
8:55:23Okay, this is same right. So you can see
8:55:27start then it is going to the convert
8:55:29temperature.
8:55:31then it is uh giving you the final
8:55:34output that means the end nodes. Okay,
8:55:36amazing. So guys, congratulation. We
8:55:39have created our first workflow, first
8:55:41uh line graph graph and this is
8:55:43completely working fine. So guys, now
8:55:45what we'll do, we'll just try to uh
8:55:48update uh the workflow we have created.
8:55:50Let's say this is our workflow. Uh so
8:55:53here we are only converting the
8:55:55temperature to the Fahrenheit. Now what
8:55:57I have done, I created another workflow.
8:55:59So this is the sim similar workflow only
8:56:01I have added a new node here you can
8:56:04see. So the node name is label weather.
8:56:07So what this label weather will do let's
8:56:09say the fahrenheit temperature we are
8:56:12getting uh we'll just try to label that
8:56:15label means let's say if this fahrenheit
8:56:18temperature is less than 50 that time
8:56:21weather status is cold. Okay. If let's
8:56:23say Fahrenheit temperature is it is uh
8:56:26less than equal 50 and less than equal
8:56:29uh 77 that time it is mild. Okay. If it
8:56:32is less than 95 uh then that time it is
8:56:36hot. And if it is not all of them that
8:56:39means it is extreme heat. Okay. So this
8:56:41kinds of labeling I want to do. So for
8:56:44this I have created another node here.
8:56:47I'll I'll be writing another node here.
8:56:48this particular node will try to um try
8:56:52to uh figure out the weather status.
8:56:55Okay, it will try to figure out the
8:56:56weather status whether the weather is
8:56:58hot, cold, mild. Okay, or extreme hot
8:57:01etc. Right? And uh to create this
8:57:04particular uh graph guys, I need another
8:57:07state called weather status because uh
8:57:10these nodes will return the label right
8:57:13whether it is hot, cold, mild or
8:57:15anything. So this particular data I have
8:57:18to also save in the state that's why I
8:57:19have taken another variable called
8:57:21weather status here. But previously this
8:57:23was missing here. Okay. Now let's try to
8:57:25update this. So what I'm going to do I'm
8:57:27going to open up my code again. So see
8:57:29here I'll add another nodes. Okay. I'll
8:57:31add another nodes here.
8:57:34Yeah.
8:57:36Let's say the node name is
8:57:40uh label weather. Okay. And it will take
8:57:42a function Python function called level
8:57:44weather. So now let's write this
8:57:46function. So after this function maybe I
8:57:48can write it here.
8:57:51So def label weather. So this will take
8:57:54this state as an input.
8:57:59Okay. And it will also return this state
8:58:01as an output.
8:58:04State as an output. Okay. So already I
8:58:07got the suggestion code from my uh from
8:58:11my co-pilot. Let me show you the code I
8:58:14have written.
8:58:16So this is the code. Okay. Now let me
8:58:20also
8:58:23comment here.
8:58:26Let's say this is for
8:58:29label
8:58:34weather
8:58:37condition. This is our second note.
8:58:39Okay. So now what what we are doing the
8:58:42Fahrenheit temperature we are getting
8:58:44we're taking it from the state okay we
8:58:46are pulling the Fahrenheit from the
8:58:47state instead of Celsius
8:58:50uh because I want to check with respect
8:58:53to the Fahrenheit okay I want to check
8:58:55with respect to Fahrenheit you can also
8:58:56do it with the help of Celsius as well
8:58:59Celsius temperature as well you can also
8:59:00label that but I want to do it with the
8:59:02help of Fahrenheit I want to I want to
8:59:03only show you the output we are getting
8:59:06whether we can use it inside this
8:59:08particular node or not okay that's why
8:59:09I'm using is uh temperature um finite
8:59:14then after that I'm checking if finite
8:59:15is less than 50 that time uh weather
8:59:18status should be cold we are updating
8:59:21this
8:59:23state okay there should be another
8:59:24variable called weather status and right
8:59:28now this status should be hot cold mild
8:59:30so I can consider this should be a
8:59:31string type data okay now let me execute
8:59:34this node yeah now you can see this
8:59:36weather starter should be cold if it is
8:59:40less than and equal 50 or less than 73
8:59:4377 that time the weather status should
8:59:45be mild. If it is uh less than 77 and
8:59:49less than 95 this should be hot
8:59:51otherwise it should be extreme heat.
8:59:53Okay. So this is our uh uh this is our
8:59:56logic we have written inside this label
8:59:58weather function and we are returning
8:59:59the state. Okay. Now let me execute. Now
9:00:02what I'm going to do just execute from
9:00:05the beginning one one more time just to
9:00:07show you the output.
9:00:10H. So the node add is done. Now we'll
9:00:12try to add the edges. Okay. Now we'll
9:00:15add the edges. That means after convert
9:00:18temperature, this will go to the label
9:00:19weather. Okay. So here I'm going to
9:00:21write
9:00:22um
9:00:24see uh start start uh convert
9:00:28temperature. Okay, that means this part
9:00:29is done. Now I have to work on this
9:00:32part. Convert temperature to level
9:00:34weather. So here I have to write
9:00:37convert temperature to level weather.
9:00:39Okay. Now label weather to end. Now here
9:00:43I just need to light right level weather
9:00:47to end. Okay. Now I think you have
9:00:49understood this particular edge
9:00:50connection. Okay this like very amazing
9:00:53right and if you understand this edge
9:00:55connection just trust me you can create
9:00:56any kinds of workflow inside langraph.
9:00:58Okay that's why I'm showing you this
9:01:00easy workflow at the very beginning. Now
9:01:02once it is done, now let's try to
9:01:04compile the graph again. Then I will
9:01:08execute
9:01:10the graph. This only takes the uh
9:01:12temperature Celsius input.
9:01:15H uh so you can see temperature Celsius
9:01:18this 28.5 we are getting the Fahrenheit
9:01:21and based on the Fahrenheit result we
9:01:24are seeing that weather status is hot
9:01:26right now. We can check if it is 83
9:01:28right
9:01:3083 that means here this condition is
9:01:32matching here okay that means this
9:01:34particular condition is hot right now
9:01:37okay now if I visualize this graph now
9:01:39see another node is added which is level
9:01:41weather now this uh this graph and this
9:01:45graph I think you can match okay great
9:01:49guys so yes this was the first uh
9:01:53sequential uh sequential actually
9:01:56workflow we have created without using
9:01:58any kinds of large language model. So
9:02:01now I'm going to show you how we can
9:02:03create sequential workflow uh with the
9:02:05help of large language model as well. So
9:02:08guys uh now we'll be creating a LLM
9:02:11workflow. Uh previously the workflow I
9:02:13showed you uh this workflow I have
9:02:15created this is a non-LM based workflow.
9:02:17Uh here I'm not using any kinds of LLM.
9:02:19Okay. uh with the help of simple python
9:02:21function simple python logic I was
9:02:24handling everything now let's say you
9:02:25want to use llm okay llm inside the
9:02:28workflow so how to create the workflow
9:02:31for that let's try to understand and see
9:02:33here our main goal is to learn the lang
9:02:36graph uh like workflow creation the
9:02:39problem statement I'm taking uh it might
9:02:41be very simple uh you can think about
9:02:43okay this this thing I can create with
9:02:45the help of simple python function only
9:02:47but why we are writing that much line of
9:02:49code. Okay. So our intention is to learn
9:02:52the um lang graph workflow. Okay. How we
9:02:55can use the lang graph? How we can
9:02:56create the workflow? How we can create
9:02:58the node edges. Okay. Each and
9:03:00everything this idea I'm giving you.
9:03:01Okay. So problem statement doesn't
9:03:03matter. You can use any kinds of problem
9:03:04statement. So after learning this simple
9:03:07concept so later on whenever we'll be
9:03:09creating the actual agents or big
9:03:12project. So this concept will help us a
9:03:14lot. Right? So that's why we are um uh
9:03:17explaining this concept with the help of
9:03:18simple workflow. Now here I'm going to
9:03:21take another uh very simple workflow
9:03:23guys for the LM workflow. So here what
9:03:26I'm going to do uh here this is the uh
9:03:29workflow. This is the graph you can see.
9:03:31So basically this will have the start
9:03:33and end nodes definitely because this is
9:03:35common. So the only one nodes I'll be
9:03:37creating here the LMQA nodes. Okay. So
9:03:39LMQA means what it will perform. So
9:03:41basically user will give some of the
9:03:43question and this lm will uh answer that
9:03:46particular question and this will return
9:03:48you the answer only this simple
9:03:50operation will be doing okay in this
9:03:52particular workflow. So for this what
9:03:55should be the state? The state should be
9:03:56definitely the question whatever
9:03:58question user is giving and whatever
9:04:00answer we are getting from the LLM this
9:04:02should be another state. Okay. So this
9:04:05state should be passed to all of the
9:04:06nodes and it will real time update that
9:04:09and our uh uh workflow would be ended.
9:04:12So this is the simple uh graph guys. Now
9:04:15let's try to implement this graph with
9:04:17the help of lang graph. So for this I
9:04:19have already prepared a notebook as you
9:04:21can see simple keyway LA workflow. So
9:04:23let me open it up and uh to run this uh
9:04:26um um code guys you need this file
9:04:30because in the env I have mentioned my
9:04:32openi API key because here we are using
9:04:34large language model and I'm using openi
9:04:37large language model but if you want to
9:04:38use any other large language model you
9:04:40can use it completely fine for this you
9:04:42can change the API key here. So this is
9:04:44the uh code guys. This is the notebook I
9:04:46have prepared. Now this is this looks
9:04:49same as per your previous uh notebook.
9:04:51Only the things I have added the llm
9:04:53functionality here. Now first of all you
9:04:55have to import some necessary library.
9:04:57So see you can see we are importing the
9:04:59same uh state graph start ends from the
9:05:02langraph graph. Then one additional
9:05:04package we're importing langchen peni
9:05:07chat opi. I told you if I want to use
9:05:09any kinds of uh let's say large language
9:05:12model or whatever I have to still use
9:05:15langen because langraph doesn't have
9:05:17direct functionality so that
9:05:19functionality can load any kinds of llm
9:05:21okay so it has to use this langen to
9:05:23load the large language model so here
9:05:25one more thing you are also learning how
9:05:27we can use langen along with the lang
9:05:28graph okay so this is the concept so we
9:05:31are importing chat open a let's say if
9:05:32you're using any other other provider if
9:05:34you're using grock or open router inside
9:05:36langen it is available you simply you
9:05:38can open it up. Then we are also
9:05:40importing type dict just to create the
9:05:42state and the load envadment
9:05:45variable.
9:05:48Now the first step we are loading the
9:05:49environment variable this env. For this
9:05:52we are calling this load env. So if it
9:05:54is returns two. Okay first of all I have
9:05:57to import this. Now I'll execute. Now if
9:06:00it if it returns to that means this env
9:06:03file is present and inside that we have
9:06:04the uh key right. It has loaded
9:06:07successfully. Now we'll try to define
9:06:09the large language model. Okay. So here
9:06:10we are creating a model object and we
9:06:12are calling the chat openi. So by
9:06:14default I think it loads a model. Okay.
9:06:16Uh I think GPT 3.5 turbo model it will
9:06:19load. You can also change the model
9:06:21parameter. If you want to use any other
9:06:22model like GPT 5 or 4 you can easily do
9:06:25that. But I will take the default model.
9:06:27It's completely fine for me. Okay. So I
9:06:28got my model object. Now here you can
9:06:30change with any model object. Either you
9:06:32are using grock uh either you can using
9:06:34open router Gemini anything you can use.
9:06:37Now we have to create this state. Okay,
9:06:40this state we have to create and I told
9:06:41you to create this workflow I need u
9:06:45this these two state question and
9:06:46answer. So this thing I'll be creating
9:06:48right now. You can see I have written a
9:06:50class I named it as LLM state and again
9:06:53I'm inheriting with the help of type
9:06:54dict. Now we can store the data as a
9:06:57question uh key value pair. Now the
9:06:59first state you can see this is the
9:07:00question and the data type should be
9:07:02string because usually uh whatever
9:07:05question we are writing this is kinds of
9:07:06string type data and answer also this is
9:07:09a string type data okay we are
9:07:10preferring the state now once uh state
9:07:12preparation is done now we'll be
9:07:15creating the nodes but before uh showing
9:07:17you the nodes u logic I will show you
9:07:20the graph definition so you can see guys
9:07:22uh we are creating the state graph and
9:07:24we are passing the state the state we
9:07:26have created this state then After that
9:07:29we are adding the nodes. Okay. The first
9:07:31node we have added the LM QA. Okay. Now
9:07:33this LLM QA we have to write. Okay. This
9:07:35LLM QA we have to write. So this this is
9:07:37this should be a simple Python function.
9:07:39Inside that we'll perform the LLM call.
9:07:41So see LM QA this is the function we are
9:07:44writing. This will take this state as an
9:07:45input and return the state as an output.
9:07:48Now whatever question user is giving I
9:07:52am taking it from the state. Then I'm
9:07:54preparing a prompt. Answer the following
9:07:56questions. We are giving the questions.
9:07:57Then this particular prompt I'm just
9:07:59giving to the model. We're just doing
9:08:01model.info giving the prompt and
9:08:03whatever content it is giving me. I'm
9:08:05just extracting in the answer and this
9:08:07answer I'm updating in the state memory
9:08:09again. Okay. So you can see it is having
9:08:11the answer key. I'm updating the value
9:08:13there and we're returning the state.
9:08:15Okay. Now let's execute.
9:08:21Now once our node is added now we'll be
9:08:24working on the edges. We'll try to
9:08:25connect the edges. Now if you see the
9:08:27graph so see first of all start node
9:08:29will connect to the lm QA. So we are
9:08:32connecting that start to lm QA. Then LLM
9:08:35QA will be connected to the end. You can
9:08:37see then add LLM QA to end. Okay. And I
9:08:42told you start and end is a default node
9:08:44inside Langraph. You don't need to
9:08:46manually add that. This is a dummy node.
9:08:48Okay. So only we'll be calling whenever
9:08:50we'll be adding the edges. So once it is
9:08:52done we'll try to compile the graph.
9:08:54Let's compile. Okay, now everything is
9:08:57ready. Now we can execute the graph. So
9:08:59we are preparing the initial state which
9:09:00is nothing but the question. Let's say
9:09:02here I'm giving a question who is the
9:09:04creator of Python and uh the workflow we
9:09:07have created. We are just doing the
9:09:08inbing operation. We are giving the
9:09:09initial state and we are getting the
9:09:11final state output. Then we are just
9:09:13returning the answer. So I'm asking a
9:09:16question which is the creator of Python.
9:09:18Now let's see.
9:09:20So see the Python was created by Guido
9:09:23Van Rosrom in the late '9s80s. Okay,
9:09:261980s. So it's working fine. Okay, you
9:09:28can give any other question as well. It
9:09:30will work. Now let's try to visualize
9:09:32the graph. So here I will execute this
9:09:34code. This code is common. Now see this
9:09:36is uh the graph. You can see start LMQA
9:09:39and ends. Okay, amazing. So this is the
9:09:42actually LM workflow we have created. So
9:09:44previously we created without uh nonLM
9:09:47workflow. Now we have created LM based
9:09:49workflow. Okay, I hope you get it. So
9:09:51that's how guys, if you want to use any
9:09:53kinds of large language model inside the
9:09:55workflow, you can uh define it like
9:09:57that. Okay, now we'll be learning
9:09:59another uh amazing concept. I I think I
9:10:02told you in my previous video as well
9:10:04called prom chaining. Promching means
9:10:06you can use multiple LM calls. See here
9:10:09I'm using only one LM call, right? One
9:10:11LM call. But if you want to use multiple
9:10:13LM call, that is also possible. So we'll
9:10:16be learning in the pom uh we'll be
9:10:18learning this concept in the prom
9:10:19chaining. Okay. So I'm going to create
9:10:20another notebook. There I'm going to
9:10:22show you how we can perform the prom
9:10:24chaining operation. That means one uh
9:10:26LLM answer you are getting. You can pass
9:10:28this answer to another LM to get another
9:10:30response. Okay, this is also possible
9:10:31here. Let me show you that part as well.
9:10:33So guys, now I'll explain about this
9:10:36prom training. Uh this is another
9:10:38sequential workflow. So in our previous
9:10:41uh workflow, we did the single LLM call.
9:10:44That means uh user was giving any kinds
9:10:46of question and it was generating the
9:10:48answer. But let's say you want to do
9:10:50multiple LM call that means uh after one
9:10:52LM call that output you want to use for
9:10:55another LM okay as an input. This is
9:10:57called prompt chaining. So for an
9:11:00example let me just uh tell you see here
9:11:03what I'm going to do. I'm going to let's
9:11:05say uh create a blog generator. Okay
9:11:08blog generator from a topic. So here
9:11:11let's say user will give a topic name.
9:11:13Okay. So this will generate a blog.
9:11:16Okay, block blog for that. But this
9:11:18block I'm not going to generate
9:11:19directly. Instead of that what I'm going
9:11:21to do first of all I'm going to take
9:11:22this topic name. Then I'm going to pass
9:11:25to LLM. Okay, I'm going to pass to LLM.
9:11:29And this LLM will try to generate the
9:11:31outline. Okay, outline for the block. So
9:11:34let's say this will generate the
9:11:36outline. Okay, outline of the block from
9:11:39this LLM. And whatever outline I will
9:11:41give uh get from this LLM, I'll pass to
9:11:43another LLM. Okay. And this LLM will try
9:11:46to
9:11:48take this topic as well as this outline
9:11:50and it will generate the block.
9:11:54Okay. And we'll be getting the final
9:11:56block as an output. Okay. At the last.
9:11:58So this is the workflow and this is
9:12:00called actually prompt chaining concept.
9:12:03Okay. Prompt chaining concept. Basically
9:12:05whatever output we are getting from a
9:12:07first large bank model we are passing it
9:12:09to the second LLM as an input and we are
9:12:11getting a final output. That means we
9:12:13are calling multiple LM call here. This
9:12:14is called prompt shading concept. Okay.
9:12:16So this workflow we'll try to create
9:12:18right now. Now see guys I have already
9:12:20created this uh graph. Okay. Uh I've
9:12:23already created this workflow as you can
9:12:24see. So start and end would be common.
9:12:26So here I have to create two nodes. One
9:12:28is the create outline. That means
9:12:30whatever input I'll be getting. That
9:12:32means uh the topic. So first of all I'll
9:12:35generate outline and this outline as
9:12:37well as the topic I'll send to another
9:12:39nodes which is create block. This will
9:12:41generate the blog and I'll be getting
9:12:43the final block as an output. Okay. And
9:12:45what should be the state for this
9:12:46particular uh workflow? First of all the
9:12:49title that means the blog title. Okay.
9:12:51Then whatever outline it will generate
9:12:53this outline as well. And whatever
9:12:55content that means the blog will be
9:12:57getting this should be another state.
9:12:59Okay. So that means three state will be
9:13:00available for this particular uh
9:13:02workflow for this particular graph.
9:13:04Okay. Now let's try to represent in the
9:13:06lang graph code. So for this I have
9:13:08created another notebook as you can see
9:13:10prompt chaining workflow. So let's open
9:13:12it up. So this is the notebook. So again
9:13:14this is the same uh as per your previous
9:13:16notebook I created. First of all we have
9:13:18to import all the necessary libraries.
9:13:21You can see we are importing state graph
9:13:22start ends chat open. Okay. Then type d
9:13:26load env. Then we'll be loading the env
9:13:28uh env file to load the opinion API key.
9:13:32Then we'll be defining the large
9:13:33language model. Then we'll be creating
9:13:36the state and uh this state name I have
9:13:39uh named it as blog state. And again I'm
9:13:41doing the inheritant inheritance
9:13:43operation with the help of this type
9:13:45dict. Now we are preparing the state.
9:13:47State means the title, outline and the
9:13:49content. Okay. Three state we are
9:13:50taking. H now before creating the nodes
9:13:54first of all let me show you the graph
9:13:57okay see here we are creating the graph
9:14:00state graph and we are passing the state
9:14:02and first of all we are adding the nodes
9:14:04okay so the first nodes we are adding
9:14:06for the create outline now let me show
9:14:08you this create outline function so this
9:14:10is the create outline function so this
9:14:11will take this state as an uh input and
9:14:14uh return you the state as an output
9:14:17okay so whatever title user is giving
9:14:19first of all I'm taking the title And
9:14:21here I'm preparing a prompt generate a
9:14:23detail outline for the blog uh for a
9:14:26blog on the topic. So then we are
9:14:28passing it to the LLM. LM is giving the
9:14:30outline. This outline we are saving
9:14:31inside the state. Okay, inside outline
9:14:33variable then we are returning the
9:14:35state. Then after that if you show if
9:14:37you see I'm adding another nodes okay
9:14:40called generate blog. Now whatever
9:14:43outline I got and title I got I will
9:14:45pass to this particular function. You
9:14:47can see uh it will take from this state
9:14:50the title as well as the outline. Then
9:14:51I'm preparing another prompt. This
9:14:53prompt is telling write a detailed blog
9:14:55on the title. Okay, using the following
9:14:57outline. The outline we are getting as
9:14:58well as the title we are using here.
9:15:00Then we are passing it to the LLM. Okay,
9:15:02again we're doing the LM call. Whatever
9:15:04LM is generating, I'm just storing in
9:15:06the content. That means this is the
9:15:08final block. Okay, I'm storing inside
9:15:09this content uh content state. Okay, so
9:15:13it is done. Now you can see we are
9:15:15adding both of the nodes one by one. So
9:15:18this uh nodes is added create outline
9:15:20and uh create blocks. Now I have to
9:15:22create the edges. Now to create the
9:15:24edges guys here you can see I'm creating
9:15:26the edges. First of all age would be
9:15:28created. Start to create outline. You
9:15:31can see start to create outline. Then
9:15:34create outline to create block.
9:15:38Create outline to create block. Okay.
9:15:40Then create block to end. create block
9:15:44to end. Okay, then we are doing the
9:15:45compile operation.
9:15:48Then now we'll execute the graph. So
9:15:50here as initial state we are giving the
9:15:52title. Okay, we are giving a title let's
9:15:54say raise of AI in India. Let's say this
9:15:56is our uh title and I want to generate
9:15:59outline and then block. Now we are
9:16:01giving into the workflow. We are doing
9:16:03the blocking operation and we are
9:16:04getting the final state as an output.
9:16:09See
9:16:15it is doing multiple LM call that's why
9:16:17it's taking some time. First of all it
9:16:19will invoke first LLM then the second
9:16:22LM. Right now see here we are getting
9:16:24the output. So this is the title based
9:16:26on the title we are getting the outline
9:16:28and also we have a content final content
9:16:31I think somewhere content is also there.
9:16:33Uh we can see uh here. So final state uh
9:16:37first of all I want to see the outline.
9:16:39So this is the outline. Okay, it has
9:16:40prepared. Now if I want to show you the
9:16:44content that means the blog. So this is
9:16:46the blog guys. Okay, I'm getting. So
9:16:48this is called prompt shading concept.
9:16:50Now if I want to show you the
9:16:53graph. So this is the graph. You start
9:16:55create outline then it will go to the
9:16:57generate block create block then hands.
9:17:00Okay, I hope you got it guys. Okay, so
9:17:02that's how guys we can create any kinds
9:17:04of sequential workflow. Either you can
9:17:06create a nonLM based, either you can
9:17:08create LLM based, either you can create
9:17:10prompt chaining based, anything you can
9:17:12create only you just need to know how to
9:17:14uh how to define these uh nodes and this
9:17:18particular connection. Okay, age
9:17:19connection if you can understand this
9:17:21concept you can just trust me you can
9:17:24create any kinds of workflow okay inside
9:17:26lang graph. Now I think by end of this
9:17:29video it is uh very much clear how we
9:17:31can create any kinds of sequential
9:17:32workflow inside lang graph. Okay don't
9:17:34worry I'm also going to show you uh like
9:17:37complex workflow as well like parallel
9:17:38workflow. Okay there are lots of
9:17:39workflow we saw right we'll be learning
9:17:42each of them don't need to worry but
9:17:44before starting that complex workflow
9:17:46first of all I've given you the
9:17:47sequential workflow. uh I think uh now
9:17:50you have enough understanding how to
9:17:52code inside langraph at least right now
9:17:54I think these are the syntax won't be
9:17:55confusion to you right like what is a
9:17:58node what is ajs okay so so far we have
9:18:00learned so many theoretical concept now
9:18:02we have seen the practical
9:18:04implementation
9:18:05and all of this code and everything
9:18:07would be available in the description
9:18:09from there you can uh download and you
9:18:11can uh try in your system and one more
9:18:14exercise you can perform let's say this
9:18:16prom training u we have
9:18:19Maybe you can add another node for the
9:18:21evalu evaluation for this block. Let's
9:18:23say the blog you are generating whether
9:18:25this is good or bad. You can uh take
9:18:28another LLM. You can take another nodes
9:18:30and you can evaluate that and you can
9:18:31also uh print the evaluation result.
9:18:34Let's say it needs the feedback or not
9:18:37or it is completely fine. This kinds of
9:18:39result you can also uh print. Okay, that
9:18:42means you you have to take another state
9:18:43here and whatever result you are getting
9:18:45you can also show the result here. Okay,
9:18:47after you can see uh content maybe you
9:18:51can uh print another result which is
9:18:53evaluator result. Okay. Now the best
9:18:56part is of this state is you you can
9:18:58access all of the output. Okay. All of
9:19:00the output input any time. Let's say we
9:19:02have generated uh these three uh three
Implement Parallel Workflows in LangGraph
9:19:05things right? Uh title, outline and
9:19:07content and it is accessible anytime.
9:19:09Okay. This is the final state. From the
9:19:11fin from the final state you can access
9:19:15um any kinds of state. Let's you can
9:19:17access title, outline, content or if
9:19:19you're adding the evaluator you can
9:19:21access it anytime. Okay. So yes that's
9:19:23it guys. So yes uh this is all about
9:19:26from this video. I hope you got it. Now
9:19:28in the next video guys we'll be uh we'll
9:19:30be learning uh some other workflow as
9:19:33well. Okay like uh parallel workflow
9:19:35we'll be also learning conditional
9:19:37workflow, iterative workflow. Okay, all
9:19:38the workflow we'll try to cover one by
9:19:40one. So guys uh we are continuing with
9:19:42our uh complete agenti course and as you
9:19:46know we started uh learning our first
9:19:49orchestration framework which is
9:19:51langraph and in our previous video I
9:19:54have already showed you how we can build
9:19:56sequential workflow inside langraph. So
9:20:00if I open up my um previous uh like uh
9:20:04materials. So there I already showed you
9:20:07about the sequential workflow and I
9:20:08think you know how sequential workflow
9:20:10works. Basically it will work as a
9:20:12step-by-step manner. Okay. First of all
9:20:14let's say this node then this node then
9:20:16this node okay that's how it will
9:20:17execute okay as a sequence. So if I uh
9:20:20show you see I created a nonlm based
9:20:23workflow and lm workflow uh then prompt
9:20:26chaining workflow. So as you can see u
9:20:29after executing this node this node
9:20:31would be executed. Okay then you will be
9:20:32getting the output. So this is a
9:20:34sequential order. Now we'll try to
9:20:36understand this uh parallel workflow
9:20:39like how parallel workflow works and
9:20:42we'll also try to uh write the code
9:20:45inside langraph. And uh here is the
9:20:47example guys. The first example I'm
9:20:48going to show you the employee analytics
9:20:51workflow. Okay. So this is the example I
9:20:52have taken. uh I already told you just
9:20:55don't um I mean don't focus on the
9:20:57problem statement I I have taken some of
9:21:00the problem statement uh easy problem
9:21:01statement so that I can make you
9:21:03understand these are the workflow so
9:21:04later on we'll be building some amazing
9:21:06ANTI application completely end to end
9:21:09so you can see guys uh here uh this is
9:21:12the parallel workflow uh graph as you
9:21:15can see uh so you you can see the
9:21:17difference between the sequential and
9:21:20the parallel sequential means uh After
9:21:23executing this node, this node will be
9:21:25executing. That means the output you are
9:21:28getting from this particular node, you
9:21:30are passing this particular output to
9:21:32the next node and this node is taking
9:21:34that um output as an input. Then it is
9:21:36executing. Okay, that means um you have
9:21:40to wait okay um you have to wait till
9:21:42this node just complete the execution
9:21:45then this node will start. But in
9:21:47parallel workflow um it's not like that.
9:21:51Each of the nodes are independent that
9:21:53means you can execute them
9:21:55independently. Okay, simultaneously you
9:21:57can execute all of the node and you can
9:22:00get the output. So for this I have taken
9:22:02one amazing example called employee
9:22:04analytics workflow. So basically what
9:22:06we'll do here we'll just try to take
9:22:08some employee data. So here I already
9:22:10created the state as you can see I have
9:22:12already defined the state for this
9:22:14particular demo. So as you can see let's
9:22:16say this is our employee state and you
9:22:17know what is a state right? state is a
9:22:20uh a shared memory uh inside our graph,
9:22:22right? And it will pass to all of the
9:22:25nodes. So you can see these are the data
9:22:28we'll be taking from the user. Okay,
9:22:30let's see employee name, monthly salary,
9:22:33working days and completed projects.
9:22:35Okay, based on that what we'll do, we'll
9:22:37just try to calculate the bonus of the
9:22:40employee, uh yearly salary of the
9:22:42employee and the project evaluation. Ev
9:22:44evaluation means the project is
9:22:46excellent. uh let's say project work is
9:22:48excellent or average okay we'll try to
9:22:50mark that now you can see u to do that I
9:22:54don't need to wait for any of the node
9:22:57here let's say I don't need to wait for
9:22:59this bonus to calculate the yearly
9:23:01salary then I don't need to wait for
9:23:04project evaluation for this calculate
9:23:07yearly salary okay I don't need to wait
9:23:08for each and every nodes here because
9:23:11each and every nodes are independent the
9:23:13task I have taken you can see this is
9:23:15completely independent task So instead
9:23:17of running this in a sequential manner
9:23:20so I can follow this par parallel
9:23:22workflow. Okay. So that I can execute
9:23:25them in parallel and I can quickly
9:23:27complete my task. Okay. Otherwise if you
9:23:30if you are running in sequential order
9:23:32you have to wait for the previous node
9:23:34to be executed. Okay. But here it's not
9:23:36like that. This is completely
9:23:37independent. Then after uh getting all
9:23:40of this uh information what we'll do
9:23:42guys we'll just try to give a summary.
9:23:45uh summary means let's say the employee
9:23:47name their salary yearly salary project
9:23:51evaluation calculated bonus we'll just
9:23:53try to return a string complete uh
9:23:55detail summary string and we'll just try
9:23:57to end the graph okay so this is a
9:23:58simple problem statement I have taken
9:24:00again I told you guys uh don't uh just
9:24:03focus on the problem statement uh just
9:24:05to make you understand I have taken this
9:24:07problem statement the main intention you
9:24:08have to learn this workflow okay how we
9:24:10can build this workflow so first of all
9:24:12we'll try to learn this nonLM based
9:24:14workflow So here I'm not going to use
9:24:15any kinds of LLM. Uh then after learning
9:24:18this nonLM based workflow, the next one
9:24:20I'm going to take the LM workflow. Okay.
9:24:23So both we'll be learning. No need to
9:24:25worry. Now let's start the coding inside
9:24:27Langraph. So what I'm going to do guys,
9:24:29I'm going to simply
9:24:31um create a
9:24:34I'm going to simply create a file here.
9:24:37I'm going to name it as four
9:24:40um employee data analytics. Okay.
9:24:42Employee
9:24:53analytics
9:24:58workflow.
9:25:06I'm going to create a notebook file.
9:25:10Perfect. So here I'll take the code cell
9:25:12and I will select the kernel. Uh so
9:25:14previously I created this environment. I
9:25:16think you remember we'll try to select
9:25:18that as well. H fine. Now guys the first
9:25:22thing what you have to do I think you
9:25:24remember the first thing you have to
9:25:26import all of the necessary library. So
9:25:28maybe what I can do I can refer my
9:25:30previous notebook and I can just import
9:25:34all of the necessary library. I need um
9:25:37I need this one right? this uh line
9:25:41graph state graph and start and end. So
9:25:44I'll try to import the this as well as I
9:25:46need this uh typing
9:25:49to create this uh state. Okay, I need
9:25:52this particular type dict. Now let's
9:25:54import it. H now the second thing guys
9:25:58you have to define the state. Okay, if
9:25:59you uh if you see that let's say the
9:26:02previous example also uh so this is LM
9:26:04workflow. But if I open my previous
9:26:06example, let's say this one I created,
9:26:08right? This is the non LLM based
9:26:10workflow. Uh then second thing you have
9:26:12to define the state and uh for this uh
9:26:15example guys what should be the state.
9:26:17So this is the state I already prepared.
9:26:19First of all uh these are the state
9:26:20we'll be taking from the u user and
9:26:24these are the state we'll be uh we'll be
9:26:26just calculating. Okay we'll be updating
9:26:27basically let's say this calculate uh
9:26:30yearly salary. We'll try to calculate
9:26:32the yearly salary and we'll try to
9:26:33update in the inside this particular
9:26:34state. Then bonus okay we'll update
9:26:37inside this uh state then project
9:26:39evaluation we update inside this project
9:26:41status and summary whatever summary we
9:26:44are getting we'll also update here okay
9:26:46and all of the data type I have also
9:26:47mentioned you can see employee name
9:26:49should be string data type monthly
9:26:51salary should be integer working days uh
9:26:53it should be also integer completed
9:26:55project it should be integer that means
9:26:57the number of project employee has
9:26:59completed yearly salary this is also
9:27:01integer bonus amount also integer
9:27:03project status okay uh this status I
9:27:06will let's say tell excellent average
9:27:08okay so this should be a string and
9:27:09summary also should be a string okay so
9:27:11this is the data type now let's uh try
9:27:13to um just write same uh uh state uh
9:27:17inside our notebook I'm going to just
9:27:19close this other file
9:27:21so
9:27:23this is the state guys okay you can see
9:27:25the same state we have prepared here and
9:27:27I just named it as employee state and I
9:27:29inherited with type tic because I can
9:27:32store my data as a key value pair okay I
9:27:34think I have already disced test
9:27:35previously. Okay, this thing. So, I'm
9:27:37not going to repeat again. Now, uh my
9:27:40state is done. Now, I'll just need to uh
9:27:43create the graph. Now, let's try to
9:27:45create the graph. So, we'll try uh
9:27:48create the graph. You can see we are
9:27:49using a state graph. And inside that we
9:27:51are passing our state. Okay. Employee
9:27:53state. Now, we have to add the nodes.
9:27:55Okay. Now, how many nodes we are having?
9:27:57Uh 1 2 3. Okay. And last, we have
9:28:00another nodes called summary. And start
9:28:02and end. You don't need to take it
9:28:03because this is a default node inside
9:28:05langraph. This is a dummy node. So first
9:28:07of all let's try to create this um uh
9:28:10this one this um calculate bonus or you
9:28:16can create any of them because this is
9:28:18completely independent right uh you are
9:28:19not uh I mean uh you you don't need to
9:28:22worry about the like order because this
9:28:24is not a sequential one you can create
9:28:26any of them any of them. Okay. So first
9:28:28of all let's create uh this calculate
9:28:30yearly salary. So here I'm going to add
9:28:33a node.
9:28:38So this is the node guys. Graph add
9:28:40nodes. I named it as calculate early
9:28:42salary and the same name I used for this
9:28:44particular function. Okay. And this is
9:28:47going to be a python function. We'll
9:28:48just try to write the function. Okay.
9:28:50Just give me some time. So like that
9:28:52I'll also define for all of these nodes
9:28:55one by one. Uh the next one I'm going to
9:28:57create for
9:28:59uh calculate bonus and project
9:29:01evaluation.
9:29:04Yeah. So calculate bonus this one and
9:29:06the project evaluation. Project
9:29:08evaluation. Okay. So all of the nodes I
9:29:10have created only the last node I have
9:29:12to create this summary.
9:29:14Now let's also create the summary.
9:29:18Summary. Okay. My node uh creation is
9:29:22done. Now I'll write these are the
9:29:23function one by one. So I'll come here.
9:29:27So here I will comment
9:29:29uh this is our node one and the function
9:29:31name is calculate yearly salary. Okay.
9:29:33Now let's define a function def uh
9:29:36calculate yearly salary
9:29:40and uh this will uh take this uh
9:29:42employee state uh as an input because
9:29:45every nodes takes this uh state. I think
9:29:47you remember okay every node takes this
9:29:49state. Okay. And also return a state
9:29:52right. So we are we are giving this type
9:29:54hint here. So let's try to write write
9:29:57the logic here. Uh so first of all we'll
9:29:59try to calculate the yearly salary. So
9:30:01how to calculate the yearly salary? I
9:30:03think you know that we have the monthly
9:30:04salary. So what I can do uh I can just
9:30:07multiply by 12. So this will give me the
9:30:09yearly salary and multi salary I have
9:30:12inside the state. You can see the
9:30:13monthly salary I have inside the state.
9:30:15So once it is done I'm going to update
9:30:17the yearly salary where in my state
9:30:19again. You can see we are updating this
9:30:21yearly salary in this state. Then we are
9:30:23returning the state. You know that every
9:30:26nodes return the state. Okay, we are
9:30:28returning the state. It's completely
9:30:29fine, right? We have written the first
9:30:31uh first nodes. Now like that we'll also
9:30:34write the second nodes uh state nodes
9:30:37doine. We have to execute this cell. Now
9:30:40let's execute. Okay, now it's working
9:30:42fine. Now the second node guys, we have
9:30:44to write for the calculate bonus for
9:30:48this one. Uh let's write this function
9:30:56def calculate bonus. This will also take
9:31:00um
9:31:02this will also take uh employee uh state
9:31:06that means the state and also return the
9:31:08state. Okay. And here we'll try to
9:31:10calculate the bonus. So you can see we
9:31:13whatever um
9:31:16so what I can do I can calculate the
9:31:19bonus based on the monthly salary
9:31:23monthly salary so I'll just try to
9:31:25multiply by two okay see here I'm not
9:31:29calculating the exact bonus yet just try
9:31:31to think about just I'm adding some
9:31:33bonus uh based on the monthly slid of
9:31:35that particular employee okay and after
9:31:37that we are adding this bonus amount uh
9:31:39inside the state then we are returning
9:31:41this state. Okay, it's done. Now we'll
9:31:44try to create the next one which is uh
9:31:46project evaluation
9:31:51node three project evaluation def
9:31:54project evaluation this will also take
9:31:56the state as an input and return the
9:31:57state as an output. So here I can just
9:32:00write a logic. So let's say this is the
9:32:02logic. I can write simple logic. If uh
9:32:06let's say the completed project amount
9:32:08is more than five. So that time I can
9:32:11just give the status excellent otherwise
9:32:14I'll just try to tell it's average one.
9:32:16Okay. Now I'll update this project
9:32:19status. Then I will return the status.
9:32:21Okay. So yeah this is our notes we have
9:32:23uh prepared. Now uh once it is done the
9:32:27at the last I will add this summary
9:32:28notes as well. Now let's add the summary
9:32:30note. So inside summary I'm just going
9:32:33to return all of the summary. That's it.
9:32:38So ref summary.
9:32:43So here I will just initialize the
9:32:46summary. Let's say this is the entire
9:32:48summary text. I've taken the f string
9:32:50and I'm just joining the string all
9:32:52together. employee employee name then
9:32:55has a yearly salary of yearly salary a
9:33:00bonus of bonus amount project status is
9:33:03the project status okay that mean this
9:33:05is a complete string I'm just writing
9:33:06and updating and returning it okay
9:33:09that's it now let me execute yeah my all
9:33:11of the nodes are prepared now what I
9:33:14have to do guys uh we have already
9:33:15created all of the nodes that means
9:33:17nodes is created now we have to add the
9:33:20edges okay this is called edges now we
9:33:21have to do the edge connecting
9:33:22connection. Now let's try to do the edge
9:33:24connection.
9:33:25So for this I think you know that we use
9:33:28this
9:33:30add edge uh uh addage function inside
9:33:33lang graph. So here I can comment h. So
9:33:36first of all try to see how we are going
9:33:38to connect the edges. You can see from
9:33:41start it is connecting to calculate
9:33:44bonus. It is connecting to calculate
9:33:47yearly salary. It is connected to
9:33:49project evaluation. Okay, that means
9:33:52simultaneously you can see it is having
9:33:54three connection. Okay, with calculate
9:33:56bonus, uh calculate yearly salary and
9:33:58project evaluation. So what I'm going to
9:34:00do, I'm going to do the same thing.
9:34:01First of all, I'm going to add this
9:34:04start with calculate yearly salary. Then
9:34:07I'm going to add with my calculate
9:34:10bonus. Then I'm going to add with
9:34:13project evaluation.
9:34:15Okay, I'm going to add with project
9:34:17evaluation. Now just try to um relate
9:34:20you can see start is connected with
9:34:22yearly salary calculate bonus and
9:34:23project evaluation. Okay. So these are
9:34:25the connection I have already made. You
9:34:27can see these are the connection I have
9:34:28already made. Now this connection is
9:34:31complete. Now I have to build this
9:34:32connection. Okay. That means now um
9:34:36calculate bonus is connected to the
9:34:37summary. Yearly salary also connected to
9:34:40the summary. Project evaluation is also
9:34:42connected to the summary. Okay. That
9:34:43means I have to build this connection.
9:34:44Now let's do that. So here what I'm
9:34:46going to do
9:34:48I'm going to write uh calculate yearly
9:34:51salary it is connected to summary
9:34:53calculate yearly salary it is connected
9:34:55to summary okay then calculate bonus it
9:34:59is also connected to the summary and uh
9:35:02project evaluation this is also
9:35:04connected to the summary okay project
9:35:06evaluation this is also connected to the
9:35:08summary and summary is connected to the
9:35:10end now let's add another edge
9:35:14H summary is connected to the end. Now
9:35:17just try to relate. Okay, just trust me
9:35:20if you can understand this one just the
9:35:23age connection at the node creation you
9:35:25can build any kinds of workflow inside
9:35:27langraph. Okay, any kinds of workflow
9:35:29you can create. So I hope guys you got
9:35:31it. Okay, I hope guys you got it how we
9:35:33have made this connection. Okay, and
9:35:36this is a independent connection. This
9:35:38is a independent connection. Nobody uh I
9:35:41mean none of the nodes is dependent on
9:35:44another nodes. Okay. So that's why we
9:35:46call it as a parallel workflow. Now let
9:35:48me show you for this. First of all we
9:35:50have to compile the workflow. Let's
9:35:52compile. Okay. Now I'll compile the
9:35:55workflow. Now you can just see the
9:35:57workflow graph. See if you're using uh
9:36:00this Jupyter notebook you don't need to
9:36:02write uh this extra code for that.
9:36:05uh I think in the recent update u they
9:36:07have uh automatically done this one in
9:36:10the cell itself. So previously I used
9:36:12this code to draw this graph but right
9:36:15now you don't need to do that. If you
9:36:17just print this workflow you'll
9:36:18automatically see this particular uh
9:36:20graph. Okay. Now see guys this is the
9:36:23graph and this is our parallel um
9:36:27parallel workflow we have created. Now
9:36:29just try to relate this graph. Okay. Now
9:36:31you can see start and it is connected
9:36:33with all of the nodes independently
9:36:35connected. Then whatever um result we
9:36:39are getting we are just returning the
9:36:40summary and we're ending the graph.
9:36:42Okay. So this is the parallel workflow.
9:36:44Now let's try to execute. So what I'm
9:36:46going to do I'm going to uh initialize
9:36:50my initial state and what should be the
9:36:52initial state. These are the uh state
9:36:54should be the initial one because we'll
9:36:56be taking these are the data from the
9:36:57user. So let's define that.
9:37:01So this is our initial state. You can
9:37:03see I'm taking the employee name. Um
9:37:05then monthly salary. So I'm going to
9:37:07take my name. Let's say I'm the
9:37:09employee. This is the monthly salary.
9:37:11This is the working days. And this is
9:37:12the completed project. Okay. Now we'll
9:37:14just try to run this workflow.
9:37:17Run the workflow. So we're just running
9:37:20this workflow dot invok. We are giving
9:37:22the initial state and we're getting the
9:37:24result. Now execute. Okay. Now see guys
9:37:28here we are getting one output. The
9:37:30output is add key employee name can
9:37:32receive only one value per step. Use an
9:37:35annotated key to handle multiple uh
9:37:38value. Now you can ask me why we are
9:37:41getting the error. Okay, why we are
9:37:43getting this error? Because everything
9:37:45is fine so far, right? Everything is
9:37:47fine so far. But why we're getting the
9:37:49error? See the reason I showed you this
9:37:52error? Actually, I could have fixed it
9:37:54previously, but I showed you this error
9:37:56so that you can relate the difference
9:37:57between the sequential workflow and uh
9:38:01this um this uh parallel workflow. Okay,
9:38:05if you can understand this, I think you
9:38:07won't be having any kinds of problem.
9:38:09See what is happening. If I show you my
9:38:12workflow again, so this is my workflow.
9:38:15See here we created the state, right? We
9:38:18created this state and we are passing
9:38:20the state to the all of these nodes. But
9:38:22if you just observe uh if you just
9:38:24deeply observe what is happening
9:38:26whenever we are passing this uh state uh
9:38:29to all of the nodes what is happening to
9:38:31calculate the bonus what I'm using okay
9:38:34to calculate the bonus what I'm using
9:38:36I'm using this uh initial state that
9:38:39means whatever data user is passing I'm
9:38:40I'm using that so to calculate this I
9:38:43think I was using this um monthly salary
9:38:46only right I was using the monthly
9:38:47salary and I was updating this value
9:38:52wire
9:38:53in this particular section
9:38:56that means this boner bonus amount
9:38:58variable would be changed okay after
9:39:01running this state this particular
9:39:03variable would be changed I'm not
9:39:04changing these are the variable right
9:39:06that means the monthly salary is remain
9:39:08same I'm not changing it anywhere that
9:39:10means the employee name I'm also not
9:39:11changing working days also I'm not
9:39:13changing completed project also I'm not
9:39:16changing right I'm only changing these
9:39:18are the variable here but these are the
9:39:20variable remains same common right so
9:39:23wherever you are passing the state
9:39:25everywhere it is updating here only not
9:39:27here okay so that's why in parallel
9:39:30workflow whenever you are giving this
9:39:32simultaneously to all of the nodes okay
9:39:35so this nodes uh actually
9:39:39conflicts each other conflicts each
9:39:40other means there is no update so it
9:39:43conflicts like uh whether the value we
9:39:45are getting here this is correct for
9:39:46this nodes or not whether the value we
9:39:49are getting here this is correct correct
9:39:50for these nodes or not. Okay, that means
9:39:52it conflicts inside because we are
9:39:55returning the entire state. Here you can
9:39:56see we are returning the entire state.
9:39:58Although we are not updating this at the
9:40:00state but still we are returning the
9:40:02entire state that means the entire state
9:40:04will go to the another node. Okay, that
9:40:06means the entire state will go to the
9:40:08another node. Although we are not doing
9:40:10any kinds of update but we are returning
9:40:11the state. Okay, it's not recommended.
9:40:13So whenever you are creating the
9:40:14parallel workflow you have to make sure
9:40:18only the update you are doing inside the
9:40:20variable that particular variable or
9:40:22that particular state you have to return
9:40:23only okay let's say in this case let me
9:40:26just give you an example let's say in
9:40:28this case we are only calculating what
9:40:31we are only calculating the yearly
9:40:32salary so instead of returning all the
9:40:34state together what I'm going to do only
9:40:36I'm going to return the yearly salary
9:40:38okay because this is a parallel one I
9:40:41don't need to like wait for my employee
9:40:44name monthly salary these are the things
9:40:45right whatever update I'm just doing
9:40:47I'll just only try to return that so
9:40:49instead of uh this uh update what I'm
9:40:52going to do guys I'm going to only
9:40:54return
9:40:57I'm going to only return
9:41:01uh yearly salary
9:41:05see I'm going to only return the yearly
9:41:07salary we have calculated we are only
9:41:08returning that because at the end uh
9:41:11this is this is a dictionary. Okay, this
9:41:13this nodes returns a dictionary. Okay,
9:41:14we have to return a dictionary somehow.
9:41:16Now I don't need to give this time type
9:41:18time type time type time type time type
9:41:18time type time type time type time type
9:41:18time type time type int. Okay, this is
9:41:19not required because we are not
9:41:20returning the entire employee state.
9:41:22Okay, now I'm going to just remove it.
9:41:24So only it will take the state and
9:41:26whatever update it will do inside the
9:41:28state and that state will only return
9:41:30not any other state. Okay, not any other
9:41:33state only the updated one it will
9:41:34return. So for this I'll uh update for
9:41:36all the nodes I have done. So let's say
9:41:39here
9:41:40uh I was
9:41:43uh updating the bonus amount. So I'll
9:41:45only return the bonus amount and this
9:41:47thing is not required.
9:41:52Okay. Now for this project evaluation
9:41:55also I'll do the same thing.
9:42:00Return the project status. This thing is
9:42:02not required.
9:42:04Now for summary also
9:42:07we'll do the same thing.
9:42:16This is not required. Okay. So let me
9:42:19check everything is fine or not. Yeah,
9:42:21everything is fine. Now let me execute
9:42:22from the beginning.
9:42:26Now our workflow is created.
9:42:29Now we'll
9:42:31uh now we'll just try to invoke this
9:42:33workflow. Now see it's working. Now if I
9:42:35print the result
9:42:38see we are getting the final result. So
9:42:40this is the employee name, monthly
9:42:41salary, working days, completed project,
9:42:44yearly salary. So see we got the
9:42:46calculated yearly salary. Then bonus
9:42:49amount project status excellent because
9:42:52the completed project is seven and our
9:42:55logic was if it is more than five right
9:42:57more than an equal five that means it is
9:42:59excellent you are getting the excellent
9:43:01here and here's the summary but summary
9:43:04is giving a function so let me check
9:43:10okay so this should be summary text I'm
9:43:13just returning the function only right
9:43:15the nodes only so this should be a um
9:43:18this this variable. Now I think this
9:43:20should work.
9:43:26H now we are getting the summary.
9:43:28Employee BP has yearly salary of that
9:43:31amount. Bonus uh bonus is that amount
9:43:33and project status is excellent. Okay.
9:43:36So this is our uh uh parallel workflow
9:43:39guys we have created and I hope you
9:43:41understood. Okay. Okay, I hope you
9:43:43understood and uh this particular
9:43:45concept also you understood why we don't
9:43:47need to return the entire state inside
9:43:50parallel workflow. If you're creating
9:43:52the sequential workflow, it's completely
9:43:54fine. You can return the entire state
9:43:56that time. Okay, you can return the
9:43:57entire state that time. But whenever you
9:44:00are creating the parallel workflow, make
9:44:01sure only the state you are changing,
9:44:05just try to uh return those state only.
9:44:08Okay, not the entire state. Okay, you
9:44:10don't need to do like that because uh
9:44:13internally it will do the conflict
9:44:14operation because we can't pass
9:44:16simultaneously to all of the nodes the
9:44:19same state. Okay, this is not possible.
9:44:21So in every state that should be that
9:44:23should uh should be updated. Okay, state
9:44:26should be updated. But here you can see
9:44:28it is not getting updated. Okay, after
9:44:30going to the every state, every nodes it
9:44:33is not going to be updated. Okay, that's
9:44:34why this is going to be conflicted. So
9:44:37we have to update it somehow. So that's
9:44:39why we only are returning these are the
9:44:41state which is getting updated. Get it?
9:44:43Yeah. So this is the concept guys and
9:44:45this is our first non nonLM based
9:44:48workflow we have created and this is the
9:44:49parallel workflow. It is executing as
9:44:52parallel. Okay. Now we'll try to create
9:44:55another workflow. Uh we'll use the LLM
9:44:58and we'll call as a LM parallel
9:45:00workflow. Now let's try to see how we
9:45:02can uh create this LLM based parallel
9:45:05workflow guys. So guys, so far we have
9:45:08created uh this nonLM based parallel
9:45:11workflow. Uh we have already seen the
9:45:13example how it can be done. Now I'm
9:45:16going to show you how we can create LLM
9:45:18based parallel workflow. Now we'll try
9:45:20to integrate LLM with that. And for this
9:45:23example uh I'm going to take uh this
9:45:26particular demo called SA workflow. So I
9:45:28think you remember uh in my introductory
9:45:31session whenever I was giving you the
9:45:33introduction about the langraph I used
9:45:36one example called essay okay essay
9:45:38writing example so there there I created
9:45:40a system I created a workflow that
9:45:42workflow takes an essay as an input and
9:45:45it does uh the evaluation based on some
9:45:47parameter like uh it checks the um it uh
9:45:52depth analysis then language uh
9:45:55evaluation then uh um like research of
9:45:58thought evaluation. Okay, based on that
9:46:01uh it returns you uh some kinds of
9:46:03feedback as well as the score and we get
9:46:06the final evaluation then we conclude
9:46:08that right. So these kinds of things I
9:46:10think I uh already discussed about my uh
9:46:13this session. Okay. Uh this is the
9:46:15number seven video I have already
9:46:16discussed. You can go through that uh if
9:46:18you want to understand about that
9:46:20particular workflow. But again I'm going
9:46:22to um show you the workflow here. I
9:46:24already created the workflow. I'm going
9:46:25to discuss it here. And uh you can also
9:46:27see what is essay. Essay is a like uh
9:46:30it's a short non-frictional
9:46:32piece of writing that presents a
9:46:34specific argument analysis or personal
9:46:36point of view on a particular subject.
9:46:38Okay. So basically whenever you um
9:46:41attend any kinds of uh let's say uh
9:46:44exams or you if you are studying in a
9:46:47university any kinds of university that
9:46:48uh so these are the essay writing you
9:46:50will be getting there. Okay. So this is
9:46:52a kinds of research topic you can talk
9:46:54about. So what I'm going to do I'm going
9:46:56to take this same example uh here to
9:47:00make you understand this LM based
9:47:01workflow because here we'll be utilizing
9:47:03the LLM to analyze is the essay right
9:47:05and we'll also do the marking and all.
9:47:07So this is the workflow. This is the
9:47:09graph guys. Uh we we I have created as
9:47:11you can see start and end nodes would be
9:47:14common and these are the nodes we'll be
9:47:15creating. Uh evaluate analysis nodes.
9:47:18That means uh whatever essay topic will
9:47:20be giving right. Uh essay will be giving
9:47:22it will try to evaluate the analysis
9:47:24whether the analysis section is good or
9:47:26not. It will evaluate and it will give
9:47:27you two things. Okay. This is this will
9:47:29give you two things. Uh just let me
9:47:32write down
9:47:33what I can do. I can take a screenshot.
9:47:40I can take a screenshot and I'll open up
9:47:42my board.
9:47:46So now let me tell you
9:47:52so let's say you are giving a essay
9:47:54here. You are giving a
9:47:58essay here. Okay. That that means the
9:48:01entire essay essay text you are giving.
9:48:03So basically first of all we'll be
9:48:04running this uh evaluate analysis. So
9:48:07this evaluate analysis will try to
9:48:08analyze the entire essay. It will this
9:48:10it will give you two things. The first
9:48:12one is the uh feedback.
9:48:16Okay
9:48:17feedback feedback of the essay and
9:48:21second one is the score.
9:48:23This will give you a score. Uh let's out
9:48:26of 10 it will give you some kinds of
9:48:27score. Then next nodes we have writing
9:48:30for the evaluate language. Let's say you
9:48:32are using English language, right? So,
9:48:35how is your grammatical uh let's say uh
9:48:38I mean uh grammatical arrangement or if
9:48:41you are following the right grammaticals
9:48:44structure or not and uh what is the
9:48:46words you are using. So this kinds of
9:48:48language related evaluation will perform
9:48:50then again this will give you a
9:48:51feedback.
9:48:54Okay. And this will also give you a
9:48:55score out of 10 right then we'll just
9:48:58perform another analysis. This is the
9:49:00like uh uh thought analysis. Thought
9:49:03analysis means the thought thought of on
9:49:06top of this essay. Okay. Uh so here this
9:49:08will also give you a feedback
9:49:12and the score.
9:49:15Okay. That means every nodes we are
9:49:17getting two two things feedback score.
9:49:20Feedback is score feedback is score.
9:49:21Okay. Then we'll pass this feedback
9:49:24score uh uh feedback and score all of
9:49:26the feedback and score from all of the
9:49:28nodes. Let's say this is node one, this
9:49:29is node two, this is node three to
9:49:31another nodes called final evaluator. So
9:49:33that means this will evaluate based on
9:49:35all of the feedback. Let's say this is
9:49:37feedback one, this is feedback two, this
9:49:38is feedback three. So it will take all
9:49:40of the feedback then it will give you
9:49:41the final feedback.
9:49:43Final feedback,
9:49:47okay, or evaluation. Then it will take
9:49:50all of this code, okay? All of this
9:49:52code. And this will return you the
9:49:54average score of that. Okay, average
9:49:57final score of that. Okay, so this is
9:50:00how actually we'll be uh implementing
9:50:02this particular essay. Then once it is
9:50:03done, we'll try to end this particular
9:50:06uh end this particular but um graph.
9:50:09Okay, now if I get back to my workflow,
9:50:12I think now you are getting right and to
9:50:14make this workflow I need these state.
9:50:16Okay, I already prepared the state as
9:50:18you can see. I need this state. I named
9:50:20it as assay state and I inherited with
9:50:22type dict and first of all I need to
9:50:24take the essay and essay should be
9:50:25string right this is a variable then
9:50:28language feedback that means uh here so
9:50:30evaluate uh language this will basically
9:50:32do the language uh language evaluation
9:50:35and whatever feedback we'll be getting
9:50:36we'll try to save inside language
9:50:38feedback then it will also give you uh
9:50:40this will also give you um another score
9:50:44right uh that means the uh language
9:50:46score so instead of storing inside a
9:50:48single var variable. So what I'm doing?
9:50:50So here you can see I have taken another
9:50:52variable called individual score. Okay.
9:50:55And here I use this annotated list
9:50:58integer operator add. So I think you can
9:51:01call this uh call this concept right. So
9:51:03this is called actually reducer. I
9:51:05already talked about the reducer here uh
9:51:07in my um demo whenever I was explaining
9:51:10about the langraph core component there
9:51:12I talked about the reducer. So if you
9:51:14haven't watched that video guys please
9:51:15try to watch because this is important
9:51:17without that actually you won't be able
9:51:18to understand what is reducer exactly.
9:51:20So reducer uh will help us to uh replace
9:51:24add and merge the uh like data inside
9:51:28the state. So uh by default it will
9:51:30replace everything. I think so far
9:51:32whatever state we have created it was
9:51:34replacing every time right but as you
9:51:36can see from each and every nodes from
9:51:39each and every nodes we are getting some
9:51:41score. Okay, let's say if I'm only
9:51:43taking one let's say score variable. So
9:51:46what will happen? So whenever I'll get
9:51:48this score from here, let's say I got 12
9:51:50uh sorry I got let's say 8. Then from
9:51:54this particular nodes I'm I get another
9:51:56score from this particular node I get
9:51:58another score. Let's say this is 8.5. So
9:52:00what I will do this 8.5 8 would be
9:52:02replaced by 8.5. So that means I will
9:52:04lose my previous score of that evaluate
9:52:06analysis. Right? Then let's say this
9:52:08this node has generated another one.
9:52:10Okay, let's say 9.5. So again, it will
9:52:13replace by 9.5. So I lose my previous
9:52:15like uh score, right? But I need all of
9:52:17this code to make the average. So I need
9:52:20this score as well. I need this score as
9:52:23well. I need this score as well. That
9:52:24means I need to keep inside a
9:52:27dictionary. Let's say the first score
9:52:29I'm getting eight. Second score I'm
9:52:31getting 8.5. The third score I'm getting
9:52:339.5. I'll store all of the score from
9:52:36all of the nodes. Okay, inside a list.
9:52:39Then I'm going to create a average of
9:52:40that particular score. And this is going
9:52:42to be my final evaluation. Okay. And for
9:52:45this we are using this operator do add
9:52:47here. Okay. You can see we are using
9:52:49operator do add here. And we are using
9:52:51annotated. Okay. I think you know what
9:52:53is annotated. Whenever I want to use
9:52:55reducer, right? I have to use this
9:52:57annotated. And here we are mentioning
9:52:59that should be a list of integer. Okay.
9:53:01There should be a list of integer. That
9:53:03means I want to uh I want to uh let's
9:53:06say store uh store list of integer here.
9:53:09So here I have taken a float value but
9:53:10you can consider I want to uh you can
9:53:13also like give it as float value here.
9:53:15Let's say sometimes uh score should be
9:53:17also um float value 8.5 7.5 but I told I
9:53:21need only integer type uh like feedback
9:53:24okay integer type score. So that's why
9:53:26given list of integer and operator dot
9:53:29add that means I want to perform reducer
9:53:31reducer what operation add operation
9:53:34that means instead of replacing it will
9:53:35every time add all of the score so
9:53:37whatever score I'm going going to get
9:53:39from my evaluator analysis I'll store it
9:53:41here okay apart apart from the feedback
9:53:43then from evaluator language also I'm
9:53:46going to add the score from uh evaluate
9:53:48thoughts whatever feedback score I'm
9:53:50getting I will also try to add there
9:53:51okay so that's how you can see for all
9:53:54of the nodes I have indiv individual
9:53:56variable. So you can see language
9:53:58feedback I have one variable then
9:54:00evaluate of thought that means uh uh
9:54:04this one
9:54:06clarity feedback okay uh this is uh
9:54:08clarity of thought you can consider and
9:54:10the full name is clarity of thought we
9:54:12have taken a variable called clarity
9:54:14feedback so basically this feedback will
9:54:16store here then we have evaluator
9:54:19analysis that means the analysis
9:54:20feedback it will store here okay that
9:54:22means language analysis then evaluate
9:54:26thoughts. Okay, clarity of thoughts.
9:54:28Then the overall feedback. That means
9:54:30from final evolution also we are getting
9:54:31a feedback. From final evaluation also
9:54:34we are getting a feedback. So this
9:54:35feedback will store inside overall
9:54:37feedback. Okay. And final evalution will
9:54:41give you another uh score which is
9:54:43average score. And for average score we
9:54:45have kept another separate variable
9:54:47called average score. And this should be
9:54:48a float value. Okay. And for individual
9:54:52uh score we are getting we are storing
9:54:54inside this particular list. Okay,
9:54:56individual score this should be a list
9:54:58and we are performing the reducer add
9:55:00operation. Okay, now I think you got it
9:55:02how we created this particular state.
9:55:05Okay, how we created this particular
9:55:06state. Now I think this is pretty much
9:55:08clear guys
9:55:10and to understand this reducer concept I
9:55:12will suggest you go through this uh
9:55:14recording. Okay, lang core component you
9:55:15will try to understand okay how reducer
9:55:17works. So yeah, I think our uh uh our uh
9:55:21state is ready. Everything is ready. Now
9:55:23we can start working on that. But one
9:55:25more issue we'll be having which is this
9:55:27u uh output format. Okay, that means I
9:55:31need a structure output from my LLM.
9:55:33That means every nodes will return
9:55:35feedback and score feedback and score
9:55:37feedback and score. And we are using LLM
9:55:38and you know LLM is unstructured uh uh
9:55:41data generator. Okay, we won't be
9:55:43getting this kinds of feedback score
9:55:45every time. Let's say if you're adding
9:55:47by the prompt I need a feedback and
9:55:49score only let's say it will run five
9:55:51times maybe in six times it will give
9:55:53you some other parameter as well that
9:55:55time your code will crash right so to
9:55:57make our output stack chart so I taught
9:56:00you about uh I already taught you about
9:56:02this pyantic right so you can see
9:56:04pyantic for AI agents I've already taken
9:56:07a class on that so you just need to go
9:56:09through this pantic because we'll be
9:56:11using pentipic concept to get the
9:56:13structured output from my lm Okay. Now
9:56:16let's try to show you how it can be
9:56:17done. So what I'm going to do here I'm
9:56:19going to create another um another file.
9:56:23So I'm going to name it as
9:56:26pipe
9:56:30as a workflow.
9:56:39I'm going to select my environment.
9:56:43So first of all I will import all of the
9:56:45necessary library.
9:56:47So I need this state graph start end
9:56:50okay from lang graph. Then I also need
9:56:55openi model because here I'm going to
9:56:58use llm and for lm I'm going to use
9:57:00openi model. You can use any model. Okay
9:57:02it's up to you. You can use gemini gro
9:57:05provider any kinds of model you can use.
9:57:07But I already have the open API key
9:57:09yesterday. I already collect uh
9:57:10collected. I think remember okay that's
9:57:12why I'm using that then uh okay I'm
9:57:15going to close this
9:57:17then I need this uh load env to load my
9:57:21involvement variable because inside
9:57:23environment variable I I have my API key
9:57:25then I need um
9:57:28these are the
9:57:32these are the import as well from typing
9:57:34I'm importing this type dict and
9:57:35annotated why annotated because you know
9:57:37that uh to make this reducer Okay, I
9:57:41need this annotated. Okay, annotated is
9:57:43required. Uh and it is available inside
9:57:45this typing. We are importing annotated
9:57:47and we are using pientic. So from
9:57:49pientic we are importing base model
9:57:53and field and you have to install
9:57:56pientic for this. Uh let me install
9:57:58pientic.
9:58:04Pentic
9:58:06I'll install this specific version of
9:58:08the piantic. Now let me
9:58:12uh activate my environment.
9:58:20Then let's install the requirements
9:58:22again.
9:58:32Okay. Done. Now I'll come here. Now you
9:58:35can use this pi identic. So from identic
9:58:37I'm importing base model and field and
9:58:39what this base model field does guys I
9:58:41already discussed in this session please
9:58:42go through that okay I'm not going to
9:58:44repeat again so this session will give
9:58:45you the entire entire idea about pi
9:58:47identity okay why it is required and
9:58:50operator for this add operation that
9:58:53means for the reducer okay uh operation
9:58:56dot add operator do add we have to write
9:58:58it here so once it is done now let me
9:59:00import all of the package yeah so it's
9:59:04working fine now first of all we'll try
9:59:06to load put the involvement variable.
9:59:10Yeah. Then we'll prepare the model.
9:59:14So here I'll take GPT4 mini. Okay. This
9:59:17model. This is our LM. Now you can
9:59:21perform the invoke operation if you want
9:59:24directly. But if you perform the invoke
9:59:26operation right now, so what will
9:59:27happen? Uh this will uh give you
9:59:29unstructured output. But I need what? I
9:59:32need only this uh feedback and score.
9:59:34Okay. Okay, I need feedback score uh
9:59:36from this uh model. Okay, whatever essay
9:59:39I'll give you um I'll I'll give to this
9:59:42uh model, it will give me feedback and
9:59:44score. So I have to make the structure.
9:59:46So how to make the structure? For this
9:59:48we'll be using the pyic. So here I have
9:59:51created one pentic class.
9:59:54So this is the pentic class. So the name
9:59:58of the pyic class is evaluation schema.
10:00:01Uh and we are inheriting with the base
10:00:03model. Okay, the base model we have
10:00:04imported here, we have inherited and
10:00:08here is the pentic syntax. Okay, this
10:00:11syntax I already taught you in that
10:00:12session. So this should be uh string and
10:00:14this should be integer and here I have
10:00:16given the field. So in the field I'm
10:00:18telling detail feedback for for the
10:00:22essay and for score I've given a
10:00:25description score out of 10. uh so this
10:00:28is the greater than and this is the
10:00:30lesser than okay greater than zero and
10:00:32lesser than 10 so this should be the
10:00:34score so this that's how you can make
10:00:36the structured output from any kinds of
10:00:38given lm okay now uh to make the
10:00:43structured uh model what I'm going to do
10:00:46simply I'm going to just add this uh add
10:00:51the schema to the model so for this you
10:00:53have to call the model dot with
10:00:56structure output there is a function
10:00:57function called with structured output I
10:00:58think
10:01:02with structured output inside that you
10:01:04have to pass this class okay this pentic
10:01:07class now this will set um uh into the
10:01:10model that means whenever you will
10:01:12generate any kinds of output this will
10:01:14have two things one is the feedback is
10:01:16the score okay now I'll store inside
10:01:19another variable called structured model
10:01:21now this is going to be my structured
10:01:23model object okay now every time I'm
10:01:25call this I'm going to call this model.
10:01:27Okay, not this model. This model will
10:01:28give you unstructured output, but this
10:01:30model will give you the structured
10:01:31output. Okay, now let me execute
10:01:36and see whether everything is fine or
10:01:38not. H now if you want to test guys, so
10:01:40maybe I can show you. So I'll give a
10:01:42essay here.
10:01:44So this is one essay I generated from
10:01:46chart GPT. You can see this is essay I
10:01:49generated from chart GPT Europe in the
10:01:52age of AI, the regulatory super power.
10:01:55So what I'm going to do, I'm going to
10:01:57pass this asset to this structured model
10:02:00with a prompt.
10:02:03So this is the prompt uh I have written.
10:02:05Evaluate the language quality of the
10:02:08following essay and provide a feedback
10:02:11and assign a score out of 10. Okay, I'm
10:02:12giving the essay text here and right now
10:02:15I'm calling the structured model, not
10:02:16the model only. Okay, structured
10:02:18model.invoke and I'm passing the prompt.
10:02:20Now this will give you the result.
10:02:24Okay, result I stored inside result
10:02:26variable. Now let's execute.
10:02:38Yeah. Now if I print this result,
10:02:44you'll see that it will have two
10:02:46parameter. One is the feedback. Okay.
10:02:48Feedback of the essay and another one is
10:02:51the score. Okay, see I got this code.
10:02:54You can also extract it if you want. So
10:02:56you just simply need to write result dot
10:03:00feedback.
10:03:04Okay, you'll get the feedback and if you
10:03:06want this code, you can call
10:03:08result.core.
10:03:10Okay, this this code you got. I hope you
10:03:13got it guys. Okay, that's with the pyic
10:03:15you can um you can get the structured
10:03:17output from any large than case model.
10:03:19Okay, this is very much important.
10:03:22Now we'll try to start writing our uh
10:03:25this workflow. Now first of all let's
10:03:26prepare this state. So already state is
10:03:29given. I'm going to just replicate the
10:03:30same state here.
10:03:33So this is our state
10:03:36essay state. So we giving the essay
10:03:38language feedback test analysis feedback
10:03:40clarity of clarity feedback overall
10:03:42feedback individual scores and this is
10:03:44uh reducer uh reducer concept you're
10:03:47using. Basically this should be a list
10:03:48of score. Okay. and it will add every
10:03:50time and the average score. Now let's
10:03:53initialize that.
10:03:55Now we'll write our our graph. Let's
10:03:58prepare the graph.
10:04:01Yeah. So we have given this state to
10:04:03this graph. Okay. Now we'll try to add
10:04:08the nodes. So first of all I will add
10:04:10this node, this node, this node. Okay.
10:04:13And the final evalation node. Total four
10:04:15nodes I have to add. Let's add it. Um I
10:04:19have already prepared all of the node
10:04:24add node.
10:04:30So yeah you can see we're adding the
10:04:31nodes. First of all we're adding the
10:04:33evaluation evaluate language. Okay
10:04:36evaluate language this node. Then we are
10:04:38adding evaluate analysis this node. Then
10:04:42we are giving evaluate thoughts this
10:04:44node. Okay. Then last final evaluation.
10:04:47final evalation. Okay, my node is done.
10:04:50Now we have to uh create these are the
10:04:52Python function one by one. Let's create
10:04:54quickly.
10:05:04So here I'm going to just create it
10:05:06quickly. First of all I'm going to
10:05:07create this function evaluate language.
10:05:11So I already created let me show you.
10:05:15Yeah. So evalute language this will take
10:05:17this state as an input and here you can
10:05:19see uh I'm using llm and for this I
10:05:22prepared a prompt. So here I'm telling
10:05:24evaluate the language quality of the
10:05:26following essay and provide a feedback
10:05:27and assign a score out of 10 and we're
10:05:29giving the state uh sorry essay from the
10:05:32state. Okay and we are calling this
10:05:34structured model that means the
10:05:36structured model we have prepared here
10:05:38this model. Okay, instead of this model,
10:05:40so structured model, so this model will
10:05:42give you two things. One is the
10:05:43feedback, one is the score. So the
10:05:46feedback we're storing inside language
10:05:47feedback. That means this particular
10:05:49variable because we are evaluating the
10:05:51language here. That's why feedback will
10:05:52go to the language feedback. And the
10:05:54score we are getting we are storing
10:05:56inside individual score and this is um
10:05:59like uh reducer type that means we are
10:06:01adding inside a list. So that's why you
10:06:04can see individual score output score.
10:06:06Okay, that means the first code will
10:06:08save here. That means let's say
10:06:10uh what I'm going to do
10:06:16see
10:06:17that means um from here uh evaluate
10:06:21language right I think it is evaluate
10:06:23language uh evaluate language so that
10:06:26means we are executing this note so this
10:06:28node will give you two things one is the
10:06:29feedback
10:06:32one is the score okay so feedback I
10:06:35already stored inside my feedback um
10:06:39feedback um uh feedback state that means
10:06:43here language feedback now score okay
10:06:45score what I'm doing because I created
10:06:47an individual feedback variable okay uh
10:06:50so here let me show you
10:06:52maybe I can take a screenshot
10:07:06so Here you remember I created this
10:07:10individual score variable. So basically
10:07:11this is a list. Okay. This should be a
10:07:13list. This should be a list. Okay. And
10:07:16we added our first score which is this
10:07:20uh evaluate language. Let's say it has
10:07:21given you eight. Okay. Then there would
10:07:24be a comma
10:07:26done. Okay. Now I will write for the
10:07:29next nodes which is evaluate analysis.
10:07:32Okay. because I already executed uh I
10:07:35already created this node evaluate
10:07:36language this will give you feedback and
10:07:38it's code I already got it and instead
10:07:40of returning all the state we are
10:07:41returning the updated one only because
10:07:44in my previous example I showed you if
10:07:46you're creating parallel workflow you
10:07:48don't need to return the entire state
10:07:50instead of that only you just you just
10:07:52need to return the updated state okay
10:07:54otherwise there would be a conflict
10:07:56problem okay yeah so now let me define
10:07:59this node now once it is done I'll
10:08:02define Find the next note which is the
10:08:05depth of analysis. Evaluate analysis.
10:08:08This will take the state and here we are
10:08:10giving the prompt again. Evaluate the
10:08:12depth of analysis of the following essay
10:08:13and provide a feedback and assign a
10:08:16score out of 10. And we are giving the
10:08:17essay and this will uh pass to the
10:08:19structured model. This will give you two
10:08:21things. One is the feedback. So this
10:08:22feedback I'm storing inside analysis
10:08:24feedback. that means here in this
10:08:27particular variable and it is giving you
10:08:29the individual score and we are uh
10:08:32storing this uh score in the individual
10:08:34score that means here okay this is a
10:08:37list so like let's say this has given
10:08:39you uh again eight okay this will store
10:08:42here okay that's how we are storing now
10:08:47this is also done now we'll write for
10:08:50the next one which is
10:08:53clarity of thought analysis is evaluate
10:08:55clarity clarity of thought. Again, this
10:08:57will take the state as an input. We are
10:08:59defining the prompt. Evaluate the
10:09:00clarity of the thought of the following
10:09:02essay and provide a feedback analysis
10:09:04and assign a score out of 10. Okay,
10:09:06we're giving the essay and we are
10:09:09passing it to the structured model
10:09:14and this will give you two things. One
10:09:15is the feedback. So feedback I'm storing
10:09:17inside clarity feedback in this uh
10:09:20variable and the score we are getting
10:09:22we're storing inside individual score.
10:09:24Okay, that means here then again it will
10:09:27get give you another score. Let's say
10:09:29you got uh nine here. Okay, so that's
10:09:32how your individual score will form,
10:09:35right? And now we have all of the score
10:09:37from all of the nodes. Now we'll try to
10:09:39make the average one. Okay, later on.
10:09:42Now it's done. You can see uh we are
10:09:44also returning uh these two things
10:09:46clarity of uh clarity feedback and
10:09:47individual scores and this will become
10:09:49my next node. Now we have to work on the
10:09:53uh final node which is final evaluation.
10:09:56Now let's also write that
10:10:00this is our final evaluation nodes.
10:10:02Again this will take the state as an
10:10:04input and again we are preparing a
10:10:06prompt based on the following feedbacks.
10:10:08Uh create a summarized feedback. Okay.
10:10:10Now here we are passing all of the
10:10:12feedback one by one. That means this
10:10:14feedback, this feedback, this feedback.
10:10:16Okay. This feedback, this feedback, this
10:10:18feedback. Three feedback we are giving.
10:10:20language feedback
10:10:22then depth of analysis feedback clarity
10:10:24of thought feedback and I'm just uh
10:10:28telling the model give me a overall
10:10:30feedback and right now I only need a
10:10:32feedback I know I don't need any kinds
10:10:34of score okay so that's why I'm using
10:10:37the original model instead of working on
10:10:40the structured model I'm now invoking
10:10:43the original model because I only need
10:10:45the feedback that's why I'm invoking on
10:10:48the original model I'm giving giving
10:10:50this prompt and whatever content it is
10:10:52generating I'm just storing inside
10:10:53overall feedback. Okay. Now I have to
10:10:56calculate the average um average score.
10:10:58Okay. And how to calculate the average
10:11:00score? Because I already have the all of
10:11:02this score, right? All of this score as
10:11:04a list. Now you can see from this state
10:11:07I'm extracting the individual score.
10:11:09Okay, individual score uh because this
10:11:12is a list. Okay. Now we are calculating
10:11:14the length of this uh uh uh like list
10:11:18and how many uh like let's say variable
10:11:21uh how many value we are having we are
10:11:23just doing the dividing operation. Okay
10:11:25first of all we are doing the sum
10:11:26operation you can see. So how to
10:11:28calculate average? First of all you will
10:11:29do the sum operation. You will do the
10:11:31sum operation 8 + 8 + 9. Okay then
10:11:34you'll just try to divide with the
10:11:36number of uh item you have. Let's say we
10:11:38have three here. Now whatever output you
10:11:40will be getting this is your average.
10:11:42Okay. So we are calculating the average
10:11:43like that. First of all we are summing
10:11:46all the value. Then we are dividing with
10:11:48length of the uh item we are having
10:11:50inside the list. Then this is going to
10:11:52be your average score and we are
10:11:54returning the overall feedback and
10:11:56average score. So overall feedback we
10:11:57are storing inside this variable overall
10:12:00feedback and the average score we are
10:12:02storing this average. Okay average score
10:12:04here. That's it.
10:12:07Okay. Now all of the function we have
10:12:09created. Now we have to add the nodes.
10:12:11Now let's try to refer this graph and
10:12:13add the nodes. Now see whenever you are
10:12:15adding the nodes first of all you can
10:12:17see start would be connected to the
10:12:18evaluate analysis evaluate language
10:12:20evaluate of thoughts. Let's add that
10:12:29addages.
10:12:35Yeah. So you can see start is connected
10:12:37with evaluate language, evaluate
10:12:39analysis, evaluate thoughts, evaluate
10:12:42analysis, evaluate language, evaluate
10:12:43thoughts. Okay, that means these are the
10:12:45connection we have built. Now evaluate
10:12:48analysis is connected with final
10:12:49evaluation. Evaluate language is
10:12:51connected with uh final evaluation and
10:12:53evalu evaluate thought is connected to
10:12:55final evaluation. Now I have to make
10:12:57this connection. Now let me do that.
10:13:01See evaluate language is connected to
10:13:04the final evaluation. Evaluate analysis
10:13:05is connected to the final evaluation.
10:13:07Evaluate at heart is connected to the
10:13:09final evaluation. That means this
10:13:10connection is also done. Now final
10:13:12evaluation is connected to the end.
10:13:17Now final evaluation is connected to the
10:13:19end. Okay. Now we have to compile the
10:13:21graph.
10:13:25Done. Now if you print the workflow.
10:13:29So that's how your workflow looks like.
10:13:31And now you can verify this workflow and
10:13:33this workflow. Okay. These are same. Now
10:13:37I need to uh invoke this workflow. So
10:13:40for this let's prepare another essay.
10:13:43So I generated another ay from my chart
10:13:45GPT. So this is another essay. I named
10:13:48it as ay 2. Okay. So this is in test
10:13:50state in the age of AI then
10:13:52infrastructure and capital super power.
10:13:55So I'm going to invoke it right now with
10:13:57my workflow.
10:13:59So let's do that.
10:14:02So first of all here I have prepared the
10:14:04initial state and I have given my SA
10:14:06okay then we are involving the workflow
10:14:09and this will return you the result
10:14:29done now we'll print this result.
10:14:33See here you have all of the data. So
10:14:35this is the essay. This is the language
10:14:37feedback you got. This is the analysis
10:14:39feedback feedback you got. This is the
10:14:40clarity feedback you got. This is the
10:14:42overall feedback you got. This is the
10:14:44individual scores for from all of the
10:14:46nodes. Okay. And this is the average
10:14:48score. I hope you get it guys. See
10:14:52amazing right? So that's how we can
10:14:54create any kinds of LLM based parallel
10:14:57workflow. Uh now I think it is pretty
10:14:59much clear and the only things is that
10:15:03you have to understand the connection
10:15:05you have to understand this graph and
10:15:07the state. Okay the state you will be
10:15:08using here and when to use this u
10:15:12reducer when to use the pantic you have
10:15:15to understand
10:15:17uh by seeing the problem statement. So
10:15:20here two things you have learned um I
10:15:23just used in this particular practical
10:15:25demo. One is the pientic how to use
Master Conditional Workflows in LangGraph
10:15:28pientic to get the structured output.
10:15:30Okay. Then another one this reducer. So
10:15:34reducer we already uh saw right uh in
10:15:37the concept understanding now we
10:15:40practically applied this reducer as
10:15:42well. Okay in the lang lang graph. So
10:15:44yes guys uh this is all about uh that's
10:15:47how we can create any kinds of parallel
10:15:48workflow. Now in the next video I'm
10:15:51going to teach you some other workflow
10:15:53like conditional, iterative. Okay, each
10:15:56and everything we'll try to discuss then
10:15:58we'll also implement some amazing uh
10:16:01practical project. Okay, agent project.
10:16:03Okay, in our previous video I have
10:16:06already discussed about uh parallel
10:16:08workflows like how parallel workflow
10:16:10works and uh we already did the coding
10:16:13as well with the help of lang graph. Uh
10:16:16now let's try to understand this
10:16:17conditional workflows and this
10:16:19conditional workflows would be more
10:16:21interesting because if you have already
10:16:23uh let's say learned programming
10:16:25language you know that inside
10:16:26programming language we have something
10:16:28called a condition right so based on
10:16:30this a condition we uh handle any kinds
10:16:33of conditional based scenario so the
10:16:35same thing you can do inside langraph as
10:16:38well whenever you are having a workflow
10:16:40this is having some kinds of condition
10:16:42you can handle this kinds of scenario
10:16:43with the help of this conditional
10:16:45workflows. Okay. So, make sure you watch
10:16:48this video till the end. Don't miss
10:16:50anything. And if you found this content
10:16:52useful, guys, please try to subscribe to
10:16:54my channel and hit the like. Uh just uh
10:16:57hit the like guys because like is
10:16:58required if you like the session. So, uh
10:17:01it will be uh it will be reaching to all
10:17:03the people out there so that they can
10:17:05also find this kinds of content and
10:17:08please try to share this video with your
10:17:09friends and family. So, first of all,
10:17:11let me give you the idea about
10:17:12conditional workflows. Then I will also
10:17:14show you how we can code with the help
10:17:16of lang graph. How we can implement this
10:17:18conditional workflow with the help of
10:17:19lang graph. So here also I'm going to uh
10:17:22take two kinds of example. I'm going to
10:17:24take the first example nonlm based
10:17:27conditional workflows. First of all I'm
10:17:28going to show you the nonlm based
10:17:30workflows. Then after that I'm also
10:17:32going to show you the lm based
10:17:33workflows. Okay. Both we're going to
10:17:35cover here. So if you see here um this
10:17:38is the conditional workflows guys. So
10:17:40this is uh similar to the uh parallel
10:17:43workflows. I think you already studied
10:17:45about parallel workflows. Okay. So let
10:17:47me show you. So previously I already
10:17:48discussed about this parallel workflows,
10:17:50right? So in uh parallel workflows what
10:17:52happens if you give a task. So basically
10:17:56here we are having multiple nodes and
10:17:58all of the nodes would be executed
10:18:00independently. That means it will
10:18:02execute uh it will be executed in
10:18:04parallel. Okay. Altogether it will be
10:18:06executing. Then whatever result I was
10:18:08getting, I was just aggregating and u
10:18:12showing the results. Okay. But inside
10:18:14this conditional workflow, this is uh um
10:18:17little bit different. Let me show you.
10:18:19So inside conditional workflow, what
10:18:21will happen? See here also we are having
10:18:23multiple nodes. Okay. Uh in parallel but
10:18:26these are actually condition. Okay.
10:18:28These are actually condition. That means
10:18:30let's say uh let's say whatever content
10:18:33we are sending. So first of all it will
10:18:35analyze that after doing the analyze it
10:18:38will perform a conditional statement
10:18:41that means if this content is good let's
10:18:44say it will approve that particular post
10:18:47if it is let's say uh if is let's say
10:18:51needs any human review that time it will
10:18:55send it to the human review okay and it
10:18:58if it is having any kinds of problem
10:19:00that time it will directly reject the
10:19:01post that means here you are checking
10:19:03the condition based on the condition you
10:19:05are executing one of the node. Okay, you
10:19:07are not executing all of the node. You
10:19:10are only executing one of the node.
10:19:12Okay, let's say
10:19:15this node can be executed based on the
10:19:17condition or this note can be executed
10:19:19based on the condition or this node can
10:19:21be executed based based on the
10:19:23condition. Okay, based on that you are
10:19:25ending the entire graph. But here it's
10:19:27not like that. Here you are executing
10:19:28all the node togethers. Okay, in
10:19:30parallel you are executing then you are
10:19:32aggregating the results and you are
10:19:33showing that. But here it's not like
10:19:35that. This is working as a a fields
10:19:37condition. Okay, so let me show you. See
10:19:40here basically we'll just write a
10:19:42condition. Okay, let's say here the
10:19:44problem statement. First of all I'm
10:19:45going to show you u this is actually
10:19:48content moderation system. This is the
10:19:50nonlm based workflow. First of all I'm
10:19:52going to create then after that I'm also
10:19:54going to show you how to create the LMB
10:19:56based workflow. So here basically we'll
10:19:57be creating a content moderation system
10:19:59for a social media platform. It
10:20:02processes a user text post and evaluate
10:20:05it for spam and conditionally allowed it
10:20:08to be published. Okay, published either
10:20:12flagged for the human review. If it is
10:20:15uh need any kinds of human review it
10:20:16will try to send to the human review or
10:20:18it will automatically reject that
10:20:20particular post. That means here we'll
10:20:22be uh basically deciding this kinds of
10:20:25statement based on the condition. Okay,
10:20:28condition we'll first of all check the
10:20:29content. Whatever content user will
10:20:32post, whatever text user will post,
10:20:33we'll try to check that. Okay, before
10:20:35checking that we'll try to first of all
10:20:36format the post. Format the post means I
10:20:38will show a message. Okay, I will show a
10:20:41message like let's say this is the user
10:20:43he has posted this uh this this
10:20:45particular content. After that we'll
10:20:47analyze that, right? Analyze that. So
10:20:49this analyze function will try to
10:20:52analyze whether this is uh this is uh
10:20:55this particular post I can directly post
10:20:56or not if it doesn't have any kinds of
10:20:58violation or not or either if user is
10:21:02completely new to my platform okay first
10:21:04of all I have to send this post for the
10:21:07review okay either if it is having any
10:21:10kinds of uh violation related post I'll
10:21:12just try to reject that particular post
10:21:14okay so this is the condition so
10:21:16basically here you are sending uh you
10:21:18are handling this kinds condition. If
10:21:20else condition,
10:21:24if else condition, okay, if else
10:21:27condition, if this uh post is fine, you
10:21:30are approving that. Okay, if it is uh uh
10:21:34like uh uh if it uh
10:21:39or if user is completely new user, okay,
10:21:43new user, you are sending for the human
10:21:45review or else you are rejecting the
10:21:47post. that means there is there is a
10:21:49violation problem. Okay. So this is a
10:21:52conditional based workflow. Now I think
10:21:54you got it. What is the difference
10:21:55between this conditional workflows and
10:21:58the parallel workflows. Okay. And to
10:22:00implement this workflows guys I need a
10:22:02state. So I already prepared the state.
10:22:03As you can see I named it as moderation
10:22:06state and I inherited with the type dict
10:22:08and here I have taken some of the
10:22:10variable. So the first one I have taken
10:22:12for the post content that means whatever
10:22:14text user will pass I'll try to save it
10:22:17here. post content and this should be a
10:22:18string type data. Then uh user
10:22:21reputation. This is also userable pass.
10:22:24User reputation means either user is a
10:22:26uh registered user or he's the new user.
10:22:29Okay. Let's say if user reputation is
10:22:31equal to is equal to let's say um let's
10:22:34say the user is uh the user is let's say
10:22:38trusted user. Okay. Trusted user means
10:22:40this is uh this user is already
10:22:42registered user. Okay. So that time I'll
10:22:45uh not send this post for the review.
10:22:47Okay, this post uh won't be going for
10:22:50the review because the review I I will
10:22:52only learn uh I mean I will only execute
10:22:54whenever the user is completely new to
10:22:56my platform. Okay, so this this uh
10:22:59statement will uh store here and this is
10:23:01going to be also string type data. Then
10:23:03formatted post. So whatever content user
10:23:06will give give us first of all we'll try
10:23:08to format that particular post. Format
10:23:10means I will give a message. Let's say
10:23:13um let's say user says this is the post.
10:23:17Okay, that that kind of like uh I'm
10:23:19going to just give a message then
10:23:22content flag. Content flag means u here
10:23:25is the content flag. Basically all of
10:23:26the condition whether this should be
10:23:28approved or whether this should be
10:23:31rejected or whether this should be uh
10:23:34flagged for the human review. Okay. So
10:23:36these kinds of condition I'll try to
10:23:39save inside content flag and this is
10:23:40also going to be a string because here
10:23:42I'm going to store uh either approved
10:23:44either review either reject post okay
10:23:46that's why it's going to uh it's going
10:23:48to be string then result the final
10:23:50result okay final result means whether
10:23:52the post has been approved uh that mean
10:23:55uh it will give a message right let's
10:23:56say post automatically approved or post
10:23:59flagged for the human review or post or
10:24:01already rejected okay these kinds of
10:24:03methods I want to show at the last
10:24:04that's why I have taken another variable
10:24:06called result and this is also going to
10:24:07be a string. Okay, I hope you got it
10:24:09guys. Now let's try to code inside lang
10:24:12graph how we can uh create this graph
10:24:14how we can create this workflow. So I
10:24:16think you already get it. First of all I
10:24:18have to create some of the nodes. Okay,
10:24:20this node, this node, this node, this
10:24:22node, this node. Okay, then I'll try to
10:24:23do the edge connection and I will show
10:24:25you how we can uh handle this kinds of
10:24:27conditional workflow as well with the
10:24:29help of this
10:24:31um this langraph. Okay, this can be also
10:24:34um discussed in this particular video.
10:24:36Now, let me create a file first of all
10:24:38here. So, I'm going to create a file.
10:24:45I'm going to create a new file. I'm
10:24:47going to name it as
10:24:49six content moderation workflow. PY NB.
10:24:54Okay, this is a notebook file. So, I'll
10:24:57take a code cell and here also I'll take
10:24:58the kernel H.
10:25:01So the first thing guys I have to import
10:25:03the necessary library and I I think you
10:25:05know that uh what are the library we
10:25:08need right so let's import so I need
10:25:12this uh uh state graph start end from
10:25:14lang graph graph and type date let's
10:25:17import them then after that we have to
10:25:20create this state right so the same
10:25:22state I'm going to create here
10:25:26so this is the state
10:25:28I have taken the post contain user
10:25:30reputation
10:25:31Then uh formatted post content flag and
10:25:33result.
10:25:37So first of all now I'm going to uh
10:25:41create the graph. Okay. Then after
10:25:42creating the graph we'll try to add all
10:25:44of the nodes. Now let's create the
10:25:45graph.
10:25:49So graph is equal to state graph. Then I
10:25:50have given my state moderation state.
10:25:53Then after that we'll just try to add
10:25:55the nodes.
10:25:57add the nodes.
10:26:01Okay, first of all, I'm going to add my
10:26:04first nodes which is uh this one format
10:26:07post. Let's add that
10:26:12format post and this function I have to
10:26:14write. Okay, this format post Python
10:26:16function I have to write separately.
10:26:18Then the next uh nodes I have to write
10:26:22this uh analyze content.
10:26:25Analyze content. Okay. I have give given
10:26:28the same name. Then the next node I have
10:26:32to create approve post.
10:26:37Then next node I have to create flag for
10:26:40review.
10:26:44Then next po uh node I have to create
10:26:46this reject post.
10:26:50Okay. Now let me check whether I have
10:26:52any node or not. No, it's completely
10:26:54fine. I have created all the nodes. Now
10:26:56we have to create all of these node one
10:26:58by one. So first of all let's create the
10:27:00format post.
10:27:03Uh see inside formatted post I'm not
10:27:07going to do anything. This is the nonLM
10:27:09based workflow. So I'm going to just
10:27:11write a simple Python code here. So
10:27:13basically whatever um let's say user is
10:27:15passing input user is passing. Let's say
10:27:17user is passing post content and user
10:27:19reputation. So I just created a
10:27:21formatted string here. So here I told
10:27:24user uh reputation. Okay that means
10:27:26let's say user is trusted user. So here
10:27:28trusted user will come. That means user
10:27:30trusted user says post content. That
10:27:33means whatever post he's giving this
10:27:35particular post it will show here. Let's
10:27:36say user has given uh one post uh check
10:27:39out this amazing new product and buy
10:27:41now. Okay. So this will show here inside
10:27:43a uh this f string. Okay. Then after
10:27:46that we are just returning this
10:27:48particular formatted post. Okay.
10:27:50Formatted because we created this
10:27:52formatted post and whatever formatted
10:27:53output we are generating right we'll
10:27:55just try to store in the formatted post
10:27:57string. Okay we are storing uh storing
10:27:59here and we're returning it. And why we
10:28:01are not returning the enter state guys?
10:28:04Because in my previous uh previous video
10:28:07I already told you about right I
10:28:09whenever I created the parallel workflow
10:28:10that time I told you uh if you are
10:28:13having this kinds of scenario um that
10:28:16time don't use the entire state uh
10:28:19returning concept instead of that uh
10:28:21whatever state you are changing only
10:28:22just try to return those state okay this
10:28:24is a good practice okay instead of
10:28:26returning the whole one because here you
10:28:29are not changing inside that okay after
10:28:31the execution node execution you are not
10:28:33changing inside this particular variable
10:28:36you are only changing inside that right
10:28:37that's why don't return the entire state
10:28:39instead of whatever state you are uh
10:28:42changing only just try to return that
10:28:44okay I hope you got it so this is our
10:28:45first node we have created now let's
10:28:47create the next one called uh this
10:28:51analyze content okay now analyze content
10:28:53would be very simple uh see here I just
10:28:57written a simple condition so see here
10:29:01I'm giving my state And whatever post
10:29:04content we are having first of all we're
10:29:06doing the lower operation. Okay
10:29:10lower operation then after that we are
10:29:14checking the condition. So as you can
10:29:16see if spam in the content or buy now in
10:29:19the content. See here we are only
10:29:20considering uh this particular post
10:29:23would be rejected based on some like
10:29:25parameter whether it should be a spam
10:29:27whether it should be buy now. If user is
10:29:29giving this kinds of word in the text
10:29:31itself, I'm going to directly reject
10:29:33that particular content. Okay? Because
10:29:35this is a condition I mean non-LM based
10:29:37one. So that's why I I just taken uh
10:29:40like manual verification. But whenever
10:29:41it would be LM based that time it would
10:29:43be more robust. Okay. But just for your
10:29:45understanding I kept this particular
10:29:46easy example. So that's why I only
10:29:49considered two word. One is spam one is
10:29:51buy now. Okay. If it is present in the
10:29:53content I'm going to directly reject
10:29:55that particular content. So flag would
10:29:56be rejected. If the state reputation if
10:30:00is equal to is equal to new user that
10:30:02means I told you if user reputation is
10:30:04equal to is equal to new user that means
10:30:06he is the completely new user on my
10:30:08platform first of all I'll review this
10:30:10particular post okay I'll send it for
10:30:12the review or else I'm going to approve
10:30:15the post let's say if it it doesn't have
10:30:17any kinds of spam content or it doesn't
10:30:20need any kinds of review that means this
10:30:21content is fine I'm going to approve
10:30:23that okay that's why in the s block the
10:30:25flag is equal to approved then whatever
10:30:28uh flag we are getting based on the
10:30:29condition we are just storing inside
10:30:31content flag okay here we are storing
10:30:33that and we are returning this
10:30:34particular state okay I hope you got it
10:30:37now the next one I have to create for
10:30:39this approved post
10:30:43okay approved post so this will
10:30:44basically return this approved message
10:30:47uh result is equal to post published
10:30:49successfully to the timeline and result
10:30:51is equal to result so we are storing
10:30:53inside result okay now we'll do it for
10:30:55the same uh for the flag review and
10:30:58reject post as well. Now here also I'm
10:31:02going to just return the message for
10:31:03flag for review post sent uh to the
10:31:07human moderation uh queue okay for the
10:31:09review and we are updating the result
10:31:12okay and here you can see uh we don't
10:31:14need to store all of the like uh result
10:31:18here because this is not required
10:31:20because this is a conditional workflow.
10:31:22So either one of the node would be
10:31:24executed it it should not be executed
10:31:26all of the node right like that okay so
10:31:29previously it was executing all of the
10:31:30node and I was uh I was collecting all
10:31:33of the ratings okay and I was storing
10:31:35inside a list that's why I I uh I used
10:31:38actually reducer concept here but here
10:31:40reducer concept is not required because
10:31:42here either one of the node would be
10:31:44executed and I only need to save one
10:31:46particular result okay that's why this
10:31:48is completely uh string type okay I
10:31:51haven't taken any kinds of reducer type
10:31:54here. Okay, every time it will uh
10:31:57replace that.
10:31:59Then the next one I have for the reject
10:32:01post.
10:32:03Reject post. So as you can see uh post
10:32:06automatically deleted due to the policy
10:32:07violation and we are updating the
10:32:09result. That's it. So let's execute this
10:32:11one. Execute this one.
10:32:19And I'll execute this one also. Execute
10:32:22this one. Okay. Once it is done, now uh
10:32:26I have to
10:32:28I have to um do the age connection.
10:32:31Okay. So first of all, let's do the age
10:32:33connection. Then I will show you how we
10:32:35can uh handle the conditional scenario.
10:32:37So here let's try to do the age
10:32:39connection.
10:32:41Add
10:32:42the edges. So first of all you can see
10:32:45the age connection would be start to
10:32:47formatted post. Okay, let's try to do
10:32:49that.
10:32:51Start to formatted post.
10:32:55Okay, then the next one, formatted post
10:32:57to analyze content.
10:33:03Formatted post to analyze content. Okay.
10:33:05Then after that uh what we have
10:33:11uh we have um we have uh this
10:33:14connection. Okay. But this connection
10:33:16will build up um based on the condition
10:33:19either uh analyze content will return uh
10:33:24this particular output to the approved
10:33:26post or flag review post or rejected
10:33:27post. Okay. Now this conditional
10:33:30statement will come come into picture.
10:33:32Okay. Now this conditional statement
10:33:33will come into picture. So let's say if
10:33:35I'm not adding the condition if I'm
10:33:37directly just let's say this these nodes
10:33:39are not there. I'm directly just adding
10:33:41this um analyze content to the end.
10:33:45Analyze content to the end.
10:33:52Analyze content
10:33:55to the
10:33:58and okay. Now if I compile the graph and
10:34:02if I show you the workflow
10:34:09again not
10:34:19okay uh there should not be any
10:34:21quotation that's why it's coming the
10:34:23error now if execute this workflow is
10:34:25created now if I show you the workflow
10:34:27now see the workflow look Next lab.
10:34:31So this is the workflow right now.
10:34:34Okay. But I created the nodes already,
10:34:36right? So if I let's say um comment is
10:34:39at the node. Now if I execute,
10:34:42see
10:34:45this will look like that. So start
10:34:47formatted post then analyze content and
10:34:50end. Okay. Uh let's say these are the
10:34:53nodes are not there. Okay. But now I
10:34:55have to create this node because uh I
10:34:57have to handle the condition statement.
10:34:58Now let's uh uncomment that.
10:35:01Now here I'll just try to add the
10:35:03condition. Now I'll remove this one.
10:35:04Okay. Now here only you have to add the
10:35:06condition. Now see if you want to add a
10:35:10condition. Okay. If you want to add a
10:35:12condition, so you have to use this
10:35:14function
10:35:18add conditional age. Okay. There is a
10:35:21function inside graph called add
10:35:22conditional edge. inside that you have
10:35:25to you have to give a
10:35:28uh you have to give a function object
10:35:31okay condition function object okay
10:35:33condition function object and you have
10:35:35to provide from where to it will go to
10:35:37the conditional function let's say you
10:35:40can see condition will start after this
10:35:42analyze content okay so here I'll just
10:35:44write
10:35:46analyze content okay analyze content
10:35:52Yeah.
10:35:54Now from analyze content it will either
10:35:56go to the
10:35:58it will either go to the approved post
10:36:00flag for review or rejected post. Okay.
10:36:02Now I have to write this conditional
10:36:04function. Now separately I have to
10:36:06create another function.
10:36:09Let me show you the function. So this is
10:36:11the function guys. Okay. This is the
10:36:14function. Now we have to import this
10:36:16literal. Okay. Literal from this typing.
10:36:21Okay. Now see whenever you are writing
10:36:24any kinds of condition this code would
10:36:25be common. See I have named this
10:36:27function as check condition and it will
10:36:29also take this state okay and it will
10:36:32return
10:36:33uh it will return the nodes. Okay you
10:36:37can see we are giving the nodes name
10:36:39analyze content approved. Okay sorry
10:36:43approved post flag for review and reject
10:36:46post. That means these are the node
10:36:47approve post flag for review reject
10:36:49post. Okay, because these are my node
10:36:51name, right? So this function basically
10:36:53what happens? See this function takes
10:36:55this state and it returns either one of
10:36:57this particular node. Okay, based on the
10:36:59condition. Now let's try to see the
10:37:01condition.
10:37:02See if my state flag I already
10:37:05calculated the state flag guys here
10:37:06right if it is if it is uh let's say
10:37:09approved that means my approved post
10:37:13approved post node would be written that
10:37:15means this node would be written that
10:37:17means that time only this node would be
10:37:19executed not these are the nodes okay
10:37:21then
10:37:24if uh my content flag is equal to review
10:37:26that means only flag for review will be
10:37:28executed that means if my flag post is
10:37:32equal L2 is equal to uh let's say
10:37:35uh review that means this this
10:37:37particular node would be executed not
10:37:38these two nodes then if uh either none
10:37:43of them then rejected post post would be
10:37:45written that means if it is not approved
10:37:48post and flag for review then reject
10:37:50node would be executed okay neect node
10:37:52would be returned so this is the logic
10:37:53we have written here that's why we are
10:37:55using this literal literal means you can
10:37:58return the node object here okay you can
10:38:00return the node object Okay, that's why
10:38:02we have to give this particular syntax
10:38:04and this syntax uh basically uh
10:38:06recommended by langraph. If you check
10:38:08the langraph documentation, you will see
10:38:10that they have also uh given the same
10:38:12thing. Okay, so this is the condition
10:38:14function you have to write whenever you
10:38:16want to use this kinds of conditional
10:38:18edges. Okay, if you want to handle this
10:38:20kinds of conditional scenario that time
10:38:22you have to write this kinds of
10:38:23function. Now this function object you
10:38:25have to just provide here. Okay, after
10:38:27this analyze content, you have to
10:38:29provide this kind uh this this function
10:38:31object check condition. That's it. Okay,
10:38:34now what will happen after analyze
10:38:36content? This particular uh connection
10:38:39would be either with this particular
10:38:42node or with this particular node or
10:38:44with this particular node. Okay, but you
10:38:45don't know which one because it will
10:38:47check the condition based on the
10:38:49condition which condition will match it
10:38:51will go to that particular node. Okay,
10:38:53that's why we have written the
10:38:54condition. Okay, I hope you got it. Now
10:38:57this connection is also done. This
10:38:59connection is also done. Now it will uh
10:39:01do the connection either one of them.
10:39:03Okay, now you have to make this kinds of
10:39:05connection. That means approve post will
10:39:07be connected to the end. Flag for review
10:39:09will connect to the end and reject post
10:39:11will also connect to the end. Okay, now
10:39:13let's do uh do this connection. So here
10:39:16I will
10:39:19just do the connection. So this is the
10:39:20connection. You can see approved post is
10:39:23connected to the end. Then flag for
10:39:26review which is also connected to the
10:39:27end.
10:39:29Okay. Then uh reject post will be also
10:39:31connected to the end. Then we are
10:39:33compiling the graph. Now if I execute
10:39:36the graph uh okay check condition is not
10:39:39defined because I have to execute this
10:39:40function.
10:39:42Uh lit is not defined. Okay sorry I have
10:39:45to also import it first of all. Then I
10:39:49will execute.
10:39:51Then I will compile the graph. After
10:39:54that now let me show you the workflow.
10:39:56Now see guys this workflow and this
10:39:58workflow is same. Okay I hope you got it
10:40:01guys how we are handling this kinds of
10:40:04conditional scenario. Okay, I know I
10:40:07hope you already got it right. Only the
10:40:10change is that
10:40:12you have to use this kind use this
10:40:15function add conditional edges and this
10:40:17add conditional ages takes the uh
10:40:19previous connection. Okay, previous
10:40:21connection and it takes the condition uh
10:40:24condition function because condition
10:40:26function will decide uh after that which
10:40:29node should be connected. Okay, either
10:40:31approved post, either flag post, either
10:40:33rejected post. Okay, but it should not
10:40:35be executed all together. It would be
10:40:37only executed either one of them based
10:40:39on the condition. This is what we have
10:40:41done guys. Now let me check this
10:40:43workflow. So I'll invoke this workflow.
10:40:46First of all, let's define initial
10:40:48state.
10:40:49So this is our initial state. So first
10:40:52of all, I've given the post content.
10:40:53Check out this amazing new product and
10:40:56buy now. And then I've given the user
10:40:57reputation. Let's say this is the
10:40:59trusted user already registered user.
10:41:01Then we're invoking the workflow and
10:41:03this workflow will give me a result
10:41:08result. Okay. Now if I print this result
10:41:12now see guys this is the post user has
10:41:15given user reputation is trusted user
10:41:17and we are formatting that particular
10:41:20uh post. So you can see user trusted
10:41:22user says check this amazing product buy
10:41:25now. Content flag is rejected. Okay. Why
10:41:28it is rejected? because it is having buy
10:41:30now and we already did the condition
10:41:32check here
10:41:35uh buy now by now here. So if uh buy now
10:41:39is present in the content it would be
10:41:40rejected. Okay. So that's why
10:41:44uh you can see content flag is rejected
10:41:47and result is also post automatically
10:41:49deleted due to the policy violation.
10:41:51Okay. Now let's say here I'm not giving
10:41:53this by now. By now I will remove it.
10:41:56Now if I execute the workflow again. Now
10:41:58see uh right now it is approved because
10:42:00it doesn't have any kinds of violation.
10:42:02Uh again user is trusted user so it
10:42:04doesn't need any kinds of approval.
10:42:06Okay. Uh it doesn't need any kinds of
10:42:08review that's why directly approved and
10:42:10post published successfully. Okay. Now
10:42:12let's say user is new user.
10:42:18New user. Okay. Now see although this uh
10:42:22um I mean content is fine but still it
10:42:25will uh okay I have to execute
10:42:30then result huh so although see although
10:42:32this uh content is fine but still it is
10:42:35waiting for the review because I have to
10:42:37first of all check the user because this
10:42:39is uh he is not registered in my
10:42:41platform that's why it is uh going for
10:42:44the review and you can see post sent to
10:42:46the human moderation P okay I hope you
10:42:48got it That's how this conditional
10:42:50workflow is working. Okay, that's how
10:42:53this conditional uh conditional workflow
10:42:55is working. So whatever message you are
10:42:57giving based on that it is first of all
10:42:58checking the condition. Okay, after
10:43:00checking the condition it is executing
10:43:02either one of this particular node.
10:43:04Okay, not all the nodes altogether. I
10:43:06hope you got it guys. So this is what
10:43:08our nonLM based workflow. Now let's try
10:43:11to discuss the LM based workflow as
10:43:13well. So guys, so far we have seen the
10:43:15nonLM based workflow, conditional
10:43:18workflows and I showed you how it works,
10:43:20right? How we can handle the conditional
10:43:22scenario. Now let's try to learn the LLM
10:43:25based conditional workflows. Okay, now
10:43:27we'll be uh using large language model.
10:43:29But previously I didn't use any kinds of
10:43:31large language model here. Okay,
10:43:32everything I handled manually. So see if
10:43:35I u um first of all explain the problem
10:43:39statement we're going to uh create here.
10:43:41So this is going to be a um review reply
10:43:45system. Review reply system means let's
10:43:47say here uh user will give a review.
10:43:50Okay, user will give a review and what
10:43:53we have to do we have to uh give a reply
10:43:56to that particular review. Now review
10:43:58can be anything whether it should be a
10:44:01positive review, it should be a negative
10:44:02review. Let's say uh we are working we
10:44:06are working in a uh [clears throat] tech
10:44:07company right we are uh selling a
10:44:09product let's say we have created a
10:44:11software right so in that software uh uh
10:44:15let's say I I have uh made a
10:44:18subscription plan and some of the user
10:44:19have taken their subscription okay now
10:44:22definitely they will be using your
10:44:23product and uh based on the product
10:44:25actually they will uh give some kinds of
10:44:28uh like um I mean review right on on
10:44:30your product and uh as a let's say
10:44:34company owner what you have to do
10:44:36definitely you have to take take care
10:44:38about the um uh user review okay
10:44:40whatever user is giving the review uh
10:44:43you have to take care if they are giving
10:44:44the positive review that means it's
10:44:46completely fine your product is amazing
10:44:48okay you don't need to change inside
10:44:49your product but if they're getting some
10:44:53if they're giving some negative review
10:44:55that means if they're having some of the
10:44:56issue definitely you have to handle
10:44:57their issue right so you just think in
10:44:59that way so basically user will give a
10:45:01review. First of all, what we'll do is
10:45:03just try to check the sentiment of that
10:45:05review whether uh this is a positive
10:45:08review or whether this is a negative
10:45:10review. And whenever I want to do this
10:45:12uh sentiment uh check, right? So
10:45:14definitely I have to use a large
10:45:15language model here. So here I'm I'll be
10:45:18using a large language model. And this
10:45:20large language model either will return
10:45:22the positive,
10:45:24either it will uh return the negative.
10:45:26That means this is also a structured
10:45:28output. And if I want to get the
10:45:29structured output guys, what I have to
10:45:31do? I have to use the pientic. I already
10:45:33uh showed you in my previous lecture as
10:45:35well whenever I created that parallel
10:45:37workflow that time I also told you with
10:45:39the help of pientic uh you can uh get
10:45:42the structured output. Okay, you have to
10:45:43just create a schema and you have to
10:45:45provide the schema to the model and
10:45:46model will work in uh uh in that way and
10:45:49for this you have to learn the pyic and
10:45:51pyic video I already have in my
10:45:52playlist. Please try to check that.
10:45:54Okay. So this particular node will
10:45:57return either positive or negative based
10:45:59on the review I will be using a large
10:46:01lang based model. Large lang based model
10:46:02will uh uh like uh analyze that uh
10:46:05analyze the sentiment and based on that
10:46:08it will give me positive either
10:46:09negative. Okay. If it is positive so see
10:46:11here your condition statement is
10:46:13working. If let's say this particular
10:46:16sentiment is positive that means I'll
10:46:17generate a positive response. Okay
10:46:19positive reply to the customer. Okay.
10:46:22But if it is negative, if this review is
10:46:25negative, sentiment is negative. So
10:46:27again, I'm running another node called
10:46:29run diagnosis. Okay. So what this run
10:46:32diagnosis will do? Basically I want to
10:46:35uh analyze this particular review uh in
10:46:39little more depth because I want to
10:46:42understand what is the uh what is the
10:46:44issue they are having. Okay. What is
10:46:46their main concern? I have to analyze
10:46:48that. That's why I will be running
10:46:49another nodes called run diagnosis. So
10:46:52this run diagnosis will return three
10:46:53things. One is the issue type. First of
10:46:55all, it will return the issue type. What
10:46:56is the issue related? Whether the issue
10:46:58is coming from UI uh UX okay or whether
10:47:02it is coming from performance or whether
10:47:05it is kinds of bugs or whether they need
10:47:07any kinds of support or any other
10:47:08things. Okay. I have to understand the
10:47:10issue type. Then I have to understand
10:47:11the tone whether they're angry,
10:47:13frustrated, disappointed or calm. Okay.
10:47:15I have to understand the user. Then I
10:47:17have to understand their urgency.
10:47:19whether this urgency is low, medium or
10:47:21high. Okay, based on that definitely I
10:47:23have to uh take the actions. Okay,
10:47:26otherwise I can't sell my product
10:47:28anymore. Right then once I got these are
10:47:30the let's say issue type based on that
10:47:33okay I will be generating a reply
10:47:36negative uh like reply to that
10:47:39particular user let's say I'll tell okay
10:47:41you are getting this kinds of UI related
10:47:43problem you you you are very angry okay
10:47:46and your urgency is high so definitely
10:47:48uh we'll our team will look into that
10:47:50immediately or if it is low uh so you
10:47:53just wait for 3 to two days I will look
10:47:55into that okay so this kinds of reply
10:47:57will try to generate Okay, I hope you
10:47:58got it this workflow. Uh now you can see
10:48:01here this is the workflow. This is a
10:48:03conditional workflow but we'll be
10:48:04solving with the help of llm. Okay, so
10:48:06we will be ling l we'll be using the lm
10:48:09uh two u uh two times here. So in this
10:48:12particular nodes and here also we'll be
10:48:13using the llm to run this diagnosis I
10:48:15need another llm. Okay, with help of llm
10:48:17we'll try to generate these are the
10:48:19structure and again this should be a
10:48:21structured output. Okay. So every time
10:48:23whenever I run this nodes run diagnosis
10:48:25node LM will return three things issue
10:48:27type, tone and urgency again I have to
10:48:29use pientic for that. Okay. Pentic for
10:48:32that we'll be creating a schema and
10:48:34we'll generate this structure output.
10:48:36Okay. So this is what we'll be
10:48:37implementing guys right now. And for
10:48:38this whatever state I need I already
10:48:40created the state as you can see I named
10:48:42it as review state inherited with type
10:48:44dict. So first of all whatever review
10:48:46user will give me I will store in the
10:48:47review and this should be a string and
10:48:49our this node will try to find the
10:48:51sentiment okay sentiment of the review.
10:48:54So either it would be a positive or
10:48:56negative. You can either create it as a
10:48:58string. Either you can create it as a
10:48:59literal type. In literal type you can
10:49:01mention uh because this is a category
10:49:02right? Either it would be a positive or
10:49:04negative. It kinds of category. So
10:49:06that's why we have taken this literal
10:49:07type. You can also take a string type.
10:49:09It will also work. Okay. I have taken
10:49:10literal type. So positive and negative.
10:49:12Okay. Sentiment should be positive or
10:49:13negative. And uh diagnosis. So diagnosis
10:49:16will return three things. That means uh
10:49:19tone type, tone and angry. Okay. So this
10:49:22this should this structure should be a
10:49:24dictionary type you can see this is the
10:49:25key this is the value this is the key
10:49:26this is the value right so that's why I
10:49:28have taken this should be a dictionary
10:49:29type and the response whatever response
10:49:32I'll try to generate whether I should
10:49:33I'll generate a positive response or
10:49:35negative response it will come here and
10:49:36this again this should be a string type
10:49:38okay I hope you got it now we can start
10:49:40coding inside lang graph guys okay so
10:49:43what I'll do guys I'll create another
10:49:44file here
10:49:46let's create another file
10:49:49I'm going to name it as Seven
10:49:53uh
10:49:56review workflow
10:50:01review
10:50:06workflow
10:50:07dot ip yv
10:50:11I'll take the code cell select the
10:50:14kernel
10:50:16fine so the first thing guys what I have
10:50:18to do I have to import all the necessary
10:50:20libraries so let's port and here we'll
10:50:21be using LLM. So again I'm going to use
10:50:23my uh open AI model. I already have the
10:50:26API key inside my env. So you just also
10:50:29need to generate API key. Okay. You can
10:50:31either use any other model as well. It's
10:50:33completely fine. Uh
10:50:36yeah. Then after that uh I need uh this
10:50:39uh typing
10:50:42type dict and literal from typing. Then
10:50:45I also need to load this env. For this I
10:50:47need this load env.
10:50:50And I also need to import the pi dantic.
10:50:52Okay, because I have to generate a
10:50:53structured output. So pi dantic I need
10:50:56best model and field. So please try to
10:50:58see in my uh playlist guys this tutorial
10:51:01is already there. So here is the
10:51:03playlist guys complete aentici course
10:51:05and here is the pentic video. Please try
10:51:08to go ahead with this pyic you'll try to
10:51:09understand. Okay and previously I also
10:51:13discussed about this uh uh sequential
10:51:15workflow and parallel workflow. Okay
10:51:17that this concept you have to also
10:51:19understand. Okay, if you're
10:51:20understanding this um uh conditional
10:51:23workflow because each of the workflow is
10:51:26uh something is like connected with each
10:51:29other that means if you can understand
10:51:32uh our workflow then you can relate with
10:51:35another workflow. Okay. So that's why
10:51:37this is required and the way I have
10:51:39structured this course course right step
10:51:41by step this is interconnected between
10:51:44so if you missed out the previous
10:51:45sessions so I think it would be a little
10:51:47bit confusing okay for the current
10:51:49session so that's why I'm telling you
10:51:51just try to go ahead with the previous
10:51:52session yeah
10:51:55so yeah so after that I'll first of all
10:51:57load the environment variable
10:52:03okay now let's initialize the model LLM
10:52:06model. So here I have taken GPT photo
10:52:08mini. Yeah. Now I told you I have to
10:52:12generate this uh I have to create this
10:52:14uh structure. So yeah. So I told you
10:52:18this fine sentiment nodes will give you
10:52:21two things either positive or negative.
10:52:23Okay. For this I'll create a a
10:52:25structured output and for run diagnosis
10:52:28node I'll create a structured output.
10:52:29That means it will generate three
10:52:30things. One is issue type, tone and
10:52:32urgency. Right? So for this let's try to
10:52:35write this pyic class.
10:52:38So this is the first class I have
10:52:40written for the sentiment.
10:52:43Okay. So basically this will uh return
10:52:46two uh uh two things positive or
10:52:48negative based on the
10:52:50review. Okay. So this is going to be my
10:52:53first uh actually structured output from
10:52:55my LLM. Okay. So maybe I can show you.
10:52:58So let's create a object
10:53:01of a model.
10:53:04Yeah. So let's say structured model uh
10:53:06is equal to model dot with structured
10:53:07output I have given the sentiment
10:53:09schema. Now see if I show you the
10:53:11output.
10:53:13Let's say I have generated uh structured
10:53:15model. Now if I give any kinds of
10:53:18uh if I give any kinds of let's say
10:53:20prompt here
10:53:23let's say this is the prompt. What is
10:53:24the sentiment of the following review?
10:53:26This software is too good. Okay. Now
10:53:28I'll give it to my model. Now see here
10:53:32I'm not using the direct model. I'm
10:53:34giving my structured model. Okay. Now
10:53:36I'm doing the invok operation and I'm
10:53:38only getting the sentiment.
10:53:40Now see
10:53:43see positive it will either return
10:53:45positive or negative. Now let's say here
10:53:47I've give two bat. Now this will return
10:53:51me negative. Okay. So this is the
10:53:53structured output and if you want to get
10:53:55this kinds of output you have to use the
10:53:56py okay schema for that. So the same
10:53:59thing I'll also write for my diagnosis
10:54:03uh node.
10:54:05So this is for my diagnosis node. Okay.
10:54:08So again I'm inheriting with the base
10:54:09model of the pentic and here I have
10:54:11written the issue type tone and urgency.
10:54:14So this uh node will return this three
10:54:16thing issue type. Now here I have given
10:54:18some of the hint like I need uh issue
10:54:20type should be UIX performance bug
10:54:22support and others. Here I have given
10:54:24the field description the category of
10:54:26the issue mentioned in the review. Then
10:54:28tone, angry, frustrated, disappointed,
10:54:30clam, the emotion, tone expressed by the
10:54:32user. Urgency, low, medium, high. How
10:54:36urgent to uh or critical the issue
10:54:39appears to be. Okay. So this thing I
10:54:41have discussed in my pentic uh uh class.
10:54:44Okay. So I already talked about what is
10:54:47this um literal, what is this field,
10:54:50what is the description, each and
10:54:52everything I have already discussed.
10:54:53Okay. So this is another structured
10:54:55output we have created. Okay. Now you
10:54:57can also test for this you can create
10:54:58another uh another model. So let's say I
10:55:03have named this model as structured
10:55:05model to model uh uh with structured
10:55:08output and we are giving the diagnosis
10:55:10schema here and this is going to be my
10:55:12another object. Okay. Okay. I'm getting
10:55:14an output. Okay. I have to execute this
10:55:16one. Now I'll execute. Now see this is
10:55:19working. Now you can also give a prompt
10:55:21and you can
10:55:23uh you can uh basically uh do the
10:55:26analysis. Let's say
10:55:29uh now I'll call this model.
10:55:32Okay. Uh structured model 2. Now I'm
10:55:34giving the same prompt. Now I want to
10:55:37see the
10:55:39uh output.
10:55:42Now see uh issue type is other tone is
10:55:45disappointed. U is medium. Okay. So this
10:55:47is returning three things. Okay, I hope
10:55:49you got it. Now, uh what I'm going to
10:55:52do, I'm going to simply um
10:55:56um create the
10:55:58um state. Okay, now I have to prepare
10:56:00the state. So, let's define the state,
10:56:02the same state.
10:56:04So, this is the state review state uh
10:56:06review, sentiment, uh diagnosis and uh
10:56:09response.
10:56:11It's done. Now, I'll define the nodes.
10:56:17Okay, I have given my state here. Now
10:56:20add the nodes.
10:56:25So now see the node connection. Uh see
10:56:27the nodes how many nodes you are having.
10:56:29Find sentiment then you have positive
10:56:32response. You have brand diagnosis. You
10:56:34have negative response. Okay these are
10:56:35the nodes. Let's add one by one.
10:56:40So these are the note find sentiment
10:56:42positive response run diagnosis and
10:56:44negative response. Okay. Okay. Now I
10:56:45have to create these other function one
10:56:47by one. Okay. So let's create
10:56:51uh
10:56:53first of all I'll create find sentiment.
10:56:57So this is the function. This is the
10:56:59note find sentiment. It will take the
10:57:01state and here I have given a prompt for
10:57:03the following review. Please uh find out
10:57:06the sentiment and here we are giving the
10:57:08review. Uh review is present inside our
10:57:10state. Okay. And here we are getting the
10:57:12sentiment from the model and we are
10:57:14calling the structured model that means
10:57:15the first model and first model I think
10:57:17returns the only the sentiment whether
10:57:18positive or negative. Okay, we're
10:57:20getting the sentiment and we're updating
10:57:21the sentiment and we're returning this
10:57:23particular sentiment only. Okay, instead
10:57:24of returning the whole state then
10:57:28uh I'm going to write the next nodes
10:57:31which is uh
10:57:33positive response.
10:57:38Positive response. Okay. So again it is
10:57:40taking the state and we are preparing
10:57:42the prompt. Write a warm thank you
10:57:44message in response uh uh to this
10:57:47review. So we are giving the review also
10:57:49kindly ask user to leave feedback on our
10:57:52website. Let's see that means if uh the
10:57:54review is completely positive other time
10:57:56I want to just give a thank you message
10:57:58to the user. Okay. And I will tell also
10:58:00just please leave a feedback to the
10:58:02website. Then once it is done we are
10:58:04giving to the model and see we are not
10:58:06using any structured model here. we are
10:58:08giving the main model because why here I
10:58:11don't need any kinds of structured
10:58:12output because it will only generate
10:58:14some kinds of thank you message okay and
10:58:16I don't need any kinds of structured
10:58:17output that's why I'm giving the
10:58:19original model and whatever content it
10:58:21is returning I'm just uh saving inside
10:58:23my response okay done now next thing I
10:58:28have to create my diagnosis
10:58:33run diagnosis
10:58:35so this is the run diagnosis again it is
10:58:37taking the state and here I preparing
10:58:38the prompt diagnosis this negative
10:58:40review we are giving the review uh
10:58:42return issue type tone and urgency so we
10:58:45are executing this structure to model
10:58:49okay and basically this will return this
10:58:51three things and whenever we are getting
10:58:53we are updating my uh diagnosis you can
10:58:57see we're updating the diagnosis because
10:58:58diagnosis type is dictionary and this is
10:59:00also a dictionary type output okay we
10:59:03are doing that
10:59:06now once it is I'll do it for my next
10:59:09one. Uh negative response.
10:59:13Negative response. So we are passing the
10:59:15state. Then uh we are taking the
10:59:19diagnosis. Okay. Then we are preparing
10:59:21the prompt. You are a supportive
10:59:22assistant. You uh the user had a issue
10:59:25type then tone then urgency. Based on
10:59:30that just write a empa uh empathetic
10:59:33helpful resolution message. and we are
10:59:36involving the actual model and whatever
10:59:39response we are getting we are updating
10:59:40the response. Okay. So that's how we are
10:59:42getting all of the node one by one. Now
10:59:44my node is ready. Now what I have to do
10:59:46guys I have to
10:59:48um make the age connection. Now let's do
10:59:51the edge connection.
10:59:55So add ages with condition H. So first
10:59:59[clears throat] of all the connection
11:00:00should be start to find sentiment.
11:00:04Start to find sentiment.
11:00:06Okay, start to find sentiment then you
11:00:09have to uh take the conditional is right
11:00:12now because either it will go to the
11:00:14positive response either it will go to
11:00:15the uh run diagnosis. Okay. So here
11:00:18we'll just write the condition right
11:00:20now. Uh
11:00:24yeah so this is the conditional edges.
11:00:27So see it will uh start from fun uh find
11:00:32sentiment and either it will connect to
11:00:34the positive either it will connect to
11:00:35the negative. So that's why we have
11:00:37taken the find sentiment. Now we have to
11:00:39write the check sentiment function. I
11:00:41think previous also we have created a
11:00:43conditional function right and this
11:00:44conditional function is return uh
11:00:46returning your notes based on the
11:00:48condition either it will return this
11:00:49note, this node or this node. Okay,
11:00:51we'll write the same thing here. So
11:00:52let's write this function. Uh very
11:00:55simple function that's I told you this
11:00:57code would be common everywhere whenever
11:00:59you are using conditional based
11:01:00workflow. So see this is the function I
11:01:02have written check statement uh
11:01:05sentiment it will take the state and it
11:01:07will return the uh nodes either positive
11:01:11response node. Okay either positive
11:01:13response node either run diagnosis node
11:01:16that means this run diagnosis node.
11:01:18Okay, based on the condition now where
11:01:20I'll check the condition in the
11:01:22sentiment. If the sentiment is positive,
11:01:24I'll return the positive node, positive
11:01:26response node. Okay, that means this
11:01:27node will be return or if it is
11:01:30negative, I'll return this run diagnosis
11:01:33node. That means this node would be
11:01:34written. Okay, I hope you got it guys.
11:01:37So that's why we have to give this
11:01:39particular function here. Now this
11:01:40function will decide which node should
11:01:42be called. Okay, so once it is done, now
11:01:45let's say this connection is done. Okay,
11:01:47now this connection is done. Now I have
11:01:48to make the other connection. Now what
11:01:50will happen?
11:01:52Uh this uh positive will connect to the
11:01:55end. Then run diagnosis will connect to
11:01:58the negative response and negative
11:01:59response will connect to the end. Okay.
11:02:01We'll try to make this connection right
11:02:02now.
11:02:05So this is the connection.
11:02:08Yeah. So you can see positive response
11:02:09is connected to the end. Then run
11:02:13diagnosis will connected to the negative
11:02:15response. Okay. If let's say diagnosis
11:02:17run successfully, we got the issue type,
11:02:19tone and urgency, we'll connect to the
11:02:21negative. We'll generate the negative
11:02:23response and negative response will
11:02:24connect it to the end. It is uh
11:02:26connected to the end. Okay, I hope you
11:02:28got the connection. Now let's uh define
11:02:30the workflow. Compile the workflow.
11:02:34Compile the workflow. Now let's execute.
11:02:36Done. Now if I show you the workflow.
11:02:41So this is the workflow guys. Now this
11:02:43workflow and this workflow is same. You
11:02:45can check uh find sentiment positive,
11:02:48run diagnosis negative and okay
11:02:50completely fine. Now let's uh invoke
11:02:53this workflow.
11:02:57So what I can do
11:02:59I can give a positive
11:03:03positive uh uh positive review first of
11:03:06all.
11:03:08So I will generate from chat JP. I'll
11:03:10just tell generate a
11:03:15Write a positive
11:03:21review for a
11:03:25tech software
11:03:31in short.
11:03:36Okay. Now I'll copy this and what I'm
11:03:39going to do I'm going to add inside my
11:03:43initial state.
11:03:51So let me define my initial state.
11:04:04So in the review itself I'll try to
11:04:06write my
11:04:17Now let's invoke the workflow
11:04:25and this will give me the result.
11:04:32Now I'll print the result.
11:04:36Now see this uh this is the review and
11:04:39the sentiment is positive and response
11:04:42is also positive. Their username thank
11:04:44you for your wonderful field uh uh here
11:04:48to that our software made such a
11:04:49positive. Okay, your kinds of word means
11:04:51a lot blah blah blah and also please uh
11:04:54give a review in inside our website.
11:04:57Okay, now let's give a negative response
11:05:00as well. Now I'll generate another one.
11:05:03Now uh negative review.
11:05:16Now what I can do? I can copy the same
11:05:18code
11:05:22only. I'll just change this preview.
11:05:35So I will invoke the result uh workflow
11:05:39and print the result.
11:05:57Okay, now we are getting the negative.
11:06:00You can see this uh sentiment is
11:06:01negative and diagnosis we got. Issue
11:06:04type is performance, tone is frustrated,
LangGraph Iterative Workflows Explained
11:06:06urgency is high and this is the uh
11:06:08negative response we're writing. We are
11:06:11here to help you with the performance
11:06:12issue. Hi user blah blah blah. Okay. So
11:06:15amazing that means it's working fine.
11:06:17Okay. And I think you got how we have
11:06:19created the entire workflow with the
11:06:21help of this conditional workflow.
11:06:24Get it? So now I think you can create
11:06:26any kinds of conditional workflow either
11:06:28it is non LLM based or LM based it
11:06:30doesn't matter you can create it only
11:06:32you just need to understand this
11:06:34conditional connection okay if you
11:06:35understand this conditional connection
11:06:38then you will be able to create any
11:06:39kinds of conditional workflow. So guys
11:06:42in this video I'll be discussing about
11:06:45the last workflows uh inside langraph
11:06:48which is iterative workflows. So far I
11:06:51have discussed about uh sequential
11:06:53workflows, parallel workflows,
11:06:55conditional workflows. Okay, each and
11:06:57everything I have already covered. If
11:06:59you haven't checked those videos, uh it
11:07:01is already available inside my playlist.
11:07:03Uh I have given the link in the
11:07:05description from there you can check it
11:07:07out. So uh this is going to be a very
11:07:10important and interesting workflows guys
11:07:12inside Langraph because with the help of
11:07:14iterative workflows you can perform the
11:07:17looping operation. So let's say whenever
11:07:19you are performing any task and uh if
11:07:21you feel like uh this uh task needs some
11:07:24more improvement you can continuously
11:07:27actually perform the looping operation
11:07:29with the help of this iterative
11:07:30workflows. So we'll try to understand
11:07:32this one. So if you found my uh content
11:07:36useful guys and if you are really
11:07:38learning okay from this particular
11:07:40playlist uh I would like to request you
11:07:42please try to subscribe to my channel
11:07:44and hit the like and please try to share
11:07:46this with your friends and family. So if
11:07:48you are supporting me guys if you are
11:07:50supporting my channel I'll be getting
11:07:52more motivation to bring this kinds of
11:07:54content. So if you uh see guys uh here
11:07:58is the iterative workflows we'll be
11:08:00discussing about. So previously I
11:08:03already discussed about all the
11:08:04workflows um I told you about uh inside
11:08:08langraph like sequential workflows you
11:08:11have understood the LLM non LLM based
11:08:13okay then I have discussed about the
11:08:16parallel workflows then I discussed
11:08:18about the conditional workflows okay now
11:08:20we'll try to understand this iterative
11:08:22workflows so you can see this is the uh
11:08:26iterative workflows graph I already
11:08:28created this particular graph so guys to
11:08:30make you understand this iterative
11:08:32workflows. I'm going to take one amazing
11:08:34example. I'm going to take Facebook post
11:08:37generation example. So what happens?
11:08:40Let's say I want to post uh anything on
11:08:43my Facebook. Let's say I want to post uh
11:08:45any kinds of tech related uh content on
11:08:48my Facebook. So nowadays actually what
11:08:51will happen? I'll be definitely using
11:08:53chat GPT or any other large language
11:08:56model let's say provider and I'll try to
11:08:59generate that content. Okay. And uh what
11:09:02I will do, I will uh um copy that and I
11:09:05will post on my Facebook. Okay. But it's
11:09:08not like that. At the very first time,
11:09:11you will be getting the perfect post,
11:09:12right? Let's say you have given a prompt
11:09:15uh and it has generated something for
11:09:17the first uh time, right? It's not like
11:09:19that that should be 100% uh perfect and
11:09:22optimized for for you for your needs. So
11:09:26maybe you just need to do some little
11:09:27bit let's say change or you need some
11:09:31improvement you need some optimization.
11:09:33So again what you will do you will you
11:09:35will send it to the LLM and you will try
11:09:37to tell okay try to optimize it more.
11:09:40Okay. So once you have let's say
11:09:42optimized another one again you will try
11:09:44to review that evaluate that if it is uh
11:09:46perfect for you then you will try to
11:09:48approve and you will post it over the
11:09:50Facebook. Okay. Otherwise you will uh
11:09:51again uh do the optimization. Okay. So
11:09:54that's how let's say we usually generate
11:09:57any kinds of content from the LLM right.
11:09:59So why not we can uh create a automatic
11:10:01workflow. So this workflow will
11:10:03automatically generate u let's say u
11:10:06Facebook content u based on the topic
11:10:09you have provided. Then after that it
11:10:11will automatically evaluate that whether
11:10:13this content is perfect or not. Okay.
11:10:15Let's say after doing the evaluation it
11:10:17found okay this is uh useful this is
11:10:19fine then it will approve. then you can
11:10:22post over the Facebook otherwise it will
11:10:24send it send it to the another let's say
11:10:26nodes and that nodes will try to do the
11:10:30optimization okay optimization it will
11:10:32optimize
11:10:34like um uh it will do some improvement
11:10:37then after that um again it will try to
11:10:40send it to the evaluator okay evaluate
11:10:42will again evaluate that if found let's
11:10:44say this content is fine then it will
11:10:46approve otherwise again it will try to
11:10:48send it to the optim optimizer then
11:10:50optimizer again it will optimize the
11:10:53content and it will again send it for
11:10:54the uh evaluation. Okay, so that's how
11:10:57this kind this particular loop will
11:10:59continuously run unless and until this
11:11:01content is approved. Okay, so this is
11:11:03called actually iterative workflows. So
11:11:05to make iterative workflows guys uh we
11:11:08are using um conditional workflows as
11:11:10well as you can see because here is the
11:11:12condition if uh this content is
11:11:15completely fine after doing the
11:11:16evaluation it will approve okay
11:11:18otherwise it will send it to the
11:11:20optimizer and optimizer will u like do
11:11:22the improvement and it will again send
11:11:24it to evaluator okay so here is the
11:11:27looping concept and this looping concept
11:11:29we call it as a iterative workflows
11:11:31inside lang graph. Now we'll try to
11:11:33implement this particular workflows.
11:11:34Okay, inside lang graph and for this
11:11:36whatever uh uh state I need guys I
11:11:39already prepared the state as you can
11:11:40see this is the state I named it as post
11:11:42state and I inherited with the type
11:11:44dict. So first of all I have taken a
11:11:46variable called topic. So user will pass
11:11:49a topic. Okay for post generation let's
11:11:52say I have given a topic related uh
11:11:54let's say agentic AI. So it will
11:11:55generate some kinds of post related
11:11:57agentic AI. Okay. So that uh let's say
11:12:00I'll send it to the generate llm. Right
11:12:02here we'll be using a llm. Then this uh
11:12:06uh this uh llm or let's say this node
11:12:08will generate the post. Okay. Let's say
11:12:10this post I'm going to save inside this
11:12:12post variable. And this is also going to
11:12:13be string type data. Then after that
11:12:16we'll try to send it to the evaluator.
11:12:17Evaluator will also use a llm right
11:12:19large language model. And it will
11:12:21evaluate that particular result. And it
11:12:23will send two things. One is the
11:12:25approved another is the needs
11:12:27improvement. Okay. If it is sending uh
11:12:29returning approved that that means this
11:12:32post is completely fine we can directly
11:12:34approve that and if it is sending needs
11:12:36improvement okay that time we'll try to
11:12:37send it to the optimizer okay and it
11:12:40will also give you some kinds of
11:12:41feedback okay let's say what should be
11:12:43the improvement it will also send it to
11:12:45the optimizer this feedback will try to
11:12:47save inside this particular uh variable
11:12:50then
11:12:51uh we'll also try to see the iteration
11:12:54iteration means let's say it has given
11:12:56this uh content to to the evaluator.
11:12:58Evaluator tells okay uh this needs the
11:13:01improvement again it will send it to the
11:13:03optimizer. Optimizer will try to again
11:13:05generate a new uh or let's say optimize
11:13:08that particular post and it will again
11:13:10send it to the evaluator. That means one
11:13:12iteration is done. Then again it
11:13:14evaluator will try to check that again
11:13:16let's say it will tell it needs the
11:13:18improvement again it will try to send it
11:13:19to the optimizer. optimizer again it
11:13:21will improve that again we'll center the
11:13:23evaluator that that means iteration goes
11:13:25to that means how many loop it is
11:13:27performing we'll try to log that
11:13:29particular informations in this
11:13:30iteration variable okay and here we'll
11:13:32also set a maximum iteration let's say
11:13:36uh if you don't set this maximum
11:13:37iteration what what is the possibility
11:13:39let's say if you're using any very poor
11:13:41large language model that time let's say
11:13:43every time whatever content it will
11:13:45generate maybe your evaluator will not
11:13:48evaluate that or let's say approve
11:13:50that time this particular loop will
11:13:52continuously running. Okay, we'll not
11:13:54get any final result. That's why we'll
11:13:56set a maximum iteration let's say four
11:13:58to five. So after four or five uh let's
11:14:00say iteration this particular loop will
11:14:03break and whatever content we got after
11:14:05four or five iteration that I will try
11:14:07to make it as final post. Okay, that's
11:14:09why this maximum iteration will also
11:14:10set. Then whatever let's say post we are
11:14:13generating whatever feedback we are
11:14:16getting okay from this evaluator will
11:14:18also try to save inside this particular
11:14:20variable as a history that's why we made
11:14:22it as post history and feedback history
11:14:25that means it will continuously add okay
11:14:27it will not replace it will continuously
11:14:29add so that that's why we'll be using
11:14:30reducer concept I think you know what is
11:14:32reducer inside lang graph you can see
11:14:34we're using annotated we are we have
11:14:36taken a list uh type data structure and
11:14:39we're using operation add That means
11:14:41every time it will add the post story
11:14:43and feedback story instead of replacing
11:14:46but here we are we haven't take any
11:14:47kinds of reducer it will continuously
11:14:49replace here okay I hope you got it then
11:14:52uh let's say once this uh uh improvement
11:14:55is done evaluator will uh let's say
11:14:57found this is useful or this is
11:14:59completely fine that time this would be
11:15:01approved and this loop would be break
11:15:03okay so this is what actually iterative
11:15:04workflows now we'll try to um we'll try
11:15:07to code inside lang graph then we'll try
11:15:09to understand uh the whole concept
11:15:10script. Okay. Now for this what I'm
11:15:12going to do guys, I'm going to simply
11:15:14open up this uh iterative workflows.ipb
11:15:17file and let's select our kernel. So
11:15:20first of all we have to import the
11:15:22necessary library. So let's import.
11:15:28So I'll import all of the necessary
11:15:30library. So you can see I'm importing
11:15:32the state graph start end. Then from
11:15:34typing I'm importing type dict literal
11:15:37and annotated. Then uh I'm using chat
11:15:40openi that means I'll be using openi
11:15:42large language model. You can use any
11:15:44kinds of large language model. For this
11:15:45I have oneb file and I set my open key
11:15:48here already. Then uh I'm importing the
11:15:51system message and human message. Okay.
11:15:53Where we are importing the system
11:15:54message and human message because I want
11:15:56to give the prompt for each and every
11:15:58LLM. See you can see here we'll be using
11:16:00the LLM. Here also we'll be using the
11:16:02LLM. For optimization also we'll be
11:16:04using the LLM. Okay. And every LLM I'll
11:16:06try to set a different different prompt.
11:16:08Let's say for generation one I will set
11:16:10uh generation related prompt. For
11:16:12evaluator I'll set evaluation related
11:16:14prompt. For optimization I'll set
11:16:16optimization related prompt. Okay. So
11:16:18you can directly give the prompt as well
11:16:20but it is recommended to use this system
11:16:22message and human message function
11:16:24whenever you are giving the prompt.
11:16:25Okay. This should be more optimized one.
11:16:27Then operator I need because I want to
11:16:29perform the reducer. I have to do the
11:16:30adding operation. Then env. So let's
11:16:33import all of them.
11:16:39So as you can see execution is complete.
11:16:41Now we'll load our environment variable.
11:16:46Now uh we'll define all the large
11:16:49language model. So here you can see
11:16:54um yeah so I need uh three large
11:16:57language model. One is for generation,
11:16:59one is for evaluator, one is for
11:17:01optimization. Okay. So what I'm going to
11:17:03do I'm going to make three object
11:17:06for three large language model. Uh see
11:17:09I'm going to use the same model only but
11:17:11I'm going to create uh three object.
11:17:13Okay because here I told you we'll be
11:17:15using three no three nodes okay
11:17:17differently. So whenever you are
11:17:18creating this kinds of project uh let's
11:17:20say uh in real time actual real project
11:17:23that time you have to select this large
11:17:25language model in such a way. So let's
11:17:27say whatever model is very good for
11:17:30generation that time you can use that
11:17:32particular model. Let's say some model
11:17:34is very much good for evaluation that
11:17:36time you can take that particular model.
11:17:38Let's say some model is very much good
11:17:40for optimization you can take that
11:17:42particular model. Okay. So that's how we
11:17:43have to select in real time. But right
11:17:45now we are only understanding the
11:17:47example that's why I have taken the same
11:17:49model but I created three object. Okay.
11:17:51One is for generator, evaluator and
11:17:52optimizer. Generator, evaluator and
11:17:54optimizer. Done. Now next uh I'm going
11:17:58to
11:18:00uh I'm going to define the state. But
11:18:02before define the state I already told
11:18:04you uh here see this evaluator this
11:18:08evaluator nodes will return you two
11:18:11things. Okay one is the evaluation. Okay
11:18:14evaluation uh that means it should be
11:18:17approved or needs improvement. Okay
11:18:20these two things and another one is the
11:18:23feedback. Okay, what should be the
11:18:24feedback for the optimization, right?
11:18:26So, it will generate two things. I don't
11:18:29need anything anything else apart from
11:18:31these two two things. One is the
11:18:33evaluation and another one is the
11:18:34feedback. So, if I want to get this kind
11:18:36of structured output, what I have to do?
11:18:38I have to use the pidentic. I already
11:18:39told you previously I also uh I have
11:18:42also taken the same example. So, what
11:18:44I'm going to do guys, I'm going to just
11:18:46create a
11:18:48um pyic class. As you can see, I have
11:18:50created a pyic class. So here uh I have
11:18:53named it as post evaluation I'm
11:18:54inheriting with the pidentic based model
11:18:57and two things I have taken evaluation
11:18:59and feedback. So in evaluation you can
11:19:01see this is the literal type it should
11:19:03be approved or need needs approved okay
11:19:06needs improvement and another one is the
11:19:08feedback that means it will generate
11:19:09some kinds of feedback for Facebook post
11:19:12that means if I now pass this thing to
11:19:14the u model that means if I add this
11:19:17line uh evaluator lm with structured
11:19:21output and if I pass this class this
11:19:23model will try to generate the
11:19:24structured output now so it will only
11:19:26give you evaluation and feedback not
11:19:28anything else okay now let Let me show
11:19:30you. So let's say I have defined this
11:19:32one.
11:19:34Now here I'm going to just generate a
11:19:37Facebook post from my chart GPT.
11:19:51Facebook post
11:19:56about
11:20:03presentic AI.
11:20:11Okay, I'll copy this and uh let's say
11:20:15here
11:20:17I can take a variable post.
11:20:32Now inside that I'm going to paste this
11:20:34post.
11:20:39Okay. Now I'm going to send it to the
11:20:44the structured evaluation.
11:21:04Done. Now if I show you the result.
11:21:07See this is giving you two things. One
11:21:08is the evaluation. You can also extract
11:21:11evaluation
11:21:13approved and the feedback.
11:21:19See this is the feedback for this
11:21:21particular post. Okay. So that's how
11:21:22every time we'll be getting this
11:21:24structured output from this uh large
11:21:27language model. Okay. The evaluated
11:21:29large language model because we have
11:21:30used pyic um um uh data evaluation for
11:21:34that. Now what I'm going to do guys next
11:21:37I'm going to define the state. I'm going
11:21:39to define the same state I have taken
11:21:40here. Um
11:21:43this is my state as you can see topic
11:21:46post evaluation feedback iteration max
11:21:49iteration post history and feedback
11:21:50history. So here I have uh added the
11:21:53reducer concept. So every time I'll try
11:21:55to add this uh two information instead
11:21:57of replacing. And these are the things I
11:21:59think you already got it right. Yeah.
11:22:04H and why I've taken literal here
11:22:06because evaluation will only return two
11:22:07things approved or need needs
11:22:09approvement. Okay, these two category
11:22:10that's why I've taken literal type
11:22:12instead of string.
11:22:15So now I will um I will um add my nodes.
11:22:20Let's define the graph and add the
11:22:22nodes.
11:22:26Yeah. So I have already defined the
11:22:28graph. You can see state graph. I have
11:22:30given this post state here. Now I'll add
11:22:32the node.
11:22:35Add
11:22:37node.
11:22:39So how many nodes we are having? 1 2 3.
11:22:44Okay. Three nodes we are having. We'll
11:22:46add this three node all together.
11:22:50Yeah. So these are three nodes. Generate
11:22:53post, evaluate post and optimize post.
11:22:57Okay. Generate, evaluate and optimize.
11:22:59Now we'll write this function one by
11:23:01one. So first of all we'll just try to
11:23:04write this generate post function note.
11:23:12So this is the function guys I've
11:23:14already written as you can see uh
11:23:16generate post it will take the state and
11:23:18here is the prompt I have prepared. It's
11:23:20a detail prompt I created with the help
11:23:22of chart GPT and here we are using the
11:23:24system message and human message
11:23:26function whatever I have imported from
11:23:28here. Okay. So as you can see this is
11:23:30the prompt. So system message I've given
11:23:32you are a funny and clever Facebook in
11:23:35influencer and human message write a
11:23:38short original and hilarious Facebook
11:23:40post on the topic whatever topic user
11:23:43will give and here I have assigned some
11:23:45rules do not use a question answer
11:23:47format maximum
11:23:49500 characters okay and blah blah blah
11:23:51these are the things I have added now
11:23:53after that I'm just uh invoking my
11:23:55generator lm and whatever content I'm
11:23:57getting I'm just updating the response
11:23:59inside the post and post history I am
11:24:02also updating because simultaneously
11:24:04update two things one is the post and
11:24:06this is the post history both I will
11:24:07update right so here it will replace
11:24:09every time here it will add every time
11:24:11because here we're using reducer concept
11:24:13and we are returning this particular
11:24:14state okay instead of returning whole
11:24:16state we are only returning the state we
11:24:18are changing so this is our uh generate
11:24:21post um nodes we have created that means
11:24:23this node is complete now let's try to
11:24:25add the evaluator one
11:24:28generate is done now we'll try to create
11:24:29the evaluator one.
11:24:33So this is the evaluator one guys. Again
11:24:35um I named it as evaluate post and
11:24:38sending this state. And here is the
11:24:39prompt guys I have prepared. Again I
11:24:41have given a sim uh system prompt. So
11:24:43this is the system prompt I have given.
11:24:45Okay. Now this is the human prompt.
11:24:47Evaluate the following Facebook post. Uh
11:24:49we have given the post from the state
11:24:51and here are some criteria I have given.
11:24:54Based on that it will try to evaluate
11:24:55and it will return two things. One is
11:24:57the evaluation approved or need
11:24:58improvements. Another one is the
11:25:00feedback. Then we are uh invoking our
11:25:03structured evaluator LLM that means this
11:25:05one. Okay, this one we are invoking this
11:25:08one instead of uh this one because here
11:25:12we have added the pentic class for the
11:25:13structured output.
11:25:17See and whatever evaluation result we
11:25:18are getting we are sending uh saving to
11:25:20the evaluator state evaluation state and
11:25:23feedback also uh I'm saving inside
11:25:26feedback and I'm also saving the
11:25:27feedback history because feedback
11:25:29history should be also updated. Okay.
11:25:32Yeah. So once it is done uh we are also
11:25:35returning the state. Now let's
11:25:38execute.
11:25:40Done. Now we'll try to create the last
11:25:42one which is optimize post.
11:25:48So this is for the optimize post. Again
11:25:50we are passing the state and here is the
11:25:52prompt you are a punch uh a Facebook
11:25:55post or virality and humor based on the
11:25:59given feedback. Then here is the human
11:26:02prompt I have given improve the Facebook
11:26:03post based on this feedback. We are
11:26:06giving the feedback. We're giving the
11:26:07topic as well as the original post. it
11:26:10uh my model has generated okay so based
11:26:13on the original post based on the
11:26:14feedback based on the topic it will
11:26:16optimize that uh post okay and it will
11:26:20rewrite that particular post and it will
11:26:21give it to you for this I'm hitting this
11:26:24uh optimizer lm and getting the response
11:26:27and we are updating the iteration here
11:26:29see here here we are updating the
11:26:30iteration like how many iteration it has
11:26:33to perform to give the final or let's
11:26:36say uh optimized version of the post
11:26:38okay every time this loop loop will
11:26:40execute and once let's say it found okay
11:26:43now this post is completely fine that
11:26:45time it will approve otherwise this loop
11:26:47would be continuously um running and how
11:26:50many times it will run for this we are
11:26:52just logging this iteration we are just
11:26:54adding one okay so this iteration value
11:26:57I'll give initially one okay u whenever
11:27:00I'll create the initial state and every
11:27:02time it will add the one how many time
11:27:03it will execute okay after that we are
11:27:06just returning the uh response okay that
11:27:09means the final post
11:27:11then the iteration okay then we are also
11:27:15uh saving this inside the post history
11:27:17and we are returning the state done guys
11:27:20okay now all of the nodes we have
11:27:23created successfully now we have to
11:27:25define the edge connection now let's do
11:27:27that so here I'll just try to comment
11:27:30add edges so first of all here we have
11:27:32to add the edges for
11:27:36this um
11:27:38start to generate
11:27:40Let's define
11:27:44start to generate.
11:27:46Then we have to define generate to
11:27:48evaluate.
11:27:53Generate to evaluate. Okay. Now here
11:27:56conditional ages will come because
11:27:58evaluate either it will send it to the
11:28:01approved. Okay. It will directly uh to
11:28:04the approved otherwise it will send it
11:28:06to the optimizer. Right? optimization.
11:28:08So here we'll be using using the
11:28:10conditional edges. So let's use the
11:28:13conditional edges here.
11:28:16So here we're using conditional edges.
11:28:18So it will start from evaluate and
11:28:20evaluate will decide where to send
11:28:22whether it will approved or send it to
11:28:24the optimize. For this we have to write
11:28:26a conditional function. I think remember
11:28:29for conditional statement we write a
11:28:30conditional function separately. So this
11:28:33is the conditional function. So it will
11:28:36take the state and here we are checking
11:28:37the condition if my evaluation okay that
11:28:40means I already saved this evaluation
11:28:42inside my state right you remember right
11:28:44evaluation and what is the evaluation
11:28:46approved or needs improvement okay so
11:28:49here we are checking if this state is
11:28:51equal to uh state evaluation is equal to
11:28:52is equal to approved or state iteration
11:28:55is greater than equal state max
11:28:57iteration that means if let's say it has
11:28:59performed maximum iteration let's say we
11:29:01have given maximum iteration is equal to
11:29:02four let's say four time it has done the
11:29:05iteration and uh uh whenever it is
11:29:08running for the five time that time I
11:29:11think our condition is matching right
11:29:13because my highest uh highest iteration
11:29:16is maximum iteration is four but
11:29:17whenever it is going for five that means
11:29:19this particular loop will break right so
11:29:21that's how we are checking another
11:29:22condition if this iteration is equal to
11:29:25it is greater greater than equal to
11:29:26maximum iteration that time just return
11:29:28approved okay otherwise return needs
11:29:31approved so this will basically redirect
11:29:34take this particular route whether it
11:29:35will send it to the optimizer or for the
11:29:38approver.
11:29:39Now we'll try to define this uh method
11:29:41here
11:29:43route evaluation.
11:29:45Route evaluation we'll write it here
11:29:48route evaluation. Okay
11:29:51H now here we'll be adding the
11:29:55iteration. Okay this that means the
11:29:56iterative workflows right now. Now now
11:29:58what will happen? See, let's say this
11:30:01evaluator returns approved. That means
11:30:04this particular workflow will exit here
11:30:06because I got my final post. But if it
11:30:09doesn't got the approved, let's say it
11:30:12it sends needs improvement that time
11:30:14what will happen? It will send it to the
11:30:17optimizer. Okay, it will send it to the
11:30:19optimizer node and optimizer will
11:30:20optimize then again it will send it to
11:30:22the evaluation. So these kinds of things
11:30:23if you want to write you have to give
11:30:25this statement inside conditional
11:30:27workflow only you have to write this you
11:30:30have to write this additional line see
11:30:33okay double comma I have given yeah now
11:30:35I think you can get see once this route
11:30:39evaluation returns approved okay that
11:30:42means it will end that particular
11:30:44workflow but if it return needs
11:30:46improvement that time it will execute
11:30:49the optimize node
11:30:51this optimize node
11:30:53Okay, optimize node. See, it is
11:30:55redirecting from here. If it needs
11:30:57improvement, it will hit the optimize
11:30:59node. Otherwise, it will hit the end
11:31:01note. See that? That is what we are
11:31:02doing. And this is called actually your
11:31:04iterative workflows. So, here we are
11:31:06adding the iteration. Okay, this is
11:31:08called actually iteration. I hope you
11:31:10got it guys. You don't need to take any
11:31:12kinds of separate function for this.
11:31:13Inside conditional is only you have to
11:31:15only write this statement. Okay, that
11:31:17means this route evaluation if it is
11:31:19returned the approved it will go to the
11:31:21end otherwise if it returns needs
11:31:24improvement it will um execute my
11:31:26optimize node and how many time it will
11:31:29perform unless and until we're not
11:31:31getting approved okay approved from my
11:31:34evaluator or this maximum iteration ends
11:31:37okay I hope you got it now our age
11:31:40connection is also done now simply what
11:31:42I'm going to do I'm going to
11:31:44um see this connection is
11:31:47this connection and uh this connection
11:31:49is done. Uh optimize to
11:31:54uh evaluate. Huh. So this connection is
11:31:56done. Now we'll try to make this
11:31:58connection. Optimize to evaluate. So
11:32:00let's say once it is in the optimize. So
11:32:04optimize will try to connect to the
11:32:05evaluator. That means optimize will send
11:32:07this optimization result to the
11:32:09evaluator. So this connection will try
11:32:10to add. So this is the connection.
11:32:17This is the connection. Okay. Optimize
11:32:18to evaluator.
11:32:20Now we'll try to compile.
11:32:26Okay. Now we'll try we'll show you the
11:32:28workflow.
11:32:30So see this is the workflow. Now this
11:32:32workflow and this workflow is exactly
11:32:34same. You can check it here. Okay. Now
11:32:36we'll try to execute this workflow. For
11:32:39this let's u define uh
11:32:44state
11:32:50let's say I have given the topic
11:32:53agentic AI let's say this is our topic
11:32:57and iteration initially I have sent it I
11:32:59have set it to the one because after
11:33:01that it will every time update um it
11:33:04will every time update one okay so uh
11:33:07whenever it needs any kinds of
11:33:09improvement optimization it will add
11:33:10one. Okay, that means the iteration
11:33:13update and this is our maximum
11:33:15iteration. I want to uh perform this
11:33:18iteration maximum five time. Okay, if it
11:33:21is not found in five time that means
11:33:23this loop will execute. Then we are
11:33:25giving this uh initial state to my
11:33:27workflow and we are getting the result.
11:33:29Now let me execute.
11:33:40Done. Now if I show you my result.
11:33:44So see this is the result we are
11:33:45getting. Uh as you can see
11:33:49uh this is the topic and this is the
11:33:51post it has generated. Evaluation is uh
11:33:54okay evaluation return approved. See at
11:33:57the first iteration it it got approved.
11:33:59Okay. Then feedback. This is the
11:34:01feedback and uh you can see iteration is
11:34:05one. That means it didn't updated any
11:34:07iteration. That means at the first time
11:34:08only it has approved. This is our
11:34:11maximum iteration and this is the post
11:34:13history and this is the feedback
11:34:14history. Okay. Now maybe you can change
11:34:17to another topic. Let's say I'll give uh
11:34:20LLM.
11:34:21See here we are using openm right?
11:34:23That's why this LLM is very powerful. Uh
11:34:26at the very first time it is generating
11:34:27good post. Okay. That's why it is
11:34:29getting approved. Okay. In the first
11:34:30iteration only. Now let me give any
11:34:32other topic or random topic and see the
11:34:35output. So maybe okay
11:34:46I'll give any random topic and let's see
11:34:55still uh at the first time only it is uh
11:34:58approving okay it's completely fine you
11:35:00can maybe try with different different
11:35:02topic okay and you will able to see that
11:35:04whenever it needs any kinds of improve
11:35:06improvement. Okay. Um it will run this
11:35:09iteration and it will update. Okay. And
11:35:12again it will send it to the optimizer.
11:35:14The reason uh it is giving you one short
11:35:17uh approval because we're using this
11:35:19open AAI uh GPTO mini and this is uh
11:35:22like good model. Maybe you can use any
11:35:25weaker model. Okay. Like more weaker
11:35:26model, more poor model. That time I
11:35:28think this uh loop will uh run. Okay.
11:35:31Iteration will run because we're using
11:35:33good model. That's why we are getting
11:35:34the result at the very first time. Okay.
11:35:36Okay, I hope you got it. Now, if you
11:35:37want to see the post history separately,
11:35:39you can also just write a loop and uh
11:35:43from the result you can extract the post
11:35:45history and you can see all of the post
11:35:46history you are getting. Okay, you can
11:35:49also see the feedback history. This is
11:35:50also possible. Okay, anything you can
Build Your First Agentic Chatbot with LangGraph
11:35:52extract because you are getting all the
11:35:54object here. Okay, so yes guys, that's
11:35:57how we can write this uh iterative
11:35:59workflows inside Langraph and this is
11:36:01super useful. Trust me whenever you will
11:36:03be implementing uh actual AI agents so
11:36:05this concept you need okay without that
11:36:08uh you can't perform this continuous u
11:36:11looping operation and you need uh to
11:36:13create a workflow I need this kinds of
11:36:14looping I need this kinds of conditional
11:36:16statement parallel statement okay each
11:36:18and everything is required now we have
11:36:20understood the last workflows inside
11:36:22langraph now uh in the next video onward
11:36:25guys we'll try to start working on the
11:36:27project so guys as you know I have
11:36:29started a complete agenti playlist on my
11:36:32YouTube channel and so far we have
11:36:34completed um uh so many important topic
11:36:37uh in this playlist. So if I show you my
11:36:40playlist guys, as you can see I started
11:36:43from introduction. I have already
11:36:45discussed about the uh evaluation from
11:36:48LLM to uh aentki how aentki came. We
11:36:52already understood about the entire
11:36:54aentki concept how agentic system works.
11:36:57Then I told you about asynchronous
11:36:59programming pentic. Okay. We also saw
11:37:02how we can implement AI agents with the
11:37:04help of langen. Okay. Then we started
11:37:06our first orchestration uh framework for
11:37:09AI agents implementation which is
11:37:11langraph. Uh even we also understood
11:37:13this langraph u um each and every
11:37:16component in detail with the code
11:37:18implementation as well. Now what I'm
11:37:21planning for guys I'm planning for the
11:37:23uh practical development of uh project.
11:37:26So what I'm going to do uh I'm going to
11:37:28start implementing a agentic uh chatbot
11:37:31from this video onward. So first of all
11:37:33let's try to understand uh each and
11:37:35every component in detail. Um we'll try
11:37:38to explain the things in detail because
11:37:40if you want to uh create a aentic
11:37:42chatbot so for this you need lots of
11:37:44component like you need uh tools, you
11:37:47need memory, you need persistence, you
11:37:49need streaming, you need user interface.
11:37:51Okay, there are so many things you have
11:37:53to implement uh independently then you
11:37:55will be combining them all together then
11:37:58one agentic chatbot would be ready.
11:38:00Okay. And if you found my content useful
11:38:02guys, please try to subscribe to my
11:38:04channel and hit the like and please try
11:38:05to share it with your friends and
11:38:07family. So, uh first of all, let's try
11:38:09to understand uh in this agentic chatbot
11:38:12whatever component we're going to
11:38:13implement. So, guys, first of all, let's
11:38:16discuss our plan like how we'll be
11:38:18implementing this entire agentic
11:38:20chatbot. So, the entire agentic chatbot
11:38:23I'll be implementing with the help of
11:38:26langraph.
11:38:28Okay, we'll be using Langraph
11:38:31orchestration framework to implement the
11:38:32entire agentic chatbot because uh this
11:38:36project is the part of our langraph uh
11:38:38orchestration framework in our playlist.
11:38:42So in this video first of all I'm going
11:38:44to create a simple
11:38:48simple chatbot
11:38:51workflow.
11:38:53Okay, we'll try to create a simple
11:38:55chatbot workflow.
11:38:57uh then we'll try to um make this
11:39:00agentic chatbot like more advanced. Uh
11:39:04we'll try to add some more advanced
11:39:06component in this particular agentic
11:39:07chatbot and with the help of that we'll
11:39:10be learning all of the langraph core
11:39:14component. Okay. So whenever let's say
11:39:16you want to implement this kinds of
11:39:18project whatever component you need from
11:39:21the langraph you will be understanding
11:39:23each and every component. Okay. So
11:39:25that's why I made this particular
11:39:27implementation like a series okay series
11:39:29of video. So next in the next video I'm
11:39:32going to show you the persistence
11:39:35concept
11:39:37like what is persistent
11:39:39okay persistence
11:39:42and uh why it is required why uh
11:39:44persistence uh we have to add inside our
11:39:47agentic chatbot we'll try to understand.
11:39:50So persistence in line graph.
11:39:54Okay. Then we'll try to understand
11:39:58um how to
11:40:02how to add
11:40:05streaming feature.
11:40:08Okay. Streaming feature to our chatbot.
11:40:12Then we'll try to understand the concept
11:40:16of
11:40:17um resume chat.
11:40:22Okay. How we can resume any kinds of
11:40:24chat inside our chatbot. Then we'll try
11:40:28to see the database integration.
11:40:33Okay.
11:40:34Integration
11:40:37in our chatbot.
11:40:39Then we'll try to see how we can
11:40:42implement
11:40:44uh user interface. Okay, let's say
11:40:48chatbot
11:40:51UI. Okay, we'll try to also implement
11:40:53this. Then uh after that I will also
11:40:56show you
11:40:58how to
11:41:00add the tools.
11:41:05Okay tools inline graph
11:41:12then we'll try to understand um the
11:41:15observability okay observability
11:41:23uh so in observability we'll try to see
11:41:25how we can integrate lang
11:41:28okay langmith to our agent so I think
11:41:32you have already heard of about lang
11:41:34langismith is observability tool. Uh
11:41:37with the help of that we can monitor the
11:41:39entire application. Okay. Uh what is the
11:41:41flow of the application? Uh when it is
11:41:43executing uh what component each and
11:41:46everything we can track okay in this
11:41:47particular lang lang smmith we'll also
11:41:49try to see how we can use the langismith
11:41:51here. Then after that we'll see the
11:41:55um RG concept okay how we can integrate
11:41:59the rag features inside our agentic
11:42:01chatbot because uh if you have already
11:42:03used this kinds of agentic uh system you
11:42:06know that it will also work with your
11:42:08documents let's say you can upload your
11:42:09documents and you can uh do the chat
11:42:12operation on on top of your entire
11:42:13documents okay this is called RG concept
11:42:15so the rag means retrieval augmented
11:42:17generation so we'll also try to
11:42:19understand this thing then we'll
11:42:21understand this uh
11:42:24hi TL that means human in loop concept
11:42:28then we'll also understand the
11:42:30short-term
11:42:32okay short-term and
11:42:36long-term memory concept as well
11:42:40okay memory so yes uh this is the entire
11:42:43plan guys so in this video first of all
11:42:45let's try to uh implement the simple
11:42:48chatbot workflow with the help of lang
11:42:50graph
11:42:51uh then from the next video onward I'm
11:42:53going to discuss these are the concept
11:42:54as well. So guys uh let's try to
11:42:57implement our chatbot workflow. So if
11:43:00you want to implement any kinds of uh
11:43:03agentic chatbot uh first of all you have
11:43:05to implement the uh chatbot workflow and
11:43:09how chat uh chatbot workflow works I
11:43:11think you already know that um so let's
11:43:14say if I want to uh implement with the
11:43:16help of lang graph. So how many node I
11:43:18have to take I have to take only one
11:43:20node which would be chat node. So here
11:43:22user will pass some message okay any
11:43:25kinds of message and uh it will go to
11:43:27the chat node and chat node will try to
11:43:29return something okay so this is a
11:43:31simple chat operations we'll be doing
11:43:33here and to run this particular uh graph
11:43:36actually we need a state and uh for this
11:43:39particular chatbot what would be the
11:43:40important state important state would be
11:43:42the message okay uh let's say the
11:43:44message user is passing let's say hi my
11:43:46name is BP so this message should be
11:43:48saved right and uh let's say your bot
11:43:52has replied uh welcome bi okay and how I
11:43:55can help you today. So these kinds of
11:43:57message would be also saved uh inside
11:43:59this particular state right. So for this
11:44:01uh what I have done guys, I have taken
11:44:03this um uh this particular state and
11:44:07here we are using the reducer concept.
11:44:09Okay, here we'll be using the reducer
11:44:10concept otherwise what will happen every
11:44:13time uh this uh state would be replaced
11:44:16with the new message. So I don't want
11:44:18that. I want to save all of the
11:44:20conversation story inside this
11:44:22particular state. Okay. And uh now you
11:44:24can ask me why we haven't taken string
11:44:27type data here because messages string
11:44:29type data. uh because I already told you
11:44:31here this is a conversational story and
11:44:34uh in langraph actually this is
11:44:36recommended whenever you are creating
11:44:37this kinds of uh chatbot you have to
11:44:40take this function this is a u uh like
11:44:42langraph function we have to import from
11:44:44the langraph called add messages in uh
11:44:48uh basically this add messages will try
11:44:49to handle this kinds of scenario it will
11:44:52take all of the conversation story the
11:44:53user message as well as the replied
11:44:56message and it will stored in this
11:44:57particular state okay and this state
11:44:59will go to the chat node. I hope you
11:45:01clear. Okay. So once we have built this
11:45:03uh uh workflow, the simple chatbot
11:45:06workflow, then we'll try to make it more
11:45:08advanced. We'll try to make this
11:45:11particular workflow uh as agentic
11:45:14chatbot workflow. Okay. So for this what
11:45:16we'll try to add guys uh we'll try to
11:45:18add uh see as of now in this particular
11:45:20workflow you can perform the simple chat
11:45:23operation.
11:45:25In this workflow you can perform simple
11:45:29chat operation. Okay. After that we'll
11:45:31try to add the rag functionality. That
11:45:34means even you can also upload any kinds
11:45:37of documents and you can perform the
11:45:38chat operation on top of that. Okay. You
11:45:40can add extra knowledge base on this
11:45:42particular chatbot. Right? Then we'll
11:45:44add the tools. Okay. Realtime tools
11:45:47we'll try to add so that uh if you are
11:45:49asking any kinds of question and if it
11:45:51needs any kinds of tool it will try to
11:45:53use that. Okay. And uh that time
11:45:56actually it will become agentic chatbot
11:45:58that means it doesn't only have the um
11:46:01like uh I mean um the existing knowledge
11:46:04base it has also connection with lots of
11:46:06tools okay so that whenever you are
11:46:09asking something it will real time fetch
11:46:11those informations and it will give it
11:46:12to you then um I will also add the user
11:46:15interface
11:46:17uh because user needs a user interface
11:46:19to use this particular chatbot. So
11:46:21definitely we try to create the UI and
11:46:23for UI implementation as of now I'll be
11:46:25using a streamlit package. It's a Python
11:46:28package and here you don't need to write
11:46:29any kinds of HTML and CSS code but later
11:46:32on I'm also going to show you how we can
11:46:34use HTML and CSS code how we can use the
11:46:37fast API okay with the help of that
11:46:39we'll try to create the entire asentic
11:46:41chatbot but as of now we are learning
11:46:43okay this is our first project so that's
11:46:45why I'll be using streaml so that
11:46:47everyone can implement with me okay then
11:46:50we'll also try to add the observability
11:46:52tool which is lang
11:46:56okay lang hangmith will try to add. So
11:46:58with the help of that we'll try to
11:47:00monitor the entire chatbot. Okay. Uh
11:47:02like how it is performing which
11:47:03particular component is triggering each
11:47:05and everything. We'll try to log in the
11:47:07lang speed dashboard. Then we'll also
11:47:09learn some advanced topic as well. Some
11:47:12advanced topic as well.
11:47:14Okay. Inside advanc topic we'll be
11:47:16learning memory concept. Okay.
11:47:19Short-term and long-term memory concept
11:47:21we'll try to learn. Um um okay I missed
11:47:24out one thing which is uh persistence.
11:47:27Okay here we'll also try to learn this
11:47:30persistence.
11:47:33Okay we'll also try to add the
11:47:35persistence in the chatbot. Then we'll
11:47:37be learning the memory the advanced
11:47:38topic. Then we'll also try to learn this
11:47:42hit human in the loop. Okay. Uh then
11:47:45here also we'll try to learn the retry
11:47:47functionality like how we can perform
11:47:49the retry functionality and all. So
11:47:50these are the thing we'll try to cover
11:47:52that means by this particular project
11:47:54itself we'll try to master okay all of
11:47:57these langraph concept in detail okay
11:48:00that's why I made this particular
11:48:02implementation as a series so that each
11:48:04of the video will cover uh each of these
11:48:06concept in a detailed way okay so yes
11:48:09guys uh this is the uh plan I think you
11:48:11got it now uh we already have the graph
11:48:14okay we already have the workflow uh
11:48:17architecture now based on this
11:48:18architecture now let's try to implement
11:48:20ment our uh chatbot. Okay, first of all,
11:48:22we'll try to create this simple chatbot
11:48:25workflow in this particular video. Then
11:48:27from the next video onward, I'm going to
11:48:29discuss one by one all of this advanced
11:48:31component. So first of all, let's try to
11:48:34create a Jupyter notebook file. Uh
11:48:36because initially I want to show you
11:48:38this workflow in the Jupyter notebook.
11:48:40Then I'm going to just uh write
11:48:43everything in the py file. Okay, Python
11:48:45scripting file because Jupyter notebook
11:48:47file we won't be using whenever we'll be
11:48:49creating the project. Okay. But for
11:48:50experiment purpose, we'll be using this
11:48:52Jupyter notebook. So here, let's try to
11:48:55create a file ipv.
11:49:03Yeah. So previously I had my environment
11:49:05which is uh this langraph test. I'll try
11:49:08to select this one. And here we'll try
11:49:11to import all the necessary library we
11:49:13need. And this import would be common
11:49:15guys. I think you know that what is this
11:49:16import? Let's import everything.
11:49:21So these are the import we need. Uh we
11:49:24are importing this state graph start
11:49:26end. Then from typing we are importing
11:49:28uh type dict annotated. Then we are also
11:49:31importing this base message and human
11:49:33message. And uh we will be using openi
11:49:36large language model. That's why from
11:49:38langen we are importing chat openai. You
11:49:40can also use any other uh large language
11:49:42model provider like grock. You can also
11:49:44use open router, gemini. Okay. anything
11:49:48you can use only you just need to check
11:49:49the lang chain documentation how to
11:49:51import that okay even you can also copy
11:49:53this code and if you give to the chat
11:49:55JPT this will replace with another model
11:49:58but I have my open API key that's why
11:50:00I'll be using open AI model here so
11:50:02let's import all of the package okay
11:50:04it's done now the next thing guys what
11:50:06you have to do you have to get this open
11:50:08API key so quickly I'm going to move my
11:50:11env file from my previous uh previous
11:50:15code.
11:50:17So guys, as you can see, this is myb
11:50:19file. And inside that, I'm going to
11:50:22simply copy my
11:50:26um open environment v uh open API key.
11:50:32So this is my open API key. I already
11:50:34collected.
11:50:37Now let's try to
11:50:40uh write the further code. Yeah. So now
11:50:43what I'm going to do guys uh first of
11:50:45all here I'm going to
11:50:48um I'm going to initialize the LM.
11:50:53So here I'm initializing the LLM. Okay.
11:50:56So we'll be taking the default large
11:50:58language model. Okay. Here I'm getting
11:50:59an error because uh I have to load this
11:51:02environment variable right. So let's
11:51:04load it. So from env
11:51:12import load env
11:51:15we'll try to load this environment
11:51:16variable.
11:51:20Then now this code will work. Yeah. Now
11:51:23we are able to load our lm. Now first of
11:51:26all you have to define the state. Uh so
11:51:28let's try to define the state.
11:51:31Um this is the state guys.
11:51:34And I already told you if you are uh
11:51:37storing conversational story that time
11:51:40you can use this function add messages
11:51:42from langraph graph message. Okay. So
11:51:44here uh we are using the reducer
11:51:46concept. Um um I think you know what is
11:51:49the reducer function um like um
11:51:52operation add previously we used but
11:51:55right now uh this is a conversational
11:51:57story. So we'll be using this add
11:51:58message and by default actually it will
11:52:00perform this uh adding operation instead
11:52:02of replacing. Okay. And uh here I given
11:52:06the base message.
11:52:08Base message means uh see inside base
11:52:10message what happens? We are telling
11:52:12this is a uh like u uh chat history.
11:52:15Chat history means uh there will be uh
11:52:17user message as well and there would be
11:52:19um like uh AI reply as well. Okay. So if
11:52:22you combine all of them together, this
11:52:24will become a base message. Okay. So
11:52:26this is why we are using the base
11:52:28message here. So this is going to be my
11:52:31state. Now let's try to define the
11:52:32state. So after that we'll try to create
11:52:34the uh graph. Now let's create the
11:52:37graph.
11:52:40So this is our graph guys uh state graph
11:52:42and we have given the state to the
11:52:44graph. Now after that we'll try to add
11:52:46the nodes. So let's comment here
11:52:52add
11:52:55nodes. So if you see we only have one
11:52:59nodes which is chat nodes. Okay, let's
11:53:01try to add that.
11:53:04So, graph dot add
11:53:08graph dot add uh chat node and uh this
11:53:11function we have to write separately. Uh
11:53:14so, let's try to write this function.
11:53:17I'm going to create a function def chat
11:53:19node and this will take this state
11:53:24but I'm not going to return all of this
11:53:25state all together. Instead of that
11:53:28simply
11:53:30um I'm going to only return the update
11:53:33message. Okay.
11:53:35So first of all here we'll be taking the
11:53:37user query
11:53:39from this state.
11:53:41Okay. Take the user query from the
11:53:44state.
11:53:46Yeah. So user will give the message
11:53:48right? User will give the message. So
11:53:49this message I'll be uh uh basically
11:53:52this will start store as a message.
11:53:54Okay. So this message I'm extracting.
11:53:57Then after that we'll try to send it to
11:53:59the llm.
11:54:02Okay. Send it to the llm. You can see
11:54:04llm.inbox. We are giving the message and
11:54:06we are getting the response. Okay. Now
11:54:08this response
11:54:10I'm going to store in the message again.
11:54:12Okay. Uh response stored in the state.
11:54:16Uh that means in the message keyword
11:54:18because this is a list type. Okay. And
11:54:19every time it will uh store your user
11:54:22message as well as the um response.
11:54:24Okay, altogether it will store and we
11:54:27are returning the state. So this is
11:54:28going to be my chat note. As you can see
11:54:30this is going going to be my chat node.
11:54:32So once this chat note is prepared. Now
11:54:35let's try to add the edges. Okay. Now if
11:54:37you see the edge connection first of all
11:54:39start will be connected to the chat
11:54:41node. So let's try to add the edges.
11:54:47Add edges.
11:54:49So start would be connected to the chat
11:54:51node and chat node would be connected to
11:54:54the end.
11:54:56Chat node would be connected to the end.
11:54:58Okay. So this is the simple um like edge
11:55:00connection. After that we'll try to
11:55:02compile the graph.
11:55:08Let's compile the graph.
11:55:11We have com uh here we'll be compiling a
11:55:14graph. Okay. Now let's compile. Yeah.
11:55:16Done. Now if you want to see the
11:55:17workflow.
11:55:21So this is the chatbot workflow. Okay.
11:55:23This is the simple chatbot workflow we
11:55:25have created like that. Okay. Now here
11:55:28you can perform this simple chat
11:55:30operation. So this simple chat operation
11:55:32you can perform as of now. Now let me
11:55:34show you how we can perform the chat
11:55:35operation. Now let's give the initial
11:55:37state. So this is our initial state
11:55:39guys. As you can see, we are using human
11:55:41message because this is a human prompt
11:55:43and for this we have already imported
11:55:45this human message. It's good to uh use
11:55:48this function whenever using uh whenever
11:55:50you are implementing this kinds of
11:55:51chatbot. So as you can see message uh
11:55:55this should be a dictionary we are
11:55:56giving the message and uh you can see it
11:56:00takes u as a list okay as you can see it
11:56:04takes as a list okay input.
11:56:07So that's why we are giving as a list.
11:56:11Now we are giving the human message and
11:56:13this is the content what is the object
11:56:15oriented programming. So this thing I
11:56:16will try to pass to my
11:56:19uh chatbot. Okay. So chatbot do invoke
11:56:22we are giving the initial state and this
11:56:24will return you. Let me show you if I
11:56:26don't give this line.
11:56:32Yeah. So this will give you this kinds
11:56:34of response. So maybe I can store inside
11:56:36a variable response is equal to
11:56:37chatbot.invoke.
11:56:41Now if I show you the response. So this
11:56:44is the response. Inside this response
11:56:45you have two things.
11:56:50Uh here one you have the message. Okay
11:56:53the human message and another one is the
11:56:56AI message. Okay. Now I have to extract
11:56:59this AI message for this uh uh this is a
11:57:03dictionary. First of all, I have to
11:57:05extract the message. Okay, message
11:57:06keyword.
11:57:08This message uh message key I have to
11:57:10extract. Once we got the extract, now
11:57:13this is a list. And here we have two
11:57:14items. Okay, one is the human message
11:57:16and one is the AI message. And that's
11:57:17how this uh um add message stores your
11:57:21data right inside this list. Now I need
11:57:24the last one. So for this I give minus
11:57:26one.
11:57:27Okay, the last index AI message. Now I
11:57:30only need the content. So here simply
11:57:32I'll just give dot content.
11:57:34Okay, if you do it now you will be able
11:57:36to get this content guys. Very simple.
11:57:39Okay. So that's how guys you can perform
11:57:41any kinds of chat operation right now
11:57:43with this particular workflow. Now let's
11:57:44say I will ask another question. What is
11:57:46uh let's say
11:57:48object- oriented programming in Python.
11:57:56Now see object oriented programming in
11:57:58Python blah blah blah. Okay, it's
11:58:00working perfectly. Okay, so guys, now
11:58:03what I'm going to do, I'm going to just
11:58:05make a loop so that user can
11:58:07continuously give the uh input and uh
11:58:11this chatbot will be working. Okay, uh
11:58:14it will provide the output u because
11:58:16right now every time I have to change
11:58:18the um message here and I have to
11:58:20re-execute the cell but I don't want
11:58:22that. I want a loop. Okay. So for this
11:58:25uh what I can do guys, I can just make a
11:58:28while loop.
11:58:30So this is our while loop.
11:58:33Okay. So here we are taking a input from
11:58:35the user. Uh I'm just telling type here
11:58:38some message. Then we are printing this
11:58:41uh uh user message. Then I'm checking if
11:58:45user messagees uh uh let's say if it is
11:58:48uh if they write like say Z, exit, quite
11:58:51and by. So that time I'm going to break
11:58:53the loop. Okay. Otherwise I'm going to
11:58:56simply invoke my
11:58:59LM.
11:59:02So let's do that.
11:59:06So we'll be invoking our LM here. That
11:59:09means the workflow. So as you can see we
11:59:12are doing the same thing. We are just
11:59:13hitting this chatbot invoke. We are
11:59:16giving the message human message. Right
11:59:19now the content should be equal to the
11:59:20user message. Okay. because previously I
11:59:23hardcoded this message but right now I'm
11:59:25taking as a variable input variable once
11:59:28it is done I'm going to print this
11:59:29response in the terminal okay we'll be
11:59:32printing this message in the terminal
11:59:33that's it now let's execute okay now
11:59:36let's execute this while loop now here I
11:59:38can give the message hi
11:59:42now see user given hi and it's telling
11:59:45hello how I can assist you today I'll
11:59:47tell my name is puppy
11:59:52Okay. Hello By, nice to meet you. How I
11:59:54can assist you? I'll tell
11:59:57what is
12:00:01Python.
12:00:07See, it's working fine. Okay. But one
12:00:10issue I want to show you in this
12:00:11particular chatbot. Let's say now if I
12:00:14ask what is my
12:00:18name?
12:00:22Now it will tell you I'm sorry I'm not
12:00:24able to access the personal information
12:00:26about the user. But although if you see
12:00:29every time we are saving this
12:00:32information to this state and we are
12:00:34passing this state to the uh to this
12:00:36node okay if I open my
12:00:39um diagram I think you see that. So
12:00:42every time what is happening whatever
12:00:44message user is giving I'm storing in
12:00:46this uh state and whatever uh response
12:00:49also I'm getting I'm also storing in
12:00:51this particular state and we are passing
12:00:53the state to the chat node. So chat node
12:00:55should have the informations okay about
12:00:58the older conversation because we are
12:01:00storing the conversation story but still
12:01:03why it is not able to give you the
12:01:05answer. Okay still why it is not able to
12:01:07give you the answer? This is a question
12:01:09to you just try to think about and uh
12:01:12please reply in the comment if you uh
12:01:14can you can pause the video and you can
12:01:16reply in the comment okay why uh it is
12:01:18happening like that see if I tell you um
12:01:21uh see what is happening if you're using
12:01:24the state concept right if you're using
12:01:26the state concept so what will happen
12:01:28first of all let's say it will start
12:01:30this node then the input will go to the
12:01:32chat nodes okay then chat node will
12:01:35return some kinds of response then it
12:01:37will go to the end okay so once Once it
12:01:39is reaching to the end, right? Once it
12:01:41is reaching to the end, that time this
12:01:44execution is um this execution is
12:01:47ending. Okay, this execution is ending
12:01:49that means whatever you have in the chat
12:01:52state. Okay, that means in the state
12:01:54this particular data would be erased.
12:01:57Okay, this particular data would be
12:01:59erased. So that time whenever you are
12:02:01running this loop, right? You are
12:02:03running this loop. So every time what
12:02:06you are doing you are invoking the
12:02:07chatbot you are invoking the workflow
12:02:09and whenever you are invoking the
12:02:11workflow that means what is happening
12:02:13you are re-executing from from here okay
12:02:16you are reexecuting from here that means
12:02:18again it will go to the chat node to the
12:02:21end again this data would be erased okay
12:02:23so every time this particular list will
12:02:26be erased okay it is not able to like uh
12:02:28let's say uh store the older
12:02:32conversation it will only store in this
12:02:34particular particular session only only
12:02:36one session let's say right now this
12:02:38loop is running right in this particular
12:02:40session this information is available
12:02:42but whenever we are again executing this
12:02:44loop is again executing from here that
12:02:47time this information is getting erased
12:02:51this is the problem okay now how we can
12:02:54handle this kinds of scenario we can
12:02:56handle this kinds of scenario with help
12:02:57of persistence okay I I think I already
12:02:59told you about persistence right now
12:03:01we'll be using persistence concept it
12:03:04and uh we can uh we can actually handle
12:03:07this kinds of scenario that means
12:03:09whatever conversation story we are let's
12:03:11say having okay so we [snorts] can store
12:03:15somewhere this conversation story
12:03:17because right now this is only storing
12:03:19inside the variable and once it is
12:03:21getting initialized again this variable
12:03:23is getting cleared okay this is the main
12:03:25problem so that's why langraph uh
12:03:28supports actually persistence concept so
12:03:30inside persistence either you can save
12:03:33these informations in the memory saber
12:03:34that means inside your RAM either you
12:03:37can save this particular informations in
12:03:38the database and you can load load
12:03:41anytime okay these kinds of things you
12:03:43can perform now let's try to see how we
12:03:45can do this kinds of persistence uh
12:03:47operation
12:03:48so for this I'm going to open up my code
12:03:50again
12:03:52okay so here simply I can exit my bot so
12:03:56for this you have to give this exit
12:03:57message
12:04:00sorry
12:04:02this exit message only
12:04:05done now see it has exited now see uh
12:04:08persistence concept I'm going to explain
12:04:10in detail in the next video so only I'm
12:04:13just going to add this persistence uh
12:04:16let's say um uh implementation here how
12:04:19we can add the persistence so inside
12:04:21persistence uh basically we just try to
12:04:25add a memory here okay we just try to
12:04:27add a checkpoint memory so what happens
12:04:31let's say the entire state we we are
12:04:32having right this entire state we are
12:04:34having so this entire state we can save
12:04:37inside a memory either you can save
12:04:38inside your RAM okay this memory you can
12:04:41say uh this state you can save inside
12:04:42your RAM either you can save inside the
12:04:45database okay but right now this
12:04:47particular state is not getting saved
12:04:48anywhere this is only storing the data
12:04:51in the variable and you know whenever
12:04:53code will re-execute this variable would
12:04:55be clean clear that time right we
12:04:58already know that if you understand the
12:04:59Python concept you already know that so
12:05:01Somehow we have we have to store this
12:05:04state inside a storage uh storage
12:05:07actually um let's say service either you
12:05:10can uh use your RAM because you know
12:05:12that RAM would be the temporary storage
12:05:15it's completely fine but if you want a
12:05:17permanent storage that time you can use
12:05:20any kinds of database this database part
12:05:22I will also show you in future but I
12:05:24told you I'll be going uh step by step
12:05:26so that I can explain each and every
12:05:28concept in detail. So initially we'll
12:05:30try to see how we can save this
12:05:31information in the RAM. So whenever
12:05:33we'll save inside the RAM so what will
12:05:35happen this uh this particular uh data
12:05:39would be saved unless and until I don't
12:05:41restart my kernel. Okay if I restart my
12:05:44kernel that time this information would
12:05:46be clean up otherwise this information
12:05:48will remain same inside my RAM. Okay. So
12:05:50this kinds of concept we'll try to add
12:05:51right now. So here
12:05:54uh for this I'm going to import a
12:05:56function from lang graph. So inside lang
12:05:59graph there is a function called
12:06:02um memory saver. Let me import that.
12:06:06So this is the function langraph.
12:06:08Checkpoint [snorts] domemory import
12:06:10memory saver. Okay. So this memory saver
12:06:12stores your state inside the memory
12:06:14inside the RAM. You can also use any
12:06:17kinds of database. That part I will also
12:06:19show you later on. Okay. First of all
12:06:20let's try to see the memory server one.
12:06:22Now let me import.
12:06:24Okay. So once it is done now simply
12:06:28here whenever you are defining the
12:06:31graph. So before the graph
12:06:34initialization you have to define a
12:06:36checkpoint. This checkpoint should be
12:06:39the memory server. Okay. So this is
12:06:41going to be this is going to become your
12:06:43memory server object. Okay. Checkpoint.
12:06:45Now whenever you are compiling your
12:06:48entire graph that time you have to
12:06:49mention I have a checkpointer. Okay I
12:06:52have a checkpo pointer. So this
12:06:54checkpointer will basically store your
12:06:57state in the RAM. Okay you can see
12:07:00checkpo pointer is equal to checkpoint
12:07:01and here we are using memory server.
12:07:03Memory server means the RAM that means
12:07:05whatever state it is getting right the
12:07:07chat state that means the entire state
12:07:08it is getting and every time it is
12:07:11updating right with the user message and
12:07:13the reply of the AI message right every
12:07:15time it is getting update so this
12:07:17information will save in the RAM right
12:07:19now okay because we are using the
12:07:20checkpoint uh checkpointter right now
12:07:22okay now let's try to compile the graph
12:07:25so one compilation is done now let me
12:07:29show you h now let's Okay. Uh I don't
12:07:34need to execute this code. I will
12:07:35directly execute my while loop. Okay.
12:07:38Yeah. But before executing the while
12:07:40loop
12:07:42here, I will pass one thing. Uh here you
12:07:45can specify the trade. Okay. Trade means
12:07:50um
12:07:52it should be like kinds of unique uh
12:07:55unique ID for each of the user. Let's
12:07:57say this chatbot can use many people,
12:08:01right? This chatbot can use by me then
12:08:05this chatbot can be used by any other
12:08:07person. So all of the people can chat
12:08:10together here right and if they're
12:08:12chatting together it's not like that
12:08:14let's say I will let the people to chat
12:08:17with my chat history right so instead of
12:08:20that what uh it should have it should
12:08:22have a different trade ID okay different
12:08:25trade ID different trade ID means let's
12:08:26say if this trade ID is equal to one I
12:08:29have set let's say trade is equal to one
12:08:31that means this is my trade ID so
12:08:33whatever chat I will perform
12:08:35it will store all of the information in
12:08:38this particular trade right in this
12:08:40particular let's say whenever it will
12:08:41store inside the memory right because I
12:08:43used the memory server so in the memory
12:08:45it will create a separate section for
12:08:48one okay and all of the information all
12:08:50of the chat history it will save inside
12:08:52this particular trade okay now if I
12:08:54change it to two right that time uh
12:08:57another user will come and he will
12:08:59perform the chat operation that means
12:09:01what is happening in the memory there
12:09:03are different block is getting created
12:09:04let's say this is trade one this is
12:09:07trade two okay whatever chat I'm
12:09:10performing in the trade one uh trade two
12:09:13person won't be able to see that okay he
12:09:15won't be able to access this information
12:09:17and whatever let's say uh chat trade two
12:09:20is doing trade one won't be able to see
12:09:22or get this particular information okay
12:09:25like the chart GPT like chart GP is
12:09:26having different trade right whenever
12:09:29let's say you uh you just create a new
12:09:32chart right uh in the chart GP whenever
12:09:34you create a new chart let me show you
12:09:37so here
12:09:40so this is my chat GPT so let's say here
12:09:43you can create a new chart right you can
12:09:45create a new chat and you can perform
12:09:47some chat operation here
12:09:50right so this is this becomes a trade
12:09:52right then whenever you takes another
12:09:54new chart that means the complete new
12:09:57trade will be getting here and you can
12:09:58perform the another chart operation here
12:10:01okay so that means you won't be able to
12:10:03get the previous uh let's Okay. Uh
12:10:07previous let's say trade uh information
12:10:09in this particular trade but you can
12:10:11switch to the trade. Okay. Let's say you
12:10:12can uh switch to the trades anytime. You
12:10:14can go to the previous trade. You can uh
12:10:16go to the current trade. Okay. That's
12:10:18how we can switch. So these kinds of
12:10:20things also we can perform with the help
12:10:21of this persistence. Okay. We can make
12:10:23different different trades here. Now
12:10:25let's try to do that. Let me show you. I
12:10:27think after seeing the practical
12:10:28implementation you will be able to
12:10:30understand. Now let's say I'll make it
12:10:31as trade ID. Initially I'll give it as
12:10:33one. And uh whenever you are um using
12:10:37this persistence concept that time you
12:10:39have to define a configuration.
12:10:42So this is the configuration before
12:10:44response maybe I can create it.
12:10:47So this is the configuration config is
12:10:49equal to configurable and here you have
12:10:51to pass this trade ID is equal to trade
12:10:53ID. So your trade ID okay then this
12:10:54should be a dictionary. Okay dictionary
12:10:56object and this config you have to pass
12:11:00whenever you are invoking the workflow.
12:11:02So here at the last you have to give
12:11:04this uh config.
12:11:09You have to give this config. Config is
12:11:10equal to config. Okay. Now what will
12:11:13happen? Every time uh this uh this uh uh
12:11:17persistence what it will do it will try
12:11:19to uh load the information load the
12:11:22state from the memory and it will try to
12:11:25pass to the um it will try to pass to
12:11:28the
12:11:30um invoke function. Inbox function means
12:11:32you are giving the user message as well
12:11:34as the older history. Okay, user message
12:11:37as well as the older history. That means
12:11:38whatever older history you are having,
12:11:40whatever chat state you are having, you
12:11:42are entirely passing the chat history as
12:11:46well as the new message user is giving.
12:11:48Okay, right now it won't be replacing
12:11:51because we are storing in the memory and
12:11:53every time we are loading it and passing
12:11:55it to the invoke function. Now see if I
12:11:57execute the code.
12:12:00Now let's say here I'll tell my name is
12:12:04BP.
12:12:10Okay. Now let's say I'll give another
12:12:12message. What is Python?
12:12:19Done. Now if I ask let's say what is my
12:12:24name.
12:12:26Now see your name is BYI. It is able to
12:12:29remember right now. Okay, it has some
12:12:31kinds of memory right now and this
12:12:33information is saving inside my RAM
12:12:36because we are using memory saver here.
12:12:38And this is called persistence. Okay,
12:12:40this is called persistence. Now if I
12:12:42let's say give another trait. Okay,
12:12:45let's see if I give another trade. Let's
12:12:46see if I do exit right now. Um one thing
12:12:49I want to show you uh if I run it inside
12:12:51my while loop. So if I exit my while
12:12:53loop so that time your entire session
12:12:55will be um like restarted. So instead of
12:12:58that maybe I can use this code. I'll
12:13:01copy this trade ID here
12:13:06trade ID and uh I will also copy this
12:13:11config
12:13:15and we'll pass this config to this
12:13:24Whenever we're doing the invoke
12:13:25operation here, I'll try to pass the
12:13:26config. Okay. Now let's execute. So
12:13:29let's say I'll type what is
12:13:33or I'll pass my name is puppy.
12:13:44Now see uh nice to meet you BP. Now if I
12:13:47ask um
12:13:50what is my name?
12:13:58What is my name?
12:14:05It's giving your name is BP. Okay. Now
12:14:08let's see if I give another trade here.
12:14:10Okay. Let's say trade two. Now if I ask
12:14:13what is my name?
12:14:16Now see it is telling I'm sorry I do not
12:14:18know what is your name is an uh is uh as
12:14:23I am a AI assistant and I do not do not
12:14:25uh have access to the personal
12:14:27informations. Okay because this is a
12:14:29completely new trade right now. Okay.
12:14:31Now let's say in this particular trade I
12:14:33will give let's say my name is
12:14:37my name is Alex.
12:14:42Now it is telling nice to meet you Alex.
12:14:44Okay. Now if I ask what is my name?
12:14:55Now it will tell your name is Alex.
12:14:57Okay. Now if I switch to my trade one.
12:15:00Okay. Now if I again ask what is my
12:15:02name? You will see that it will tell you
12:15:04your name is BP. See your name is BP.
12:15:06Okay. Now if I go to my trade two,
12:15:11trade two that time uh your name is
12:15:15Alex. Okay, I hope you got it this
12:15:17concept. Okay, this trading concept that
12:15:19means we can separate out the chat
12:15:22session. Okay, chat session for each and
12:15:24every user. This is possible, right? And
12:15:28uh here you can also see the u state.
12:15:33Uh so for this you can use this code
12:15:37so chatbot dot get state and you have to
12:15:40pass the config and you will be able to
12:15:43see like uh how many trades you are
12:15:46having okay all of the history you will
12:15:48be able to see the entire state that
12:15:50means the entire state you will be able
12:15:51to see the state is saved in the memory
12:15:53so this is the snapshot object as you
12:15:55can see whatever question you have asked
12:15:58like what is my name some other metadata
12:16:01the AI response okay So each and
12:16:03everything is visible here
12:16:07the input token output token
12:16:10and you will be able to see the trade ID
12:16:11as well. So what is the trade ID?
12:16:14Yeah. So this is the trade ID 2 and
12:16:16trade ID one is also there
12:16:20somewhere. Okay. So that means the
12:16:21entire U state snapshot you will be able
12:16:24to see here. So this entire step
12:16:26snapshot you will be able to see here.
12:16:28If you're using this persistence concept
12:16:31and there is a function called get state
12:16:33inside that you have to only pass the
12:16:35configuration the configuration you are
12:16:36preparing you'll be able to see the
12:16:38entire state. Okay. Uh it is saved in
12:16:41the memory. So yes uh this is the
12:16:43concept uh of this persistence. Okay we
12:16:45have learned this persistence concept.
12:16:48So here I already told you persistence
12:16:51we can add inside langraph. This is also
12:16:53possible. And don't worry I'm also going
12:16:55to um take another I'm also going to
12:16:57record another video on top of this
12:16:58persistent in detail. We'll try to
12:17:00understand each and every uh concept
12:17:02okay of this particular persistence. Now
12:17:05uh this thing is working fine. Now what
12:17:07I can do I can quickly
12:17:10uh I can quickly convert it to the um py
12:17:14file. So let's create a file here. I'm
12:17:16going to name it as
12:17:20aentic
12:17:25chatbot.py
12:17:29pipe
12:17:31and whatever code I have written here
12:17:34I'll just try to copy here
12:17:41or let's name it as aic chatbot back end
12:17:46back end okay now I'm going to copy here
12:17:49so first of all let's import all the
12:17:50necessary library.
12:18:01Select my environment.
12:18:05Then I'll load the environment variable.
12:18:13Then
12:18:16initialize the model.
12:18:19Define the state.
12:18:38So this is my state. Now I'll copy my
12:18:42node.
12:18:45After
12:18:49node I will copy my
12:18:53enter graph.
12:18:57Okay. Uh so this is going to be my uh
12:19:00final.
12:19:03Yeah. So this is going to be my final uh
12:19:06workflow object. Okay. Chatbot object.
12:19:07Now we can use this chatbot object
12:19:09anywhere to run this particular
12:19:11workflow. Now what I'm going to do guys
12:19:14um I'm going to show you whether it is
12:19:16working or not. So maybe I can create
12:19:18another file here called let's say
12:19:21app.py.
12:19:24Inside app.py let me first of all import
12:19:27this chatbot object. So from
12:19:31aentic
12:19:33chatbot back end import chatbot.
12:19:38Okay chatbot. Now I'll just write
12:19:41response is equal to chatbox.invoke
12:19:45and here we have to pass the human
12:19:46message. Okay. And for human message we
12:19:48have to import this library.
12:19:50This one
12:19:57so here I'll give let's say what is um
12:20:03python
12:20:05and whatever response I'll get I'll just
12:20:07try to print the response. Okay. Now
12:20:09let's see whether it's working or not.
12:20:11So I'll open up my terminal.
12:20:15Then I will activate my environment. So
12:20:17cond activate
12:20:22uh lang graph test
12:20:24h. After that we'll try to execute then
12:20:27app.py. So python app.py.
12:20:35Okay. Here
12:20:37uh okay. Uh sorry actually I have to
12:20:39give this uh I have to give this um uh
12:20:42trade ID right trade ID I haven't given
12:20:44because here uh initially we pass the
12:20:47trade right we are giving the checkp
12:20:49pointer so here I have to get the uh
12:20:50pass this trade
12:20:53so here I will copy this trade
12:21:05and also copy this configuration
12:21:13Then we'll pass this config. Now I think
12:21:16this will work.
12:21:26See it's working. Python is a high level
12:21:29um widely used programming language blah
12:21:31blah blah. Okay. But here uh actually I
12:21:34can't left this kinds of application to
12:21:36the user because user don't know how to
12:21:39code right and how to execute this uh
12:21:41app.py from the terminal. So definitely
12:21:43I have to add the user interface. Okay.
12:21:46Now let's try to add a user interface
12:21:47with the help of streaml here. So guys
12:21:50now we'll try to add the user interface
12:21:53uh for this uh chatbot with the help of
12:21:55streamlit. So streamlit is a python uh
12:21:58package and here you can uh create any
12:22:01kinds of user interface without using
12:22:02any HTML and CSS code. Right? So for
12:22:05this uh uh we have to install this
12:22:07streaml. So what I'm going to do in the
12:22:10same requirement file uh I think you
12:22:11know this requirement file I am using uh
12:22:15so far okay inside my langraph u
12:22:17tutorial. So here I'm going to add
12:22:20another package. I'm going to name it as
12:22:22stream.
12:22:25Okay, streamlit. You can uh specify any
12:22:28kinds of version if you want to install.
12:22:30So let's say I want to install this uh
12:22:32specific version. Then I will open up my
12:22:34terminal and I'll just write pip
12:22:36installer
12:22:43requirement.txt.
12:22:45Oh, sorry. Install spelling is not
12:22:47correct.
12:22:55Okay, as you can see installation is
12:22:57complete. Now, uh I'll come back to my
12:23:00app.py.
12:23:01Uh I'll close these other are the file.
12:23:04Now let's [clears throat] uh start
12:23:05implementing the UI. See uh your back
12:23:08end code will remain same. You don't
12:23:10need to change anything. Uh you only
12:23:12need this chatbot uh let's say uh object
12:23:16here. So which we have already imported.
12:23:18Okay. from agentic chatbot back end. We
12:23:21have already imported the chatbot. Now
12:23:24I'll just remove these are the code as
12:23:27of now. Okay. So see first of all here I
12:23:30need a streaml uh server right. Uh in
12:23:33that particular server uh I'm going to
12:23:36just add my UI functionality and uh this
12:23:39server should be run on my local host
12:23:42right and if you're using a streaml it's
12:23:44super easy to launch the server only you
12:23:46just need to import the streaml. So from
12:23:49or import
12:23:51streamllet
12:23:57as st. Okay. If you only import that and
12:24:01let's say here I will give a title only
12:24:04st. title. Let's say I'll give uh
12:24:07agentic chatbot with langraph. I have
12:24:10given this title. Now you have to
12:24:12execute this file only. Okay. Now if you
12:24:14want to execute this file uh if you just
12:24:17uh let's say write python app.py it
12:24:19won't be running that time for this you
12:24:20have to use streaml command streaml
12:24:24run
12:24:26app.py Pi. So basically you are
12:24:28launching the streaml server. Okay. Now
12:24:30if I execute
12:24:32and now see streaml server will be
12:24:34running.
12:24:38See this is the streaml server guys. And
12:24:40this is running on local host port
12:24:42number 85.
12:24:44Okay. Uh port number 8501. So by default
12:24:47streamllet runs on port number 8501 on
12:24:50the local host. See one thing you have
12:24:52observed here without writing any kinds
12:24:54of HTML and CSS. uh we got this kinds of
12:24:57user interface. Okay. So this is the
12:24:59work of streamllet and uh here you you
12:25:02can also change the settings. You can go
12:25:04to the settings. You can also um change
12:25:07the appearances. If I let's say active
12:25:10this wid mode uh this u title will be uh
12:25:15moving to the left side and let's say if
12:25:17I change the color let's say I want a
12:25:19light color. I want a dark color. Okay.
12:25:22Everything is [snorts] possible here.
12:25:24But here we'll try to uh customize uh in
12:25:26the code whatever things we need we'll
12:25:28only just try to add it. Okay, you can
12:25:30make it more beautiful for this. You can
12:25:32go to the streaml documentation and you
12:25:34can check it out. There are so many
12:25:36functionality you can use. But uh this
12:25:38front end is not like our concern. Okay.
12:25:41Uh there would be other front- end
12:25:43developer. Okay. They will take care
12:25:45about the front end and everything. uh
12:25:47but uh as a agent engineer we have to
12:25:51know the actual concept actual back end
12:25:53engineering I think this is more than
12:25:55enough okay so for this particular
12:25:57project uh whatever uh let's say uh UI
12:26:00interface we need we'll only just try to
12:26:02focus on that part see uh we already
12:26:05launched this uh streaml server and we
12:26:08set the title now here uh I need a user
12:26:11input box okay that means the chat box
12:26:13so here user will be able to pass any
12:26:16kinds of messages Okay, for this uh we
12:26:18can take this uh
12:26:21chat input.
12:26:24So if you want to get the chat input
12:26:28uh you can write this code st. chat
12:26:30input okay and you can give any kinds of
12:26:32message um because if you go to the chat
12:26:34GPT right so here you will see by
12:26:37default ask anything. So if you want to
12:26:39give this kinds of message, display
12:26:40message, you can write it here. And
12:26:42whatever message we will provide, it
12:26:44will store in the user input variable.
12:26:47Okay. So once we got the user input
12:26:49variable, if I show you, so if I let's
12:26:51say refresh now, see here, I got a chat
12:26:53chat input box. Okay. Now, whatever uh
12:26:56input you will give here, you will try
12:26:57to send it here. It would be stored
12:27:00here. Okay. Now I can also print and
12:27:02show you our S3.print
12:27:09ST
12:27:12uh dot
12:27:14text
12:27:18or let's say write
12:27:22I think there's a function called write
12:27:27now let me show you refresh
12:27:31user return none so if I let's say give
12:27:33hi now see here hi will come okay Okay,
12:27:36that's how you can take any kinds of
12:27:38user input. So after taking the user
12:27:40input guys, what I will check? I'll
12:27:42check first of all user has given any
12:27:43input or not. If uh user has given the
12:27:46input that means if user input is equal
12:27:48to is equal to true. Okay, that time
12:27:52I'll just try to
12:27:58um
12:28:00I'll just try to give a uh display
12:28:03display um actually icon. Okay. of the
12:28:06user
12:28:08and uh from this icon I'm going to take
12:28:11the user message
12:28:15H user input whatever user input we'll
12:28:17pass we'll try to pass it here. Now see
12:28:20what will happen if I refresh
12:28:22now say if I pass any text here. Now see
12:28:26uh this icon is coming because of this
12:28:29particular line chat message and this is
12:28:33user. Okay, this is the user icon and
12:28:35user has passed hi. So if you see any
12:28:37kinds of chatbot guys, you will be able
12:28:38to see people are using this kinds of
12:28:40icon to identify the human message as
12:28:42well as the AI message. Okay, that's why
12:28:44we have given this line and by default
12:28:45in streamllet it is available.
12:28:48So once I got the user input now what I
12:28:52have to do guys, I have to uh invoke the
12:28:55message to my chatbot. Okay, the chatbot
12:28:57object we have created. But before that
12:28:59we have to configure the
12:29:03uh trade right. So maybe what I can do
12:29:06here only I can prepare my trade.
12:29:11So config is equal to configurable trade
12:29:14ID. So here I have given let's say trade
12:29:17one. Okay. Trade one. You can also give
12:29:201 2 3 4. It's completely up to you.
12:29:22Okay. Even you can also write like that.
12:29:24Okay. You can also write like that. It's
12:29:26completely fine. But in in just one line
12:29:29I have added like that. Now let's try to
12:29:33invoke the message.
12:29:38Yeah. So here we'll try to invoke the
12:29:40message. Yeah. Chatbot dot invoke and
12:29:43message is equal to we are giving the
12:29:44human message. Content is equal to right
12:29:46now the user input and we're giving the
12:29:48config. Now whatever response I'm
12:29:50getting guys I will also show this
12:29:52response. So first of all I will extract
12:29:54the content from this response. So AI
12:29:57message is equal to response message
12:29:59minus one content. Okay, that means we
12:30:00are we are doing this operation. We are
12:30:03only extracting the AI message.
12:30:05And this AI message I will try to uh
12:30:08show in the console.
12:30:11For this I'm going to create another
12:30:12icon assistant icon and this message
12:30:15would be showing the assistant icon.
12:30:16Okay. Now let me show you if I refresh.
12:30:20Done. Now let's say if I give hi send.
12:30:24Now see assistant is giving hello. how I
12:30:26can assist you today. Now this is the
12:30:28assistant icon. This is the user icon.
12:30:29Okay, that's why we have given this chat
12:30:32message is uh inside that I have
12:30:34mentioned assistant. Whenever you will
12:30:36get give assistant automatically it will
12:30:37take the assistant icon and whenever you
12:30:40will give us user that time
12:30:41automatically it will take user icon.
12:30:43Okay. So that's how streamly it works
12:30:45guys. By default internally they are
12:30:46handling each and every scenario. Uh and
12:30:49uh they have given some highle
12:30:50functionality. We can use that and we
12:30:52can create our chatbot. Okay, it's
12:30:55working fine. But one issue uh in this
12:30:58particular chatbot would be let's say if
12:30:59I give another message I am bp
12:31:04now see previous message is getting
12:31:06replaced okay previous message is
12:31:08getting replaced now it is giving you
12:31:10the new one but I can't see my previous
12:31:12conversation but in chat GPT so let's
12:31:15say if I give I am buffy so I will be
12:31:19able to see my previous message as well
12:31:21okay so this kinds of thing uh if you
12:31:23want to do it that time you have to use
12:31:25something called session. Okay, session
12:31:27state inside streamllet. So streamllet
12:31:30also works in that way. U by default if
12:31:33you're not using session state what is
12:31:35happening? So every time it is
12:31:37reexecuting re-executing code from here
12:31:39and whenever it is re re-executing code
12:31:41from the beginning that time this
12:31:43message is getting erased. Okay, it is
12:31:45getting cleaned and new message is
12:31:47getting replaced here. But if you're
12:31:48using session state, session state will
12:31:50store this informations
12:31:53in memory and every time whenever it
12:31:56will execute from the beginning, it will
12:31:58not erase. Okay, still uh this
12:32:00information will be available inside
12:32:01memory and from memory it will uh able
12:32:03to load that. Okay, the same concept
12:32:05like um uh trading. Okay, we have
12:32:08learned before, right? Yeah. Now let's
12:32:11try to add this uh uh session state.
12:32:16First of all, we'll create a session
12:32:17state here.
12:32:21First of all, we'll try to create a
12:32:22session state. I'll check if message
12:32:24history is not in session state, then
12:32:26I'll try to create this message. Okay,
12:32:28it will uh create like a dictionary
12:32:31kinds of thing uh by default inside um
12:32:34this uh streamllet and this dictionary
12:32:37um it's a different type of dictionary.
12:32:39Basically, this dictionary will store
12:32:41the informations in the memory. It will
12:32:43not erase. Okay, if you execute the code
12:32:46from the beginning, still this
12:32:48dictionary data would be remaining same.
12:32:50Okay, then after that we'll load the
12:32:56conversation from the dictionary. So
12:32:58this is the code I have written loading
12:33:00the conversation story. So for message
12:33:02in state uh session state message and if
12:33:05it founds this message so it will
12:33:08basically load the role and the content.
12:33:11So role means uh whether it is the
12:33:14message for the user or AI. Okay, this
12:33:17particular role and the content.
12:33:21Now
12:33:22um here you have to write some line of
12:33:25code. Let's say whenever user is giving
12:33:27any kinds of input, this input should be
12:33:29stored in the message story. So this
12:33:32additional line you have to write here.
12:33:41This is the additional line. First add
12:33:43the message to the message story. So
12:33:44state session state message story we are
12:33:46appending it. Okay. Ro user content the
12:33:51user input. Okay. We are storing in this
12:33:53particular
12:33:55list. Once it is done now I will also do
12:33:59the same thing whenever I got the AI
12:34:00response. So after getting the AI
12:34:03response, we'll also
12:34:07save this in the message story.
12:34:11So you can see ST dos session state
12:34:13message append role. Now this role
12:34:15should be assistant. Okay, because this
12:34:16is the response from the assistant
12:34:18content is equal to AI message. Okay,
12:34:20done. Now if I come back here, refresh.
12:34:23Now if I give the message, let's say,
12:34:25hi.
12:34:27Hello. Hi. Can I assist you? My name is
12:34:31BPI.
12:34:35Um, nice to meet you. How I can assist
12:34:37you today? Okay. But this agentic
12:34:39chatbot with langraph is coming here.
12:34:42Let me see why. Okay, because you have
12:34:45to assign it at the beginning. Okay,
12:34:48because after load conversation story,
12:34:50we have assigned it. That's why it's
12:34:51coming here. So maybe at the top I will
12:34:53try to assign this one. Okay, now I
12:34:55think this will work fine. Refresh. Now
12:34:57I'll give hi.
12:35:00Fine. My name is
12:35:05BP.
12:35:07Now see nice to meet you BP. What is
12:35:10Python?
12:35:13Now see okay it's working perfectly and
12:35:16I am able to see my older message story
12:35:18as well. Okay. So yes guys we are able
12:35:21to create our um uh we are able to
12:35:25create our uh first uh chatbot workflow
12:35:29okay with the user interface even we
12:35:30have also added the uh this uh
12:35:33persistence concept that means the
12:35:34trading concept and don't worry I'm
12:35:36going to explain this trading course uh
12:35:38persistence concept in more detail in
12:35:39the next video but this is the first
12:35:41video guys I wanted to show you how we
12:35:43can create the skeleton of the agentic
12:35:45chatbot now the chatbot skeleton is
12:35:47ready okay now we have to add these are
12:35:50the functionality one by one. Okay, we
12:35:52have to add these are the functionality
12:35:53one by one. Now next I'm going to show
12:35:55you maybe the persistence concept in
12:35:58detail. Okay. After uh next uh I will
12:36:00discuss about the rag concept. How we
12:36:03can add the rag functionality. How we
12:36:04can add the tool functionality. Okay. UI
12:36:06I have already I have already shown you.
12:36:08Okay. UI um I'm not going to show you
12:36:10again. Maybe I'm going to update
12:36:12continuously update the UI as per my
12:36:14need. Then I'm also going to show you
12:36:15how we can uh add the observability tool
12:36:18like lang memory okay HITL okay each and
12:36:22everything we'll be discussing one by
12:36:23one guys okay so yeah this is the part
12:36:26one uh for this implementation guys of
12:36:28this agentic chatbot and we are able to
12:36:31build our first interface of the chatbot
12:36:34but right now it doesn't have any kinds
12:36:37of tool it doesn't have any kinds of
12:36:38rack capacity uh we'll try to add one by
12:36:41one okay uh through the entire series of
12:36:43the video and I'm going to share all of
12:36:46this code in my video description. From
12:36:48there you can get and you can execute
12:36:49inside your system guys. Okay. Now I can
12:36:52test one more thing which is the
12:36:53persistence. That means whether it is
12:36:55able to remember my name or not. So I'll
12:36:57ask what is
12:37:02my name?
12:37:07Your name is BPI as you mentioned
12:37:09earlier. Okay perfect it is able to
12:37:11remember. So guys here one more update
12:37:13we have to do inside this uh chatbot um
12:37:17which is let's say if I ask anything um
12:37:22let's say if I tell generate
12:37:26uh blog
12:37:29about
12:37:32um about let's say python now see if I
12:37:36give this uh prompt to my chatbot
12:37:40it will take some time Right? It is
12:37:42taking some time to generate this
12:37:44particular block and user has to wait uh
12:37:47till the execution. Right? But if you go
12:37:50to the chat GPT, if you give the same
12:37:52prompt, right? If you give the same
12:37:54prompt
12:37:56and if you send this message, so
12:37:59instantly you'll be able to see it will
12:38:02start generating one by one. So this is
12:38:04called streaming response. See it is
12:38:07still generating streaming response. But
12:38:10the chatbot we have created it is
12:38:12generating in one shot. Okay, we have to
12:38:14wait for the execution. Once execution
12:38:16is complete, once my generation is
12:38:18complete from the chatbot, then you will
12:38:20be able to see the content. Okay, so
12:38:22let's say if you are generating a big
12:38:24blog or any kinds of big content from
12:38:26the chatbot, that time you have to wait
12:38:28and this is not a good user experience,
12:38:30right? But in chat GPT, this is a good
12:38:32experience. Uh if you give any kinds of
12:38:34prompt, whether it is a big content, it
12:38:37doesn't matter. it will generate this
12:38:40content okay token by token uh and user
12:38:43will read it okay instantly user will be
12:38:45able to read it so this is called
12:38:47streaming response so if you want to
12:38:49implement this kinds of streaming
12:38:50response inside your chatbot as well you
12:38:53can also do it because I already told
12:38:54you I will also show you this streaming
12:38:56response as well okay uh streaming yeah
12:38:59how to add the streaming uh inside
12:39:01langraph in langraph also you can uh add
12:39:04this streaming concept now let's try to
12:39:05add it I will open up my
12:39:08So in this app.py only you have to add
12:39:12this line. So there is a like a very
12:39:16minor change you have to do. See uh
12:39:18whenever you are getting this um
12:39:22you are getting this
12:39:25uh assistant message right
12:39:28we we are invoking the response
12:39:32and after invoking the response we are
12:39:35getting the AI message. So basically
12:39:37here what is happening first of all you
12:39:39are invoking the message and you are
12:39:42waiting for the response once you got
12:39:44the response then you are showing this
12:39:46response to the streamly user interface.
12:39:49So we have to replace this code with
12:39:51this code.
12:39:55So this is the code guys
12:39:58you have to use. See here instead of
12:40:01inboxing at the very first time first of
12:40:03all what we are doing see we are
12:40:05preparing this assistant icon. After
12:40:07that there is a function inside streaml
12:40:10called write stream. Okay we are using
12:40:12this write stream function. Inside that
12:40:15uh we are using the chatbot object.
12:40:18Okay. Now instead of invoking we'll be
12:40:20using stream. Inside that you have to
12:40:22pass the uh message user input and you
12:40:26have to give the configuration. Okay. We
12:40:28already have the configuration. I need
12:40:29to pass the config only. So config is
12:40:33equal to config. Yeah. And stream mode
12:40:36is equal to message. You have to provide
12:40:37this particular uh configuration. And
12:40:41you have to run a for loop uh for
12:40:44message chunk and metadata. So whatever
12:40:46message chunk you will be getting you
12:40:48will only take the content and this
12:40:50message chunk
12:40:52uh continuously it will be showing in
12:40:55the streaml cons uh streaml user
12:40:57interface because we are using write
12:40:58stream that means every time whenever
12:41:01using chart gpt and you are generating
12:41:02something okay let's say you are
12:41:05generating something let's I'll tell
12:41:07more about it
12:41:10it is giving you the response token by
12:41:12token as you can see token by token okay
12:41:15so this kinds of token by token output
12:41:17you will be getting and you will be
12:41:19writing in the streamlit user interface.
12:41:21So this will feel like uh this is a
12:41:23streaming response that time. Okay. Then
12:41:25once everything is done then we will try
12:41:27to store this uh AI message to the
12:41:31history message we are appending like a
12:41:35same uh previously we did okay as
12:41:37assistant we are appending in the
12:41:38session state. Now let me show you. So
12:41:40if I get back if I refresh fine now
12:41:44let's say I'll give hi
12:41:49stream has no attribute right stream
12:41:55why this error is coming let me check
12:42:02maybe the version we are using it
12:42:04doesn't have this right stream so what I
12:42:06can do I can install the latest on.
12:42:22Now if I give the message again. Okay,
12:42:25still the same issue. Let me check guys.
12:42:31Okay, I have given this error to the
12:42:33chart GPT and CH GP is telling you still
12:42:35you need to upgrade this streaml. So let
12:42:37me execute this command.
12:42:42p install upgrade streamllet.
12:42:47H. So basically this will download the
12:42:49upgraded version.
12:42:55Then now we can try again.
12:43:08Now I'll give message hi.
12:43:14Now see we are getting the response. Now
12:43:16if I ask let's say generate
12:43:20uh blog
12:43:22about python.
12:43:25Now see it is streaming response like
12:43:27chatgity right now. Okay. And this is
12:43:30more interesting and more
12:43:33uh good experience to the user. Okay. So
12:43:36that uh this kinds of scenario you also
12:43:38you also need to take care whenever you
12:43:40are creating this kinds of uh agentic
12:43:43system. Okay. Or any kinds of simple
12:43:44chatbot whatever you are creating this
12:43:46kinds of thing you have to take care and
Why Persistence is Required in LangGraph
12:43:49a lang uh graph is having this kinds of
12:43:52concept integrated. Okay. You can easily
12:43:54implement this thing in the lang graph.
12:43:57Okay. Okay. So we have also se seen how
12:43:59we can add the streaming response inside
12:44:02our application. Okay. Now this
12:44:04application looks more cool. Now in the
12:44:06next video guys I'm going to discuss
12:44:08about this uh persistence concept in
12:44:10more detail. We'll try to see uh what is
12:44:14this persistence is all about. We have
12:44:16already understood in this video as a
12:44:18high level but uh in detail I'll try to
12:44:20discuss in the next video. So yeah guys
12:44:22this is all about from this uh first
12:44:24part of this implementation. So guys as
12:44:27you can see this is the definition of
12:44:29persistence and uh in my previous uh
12:44:31video that means in the part one maybe I
12:44:34already given you the highle overview on
12:44:36top of this persistence like what is
12:44:38persistence and how we can integrate
12:44:40with our chatbot I already told you
12:44:42about but let's try to understand the
12:44:44detailed definition of persistence as
12:44:46you can see persistence in langraph is a
12:44:48built-in layer that automatically saves
12:44:50and restores the state of your agent or
12:44:54graph workflow over time. Okay. It works
12:44:58by uh using a checkpointer to
12:45:00automatically capture snapshot of the
12:45:02graphs state at every step organizing
12:45:06them into unique and retrievable traits.
12:45:10Okay. So I think uh by the definition
12:45:12itself you can understand uh what I'm
12:45:14trying to say here because if you have
12:45:16already completed the part one uh of
12:45:18this uh uh chatbot implementation I
12:45:20think you know that uh see persistence
12:45:23why it is required. First of all, let's
12:45:25try to understand from the beginning.
12:45:28Um, I think you know uh inside aentic
12:45:31application first of all we'll have a
12:45:33goal, right? So let's say yeah let me
12:45:35write down.
12:45:38Yeah. So see in any kinds of agentic
12:45:41application first of all definitely
12:45:42we'll have a goal. Let's say you have a
12:45:46problem statement right? You want to
12:45:47let's say here we are creating a aentic
12:45:49chatbot. So definitely this is our goal.
12:45:51Now this goal should be divided into
12:45:53multiple tasks. So first of all what
12:45:55we'll do guys we'll try to divide this
12:45:57goal to the multiple task. Let's say
12:45:59this is task one. Okay this is task two
12:46:05and so on. That's how we'll be breaking
12:46:07down different different task and
12:46:09whenever we'll be using lang graph right
12:46:11whenever we'll be using lang graph
12:46:15because so far we are learning about
12:46:16lang graph. So in lang graph to define
12:46:19this particular task we use something
12:46:21called nodes right each of the task will
12:46:23become a nodes let's say this is our
12:46:25first nodes this is our second nodes
12:46:27okay and so on so that means first of
12:46:30all we'll be having a goal and we'll
12:46:33define a task from this particular goal
12:46:35like u step-by-step task and this
12:46:38particular task would be our nodes okay
12:46:40inside the graph because this is the
12:46:42entire graph as you can see this is the
12:46:44entire graph
12:46:48entire graph in line graph, right? This
12:46:50is the entire graph in line graph and
12:46:52these are the nodes. Okay. And you can
12:46:53see this is the age connection.
12:46:56Uh this is the age connection and this
12:46:58start node is nothing but this is the
12:47:00input. So here we pass our initial state
12:47:04initial input right and this input will
12:47:06go through this edges. This edge is
12:47:09nothing but it's a connection. This edge
12:47:11defines basically after which node what
12:47:14node should be executed. Okay, because
12:47:16of this particular arrow symbol. As you
12:47:19can see this arrow symbol defines okay
12:47:20after start nodes node one would be
12:47:23executed. After node one node two would
12:47:25be executed like that right. So this is
12:47:27called ages. This is called ages and
12:47:30this is called nodes. We already know
12:47:32about this is called nodes right.
12:47:35Okay. Then this particular task will go
12:47:38through all of the nodes. Then at the
12:47:40last we use a end nodes. What this end
12:47:43nodes will do it will first uh basically
12:47:45uh stop the graph execution. Okay. Let's
12:47:47say whenever we'll give any kinds of
12:47:49input and whenever it will reach to this
12:47:52particular end it will stop the graph
12:47:55execution and you will be able to see
12:47:56the final okay final result here. Final
12:48:01result here and we have already seen
12:48:02this particular things in the practical
12:48:04implementation as well. I think this is
12:48:06pretty much clear to you right now. See
12:48:09the main things we have to understand uh
12:48:12whenever we are defining any kinds of
12:48:14graph right whenever we are defining any
12:48:16kinds of graph and if I want to execute
12:48:18this graph in lang graph we have to
12:48:20provide something called state right we
12:48:22have to provide something called state I
12:48:24think you know that without state we
12:48:25can't execute any kinds of graph and
12:48:27what is state is nothing but it's kinds
12:48:30of uh it's kinds of variable we are
12:48:32passing right it's kind of some of the
12:48:34data we are passing to the graph okay
12:48:37let's say in this particular chatbot
12:48:39what is should what should be the state
12:48:41state should be the message let's say
12:48:43the message user is giving okay and our
12:48:46AI bot is replying so this is the
12:48:48message this is the information so every
12:48:49time what will happen this state will go
12:48:51to the every nodes okay every nodes and
12:48:54this nodes whatever uh output will
12:48:56return it will basically update in this
12:48:57particular variable okay this is called
12:48:59state but what happens if we are giving
12:49:02this particular state to the um graph so
12:49:05let's say we are passing the state to
12:49:07the start node right Then start node
12:49:09will pass to the node one then node two
12:49:11then n then end. So whenever it will go
12:49:13to the end that means this graph
12:49:16execution is getting over and whatever
12:49:19state whatever state data you are having
12:49:21here it will be basically erased that
12:49:23time. Okay it will be basically erased
12:49:25that time. Then whenever you will be
12:49:27running second time you won't be able to
12:49:29get the previous information whatever uh
12:49:32you got in the first execution right
12:49:34inside the state. So this is the main
12:49:35problem. Then what we introduce we
12:49:37introduce something called persistence
12:49:39right we introduce something called
12:49:42persistence. So in persistence what we
12:49:45usually do here we basically save the
12:49:49entire state okay inside a storage
12:49:51service either you can use your uh RAM
12:49:54okay we call it as a memory saver either
12:49:56you can use any kinds of database that
12:49:58means two kinds of storage service you
12:50:00can use either you can use your RAM that
12:50:03means memory
12:50:05okay your computer memory either you can
12:50:08use any kinds of database here okay
12:50:11database is the permanent one. Okay,
12:50:14perma
12:50:16net one and this is the temporary one.
12:50:20Temporary one. Okay, temporary means if
12:50:22you restart your application that time
12:50:24this data would be erased. But in
12:50:26database if you restart your application
12:50:28okay it doesn't matter you if you
12:50:30restart if if your uh uh let's say
12:50:33system crashes it doesn't matter your
12:50:35data will be permanent okay you can load
12:50:37anytime this kinds of data that okay
12:50:40[snorts] that means uh inside persistent
12:50:43whatever state snapshot we are having
12:50:45okay we try to store inside a storage
12:50:47service that's why in in the definition
12:50:49itself you can see persistence in lang
12:50:51graph is a built-in layer that
12:50:52automatically save okay and restore That
12:50:55means you can restore this particular uh
12:50:57state anytime okay from the storage
12:50:59service the state of your agents okay
12:51:02the state of your agents or graph
12:51:04workflow over time okay over time means
12:51:07because it is every every time it is
12:51:09capturing your snapshot it is um let's
12:51:12say this persistence every time it will
12:51:14save the informations in the u uh
12:51:17storage service let's say after start
12:51:18whatever uh state uh update you got
12:51:21right this particular information would
12:51:23be saved after node one execution
12:51:25Whatever uh state would be saved, it
12:51:27will be basically saved in the database
12:51:29or your local storage. Okay, that's how
12:51:31every step okay every step it will be
12:51:35saving the information of your state.
12:51:37That's why we call it as a overtime here
12:51:39and it works by using a checkpointer to
12:51:42automatically capture the snapshot of
12:51:44the graph state at the every step. Okay,
12:51:46I already told you and in my previous
12:51:48implementation I used something called
12:51:49checkpo pointer. I think you know that
12:51:51again I will give you the idea. Okay,
12:51:52how checkpoint pointer works and uh each
12:51:54and everything I'll give you. Then one
12:51:56uh another thing we learned this
12:51:57organizing them into unique and uh
12:51:59retrievable trades. Okay, we'll be also
12:52:01learning about the trades. Trade means
12:52:03you can create multiple trades. Let's
12:52:05say uh trade one you can do some kinds
12:52:08of conversation in trade two you can do
12:52:10another uh kinds of conversation. Okay.
12:52:12So both conversation would be different
12:52:14and you can't use trade one information
12:52:16in trade two and trade two information
12:52:19in trade one. Okay. we can also make
12:52:21this particular difference. Okay, I hope
12:52:22you got it guys. Now that's how your
12:52:25persistence comes into picture and this
12:52:27is very much important whenever you are
12:52:28creating this kinds of agentic AI
12:52:30application otherwise what will happen
12:52:32your application may not get this state
12:52:35uh data okay over time whenever you are
12:52:39creating this kinds of uh agentic
12:52:41chatbot or any other let's say advanced
12:52:44application uh which is required your
12:52:46older data as well okay just try to
12:52:48think about whenever we are creating
12:52:49this agentic chatbot definitely I need
12:52:51my previous response let's say I have
12:52:53given the input my name is BP right and
12:52:56second time if I'm asking what is my
12:52:58name so definitely it should remember
12:52:59that particular informations right
12:53:01whatever it has updated uh in the state
12:53:04okay but if it is getting end right and
12:53:06if the final result is getting erased
12:53:09okay of this state that time definitely
12:53:11your uh definitely your agent won't be
12:53:14able to give you the response but if
12:53:15you're using the persistence concept and
12:53:18if you're capturing this state okay
12:53:19inside a memory okay if you're saving
12:53:21this inside a memory so anytime time we
12:53:23can load this and we can pass again to
12:53:26the graph and graph will be able to
12:53:27recall the previous information and that
12:53:29that will be able to give me the result.
12:53:31Let's see your name is BP. So this is
12:53:33the main fun here. Okay, I hope you
12:53:35clear guys. So guys now let's try to
12:53:37understand the specialtity of
12:53:39persistence. Uh see persistence
12:53:42uh is having some kinds of specialtity.
12:53:45Um see I told you uh whenever we define
12:53:49any kinds of state right and uh uh
12:53:52whenever we execute a graph so this
12:53:54state will go to the every nodes right
12:53:56every nodes it will go and uh all the
12:53:59nodes will be uh updating something in
12:54:02the state okay and we'll be getting a
12:54:04final result from here so it doesn't
12:54:07mean this persistence will only capture
12:54:09the final updated state information
12:54:12instead of that it will be able able to
12:54:16uh store your intermediate uh let's say
12:54:19data intermediate data means see what
12:54:22happens whenever we define any kinds of
12:54:24state right let's try to take example
12:54:27let's say state so let's say here I have
12:54:30taken a state um the state name is let's
12:54:32say I will take name I want to only save
12:54:35the name information here okay name
12:54:38let's say I have only taken one variable
12:54:40so what will happen this state will go
12:54:42to the every node first of all it will
12:54:44go to the start node. Okay. After going
12:54:47to the start node, uh this uh uh uh your
12:54:51graph would be initialized, your graph
12:54:53would be executed. So through this
12:54:55edges, it will reach to the node one.
12:54:57Okay. Let's say in node one, we are
12:54:59doing some kinds of update. That means
12:55:00node one is updating this name.
12:55:04Let's say initially it was uh let's say
12:55:06initially I have given a let me take
12:55:09this color. Initially let's say the name
12:55:11was A. Okay. Now what will do? This node
12:55:14one will try to update this particular
12:55:16name. Let's say it will be uh updating
12:55:20B. Okay. It will update B. But whenever
12:55:23we pass this state okay initially it was
12:55:26name A. Okay. But whenever we pass
12:55:29through this node one uh this uh was
12:55:32changed to to the B. Right. So the
12:55:35execution you can see here node uh start
12:55:37to node one uh that means through this
12:55:40execution okay this is called super
12:55:44super step okay this is called super
12:55:47step so what is super step basically to
12:55:49execute the entire nodes okay to execute
12:55:52the entire graph uh whatever super step
12:55:55we perform okay let's say if I want to
12:55:58execute the entire graph definitely I
12:56:00have to execute node one node two okay
12:56:02then it will go to uh go to this end
12:56:04then your entire graph would be
12:56:06executed. Then you can see multiple age
12:56:08connection is there and each of the age
12:56:10connection is a super step here. Okay,
12:56:12that means in every super step there
12:56:14would be some kinds of update in the
12:56:16state and your persistence would be able
12:56:18to capture this informations in the uh
12:56:21stories. Okay, that means let's say
12:56:24after node one it will go to the node
12:56:26two let's say node two will try to
12:56:28replace this uh B to this C. Okay. And
12:56:32whenever it will reach to the end and
12:56:34here you will get the final name MC.
12:56:37Right. But it's not like that. It is
12:56:39replacing all of the previous
12:56:41information. Still the previous
12:56:42information is available. Okay. Still
12:56:44the previous information is available.
12:56:46Okay. So this information I we call it
12:56:48as a intermediate
12:56:51intermediate.
12:56:55Okay. Intermediate state.
12:56:58Okay. We call it as intermediate state.
12:57:00And this is called final
12:57:03state. Okay, final state. That means the
12:57:06specialty of persistence is it will
12:57:08capture your intermediate state. State
12:57:10state as well and the final state as
12:57:12well. Okay, it's not like that. Every
12:57:13time you'll get the final state
12:57:15definitely intermediate state would be
12:57:17available uh after each and every super
12:57:20step execution. Okay. Let's say in
12:57:23future uh your application will crash
12:57:25here. Let's say node one it will crash
12:57:27or let's say node two it will crash.
12:57:29Okay, that time it's not necessary.
12:57:32Whenever you will restart your
12:57:33application, it will execute from the
12:57:35beginning. Okay, it's not like that
12:57:36because it has the intermediate state
12:57:38and it has already has the information.
12:57:41Okay, so what it will do? It will re
12:57:44able to resume. Okay, it will able to
12:57:45resume your application from node one or
12:57:48node two because it has captured the
12:57:50intermediate state. Okay, so this is
12:57:52called actually fault tolerance. I
12:57:54already told you about this, right?
12:57:56fault tolerance in my introductory
12:58:00session I already told you about fault
12:58:02tolerance right that means whenever your
12:58:04application get crashes it not it's not
12:58:07necessary to re-execute application from
12:58:09the beginning okay you can execute your
12:58:11application wherever your application
12:58:13got crashes let's say this is crash
12:58:15point okay or let's say this is crash
12:58:17point wherever your crash point happens
12:58:20it will resume the application from here
12:58:22itself okay I hope you get it so this is
12:58:25the specialty of This persistence uh if
12:58:28you see these kinds of question in the
12:58:30interview what is the specialty of
12:58:32persistence that time you can tell it
12:58:34can also save the information uh of the
12:58:37intermediate state along with the final
12:58:39state okay I hope you get it and if you
12:58:42go to the uh uh real time let's say
12:58:44application let's say if I go to the
12:58:45chart GPT okay chart GPT also using this
12:58:48kinds of persistence concept so in chat
12:58:50GPT what you can do you can either
12:58:52create a new conversation okay new chat
12:58:55either you can continue with your old
12:58:57chat, right? Either you can continue
12:58:58with your old chat. Let's say if I want
12:59:00to continue some kinds of old chat, I
12:59:03can continue here. Let's say this is my
12:59:05old chat as you can see, right? I can
12:59:08continue here. So, let's say what is
12:59:13the final
12:59:15code?
12:59:17See, it will basically uh reusing my
12:59:21older state.
12:59:23See and it is continuing the
12:59:26conversation. Okay. And even I can also
12:59:29start a new conversation here. Okay. If
12:59:31I start a new conversation that means my
12:59:33new state would be created and one by
12:59:36one this uh super step will be executed
12:59:39and each and every okay step this
12:59:42snapshot would be captured. It will be
12:59:43updated in the state. Okay. So without
12:59:46this state you can't create this kinds
12:59:48of application. Definitely uh for this
12:59:51kinds of advanced agentic chatbot you
12:59:53need this state and this state is
12:59:55already sorry um uh you need this kinds
12:59:58of persistence concept and this
12:59:59persistence is already okay integrated
13:00:02inside lang graph. Okay and with the
13:00:04help of that you can handle this kinds
13:00:06of fall tolerance in a very easiest
13:00:07manner. Okay, I hope you got it guys.
13:00:10I've given you the example with the real
13:00:12world example as well like chart GPT. So
13:00:14charge GPS are also using this kinds of
13:00:18persistence in the back end. So in
13:00:20charge GPT what is happening whatever
13:00:22conversation you are doing okay whatever
13:00:25conversation you are doing uh this kinds
13:00:27of information is getting saved uh okay
13:00:31uh in the state and they're using
13:00:33persistence concept here definitely and
13:00:36they're storing this kinds of
13:00:37information um in a database okay
13:00:39they're not using any kinds of local uh
13:00:42storage service instead of that they're
13:00:43using some kinds of database and from
13:00:45the database itself this information is
13:00:47getting okay fetched okay Whenever you
13:00:50are opening any kinds of old
13:00:51conversation, you will be able to see
13:00:53whatever uh message you have done here.
13:00:55So the this information is coming from
13:00:57the database. Okay, I hope you clear
13:00:59guys. Now guys, this definition would be
13:01:02pretty much clear uh like uh what is
13:01:04happening inside persistence. Uh now
13:01:07let's try to understand another uh
13:01:09concept here. As you can see, it works
13:01:10by using a checkp pointer to
13:01:12automatically capture the snapshot of
13:01:14the uh graph states. Okay, at every
13:01:17step. Now let's try to understand what
13:01:19is this uh checkpointer exactly. So here
13:01:22I have taken another example guys. As
13:01:23you can see checkpointer is uh in inside
13:01:26of persistence.
13:01:28See checkpointer is nothing but uh you
13:01:32can consider this checkpointer is kinds
13:01:34of uh it's kinds of tracking uh tracking
13:01:38functionality. Tracking functionality
13:01:39means each and every super step whenever
13:01:42it is executing and whatever update we
13:01:45are making inside the state that time
13:01:47checkpointer will be able to capture
13:01:50those informations in the uh state right
13:01:53in the state means it will be able to
13:01:55capture those information and it will
13:01:56save inside the uh persistence memory
13:01:59okay so let's try to understand this
13:02:01concept in detail so what I'm going to
13:02:03do I'm going to open up my blackboard
13:02:04and here let me make you understand see
13:02:07what I told Okay. Uh whenever we uh give
13:02:10any kinds of state to a graph. Okay. Uh
13:02:14so what will happen? It will execute the
13:02:15nodes one by one. As you can see we are
13:02:18having lots of nodes here. And uh you
13:02:21can see the age connection. This is the
13:02:22age connection. And whenever you are
13:02:24doing this kinds of age uh age
13:02:26connection uh and age execution that
13:02:28means after start to uh sorry um from
13:02:31start to node one here we are get doing
13:02:34a execution and this execution we call
13:02:36it as a super step right I already told
13:02:38you about super step
13:02:41right. So when whenever you are having
13:02:43this kinds of super step okay whenever
13:02:46you are having this kinds of super state
13:02:48uh after that you will basically set a
13:02:51checkpoint okay set a checkpoint that
13:02:53means whenever we are passing a initial
13:02:55state to the start that time one
13:02:57checkpoint would be available here
13:02:59checkpoint
13:03:01uh checkpoint one okay let's say this is
13:03:03our checkpoint one then [snorts]
13:03:06u after doing this uh superstep
13:03:08execution there would be again a update
13:03:10so there would be another Checkpoint
13:03:13let's say this is checkpoint two and you
13:03:16here you are having multiple nodes okay
13:03:18as parallel so this is one execution
13:03:21this is another execution this is
13:03:22another execution we combine all of the
13:03:24execution and we will be calling as a
13:03:26another super step another
13:03:29super step
13:03:37right and uh after this super step there
13:03:40would be another checkpoint and
13:03:44checkpoint three. Okay. And at the last
13:03:48uh because here we are doing another
13:03:49superstep execution and I'm getting the
13:03:51final response. Okay. Here also another
13:03:53checkpoint would be available.
13:03:55Checkpoint let's say four. Okay. And
13:03:57every checkpoint will capture the
13:03:59updated state. Let's say after this
13:04:01start to node one whatever update will
13:04:03be happening in this state this
13:04:05checkpointer will capture that
13:04:06information. It will save in the
13:04:08persistence memory.
13:04:11Okay, persistence
13:04:13memory it will save either you are using
13:04:15local local storage that means your RAM
13:04:18either you you are using any kinds of
13:04:20database okay database it will store
13:04:24there okay whenever it is uh storing
13:04:28that means it is not replacing the value
13:04:30instead of that it is merging that means
13:04:32it is adding the information
13:04:34adding the information and we call it as
13:04:36a reducer concept I think you know that
13:04:39reducer That means whenever we are using
13:04:41this kinds of persistence concept
13:04:43definitely we have to use the reducer
13:04:45okay reducer concept we'll be
13:04:47continuously adding the informations
13:04:49instead of replacing the old one okay I
13:04:51hope you get it guys okay then uh this
13:04:54kinds of uh checkpoint we have in every
13:04:58uh super step and whenever any kinds of
13:05:00update would be happen in the state it
13:05:02will capture the information and you'll
13:05:04be getting a final snapshot final let's
13:05:06say state at the last checkpoint and
13:05:08this will like store at the last. Okay,
13:05:10but you will be able to see the previous
13:05:12update as well in the state. Okay, this
13:05:15is how this particular checkp pointer is
13:05:17working.
13:05:19I hope you got it right. To get the like
13:05:23updated data in the state, we use this
13:05:25kinds of checkpointter and the
13:05:26checkpointer work is to capture this
13:05:28information in the storage service. This
13:05:30is the work of a checkpointer. That's
13:05:32why in the definition itself I think you
13:05:34see the definition in the definition
13:05:36itself it is telling it works by using a
13:05:38checkpoint to automatically capture
13:05:40snapshot of a graph state at every step.
13:05:42Okay. Because we're using every step
13:05:44execution here. I hope you get it guys.
13:05:47Okay. Now let's try to understand this
13:05:49checkpointer concept through an example.
13:05:51Let's say I'll take the same graph
13:05:53execution here. So let's say here I will
13:05:56define a state.
13:05:58Let's say
13:06:01I'll define a state here. Uh the state
13:06:04variable I'll take number.
13:06:07Okay. Number. So this number will be a
13:06:11list of integer.
13:06:13List of
13:06:15integer. Okay. And here we are using add
13:06:21operation. Why we are using add
13:06:22operation? Because we are using reducer
13:06:24concept. I think you know that. Okay.
13:06:26And uh this uh this number would be a
13:06:29list list of numbers and all of the
13:06:31number would be integer. Okay. So let's
13:06:34say initially whenever I will pass this
13:06:36number
13:06:38pass this number to the uh graph
13:06:41initially let's say the value is one.
13:06:43Okay. The value is one. So I told you
13:06:47each and every
13:06:49uh super step will be having a checkp
13:06:51pointer. Let's say I can define all of
13:06:54the checkpointer definitely uh at the
13:06:57first node there would be a
13:06:58checkpointter let's say CP1
13:07:02then here also we'll be having a
13:07:03checkpointer CP2 here also we'll be
13:07:06having a checkpointer CP 3 and here we
13:07:09are having let's say CP 4 we are having
13:07:13all the checkp pointer so what will
13:07:15happen
13:07:17uh yeah so whenever it will execute it
13:07:21will go to the node one. Okay, let's say
13:07:23node one update um update this value.
13:07:27Let's say this number, it will update uh
13:07:30let's say two.
13:07:32Okay, two. It will return two. So what
13:07:35will happen? Um now the number will
13:07:37become like that.
13:07:40So in this list
13:07:44list so initially the number was I'll
13:07:47denote with n. N means number. Initially
13:07:50it was one right one and now it has
13:07:53updated uh two. So instead of replacing
13:07:56the previous one it will add the number
13:07:58at the last. Okay this is the concept of
13:08:01the reducer. Okay and this is called
13:08:03your intermediate state. Now we got the
13:08:06intermediate state. Now it will go to
13:08:08the next node execution and here also
13:08:11you are having a check pointer. Now
13:08:13let's say this generates uh single
13:08:15number. Let's say it will generate
13:08:17three. This will generate four and this
13:08:19will generate five. So what will happen
13:08:21again? The number should be like that 1
13:08:252 then this uh three will come four will
13:08:29come and five will come. So three
13:08:33four and five. Okay. Then it will save
13:08:36this information to the memory. Okay.
13:08:40Every time it will save this information
13:08:41to the memory because checkp pointer is
13:08:43saving the information to the memory.
13:08:45either you are using local memory or any
13:08:46kinds of database. Okay, it will try to
13:08:48save that particular state. Then it will
13:08:50go to the last one that mean checkp
13:08:52pointer um checkpo pointer four uh let's
13:08:56say uh this returns the final result and
13:08:58here you haven't done any kinds of
13:09:01update. So what would be the final okay
13:09:03final number final number should be 1 2
13:09:073 4 and five then this final state would
13:09:11be also saved okay in the database.
13:09:13Okay, that's how we are not only getting
13:09:16the updated state and instead of that we
13:09:18are also getting the intermediate state.
13:09:20How? Because of the checkp pointer.
13:09:22Okay, now I think this part is clear to
13:09:24all of you guys. So guys, we have
13:09:26understood about this uh persistence. Uh
13:09:29we have understood the persistence then
13:09:31then we have also understood what is
13:09:33checkpointer and how it works. Okay. Now
13:09:36let's try to understand another
13:09:37important concept as you can see
13:09:39organizing them into unique and uh
13:09:42retrievable traits. Okay. Now let's try
13:09:44to understand what is this trades. Okay.
13:09:46Trades is also a concept of persistence.
13:09:49So in my previous uh uh part guys that
13:09:52mean in the part one I already told you
13:09:54about the trades right? We added the
13:09:56trades uh with the help of trades
13:09:58actually we can separate out each and
13:10:00every let's say chat. Now let's say if
13:10:04you are doing um chat in trade one that
13:10:08means in trade two you won't be able to
13:10:10see that particular chat or in trade
13:10:13whatever uh chat you are doing in trade
13:10:15one you won't be able to see in inside
13:10:17trade two. So this kinds of thing I
13:10:19think I already showed you if you
13:10:20haven't checked that please try to check
13:10:21check my previous part guys. So here
13:10:24let's try to understand this trading
13:10:26concept as you can see trades in part
13:10:27persistence we have already taken an
13:10:29example here. So I'm going to open it
13:10:31up. So see here what is happening let's
13:10:35say here we have taken two trades let's
13:10:38say this is trade
13:10:41this is trade one and this is trade
13:10:45sorry this would be trade
13:10:51trade one and this is
13:10:54trade two okay now in trade one as you
13:10:57can see I have um I have updated some
13:11:01kinds of state okay so here would be one
13:11:03actually I missed out. Yeah. So you can
13:11:05see um let's say here we got one then
13:11:07after node two execution we got one two
13:11:09okay and so on like I already showed you
13:11:12this example before right yeah now I
13:11:15have taken the same example but I
13:11:17updated let's say another state number
13:11:20let's say here I started from six then
13:11:22node after node one execution I got 6 7
13:11:26then 6 7 8 9 10 okay then 6 7 8 9 10
13:11:29this is the final number so see what is
13:11:31happening here although I am executing
13:11:34ing this graph two time okay two times
13:11:37but in a different trades so for the
13:11:40first time I have given a separate
13:11:42number and for the second time I have
13:11:45given another number so it is not
13:11:48replacing the previous information as
13:11:50you can see previous information is
13:11:51remaining same because it is running in
13:11:53a different trade and here trade ID is
13:11:55different it is also running the same
13:11:58graph but it is running in the another
13:12:00trade okay I hope you got this concept
13:12:03so if I uh give give you one real time
13:12:05demo guys if I go to the chart GPT. So
13:12:07in charge GPT also I think you
13:12:09understand let's say whenever we do
13:12:12chart operation right uh it will
13:12:14basically creates a trades let's say
13:12:16this is a trades this is another trades
13:12:18okay that's why we are having different
13:12:19different trades
13:12:21okay let's say if I show you let's say
13:12:24this is the different different trades
13:12:25let's say this is another trades
13:12:27okay this is another traits
13:12:31that means this information you won't be
13:12:34able to see in this particular trades
13:12:37Right? And whatever information you are
13:12:39having, you won't be able to see in this
13:12:41particular trades. Right? These two
13:12:44trades are completely different. And
13:12:46whenever you are creating this kinds of
13:12:48real time agentic chatbot or agentic
13:12:51application definitely you have to take
13:12:53care this particular traits otherwise
13:12:55what will happen it will be getting the
13:12:58previous context as well. Okay. and I
13:13:01will be able to separate out my chat
13:13:04whenever let's say this inform uh this
13:13:07application uh is using by multiple
13:13:09person or let's say by me only I won't
13:13:12be able to uh separate out my chat
13:13:15informations okay everything will be
13:13:18combining in one particular trades and
13:13:19this is not good right so that's why we
13:13:22create this particular trades and now we
13:13:24can also create another trades by click
13:13:26on new chart now if you do any kinds of
13:13:28conversation see it will create another
13:13:30trades automatically here. See, new
13:13:33chart has created and this is another
13:13:34traits. Okay. So, we'll also able to see
13:13:38uh how we can add this kinds of uh
13:13:41trading uh how we can add this kinds of
13:13:43let's say uh realtime trading inside our
13:13:46chatbot also. Although I have shown you
13:13:48the trades but I hardcoded the trade one
13:13:50and trade two right u in my previous
13:13:53demo but I will show you okay whenever
13:13:55you are creating this kinds of chatbot
13:13:56uh in a user interface also how we can
13:13:59add uh like chart GPT okay these kinds
13:14:01of trading I will also able to show you
13:14:03so now I think you understood about the
13:14:05trades guys what is trades exactly
13:14:07trades is basically uh it stores the
13:14:11informations with a trade ID let's say
13:14:13whenever you are using any kinds of
13:14:14database or your local storage it
13:14:17doesn't matter let's say whenever you
13:14:18are using local storage that means your
13:14:20RAM that time what is happening in the
13:14:22RAM only it is creating a separate ID
13:14:26trade ID okay that means it is taking a
13:14:28separate space inside a RAM and for
13:14:32trade two it is taking another separate
13:14:34space in the RAM although it is
13:14:35executing the same graph but it is
13:14:37executing in a two different place but
13:14:39in database what is happening I know you
13:14:41know that in database we create a table
13:14:43right inside a table we can create a
13:14:47another column called uh trade id okay
13:14:50trade ID let's say if trade ID one all
13:14:53of the information would be saved about
13:14:55the trade ID in this particular row
13:14:57itself let's see if trade is equal to
13:14:58two all of this information would be
13:15:00saved related trade two here so whenever
13:15:02I need trade one I will try to fetch the
13:15:04trade one whenever I need trade two I
13:15:06will fetch the trade two okay that's how
13:15:08the things work actually basically it
13:15:09saves the same information but in a
13:15:11different different threads to separate
13:15:13out my each of the that's a state or
13:15:15each of the charts. Okay, I hope you get
13:15:17it guys. So guys, we have understood the
13:15:20theoretical concept of persistence in
13:15:23line graph. Now let's try to see the
13:15:25code example. Okay, for this I will
13:15:28create a simple sequential workflow
13:15:30here. So this is the graph I have taken.
13:15:32As you can see this is the this is our
13:15:33workflow. So here basically we'll try to
13:15:36um see um um see example. In this
13:15:40example, first of all, we'll try to
13:15:42generate a joke of a topic. Let's say
13:15:46here we'll pass a topic. Let's say we
13:15:47will pass any kinds of topic. Let's say
13:15:50I passed football. So, first of all,
13:15:51what will happen? Uh here we'll create a
13:15:54node and this node will try to generate
13:15:56a joke on top of that topic. Let's say
13:15:58it will generate a joke on football.
13:16:00Then after that, we'll pass this uh joke
13:16:02to another nodes called gen um uh exp.
13:16:07Basically uh this will uh generate the
13:16:10explanation of that particular joke.
13:16:12Let's say the joke we have generated we
13:16:14want to generate the explanation of that
13:16:16particular joke. Then this um workflow
13:16:18will be end. And to make this uh graph
13:16:20guys we need a state. So I already
13:16:22prepared the state. As you can see we
13:16:23named it a joke state. We are inheriting
13:16:26with the type dict and uh we have taken
13:16:28the state. First of all we need a topic.
13:16:31Then whatever joke it will generate joke
13:16:33would be there. Then explanation. Okay
13:16:35that means the three variable we have
13:16:36taken. I think this is pretty much
13:16:37clear. So I have already written the
13:16:40code. As you can see this is the code.
13:16:42So first of all let's import all of the
13:16:43necessary library. We are importing
13:16:46state graph start type d chat openi load
13:16:49env only the new things. I have imported
13:16:51this inmemory saber from lang graph
13:16:54checkpoint dot memory in memory saber.
13:16:56Okay. So this is what your uh
13:16:58persistence uh like uh persistence
13:17:02memory that means the checkp pointer
13:17:04like where you want to save this state.
13:17:06So here we're using inmemory. Inmemory
13:17:08means it will save the information
13:17:09inside your RAM. You can also use any
13:17:11kinds of database. We'll also see
13:17:12database in future but as of now just to
13:17:14show you the demo, we'll be using our
13:17:16RAM. So let's import all of the
13:17:18necessary library. Okay. Then we'll try
13:17:20to load the environment variable because
13:17:22there I have my open API key. I already
13:17:24set my open API key here. Then after
13:17:26that we'll try to define a large
13:17:28language model. Then we'll define the
13:17:30state. The same state I showed you here.
13:17:33We are defining the state. Then we'll be
13:17:35writing the nodes. Okay. So first of all
13:17:38we have created the graph as you can
13:17:40see. Then we are adding the nodes. First
13:17:42node is generate joke. Second node is uh
13:17:45generate explanation. So generate nodes
13:17:47sorry generate jokes and generate
13:17:49explanation. So these two function I
13:17:50have to write separately because this is
13:17:52going to be my node. So this is the
13:17:54generate joke uh nodes. As you can see
13:17:56it will take this state and it will
13:17:58generate the joke and it will update
13:18:00that joke state and this particular uh
13:18:03nodes will try to generate the
13:18:04explanation. Here we have given the
13:18:06prompt. So it will take the joke from
13:18:07this state and it will generate the
13:18:09explanation and it will update the
13:18:10explanation. Okay. So let's try to
13:18:12define all of them.
13:18:14H so after that we are uh defining the
13:18:17graph. So as you can see we are adding
13:18:19the nodes. After that we have to do the
13:18:21edge connection. As you can see as
13:18:22connection start to gen start to
13:18:25generate joke then generate joke to
13:18:27generate explanation generate joke to
13:18:29generate explanation then generate
13:18:31explanation to end generate explanation
13:18:33to end. This is the connection. Now if
13:18:35you're using this persistence concept
13:18:37you have to define a checkpointer. So
13:18:39here we are defining the checkpoint and
13:18:40we are defining the inmemory server and
13:18:43if you're using any kinds of database
13:18:44you have to define the database uh class
13:18:46here. This will become my checkpointter.
13:18:48Now we'll whenever we'll try to compile
13:18:50the graph we'll pass this particular
13:18:52checkp pointer okay uh in this
13:18:55particular parameter. Now basically by
13:18:57this code you are telling your line
13:18:59graph um graph to use this persistence
13:19:02concept that means whatever state you
13:19:05are having okay whatever state update it
13:19:07will do whether it's intermediate or
13:19:09final it will try to save all of the
13:19:12information in this particular memory
13:19:14okay I hope you get it now let's try to
13:19:16compile the graph done now let me show
13:19:19you uh how we can execute this workflow
13:19:21to execute this workflow you need to
13:19:24define a configuration okay you need to
13:19:26define a configuration and in the
13:19:28configuration you have to define the
13:19:29trades. I already told you okay trades
13:19:31is important whenever you are using
13:19:32persistent concept definitely you have
13:19:34to pass the trade and each and every
13:19:37trade will store your informations in a
13:19:40separate uh separate space in the memory
13:19:42okay if you're using a memory it will
13:19:44use a separate space if you're using a
13:19:45database it will use this particular
13:19:47trade ID to store those information
13:19:49basically in trade one whatever
13:19:51conversation you are doing you won't be
13:19:53able to see in trade two or in trade two
13:19:55whatever conversation you are doing you
13:19:57won't be able to see in trade one okay
13:19:59that's how you can create as much as
13:20:00trade you can like the chat GPT we saw
13:20:03the example right so we are preparing
13:20:05the configuration there is a parameter
13:20:07called configurable you have to define
13:20:08as a dictionary then you have to define
13:20:10the trade ID so let's say we have given
13:20:12one then we are invoking the workflow we
13:20:14are passing let's say topic is equal to
13:20:15football let's say uh here the topic
13:20:18should be the football and it will
13:20:19generate a joke on top of the football
13:20:21okay then we are passing the
13:20:22configuration here now let's execute
13:20:32Okay guys, so here I'm getting an error
13:20:34rate remit uh limit error. I think my
13:20:37openi credits is over. Uh so what I can
13:20:40do? Maybe I can use um other model. So
13:20:42let's use uh another model. Maybe I can
13:20:44use Gemini. Gemini maybe I can use uh
13:20:47this model uh freely. Okay, for some
13:20:49request. So what I'm going to do guys uh
13:20:52quickly
13:20:53um
13:20:55You can simply go to the chart GPT
13:20:59I have already done. Let me show you
13:21:03see. So I go to the chat GPT then I
13:21:06given my code let's say this is the code
13:21:08I'm using and can you change the model
13:21:10to Gemini uh uh model to Gemini open a
13:21:14credit is over. Now it has suggested
13:21:17okay that's how you have to use the
13:21:18Gemini model. First of all you have to
13:21:19install this library langen uh Google
13:21:22geni. So let's try to add inside our
13:21:24requirement.
13:21:26So I've already added inside my
13:21:28requirement. Now let me install that. So
13:21:30pip install
13:21:32r requirement.txt.
13:21:41Yeah, that's how you can use any model.
13:21:42Okay, model doesn't matter either you
13:21:44can use open model, gemini model, open
13:21:46router provider, anything you can use.
13:21:48Once it is done then I'll try to simply
13:21:52uh see the next step. I have to collect
13:21:54my Google API key. So and we have to add
13:21:57inside the environment variable. So
13:21:58let's try to do that. So this is my
13:22:01environment variable.
13:22:04So here I'll try to add my Google API
13:22:07key. And where you will get the API key?
13:22:09You have to go to the Google uh AI
13:22:12studio.
13:22:15Google AI Studio.
13:22:24So left hand side you will be able to
13:22:25see the API key option.
13:22:28Now let's try to generate the API key.
13:22:31I already have some API key here. Maybe
13:22:33I can delete.
13:22:40Okay. You want to create a new one.
13:22:42Click on create API key. Gemini API key.
13:22:44You can select your project if you have
13:22:46any project. Let's I'll select my
13:22:47project and create the API key.
13:22:55Once done, let's copy this API key and
13:22:57I'll try to paste it here.
13:23:02Done.
13:23:06Okay. Now let's try to Yeah. Now let let
13:23:10me check. So if you want to do that
13:23:12first of all you have to import this
13:23:13line
13:23:17instead of open AI you will import this
13:23:20lang chain Google geni import chat
13:23:23Google generative
13:23:25let's import
13:23:27load the environment variable then you
13:23:29have to uh replace this
13:23:36okay replace this uh model definition
13:23:39with uh uh Here I'm using Gemini 1.5
13:23:42flash. I think this is the free model,
13:23:43free to use model and this is the
13:23:44temperature parameter. Now let's define.
13:23:47Okay, now I think it's fine. Now
13:23:49everything is good. Now I'll come here
13:23:52or let's try to uh execute all the
13:23:56cell again otherwise I think I might get
13:23:59some issue. I'll define the graph. Now
13:24:02let's invoke this workflow. Okay, here
13:24:05I'm getting a client error. Uh okay.
13:24:09This model not found
13:24:14is uh during the task with name joke ID.
13:24:19Okay, let me check this model not found.
13:24:31I can try with this pro model.
13:24:50Okay, this is also not found. Maybe I
13:24:52can try with this
13:24:552.5 plus.
13:25:03I think this should work.
13:25:05Yeah, 1.5 I think it is deprecated from
13:25:07the uh API. You have to use 2.5.
13:25:16Now see we are getting the output that
13:25:18means 2.5 is working. Okay. You have to
13:25:20use this 2.5 flash. Okay. Now see here
13:25:23is the topic we have given and this is
13:25:24the joke I got and this is the
13:25:26explanation. Okay. We are getting from
13:25:28this particular joke. It's working fine.
13:25:31Okay. Now if you want to see this state
13:25:33right? If you want to see your state uh
13:25:35because this state got saved in the
13:25:37memory you have to call this function
13:25:39get state and you have to pass the
13:25:41configuration that means our trade ID
13:25:43configuration trade one configuration.
13:25:45Now if execute now see this is the
13:25:47snapshot this is your state you can see
13:25:49the topic you can see the joke you can
13:25:52see the explanation and some other
13:25:54metadata informations are available
13:25:56here. Okay. Now if you want to see the
13:25:58entire uh like uh intermediate state as
13:26:01well as the final state you have to
13:26:03execute this function get state history
13:26:04story and again you have to pass the
13:26:06configuration that means trade one. Now
13:26:08if I execute this now see guys you are
13:26:10getting all of the intermediate state as
13:26:12well as the final state. Okay. Now the
13:26:16last one you can see this is the last
13:26:18last uh like that means the final state
13:26:21and the first one this is the first uh
13:26:23state first intermediate state. Now if I
13:26:25show you this graph guys. So how many um
13:26:29checkpoint you have here. See you have
13:26:31one checkpoint 2 3 and four. So that
13:26:34means four output we are getting. So
13:26:36this is the first checkpoint output. So
13:26:38initially whenever we pass the topic we
13:26:41didn't have any kinds of joke. Uh then
13:26:44uh uh explanation. Okay we didn't have
13:26:47anything. You can see initially this was
13:26:50only running the uh start node and there
13:26:53is nothing. Okay. Then we executed the
13:26:56second node that means the second
13:26:57checkpoint. In second checkpoint we
13:26:59passed the we only passed the topic.
13:27:02Okay. And that time we didn't have any
13:27:04kinds of joke. You can see we didn't
13:27:06have any kinds of joke or uh this
13:27:09explanation. Okay. You can see this was
13:27:11nothing. Then at the third third uh you
13:27:15can see checkpoint it was uh it has
13:27:18generated the joke. Okay. Uh that time
13:27:21explanation was not available. Okay. You
13:27:23can see uh topic was there, joke was
13:27:26also there. Okay, joke was also there
13:27:28but explanation was not there. You can
13:27:31you can see explanation is completely
13:27:33empty. It it was not there. Right? Then
13:27:36whenever we executed the last node that
13:27:39means we uh got the checkpoint for that
13:27:42time explanation was available. You can
13:27:44see topics is available, joke is
13:27:46available, explanation is also
13:27:48available. Okay, that's how you will be
13:27:50able to see the final snapshot as well
13:27:52as the intermediate snapshot of this
13:27:54state. Okay, this is amazing, right? And
13:27:57that's how your persistence is working.
13:27:59And this is super important guys. Just
13:28:01trust me, this is super important
13:28:03concept whenever you are implementing
13:28:05any kinds of agentic AI application.
13:28:07That's why uh in my first part the
13:28:10application I started guys agentic
13:28:11chatbot. So there I use this particular
13:28:13concept this persistence concept. So
13:28:16there also we created this checkpoint. I
13:28:18think you remember we created a
13:28:19checkpoint but here I used this memory
13:28:21saber. I was saving everything in my RAM
13:28:24but later on I will also show you how we
13:28:26can add the database as well. Okay.
13:28:28Because I told you we'll be going step
13:28:30by step so that I can teach you each and
13:28:31everything. Okay. I hope you clear. So
13:28:35now I'll get back to my code. Yeah. Now
13:28:37let's uh let me show you one thing this
13:28:39uh uh trading concept. Let's say if I
13:28:42right now give this trade ID is equal to
13:28:44two. Right. That means uh completely one
13:28:47another trade would be created another
13:28:48block would be created in the memory and
13:28:50in that particular memory it will save
13:28:52all the informations. Now see we are
13:28:54invoking with another topic called
13:28:56cricket. Now it will generate uh
13:28:58generate the joke on top of the cricket
13:29:00but in a different rate.
13:29:02Let me show you.
13:29:12Okay. If you're using free model it
13:29:14might take some time. Now you can see
13:29:15this is the topic and this is the joke
13:29:17and this is the explanation we are
13:29:18getting on top of cricket. If you want
13:29:19to see the state final state final
13:29:21snapshot this is the final snapshot. And
13:29:23if you want to see the all the
13:29:24intermediate state as well as the final
13:29:26state you have to execute this line. Now
13:29:28you can see this is for football. Okay.
13:29:30Now the best part is that if I change
13:29:32this configuration anytime let's say I
13:29:34want to get my uh I want to get my um uh
13:29:38football. Sorry not football. Okay this
13:29:41is configuration one pass. Sorry, I have
13:29:42to give configuration two. Now if I give
13:29:45configuration two, now see this is for
13:29:46cricket here also I have to pass the
13:29:48configuration two because this is my uh
13:29:52uh trade two right now if I give
13:29:54configuration one.
13:29:56So this is my trade one that means
13:29:57cricket sorry football. Now if I give
13:30:00you trade two now this is cricket. Okay
13:30:02see all of the state is different right
13:30:05now because it is saving inside
13:30:07different different trade. Okay I hope
13:30:09you get it guys. So from this
13:30:11persistence guys we got some benefit
13:30:13definitely. So let's try to define the
13:30:15benefit
13:30:19benefit of
13:30:21persistence.
13:30:26So the first benefit we got the
13:30:28short-term
13:30:33memory.
13:30:36I think you already saw the short-term
13:30:38memory, right?
13:30:40uh we have implemented because it is
13:30:43saving the information in this state
13:30:45okay in a database and in my previous
13:30:49code example also the chatbot I created
13:30:51this was also able to remember my
13:30:53informations okay this is called
13:30:54short-term memory we can implement okay
13:30:56with the help of this persistence now
13:30:59the second one
13:31:01um benefit you will be getting called
13:31:03this fault tolerance
13:31:05fault
13:31:07tolerance
13:31:10Okay, I already told you about this
13:31:12fault tolerance. Fault tolerant means I
13:31:14think here I showed you somewhere. Yeah.
13:31:16So let's say um if uh your application
13:31:20got crashes um um from any any
13:31:23particular nodes instead of executing
13:31:26your application from the beginning you
13:31:27can resume the application uh from the
13:31:30same uh same crash point um itself.
13:31:33Okay, let's say node one your
13:31:35application got crashes. From node one
13:31:36itself you can execute your application.
13:31:38Okay, for this I will show you a
13:31:40practical demo. I think after that you
13:31:42will be able to um understand. Then uh
13:31:46this persistent helps us to implement
13:31:48this hl that means human in the loop
13:31:51concept. Then there is another one
13:31:53called time travel.
13:31:57Okay time travel we'll also see the
13:31:58example itself. Now uh we have al
13:32:01already seen the shortterm memory
13:32:03example. Uh even going forward also I'll
13:32:06use this concept in my application.
13:32:08Okay. Uh you already understood this
13:32:10concept. Now let's try to understand
13:32:12this fault tolerance like how we can
13:32:13resume the application whenever it got
13:32:16crashes. Okay. So let's see the fault uh
13:32:19tolerance uh example. Um like I will
13:32:22show you a code example how it works.
13:32:24For this here I have taken uh this
13:32:26particular workflow. uh it's a like very
13:32:30uh basic dummy workflow I have taken I
13:32:32generated from uh this uh workflow
13:32:36uh from chart GPT. So here uh what I
13:32:38have done guys I have um uh taken
13:32:42actually three step one step two step
13:32:44three. So what is fault tolerance? I
13:32:46told you fall tolerance means uh let's
13:32:48say uh at step two let's say you got
13:32:51crash okay crash your application. So
13:32:56instead of uh instead of running from
13:32:59the beginning whenever you you are
13:33:00resumeuming your application instead of
13:33:02starting from beginning so what you can
13:33:04do you can start from step two itself
13:33:06okay because I have all of the
13:33:08intermediate state data okay till uh
13:33:12step one so I don't need to execute from
13:33:14step uh uh sorry uh step uh from the
13:33:17first step again I will execute from
13:33:19step two okay so this is called fault
13:33:21tolerance
13:33:22so this example we'll try to see in a
13:33:24code example So here what I have done
13:33:26guys here uh manually just I have uh
13:33:30taken up uh like time I am using time
13:33:33module in Python and here I will wait
13:33:35for 30 seconds okay and in 30 seconds
13:33:37what I'm going to do I'm going to just
13:33:39do a manual keyboard interruption and I
13:33:42will just crash my application here okay
13:33:44and I'll show you how we can resume your
13:33:46application from step to itself okay
13:33:48that means wherever your application
13:33:50will get crashed from here itself it
13:33:52will try to uh from here itself it will
13:33:54try restart the application. Okay, this
13:33:56part I'll show you for this. What I have
13:33:58done guys, I have written a code u in
13:34:01Google Collab. So why I'm writing in
13:34:03Google Collab? Because in my VS code uh
13:34:06I was not able to uh I was not able to
13:34:09interrupt this uh sale. Okay, it was
13:34:11taking lots of time that's why I have uh
13:34:13copied this code on my Google Collab. So
13:34:15I already connected the notebook and I
13:34:17will share this notebook with you guys.
13:34:18So here what I'm going to do guys I'm
13:34:20going to import all of the necessary
13:34:23library then here for this particular um
13:34:27um graph I have defined all of the state
13:34:29I need like I need input step one step
13:34:32two okay and I uh inherited with the
13:34:35type D then here I have defined all of
13:34:37the step one step two step three you can
13:34:40see all of the step I have defined step
13:34:41one step two step three only in step two
13:34:43guys here I am uh just taking this time
13:34:46dots sleep I will wait for 30 seconds.
13:34:49Okay. And here I'm only just doing the
13:34:50print statement. I'm just doing like a
13:34:52step one executed and return the step.
13:34:54Okay. And update the state. And step two
13:34:56only I'm just doing this uh waiting
13:34:58operation. 30 secondond will wait. And
13:35:00in between I'll just try to crash my um
13:35:02the cell. And step three also I'm just
13:35:04only doing the print statement. Okay.
13:35:06This is a dummy code I generated from CH
13:35:07GPT. Now let's execute this cell also.
13:35:11Now here we are building the graph. As
13:35:12you can see we are taking the graph and
13:35:14we are adding all of the node one by
13:35:15one. Then we are doing the edge
13:35:16connection. Okay, then we are taking the
13:35:19checkp pointer in memory saber. Then we
13:35:21are just compiling the graph and we're
13:35:23giving the check pointer.
13:35:26Done. Now here guys, uh in the t set
13:35:28block I am invoking my um you can see
13:35:31graph and I am just doing some print
13:35:33statement. Okay. So you can see I'm
13:35:35giving um uh input is equal to start
13:35:37because here I told you we are only
13:35:39doing uh by very basic workflow
13:35:42execution. That's why I have just given
13:35:44some dummy value here. And here we are
13:35:46giving the trade also that means the
13:35:47configuration. I think you know in
13:35:49persistence you have to give that. Then
13:35:51in exception we are uh also printing
13:35:53kernel manually interrupt crash
13:35:55simulated. Okay. Now let's execute. Now
13:35:57see it will wait for 30 second. In
13:35:59between I'll just try to um stop the
13:36:02kernel. Okay. Now see kernel stop that
13:36:04means my application got crashed. Now if
13:36:06I show you my state as you can see uh
13:36:10step one done. Okay. Step one executed
13:36:13perfectly. Uh perfectly it's done. Now
13:36:16whenever it was running a step two right
13:36:18there is nothing. You can see step two
13:36:20didn't completed because here it got
13:36:22crashed. Now I will rerun this
13:36:26particular workflow again and you will
13:36:29see that instead of running from the
13:36:30beginning step one it will run from step
13:36:32two. So again what I'm doing guys I'm
13:36:34invoking the graph and as of now the
13:36:36input I'm only giving this none. Okay.
13:36:39Why I'm giving the none? Because uh if
13:36:41you're uh uh doing the fault tolerance
13:36:43instead of see previously I was giving
13:36:45my input but right now I want I don't
13:36:48want to start from the beginning. I want
13:36:50to start where it got crashed. That's
13:36:51why I have to pass the none. Okay then
13:36:54we are giving the trade again and we are
13:36:56giving the same trade. Now let's
13:36:58execute. Now you'll see that it is
13:37:00running from the step two. As you can
13:37:01see it is not running from the step one.
13:37:03It is running from the step two. And
13:37:05after waiting for 30 seconds you will be
13:37:06able to see the final output. Let me
13:37:08show you.
13:37:2830 second you have to wait. Now see
13:37:30execution is done. Now we're getting the
13:37:32final step. You can see step two is also
13:37:34done. Now if you want to see the state
13:37:36as you can see step one is done. Step
13:37:38two is also done. Okay. So that's how
13:37:40guys fault tolerance works with the help
13:37:42of this persistence. I hope you get it
13:37:44guys. That's how you can resume. Okay,
13:37:46you can resume your any kinds of
13:37:47workflow whenever it got crashes in
13:37:49production. Okay, I hope you clear guys.
13:37:52Now let's try to understand this hit
13:37:55that means human in the loop. Uh like
13:37:57how persistent helps us to implement
13:37:59this human in the loop. See uh for this
13:38:01u let's take a simple example and try to
13:38:04understand this one because I'm not
13:38:05going to show you as a code example for
13:38:07this human in the loop. I'm going to
13:38:09create a dedicated video. See let's say
13:38:11I want to generate a LinkedIn post okay
13:38:14or let's say Facebook post first of all
13:38:15I have to take a topic okay topic name
13:38:17from the user then it will go to the
13:38:20next um nodes it will basically generate
13:38:22let's say this
13:38:24uh Facebook
13:38:28post okay once it generated the Facebook
13:38:32posts then uh I want actually uh it will
13:38:35wait for the human verification let's
13:38:37say it will wait for the human
13:38:38verification let's say if I verify by
13:38:41post is completely fine. That time I'll
13:38:43give the permission just try to post
13:38:45this particular uh post to the Facebook
13:38:48platform. For this maybe we can use a
13:38:50API provider Facebook API provider and
13:38:52we can basically post this uh sorry here
13:38:56I will yeah uh basically here we we we
13:38:58can post this particular post on the
13:39:00Facebook. So maybe I can draw it
13:39:04uh perfectly.
13:39:06So topic
13:39:09then Facebook
13:39:13post
13:39:15then here it will wait
13:39:19H I T L human in the loop then it will
13:39:23post this uh post this uh let's say post
13:39:29to the Facebook platform. Okay. Now you
13:39:32can see here uh whenever we'll try to
13:39:34build this workflow right whenever we
13:39:35try to build this workflow so that time
13:39:37user will give a topic name it's
13:39:39completely fine from the topic itself
13:39:41your Facebook post would be generated
13:39:43then here itself it will wait for the
13:39:45human verification okay here it will
13:39:47wait for the human verification so that
13:39:49time uh human can give this particular
13:39:52verification in 1 minute 30 seconds 1
13:39:55day 2 day okay it doesn't matter or
13:39:56after 1 month also okay based on the
13:39:58user let's say uh choice user
13:40:01preferences Okay. So it's not like that
13:40:03your entire workflow should be running.
13:40:05Let's say user want to give this uh uh
13:40:08permission after 2 days. It's not like
13:40:09that you have to run your entire
13:40:11workflow 2 days. Okay. And you have to
13:40:13wait for the user verification.
13:40:15Otherwise what will happen if you are
13:40:16continuously running uh you are ending
13:40:18up with like your hosting cost right? I
13:40:21don't want that computation cost. I
13:40:23don't want that. So what will happen
13:40:24this uh fault uh sorry this persistence
13:40:27that means uh you have learned about
13:40:30this fault tolerance right so here
13:40:32basically fault tolerance concept would
13:40:34be applied that time automatically this
13:40:36particular uh execution would be
13:40:38interrupt okay
13:40:41interrupt it this execution would be
13:40:43interrupt interrupt would be it would be
13:40:44stopped okay then human will come and
13:40:48give the let's say feedback let's say he
13:40:51has accepted this particular post that
13:40:53time this workflow will again re-execute
13:40:56and instead of running from the
13:40:57beginning okay instead of running from
13:40:59the beginning what it will do it will
13:41:01start from here only that means the post
13:41:03is accepted now it will run the next
13:41:05workflow which is post okay the next
13:41:07note which is post instead of running
13:41:09from the beginning okay and how it is
13:41:11remembering because it has the
13:41:13persistence concept because all the
13:41:15intermediate data it has also saved okay
13:41:17so whenever it will get the new data
13:41:19that time from here only it will start
13:41:22the example I showed you right now fall
13:41:24tolerance it will work in the same way.
13:41:26Okay, I hope you got it guys. That's why
13:41:28this percentage is also required
13:41:30whenever you are using whenever you are
13:41:32imple implementing this hit concept that
13:41:34is human in the loop concept. Okay, I
13:41:36hope you cleared. Now guys let's try to
13:41:38understand the last benefit uh which is
13:41:40time table. Okay. Uh the concept looks
13:41:44interesting uh even this is also
13:41:46interesting inside this um uh langraph
13:41:49uh inside the persistence. Let's try to
13:41:51understand what is time table exactly.
13:41:53Okay. So see here I have already taken
13:41:55the code example. Uh I will just show
13:41:57you okay how things are working. So I
13:41:59think remember we just created this um
13:42:03this um um joke generator generator
13:42:07actually workflow right we created this
13:42:08joke generator workflow. So in tribe
13:42:11table actually what you can do uh you
13:42:13can actually uh go to the each and every
13:42:16um nodes and you can see their
13:42:18execution. Okay. So here see let's say
13:42:21this is our workflow we created
13:42:22previously right now uh here I showed
13:42:26you all of the execution all of the
13:42:28snapshot all of the like state update
13:42:30right all of the intermediate and final
13:42:32now let's say I want to go to a
13:42:34particular um particular let's say
13:42:37checkpoint let's say I want to go in
13:42:39this particular checkpoint
13:42:41okay where I only pass the uh where I
13:42:44only pass the let's say topic is equal
13:42:45to cricket so what I will do I'll just
13:42:47do workflow get state And here you have
13:42:50to pass the configure configuration. So
13:42:52here this is was my uh trade two right
13:42:55that means configuration two. I'm
13:42:56passing my configuration two. That's why
13:42:57you're giving the trade two here because
13:42:59in configuration I was giving the trade
13:43:01two. Then here you have something called
13:43:03checkpoint ID. So here you have to give
13:43:04the checkpoint ID. Now you can see every
13:43:06snapshot is having a checkpoint ID. So
13:43:08here if you just go right side here you
13:43:10can see the checkpoint ID. You just need
13:43:12to copy this checkpoint ID and you have
13:43:14to provide it here. Okay. Once you do
13:43:16that now if you execute this okay you
13:43:18will be able to see that it will only
13:43:19return you that particular snapshot uh
13:43:21let's say output that particular state
13:43:23only okay now you can ask me why it is
13:43:26required and uh how it is helpful see
13:43:28whenever you are creating any kinds of
13:43:30complex workflow and you want to do the
13:43:31debugging operation that time this
13:43:33concept is required okay this thing you
13:43:35won't be using frequently whenever you
13:43:37want to perform some kinds of debugging
13:43:39you want to see each and every node
13:43:40execution that time this time travel you
13:43:43can use okay now you can see the exact
13:43:45same thing you are getting here. Now
13:43:47let's say I want to see the after that
13:43:49uh let's say this this uh snapshot.
13:43:52Okay. So I'll give this particular ID.
13:43:54So if I go to the right side you will
13:43:56have the checkpoint ID. You just need to
13:43:58copy that and here I have already passed
13:44:00that. Okay. Now I already executed. You
13:44:02can see here I'm getting topic is equal
13:44:04to cricket and this is the joke and uh
13:44:07here I got the explanation. Okay. Now if
13:44:10I show you the entire uh get uh state
13:44:13story. Now see initially it was four.
13:44:15Now two more uh snapshot is created
13:44:17because I did the time table. Okay. So
13:44:19this is the first one. There I only got
13:44:22the uh topic and here is the second one.
13:44:25Okay. Now let's try to see another
13:44:29concept which is update state. Okay. U
13:44:31like let's say here I'm having this
13:44:34particular node right and each and every
13:44:36node is updating some kinds of state
13:44:39right? Now if you want you can also
13:44:41manually update your state. Let's say
13:44:44your workflow has generated some state
13:44:46state. Okay. But you want to update
13:44:48let's say initially I have g given
13:44:50cricket topic is equal to cricket but
13:44:52right now I want to let's say debug with
13:44:54uh tennis. Okay. So what I will do I'll
13:44:57just write uh workflow update state and
13:44:59here also you need to pass the
13:45:01configuration that means your trade ID
13:45:03and you have to give the checkpoint ID.
13:45:04Now let's say uh at the very first
13:45:06checkpoint this was the checkpoint right
13:45:08there I give it the cricket topic is
13:45:10equal to cricket. So I'll copy this uh
13:45:12checkpoint ID. Okay, I'll copy the
13:45:14checkpoint ID and you have to provide
13:45:15the checkpoint ID here. Okay, after that
13:45:17here you have to pass the topic. Topic
13:45:19is equal to tennis I have given. Okay,
13:45:21this is a dictionary. Now if you
13:45:22execute, you will see that this
13:45:24particular uh state would be updated.
13:45:26Now if you again execute the workflow,
13:45:27now you'll see that another state would
13:45:29be created. Now here topic is equal to
13:45:30tennis. Okay, so that's how you can do
13:45:33the debugging operation. If you want you
13:45:35can update your state even you can do
13:45:36the time travel through your entire
13:45:38state. Okay, this is also possible. And
13:45:40here I already updated your fall
13:45:41tolerance code in the same notebook
13:45:43itself. Okay. So that you can copy paste
13:45:45in the Google collab guys. So yes guys
13:45:48this is the concept uh we have
13:45:50understood inside persistence and by
13:45:52this video itself you have now enough
13:45:54informations like how much persistence
13:45:57important uh importance uh is like
13:46:00whenever we are creating this kinds of
13:46:02agent application and how persistence is
13:46:05helping us without persistence actually
13:46:07what will happen. Okay, we have
13:46:08understood each and everything. Now I
13:46:10think you don't have any kinds of
13:46:11question. Okay, that's why um in my
13:46:13first part guys, I added this
13:46:15persistence concept. I added this
13:46:17checkpointter concept. Okay, now I think
13:46:18this part is pretty much clear guys.
13:46:20Okay, so that's how guys we'll be
13:46:22implementing the chatbot um in detail. I
13:46:25will try to make this particular chatbot
13:46:27more advanced. Okay, aentic chatbot more
13:46:29advanced. I'll try to add all of the
13:46:31concept one by one by explaining this
13:46:33kinds of concept separately. Okay. So we
13:46:36have created our basic uh skeleton basic
13:46:39uh agentic chatbot workflow. So here you
13:46:41can perform any kinds of chat operation
13:46:44right now. So let's see if I uh give a
13:46:46message u
13:46:49generate a
13:46:51blog about
13:46:55let's say python.
13:47:00So if I send this prompt now see it is
13:47:03able to generate the block. Okay. So we
13:47:06have already created this kinds of uh
13:47:08skeleton this kinds of workflow like
13:47:10chat workflow and everything is working
13:47:12fine. Now in this video guys I'm going
13:47:14to um just deep dive into this streaming
13:47:18like what this streaming is and why it
13:47:20is required and we'll also try to
13:47:21understand if we don't use this kinds of
13:47:23streaming features inside our agentic
13:47:25chatbot or any other agentic application
13:47:27you are creating. So what should be the
13:47:29issue? Okay. So guys uh we'll try to
13:47:32continue with our discussion of the
13:47:34streaming features inside uh agentic
13:47:37chatbot and if you are using langraph
13:47:40guys uh by default inside langraph the
13:47:42streaming features is available. Okay uh
13:47:44with the help of that you can easily
13:47:46create the streaming features. So for
13:47:48this you can go to the documentation of
13:47:49this langraph. So there they have given
13:47:51some code example. Okay. But let me
13:47:53first of all show you my code example.
13:47:56Okay. Okay. Then after that you can go
13:47:57through the entire documentation. Okay.
13:47:59And you can understand about the
13:48:00streaming. Okay. Yeah. So guys see if I
13:48:04not using the streaming features. So how
13:48:06my chatbot will look like? First of all
13:48:08let me show you. So guys as you can see
13:48:10this is the code we have already written
13:48:12uh for this uh agentic chatbot. And this
13:48:15is our uh first initial workflow we have
13:48:18created. Okay. Uh this is the chatbot
13:48:21workflow we have created. And here if
13:48:23you just go to the last part. So here I
13:48:26already discussed about the streaming.
13:48:28Okay, how to add the streaming features
13:48:30but yeah I think in the first part you
13:48:33might have uh some kinds of confusion
13:48:35like how we have added this particular
13:48:37stream uh stream features here. So in
13:48:39this particular video I'm going to
13:48:41clarify each and everything then I think
13:48:43this would be more clear. Okay. So here
13:48:46what I'm going to do guys uh let me show
13:48:48you the non-streaming um like features
13:48:50first of all. So I think this code is
13:48:52also common. Initially I also created
13:48:54this code and you remember there I'm not
13:48:56using any kinds of streaming features.
13:48:58Okay. So what I'm doing I'm just
13:49:00generating the response after that I was
13:49:02um like uh waiting for the entire
13:49:05response. Once I got the response I was
13:49:08just showing on the streamlit user
13:49:10interface. So if I execute this
13:49:12particular file let me show you. So I'll
13:49:15stop my app.py and I will execute this
13:49:18nonstream.py.
13:49:20So I'll just write streamlit.
13:49:23Okay, streamlit run non stream.pfy. Now
13:49:29if I hit enter, so this will load my
13:49:31application. Now here let's see if I
13:49:33give the same prompt generate a blog
13:49:38about
13:49:41okay about let's say
13:49:44I'll give um machine learning
13:49:51now see if I give this prompt now see
13:49:55here we have to wait right we have to
13:49:58wait uh till the execution now see so
13:50:00here I think you have observed uh we had
13:50:02to wait uh unless and until this output
13:50:05got generated here. Uh so let's say if
13:50:07you're generating uh some more uh let's
13:50:10say content here some more big content
13:50:13that time it will take some time maybe
13:50:15it can take let's say 30 seconds 60
13:50:18seconds okay it depends upon your uh
13:50:20output or the prompt you are giving
13:50:22let's say you are running an agent and
13:50:24that that agent is taking time it is
13:50:26using some kinds of tool okay so uh in
13:50:29between actually it will do lots of work
13:50:31and you have to wait for the execution
13:50:33so this is not good right uh this is not
13:50:35good uh user experience. So if I open
13:50:37chart GPT okay if I open chart GPT in
13:50:40chart GPT if you give any kinds of
13:50:43prompt let's say I will give the same
13:50:44prompt in the chart GPT okay you'll see
13:50:47that chart GPT also will give you some
13:50:49kinds of streaming response see this is
13:50:51giving you streaming response one by one
13:50:53right and this is more interactive right
13:50:56this is more interactive because we
13:50:57don't need to wait for the entire
13:50:59execution to be completed okay whether
Streaming Responses in Agentic Chatbot with LangGraph
13:51:01it is using any kinds of tool whether it
13:51:03is uh doing the reasoning operation it
13:51:05doesn't matter But I'm able to see my
13:51:07output token by token. Okay. So this is
13:51:10good user experience here. But inside
13:51:12this particular application this is not
13:51:14good experience. So if I uh give this
13:51:16kinds of prompt so what is happening? It
13:51:18is taking some time. Right. That's I'll
13:51:20give right now deep learning.
13:51:23See it's taking lots of time. So this is
13:51:25not a good experience. Okay. So that's
13:51:27why streaming features is required.
13:51:29Okay. Streaming features is required.
13:51:31Now let's try to understand what is
13:51:33streaming exactly and why it is
13:51:35important inside our application
13:51:36development. So guys first of all let's
13:51:38try to understand uh what is streaming.
13:51:41So here I have already written a
13:51:42definition in LLM. Streaming means the
13:51:45model start sending tokens uh that means
13:51:48word as soon as they they are generated
13:51:51instead of waiting for the entire
13:51:53response to be ready before returning
13:51:56it. Okay. See what happens whenever we
13:51:58are using any kinds of large language
13:52:00model, it generates the output as token
13:52:04by token or word by word. Okay. So
13:52:07whenever let's say we invoke any kinds
13:52:09of large language model, let's say this
13:52:10is our LLM and we are giving some kinds
13:52:14of prompt here and we get a response
13:52:16here. Okay. So what you can do either
13:52:20you can get this response in one shot
13:52:22that means you have to wait uh for the
13:52:25entire output to be generated. Okay for
13:52:28this we use something called invoke
13:52:30function. Okay invok function I think
13:52:32you already know that we are using okay
13:52:34so far. So inbox what it does it will
13:52:37wait for the entire output to be
13:52:40generated but llm will try to generate
13:52:42the output as token by token. Let's say
13:52:44it is generating something. So first of
13:52:46all uh one token will come then another
13:52:48token will come another token will come
13:52:50okay that's how it will complete the
13:52:52entire execution okay that that's how it
13:52:54will complete the entire execution then
13:52:56you will be able to see the response but
13:52:59in streaming actually what we do we use
13:53:01something called stream function instead
13:53:03of uh invoke we use dot stream function
13:53:07uh this is already default inside lang
13:53:09graph whenever we are defining any kinds
13:53:12of graph object right and uh you
13:53:14remember we we are doing the invoking
13:53:15operations. So instead of invoking
13:53:17operation we have to perform dot stream
13:53:19operation. So if you do dot stream
13:53:21operation so what will happen that time
13:53:23you will be getting this particular
13:53:24output as a token by token or word by
13:53:26word as soon as they are generated.
13:53:28Okay. Instead of waiting for the entire
13:53:31response to be ready before returning
13:53:33it. Okay. So this is what actually your
13:53:34streaming is. I think you already saw
13:53:36inside chart GPT. Okay. Chart GPT it was
13:53:39generating token by token. Let me show
13:53:41you again. So maybe I can give another
13:53:44prompt. So I'll give let's say generate
13:53:47a blog about deep learning. Now see it
13:53:50will generate the output token by token.
13:53:52You can see token by token it is
13:53:54generating. Okay. Now I think this uh
13:53:56definition is pretty much clear. Now
13:53:58let's try to understand uh why this uh
13:54:01streaming is required. Okay. You can see
13:54:04the first point faster response time and
13:54:06low drop off rates. Okay. I think by
13:54:09this uh point itself you can understand
13:54:12what I'm trying to say uh faster time
13:54:15time uh uh response time is let's say
13:54:17whenever I'm using any kinds of chatbot
13:54:19let's say I'm using chat GPT okay I'm
13:54:22using chart GPT or any other thing u so
13:54:25there I definitely need a faster
13:54:27response so if it is not giving faster
13:54:29response that time like uh I won't be
13:54:32getting interest right to use this
13:54:34particular application because nowadays
13:54:36time is expensive Okay, time is
13:54:38expensive and and nowadays people don't
13:54:41have that much of time so that they will
13:54:42wait for the entire execution. Okay,
13:54:45that is taking 1 minute to run. So they
13:54:47don't have that much of time. They will
13:54:48wait and they will get the uh let's say
13:54:51entire output. Okay, so they need a
13:54:53faster response. So definitely faster
13:54:55response is required whenever you are
13:54:57creating any kinds of application
13:54:58whether you are creating chatbot whether
13:55:00you are creating AI agents okay anything
13:55:02you are creating faster response is
13:55:04required otherwise what will happen
13:55:07there would be a drop off rates okay
13:55:09drop up rate means people will leave
13:55:11your application okay let's say if it is
13:55:13taking 1 minute to run so definitely
13:55:15I'll leave your application okay I'll
13:55:17leave your application I will look for
13:55:19some other application which can give me
13:55:20faster response so that's why uh if it
13:55:23is faster response time that means low
13:55:25drop off rates. Okay, low drop of rate
13:55:27means people will not leave your
13:55:29application. They will be continuously
13:55:30using like chart GPT people are using
13:55:32Delhi, right? Because it is having the
13:55:34faster response because of the streaming
13:55:36features. Okay, we know that LLM takes
13:55:39some time to generate the entire output.
13:55:41But we have to handle it smartly instead
13:55:44of waiting for the entire let's say
13:55:45output to be generated. Whatever token
13:55:48it is generating okay one by one we'll
13:55:50show to the user so that they will see
13:55:52something in the screen. Okay, this is
13:55:54what we have understood in the first
13:55:56point. Now the second point you can
13:55:57understand guys mimics the human-like
13:55:59conversation, build trust, feel alive
13:56:02and keep the user engaged. Okay, see
13:56:06whenever you are doing any kinds of
13:56:07conversation with any kinds of agent or
13:56:10chatbot or whatever you are doing the
13:56:12conversation. So definitely uh there
13:56:15some kinds of engagement should be
13:56:17there. Let's say if this application is
13:56:19taking 1 minute to run, right? and you
13:56:22have to wait for the execution. So
13:56:24definitely I can't tell this is like a
13:56:25human-like conversation. Let's say you
13:56:28are talking with someone. Let's say this
13:56:30is you. Okay, this is you and this is
13:56:32someone. You are talking with someone,
13:56:34right? And if you're asking something
13:56:36and let's say this person is taking 1
13:56:39minute to give you the response. So
13:56:41definitely you will not feel like uh
13:56:43interest, you will not feel engaged.
13:56:45Okay, you will uh you will not be able
13:56:47to build a trust with that particular
13:56:49person. Okay. Uh I can give you another
13:56:51example. Let's say I think you know uh
13:56:53nowadays people are using lots of uh uh
13:56:56hardware assistant right hardware
13:56:58assistant means like Amazon Alexa.
13:57:01Amazon Alexa then Google Home Mini. Okay
13:57:04Google Home many people are using that
13:57:06right? So this is kinds of personal
13:57:08assistant system and what we do we use
13:57:11this particular assistant system so that
13:57:12we can speak with uh them right speak
13:57:15with them and we can uh do lots of task.
13:57:17Now let's see if you are talking with
13:57:19your uh personal assistant, you are
13:57:21talking with your let's say Google Home
13:57:22Mini. Okay, you are talking with your
13:57:24Google Home Mini and let's say it is
13:57:25giving you the response after 1 minute.
13:57:28So definitely you will not feel engaged,
13:57:30you will not u feel alive, you will not
13:57:32feel uh like uh you are not going to
13:57:34build a trust okay with that particular
13:57:36device. So that's why mimic human like
13:57:38conversation it is required. So whenever
13:57:40I will talk with uh my let's say bot or
13:57:44let's say agents so I'll feel like okay
13:57:46I'm talking with the human okay
13:57:47instantly I'm getting the response and
13:57:49the response is engaging as well okay
13:57:51like chat GPT if you u if you're using
13:57:54chat GPT I think you know that this um
13:57:57engagement then alive trust is super
13:58:00important right and we we found inside
13:58:02that particular chatbot right that's why
13:58:04we are using continuously so that's why
13:58:05this is super important then important
13:58:07for multimodel UIs okay so Whenever you
13:58:10are using multimodel and you are
13:58:12creating a user interface so this is
13:58:14also required there. Okay. Sometimes you
13:58:16will be generating some kinds of image
13:58:18and whenever you are generating the
13:58:20image that time you can show like we
13:58:23okay we are generating the image we are
13:58:24taking this particular let's say color
13:58:27or there should be a image window
13:58:30continuously it will tell okay we are
13:58:32generating something. That's why you
13:58:33have to show something. Streaming means
13:58:35you have to show something on the
13:58:36screen. Okay? Instead of uh just keep
13:58:39waiting the user here. Then better UX uh
13:58:43uh UX for long output such as code. So
13:58:45whenever you are generating any kinds of
13:58:47code, let's say you created a agent that
13:58:49generates the code. So instead of
13:58:51waiting for the entire code generation,
13:58:53you can uh show the streaming. Okay?
13:58:56Like it is uh importing, it is defining
13:58:58the model, it is creating the
13:59:00architecture. So one by one you can show
13:59:02it here. Okay. So this is another user
13:59:04experience we get. Then you can see uh
13:59:06you can uh cancel midway savings uh
13:59:09tokens. That means whenever let's say
13:59:11you are uh chatting with your agents or
13:59:14chatbot and uh you are generating a long
13:59:17form content right and let's say you
13:59:19found uh some kinds of content useful
13:59:22and you don't need uh um like uh the
13:59:25remaining content. So what you can do
13:59:26you can stop you can cancel the midway
13:59:29execution uh to save the token because
13:59:31what happens whenever LLM generates the
13:59:34output it generates as a token right and
13:59:37whenever you're using any kinds of
13:59:39provider let's say open AI or Gemini it
13:59:41charge based on the tokens like how much
13:59:43token you are giving as an input and how
13:59:46much token your model is returning as an
13:59:48output okay to based on the token count
13:59:51it will charge you so let's say I don't
13:59:53need uh some unnecessary information So
13:59:55definitely I can uh stop the execution
13:59:57and I can save my tokens. Okay, this is
13:59:59only possible whenever you are adding
14:00:01these kinds of streaming features. So if
14:00:03you are adding like one short oneshot
14:00:05output that time this is not possible.
14:00:07Okay, then you can inter uh interl UI
14:00:10updates uh uh example show thinking show
14:00:14tool result okay etc. So whenever we'll
14:00:16be creating any kinds of agents so
14:00:18definitely it will be using tools right
14:00:20and whenever it is using tools that mean
14:00:22uh that execution will take some time.
14:00:24First of all tool will be executed and
14:00:26this will fetch the uh informations then
14:00:29it will pass to the LLM. So it's taking
14:00:31some time right that time instead of
14:00:33waiting I can show something in the user
14:00:35interface. Let's say it is right now
14:00:37using this particular tool and uh this
14:00:40tool is uh facing this kinds of
14:00:42information. Okay I can just show this
14:00:44kinds of output to the user so that user
14:00:45feels like okay now my uh application
14:00:48are using some kinds of tools uh so that
14:00:51it will generate the final outputs. user
14:00:53will wait but if it is if you are not
14:00:55showing that so what will happen user
14:00:57will think like okay my application got
14:00:59hang so definitely they will leave your
14:01:01application okay so that's why this
14:01:03streaming is super important and we need
14:01:05the streaming whenever we are getting
14:01:07this kinds of agentic system guys now we
14:01:09have already understood this uh
14:01:11streaming now let's try to understand
14:01:13through the code although I have showed
14:01:14you the code uh implementation before so
14:01:17let me show you so this is the code
14:01:18implementation I showed you but in this
14:01:20video let me show you how things are
14:01:22working. Okay, how we are adding this
14:01:24kinds of streaming features. So for this
14:01:26uh I think you know we have already
14:01:27written this um aentic chatbot back end.
14:01:31So in the back end I already created the
14:01:33entire workflow. So this is our workflow
14:01:35we created and this is our chatbot
14:01:37object we created. Okay, this is the
14:01:38graph. So what I can do maybe I can uh
14:01:41show you
14:01:43uh I will create another file. Let's say
14:01:46I'm going to name it as test.py.
14:01:49So inside that I'm going to first of all
14:01:51import my
14:01:53uh import my chatbot from agentic back
14:01:56end. So from agentic chatbot back end we
14:01:59are importing chatbot. Now see if I'm
14:02:01not using this uh uh if I'm not using u
14:02:06like uh streaming that time I was using
14:02:08inboke. I think you remember I was using
14:02:10inboke and we also need to import this
14:02:13library as well.
14:02:17Yeah.
14:02:22Human message and base message we have
14:02:23to also import
14:02:26H.
14:02:27So let me check again.
14:02:34Then I I need to also pass the
14:02:35configuration as well. So let me copy
14:02:37the configuration.
14:02:40Config should be also passed here. So
14:02:42I'll also import the define the
14:02:44configuration
14:02:46because we're using persistence here.
14:02:48Okay, we have to pass the trade and
14:02:49everything. I think you know that. Now
14:02:51we'll try to replace with that. Yeah.
14:02:55Now this is the code guys. So basically
14:02:57we are using inboke here and if you're
14:02:59using inboke so that means you have to
14:03:00wait for the entire execution to be
14:03:02completed. Let me show you now. Let's
14:03:04say if I stop the execution.
14:03:08Python test.py
14:03:17Now see uh we have to wait for the
14:03:19execution. Maybe I can show you with
14:03:20another question. Generate a blog
14:03:28about Python programming. Now you'll be
14:03:32able to observe.
14:03:39Now see okay you have to wait for the
14:03:41entire execution. So this is not good.
14:03:44Okay now we have to add the streaming
14:03:45features here. So here instead of using
14:03:48invoke uh we'll be using dot stream. So
14:03:52you can write like that chatbot
14:03:57dot stream. Okay
14:04:01stream.
14:04:04Now stream uh takes some argument. uh
14:04:07first of all you have to provide
14:04:10uh the message
14:04:13okay I'll try to provide the message
14:04:20yeah I'll try to provide the message uh
14:04:23now let's say I'll give the same message
14:04:26generate
14:04:31uh block
14:04:35line graph or let's say
14:04:39machine learning.
14:04:41Okay, this is the message. Now the
14:04:43second parameter you have to provide the
14:04:45configuration. Okay, and the third uh
14:04:50parameter you have to provide uh the
14:04:52stream mode. Okay. Now there are
14:04:54multiple stream mode are available. If I
14:04:55go to the documentation as you can see
14:04:58we have update values messes. Okay,
14:05:00custom. Uh so here I want to print the
14:05:02message only. So that's why I'll be
14:05:04using stream mode is equal to message.
14:05:05Okay, because I want to show show my
14:05:07message streaming. Okay, whatever um
14:05:09output I'm getting from my lm, I want to
14:05:12show show this. Okay, that's why we're
14:05:14using this. Now, once it is done, now if
14:05:16I let's say um show you the result. See
14:05:21this stream will return two things. One
14:05:23is the
14:05:25message chunk.
14:05:27Okay, message
14:05:31chunk
14:05:34that means the token. Okay, token output
14:05:37and it will also give you some kinds of
14:05:40metadata.
14:05:42Okay, metadata. But I don't need the
14:05:43metadata. I only need the message chunk
14:05:46and metadata. Okay, so basically this
14:05:49returns a generator object. Let me show
14:05:51you. So I'll give you
14:05:54example response.
14:05:57Now if I print the response.
14:06:05Now if I execute this code
14:06:08python test.py.
14:06:11So this will give you a generator object
14:06:12as you can see. Okay. Stream generator
14:06:15object. And you already studied inside
14:06:17Python. If we are getting the generator
14:06:19object, I can use any kinds of iterator
14:06:21to get the output. And what is the
14:06:23iterator? We can use for loop here.
14:06:25Okay. Uh for loop will try to iterate
14:06:28the output one by one here. Okay.
14:06:30Instead of getting everything in one
14:06:33shot, it will take one by one. So for
14:06:35this I will just write a for loop. So
14:06:37now I can write like that. Instead of uh
14:06:40going through the response, maybe I can
14:06:42write the for loop here only. I think
14:06:44that would be amazing. So for uh it will
14:06:48return two things I told you. One is the
14:06:49message chunk
14:06:55and it will return the metadata.
14:07:00Okay. In chatbot stream okay now I'll
14:07:05give this one H.
14:07:12Yeah. Now here I'll just write a
14:07:14condition
14:07:16if uh let's say message
14:07:20message chunk
14:07:26message chunk
14:07:28um dot content okay I will extract the
14:07:31content only okay if there is a content
14:07:34sorry content
14:07:37content I'll just try to print this
14:07:39content so print
14:07:43message chunk dot content. Okay. And
14:07:45here I will give some other parameter
14:07:47like end is equal to this empty string
14:07:50and uh
14:07:53and I will give this splash is equal to
14:07:54true.
14:07:56Okay, these two things you have to give.
14:07:58If you check the documentation, they
14:07:59have written the same thing. Okay, now
14:08:01let me show you how this output would be
14:08:03generated. Now I again I'll execute my
14:08:05test.py.
14:08:08Now see it is giving you token by token
14:08:10as a streaming output. Okay, I think you
14:08:12saw the difference and that's how we can
14:08:15um implement the streaming features
14:08:17inside lang graph. Okay, I hope you
14:08:20cleared. Now the same thing uh you have
14:08:22to also do in the user interface because
14:08:25user interface uh we created this should
14:08:28also show as a streaming output and how
14:08:31we have done guys uh I think I already
14:08:33written the code. Let me show you. See
14:08:35it is available in the app.py. So here
14:08:37is the code guys. Okay, we written
14:08:39already. Now we are using something
14:08:41called
14:08:43um this one write stream here from
14:08:46streamllet we're using write stream. So
14:08:48if you go to the streaml documentation
14:08:50as you can see stream it has having a
14:08:52chat element. So it is having multiple
14:08:54chat element like chat input chat
14:08:55message start container and there is
14:08:58another one called write stream. Okay.
14:09:00If you see the right stream so they have
14:09:01already written like how to um actually
14:09:04write this particular use this
14:09:05particular right stream. Okay. So we are
14:09:08using this write stream here. Let me
14:09:10show you. We're using this write stream.
14:09:12So inside that we have written the same
14:09:13code. We are um instead of doing the
14:09:15invoking operation, we're doing the
14:09:17streaming operation. We're giving the
14:09:18input config and stream. And we are
14:09:21running the for loop. It is returning
14:09:23two things. Message chunks and metadata.
14:09:25We are only taking the message chunks.
14:09:27Okay. And once we got the message trans
14:09:30what we doing guys we are just writing
14:09:33the stream on the uh streaml streaml
14:09:36user interface and once everything is
14:09:38done we are updating inside this uh
14:09:41message story inside uh streaml session
14:09:43state. Okay this is a simple code we
14:09:45have written now I think this code is
14:09:47clear guys. Okay how I have written. So
14:09:49I think many people has the confusion
14:09:50how these things are working. Now I
14:09:52think this is clear. Now let me show you
14:09:54the final execution. I will clear I'll
14:09:57run my app.py. So streaml run app.py.
How to Add Chat Threading in Agentic Chatbot using LangGraph
14:10:06So this is our app. Now I'll give
14:10:09generate
14:10:12generate let's say
14:10:14code
14:10:16for image classification
14:10:21in Python.
14:10:25Now see
14:10:27okay see streaming output we are
14:10:29getting. So yes guys uh this is all
14:10:31about from this video. I hope you got
14:10:33it. Uh what is the streaming and why it
14:10:35is required and why we have implemented
14:10:37inside our chatbot. So if you check my
14:10:41uh agentic chatbot guys so far we
14:10:43implemented u till here. So here we can
14:10:46perform any kinds of chat operation
14:10:47right now. Okay. And uh you can see it's
14:10:50working and it is also giving you some
14:10:52kinds of streaming response like charge
14:10:54GPT right. So in charge GPT what happens
14:10:56guys? Uh in charge GPT you can resume
14:10:58your conversation with your old trades.
14:11:01Let's say I did some kinds of
14:11:03conversation previously. I can continue
14:11:05anytime. These are the conversations. So
14:11:07let's say this was my previous trades
14:11:09right? So if I open this particular
14:11:11trades I'll be able to see all of my
14:11:13conversation story. Okay. And I can uh
14:11:16resume my chat from here only. Okay. I
14:11:18can resume my chat from here only
14:11:21right now like that I can go to any
14:11:24another trades let's say I will go to
14:11:25this uh
14:11:27the this trades okay so from here only I
14:11:30can do my conversation so this is called
14:11:33trading okay with the help of this
14:11:34trading we can separate out uh each and
14:11:37every topic let's say message okay let's
14:11:40say right now I want to do a
14:11:42conversation related uh uh let's say
14:11:45deep learning let's say I need another
14:11:47uh new session for another topic. Let's
14:11:50say I want to do the conversation
14:11:51regarding let's say NLP. It's like that.
14:11:54Okay. Instead of doing all of the
14:11:56conversation in a single trade in a
14:11:58single session, you can create multiple
14:12:01trades. Okay. And you can do the
14:12:03conversation anytime. You can come here,
14:12:05you can see the older conversation as
14:12:07well with a different different trades.
14:12:09But this kinds of feature is not
14:12:11available inside our agentic chatbot. So
14:12:14in this video what I'm going to do guys
14:12:15I'm going to implement this particular
14:12:17features so that uh you can also get
14:12:20your older trades uh and you can also
14:12:22see all of the uh old trades
14:12:25conversation as well and anytime you can
14:12:27continue your conversation from there
14:12:29only. Okay. So these kinds of features
14:12:31we'll try to add in this particular
14:12:33agentic chatbot in this video. So make
14:12:35sure guys you watch this video till the
14:12:37end. don't miss anything and if you
14:12:39found this content useful please try to
14:12:41subscribe to my channel and hit the like
14:12:43and please try to share it with your
14:12:44friends and family. So instead of
14:12:47talking too much guys let's start the
14:12:48implementation and I'm going to show you
14:12:50how we can add this trading features
14:12:52inside this agentic chatbot. So guys
14:12:55before starting the development first of
14:12:57all I want to show you the final result
14:13:00final demo uh like what are the uh
14:13:03features we are going to add in this
14:13:05particular agentic chatbot. So as you
14:13:07can see we already added this uh trading
14:13:09features inside our aentic chatbot.
14:13:11Previously uh it was a simple chatbot
14:13:14only. Okay there we didn't have any
14:13:16kinds of uh trading features like uh I
14:13:19can't see my older trades right uh it
14:13:22was not there but in the new update as
14:13:24you can see here we have added a
14:13:26separate section. So from here only you
14:13:28can go to your previous conversation. So
14:13:30let's say here I'm doing a conversation.
14:13:33Let's say I'm asking what is Python,
14:13:36right?
14:13:38Uh let's say I will ask
14:13:41my name
14:13:44is Buppy
14:13:50and I'll tell what is Python.
14:13:54Now you can see Python is a highle
14:13:57programming language and blah blah blah.
14:13:58Now if I ask what is my name?
14:14:05Now it is telling your name is BP. Okay.
14:14:07So this is a conversation we have done
14:14:11in this particular trades. As you can
14:14:12see we are using uh unique uh uh ID
14:14:16right to save this particular uh
14:14:18conversation story in this particular
14:14:19trades. Now what you can do like the
14:14:21chart GPT you can start a new
14:14:23conversation here. So I will click on
14:14:24new chart. Now see it will give me a
14:14:27completely new traits here. Now here if
14:14:29I ask what is my
14:14:34name?
14:14:37Okay what is my name? You'll see that
14:14:39I'm sorry I'm a assistant. I do not have
14:14:42access your personal information. Now if
14:14:44I ask my name is Alex.
14:14:50what is
14:14:54ML?
14:14:57Now see it is giving you the response.
14:14:59Now if I ask what is my name?
14:15:06Now it will tell your name is Alex.
14:15:07Okay. Now see this this particular
14:15:09conversation is completely separate from
14:15:10your previous conversation. Now I can go
14:15:12to the previous conversation anytime.
14:15:14Okay. Where I did like my name is By
14:15:17what is Python? Now here I can continue
14:15:19the conversation. Let's say now I'll
14:15:21tell I want to see
14:15:26hello world
14:15:31program.
14:15:34Now see it is giving you the hello world
14:15:36program because we did the conversation
14:15:38related Python. Okay. And here we are
14:15:40doing the conversation
14:15:42uh with the uh help of Buppy. Okay. So
14:15:45here Buppy is doing the conversation.
14:15:47Now even I can go to my previous
14:15:49conversation as well. So this is my
14:15:52previous conversation. This one my
14:15:53previous conversation. Now here you can
14:15:55anytime uh resume the conversation.
14:15:57Let's say um how it helps in
14:16:04AI.
14:16:07See how machine learning helps in AI. It
14:16:10is uh telling you each and everything.
14:16:12Okay. So that's how you can create
14:16:14different different trades and you can
14:16:16see your older conversation as well like
14:16:18chart GPT. So chart GPT does the same
14:16:21thing. It also using trading concept and
14:16:24every time whenever you are doing the
14:16:26chatting operation it is continuously
14:16:28saving your conversation history in a
14:16:30one particular trades and you can uh
14:16:32start new conversation anytime but the
14:16:35older conversation will remain same.
14:16:37Okay. So this kinds of thing guys we
14:16:39have added inside this particular
14:16:41agentic chatbot. Now throughout the
14:16:43entire video I'm going to show you the
14:16:44implementation part. So guys uh this was
14:16:47our uh previous code we have already
14:16:49written. So as you can see this was our
14:16:51previous app and it doesn't have any
14:16:53kinds of uh uh trading related uh uh
14:16:57code although I added the trading as you
14:17:00can see I added the trading but it was
14:17:01hardcoded. So only I was using trade one
14:17:04for all the conversation. Okay that's
14:17:07why this application was simple. Now I'm
14:17:09going to use the same code and we'll be
14:17:12writing the trading features inside this
14:17:14agentic chatbot. So what I can do
14:17:17instead of uh giving the name to app.py
14:17:20maybe I can give another name just for
14:17:22your reference. So let's say u um
14:17:26whenever you want to refer this
14:17:27particular simple code only that time
14:17:29you will be able to get this code from
14:17:31here. Okay. So I can also replace the
14:17:33code in my uh app.py pi but uh uh I
14:17:36think you won't be able to get the
14:17:38previous uh code that time. So that's
14:17:39why I'm going to create a new file. So
14:17:42first of all, let me rename it. So this
14:17:44is let's say
14:17:46simple app.
14:17:48Okay, this is simple app we created. Now
14:17:50I'm going to create another file. I'm
14:17:52going to name name it as app
14:17:55uh trade.
14:18:00Okay, that means uh this uh code has the
14:18:04trading uh trading code. Okay, trading
14:18:06related code, trading related features.
14:18:08Now what I can do, I can copy the same
14:18:10code as it is
14:18:15here. Okay. Yeah. And here this back end
14:18:19code will remain same. The back end code
14:18:21we have written this code will remain
14:18:23same here. You don't need to change
14:18:24anything. The change would be applied in
14:18:26the front end part only. Okay? because
14:18:28in the back end we are only returning
14:18:30the chatbot uh this uh graph object.
14:18:33Okay. So here what I'm going to do guys
14:18:36first of all I need some more library.
14:18:38So let me import. So I need u so here I
14:18:42need u u id. So with the help of this u
14:18:45u id I'll try to generate unique ID so
14:18:48that I can separate out my each and
14:18:50every trades. Okay instead of doing the
14:18:52hard coding. So every time I will
14:18:53generate a unique ID and I'm going to
14:18:55create my trades. Okay. uh first I'm
14:18:58going to create uh one function that
14:19:00will generate unique uh unique uh ID
14:19:04okay unique user ID because every time I
14:19:07need this unique user ID for this
14:19:09particular trading right I already
14:19:11showed you that part so for this let's
14:19:13create a function
14:19:15so this is the function guys I have
14:19:18already created
14:19:19yeah so this function what it does it u
14:19:22generates unique ID uh unique user ID
14:19:26every
14:19:27uh whenever you will execute this
14:19:28function it will give you unique user
14:19:30ID.
14:19:32So after getting this unique user ID uh
14:19:35what I want to do guys I want to
14:19:38um I want to add this uh unique ID
14:19:42inside my trades. Okay. So for this u I
14:19:45can create another function
14:19:51um called add trades. So what this add
14:19:53trades will do uh basically it will add
14:19:56a new trades ID to the conversation
14:19:59list. Okay. So basically this will get
14:20:01the trade ID and where you will get the
14:20:03trade ID we will get from this
14:20:04particular function. First of all it
14:20:06will check this trade ID it is available
14:20:09in the session state or not. Okay that
14:20:11means uh stream session state or not. Uh
14:20:14we'll try to save uh with the help of
14:20:15this chat traits um like key. So if it
14:20:19is not there it will uh try to set my uh
14:20:23trade ID the trade ID it will generate.
14:20:25Okay. So this is a simple function we
14:20:27have created because whenever you will
14:20:29try to initialize your application for
14:20:31the first time there it won't be having
14:20:34any kinds of chat trades right so that
14:20:37time one new trades should be created
14:20:39completely new trades should be created
14:20:42and it will try to append there and with
14:20:44that particular trades only we'll do the
14:20:46conversation then later on if user wants
14:20:48they can create the trades okay as per
14:20:50their requirement now you can see this
14:20:53uh chat trades is not available uh So we
14:20:56have to also create that. So if you just
14:20:58go below. So I think remember we created
14:21:02um message story previously. So here
14:21:04only I'll try to add another one.
14:21:07So after message so we'll just try to
14:21:10write this uh chat threads. Okay. As you
14:21:13can see if chat traits not in session
14:21:16state it will create a empty chat
14:21:18traits. Okay. And this will become a
14:21:21list.
14:21:23And right now we'll be able to we'll be
14:21:26able to um append that particular trades
14:21:29because now this chat trades session is
14:21:32created. Okay. Here only I will also try
14:21:34to add the comments in my previous code
14:21:37as well. So that later on whenever you
14:21:40are uh revising this code I think it
14:21:42would it will be helpful for you. Okay.
14:21:46By seeing the comments only you can
14:21:47understand what this code is doing.
14:21:49Okay. You can see this uh this code
14:21:51actually creates the message story when
14:21:53the app runs for the first time. Okay, I
14:21:55already created previously I think you
14:21:57remember. So once it is done now let me
14:22:01uh add uh the user interface because if
14:22:05you go to the chat GP left hand side you
14:22:07will be able to see all of your uh
14:22:09conversation okay all of the threads. So
14:22:10we'll try to create the same thing here.
14:22:13So for this let me just create a sidebar
14:22:15first of all. So here I'll just try to
14:22:19add a sidebar
14:22:21with the help of streamllet. So I
14:22:23already commented out this is that uh
14:22:26sidebar trading features display the
14:22:28sidebar title. So stidebar.title
14:22:32I just name it as my conversations.
14:22:35Now if I execute my code
14:22:38okay if I execute my code you will be
14:22:40able to see that. system streamllet run
14:22:44uh app
14:22:47trade.py.
14:22:49Okay, this file we are executing. Now if
14:22:52I show you my code, so as you can see
14:22:55guys, this is our uh sidebar we created.
14:22:57So anytime you can open and close it uh
14:23:00like the chart GPT chart GPT also has
14:23:02the same thing. Okay, this is the
14:23:04sidebar. Now here only we'll be adding
14:23:06our trading. Okay. So for this uh let me
14:23:10just uh show you my updated code what I
14:23:13have done. Um
14:23:16I can show you step by step. I think
14:23:18that would be uh best. So what I can do
14:23:21I can just uh quickly show you.
14:23:29So I'll just uh remove these are the
14:23:31code. Okay. My old code and I'm going to
14:23:33show you my updated code. I think that
14:23:34would be amazing.
14:23:40I'll just try to remove all of the code.
14:23:43[clears throat]
14:23:44So, first uh we'll be adding some
14:23:45utility functions. First of all,
14:23:48generate uh trade ID. I already told you
14:23:50it will generate the trade ID every
14:23:51time. And another function I have
14:23:53written uh this will basically add the
14:23:55trade ID where to the session state.
14:23:58Okay. But we have to create the session
14:24:00state. So, let's create all the session
14:24:03state. I'll just try to add all of the
14:24:05session state.
14:24:11So this is my message story session uh
14:24:14session state and this is for my
14:24:20chat uh session state. Okay, chat
14:24:23traits. Okay, that mean this this one.
14:24:26and um
14:24:29um I'm going to
14:24:32create a sidebar here.
14:24:38Sidebar here. Okay. So, this is my
14:24:40sidebar. Now, if I go to my application
14:24:43again, if I refresh
14:24:46now, see it looks like that. Okay. Don't
14:24:48worry about this chat input feature. I'm
14:24:50going to add it. Uh just let me update
14:24:52my uh this code first of all, then I'm
14:24:54going to add. Okay, that that will
14:24:55remain same like we did the previously.
14:24:57Right now, what I'm going to do guys,
14:25:00I'm going to add a new button here. So,
14:25:02I think you remember chat GP also has a
14:25:05button. If you click on this new chat
14:25:07button, it will start a new conversation
14:25:09for you and you will be able to see the
14:25:11old uh trades as well. So, these kinds
14:25:13of features we'll try to add here. So,
14:25:16this is the code. I'm going to tell you
14:25:19about this reset chat what this reset
14:25:21chat will do. But let's try to
14:25:23understand. Uh see this uh creates a
14:25:25button for starting a new conversation.
14:25:27So there would be a button stidebar dot
14:25:30button new chart. And if you click on
14:25:32new chart, see what will happen in chart
14:25:34GPT. Let's say uh let's say I'm inside a
14:25:37trades. Let's say I'm inside this
14:25:38particular trades. Okay, I'm inside this
14:25:40particular trades. Now once I click on
14:25:43new chart, you'll see that one new
14:25:45window will come and all of the previous
14:25:47chart history will be clean up. Right?
14:25:50So for this kind uh this reason I'm also
14:25:52going to write a function called recent
14:25:54reset chat. So whenever user will take
14:25:55the new chat all of the previous
14:25:57conversation would be removed. So for
14:25:59this let's create another function here.
14:26:02I'm going to name it as
14:26:05um
14:26:07reset chat. So after this function maybe
14:26:10I can add
14:26:13okay reset chat. So what it it is doing
14:26:16you can see uh first of all it will u
14:26:18basically generate a new trade id with
14:26:22the help of this function
14:26:24and it will store in the trade ID. The
14:26:26trade ID uh we created
14:26:30uh session state I think session state
14:26:32trade ID is not created. So let me
14:26:33create it quickly.
14:26:38So this is my
14:26:41trade ID. Okay. If trade ID not in
14:26:43session state uh it will create a trade
14:26:45ID and it will take a trade ID from this
14:26:47particular function. Okay, unique trade
14:26:49ID. Now it is resetting and uh what it
14:26:52is doing it is uh setting a new trade
14:26:55ID. Then after that all of the message
14:26:58would be empty. We you can see we are
14:26:59giving empty list. Then after that we
14:27:02are adding this particular trade ID in
14:27:04my session state. Okay, you can see we
14:27:06are using this add trade function and we
14:27:08are adding this trade ID the current
14:27:10trade ID in the session state because
14:27:13whenever I'm inside this particular
14:27:15trade okay I'm inside this this
14:27:16particular trade so all of the
14:27:18conversation should be saved in this
14:27:20particular trades only that's why this
14:27:23thing we are doing so every time we have
14:27:24to track this trade trade ID all right
14:27:27now uh let's say if I go to my
14:27:32application if I refresh now you'll be
14:27:34able to the uh see this new chat. Okay.
14:27:37Now, if I click on this new chat, so it
14:27:39will basically
14:27:41run this code. It will basically run
14:27:43this code and all of the recent uh uh I
14:27:46mean recent conversation would be
14:27:48removed. Okay. And uh uh we have to
14:27:52write this st. If you are doing the
14:27:54reset chat operation, this is
14:27:55recommended. So basically this this will
14:27:57uh return the streaml app to update uh
14:28:00update the interface. Okay. So basically
14:28:02what is happening uh whenever you are
14:28:04doing this uh new chat operation it is
14:28:06resetting after getting the resetting
14:28:08operation it is giving you the new
14:28:09window. Okay. So whenever you are
14:28:12getting the new window st. Return. Okay.
14:28:15This is recommended. If you check the
14:28:17documentation, you'll be able to see
14:28:19that. Okay. Now let's try to add the
14:28:21chat feature. Uh I'll just try to add
14:28:23the updated chat feature. So I already
14:28:26written the code guys. Let me show you.
14:28:29So this is the code
14:28:35and this is the same code guys. Uh only
14:28:37just few update I have done. So here
14:28:39we're taking a chat input from the user.
14:28:42Okay. And whenever user is giving their
14:28:44input, first of all we are appending to
14:28:46the message story. The same thing we did
14:28:48our uh previous code as well. So message
14:28:51story. Uh after that uh we are setting
14:28:55this is a user conversation and content
14:28:57is user input. Okay. And why we are
14:28:59doing this? Because I want to save my
14:29:02conversation story and this is the
14:29:04format to save the conversation story.
14:29:06First of all, you have to define uh what
14:29:08is the role of this conversation. This
14:29:10is user and what is the content of that.
14:29:12Okay. After this, we are showing this
14:29:15conversation in the streamlit user
14:29:16interface. For this, we're taking a chat
14:29:18message. I think remember there would be
14:29:20a um there would be a icon. Okay. User
14:29:23icon. So, we are setting that this is a
14:29:25user icon and this is the user
14:29:26conversation. Okay. And here guys, we
14:29:28are defining the configuration right
14:29:30now. Okay. This is the persistence
14:29:33configuration. This is the trading
14:29:34configuration. Config is equal to
14:29:36configurable. Now trade ID is equal to
14:29:38ST dot session state trade ID. Now we
14:29:41are not taking the hardcoded trade ID.
14:29:43Instead of that see previously we are
14:29:44taking the hardcoded trade ID. We are
14:29:46only giving trade one. But right now
14:29:48there would be a multiple trade. User
14:29:50can create the trades right. So we are
14:29:52taking it from the session state and
14:29:53already session state we have created
14:29:55here. The session state it is already
14:29:57created.
14:29:59Uh session state
14:30:02uh what is that? Yeah, s state trade ID.
14:30:05Now I think trade ID it is available.
14:30:07Yeah, you can see trade ID is available.
14:30:09And how we are getting the trade ID? It
14:30:11is generating by the UI ID. Okay, from
14:30:13here only it is getting generated. Okay,
14:30:15I hope you get it now. Yeah, from here
14:30:20actually we are showing the user uh
14:30:22sorry assistant message. As you can see
14:30:24we are taking this S3 uh chat message.
14:30:28Uh we are taking this is assistant
14:30:30reply. After that we are uh taking the
14:30:33write stream function. I told you in my
14:30:35previous video how stream it streaming
14:30:38works right how we can show the
14:30:39streaming response. So inside that we
14:30:42are generating the responses from our
14:30:44chatbot object. The chatbot we have
14:30:46imported from the back end. Okay as you
14:30:48can see this is the same code guys there
14:30:50is no chance we are using after that
14:30:53whatever message chunk we are getting we
14:30:55are continuously
14:30:57uh writing with the help of write stream
14:30:59function. Okay. And here we're passing
14:31:01the configuration and we are giving
14:31:04stream mode is equal to masses. Okay.
14:31:06And here we're getting one u suggestion.
14:31:08I have to import this AI message. So
14:31:10let's import it quickly.
14:31:16I'll just try to import this AI message
14:31:20after human message AI message. Okay.
14:31:22Because this streaming response should
14:31:23be AI message here. Okay. That's why I'm
14:31:26telling if is instance message chunk if
14:31:29it is like message chunk that means we
14:31:32are getting AI AI reply right so that's
14:31:34why telling this should be IM message so
14:31:36this will only uh show the IM message
14:31:38here then we are saving the complete
14:31:42assistant response in this stream
14:31:43session state in the message story so
14:31:45this code is common I think you already
14:31:46know that yeah this is pretty much clear
14:31:49so after uh this uh part is done guys
14:31:52now what I'm going to do I'm going to
14:31:54simply
14:31:56execute my app. Refresh.
14:32:00Now see guys, you are getting this
14:32:02window. Now if I do the chat operation,
14:32:04let's say hi.
14:32:09See, I'm getting the response. Now I'll
14:32:11tell my name
14:32:14is puppy.
14:32:16Now see previous uh message is getting
14:32:19replaced because I haven't added this
14:32:22code here. I think remember previously
14:32:23also I added this code and this uh
14:32:26loading the conversation history. Okay,
14:32:28we have to load the conversation story
14:32:29every time. So let's load that before
14:32:32the user input. So every time it will
14:32:34load the conversation story message and
14:32:37it will uh write in the stream that user
14:32:40interface as a uh human role and
14:32:42assistant role. Okay, because we are
14:32:45running a for loops every time it will
14:32:47looping through the role. First of all
14:32:50user role will come then assistant role
14:32:52then user role then assistant role and
14:32:53their content. Now let me refresh and
14:32:57again try. So hello
14:33:05my name is
14:33:09Buffy.
14:33:12Okay. Now nice to meet you Buffy. Now
14:33:14see we are able to see the previous
14:33:15conversation but right now what I have
14:33:18to do so let's say if I click on a new
14:33:20chart okay new chart will is coming okay
14:33:23it's completely fine but I am not able
14:33:25to see my older chart that means older
14:33:28trades so now we'll be adding the code
14:33:30related older trades so you can also see
14:33:32the older trades so what I can do guys u
14:33:36I can show you my updated code I already
14:33:37created for this
14:33:40here I can write
14:33:45So this is the code guys I have written
14:33:47display all the conversation trades in
14:33:48reverse order and why I have to uh show
14:33:52in the reverse order. See every time
14:33:53what is happening if you create new
14:33:55trades right? If you create new trades
14:33:58so your
14:34:00uh your u new trades is coming
14:34:04uh new trait is coming at the last.
14:34:06Okay. Because by default Python will add
14:34:09this new traits at the last. Okay. But
14:34:12if you see if I click on new trades
14:34:14every time this new trade should be
14:34:16coming at the recent chart okay at the
14:34:18first uh first uh let's say order. So
14:34:21that's why we are reversing the order.
14:34:23So if my new chart is getting added at
14:34:25the last if I do the reverse operation
14:34:28that means from the last it will come at
14:34:29the first. Okay I think you understood
14:34:31that's why we're doing the reverse order
14:34:33operation. So this is a list we are just
14:34:35doing the reverse order operation
14:34:36because in this session state we have
14:34:38the chat traits. Okay, in this session
14:34:40state we have the chat trades and this
14:34:41is a list and it will continuously add
14:34:44at the last. Okay, let's see if you
14:34:45click on the add new. So new chat will
14:34:48add here. New chat will add here, right?
14:34:52And this has your old chat also.
14:34:55But this will show at at the last but I
14:34:57don't want to see at the last because
14:34:59whenever I'm doing the new conversation
14:35:01I want to see in the recent chat
14:35:03operation that means it will come at the
14:35:05first. Okay, that's why we have to do
14:35:06the reverse operation. So if you perform
14:35:08the reverse operation what will happen
14:35:10this new chat will come here right now
14:35:12okay before the old chat and with the
14:35:15help of that I will be able to make it
14:35:17in the recent conversation. So this is
14:35:19why we are doing this one
14:35:25just a minute let me
14:35:28so this is why we are adding this
14:35:30particular code. So it is going through
14:35:32the entire uh chat trades and uh here we
14:35:36are giving a button because this should
14:35:38be also a clickable object. If I click
14:35:40on this particular traits, it will be
14:35:42able to show my conversation. Okay,
14:35:45that's why we are making it as a button.
14:35:48ST dot sidebar button. So button uh name
14:35:51should be trade ID only.
14:35:54Even you can also uh you can also uh
14:35:57give any message name if you want. Okay,
14:36:00if you want you can also add any message
14:36:02name and uh the key should be trade ID.
14:36:05So once uh button creation is done, we
14:36:08are again saving this trade ID in our
14:36:11current trade because this is the
14:36:12current trade user will do the
14:36:14conversation
14:36:15and we'll load all of the conversation
14:36:18in this particular traits because if you
14:36:20click here see if I click here it is
14:36:22loading all of the conversation I did
14:36:24previously okay from my memory. So I
14:36:27will write a function for this called
14:36:29load conversation.
14:36:31So basically this will load all the
14:36:32previous conversation here.
14:36:36So after this uh reset chat maybe I can
14:36:43write this function. So load
14:36:45conversation this will take the trade ID
14:36:47and I think you remember uh from the uh
14:36:50langraph graph we get the state. Okay.
14:36:52If you call this get state function, it
14:36:54will give you all of the all of the
14:36:57previous conversation. If you want to
14:36:59understand this guys, you have to go
14:37:01through this particular session because
14:37:02here I already explained each and
14:37:04everything. So that's why I'm not going
14:37:05to repeat it again. So this get state
14:37:07function will return you all of the
14:37:08previous conversation. So we are taking
14:37:10all of the conversation and we are only
14:37:12getting the messages. Okay, from the
14:37:14value itself, we're only getting the
14:37:15messages.
14:37:16Okay, so this particular messages will
14:37:20show here. Then we are taking a empty
14:37:23list here. Then we are going through the
14:37:25messages one by one. Then we are trying
14:37:27to separate out the u user conversation
14:37:30as well as the assistant conversation.
14:37:32Okay. So we we are using is instance uh
14:37:36function for this. If you pass any
14:37:38message uh it will automatically tell
14:37:40you whether it is human message or let's
14:37:44say AI message. If it is human message
14:37:46role should be set to the user otherwise
14:37:49role should be set to the assistant.
14:37:51Then after that we are adding inside my
14:37:53temporary message list all of the
14:37:55conversation as a role and content. Then
14:37:58after that we are just updating in my
14:38:00session state and it is uh showing you
14:38:03in the user interface. Okay. Then again
14:38:05we are doing the return operation. Now
14:38:07let me show you. So if I let's say come
14:38:09here refresh.
14:38:12Now see uh if I do any kinds of
14:38:15conversation
14:38:19if I take a new chat now see guys new
14:38:22new chat is getting created and I can
14:38:25see my previous conversation as well.
14:38:26Now let's see if I do another
14:38:28conversation. Hi
14:38:32done. Now I can go to my previous
14:38:33conversation.
14:38:43See I can go to my previous
14:38:44conversation. This is the new
14:38:46conversation. This is previous
14:38:47conversation. Okay. So we have added
14:38:49this particular code. And I'm also able
14:38:51to see my conversation history. Let's
14:38:53see if I've done any kinds of previous
14:38:54conversation. I can see the history
14:38:56because of this code. Okay. This is
14:38:58continuously
14:39:00uh where is that this function load
14:39:02conversation. this loop conversation is
14:39:04continuously fetching the informations
14:39:07because we're running a for uh running a
14:39:09for loop here. Okay. So every time uh
14:39:11this uh message is getting fetched
14:39:18and one more update we have to do
14:39:22uh every time we have to set the current
14:39:24trade to the conversation list. Okay,
14:39:27for this we'll try to add this
14:39:28particular code. Okay, now I think my
14:39:30application is ready. This is a simple
14:39:33uh code we have written only. We're just
14:39:36playing with the trade. Okay, trade ID
14:39:38and for this we're using UI ID. We can
14:39:41also make it as a u readable title like
14:39:44chart JP. Chat GPT actually generates
14:39:46readable title uh uh title. So if you
14:39:48are asking any kinds of question, it
14:39:50will generate title instead of giving a
14:39:52trade ID. We can also do do this
14:39:53particular update. It is also possible.
14:39:56Now let me refresh my app.
14:39:59Okay. So this is the app. My name
14:40:06is BBY.
14:40:11Okay. So basically this conversation is
14:40:13getting saved inside this particular
14:40:14trade. Okay. In this particular trade it
14:40:16is saving. Now I love cricket.
14:40:24Okay. Now if I take new conversation now
14:40:27it is coming as a new uh new session
14:40:30again and this particular session is
14:40:32coming at the first and previous was a
14:40:35previous one it is going at the last
14:40:36because we are doing the reverse
14:40:37operation. Now here I'll tell my
14:40:42name is Alex.
14:40:46I love football.
14:40:54Okay. Now I go I can go to my previous
14:40:56conversation
14:40:58and here I can resume the conversation.
14:41:00What is my
14:41:04uh what is my favorite
14:41:10sport.
14:41:15Okay you can see cricket is the favorite
14:41:17sport. Now I can go to my current trade
14:41:20and here also I can ask what is my name?
14:41:25Your name is Alex. Okay. So that's how
14:41:27you can create as much as trade as you
14:41:29can. What is
14:41:32transformers?
14:41:38Okay.
14:41:39So this is uh telling you about the
14:41:42movie but I can ask what is transformers
14:41:45in AI?
14:41:48Okay, now it is telling you what is
14:41:50transformers in AI. Okay, so that's how
14:41:52guys uh like chart JPT we created the
14:41:54trades. Now we can switch to different
14:41:56different trades and I can resume the
14:41:58conversation. So yes guys, that's how we
14:42:00can add this trading features uh like
Build Permanent Chat Persistence Memory with LangGraph and Database
14:42:02chart JPT. Now if you want you can also
14:42:04change this name to the actual let's say
14:42:07chat title. If you want you can also add
14:42:09inside this code. So I'll try to u give
14:42:12this part uh as an assignment to you.
14:42:14Maybe you can uh add this functionality
14:42:16in this code. Okay, simply you can go to
14:42:18the chat GPT and you can ask uh I want
14:42:21this particular features how should I
14:42:23add? You'll be getting the suggestion.
14:42:25Okay, so just try to add uh this update
14:42:28instead of showing you this uh you uh uh
14:42:32unique user ID maybe you can show chat
14:42:34title like chat GPT the way chat GPT
14:42:37shows okay you can also add this
14:42:38particular things. So we have already
14:42:40integrated this uh chat trading. Uh now
14:42:43we are able to uh continue the
14:42:46conversation uh with our previous chat
14:42:49as well. That means right now I can
14:42:51separate out my uh chat trades. I can
14:42:54create a new conversation. I can
14:42:56continue with my old conversation like
14:42:58chat GPT. So yeah we have already added
14:43:01this uh trading features. So what will
14:43:04happen right now? Let's say if I
14:43:06continue any kinds of conversation.
14:43:07Let's see here I will give hi my name is
14:43:12BP. Okay.
14:43:14So as you can see it is giving you
14:43:16response uh nice to meet you BP how I
14:43:18can assist you today. Now let's say I
14:43:20want to create a new chat like chat GPT.
14:43:22So what I will do I'll just click on new
14:43:24chat and you can see one new trade has
14:43:27created. Okay, new um conversation has
14:43:30created. Now here I will tell hi my name
14:43:34is Alex.
14:43:38See hello Alex how I can assist you
14:43:40today now I can go to my previous
14:43:43conversation where I told my name is BPI
14:43:46even I can continue with my um the
14:43:49current conversation I did right so
14:43:51that's how you can create as much as
14:43:53session you can okay but I think you
14:43:56have observed one thing uh which is if I
14:43:59refresh the application okay let's say
14:44:01if I refresh the application so see my
14:44:04previous conversation is getting erased.
14:44:06Okay, previous conversation is getting
14:44:08removed. So whenever you are refreshing,
14:44:10okay, whenever you are refreshing, that
14:44:12means your RAM is getting cleared. Okay,
14:44:14and all of the conversation is getting
14:44:16erased. And if you close your
14:44:18application as well, let's say if I
14:44:19disconnect from my terminal, so what
14:44:21will happen uh from the RAM itself, it
14:44:23will be removed and again you will be
14:44:25able to see the new chat here. You won't
14:44:27be able to see the older conversation.
14:44:29This is the problem. So yeah uh today in
14:44:31this particular video guys we'll try to
14:44:33understand how we can add the database
14:44:35features inside the agentic chatbot uh
14:44:37so that uh whenever you are refreshing
14:44:39right your agentic chatbot uh you will
14:44:41be able to see the old conversation
14:44:43right now this is the problem. So right
14:44:45now if you perform conversation with
14:44:47your chatbot and uh if you are creating
14:44:50different different let's say chat
14:44:52traits so if you refresh your
14:44:53application or if you close your
14:44:55application it will be removed from the
14:44:56RAM right so these kinds of things we
14:44:58have to fix. So that's how guys we'll
14:45:00try to add uh uh new features inside
14:45:03this agentic chatbot and we'll try to
14:45:05make this agentic chatbot more advanced
14:45:07and uh we'll be learning this particular
14:45:09project. Okay. So if you found my
14:45:11content useful guys please try to
14:45:13subscribe to my channel and please share
14:45:14it with your friends and family and
14:45:17please support me guys. Uh if you
14:45:18support me so definitely I will be
14:45:20bringing this kinds of content more okay
14:45:22on my channel. So uh instead of talking
14:45:25too much guys, let's start with the
14:45:26implementation and uh here uh in this
14:45:29video guys, I'm going to show you how we
14:45:31can integrate database functionality in
14:45:33the persistence memory. So guys, I have
14:45:36already shared the source code with you.
14:45:38It is already available in the video
14:45:40description. So if you open up my
14:45:42previous code guys, I have already
14:45:44written this code as you remember. So
14:45:46there I uh tried to uh uh integrate this
14:45:49trading features inside our agentic
14:45:51chatbot and this is the code we have
14:45:53written right. So this is the entire
14:45:55code and uh the change we have done in
14:45:58the front end uh because you can see
14:45:59this is the front end uh uh front end
14:46:02file and we had another file which is
14:46:04the back end. Okay, in the back end
14:46:05itself I had my um like let's say uh
14:46:09aentic chatbot back end. So here I
14:46:11created the chat node then the uh graph
14:46:14and ages. Okay, each and everything I
14:46:16initialized it here and I was returning
14:46:18as a checkpoint uh sorry chatbot uh
14:46:20graph object. So here uh if you see in
14:46:23this particular backend file here I was
14:46:26using this memory saver okay from the uh
14:46:29checkpoint check checkpo pointer lang
14:46:31graph checkpo pointer so I was importing
14:46:33lang graph dot checkpoint dot memory
14:46:36import in memory saver so if you're
14:46:38using this uh memory saver that means
14:46:40what is happening uh you are storing all
14:46:42of the conversation in the RAM and
14:46:44whenever you are refreshing or closing
14:46:46your terminal it is getting erased okay
14:46:48because RAM is a temporary memory now we
14:46:50have to make it as permanent okay For
14:46:52this we have to use some kinds of
14:46:53database. Now if you visit this lang
14:46:55graph documentation lang graph
14:46:57documentation um uh you will be u you'll
14:47:00be finding like uh uh some database they
14:47:04are suggesting whenever you are creating
14:47:06uh this kinds of persistence memory. So
14:47:09uh if you check the langraph
14:47:10documentation there you will be getting
14:47:12some kinds of database like SQLite
14:47:14database they are suggesting. So
14:47:15skillite database when you can use
14:47:17whenever you are creating the prototype
14:47:18right as of now we are learning uh we
14:47:21are trying to implement this agentic
14:47:23chatbot. So we are in the learning phase
14:47:25maybe we can utilize the SQLite database
14:47:27because this is completely free to use
14:47:29and SQLite database actually basically
14:47:32it will create the instance inside your
14:47:34local storage. Okay. But uh you can also
14:47:37utilize any production uh grade database
14:47:40like postgress is there then um some
14:47:43other database are also there. Okay, you
14:47:45can also utilize that. So going forward
14:47:47whenever we'll try to create production
14:47:49grade actually agentic uh chatbot uh
14:47:51that time I'll try to use these are the
14:47:53database but right now we are in the
14:47:55learning phase. So we'll try to use some
14:47:57kinds of prototype based database. Okay,
14:47:59I can utilize SQLite database because
14:48:01this is this would be lightweight for me
14:48:03and I don't need to take uh any kinds of
14:48:05subscription plan for that. Right? So
14:48:07that's why I'll continue with the SQLite
14:48:09database. So if you uh go to the SQLite
14:48:11documentation SQLite documentation
14:48:16um
14:48:18so this is the SQLite documentation
14:48:20guys. So this is uh basically a
14:48:23database. Uh this is a database actually
14:48:25you can utilize uh with the help of
14:48:27python and uh if you're using this
14:48:30langraph guys lang graph also has the
14:48:32connection with SQLite. Okay for this
14:48:35you have to install one library uh this
14:48:37library uh langraph checkpoint SQLite.
14:48:40Okay. So you have to install this
14:48:42particular library. If you install this
14:48:43library you will be able to use this
14:48:45SQLite uh with your langraph. You can
14:48:48also separately install this SQL light
14:48:50if you are only using Python programming
14:48:52that time separately you can utilize but
14:48:54here we want to utilize with the help of
14:48:56this langraph okay that's why lang graph
14:48:58connection is also there langraph SDK is
14:49:00also there someone I think has created
14:49:02this and published on the pi and we are
14:49:04able to use this um package inside our
14:49:07development okay if you check the
14:49:10langraph documentation guys uh here in
14:49:12the memory section as you can see add
14:49:14short-term memory that means this is the
14:49:16persistence memory as you can see
14:49:17short-term memory
14:49:18trade level persistence. Okay. So here
14:49:20as of now we use this memory saber uh
14:49:23database uh sorry memory saber actually
14:49:26stories uh basically this stores your uh
14:49:28conversation in the RAM and uh you can
14:49:31see uh they are also suggesting for the
14:49:33production. So for production use either
14:49:35you can use postgrace
14:49:37a postgrace it is also production grade
14:49:40database and you can create a postgrace
14:49:42server either you can create a local uh
14:49:45server local host server either you can
14:49:46create a cloud-based servers okay so um
14:49:49any kinds of cloud you can set up this
14:49:51postgrace either you can use um like
14:49:53render either you can use uh AWS GCP
14:49:57anywhere you can set up this uh uh
14:49:59postgra server and you can connect with
14:50:01your langraph okay this is possible so
14:50:03uh That's how you can also use MongoDB.
14:50:05Uh you can also connect with MongoDB.
14:50:07You can also connect with radius. You
14:50:09can also connect with Oracle. Okay,
14:50:10that's how it is having different
14:50:11different database connection. But
14:50:13whenever we are creating prototype, uh I
14:50:15think this SQL light is fine for us
14:50:17because we can u set up inside our um
14:50:20local storage only. Okay, I don't need
14:50:22to take any kinds of separate server for
14:50:24that. Okay, that's why I'm using this
14:50:26SQLite. Uh so uh database doesn't
14:50:29matter. You can use any kinds of
14:50:30database. Uh anything will work. But
14:50:32only you just need to know the um like
14:50:35connection. Okay, integration how we can
14:50:36integrate the database. Okay, right now
14:50:38I'm integrating the SQLite. Maybe you
14:50:41can also integrate any other database.
14:50:43Only you just need to get this
14:50:44connection string. Okay, let's see if
14:50:46you're uh setting up this database in a
14:50:48server. You just need to get this
14:50:50connection string. Okay, if you get this
14:50:51connection string, you can check the
14:50:52documentation and you can copy this code
14:50:54and you can change it any time. Okay,
14:50:56it's up to you. So here the main change
14:50:59guys I have to do in the back end file
14:51:01because in the back end file I am using
14:51:03this memory saber and instead of memory
14:51:05saber I have to use my uh this one uh I
14:51:09have to use my um um database. Okay so
14:51:12for this uh I have to first of all
14:51:14install this library uh where is that
14:51:18uh yeah the install this library. So
14:51:19I'll copy this command or I can copy the
14:51:24name
14:51:26and I will add inside my requirements.
14:51:30Now let's install it here
14:51:36install
14:51:38at requirement.txt.
14:51:41So for me it is already satisfied
14:51:42because I installed it previously but
14:51:44for you it may take some time. So once
14:51:47installation is complete guys
14:51:50uh I'll open up my
14:51:53backend file and in the back end itself
14:51:56I'll try to change that change that. So
14:51:59here what I'm going to do um
14:52:04I'm going to
14:52:08um should I change in the same file or
14:52:10should I create a new file. uh if I
14:52:12change in the same file then you will be
14:52:14able to uh you won't be able to get the
14:52:16older code. So what I can do maybe I
14:52:18can't um
14:52:21I can create another file. Okay.
14:52:26So I'll create a same file. I'll just
14:52:28rename it aentic chatbot
14:52:33um back end
14:52:38here. I'll just try to add DB back end.
14:52:43Okay, DB back end means uh it has the
14:52:45database integration. Okay. Uh that's
14:52:48how you will be able to see the previous
14:52:49code as well. Okay. Yeah, I think this
14:52:51is fine. Now here uh instead of this
14:52:54memory saber, we have to import this uh
14:52:57SQLite saber. So from lang graph
14:53:00checkpoint here you have a uh class
14:53:03called SQLite. Okay. And instead of
14:53:07memory server, we have to import SQLite.
14:53:10SQLite saber.
14:53:15Okay, SQLite saber. So you have to
14:53:17import that. So once it is done now,
14:53:20I'll just go below and uh here you can
14:53:22see I created a checkpoint object and I
14:53:24use this memory saber. Instead of memory
14:53:26saber, I will use my SQLite saber.
14:53:30SQLite saber. Okay, this class. Now this
14:53:34SQLite saber takes a connection object.
14:53:36Now you have to initialize the
14:53:37connection object. Database connection
14:53:38object. Basically you will be connecting
14:53:40with the SQLite uh database. So for this
14:53:43uh you have to import this SQLite
14:53:46library. import
14:53:49SQLite 3. Okay. SQLite 3. So this is
14:53:53already available inside Python. Then
14:53:56after that here I will create a
14:53:58connection object. So to create the
14:54:00connection object guys uh you just need
14:54:02to initialize this SQLite 3. Then there
14:54:06is a function you have to call called
14:54:08connect. Okay connect and inside that
14:54:12you have to give a first parameter which
14:54:15is database. You have to initialize the
14:54:17database. Okay. So here basically this
14:54:20SQLite creates the database object
14:54:22inside your local storage only. That
14:54:24means inside your project folder only it
14:54:26will create a database. Okay. Uh it will
14:54:27create a DB file. So you have to give
14:54:29the DB file name. So here I'm going to
14:54:31name this file as chatbot DB. Okay. And
14:54:35uh here you have to give another
14:54:37parameter which is check same trade is
14:54:39equal to false. Okay. Why we have to
14:54:40give this particular parameter? Because
14:54:42I think you remember we are using the
14:54:44trading concept, right? Tra uh chat
14:54:46trading concept. So every time uh user
14:54:50uh is creating separate trades and they
14:54:52are doing the conversation and uh by
14:54:54default actually scaleite doesn't
14:54:56support uh actually multi-rading that
14:54:58means you can't uh apply the trading uh
14:55:01you can't create a different trades in
14:55:03this Qite once you have created one
14:55:05particular session you have to continue
14:55:07uh the uh the same execution in that
14:55:09particular session only okay by default
14:55:11this parameter basically it's true right
14:55:13but if you make it as false then SQLite
14:55:15will try to give you the access for the
14:55:17trading concept. That means you can do
14:55:20the multiple trading chart. Okay, that
14:55:22means you can store uh your checkpoint
14:55:24in a multiple trades. Okay, this will uh
14:55:26basically allow that particular option.
14:55:28That's why we have given uh check uh
14:55:30same trades is equal to false. Okay, I
14:55:33hope you cleared. So this is basically
14:55:34here you will be getting a connection
14:55:36object. So I'm going to store inside a
14:55:37variable. Let's say this is connection
14:55:38object. Now this connection object you
14:55:40have to pass inside this SQL lightsaber.
14:55:43Okay, you have to pass inside this SQ
14:55:44lightsaber. So once you have done that
14:55:46uh now you will be getting the
14:55:48checkpoint. Okay. Now this checkpoint is
14:55:50not a simple checkpoint. It will not
14:55:52store your conversation. It will not
14:55:53store your checkpoint inside the RAM.
14:55:56Okay. Instead of that it will save the
14:55:57conversation or checkpoint inside a
14:56:00storage service inside a database
14:56:02storage which is chatbot DB. Although
14:56:05this storage service will create inside
14:56:06your uh computer storage only. But this
14:56:10is not storing inside a RAM. Okay. it
14:56:12will store as a file and we know that
14:56:14unless and until we are not uh deleting
14:56:16the file this file will be available
14:56:17inside my computer. If I turn off my
14:56:20computer as well this file will remain
14:56:21same. Okay, this is the main benefit
14:56:23here. So once we have done that guys uh
14:56:25the same code you have to write here. Uh
14:56:27no need to change anything. Now let me
14:56:29show you whether it's working or not. So
14:56:32here uh maybe I can test this file. So
14:56:35for this let's do the invoke operation.
14:56:38uh so here uh what I'm going to do guys
14:56:40I'm going to just uh
14:56:42do the invoke operation so response is
14:56:45equal to yeah so I have uh written like
14:56:48that so I just created a config because
14:56:50you know that we're using persistence
14:56:52memory and we have to pass the config
14:56:53whenever we're doing the invoke
14:56:54operation so here uh by default I have
14:56:57taken this default rate I have just done
14:56:59hard coding operation and we are
14:57:02invoking and we're giving the message
14:57:04hello how are you or let's say I'll just
14:57:06give uh
14:57:08my name is BP.
14:57:12Okay. And we're passing the
14:57:14configuration and this will give you the
14:57:15response. We'll try to print that as
14:57:17well. Okay. Now see if I execute what
14:57:19will happen. Uh you'll be able to see
14:57:21one chatbot. DB file would be created
14:57:23here. So Python
14:57:26um agentic chatbot
14:57:29DB backend, right? DB backend.py. If I
14:57:31execute,
14:57:34see chatbot. DV has created and we are
14:57:38getting the response as you can see I
14:57:39given my name is BP and my AI message
14:57:43that means my uh agent has replied hello
14:57:45BP how I can assist you today and some
14:57:48other let's say metadata informations we
14:57:50are getting okay now you can see one uh
14:57:52chatbot uh DB has created you can also
14:57:56visualize that okay it is also possible
14:57:58for this you have to install one
14:57:59extension called SQite
14:58:03viewer
14:58:05SQLite VR. Okay, I have already
14:58:07installed this uh extension inside my VS
14:58:09code. Uh if you don't have just try to
14:58:11uh install that and you can see this is
14:58:13the um this is the publisher Florian uh
14:58:16clam clamper. Uh make sure you install
14:58:19the same version. Okay, once you have
14:58:21done that uh you just need to double
14:58:23click on this uh chatbot DB and you will
14:58:26be able to see this
14:58:29uh checkpoint. It has saved in the
14:58:30memory as you can see uh sorry not
14:58:32memory in the database as you can see.
14:58:34Okay. Now you can see it has uh stored
14:58:37my trade uh checkpoint and this is the
14:58:39trade ID. Okay. We have given default
14:58:41trade as you remember we have given uh
14:58:43what is that chatbot back end. Okay. Not
14:58:46this one. Yeah this one we have given
14:58:48the default trade. Okay. Now you can see
14:58:49default rate. Now you can ask me why
14:58:51this uh three three time it is coming
14:58:53because as per our workflow guys the
14:58:56workflow we have created it has three
14:58:58checkpoint uh uh one checkpoint at the
14:59:00start uh start position uh second
14:59:03checkpoint in the uh chat node position
14:59:06and other one is the end position okay I
14:59:08think I already told you about this
14:59:09right uh in my uh this video uh
14:59:12persistence video I already told you
14:59:13about that right so please go through
14:59:15the persistence video if you don't
14:59:16understand the checkpointer concept like
14:59:18how many checkpointer uh would be
14:59:21available uh in which node it would be
14:59:23available each and everything I have
14:59:24discussed here. So here we are having uh
14:59:26three layer okay three layer inside uh
14:59:30this uh uh sorry three three node inside
14:59:33our uh agentic chatbot that's why three
14:59:36time this uh um checkpoint is getting
14:59:38created and all of the checkpoint ID as
14:59:41well as the checkpoint uh some meta
14:59:44information is also available okay and
14:59:46if you want to see the checkpoint guys
14:59:47directly you can click here so if I
14:59:49click here you'll be able to see the
14:59:51data now this data uh it stores
14:59:54basically in a binary format it's not
14:59:56readable properly but I think some of
14:59:58the message you can still able to
15:00:00understand like my name is BP okay I
15:00:02have given uh now let me show you
15:00:04whether it is able to uh store my
15:00:07checkpoint inside my database or not so
15:00:10let's say if I re-execute my um back end
15:00:14uh whether I will be able to see my old
15:00:16uh old conversation or not let's say I
15:00:18given my name is BP okay so this uh uh
15:00:21this checkpoint would be available or
15:00:23not okay so For this maybe I can just
15:00:26give a separate name here. Let's say
15:00:28Alex I will give. And uh what you can do
15:00:31you can also change the trade ID if you
15:00:32want. Let's say I will give default
15:00:34trade one. Okay. Now if I reexecute my
15:00:40back end.
15:00:43Okay. Now if I open my database um I
15:00:46have to refresh
15:00:48this.
15:00:50Okay. Now see another trade got created
15:00:52and still my previous trade is available
15:00:55here. Okay, previous trade is available
15:00:57and in the response also you can see my
15:01:00name is Alex and this is a separate
15:01:02trade it is coming. Okay, so that's how
15:01:04guys we have seen it is able to store my
15:01:08checkpoints. It is able to store my
15:01:11conversation inside my database. Okay,
15:01:14amazing. Now uh this is ready. Now we
15:01:17have to add uh we have to integrate this
15:01:19thing inside our front end app. Uh
15:01:21because right now we tested inside the
15:01:23back end file only but I have to add
15:01:25inside my front end. So what I'm going
15:01:27to do guys I will open up my front end.
15:01:29So this is the front end uh app trade or
15:01:32maybe I can create another same file.
15:01:35I'll just try to copy and paste
15:01:39and I'll just rename it app
15:01:43uh
15:01:46DB.
15:01:50Okay. So with the help of that you can
15:01:52understand um like this is uh this is
15:01:55actually database, this is trading, this
15:01:57is simple app. Okay. You can understand.
15:01:58So DB means this this has the uh
15:02:01database uh actually update. Now see
15:02:03here you don't need to change uh uh I
15:02:05mean um uh in in all the code only just
15:02:09change you have to do uh here in the
15:02:11chat uh uh chat traits okay so whenever
15:02:14I was uh actually creating this uh
15:02:17session state in the uh streaml right
15:02:20there I was uh using simple list only
15:02:23okay and whenever you are using simple
15:02:25list that time what is happening if I am
15:02:27refreshing my application and it is
15:02:30re-executing from the beginning and this
15:02:32particular ular uh list is getting
15:02:34created again and all of the data we had
15:02:37inside the list it was getting erased.
15:02:39Okay, this is this was the problem. So
15:02:41instead of uh taking this uh simple list
15:02:44here. So here I have to uh connect my
15:02:48database. Connect my database means in
15:02:50the back end I am already storing my
15:02:53checkpoint inside my database inside my
15:02:55SQLite database. So what I'm going to do
15:02:58uh instead of uh instead of actually uh
15:03:01u instead of actually giving a simple
15:03:03list here I'll try to load my uh all of
15:03:06the trades okay from my database only
15:03:09and I will just try to provide a list
15:03:11here. Okay. So for this uh in my backend
15:03:14code I'll just try to do a simple uh
15:03:17simple modification. I'll remove this
15:03:20code. It's not required. So here I'll
15:03:22just do a simple modification.
15:03:25Uh let me show you the modification.
15:03:28Yeah. So here I'll just try to write a
15:03:30function here.
15:03:33I'm going to name it as uh get
15:03:38uh all trades.
15:03:43Okay. Get all trades.
15:03:48So here uh I'll just try to um first of
15:03:51all show you this one.
15:03:53uh see uh first of all I will write a
15:03:56script then I'll just try to convert to
15:03:58a function otherwise I think you might
15:03:59get some difficulties so here uh first
15:04:02of all I'll write my checkpoint
15:04:08h checkpoint now in see checkpoint
15:04:11object is nothing but it's a database
15:04:13object right now we are using SQL
15:04:14lightsaber so it has a function the
15:04:17function name is list okay list so if
15:04:19you give uh give this function call this
15:04:21function list And uh if you execute so
15:04:24what will happen basically it will
15:04:26return you uh how many trades right now
15:04:28you are having inside the database but
15:04:31inside this list param uh list function
15:04:34you have to provide a parameter either
15:04:36you can tell okay I need uh I need let's
15:04:38say information about my default trades
15:04:40one so you have to give this name here
15:04:42okay you have to give this name here why
15:04:44is that uh here you have to give this
15:04:47name here you can give the trade name
15:04:49here but I don't want to give the trade
15:04:51name any specific trade trade name I
15:04:52want to get all of the trade right for
15:04:54this you have to provide none here so
15:04:56basically we're telling I don't need any
15:04:58specific trade I need all of the trade
15:05:00informations okay now see this will
15:05:02return you uh this will return you the
15:05:04trades
15:05:08trades okay
15:05:11uh I'll give equal sign now if I print
15:05:14that
15:05:19okay okay print that print all of my
15:05:21trades
15:05:23Now let's execute this file again.
15:05:28Okay. So this is uh giving you a
15:05:30generator object and you know that if
15:05:32you're getting a generator object so
15:05:33what you can do you can run a for loop
15:05:35on top of that. So for uh checkpoint
15:05:42in checkpoint
15:05:45or let's say trade
15:05:52or let's say I'll just write right trade
15:05:56in trades. Okay.
15:05:59uh once you have done that or you can
15:06:01directly write uh uh write like that
15:06:03let's say instead of writing two line I
15:06:06can directly run a for loop for
15:06:13for checkpoint in checkpointer
15:06:16I think this is also checkpoint right
15:06:20yeah checkpoint in checkpoint list okay
15:06:24then after that um
15:06:27uh what I'm going to do I'm going to
15:06:28just uh print my checkpoint
15:06:40both name is same. Okay. So what I can
15:06:42do I can maybe
15:06:45write like that security. Okay. That
15:06:47means checkpoint.
15:06:50Now if I
15:06:53reexecute
15:06:55now see guys uh here we are getting all
15:06:57of the trade right now it is available
15:06:58inside my uh inside my
15:07:02database as you can see and uh here we
15:07:05are getting lots of trades because if I
15:07:06open my chatbot we are getting uh six
15:07:09trades right now and why six six trades
15:07:11because every time if you execute the um
15:07:14execute the graph it will generate three
15:07:16three checkpoint why I told you because
15:07:19our uh How would actually workflow
15:07:21having three checkpoints? So in every
15:07:23conversation, every execution three
15:07:25checkpoint would be available. Okay,
15:07:27three checkpoint would be available. So
15:07:28this was the first trade and this was
15:07:30the second trade. We executed two times
15:07:31that six six times is available. Okay,
15:07:33so all of the six trades you are getting
15:07:35here. Okay, but uh here I uh whenever I
15:07:39will extract that so this would be a
15:07:41kinds of duplicates to us. I I will only
15:07:45track the unique trades here. Okay,
15:07:46let's say here I how many unique trades
15:07:48I'm having. uh default trade one and
15:07:50default trade only two units okay
15:07:52otherwise everything is repetitive one
15:07:53so I'll also try to handle this part as
15:07:55well so once we are getting all of these
15:07:58uh this uh this actually checkpoints now
15:08:01uh from the checkpoint only I only need
15:08:03this um
15:08:05config
15:08:08config
15:08:11now if I reexecute my terminal
15:08:16now I'm getting the config only okay now
15:08:18from the config I I need this trade ID
15:08:20only. First of all, I need to go to the
15:08:22configurable.
15:08:24So this is a uh this is actually
15:08:26dictionary right dictionary. So I will
15:08:28give the key
15:08:32configurable.
15:08:36Now again we are getting another
15:08:37dictionary and here we have the trade
15:08:39ID. So I only need to extract the trade
15:08:40ID.
15:08:48Now see I'm getting all of the trade but
15:08:51uh I'm getting repetitive trades. Okay,
15:08:53same uh same actually name again and
15:08:55again but I only need the unique one. So
15:08:57for this I think you know um set right?
15:09:00Set inside Python. So what what set does
15:09:03sets basically um will give you the
15:09:06unique uh unique actually name. So here
15:09:09I'll take a set. I'll just try to create
15:09:12empty sets and I'm going to name it as
15:09:15all trades.
15:09:17Okay. And whenever I'm getting my
15:09:20trades, I'll just try to add inside my
15:09:22trades.
15:09:25Sorry. Uh I'm going to add inside my
15:09:30um set.
15:09:33So there is a add function we can use
15:09:34for this. H
15:09:38then uh I'll just try to print my
15:09:42alls right now.
15:09:47Now if I execute
15:09:51now see I'm only getting trade one and
15:09:54my trades. Okay. Uh that means the
15:09:56unique one. Now I have to provide as a
15:09:59list. Okay. I have to uh give as a list
15:10:02here because here um uh the session
15:10:04state we created it it it takes a list
15:10:07right but here I'm getting a dictionary.
15:10:09As you can see here I'm getting a
15:10:10dictionary. I'm uh returning as a
15:10:12dictionary. So what I can do I can
15:10:13convert it to the list. So instead of uh
15:10:17printing um this I will just try do the
15:10:20type type conversion operation
15:10:24just try to convert to the list. Now if
15:10:27I execute
15:10:29now see it is a list right now. Okay.
15:10:32Now simply I'll just I'll just try to
15:10:34write inside a function. So I'm going to
15:10:37uh name this function as def get
15:10:42all traits.
15:10:44Okay. And all of the code I'm going to
15:10:46write inside that.
15:10:52Okay. Instead of printing, I'll just uh
15:10:54do the return operation.
15:11:00So everything is fine. Now this function
15:11:03basically will return you uh all the
15:11:05threads okay from the database itself.
15:11:08So now uh here uh in the app DB
15:11:13whenever you are importing this chatbot
15:11:14right uh so right now we have to import
15:11:17from the agentic chatbot DB back end.
15:11:19Okay instead of the simple uh aentic
15:11:23chatbot back end because we are using DB
15:11:25DB back end right now we have to import
15:11:27chatbot as well as the get all trades.
15:11:31Okay, this function we have to import.
15:11:33Now, simply you just need to call this
15:11:36function here. Whenever you are uh
15:11:39initializing this uh chat threads,
15:11:41instead of giving the simple uh list
15:11:43empty list, you will give this function
15:11:46name. Okay. So, what this function will
15:11:47do, it will get all of the trades and it
15:11:50will store in line inside my chat
15:11:51threads. Okay. So, this particular um
15:11:54code is uh sorry, this particular uh
15:11:56data is coming from my back end from my
15:11:59database. Okay, that's how. So if you
15:12:01restart your application as well, it
15:12:03will not uh effect on my app because
15:12:06every time this function is getting
15:12:08executed from my back end and it has the
15:12:10connection with my checkpointer and
15:12:12checkpointer is connected with my
15:12:14database, right? Chatbot db. So every
15:12:16time it will open the chatbot db and it
15:12:18will get how many trades you are having
15:12:20only this part will return here. Okay,
15:12:22this part will return here and after
15:12:24that we are just passing it here. That
15:12:25means if I'm refreshing my page, if I'm
15:12:28closing the application, it doesn't
15:12:29matter. Every time I'm extracting my
15:12:31trades, I'm getting my trades, I'm
15:12:32facing my trades from my database only.
15:12:34But previously, I was doing inside my
15:12:36memory because I was using simple list.
15:12:39And simple list only creates the
15:12:40instance inside the RAM. Okay. And if
15:12:43you refresh your RAM would be getting
15:12:45cleared. I hope you got the concept
15:12:47guys. Okay. Now let's try to execute and
15:12:49see whether it's working or not. So here
15:12:51I'll open up my terminal.
15:12:53Clear. Then I'll just try to run my app.
15:12:56So streaml
15:12:59run
15:13:00app
15:13:02db.py.
15:13:07Now see guys uh you you can already see
15:13:10uh I already created some trades right
15:13:13here. Uh manually I created some trades
15:13:15and these trades is also getting uh load
15:13:18here. You can see I did some
15:13:19conversation like Alex then my name is
15:13:21BP and this is the current trade right
15:13:24now. So what I can do maybe I can delete
15:13:25my database and do start a new
15:13:27conversation. I'll just try to delete
15:13:30it.
15:13:32Okay, it will not getting delete because
15:13:34it is running in the app right now. I
15:13:36can try
15:13:41delete
15:13:45some temporary file also came. I'll just
15:13:47try to delete. Okay, now I'll freshly
15:13:49execute my app.
15:13:54H. Now let's do the conversation.
15:13:57Hi, my name is By
15:14:05a
15:14:06teacher.
15:14:11Okay, great. Now I'll create a new chat.
15:14:15I'll tell, hi, my name is
15:14:19Alex.
15:14:21I am a learner.
15:14:30Okay, done. Now if I uh click my
15:14:32previous uh conversation, now you can
15:14:34see this is my previous conversation and
15:14:35this is my current conversation. Now the
15:14:37best part is that if I refresh my app,
15:14:39right? See, still this conversation
15:14:42remains same. Okay. Now if you also
15:14:44close your app, let's say I will close
15:14:45my app from my terminal. See it's
15:14:47closed. Okay. And I closed my
15:14:49application. Okay. Okay, I close my
15:14:50application. Now if I restart my
15:14:52application, see if I restart my
15:14:54application. Now, still it will be able
15:14:56to load my previous conversation. And
15:14:59anytime I can continue the conversation,
15:15:01let's say here, I'll just try to
15:15:03continue the conversation. Who am I?
15:15:10See, it is uh giving you you are Alex, a
15:15:13learner who is seeking knowledge and
15:15:14growth blah blah blah. Okay. Now I can
15:15:16also do the conversation here only. Who
15:15:21am I?
15:15:24See, you are BYP, you are a teacher, you
15:15:26are you enjoy helping students learn and
15:15:28grow in their knowledge and skills.
15:15:30Okay. So yes guys uh that's how actually
15:15:33we can add the permanent persistence
15:15:35memory uh right now inside our agentic
15:15:38chatbot and now this is like more
15:15:40powerful uh actually it will not erase
15:15:43your conversation. It will not erase
15:15:44your checkpoint if you restart your
15:15:46application like chat GP like if I open
15:15:48my chat GPT right anytime and I can
15:15:51anytime I can see my previous chat
15:15:53previous trades as well okay if I close
15:15:56the app also if I turn off my computer
15:15:57also if I disconnect my internet
15:15:59connection also still these are the
15:16:01things would be common these are the
15:16:03things would be available because
15:16:04they're using p permanent persistence
15:16:06memory okay they're using some kinds of
15:16:08database whether they're using postgrace
15:16:11whether they're using MongoDB doesn't
15:16:13matter But they're using some kinds of
15:16:14database because of that this thing is
15:16:16permanent like our application. Okay, I
15:16:19hope you are getting it guys. Okay. So
15:16:21yes guys, that's how we can uh slowly
15:16:23slowly make this particular chatbot more
15:16:26advanced and uh in my next video uh I'm
15:16:30going to show you some more uh advanced
Monitor Your Agentic Chatbot with LangSmith & LangGraph
15:16:32features guys. Uh we uh will be adding
15:16:34inside this aentic chatbot and we'll try
15:16:36to make it more powerful. Okay. And for
15:16:39this guys please try to complete all of
15:16:41this video uh if you want to uh uh
15:16:43implement this kinds of project because
15:16:45going forward I have lots of plan I will
15:16:47be bringing lots of project here. Okay.
15:16:50So for this definitely you have to
15:16:51understand all of this concept. Okay. So
15:16:53yes guys this is all about from this
15:16:55video. I hope you liked it and you have
15:16:57understood the entire implementation. If
15:16:59you found my content useful please try
15:17:01to subscribe to my channel, hit the like
15:17:03and please share it with your friends
15:17:04and family. And all of the code I will
15:17:06share in my description from there you
15:17:07can download. So guys in this video
15:17:09we'll be learning one very important and
15:17:12interesting concept uh called
15:17:14observability.
15:17:15So I think you have already heard of
15:17:17these kinds of word like observability
15:17:20monitoring tracing okay of agentic
15:17:22application or any kinds of GNI powered
15:17:25application. See we use this
15:17:27observability monitoring tracing not
15:17:29only in agentic application uh but also
15:17:32we use this kinds of concept in any
15:17:35kinds of LM powered application. So
15:17:37whenever you are implementing any kinds
15:17:39of LLM powered application with the help
15:17:40of lang chain or lang graph or any kinds
15:17:44of framework this observability
15:17:46monitoring tracing is super important
15:17:48there okay without that you can't
15:17:51actually debug monitor and evaluate your
15:17:53application this is not possible so for
15:17:56this observability guys we can use one
15:18:00uh very interesting and powerful tool
15:18:02called lang okay so what is this
15:18:05langismith langismith is a uh
15:18:07observability monitoring uh tool uh it
15:18:10is created by langin and uh with the
15:18:12help of that actually we can monitor any
15:18:14kinds of lm powered application whether
15:18:16it's agenti whether it's any kinds of
15:18:18rack system okay any kinds of
15:18:20application we can monitor here real
15:18:23time we can monitor here okay so first
15:18:25of all let me give you the idea what is
15:18:27this langismith is and why it is
15:18:29required then um we'll try to see the
15:18:31practical demo how we can observe how we
15:18:34can monitor our entire agentic chatbot
15:18:36with the help of this languid. Okay,
15:18:38each and every integration [snorts] I'm
15:18:40going to show you guys and trust me guys
15:18:42uh if you learn this concept I think uh
15:18:45uh it would be very helpful for you
15:18:47whenever you are creating production
15:18:48grade uh uh agent application because in
15:18:52productions uh whenever you are creating
15:18:54this kinds of system there would be lots
15:18:55of bugs there would be lots of issues
15:18:58and uh you can trace everything in a
15:19:01single platform with the help of this
15:19:02lang this is super important guys so as
15:19:05you can see guys uh langismith is a
15:19:06debugging monitoring and uh evaluation
15:19:09platform for application uh builts with
15:19:12LLM and AI agents. It is made by
15:19:15Langchen team but it can also work with
15:19:18application that do not use langen.
15:19:20Okay. So I already told you this
15:19:22langismith is uh let's say it is
15:19:24developed by Langchen but if you are not
15:19:26using any uh lang let's say framework
15:19:28inside your application development
15:19:30still you can use this lang with other
15:19:32framework integration as well. Okay it
15:19:34has all kinds of integration. So let's
15:19:36try to understand why this is useful. So
15:19:39whenever uh you are creating any kinds
15:19:41of chatbot or any kinds of let's say
15:19:43agentic powered application or any kinds
15:19:46of LM powered application there you
15:19:48perform some kinds of step some kinds of
15:19:50operation right let's say user can sends
15:19:53the questions then in between you can um
15:19:56construct the prompt then you can
15:19:58perform the LM call if you're
15:19:59implementing any kinds of agents that
15:20:01will use any kinds of tool or database
15:20:03okay then it can also use memory and
15:20:05checkpointer for the retriever then it
15:20:07can give you the final responses. So
15:20:09that means in between there are some
15:20:11hidden operations are happening but this
15:20:13is not visible to you. Okay. If you're
15:20:15writing only the code if you're not
15:20:18monitoring the entire uh if you're not
15:20:20let's say tracing the entire application
15:20:22this part is invisible to you.
15:20:25Okay. So that's why you can see lang is
15:20:28a debugging monitoring and evaluation
15:20:29platform for application building built
15:20:32with large language model or AI agents.
15:20:34Okay. because inside all of this
15:20:36application this hidden operation
15:20:38happens. Okay, this hidden operation
15:20:40happens. So if you're using Langismith
15:20:42so what will happen? Um Langismith uh
15:20:46records this complete execution as a
15:20:48trace. That means whatever execution you
15:20:50are doing here. Okay, Langismith records
15:20:53this complete execution as a trace.
15:20:55Okay, it will u u record all of the
15:20:57execution as a trace allowing you to
15:20:59inspect every step including inputs,
15:21:02outputs, error, execution time, token
15:21:04uses, tool calls and model behavior.
15:21:06Okay, this is super important guys. Uh I
15:21:08think by the definition itself you can
15:21:10understand whatever hidden operation you
15:21:12are executing okay whatever things are
15:21:14happening in between everything l speed
15:21:17can record as a trace okay in that
15:21:19platform itself okay so that anytime you
15:21:22can see the input output errors
15:21:24execution time token uses tool call
15:21:26model behavior each and everything
15:21:28should be visible to you in a single
15:21:29platform okay now as you can see for
15:21:32your langraph agentic chatbot langismith
15:21:35can help you that means the application
15:21:36we are developing right now. So here uh
15:21:39this langismith
15:21:41can help us for uh finding why an agent
15:21:44selected the wrong tool. Let's say uh
15:21:47you are running your agents and it has
15:21:49selected a wrong tool. It is giving you
15:21:51some kinds of other responses but you
15:21:53don't know why okay why it is uh giving
15:21:55you this kinds of output why it is
15:21:57selecting the wrong tool. If you want to
15:21:59see the step-by-step execution like
15:22:01after user query prompt construction lm
15:22:03call which tool it has selected okay
15:22:05based on the prompt or lm call. Okay, if
15:22:07you want to understand these things, you
15:22:09have to first of all monitor, trace your
15:22:11entire application. Okay, monitoring is
15:22:13important. Any kinds of application
15:22:14whether creating MLDDL, CB, whatever
15:22:17project you are creating, monitoring,
15:22:19monitoring is super important. If you
15:22:20cannot monitor your application, that
15:22:23means in production you will be finding
15:22:24difficulties for sure. Okay, that's why
15:22:26application monitoring is super
15:22:28important and for this Langmith is a
15:22:30very powerful tools we'll be using.
15:22:32Okay. So that's why find uh why an agent
15:22:36selected the wrong tool. Uh we can
15:22:37easily understand with the help of
15:22:39Langismith. Then inspect the exact
15:22:41prompt sent to the uh model. That means
15:22:44uh you can see like whether this palm
15:22:46con prompt construction is happening in
15:22:48a good way or not. That prompt you are
15:22:50constructing um whether it is right or
15:22:52not. It is going to the LM or not. Okay.
15:22:54Each and everything you can inspect
15:22:56here. Then debug failed nodes in a
15:22:58langraph workflow. That means if any of
15:23:00the nodes uh let's say failed during the
15:23:03execution you can easily monitor inside
15:23:05the langismith dashboard. Then measures
15:23:08responses latency and token cost. So
15:23:10that means if u some of the model is
15:23:13taking much time you can uh see like how
15:23:16much time it is taking why it is taking
15:23:18the time and how much token token
15:23:20actually it is uh spending okay to give
15:23:23you the response each and everything you
15:23:24can monitor. Then review conversations
15:23:26and multi-trren trades. That means you
15:23:29can uh review the construction uh sorry
15:23:31conversation uh review conversation and
15:23:33multi uh trend trades. That means you
15:23:35can see the entire conversation even you
15:23:38can see the trades conversation. Trade
15:23:40conversation means I think you know we
15:23:41have integrated the trades inside our
15:23:43aentic chatbot. Now user can create
15:23:45different different trades. User can
15:23:47create different different charts right.
15:23:49So you can see the trades as well. Not
15:23:51only the single conversation, you can
15:23:53also see the trades wise. Okay, this is
15:23:55also possible. I will also show you this
15:23:56part. Then compare different prompts or
15:23:59model versions. You can also compare
15:24:01different prompts or model versions.
15:24:03Then you can evaluate chatbot uh quality
15:24:06before and after the deployment. Okay,
15:24:08that means all of these uh things you
15:24:11will be getting u inside this lang and
15:24:14it will help you uh for this kinds of
15:24:17work. Okay, if you are using this uh
15:24:18this inside your application
15:24:20development. So I think um apart from
15:24:22this there is nothing uh you can monitor
15:24:24inside your application. If you can
15:24:26monitor these are the thing I think u
15:24:28your uh application should be production
15:24:30ready and you won't be having any kinds
15:24:32of problem okay going forward. So now
15:24:34we'll try to see guys this language
15:24:36speed in practical that means the
15:24:38application we have created uh this code
15:24:40is already available in my description
15:24:41from there you can get uh get the code
15:24:43guys I think you remember we created a
15:24:45uh agentic uh chatbot okay and uh in my
15:24:49last video I showed you how we can
15:24:50integrate database features okay so that
15:24:52it can uh it can have the permanent
15:24:54persistence memory okay so first of all
15:24:56let me show you the application guys we
15:24:58have developed so guys uh this is our
15:25:00agentic chatbot we have developed so far
15:25:02and uh we can perform any kinds of chat
15:25:05operation. Let's say if I give a prompt
15:25:07uh give me a
15:25:10road map to learn okay ML.
15:25:19So see this is giving you the detailed
15:25:21road map and uh you can see the previous
15:25:24trades as well. You can also continue
15:25:26the conversation with the previous
15:25:27trades you had here and this is your
15:25:29current trades. Okay. And if you refresh
15:25:30your application still this uh uh
15:25:33previous conversation will remain same
15:25:35because we have added the permanent
15:25:37memory here with the help of database.
15:25:38Okay. So in this particular video I
15:25:40already explained this concept. If you
15:25:42haven't checked that guys please try to
15:25:43go through this recording. So see guys
15:25:45uh here we have performed a
15:25:47conversation. It's completely fine. But
15:25:49uh this application doesn't have any
15:25:51kinds of observability or monitoring uh
15:25:54connection. Okay. So I can't monitor
15:25:56this application like in the back end.
15:25:58What is happening? Let's say uh if I
15:26:00deploy this application in production
15:26:02server so I don't have any kinds of
15:26:05platform there I can continuously
15:26:06monitor my application what is happening
15:26:09how much token it is uh taking okay or
15:26:11let's say any of the nodes is giving you
15:26:13any kinds of errors so I can't see these
15:26:15kinds of let's say uh issues right so
15:26:18for this we can utilize this langismith
15:26:21platform so you have to visit uh
15:26:23smith.langchen.com langchen.com. So if
15:26:25you visit this website guys, this is the
15:26:27langid platform. So first of all here
15:26:29what you have to do, you have to create
15:26:31an account. Okay. So here you just need
15:26:33to create an account guys. You can use
15:26:35your Google, GitHub, discord, anything
15:26:36you can uh use and you can create an
15:26:38account. So I already have an account
15:26:40guys. I will just try to login.
15:26:46So once you log guys, you will be able
15:26:48to see this kinds of dashboard. So this
15:26:49is your language dashboard. And
15:26:51previously I uh already created some of
15:26:54the project here. I already uh traced
15:26:56some of my project that's why it's
15:26:57coming here. But if you are using for
15:27:00the first time, you won't be able to see
15:27:01this kinds of uh like project name here
15:27:03or tracing name here. Okay. So first of
15:27:06all guys, if you want to use this uh
15:27:07langismith inside your uh application,
15:27:10you just need to collect a API key.
15:27:12Okay. And this is super easy to use. You
15:27:15don't need to write uh like uh any kinds
15:27:17of code if you want to use this lang
15:27:19guys. Only you just need to add some of
15:27:22the environment variables and
15:27:24automatically this langismith will start
15:27:26tracing your application. Okay, I'll
15:27:28show you this part. So if you want to
15:27:30get the u um API key, so what you have
15:27:33to do, you just need to uh go to the API
15:27:35section. So I think API is available in
15:27:38the settings and uh here is the API key
15:27:40guys. Okay. Now previously I already
15:27:42created some API key. What I will do? I
15:27:43just try to remove some of the API key
15:27:45so that I can create a new one.
15:27:49H So I'll create a new API key. So you
15:27:52can give the name. So let's say I'll
15:27:54give the name of u
15:27:57uh agentic
15:28:01chatbot.
15:28:05So everything just keep it as it as it
15:28:07is. Okay. Don't need to change anything.
15:28:09Now just create the API key.
15:28:11So once you have created the API key
15:28:13just try to copy and you have to add
15:28:16this API key in the environment
15:28:18variable. Okay. So let's say this is our
15:28:20app. Uh so this application we have
15:28:22created guys. This is the code I think
15:28:23you remember in my previous uh video
15:28:26previous part. So now you just need to
15:28:28open this env file.
15:28:30Um after that here you have to add uh
15:28:34some of the environment variable. Let me
15:28:36show you. So these things you have to
15:28:39add here. Yeah. So see these things will
15:28:43common for all the project you will be
15:28:44creating going forward. Only you just
15:28:46need to change the project name. So see
15:28:48first of all you have to provide languid
15:28:50tracing
15:28:52uh this parameter is equal to true. Okay
15:28:53that means you are uh allowing your as
15:28:56uh allowing your langis to trace your
15:28:58entire application. Whenever you are
15:29:00executing your application lang will
15:29:02automatically start tracing your
15:29:04application. It will automatically start
15:29:06monitoring your application. That's why
15:29:07this parameter you have to give as true.
15:29:09Then you are telling what should be the
15:29:11endpoint that means after tracing it the
15:29:14data it will get okay the let's say
15:29:17information it will get where it will
15:29:19save those information okay it needs an
15:29:21endpoint so endpoint is langismith
15:29:24platform I'm giving you have to save
15:29:26everything in the langismith platform
15:29:27that means inside this particular
15:29:29platform this is the dashboard right so
15:29:31this is what actually we're doing then
15:29:32you have to pass the API key now to
15:29:35authenticate with your dashboard you
15:29:36need a API key so what I will do I'll
15:29:38just copy this API
15:29:39And here you have to provide the API key
15:29:41and make sure you don't share this API
15:29:43key with anyone otherwise they will be
15:29:44able to uh use your platform. Okay. Then
15:29:47you have to provide the langismith
15:29:49project name. Okay. Because every time
15:29:52whenever you will execute for the first
15:29:54time it will create a project. Right?
15:29:56Inside the project it will start tracing
15:29:59all of the execution. So project is
15:30:01important. So here I'm giving agentic
15:30:02chatbot project. Okay. If you're
15:30:04creating any other project you can
15:30:05change the name as per your requirement.
15:30:07Once it is done, you just need to save
15:30:09this file and no need to change
15:30:11anywhere. Okay, no need to change
15:30:12anywhere. I can uh re-execute my app
15:30:15again. So I'll stop the execution. Clear
15:30:18and let's re-execute my app. Streamlitly
15:30:20run my app.py. Okay. So once you have
15:30:23done now what I will do uh here I
15:30:25already saved this uh API key. H so it's
15:30:28done. Now I'll go to the uh homepage.
15:30:32Yeah. Now let's execute my app. See my
15:30:35application is running right now.
15:30:37Now here again I will give the prompt.
15:30:38Let's say I'll give hi my name
15:30:43is
15:30:46By
15:30:52plan to learn AI.
15:30:56I'll send it
15:30:59now. See it is giving you some kinds of
15:31:01response. Okay. Now once I go to my
15:31:05platform. Okay. Once I go to my platform
15:31:07and if I refresh here.
15:31:13So see this agentic chatbot project is
15:31:16created few seconds ago. See
15:31:17automatically it has created. I didn't
15:31:19uh change anything inside my code. Okay.
15:31:21Now if I go inside that now inside the
15:31:24project guys you will be able to see
15:31:25your trace. Okay. So this is our first
15:31:27trace. That means we have executed uh
15:31:30only one time. We have gi a single
15:31:32prompt. That's why that's why one trace
15:31:34came and by default this trace name will
15:31:36be taken as lang graph because we are
15:31:38using lang graph and now if I click on
15:31:40the uh this trace our first trace so
15:31:42whatever message you have given as an
15:31:44input you will be able to see and
15:31:46whatever uh output you got from your AI
15:31:49even you will be also able to see okay
15:31:51and this is also coming as a chatbot
15:31:52interface okay this is like very
15:31:54interesting then there is a option
15:31:56called details so you have to click on
15:31:58details okay if you click on details you
15:32:00will be able to see all of the details
15:32:01that means you have executed your
15:32:03langraph and it has a chat node. I think
15:32:06you remember uh we are using a chat node
15:32:07if you can see uh our entire application
15:32:11workflow. So this is the chat node
15:32:12inside chat node we are using u lm right
15:32:16we are using a large language model uh
15:32:17openi model and we are using gpt 3.5
15:32:20turbo model because I used a default
15:32:22model there okay and by default GP3.5
15:32:26turbo would be available now everything
15:32:28you can see which model which node you
15:32:30are executing okay each and everything
15:32:32is visible now you can see the input and
15:32:34output you got here you can even see the
15:32:37attribute okay all of the attribute
15:32:39metadata version everything is visible
15:32:41here. And if you hover on each and every
15:32:44let's say step here, you you will be
15:32:46able to see the um uh let's say
15:32:49estimated token cost. You can see token
15:32:51cost and uh how many how much token
15:32:54actually it used. Okay, how much token
15:32:56it used for input, output, total. Okay,
15:32:59each and everything you would be able to
15:33:00see that. Okay, that's how you can see
15:33:02the each and every execution of your
15:33:05application. If you're using multiple LM
15:33:08calls, you'll be able to see the
15:33:09multiple LM. You can see the prompt.
15:33:10Okay. Each and everything should be
15:33:12available here. Okay. Now let's say if I
15:33:14do for the second time what I will do
15:33:17let's say I will give another message.
15:33:20Um let's say how much
15:33:25time it will take.
15:33:32Now I got a response. Now if I again go
15:33:34to my um dashboard. Now see another
15:33:37trace has created. Okay. because this is
15:33:39my second run. Now if I go to this trace
15:33:42and you'll be able to again see the uh
15:33:44conversation okay so how much time it
15:33:47will take based on that you got the
15:33:49entire output then you'll be able to
15:33:51also see the uh token okay like input
15:33:54token output token okay total token each
15:33:56and everything would be available here
15:33:58now even you can also switch to your
15:34:00previous uh trans as well so if I go to
15:34:02my previous trans this is the first
15:34:03trans this is the second trans okay
15:34:06everything you can see even you can see
15:34:07the name so this is tr one and this is
15:34:09tr too. Okay. So that's how everything
15:34:12would be available and even if you zoom
15:34:14out here so you'll be able to see some
15:34:16other information right side like start
15:34:18time latency like how much time it took
15:34:20to execute then whether you are using
15:34:22any data set or not then tokens cost
15:34:25okay first tokens then metadata langmith
15:34:28endpoint okay and everything you will be
15:34:29able to see. So yes that's how you can
15:34:32utilize this uh lang platform uh only
15:34:35you just need to add those uh three to
15:34:37four things in the environment variable
15:34:39and tracing would be uh automatically uh
15:34:43happening okay inside this particular
15:34:44dashboard but one issue I think you have
15:34:46observed here which is that let's say
15:34:49here let's say if I create a new trades
15:34:51okay let's say I create a new trades and
15:34:53if I do the conversation let's say I
15:34:55will give hi I am bi let's say this is
15:35:00completely new trades. Okay. But if I go
15:35:03to my um dashboard that means language
15:35:06dashboard. So as you can see in the same
15:35:10um I mean trace only it has created my
15:35:13uh my current execution that means the
15:35:15current trace the uh execution we have
15:35:17done right now. So see uh here I given I
15:35:20uh my name is BPI and hello I can assist
15:35:22you today. Okay. So that's how actually
15:35:24it is uh uh it is not separating my
15:35:28trades instead of that it is saving
15:35:30everything inside a single trace only.
15:35:32So here if you want to separate your
15:35:34trades guys uh it is also possible
15:35:36because Langismith
15:35:38by default has this uh trading uh
15:35:40features here. So if you want to
15:35:42separate out uh each and every trades
15:35:44okay the trades you are maintaining
15:35:46here. So it is possible for this inside
15:35:48the code you have to only modifi uh
15:35:50modify one particular line. Let me show
15:35:52you. So this code only you just need to
15:35:55modify. See here uh I was uh writing the
15:35:58configuration. In the configuration I
15:36:00was only giving the trade ID. Okay. Uh
15:36:02and we are passing this configuration
15:36:04whenever we are executing the uh chatbot
15:36:06whenever we're invoking the chatbot.
15:36:08Okay. Now instead of that you have to
15:36:09write this configuration. Okay. Some
15:36:11other information you need to also pass
15:36:13this metadata and the runtime. Okay. So
15:36:15run name see every time this run name is
15:36:17coming as a lang graph by by default
15:36:19name but you can change this run name if
15:36:20you want. You can give any kinds of run
15:36:22name. Let's say I give I'll give chat
15:36:24trace. Okay, you can also give any other
15:36:25name. And if you pass this configuration
15:36:28guys, right now this uh trading would be
15:36:32uh trading would be applied. That means
15:36:34all of the trades individual trades
15:36:35would be saved in the trades. Okay, let
15:36:37me show you. So I'll remove this
15:36:39configuration right now. This is not
15:36:40required. I'll use my new one. Okay, new
15:36:43configuration.
15:36:45Yeah, so let me show you the fresh
15:36:46execution. So for this I'll remove my uh
15:36:50I'll remove my let's say project. So
15:36:53here just go to the tracing and select
15:36:55your project and just try to delete the
15:36:57project.
15:37:00Okay, done. Now I will re-execute my
15:37:03code.
15:37:11So let's say here uh I'll give a
15:37:13message. Hi,
15:37:15my
15:37:17name is Buppy.
15:37:22Okay, done. So this is uh this is the
15:37:25trade guys. Uh I just uh start the
15:37:27conversation. Now if I come here, see my
15:37:30project has created. If I go inside
15:37:32that. So first trace has created the uh
15:37:34the name of the trace is chat trace
15:37:36because we changed the name and this is
15:37:38the conversation we have done. Okay. Now
15:37:40let's say I will give another message.
15:37:42Uh I will create a new trades here and
15:37:44I'll perform another message. Let's say
15:37:47I am Alex.
15:37:54Now if I come here
15:37:57now if I go to the trades now guys you
15:38:00can see trades has created. Okay. Now
15:38:02this is the trades. This was my first
15:38:04trace. Uh there I performed. Hello my
15:38:07name is BPY. Okay. How I can assist you
15:38:09today. Now let's say if I give another
15:38:11message um
15:38:13I need
15:38:16um I need a plan
15:38:20to learn Python.
15:38:28Now if I go to my trades. So see inside
15:38:31the same trace uh inside the same trade
15:38:33there is uh two trans right now. Um now
15:38:36if I go to this uh trades as you can see
15:38:40the first I given hi my name is BP uh
15:38:42how and it it has given you hello BP how
15:38:45I can assist you today. Now in the
15:38:47second trace
15:38:49uh you can see I given I need a plan to
15:38:51learn Python and uh it has given you the
15:38:54plan. Okay that means in a single trade
15:38:56now it is storing multiple trans that
15:38:58means multiple conversation. Previously
15:39:00I also did for Alex. See Alex is also
15:39:02available here. Uh yeah, you can see the
15:39:05Alex. Uh but it takes some time guys. I
15:39:07think it takes uh 10 to 20 seconds to
15:39:10update in the trades. Okay, that's why
15:39:12initially whenever I showed you uh this
15:39:14information was not updated. Now see
15:39:16here also whenever I did let's say Alex,
15:39:19right? Uh this is the Alex Alex
15:39:22conversation.
15:39:23Uh this is Alex conversation. I'm Alex.
15:39:25I need a plan to learn Python. As you
15:39:28can see I am Alex and here I given you I
15:39:31need a plan to learn Python. Okay. So
15:39:33that's how guys every uh trades you will
15:39:36be creating all of the trades would be
15:39:37available inside the trades or whatever
15:39:39conversation you'll be doing it would be
15:39:41saving as a run. Now let me show you
15:39:43another let's execution let's say in the
15:39:45Alex only I'll tell how much
15:39:51time it will take.
15:39:55Now this is my third run. Okay.
15:39:58Now if I come here.
15:40:01So you have to wait for some time then
15:40:04this TR would be updated here.
15:40:08Now see it got updated run three. Now if
15:40:11I click here now this is the turn three
15:40:13guys and here I asked how much time it
15:40:16will take and this is the answer I got.
15:40:17Okay. So that's how guys you can
15:40:19separate out the trades uh by adding
15:40:21this line of code only. You just need to
15:40:23update your configuration and everything
How to Integrate Tools in Agentic Chatbot with LangGraph
15:40:25will remain same. Okay. So that's how
15:40:26guys with help of Langismith we can
15:40:28continuously monitor our application. we
15:40:30can continuously trace our application.
15:40:32Lots of thing we can perform with the
15:40:33help of this languid. Going forward also
15:40:36I'll be using this uh tool okay in my
15:40:38project development and I will also show
15:40:40you some other advantage we can utilize
15:40:43from this lang language speed itself.
15:40:45Okay. So all the code I'm going to uh
15:40:47upload in my GitHub and give the link in
15:40:50the description from there you can get
15:40:52and please try to practice in your
15:40:53system and do let me know if you have
15:40:55any question. So yes guys, this is all
15:40:57about it and if you found my content
15:40:59useful, please try to subscribe to my
15:41:00channel and hit the like. In this video,
15:41:02I'm going to uh explain one very
15:41:05important concept, one very important
15:41:07features inside our agentic chatbot
15:41:10which is tools. If you are implementing
15:41:12any kinds of agentic system, this tools
15:41:14is very much important. Without tools,
15:41:17an AI agent cannot perform any kinds of
15:41:19action. With the help of this tools
15:41:21integration, we can make our AI agents
15:41:24more smarter and intelligence and
15:41:26powerful.
15:41:27So far the application we have created,
15:41:29it doesn't have any kinds of tool. It
15:41:32can only use the large language model
15:41:33and give you some kinds of response. So
15:41:36if I show you my application guys, so
15:41:38this is the application guys. So far we
15:41:40have developed. Uh this is our agentic
15:41:42chatbot with lang graph we have
15:41:44developed so far and we have added lots
15:41:46of feature in this particular uh
15:41:48application. We saw how we can create
15:41:51the uh basic workflow of our agentic
15:41:53chatbot. We saw how we can add the
15:41:55streaming features. We saw how to add
15:41:57the trading features. Okay. Uh we saw
15:42:00how to add the persistence memory. Um
15:42:02even how to integrate the database with
15:42:04that. Even in my last video, I showed
15:42:06you how we can add the observability
15:42:09tool to monitor the entire application.
15:42:11And we created a dashboard. Uh this is
15:42:13the lang dashboard guys. And here
15:42:16continuously we're tracing our um like
15:42:18conversation. So this is the application
15:42:21guys. And the problem with this
15:42:22application is let's say if you are
15:42:24asking any kinds of uh question uh which
15:42:27is latest uh which is not available in
15:42:30the large language model that time this
15:42:32particular chatbot will not uh able to
15:42:34give you the response. So let's say here
15:42:36we are telling hello uh tell me
15:42:41about
15:42:43Python.
15:42:45So if I give this prompt it will be able
15:42:48to give you the response.
15:42:51So see guys it is uh able to give you
15:42:53the response and why it is able to give
15:42:55you the response about the Python
15:42:57because uh this Python information is
15:42:59already available in the LLM knowledge
15:43:01base. Okay. So the model we are using uh
15:43:04every model has a knowledge cutoff date
15:43:06and the model we are using this model
15:43:08got trained till 2022
15:43:11uh I think till December it uh this
15:43:13model got trained and that time actually
15:43:15python information was available in the
15:43:17internet that's why it is able to
15:43:19generate the response but let's say if
15:43:21you are asking anything which is latest
15:43:22information this information is not
15:43:24available in the knowledge base that
15:43:26time your chatbot will fail now let's
15:43:28ask about a latest uh information uh uh
15:43:32into my chatbot. So here I will tell u
15:43:36give me
15:43:39all the latest
15:43:41news
15:43:43for [snorts] today's
15:43:49now see it is telling I understand you
15:43:51are looking for the very latest news.
15:43:53However, uh as an AI, I don't have
15:43:56realtime access to the live news feed
15:43:59and my knowledge cutoff is a specific
15:44:01point in time typically a few month ago.
15:44:04Okay, this means I cannot provide with
15:44:06you today's uh minuteby minutes uh news
15:44:09headlines. Okay, to uh get most current
15:44:12news, I highly recommend checking reput
15:44:14uh reputable news sources directly.
15:44:17Okay, and blah blah blah. That means
15:44:19this chatbot is directly telling you
15:44:22okay I don't have the access to the
15:44:24latest data okay because this this is
15:44:27using a large language model and this
15:44:28large language model has a knowledge cut
15:44:30off date okay I think uh till uh 2022
15:44:35or 2024 I don't know but uh till the
15:44:38date actually they have trained this
15:44:39model and uh um actually in that period
15:44:43of time whatever news were available in
15:44:45the internet uh this has the information
15:44:47okay but if you are asking anything
15:44:48which is latest this model will not able
15:44:50to give you the response. Okay. So this
15:44:52is the problem right now even uh if if
15:44:55you uh want to perform like other things
15:44:58as well. Let's say if you want to let's
15:45:00say uh see the stock market analysis
15:45:03report. Okay the latest stock market
15:45:04analysis report. This model won't be
15:45:06able to give you the response. So let me
15:45:08give you another demo. So tell me
15:45:11the latest stock
15:45:15of Apple.
15:45:23So as you can see as an AI I do have
15:45:25access uh to real time live stock market
15:45:27data. Stock uh prices uh fluctu
15:45:32fluctuate uh consistently uh throughout
15:45:34the trading day. Okay. and my knowledge
15:45:37cutoff means any specific price I could
15:45:40I could uh give you would be outdated
15:45:42almost im uh immediately. Okay, that
15:45:44means it is not able to give you the
15:45:46realtime information about this stock.
15:45:48And if you're asking anything, let's say
15:45:49you are asking about the current
15:45:51weather. Okay, let's say I'm asking
15:45:52about tell me the
15:45:55tell me the current
15:45:59weather
15:46:03in let's say New York.
15:46:17So see it is telling you again I don't
15:46:19have realtime access to the live uh
15:46:21weather data. Okay. So this is the
15:46:23problem with our uh agentic chatbot we
15:46:26have created so far because it doesn't
15:46:27have any kinds of tool. Okay. So tool
15:46:30means uh it is kinds of function it is
15:46:33kinds of API okay it is kinds of let's
15:46:36say uh different different tools that my
15:46:39agent can use to get the latest
15:46:42information or perform any kinds of
15:46:43action. Okay. So let's say if I go to
15:46:45the chat GPT and if I ask the same
15:46:47question, Chad GPT will be able to give
15:46:49me the response. Okay. So let's say I
15:46:51will copy the same question. Um I'll
15:46:54copy this question and if I ask in the
15:46:56chart GPT see chart GPT will be using
15:46:59some kinds of tool in action. See see
15:47:02just try to notice here now see it is
15:47:04searching over the internet. Okay. You
15:47:06see it is searching over the internet
15:47:08and it is finding different different
15:47:10latest news and once it has collected
15:47:12all the latest news then it will refine
15:47:14that particular news and it will give me
15:47:16all of the see news for today's okay and
15:47:21the reference uh reference URL as well
15:47:23like where it got uh it referred that
15:47:25particular headline where uh it uh
15:47:28referred that news okay each and
15:47:29everything it is giving me now let's say
15:47:31if I asking
15:47:33uh this question as well tell me the
15:47:35latest stock of Apple again it will be
15:47:37using some kinds of tool
15:47:43see it is using some kinds of tool and
15:47:46after that it will give you the response
15:47:48see it is using this stock market
15:47:51analysis tool and it is giving you the
15:47:53real time Apple um stock stock stock
15:47:56data okay then you can also ask um about
15:48:00the weather information
15:48:02again it will be able to give you the
15:48:04response because it has the uh current
15:48:06weather tools as well in the back end
15:48:08with the help of that particular tool.
15:48:10It is real time searching the uh current
15:48:12weather information in New York and it
15:48:14will give you the uh weather see. Okay.
15:48:18So this is called actually tool in
15:48:19action. Okay. So whenever you are
15:48:21creating the agentic system it should
15:48:24have lots of tool. Okay. And wherever it
15:48:28needs any kinds of tool it will
15:48:29automatically decide and it will select
15:48:30that particular tool. Let's say here I
15:48:32was asking about the news right that
15:48:35time to get the latest news what what I
15:48:37have to do I have to perform the
15:48:38internet search operation I have to
15:48:39perform the Google search operation so
15:48:41here it is using some kinds of search
15:48:43tool okay with the help of the search
15:48:44tool it is giving you all kinds of
15:48:46latest information latest news then I
15:48:48asked about the latest stock of Apple
15:48:51okay now it is using the stock market uh
15:48:54actually tool with the help of this tool
15:48:57actually it is getting the real time uh
15:48:59real time actually um the uh real time
15:49:03actually stock of Apple and it is giving
15:49:05you the response. So it is using some
15:49:07kinds of stock stock price or stock
15:49:09related tools in the back end. Now again
15:49:12I asked about the weather. So here it is
15:49:14using a weather tool. Okay, with the
15:49:16help of weather tool it is hitting some
15:49:18kinds of uh API of the weather and it is
15:49:21getting real time this weather
15:49:23information. Okay, the given uh location
15:49:26we are giving. Okay, so that's how
15:49:28things are working. So that's how chart
15:49:29GPT uh has lots of tool connection.
15:49:33Okay, not only three to four tools, it
15:49:34has lots of tool connection. So you can
15:49:36ask any kinds of question whether it's a
15:49:38latest news, whether it's any kinds of
15:49:40outdated news, whether you want to
15:49:42perform any kinds of task. Okay,
15:49:44everything it can perform because it has
15:49:46the tool and without this tool it can
15:49:48perform the action. Okay, I hope you get
15:49:50it. So these kinds of things we will be
15:49:52also integrating inside our agentic
15:49:54chatbot. So whenever we are asking this
15:49:56kinds of question, my agentic chatbot
15:49:58will be also able to give you the
15:50:00response. It will be also able to use
15:50:02this kinds of tool and perform the
15:50:04action. Okay. So yeah, in this
15:50:06particular video, we'll be learning this
15:50:07concept guys. We'll try to see how we
15:50:09can integrate the tools inside our
15:50:11agentic chatbot. And trust me, this is
15:50:13very important concept. If you are
15:50:15implementing any kinds of agentic uh
15:50:17powered application, you have to use the
15:50:19tool. Okay, there are lots of tools are
15:50:21available over the internet, over the
15:50:23market. Uh as per your requirement, you
15:50:26can select the tools and you can
15:50:27integrate inside your uh chatbot or
15:50:29whatever application you are developing
15:50:31and you can even create your custom
15:50:33tools. It is also possible. I'll show
15:50:35you both of them. Okay. So guys before I
15:50:37discuss about the tools concept the
15:50:39tools uh integration uh inside our
15:50:41agentic chatbot first of all I want to
15:50:43show you the demo like after adding this
15:50:46tools how my aentic chatbot will work.
15:50:49So I already integrated the tools inside
15:50:50my aentic chatbot this is the updated
15:50:52version. First of all let me show you
15:50:54the demo. So see this is the uh updated
15:50:56application. Now if I ask uh the these
15:50:59kinds of question let's say I will give
15:51:00u give me the
15:51:05latest
15:51:06news
15:51:08in AI. Okay. Now if I send this prompt
15:51:11you will be able to see uh it it will
15:51:13use some kinds of tool. Okay.
15:51:16So see it is using tably search tool. So
15:51:18with help of tably search tool it is
15:51:20searching over the internet uh about the
15:51:23latest news in AI and this will give you
15:51:25the response. See this is giving you the
15:51:27response. See so all of the latest news
15:51:30it has given me okay from different
15:51:32different uh paper different different
15:51:34publication it has given me all the
15:51:36latest news in AI. Even you can see the
15:51:39um like tools uh tools action as you can
15:51:42see internally it is using some kinds of
15:51:44uh URL some kinds of let's say uh
15:51:48resources and it is giving you this
15:51:49kinds of information even in charge also
15:51:52you'll be able to see this uh uh uh this
15:51:54back end execution okay this is also
15:51:56possible so every like said tools
15:51:58execution you'll be able to see if you
15:52:00want you can also open it and you can
15:52:02see okay so this kinds of thing we have
15:52:04also um implemented inside our agentic
15:52:07chatbot And throughout this entire video
15:52:09guys, I'm going to show you how we can
15:52:11develop these things. Okay, how we can
15:52:12add this particular tools integration
15:52:14inside our aentic chatbot. Now let me
15:52:16ask another question. Let's say here I
15:52:17will tell um um calculate
15:52:24okay um this number. Okay. So let's say
15:52:27this is my expression. I want to do a
15:52:29mathematical calculation and inside this
15:52:32aentic chatbot I I am using a a tool
15:52:35called calculator tool. So with the help
15:52:37of this calculator tool you can
15:52:39calculate any kinds of complex let's say
15:52:41expression any kinds of complex uh let's
15:52:43say um u equation you can calculate
15:52:46here. Now if I send this now you will
15:52:49see that it will be using calculator
15:52:50tool. Okay. Now with the help of this
15:52:51calculator it is calculating the entire
15:52:54uh let's say number and it is giving you
15:52:55the response. So any kinds of complex
15:52:57math problem you can give it will be
15:52:59able to perform that. Okay. So once it
15:53:01is done let me show you another demo.
15:53:03Then I have given another prompt. Tell
15:53:05me the latest stock price of Apple.
15:53:08Again you can see it is using some kinds
15:53:10of tool. It is using stock uh price uh
15:53:12tool and it is uh able to give you the
15:53:14latest stock price of Apple. Okay. Even
15:53:17you can also ask the stock related any
15:53:19other companies let's say stock price of
15:53:22Google. So stock price of Google. Now
15:53:25see it is using get stock price uh tool
15:53:27and it is able to give you the latest
15:53:29stock price of Google is uh that much.
15:53:33Okay. So yes guys that's how our entire
15:53:35uh agentic system is working right now
15:53:38and we are we have already integrated uh
15:53:40uh some tools okay inside our agentic
15:53:42chatbot that's why it is performing like
15:53:44chart GPT but chart GPT is having lots
15:53:47of uh tools guys um if you want you can
15:53:49also integrate lots of tools inside your
15:53:50application this part I will leave it to
15:53:52you first of all let me show you the
15:53:54entire development then you can uh you
15:53:56can improve this application a lot so
15:53:58first of all uh I'll be discussing about
15:54:00the tools guys what is tools uh why
15:54:03tools is required then I'm going to show
15:54:04you the implementation. So guys first of
15:54:06all let's try to understand about the
15:54:08tools what is tools exactly and why it
15:54:11is required and how tools works. Okay.
15:54:13So as you can see uh in agentic AI tools
15:54:16are external functions APIs database or
15:54:20any kinds of service that an uh AI agent
15:54:23can use to perform actions beyond
15:54:25generating the text. Okay. So previously
15:54:28the application we created guys this
15:54:29agentic uh application the previous
15:54:31version application that means in my
15:54:33previous video uh it was only able to
15:54:35generate the text okay uh if you give
15:54:37any kinds of let's say prompt based on
15:54:39the prompt if this information is
15:54:41available in the knowledge base of the
15:54:43model it is able to generate some kinds
15:54:45of text okay but with the help of these
15:54:47tools an agent can um agent can perform
15:54:51action okay like I showed you right now
15:54:53right I uh I uh per I did different
15:54:56different prompting in my agent. I asked
15:54:59about the stock price. I uh asked about
15:55:01the latest news. Then I asked to
15:55:03calculate u some kinds of mathematical
15:55:05equation and it was performing some
15:55:07kinds of action with the help of some
15:55:09third party tools. Okay. So that's why
15:55:12our agent can perform any kinds of
15:55:14actions. Okay. Uh using the tool beyond
15:55:17the text generation. So our agent cannot
15:55:19only generate the text. Okay. It can
15:55:22also perform some kinds of action with
15:55:24the help of this tool. So this is very
15:55:25much important. So a normal LM can only
15:55:28respond based on this knowledge and the
15:55:31information in in the prompt. Okay. An
15:55:33AI agent works with tool and it can
15:55:36search, calculate, retrieve the data,
15:55:38execute code, update database or
15:55:40interact with other systems as well.
15:55:42Okay. So by this definition itself I
15:55:44think you can understand what is tools
15:55:46exactly and why these tools is super
15:55:48important. Okay. So with the help of
15:55:49tools you can perform any kinds of
15:55:51searching operation, calculate
15:55:52operation, retrieve data operation. You
15:55:54can even execute any kinds of code.
15:55:55Okay. I think inside GPT you can execute
15:55:57the code. You can debug your code. Okay.
15:55:59How it is happening? Because it is using
15:56:01some kinds of tool and that tool
15:56:03actually it is working with the Python
15:56:05interpreter. Okay. So in the Python
15:56:07interpreter or any other let's say
15:56:08program you are using it is using that
15:56:10particular interpreter. It is executing
15:56:12the code. It is reviewing your code. It
15:56:14is finding the bugs inside your code and
15:56:16it is giving you the final response.
15:56:18Okay. this is the problem inside your
15:56:19code. So everything is happening with
15:56:21the help of this particular tools. Okay.
15:56:23So they're using these kinds of tool
15:56:25external tools and they are performing
15:56:26this kinds of operation. Okay. I hope
15:56:28you get it. Now let's try to understand
15:56:30a simple example. Suppose a user asked
15:56:33what is the current weather in Texas.
15:56:35Okay. The agent does not know the live
15:56:37weather uh by itself. Now it can call a
15:56:40weather tool. Okay. Let's say you have
15:56:42uh already integrated the weather tools
15:56:44inside your agents. Now your agents will
15:56:46automatically decide which tool to call.
15:56:48Now you are asking about the weather. So
15:56:50definitely it will let's say uh hit this
15:56:53get weather tools. Okay. It will use
15:56:54this get a weather tool and you are
15:56:56asking for Texas. Okay. So that's how
15:56:58the location you are giving it will find
15:57:00the weather okay of that particular
15:57:02location. Then the tool returns the
15:57:04current weather and the agent uses that
15:57:06result to answer the user. Okay. So
15:57:08that's how the entire system works. Now
15:57:10some common tools in agenti. So you can
15:57:13see web search tools can be used a lot
15:57:16whenever you are creating this kinds of
15:57:17agentic application with the help of you
15:57:19can perform search operation over the uh
15:57:22internet and you can get the current
15:57:23information. Then calculator tool okay I
15:57:25think you saw the calculator tool you
15:57:27can perform any kinds of complex
15:57:28mathematical operation. Okay then
15:57:30database tool you can even reads and
15:57:32writes data inside your database or any
15:57:34other let's say storage service these uh
15:57:37tools can be also used inside your
15:57:38aentic chatbot. then rag retriever
15:57:41tools. Okay, searches do uh searches
15:57:42over the documents or vector database.
15:57:44We'll uh in future we'll also try to add
15:57:46this uh tools inside our aentic chart
15:57:48but we'll also add the uh functionality.
15:57:51Okay, I'll show you this part as well.
15:57:52So this is also important things like
15:57:54inside GPT you can upload any kinds of
15:57:56documents right and in the document you
15:57:58can perform the uh you can perform the
15:58:00search operation you can perform the
15:58:01query operation how it is happening
15:58:02because it has the rag retriever tool
15:58:05then you can use python tool with the
15:58:06help of python tool you can execute the
15:58:08code analyze the data okay everything is
15:58:10possible you can even use email tool
15:58:12with the help of email you can read
15:58:14email you can draft your email you can
15:58:16send the email okay so everything is
15:58:18possible even in charge GPT or Google
15:58:20Gemini you can connect your email. Okay.
15:58:23Even from there only you can send the
15:58:25email. This is also possible. And how it
15:58:27is happening? Because it is using email
15:58:28tool. Then calendar tool you can use.
15:58:30You can even access your calendar. You
15:58:32can use different different API tool
15:58:34like uh you can use weather API tool,
15:58:36finance API tool, CRM API tool, any
15:58:38kinds of payment system API tool. Any
15:58:39kinds of API you can connect with your
15:58:42aentic chatbot. Okay. Aenti system. Then
15:58:44custom businesses tool. Let's say if you
15:58:46have some custom uh businesses okay if
15:58:49you want to integrate that particular
15:58:50tool let's say you can create the
15:58:52tickets you can check the inventory you
15:58:54can generate the reports okay you can
15:58:55update the customer records everything
15:58:57is possible here so these are the common
15:58:59tool guys you can integrate inside your
15:59:00aentic system okay apart from that there
15:59:03are lots of tools are available you can
15:59:05search over the internet okay there are
15:59:06thousands of thousands tools are
15:59:08available whatever you need okay you
15:59:10just try to integrate inside your
15:59:12project itself okay very simple then How
15:59:16two calling works guys? As you can see
15:59:17the typical workflow is the user gives a
15:59:20request first of all then the agent
15:59:22understand the goal. Let's say uh
15:59:24previously I showed you some kinds of uh
15:59:27action right? I asked about the uh stock
15:59:30price of Google. So this is my user
15:59:32request. Okay. My agent understand the
15:59:34goal. What is the goal? It has to
15:59:36understand the sorry it has to get the
15:59:38latest stock of the Apple. Okay. Or
15:59:40Google. Then the agent decided whether
15:59:43uh whether a tool is required. Then our
15:59:46agent was understanding okay to give
15:59:49this particular answer whether I need to
15:59:50use any kinds of tool or not. So in this
15:59:52scenario definitely it has to use the
15:59:54tool because inside the LLM uh the
15:59:56default LLM it doesn't have this kinds
15:59:58of information. Definitely it has to use
16:00:00the tool. Okay. So the agents will
16:00:02decide okay it has to use the tool. It
16:00:03it needs the tool requirement. Okay.
16:00:05Then it selects the appropriate tool
16:00:07because inside my application there are
16:00:09multiple tools I have added. Now which
16:00:11tool to call? Okay, which tool to use?
16:00:12Because here I ask different different
16:00:14uh question, right? And uh for each and
16:00:16every question uh it uh it should use
16:00:19different different tools. Okay, it it's
16:00:21not like that for all the questions it
16:00:23will be using one specific tool. Okay,
16:00:25because question might be different,
16:00:26prompt might be different. First of all,
16:00:28it has to understand the goal based on
16:00:29the goal. It will automatically select
16:00:31the specific tool it requires. Okay,
16:00:33that's why uh it selects the appropriate
16:00:35tools. Then it generates the tool
16:00:37arguments. Okay, tool argument means
16:00:39that here we are asking about let's say
16:00:41give me the latest news in AI. So what
16:00:43will happen? Uh it will search this uh
16:00:45this particular word in the internet.
16:00:47Okay, because it is using tably search
16:00:49tool, right? And you know tably search
16:00:50tool uh uh what it does? It does the
16:00:52internet search operation. The way you
16:00:54search the Google, right? Uh it will be
16:00:56using tably search and it will perform
16:00:58the search operation. Okay? And this
16:00:59will give you the latest uh information
16:01:02of that. So that's why uh this uh uh it
16:01:05generates the tool argument. Okay. Let's
16:01:06say whenever you are giving any kinds of
16:01:09uh let's say equation let's say
16:01:10calculate
16:01:14calculate
16:01:15this number with this number
16:01:18now it will be using calculated tool
16:01:20okay see and what is the uh tool
16:01:24argument here this expression okay this
16:01:26expression is the tool argument right
16:01:27now and it is calculating that and it is
16:01:30you are able to see the response okay
16:01:32then tool execution in action that means
16:01:34tool will execute and uh this will give
16:01:36you the response and this response the
16:01:38result is return it to the agent. That
16:01:40means whatever responses you will be
16:01:41getting from the tools. Okay. Uh
16:01:43sometimes these responses won't be
16:01:45readable to the user. Okay. So that's
16:01:47why what you have to do you have to send
16:01:49this response to the large language
16:01:51model again that means your agent again
16:01:53and agent will try to refine that
16:01:54particular output and you will be able
16:01:56to see the final result. Then the last
16:01:58one the agent uh produces the final
16:02:01responses. Okay, that means once my tool
16:02:03execution is complete and whatever
16:02:05output we are getting from the tools
16:02:07we'll try to pass to the agents and
16:02:08agents will try to refine that
16:02:10particular output. Okay, and this will
16:02:12generate the final uh responses to the
16:02:14user. So that's why the agents produces
16:02:17the final responses. Okay, example you
16:02:20are asking let's say what is uh uh 25%
16:02:23of uh 8,500.
16:02:27Now agent decide u you have it has to
16:02:30use calculated tool. Okay. Now it will
16:02:32perform the tool call. Now this is the
16:02:34calculation it has to do, right? Uh this
16:02:36is the expression it has to calculate.
16:02:38So after calculating this will uh uh
16:02:40your let's say uh uh tool has generated
16:02:42this output. Uh let's say this is the
16:02:44final response. But if I show this
16:02:46response to the user, user won't be able
16:02:48to understand in a in a good way. Okay.
16:02:51So I have to generate some kinds of
16:02:53readable response. So again I will send
16:02:55this particular result to my agent. Now
16:02:58agent will try to refine this out uh
16:02:59let's say answer and it will generate a
16:03:02uh final responses. You can see now
16:03:04agent is uh generating 25% of 8,500 is
16:03:092,125.
16:03:11Okay. Now this is more readable than
16:03:13this one. Okay. So that's why this this
16:03:16step is super important and whenever you
16:03:18are using any kinds of tool whenever
16:03:19your agent is calling any kinds of tool
16:03:21so this eight step it is following.
16:03:23Okay. And we'll also follow this a step
16:03:25eight step to implement tools
16:03:27integration inside our uh AI agents.
16:03:30Okay, this is the entire idea guys. So
16:03:32now guys, I think pretty much clear how
16:03:34the tools works and what is tools
16:03:35exactly and in the chart GP also how
16:03:38chart GP works and whenever you are
16:03:39asking any kinds of realtime question
16:03:41how it is able to give you the response
16:03:43because it has the tools connection.
16:03:44Okay, lots of tools connection because
16:03:46of that you are able to see the latest
16:03:48information or any kinds of action you
16:03:50can perform here. Now let's uh start the
16:03:52implementation guys. I will show you the
16:03:54entire implementation how we can add the
16:03:55tools inside our aentic chatbot. So
16:03:58guys, first of all, let's try to
16:04:00understand the workflow. Uh after adding
16:04:02this tool node inside our workflow, how
16:04:05our workflow will look like and how it
16:04:07will work. So as you can see uh this is
16:04:10the first workflow we have created so
16:04:12far. So this workflow has only one
16:04:14particular node which is chat node. So
16:04:16basically if user is giving any kinds of
16:04:18uh input it is going it uh going to the
16:04:21chat node and chat node is giving some
16:04:23kinds of output and the right side you
16:04:26can see this is the updated workflow uh
16:04:28we'll be creating inside this video. Uh
16:04:30basically we'll be adding our tools node
16:04:33here. So as you can see this is the
16:04:36updated workflow. So here uh you if user
16:04:39gives any kinds of input uh it will go
16:04:41to the chat node and here actually we'll
16:04:44be using something called tool condition
16:04:46function. Okay, there is a function
16:04:48called tool condition function. So here
16:04:50I have already written what is this tool
16:04:52condition function. it uh function does
16:04:54it's a uh tool condition. It's a uh
16:04:56pre-built conditional age function that
16:04:59helps your graph to decide should the
16:05:02flow go to the tool node uh next or back
16:05:06to the lm. Okay, that means whatever
16:05:09input user is giving. Okay, let's say if
16:05:11user is asking tell me about Python. So
16:05:14I think you know that inside large
16:05:16language model this information is
16:05:17already available. So in this scenario
16:05:19your agent doesn't need to call the
16:05:21tool, right? It can only use this chat
16:05:24node and give the response and the
16:05:26response will go to the end directly.
16:05:28Right? But if user is asking tell me the
16:05:31latest news in AI in 2026. Okay. This
16:05:35information is not available inside the
16:05:37large language model knowledge base that
16:05:40time your tool condition okay tool
16:05:42condition function will decide okay now
16:05:44it has to use some kinds of tool that
16:05:46means this kinds of question will
16:05:47redirect to the tool nodes. Okay. So
16:05:50this is how this uh two condition works.
16:05:52That's why you can see the definition.
16:05:54So this uh two condition is a pre-built
16:05:56conditional age function. Okay, I think
16:05:58I already told you about conditional uh
16:06:00conditional workflow. Okay, how
16:06:02conditional workflow works. If you
16:06:03haven't checked that, please try to
16:06:04check my previous video. So conditional
16:06:06ages function that helps your graph to
16:06:08decide should the flow go to the tool
16:06:10nodes. Okay, or back to the lm. Okay,
16:06:13now I think you got it what will happen
16:06:15here. Okay, now here we have added this
16:06:18tool. So this tool we call it as a tool
16:06:20nodes. Okay. Inside this graph this tool
16:06:21is a call we call it as a tool nodes. So
16:06:24tool nodes is also a pre-built node
16:06:27inside langraph. Okay. So as you can see
16:06:29in lang graph tool node is a pre-built
16:06:31node type that acts as a bridge between
16:06:34your graph and external tools. Okay.
16:06:37That means inside tool nodes you can use
16:06:39any kinds of function APIs utilities
16:06:42etc. So as you can see normally in
16:06:44langraph you would write a node function
16:06:47yourself. Okay it takes a state and
16:06:50return the state. So far we have written
16:06:52like that. But a tool node is a readym
16:06:55made node that knows how to handle a
16:06:58list of lang tools. That means this tool
16:07:01nodes you don't need to write
16:07:02separately. Okay. This is already
16:07:03pre-built inside langraph. You just need
16:07:06to define that. Okay as a node and it
16:07:08will automatically okay. it will
16:07:09automatically handle uh like uh the list
16:07:12of the tools you will be adding inside
16:07:14this tool nodes. Okay. Then it uh its
16:07:17job listen for tools calls from the LLM
16:07:20like let's say user wants to search
16:07:22something on the internet about the
16:07:24latest information or let's say he or
16:07:26she wants to get the weather
16:07:27information. So automatically this uh uh
16:07:30tools node will decide which tool to use
16:07:32because it has the list of the tools.
16:07:34Okay. automatically based on the input
16:07:37user input it will decide which uh tool
16:07:38to use and automatically route the
16:07:41request to the correct tools okay that
16:07:43means if user is asking about latest
16:07:44information in AI it will be using
16:07:46search tool let's say if user is using
16:07:49uh if user wants to uh know about the
16:07:51current weather okay so that time it
16:07:54will redirect to the get weather tool
16:07:55that's how it will route the request to
16:07:58the correct tool then pass the tool's
16:07:59output back to the graph okay so that's
16:08:01how the system works okay that means
16:08:04whenever you will pass any kinds of
16:08:05input. First of all, this tools
16:08:07condition will decide whether it has to
16:08:09use the any tool or not or whether it
16:08:11has to use the default large language
16:08:13model to generate the response. Okay.
16:08:15But if it needs any kinds of let's say
16:08:17tool uh tool functionality that time it
16:08:20will automatically route to these tool
16:08:22nodes. Okay. And tool nodes will try to
16:08:24decide which tool to use for what kinds
16:08:27of uh input. Okay. Now I think you are
16:08:29pretty much clear with this particular
16:08:31workflow and this workflow we'll try to
16:08:33develop inside our system. Okay. So for
16:08:36this first of all uh I'm going to show
16:08:38you a notebook experiment guys. We'll
16:08:40try to write everything in a Jupyter
16:08:41notebook. Uh we'll try to understand the
16:08:44entire tools concept there. Then we'll
16:08:46try to um integrate inside our agentic
16:08:49chatbot we have created so far. So here
16:08:51what I have done guys as you can see
16:08:53left hand side I created a notebook
16:08:55folder and inside that I already kept my
16:08:57previous notebook. I showed you right so
16:08:59this is the previous notebook I created
16:09:01uh at the very first time right uh there
16:09:03I showed you the chatbot workflow we
16:09:05created this workflow and this was the
16:09:07simple workflow so here I created
16:09:09another notebook called tools demo now
16:09:11if I open it up so you can see this is
16:09:13the tools uh demo uh related code so
16:09:16here uh basically I'm going to explain
16:09:18this code like how we have to add these
16:09:20tools inside our workflow and how we can
16:09:24uh how we can uh practically test that
16:09:25okay so once everything is working fine
16:09:27then we'll try to integrate inside our
16:09:29development and here I already added
16:09:31that documentation the documentation I
16:09:33showed you tools documentation if I
16:09:34click here so this is the documentation
16:09:36guys I already showed you this
16:09:38documentation right so this
16:09:39documentation reference I already given
16:09:41in this particular notebook you can
16:09:42refer it here now here first of all I'm
16:09:44going to select my environment so let's
16:09:46select my environment
16:09:50so this is the environment now first of
16:09:52all we'll import all the necessary
16:09:54library so as you can see we are
16:09:55importing um state graph of start end
16:09:58from lang graph then type dict annotated
16:10:00so these are the things are common I
16:10:02think you are pretty much familiar with
16:10:04this now base model human
16:10:05[clears throat] masses and one thing
16:10:07guys I have done uh actually my openi
16:10:09API key is over okay u uh my limit is
16:10:13over that's why I am using u like u
16:10:17gemini model and if you want to use
16:10:19gemini model so that time you can import
16:10:21this library called chat google
16:10:24generative AI from lang google ji Okay.
16:10:27And for this you have to install one
16:10:29library. So this is the library guys.
16:10:31Langen Google generate. Okay. And this
16:10:33specific version I have installed in my
16:10:36uh uh in my environment. Okay. So again
16:10:38you just need to open your environment
16:10:40and just write pip install
16:10:43r requirement.txt. Okay. If you do that
16:10:46it will automatically install this uh
16:10:48library inside your environment. So I
16:10:50have already done that. So let me open
16:10:51it up. So see this is the alternative
16:10:53way to use uh any kinds of large
16:10:55language model if you don't have open
16:10:57API key or if your API key limit is over
16:11:00that time you can use these are the
16:11:01freeto use large language model okay uh
16:11:04but if you want to use open API key guys
16:11:06you can refer my previous notebook I
16:11:08think in previous notebook I used the
16:11:10open API key here I used this open AI
16:11:13model okay chat open AI model only this
16:11:15part you just need to change okay h uh
16:11:19and one more thing you have to collect
16:11:20which is uh uh like Gemini API key that
16:11:22means Google API key and how you will
16:11:24get this Google API key. So for this you
16:11:27have to go to the uh Google
16:11:31AI studio. Okay this particular website
16:11:39and here you can click on get started.
16:11:43Now left hand side you will see this API
16:11:45key option get API key. I'll just click
16:11:47on get API key. Now from here you just
16:11:49need to create an API key. Okay, I
16:11:50already created the API key. So I can
16:11:52copy and I can simply paste it here.
16:11:56Okay, so make sure you collect your own
16:11:58API key guys. I'm going to remove my API
16:12:00key after this recording. So don't use
16:12:02my API key. Try to create your own API
16:12:04key from here. Okay, once you have
16:12:05created the API key, then you will be
16:12:07able to execute this notebook. Then I'm
16:12:10importing this uh add message from graph
16:12:12itself. Then load env to load my
16:12:14involvement variable. Then uh I'm
16:12:16importing some other additional library
16:12:18as you can see from langraph pre-built.
16:12:20I'm importing this tool node. Okay, I
16:12:21think I already told you about tool
16:12:22nodes, right? So here in this demo I
16:12:25told told you about the tool nodes. So
16:12:27this tool nodes will uh basically help
16:12:29you to
16:12:31uh tool nodes will basically help you to
16:12:34uh uh so yeah I think this is the tool
16:12:36node. Yeah, tool node. So this
16:12:37particular tool node. Okay, so this tool
16:12:39node will help you to um define your
16:12:41nodes. Okay, that means tool nodes and
16:12:43you don't need to write this tool node
16:12:45separately. This is already pre-built
16:12:46inside Langraph. Okay, that's why we're
16:12:48importing from pre-built. Then there is
16:12:49another function called tool condition.
16:12:51So this function I told you. So this
16:12:53tool condition we also need to add as a
16:12:55conditional ages. So basically this
16:12:58function will decide whether it has to
16:12:59use the tool or it has to use the simple
16:13:01LM call. Okay. So this is also a
16:13:03pre-built function inside langraph.
16:13:05We'll be importing that. Then I need
16:13:07this tab search. So tabularly search is
16:13:09a internet search tool. With the help of
16:13:11that you can perform the internet search
16:13:13operation. Let's see if user is asking
16:13:14any kinds of latest informations uh like
16:13:16chat GPT I showed you. Okay. Previously
16:13:18the demo I showed you if user is asking
16:13:20about latest uh information um uh
16:13:22anything which is let's say completely
16:13:24latest and available over the internet.
16:13:26So with the help of tably search we can
16:13:28uh get this informations. Okay. And if
16:13:31you're using tably search tool guys you
16:13:33have to install uh these two library
16:13:35lang tabi and tably python. Okay. So
16:13:38these two library you have to install
16:13:40and this is the specific version I'm
16:13:42installing in this project. Now what you
16:13:44have to do you just need to simply write
16:13:47pip install hyphen
16:13:54requirement.txt.
16:13:55Okay. If you do that it will install all
16:13:58of the necessary library inside your
16:14:01okay inside your environment. Okay. So
16:14:04these two libraries required if you're
16:14:05using taberts tool then uh we'll be
16:14:08importing these tools. Okay. Right now
16:14:10we have to create the tools. Okay. And
16:14:13whenever you want to create your custom
16:14:15function okay let's say custom function
16:14:17as a tool that time this tools has uh
16:14:19has to be uh imported with the help of
16:14:21this tool we'll be creating a decorator
16:14:24and this decorator will be uh will be
16:14:26represent my function as a tool okay
16:14:28I'll show you this part how to do that
16:14:30then request and math module okay so
16:14:32these are the input you have to uh you
16:14:35have to write inside your code
16:14:38done right now first of all let me load
16:14:40the environment variable so I have
16:14:41loaded my environment variable model.
16:14:42Okay. Now here I'm initializing my uh
16:14:46model guys. So as you can see here I'm
16:14:47initializing Germany 2.5 flash model and
16:14:50this is the creativity parameter. I
16:14:51think you already know about and this is
16:14:53your LLM object. And if you want to use
16:14:55OpenAI large language model here this is
16:14:58very much simple only you just need to
16:15:00write chat open AI. Okay. And if you
16:15:02want to use Gemini model you have to use
16:15:04this particular code. Okay. And if you
16:15:07want to use any other provider as well
16:15:09simply just try to change here. You can
16:15:10go to the chat GP and you can ask okay I
16:15:12want to use grock model let's say Grock
16:15:14meta model or open uh I want to use open
16:15:17router provider and I want to this this
16:15:19model okay so this particular code will
16:15:22uh change uh and you will get this code
16:15:24from the charge or any kinds of
16:15:25documentation you can change it anytime
16:15:27here okay so this will my large language
16:15:31model this will uh this will be my large
16:15:33language model okay now we'll be
16:15:34initializing the uh tably search okay so
16:15:37tably search is a internet search tool I
16:15:40already told you about right and to use
16:15:42this tably search tool you need a API
16:15:44key okay so for this what you have to do
16:15:45you have to go to this tably website tab
16:15:48you just need to write tab API key go to
16:15:51the first website
16:15:55and just try to uh continue with your
16:15:58Google
16:16:00okay so here you will be getting your
16:16:01API key if you don't have API key try to
16:16:04create from here so you just need to
16:16:05create here give the name let's say I'll
16:16:07give demo and simply create the API key.
16:16:10Okay, once you have created just try to
16:16:11copy this API key and
16:16:15uh you have to place inside your
16:16:16environment variable. So here you just
16:16:18need to create another key called table
16:16:20API key and here you just need to paste
16:16:22your API key. That's it. Okay, I already
16:16:24have my API key. I'm not going to change
16:16:26it here.
16:16:27Uh okay, so API key is also collected.
16:16:30Now see this is our first
16:16:33uh tools actually we have defined. So
16:16:35tab is it's a like a tool inside like
16:16:38aentic AI if you are creating against ai
16:16:41project. So tab is a tool by default
16:16:44it's a tool. So you don't need to give
16:16:46this particular decorator sign. So you
16:16:48just need to create an object of tably
16:16:50search. So inside the tably search you
16:16:52just need to give maximum result like
16:16:54how many uh result you need whenever it
16:16:57will search uh do the search operation.
16:16:58Let's say it has searched for uh latest
16:17:01AI news. Okay. in 2026 it will search
16:17:05maximum in five website. Okay, five
16:17:07website and it will give you the
16:17:08response. Okay, I think previously I
16:17:11showed you this part. I think I created
16:17:12lang chain agent right there I showed
16:17:14you how to use the tab search right. Uh
16:17:17then topic topic basically I want to
16:17:19search the general uh topic related
16:17:21search operation and search depth
16:17:23advance. Okay, so this kinds of
16:17:25parameter you have to pass inside table
16:17:27search and this will give you a search
16:17:28tool object. Okay, and then you have to
16:17:30create this object. So this will become
16:17:32your first tool. Then the next tool guys
16:17:35I have created here called calculator
16:17:36tool. So you can see I have written a
16:17:38custom function. So just try to ignore
16:17:40this part. Let's say as of now I haven't
16:17:42added this decorator. So let's say I'll
16:17:44remove this decorator. First of all you
16:17:46have to write a custom function. So see
16:17:47this is the custom function I have
16:17:48written. So here I'm using math module
16:17:51and here I if you are passing any kinds
16:17:53of expression right any kinds of
16:17:54mathematical expression. So this
16:17:56function will be able to calculate uh
16:17:58that expression and it will give you the
16:18:00result and if any exception is occurring
16:18:02it will raise the exception. Now let's
16:18:03if you want to uh create any kinds of
16:18:06custom function as a tool only you just
16:18:08need to give this particular decorator
16:18:10this decorator add the red tool and this
16:18:12tool we have already imported here as
16:18:13you can see from langen course tools
16:18:16tools. Okay now this will become a
16:18:18tools. Okay now this will become a tool
16:18:20object. Now you can use this tool inside
16:18:22your agents. So this is super simple
16:18:24guys. Okay. And this is very much
16:18:26interesting. You can create any kinds of
16:18:28uh like Python custom function and you
16:18:30can convert it as a tool and you can use
16:18:32it inside your AI agent. It's not like
16:18:34that. Always you have to use the
16:18:35predefined tools. Okay. It's not like
16:18:37that because I I can write any kinds of
16:18:40custom function okay for my work and
16:18:42that has to be my tools. Okay. That has
16:18:44to work with uh work work like my tools.
16:18:47So I can do that. This kinds of
16:18:48customization is also available inside
16:18:50line graph. Now as you can see this is
16:18:52my second tool calculator tool. Now the
16:18:55third tool I created get stock price. So
16:18:58let's say if you if user is asking about
16:19:00any kind of stock price about Apple,
16:19:02Tesla or Google whatever. So this uh
16:19:05tool will be working that time and it
16:19:07will give me real time stock data. Okay.
16:19:10So as you can see again I written a
16:19:11custom function. So this will basically
16:19:13take any kinds of company name uh
16:19:15example Apple, Tesla or whatever. And
16:19:18here I'm using a website. As you can see
16:19:20this is the website alphavantage.co.
16:19:24Okay, this is the website. So in this
16:19:26website basically uh this is the uh API
16:19:30endpoint of this website and to hit this
16:19:32API endpoint I you need a API key. Okay,
16:19:34so let me show you this website first of
16:19:36all. So this is the website guys. So
16:19:39this website has all of the stock
16:19:41related realtime data. Okay. Restock
16:19:43market data uh stock market data API for
16:19:46LM uh and u LLM and any other let's say
16:19:52uh uh application you are implementing.
16:19:54Okay. So here basically you just need to
16:19:56collect an API key. So to collect the
16:19:58API key so there is a option get free
16:20:00API key. I'll click here.
16:20:03Now you just need to give your
16:20:04organization name. Let's say I'll give
16:20:05DS with BP. And you just need to also
16:20:07pass your email. Let's say I'll pass my
16:20:09email. And once it is done just try to
16:20:11click on get free API key. Okay. So this
16:20:13is your API key. Just try to copy that
16:20:18and don't share this API key guys and
16:20:21try to use your API key on API key.
16:20:23Okay. And here you just need to paste
16:20:24this API key. Okay. Now this will become
16:20:27your this will become your
16:20:30um
16:20:33API endpoint.
16:20:37See now here you just need to pass a
16:20:39symbol only. Let's say I'll give
16:20:47apple.
16:20:49Um okay u
16:20:56I'll pass like that.
16:21:04See now this is giving you this stock
16:21:07data related apple okay real time you
16:21:09are getting a JSON response so that's
16:21:11how we are using this uh uh website guys
16:21:13that's how we are using this API and to
16:21:16hit this API endpoint I'm using request
16:21:18module inside Python we are passing this
16:21:20URL and it is giving you the result some
16:21:22response and we are returning that okay
16:21:24to the LLM so this is our next tool I
16:21:27have used here so in this uh like demo
16:21:30Now guys, I only use three tools. You
16:21:32can add uh like more tools here if you
16:21:34want. You can add like get current
16:21:36weather informations. You can add uh
16:21:38let's say um emailing tool. You can add
16:21:41let's say Google drive tool. Any kinds
16:21:43of tool you can add. All you just need
16:21:44to go to the chart GPT and ask like okay
16:21:46I need to use this tool. Uh how to write
16:21:49that particular function? This is a
16:21:50simple Python function you need to
16:21:51write. Okay. So just for uh just to show
16:21:54you guys I used only three tools in this
16:21:56particular project. uh but you can add
16:21:59you can feel free to add more tools here
16:22:01okay anytime let's say uh let me show
16:22:03you another example let's say if I go to
16:22:04the chart GPT and if I let's say ask I
16:22:08want to
16:22:13add a tool in
16:22:17my agent
16:22:19that will
16:22:22fetch
16:22:24weather
16:22:29or given location
16:22:34real time.
16:22:38Give me a Python
16:22:42function.
16:22:50So see this is the get current weather
16:22:52tool.
16:22:59Okay. Now simply you just need to copy
16:23:01this code
16:23:04and here it is telling what to install
16:23:06here. Okay. And uh it is telling uh this
16:23:09uh API key you also need because it is
16:23:11using open weather API I think. So let
16:23:14me copy this function as it is uh just
16:23:17I'm I'm showing you okay how to add uh
16:23:19different different tools. Okay. You can
16:23:20take the help from chart GPT anytime and
16:23:23you can create this kinds of custom
16:23:24function. So let's say here I'm going to
16:23:26add another tool.
16:23:28This is my tool.
16:23:33Okay. Get current weather tool. It will
16:23:35take a location and based on the
16:23:37location actually it will u uh give you
16:23:40the realtime information. So here I need
16:23:42to import this operating system library
16:23:46import OS
16:23:54H. So and it needs an API key. Okay,
16:23:58open weather API key. So how you will
16:24:00get this open weather API key? You can
16:24:03copy this key and search on Google. So
16:24:06this is the weather API.
16:24:10Get API key. So this is the website guys
16:24:12it is using get API key.
16:24:15Now you just need to first of all sign
16:24:17in I think
16:24:28first of all I'll create an account.
16:24:30Okay. I think I don't have any account.
16:24:49I'll give the password.
16:25:01I'll confirm all of these
16:25:04things and let's create the account.
16:25:11Okay, email is already taken. Uh okay,
16:25:13previously I think I already used this
16:25:15email. So let me sign in and see whether
16:25:18it's working or not.
16:25:30Okay guys, let me login. I think I don't
16:25:32I am having some issue. First of all,
16:25:34let me login with this website.
16:25:37So guys, as you can see, I have
16:25:39successfully signed up uh in this
16:25:41website. Uh basically, I I forget my
16:25:44password. Okay. And now I changed my
16:25:46password and now I'm able to uh visit
16:25:48this website. Okay. First of all, you
16:25:49just need to create an account here.
16:25:51Then once you have done uh here you will
16:25:53see one option called API key and here
16:25:55is your API key. Okay. So you just need
16:25:58to
16:26:00um create an API key. Let's create an
16:26:03API key. I'll give the name let's say
16:26:05agent
16:26:07generate.
16:26:10Uh this is your API key. Let's copy
16:26:12that.
16:26:16And uh here you have to write it inside
16:26:19your environment variable
16:26:27and this should be the key name.
16:26:36Okay, open weather API. So that's how
16:26:38you can collect the API and now it will
16:26:40work.
16:26:42So I will re-execute from the beginning.
16:26:52So here I have added another function
16:26:54that will basically fetch the real-time
16:26:56weather information.
16:27:04Then uh here what you have to do guys
16:27:07you have to make a tool list. So here
16:27:09you just need to pass all of the object
16:27:11one by one. First of all, uh I created
16:27:14search tool, right?
16:27:16So I'll give the search tool.
16:27:19Then I created calculator.
16:27:25Okay, calculator.
16:27:28Then I created get stock price. Then
16:27:31uh I created this uh current weather.
16:27:40this function I'll pass here.
16:27:43Okay. So that's how uh let's say
16:27:46whatever tools you are creating you you
16:27:47just need to make a tools list. Okay.
16:27:49You have to give one by one. All the
16:27:51tool list you have to give one by one.
16:27:52Okay. Just try to remember. Let's say
16:27:54you are creating 10 different tools you
16:27:55have to give 10 different list here.
16:27:57Once it is done you have to uh do the
16:28:01bind operation with your LM. That means
16:28:03you just need to uh tell your LM. Okay.
16:28:05Now you have the tool. So that's why I'm
16:28:08not going to use the simple LM right
16:28:09now. Uh so the LLM object we have
16:28:11created this completely fine.
16:28:14This is completely fine. Okay. Now we
16:28:16just need to bind this tool with the
16:28:18LLM. So here there is a function called
16:28:20bind tools and inside that you have to
16:28:22pass all of the list of the tools. And
16:28:24now you'll be using this object lm with
16:28:26tools. Okay. Now let's bind that tool.
16:28:28Then now we are defining the state. I
16:28:30think the same state you remember we
16:28:32created previously this state. No
16:28:34change. Let's define that. Now this is
16:28:37our chat node guys. I think you remember
16:28:38we created this chat node. And here we
16:28:41need to create another additional node
16:28:43called tool nodes. Okay, I told you
16:28:45about this tool nodes right in this my
16:28:48uh excalator file. You can see this is
16:28:49the node. Additionally, we are adding
16:28:51this particular node and this is a
16:28:52predefined node. Okay, you don't need to
16:28:54separately write that. So here we are
16:28:56using this tool node function. I think
16:28:58we have imported this tool node and
16:29:01inside that we are passing the tool.
16:29:04Okay, tools list of the tools we have
16:29:06and this will become your tool nodes.
16:29:07Let's define both of the nodes. Now,
16:29:10once it is done guys, now we'll try to
16:29:12create the graph. Now we are using uh
16:29:14state graph and we are passing the
16:29:15state. Now we are adding the nodes. The
16:29:17first node we are adding which is chat
16:29:19node. Okay, we are adding the chat node
16:29:21as you can see. Then the second node we
16:29:23are adding the tool node. You can see
16:29:25the tool node. Okay, we are adding this
16:29:26tool node. So both node we have added.
16:29:29Now we have to the age connection. Now
16:29:31how my age connection will look like.
16:29:34As you can see first of all start to
16:29:36chat node. So start to chat node then
16:29:40chat node itself will have a conditional
16:29:42edges with the tool condition. I think
16:29:44okay I think I told you about this one
16:29:46chat node will have a two condition.
16:29:48Okay edge connection. Basically this
16:29:50tool condition will decide whether it
16:29:52has to call the tool or whe whether it
16:29:54has to use the default large language
16:29:55model. So that's why this connection
16:29:57would like uh will look like that. So
16:29:59you will be using add additional
16:30:00conditional edges and from chat node to
16:30:03tool condition. Okay. Now this tool
16:30:05condition will decide whether it has to
16:30:06use any kinds of tools or not. Okay.
16:30:08Then here you just need to write another
16:30:10age connection tools to chat node. Okay.
16:30:12Why you have to write this one? Let me
16:30:14show you. If I let's say don't give this
16:30:16line. Let's say I'll comment this line.
16:30:19So what will happen? Let's try to see.
16:30:21Let's say I have uh added my chat node
16:30:25and tool condition. Now if I show you
16:30:28compile and show you my graph. So that's
16:30:30how my graph looks like. Okay. And this
16:30:32is similar to this particular graph.
16:30:33Okay. And one thing I think you have
16:30:35observed here I'm not using the simple
16:30:37LLM. Okay. Right now I'm using LLM with
16:30:40tools. So that means this object because
16:30:42here I did the bind operation with my
16:30:44tools. Okay. So make sure you add this
16:30:46line otherwise it will not work. Okay.
16:30:48So many people uh do this mistake. So
16:30:50basically they use the simple LLM and uh
16:30:53they they feel like okay it is not using
16:30:56the tool. So that's why this object has
16:30:57to be called here. Now let me show you
16:31:00my execution.
16:31:02So now uh here we are giving a message.
16:31:04So first of all I'm giving hello and you
16:31:07know like uh uh for the hello actually
16:31:09it doesn't need any kinds of tool right.
16:31:11So this will my regular chat.
16:31:14So it is telling hello how I can uh help
16:31:16you today. Now here I'm asking another
16:31:19question. Let's say what is uh uh this
16:31:21particular expression. Okay. uh what
16:31:23would be the result of this expression
16:31:25mathematical expression and now it will
16:31:27use the tool okay because it has the
16:31:29calculator tool I think you know so
16:31:31previously we created the calculator
16:31:32tool so this is the calculator tool
16:31:36right it will uh use that particular
16:31:38tool let's execute
16:31:44see this is the result it has given me
16:31:47okay now here I will ask another
16:31:49question what is the new movie released
16:31:50in 2026 now again it will use the tool
16:31:59see new movie released in 2026
16:32:03and all of the URL it has also given it
16:32:05has referred see this is the different
16:32:07different website uh my tool has
16:32:09referred that means I'm using tably
16:32:12search tool right and it has so my tably
16:32:15tool uh did the internet search
16:32:16operation and it found the latest movies
16:32:18okay as you can see and it has given me
16:32:21all of the title of the latest movies as
16:32:23you can see. Okay. See, but here the
16:32:26output we are seeing. See this output is
16:32:28not properly readable. Uh this output
16:32:31has also some metadata information.
16:32:33Okay. So if I give this kinds of output
16:32:35to the user, so user will confuse okay
16:32:37what to read. So that's why uh I have to
16:32:40pass this output to the agent again.
16:32:43That's why I told you in my file itself.
16:32:49Okay. So you can see uh our tools listen
16:32:53for the uh uh tool calls okay and once
16:32:56let's say it perform any kinds of tool
16:32:57calls uh then it automatically route to
16:33:00that particular correct tool then pass
16:33:02the tools output back to the graph okay
16:33:04why it has to pass this output back to
16:33:06the graph because of that because this
16:33:08output is not readable so again what I
16:33:10will do this output I'll try to pass to
16:33:12the the output we are getting see right
16:33:14now this is our architecture so whatever
16:33:17output we are getting from the tools it
16:33:18is getting ended Okay, now we have to
16:33:21again give this output output to the
16:33:23chat node. Okay, if I pass this output
16:33:25to the chat node, chat node will try to
16:33:27refine this output and it will generate
16:33:29a readable output for me. Okay, so
16:33:31that's why I have to do little
16:33:32modification inside my architecture. So
16:33:34let me show you. So here uh I'll just
16:33:38try to add this line. Okay, basically
16:33:40the tools output you are getting okay,
16:33:43you are again sending to the chat node.
16:33:45Okay, this is the modification you only
16:33:47only just need to do. Now let me again
16:33:49execute. Uh okay. So I have to execute
16:33:53from the beginning.
16:34:00Now that's how your structure will look
16:34:02like. See right now we are not returning
16:34:05the tools output. Instead of that the
16:34:07tools output we are getting we are again
16:34:08sending to the chat node. Okay. And chat
16:34:11node will refine the output and it will
16:34:12go to the end node. Now let me show you
16:34:14my output.
16:34:18Now see again uh this will this is using
16:34:20tool
16:34:29see now see the result guys okay see the
16:34:33uh response previously it was only
16:34:35giving this number but right now this
16:34:37giving the result of this equation is
16:34:39this this is more readable right because
16:34:42right now the output we are getting from
16:34:43the tools we again passing to the chat
16:34:45node and chat node is doing the
16:34:47refinement. Now here I'm asking what is
16:34:49the new movies released in 2026. Okay.
16:34:51Now if I send this prompt
16:34:57so this is the response I'm getting.
16:34:58Here are some new movies release
16:35:00scheduled uh for this date. Okay. And
16:35:02you can see all of the movie it has
16:35:04given me. Uh again this is a list. Okay.
16:35:06Uh so what I can do I can get the
16:35:11um
16:35:14get the output.
16:35:19Now I just need to get this text.
16:35:25Now see that's how you can extract the
16:35:28final result. Now see this is more
16:35:29readable. Okay this is more readable.
16:35:33I hope you get it guys. Okay. Now let me
16:35:34show you another question. Uh first find
16:35:37out the stock price of Apple using get
16:35:39stock price tool. Then uh use the
16:35:41calculator tool to find how much it will
16:35:44take to purchase
16:35:46uh 50 shares. Okay. Now these kinds of
16:35:48question I'm asking. Let's see whether
16:35:49it is able to use my tool or not.
16:35:54Now see again I'm getting the result and
16:35:58if you want to get the text you can
16:36:01extract from here.
16:36:04Okay, the stock price of AF is that much
16:36:06and to purchase 50 uh 50 shares it would
16:36:09cost around that that much of money. So,
16:36:13okay, now I think you saw it is able to
16:36:15use the tools right now and this is not
16:36:17a simple chatbot. Okay, this has the
16:36:19tool connection. It can perform any
16:36:20kinds of action. Even you can also ask
16:36:23about the realtime uh weather
16:36:24information. Let me also ask
16:36:32what is the current weather in let's say
16:36:35New York.
16:36:43The kind of weather in New York. Uh New
16:36:45York is moderate rain with the
16:36:47temperature that uh this is the
16:36:50temperature and feeling like uh uh see
16:36:53this is the temperature uh humidity and
16:36:56the pressure. Okay. Each and everything
16:36:59it is giving you. Okay. So yeah guys our
16:37:03uh system is working perfectly.
16:37:05Now we'll be um integrating inside our
16:37:08agentic chatbot. This is the complete
16:37:09notebook experiment I showed you and you
16:37:12have already understood the concept.
16:37:13Okay. Uh how to add the tools and uh I
16:37:16mean how to add the tools and how we can
16:37:18write our custom tools as well. Each and
16:37:20everything I showed you. So guys, now
16:37:22we'll try to add inside our project. So
16:37:24here what I can do uh I can simply
16:37:28create a separate file so that you can
16:37:31refer all of the previous code as well.
16:37:33So I'm going to create a
16:37:37file here.
16:37:45I'm going to name it as let's say
16:37:52this name
16:37:54agentic chatbot
16:37:56tool back end.py
16:38:01file.
16:38:05Okay.
16:38:06And inside that I'm going to copy all of
16:38:08my backend code I had.
16:38:11Okay. The same code you just need to
16:38:13copy paste here. Same code.
16:38:19H. And here I'll do the modification.
16:38:22And again uh I just uh uh finished my
16:38:25open API key limit. That's why I'm using
16:38:28this uh Gemini model. Okay. But if you
16:38:31have your open API key, you can
16:38:32uncomment this line and comment this
16:38:33line. Okay. So, alternative approach I
16:38:35showed you here. So now here I'm going
16:38:38to first of all import all of the
16:38:39necessary library from my notebook.
16:38:45Just import all of this necessary
16:38:47library.
16:38:50Okay. After that we are loading the
16:38:53environment variable. It's completely
16:38:54fine. Then if you have open AP you can
16:38:57unccomment this. that I don't have. I'll
16:38:59be using Gemini model. So once uh model
16:39:02uh initialization is done. So let me
16:39:04comment also so that
16:39:07it would be easy for you to remember. So
16:39:09this is the LLM definition. Now we'll
16:39:11try to define the tools. Okay. So here
16:39:13we'll try to define all of the tool. The
16:39:15tools we have created here. Okay. All of
16:39:17the tools we'll try to define here. So
16:39:19let's copy all of the tools.
16:39:25So here I copy pasted all of the tools.
16:39:27So first tools I had my search tool tab
16:39:29search tool. Second tool I had my
16:39:31calculated tool. Third tool I had my
16:39:33stock price and the fourth tool I
16:39:35created this weather.
16:39:38I'll also copy this one.
16:39:48Copy and
16:39:52paste it here.
16:40:05Okay, some error is coming.
16:40:10Uh, okay. Now it is solved. Uh, the
16:40:13problem was that I just copied till
16:40:14here. Okay. Uh, the last part was uh not
16:40:17copied. Uh, now I think this is fine.
16:40:20Okay, now this is fine. But here I have
16:40:22to import another uh things which is
16:40:24this
16:40:27any. Okay. So any and ways
16:40:35import
16:40:50now from typing I will import this any.
16:40:57So in the tools also I have to do the
16:41:00same thing.
16:41:04Fine. Now uh I think everything is good.
16:41:06Uh this is my calculator. This is my get
16:41:09stock. This is my current weather tool.
16:41:14And this is my chart state.
16:41:17This is my chat state. So here let me
16:41:19comment.
16:41:23This is my chat state. Now I'll define
16:41:25my nodes.
16:41:28same notes only. Okay, one more thing I
16:41:31just forget to do. I just need to do the
16:41:34tool bind operation. I think you
16:41:36remember
16:41:38here. We just need to bind this tool.
16:41:39Let's do that.
16:41:45So before initializing the state, I will
16:41:47just bind this tool. Let me comment
16:41:49here. Bind tools to lm. Now the state
16:41:54definition is also done. Now I'll define
16:41:56my chat nodes.
16:41:58So this is the chat node and the change
16:42:01I have done instead of calling the uh
16:42:04simple llm I'm calling llm with tools.
16:42:07Okay, this object
16:42:09now I'll define my second node which is
16:42:11tool node.
16:42:14Okay, tool node. So I think remember
16:42:16here also I did the same thing
16:42:20tool nodes. Okay.
16:42:22Now uh this this is my uh connector that
16:42:25means my checkp pointer for the
16:42:27persistence memory checkp pointer.
16:42:32Uh this part I already taught you. Okay.
16:42:33Um this is common for all. Now we'll try
16:42:36to define the graph.
16:42:44Okay. We'll try to define the graph. So
16:42:46as you can see this is our graph. If we
16:42:48are adding the nodes where this is the
16:42:49edge connection we are using the tools
16:42:51condition and at the last we are just
16:42:54doing this uh this uh edge connection as
16:42:56well that means whatever tool output
16:42:58we'll be getting we'll try to send it to
16:42:59the chat node that means in the same
16:43:01tools demo.ip IP 1B file I showed you
16:43:03the same thing okay I just copy pasted
16:43:05the code only okay nothing change the
16:43:07same code I copy pasted that's it once
16:43:09it is done I think this function you
16:43:11remember this is the helper function for
16:43:13this streamlend
16:43:15we used okay uh this that means uh with
16:43:18this function we are getting the traits
16:43:19okay for this streaml we created I think
16:43:21in my previous video I think remember so
16:43:23yes guys this is the modification we
16:43:24have to do in the back endpy
16:43:28now uh everything is fine I think let me
16:43:31check
16:43:33H everything is fine now we are ready to
16:43:36uh test inside our front end as well so
16:43:38now I'll just write another front end
16:43:40file
16:43:42so here I'll copy this file as it is
16:43:46and the last file was the DB right
16:43:52yeah last file was the DB so I'll just
16:43:55copy and paste it
16:43:58and I'll just rename it
16:44:05app tool.py.
16:44:12Okay. So, it has the DB with tools uh
16:44:15tools code as well. Okay. Now, here the
16:44:18change you just need to do which is um
16:44:25yeah if you don't change it's completely
16:44:27fine. You can use it as it is. Okay. uh
16:44:29there won't be any kinds of problem but
16:44:31one uh I think UI update you won't be
16:44:33able to see I think at uh whenever I
16:44:36show you my application for the first
16:44:38time right as a demo that time you saw
16:44:40whenever I was executing my agent it was
16:44:42showing it is using some kinds of tool
16:44:44okay see right now if I uh ex execute my
16:44:47app so what will happen let me show you
16:44:48first of all okay one more uh just
16:44:51modification you have to do uh this
16:44:53import okay uh previously I'm importing
16:44:55from agentic chatbot DB back end now I
16:44:57have to import from agentic
16:45:00chatbot tool back end. Okay,
16:45:03so this update only and make sure you
16:45:07have your
16:45:08uh langismith
16:45:10uh langismith uh environment variable
16:45:12that means uh the langismith API key and
16:45:15everything because uh it will trace
16:45:17everything in the langismith. Let me
16:45:18open my langismith platform.
16:45:29And uh let me execute uh completely
16:45:33fresh. So what I can do I can delete
16:45:35this one.
16:45:40I can delete this project and let me
16:45:42execute completely fresh.
16:45:47And now I will execute my app
16:45:51my app tool.py. Okay, this file
16:46:00stream
16:46:02let run
16:46:06app
16:46:08tool.py Fine.
16:46:18Now this is our chatbot. Now let's give
16:46:22the prompt. I'll give hello.
16:46:28See it's working. Now I'll give um tell
16:46:31me the latest news in AI
16:46:44see right now you are getting the output
16:46:46like that but you didn't see it is using
16:46:49the tool okay which tool it is using but
16:46:51previously in the demo itself you saw it
16:46:53is using some kinds of tool even in the
16:46:54chart also if you're asking you will be
16:46:57able to uh see some tool calling. Okay,
16:46:59some tool calling is happening, right?
16:47:01So let's say if I ask the same question
16:47:03in
16:47:04chart JPT, you'll see some kinds of tool
16:47:08calling is happening. See here, it will
16:47:10tell like okay, I'll search for the
16:47:12internet. See searching for the
16:47:14internet. It is using some kinds of
16:47:15search tool. So I want to also see this
16:47:17kinds of uh interface. Uh whenever my
16:47:20agent is using the tool, I'll be able to
16:47:22see that okay, this is using some kinds
16:47:24of tool. Okay. So if you want to see
16:47:26that you just need to do little bit UI
16:47:28update. So in the streamllet app you
16:47:30just need to do some little bit
16:47:31modification. So here uh itself you just
16:47:35need to do the modification. Let me show
16:47:36you.
16:47:38H So here you just need [clears throat]
16:47:39to do the modification whenever you are
16:47:42uh sending the user input right and
16:47:43whenever you are uh just hitting the uh
16:47:46agent that means here here you just need
16:47:48to do the modification. So what I have
16:47:50done guys, I just given this code to the
16:47:52chart GPT and I asked I just need to see
16:47:55this uh tool progress uh tool progress
16:47:58on my user interface whenever it will
16:48:00use any kinds of tool just try to do the
16:48:02UI update. So then again chart GPT given
16:48:05me this code. Let me show you
16:48:11GPT given me this particular code.
16:48:18So from here
16:48:21um everything needs to be changed
16:48:25this part.
16:48:28So this is the update uh chat GP given
16:48:30me guys. So right now uh basically it
16:48:33will automatically understand whenever
16:48:35it will uh use any kinds of tool that
16:48:38time you will able to see in the user
16:48:39interface. Okay. So this code you don't
16:48:41need to remember guys. uh you have charg
16:48:43you have gemini anytime you can do the
16:48:45modification inside at the UI interface
16:48:47because this functionality is completely
16:48:49user interface uh let's say update okay
16:48:52so as a aenti engineer this is not your
16:48:54task there are some front- end developer
16:48:57they will take care this part okay I
16:48:59need to import one tool uh things which
16:49:01is tool messes
16:49:03uh here only tool masses okay that's it
16:49:06now this is the updated code now if I
16:49:10execute this code let me show show you
16:49:12what will happen. So I'll reexecute my
16:49:14app.
16:49:20Now if I ask the same question, tell me
16:49:24tell me
16:49:27the latest news in
16:49:32here.
16:49:34Now you will see that it will be using
16:49:37some kinds of tool.
16:49:39Now see it is using tably search tool
16:49:41and it is uh doing the realtime search
16:49:43operation and the response it is uh
16:49:46generating it is again giving to the
16:49:48chat nodes and chat node is refining the
16:49:51output. Okay, now you are able to see
16:49:53the okay uh refinement result and you
16:49:58can also see the tool execution that
16:50:00means in the behind the tool what is exe
16:50:02what the execution is happening this is
16:50:04also available okay like charg
16:50:07you can also see the uh behind execution
16:50:09process like what the website it has
16:50:11referred and everything you will be able
16:50:13to also see here okay this also possible
16:50:16now let me ask another question I'll
16:50:18tell um
16:50:22calculate
16:50:30this number.
16:50:32Now you'll see that it will use my
16:50:33calculator tool.
16:50:36See calculated tool done. Okay. Now here
16:50:39I will ask now here I will give another
16:50:41prompt. Uh what is the current weather
16:50:43in New York?
16:50:48Uh okay guys, one problem I found it is
16:50:50not able to use my uh current weather
16:50:52tools. Okay, why if I show you the code,
16:50:55see whenever I did the bind operation,
16:50:58right? So here I didn't add my uh
16:51:00current weather tool here. So this is
16:51:02the problem. So what I will do? I'll
16:51:04just try to copy that code. Uh that's
16:51:06why I'm telling why it's not working. Uh
16:51:10yeah. So I'll copy this code as it is
16:51:13and paste it here.
16:51:17Okay. Now I think it should work. Let's
16:51:18see. I'll reexecute my app.
16:51:29Now here you can ask the same question.
16:51:39What is the current weather in New York
16:51:40or any other city?
16:51:51Now see it is using get current weather
16:51:53tool and this is the current weather in
16:51:55New York right now. Okay. And you can
16:51:57also ask any other question as well.
16:51:59Tell me
16:52:04give me all the movie
16:52:08list.
16:52:15in 20 26.
16:52:26See it is using table rule and it will
16:52:29realtime search over the internet and
16:52:30this will give you the result.
16:52:38See this is the entire result. I'm
16:52:40getting all the latest movie information
16:52:42I'm getting here. Amazing. Right now my
16:52:45uh aentic chatbot is working like chart
16:52:48GPT. So chart GPT has this kinds of tool
16:52:50as well. That's why it is giving you
16:52:51realtime informations. Okay. And our
16:52:54chatbot is also working in that way. Now
16:52:56if I open up my um uh Langmith
16:53:00dashboard. So if I go to my project now
16:53:02here all of the trades has executed.
16:53:04Even you can see trade wise. Okay. Trade
16:53:07wise you can see. Now let's I will see
16:53:09this particular trades. I will open it
16:53:11up and you can see the execution. Now
16:53:14here you can see guys I have added the
16:53:15tool and automatically this tools has
16:53:18integrated inside my language dashboard
16:53:20as well. Now see this is my chat node.
16:53:26Okay. And uh whenever you given this
16:53:29message it will go to the chat node.
16:53:30Chat node will uh hit the invoke the LLM
16:53:33and LLM has the tool condition
16:53:35integrated. Okay. Now tool condition has
16:53:37decided. Okay. It has to use the get
16:53:39current weather tool because what was
16:53:41the question? The question was what is
16:53:43the current uh weather in New York. So
16:53:45it will go to the tools condition. Tool
16:53:47condition will decide okay it has to use
16:53:48the tool and which tool it will call get
16:53:51current weather tool. Okay. This tool it
16:53:53will call. Now tool condition will try
16:53:55to redirect this this thing to the tool
16:53:58nodes. Okay. And now tool nodes will uh
16:54:01select this get current weather tool and
16:54:04uh what would be the location Newark.
16:54:05And if you pass this network to the get
16:54:07weather uh get weather function, this
16:54:10will return you the current weather
16:54:11information in New York. You can see
16:54:12this is the output. Okay. And this
16:54:14output we are sending again to the chat
16:54:16node. Okay. You can see say again
Implement RAG in Agentic Chatbot with LangGraph
16:54:18sending to the chat node. Now this is
16:54:20the input as well as the user input we
16:54:23are sending it and AI is generating this
16:54:26refine output. Okay. So that's how the
16:54:28entire system is working right now.
16:54:30Okay. Now I think you can see guys what
16:54:32is the use of lang as well because in
16:54:34the lang itself you can debug everything
16:54:37after which note which node is executing
16:54:39whether it is able to select the right
16:54:40tool or not okay so that's how you can
16:54:42understand each and everything I hope it
16:54:44is clear guys okay so yes guys uh this
16:54:46is all about of our agentic chatbot now
16:54:49uh this aentic chatbot is uh not a
16:54:52simple chatbot okay this has the tool
16:54:54connection it it can perform different
16:54:56different actions now uh I can tell this
16:54:59is more advanc advanced agentic chatbot
16:55:01we have created. Now uh some other
16:55:03functionality also needs to be added in
16:55:04this agentic chatbot. We'll also try to
16:55:06add the RG functionality that is you can
16:55:08upload any kinds of document you can
16:55:09apart from the chat operation. So yes
16:55:12this is all about from this
16:55:13implementation. I hope you liked it. So
16:55:14if you like this implementation guys
16:55:16please try to subscribe to my channel
16:55:17and share this video with your friends
16:55:19friends and family. So guys uh this is
16:55:21our agentic chatbot we have developed so
16:55:23far and we have integrated lots of
16:55:25features with this agentic chatbot. Now
16:55:27this is not a simple chatbot right now.
16:55:29This has uh like um uh conversation um
16:55:33like uh trades. It has uh tool
16:55:36integrations. It has streaming features.
16:55:39Even it has the persistence memory with
16:55:41the permanent database. Okay. So this is
16:55:43not a simple chatbot right now. Now the
16:55:46functionality I have added here this RG
16:55:48functionality that means rag
16:55:49functionality. Now in this chatbot in
16:55:51this aentic chatbot you can upload any
16:55:53kinds of documents. Okay. And you can
16:55:55start uh doing the conversation on top
16:55:57of that like chat GP. Okay. So, chart
16:55:59GPT also has the same features. If I
16:56:02show you the chart GPT. So, in chart GPT
16:56:04also you can upload any kinds of
16:56:05documents and you can perform chat on
16:56:07top of that. So, first of all, let's see
16:56:09our application. Okay. So, here let's
16:56:10say I will upload a documents.
16:56:14Let's say this is the documents I will
16:56:16upload. So, this is a research paper
16:56:17actually I published um uh this research
16:56:20paper. So, as you can see this is the
16:56:21paper guys. The paper name is um
16:56:24development of multiple combined
16:56:26regression method for rainfall
16:56:28measurement. Okay. So here you can see I
16:56:31was uh I was the author. Okay. So I
16:56:33contributed in this paper. So this paper
16:56:35covers uh about the uh rainfall
16:56:39measurement. Okay. Uh by uh by using
16:56:42some regression methods. Okay. You can
16:56:44go through the paper. This is also
16:56:45available on the research gate. Okay.
16:56:48Now what I'll do I'll just upload this
16:56:49paper on my aentic chatbot. I'll select
16:56:52this paper. I will upload it.
16:56:57See it is uh getting uploaded and it is
16:56:59processing. Okay. So once it is done now
16:57:02see here you can see the successful
16:57:04message. Now I can perform the chat
16:57:06operation. Now I'll just ask what is
16:57:09rainfall
16:57:11measurement
16:57:14based on
16:57:18the uploaded PDF.
16:57:25Now see it is using my rack tool. Okay.
16:57:28So internally I created a rack tool. It
16:57:30is utilizing my rack tool and it is
16:57:33giving you some kinds of response. As
16:57:34you can see the document highlight that
16:57:36uh predicting the amount of rainfall
16:57:38recorded in millimeter uh is uh crucial.
16:57:42It it uh notes that uh conventional
16:57:46methods for forecast uh for for seeing
16:57:49rainfall using equipment based on
16:57:52climate coordinate uh coordinations like
16:57:54temperature, humidity and weights are
16:57:57not productive. Okay. Instead of uh
16:57:59instead the paper process using the
16:58:01machine learning uh pro uh procedure and
16:58:05specifically
16:58:07predictive regression analysis
16:58:08technique. Okay. So yes uh if you go
16:58:11through the paper guys you will be able
16:58:12to see the same things this paper paper
16:58:14covers actually we proposed some
16:58:16regression method for this uh rainfall
16:58:18measurement technique. Okay. Now we can
16:58:21you can also ask any other things like
16:58:23say what is the methology
16:58:30uh methodology
16:58:33of
16:58:35this paper
16:58:40in methodology.
16:58:44Okay. Now I'll send this prompt.
16:58:48Now see it is again using the rag tool
16:58:51and it is uh it is giving you the entire
16:58:54methodology uh we have written in the
16:58:56paper. You can see uh this is the entire
16:58:58methodology. So if you go through our
16:59:00paper methodology you will able to see
16:59:02the same things we are discussing there.
16:59:04Okay. So that means like chart GPT we
16:59:06are able to upload any kinds of
16:59:08documents. Okay. And we can perform the
16:59:10conversation. So in charge also you can
16:59:12try you can upload your documentation.
16:59:14Okay. And you can do the conversation on
16:59:16top of that. And we have also integrated
16:59:18the uh tracing features with our agentic
16:59:21chatbot. That means it will continuously
16:59:23monitor our agentic chatbot. Okay. And
16:59:25we are continuously tracing the
16:59:27execution on the Langismith platform
16:59:30guys. As you can see these are all of my
16:59:33trace. Okay. And you can monitor the
16:59:35entire trace entire let's say
16:59:37application uh in this Langismith
16:59:39dashboard only. Okay. So this part I
16:59:42also showed uh in my playlist uh just go
16:59:44through and check that that how we can
16:59:46add this langismith functionality inside
16:59:48our um application. Okay. So yes uh this
16:59:52is the features guys I have added uh
16:59:54inside our agentic chatbot and trust me
16:59:56this is uh very much important whenever
16:59:58you are creating aentic system. Nowadays
17:00:00all the agentic uh applications are you
17:00:03uh applications are having this kinds of
17:00:05RG functionality that means uh you not
17:00:08only you can um do the conversation with
17:00:10the tools and the um default large
17:00:13language model instead of that you can
17:00:15upload your private documents and you
17:00:17can continue the conversation on top of
17:00:19that okay everything is possible here so
17:00:22uh yes guys this is the application and
17:00:24apart from that this application uh can
17:00:26also um handle different different
17:00:28conversation let's say if I'm asking
17:00:30Tell me the latest. Okay. Latest news
17:00:37uh of FIFA.
17:00:41Okay. 2026
17:00:45did uh Brazil
17:00:48on the game.
17:00:50Now see this is the question. This is
17:00:52the latest information I'm asking and my
17:00:55agentic chatbot will be using some kinds
17:00:57of search tool and it will give me the
17:00:59response. Now see it is using tably
17:01:01search tool. I already told you about
17:01:03what is tab right and it is doing the
17:01:05internet search tool. Uh it is doing the
17:01:07internet search and it is giving you the
17:01:08realtime response as you can see. Yeah.
17:01:11So this is the answer. In the FIFA World
17:01:13Cup 2026
17:01:16a group C match which ended in a one by
17:01:18one draw. Okay. Then uh Venicius Junior
17:01:22scored Brazil in this uh simulated game.
17:01:25Okay. So this was the like match guys.
17:01:28If you have already watched that Brazil
17:01:30match, you saw like uh this was a draw
17:01:32match actually and this uh Venicius
17:01:36Junior actually scored um uh one goal
17:01:39for the Brazil. So yes guys that's how
17:01:41our agentic uh chatbot works and uh you
17:01:44can upload any kinds of documents right
17:01:46now and you can uh start the
17:01:48conversation on top of that apart from
17:01:50that whatever functionality we have
17:01:51created so far whatever tools we have
17:01:53integrated so far it will be working
17:01:55like a same right so now let's start
17:01:57implementing this uh functionality
17:01:59inside our agentic chatbot but before
17:02:01that first of all I want to give you the
17:02:03idea about uh rag what is retable
17:02:06augmented generation techniques and uh
17:02:09why it is useful. Okay. And how this
17:02:12system works. Okay. First of all, we'll
17:02:13try to understand then we'll start the
17:02:16development guys. So guys uh as you can
17:02:18see uh rag in aentic chatbot it's a very
17:02:21important features uh not only in
17:02:24agentic chatbot uh whenever you are
17:02:26working with the uh generative AI
17:02:29technology especially with the large
17:02:30language model this rag is very
17:02:33important uh like component of that. uh
17:02:35if you have already studied about JNA I
17:02:37think you already work with rag concept
17:02:40right so rag helps us actually in three
17:02:43majors uh uh actually field one is the
17:02:46outdated knowledge so I think you know
17:02:48whatever large language model you are
17:02:51using it has a knowledge cut off right
17:02:53so if I'm talking about the let's say
17:02:56GPT 4 or GPT 3.5 right uh it has a
17:03:00knowledge cut off till 2021 uh this
17:03:03model got trained
17:03:05And after that actually whatever um new
17:03:08data came in the internet this model
17:03:10doesn't have the access to that data
17:03:13right because it has a knowledge cutoff
17:03:15that means if you are asking anything
17:03:16regarding after that date this model
17:03:19won't be able to give you the response.
17:03:21So it's not like that again you have to
17:03:22fine-tune that model okay on the new
17:03:24data because finetuning at the end it's
17:03:26a costly task. uh for this you need a
17:03:29good um instance, you need good
17:03:31infrastructure, you need lots of money,
17:03:33you need you need lots of data, right?
17:03:35So that's why researcher introduced the
17:03:37rack concept and with the help of rag
17:03:39actually you can give external data to
17:03:43the large language model as a knowledge
17:03:45base and your LM will be able to
17:03:48generate the response uh you are asking
17:03:51about the latest information you have
17:03:53already given right so this is the
17:03:55concept of the rag so that's why if if
17:03:57your model has outdated knowledge that
17:04:00time rag is very important for that and
17:04:03only things you have to create a detail
17:04:05knowledge base, okay, with your custom
17:04:07data. Now, the second thing is the
17:04:09private data. Okay, so what is private
17:04:11data? Uh private data means let's say um
17:04:14uh just I showed you one example. I
17:04:16uploaded my paper, right? I uploaded my
17:04:18research paper. So this research paper
17:04:20is my private data and I want to perform
17:04:23some conversation on on top of my
17:04:25private data. I want to understand about
17:04:27my private data. Not only research
17:04:29paper, you can upload any kinds of
17:04:31private documents of yourself. You can
17:04:33upload about your life story. You can
17:04:35upload about your let's say any kinds of
17:04:38inventory list. Okay. Anything you can
17:04:39upload and you can perform the
17:04:41conversation on top of that. Okay. So
17:04:43this private data actually is not
17:04:45available in the LLM. Okay. The default
17:04:48LLM we are using. So that's why uh we
17:04:51have to create this rack technique so
17:04:52that I can upload any kinds of private
17:04:54documents and I can start uh doing the
17:04:56conversation on top of that. Okay. I can
17:04:59ask anything. I can get any kinds of
17:05:01feedback from my um like chatbot. Then
17:05:04the third is the hallucination.
17:05:05Hallucination uh happens let's say
17:05:07whenever uh you are uh asking your agent
17:05:11uh uh to do something. Let's say you are
17:05:13asking give me some um give me some
17:05:16let's say uh research topic link. Okay.
17:05:20Uh for that particular topic let's say
17:05:22this topic your u um agentic uh chatbot
17:05:26doesn't know right. uh let's say this is
17:05:28completely new topic uh this is not
17:05:30available uh in the um in the large
17:05:34language model knowledge base so that
17:05:35time what will happen uh it might
17:05:37generate some wrong URL right it might
17:05:39generate some wrong URL and if you go to
17:05:41the URL you will be able to see this URL
17:05:43is not working this research article is
17:05:45not working right so instead of what you
17:05:47can do maybe you can uh give some of the
17:05:50uh resources okay you can give some of
17:05:52the document uh to your agentic chatbot
17:05:55uh as a external knowledge and you and
17:05:58uh tell like okay now refer this uh
17:06:00actually knowledge and you can generate
17:06:02some um like research topics or let's
17:06:04say URL okay on top of that so that time
17:06:07actually your LLM will not do the
17:06:09hallucination but if you are not doing
17:06:10that uh there is a possibility your um
17:06:13chatbot will do the hallucination okay
17:06:16uh it might generate something wrong
17:06:18information for you so that's why this
17:06:20RZ technique is super important whenever
17:06:22you are creating this kinds of system
17:06:24that's why nowadays all of the
17:06:25application you have seen like charg
17:06:27GPT, Gemini. Okay. Uh these are the
17:06:29application are using this uh RA concept
17:06:32in their um application. Uh that means
17:06:34you can upload any kinds of documents.
17:06:36Okay. PDF whatever and you can perform
17:06:38the conversation on top of that. Now
17:06:41let's try to understand how this uh rag
17:06:43works. So this rag came from actually in
17:06:45context learning techniques. So in in
17:06:47context learning what happens. So this
17:06:49is the like highle diagram of this in
17:06:52context learning. So here we not only
17:06:54pass a query okay to the large lang
17:06:56based model uh with the help of with
17:06:59this query we also give some kinds of
17:07:00external context okay then we prepare a
17:07:03prompt and this prompt will try to send
17:07:05to the large language model and large
17:07:07language model will uh generate some
17:07:09kinds of response now let's try to see
17:07:11this part in action so what I'm going to
17:07:13do I'm going to give you one example
17:07:14let's say uh here you are asking about
17:07:18your um let's say paper so I uploaded
17:07:22one paper I you remember called rainfall
17:07:23measurement paper. So if I ask directly
17:07:26this question okay to my large language
17:07:29model let's say here I'm using very old
17:07:30large language model and this large
17:07:32language model trained till let's say
17:07:342019
17:07:36okay and if you see my paper guys this
17:07:39paper I published around 2021 okay so
17:07:43this paper information definitely it's
17:07:45not available inside my large language
17:07:47model so if I'm asking about this uh
17:07:49let's say paper let's say tell me about
17:07:50this rainfall measurement paper okay
17:07:53rainfall
17:07:56rainfall paper. Okay, let's say I'm
17:07:58asking my large language model. This is
17:08:01my entire prompt. I'm passing to the
17:08:03large language model. That time large
17:08:05language model will definitely not uh
17:08:07provide the response because it doesn't
17:08:09have the information. Okay. So in in
17:08:11context learning what happens instead of
17:08:13giving the direct query you can also
17:08:15pass the context. Context means here you
17:08:17can give the entire paper. Okay. You can
17:08:19pass the entire paper. Okay. you can
17:08:22extract all of the uh content or you can
17:08:24directly uh give the paper okay as a
17:08:26context and you can combine a prompt.
17:08:28Let's say uh tell me about rainfall uh
17:08:31measurement paper and here is the
17:08:37uh here is the
17:08:41paper
17:08:42content.
17:08:44Okay, content and you are already
17:08:46passing the paper here, right? You're
17:08:47already passing the paper here. That
17:08:49means you are giving the query as well.
17:08:52Okay, you are also giving the paper.
17:08:55Okay, then you are asking tell me about
17:08:56the rainfall measurement. Now your LLM
17:08:59has the context as well as the query.
17:09:01Now it can generate the response. Okay,
17:09:04you are ask uh it it can generate the
17:09:06response the question you are asking by
17:09:08using this particular context. Okay. In
17:09:10real life also let's say if I'm asking
17:09:12you anything which is completely new and
17:09:15let's say if you don't don't know that
17:09:17information if you don't know that let's
17:09:18say question that time you will directly
17:09:20say okay I don't know but if I give you
17:09:22some kinds of context let's say I will
17:09:24ask about uh tell me about um let's say
17:09:28uh Brazil team okay uh so what you will
17:09:31do um if I give you some context let's
17:09:34say if I give you list of the uh Brazil
17:09:36uh player uh uh let's say name list then
17:09:39you'll be able to uh give me okay these
17:09:41are the player players are available in
17:09:44Brazil team right it's it's like that
17:09:46that means you are not only giving the
17:09:48query but also you are providing the
17:09:50answer that means the context okay the
17:09:52entire paper now is referring that paper
17:09:55and it is generating the question you
17:09:57are asking let's say you are asking
17:09:58about rainfall measurement it will be
17:10:00able to uh understand about the rainfall
17:10:02measurement from the paper and it will
17:10:04give you some kinds of refined response
17:10:05so that's how in context learning works
17:10:07okay but the problem with in context
17:10:09learning is so let's say here the paper
17:10:11I'm uploading it might have lots of
17:10:14content right it might have lots of
17:10:15content content means if you see the
17:10:19paper all of the words you can consider
17:10:21as a token right and if you count all of
17:10:23the token uh there is a chance this
17:10:25token okay number of token um might
17:10:29increase than your uh input length of
17:10:33the model input limit
17:10:36of lm okay so every model has a input
17:10:39input limit right uh token limit if you
17:10:41open any kinds of model right uh in uh
17:10:44Google you will see that it has a input
17:10:45limit token limit let's say uh the model
17:10:48we are using this model can take uh
17:10:501,000 okay 1,000 token input at a time
17:10:54but if you're passing uh the entire
17:10:56paper let's say the paper token I have
17:10:58counted it is around 5,000 token okay
17:11:025,000 token that time definitely this
17:11:04token is um um bigger than your input
17:11:07token limit that time that would be an
17:11:09error. Okay, there would be some kinds
17:11:11of input error. That means you can't
17:11:12pass uh that many of token as an input
17:11:14to the model. Okay, so this was the
17:11:16problem with the in context learning. So
17:11:18that's why from the in context learning
17:11:21one concept has introduced the concept
17:11:23name is rag. Okay, so in rag actually
17:11:26what we do instead of giving the entire
17:11:28documents directly we perform something
17:11:30called chunking we perform something
17:11:31called splitting. Okay, we uh divide our
17:11:35entire content in a different chunk,
17:11:36different split and we pass this uh
17:11:40different chunk, okay, one by one to the
17:11:43model. So this is the like updated
17:11:44architecture as you can see. Let's say
17:11:46here I am having an entire documents.
17:11:48First of all, we'll try to uh extract
17:11:50all of the content from the document
17:11:52itself. Okay, we'll load the documents
17:11:54and we'll extract all of the content
17:11:55from the documents as you can see. Okay,
17:11:58and once it is done, we'll try to
17:11:59perform some kinds of chunking
17:12:01operation. We also call it as a speeder
17:12:03text splitter. Split means let's say
17:12:04this is my entire docs, right? This is
17:12:06my entire content and I'll just try to
17:12:09create a different different chunk. I'll
17:12:11try to divide this content okay in a
17:12:12different different part. This is called
17:12:14text splitter. Okay. Now let's say if
17:12:16your original documents it is around
17:12:195,000 token. Okay. Now after doing this
17:12:22splitter or chunking every uh every
17:12:24let's say chunk will have let's say
17:12:271,000 token. Okay. 1,000 token. That's
17:12:30how you can create five uh five actually
17:12:33chunk here or let's say four chunk here
17:12:34or six chunk here. It's completely up to
17:12:36you. Okay. But it uh this input should
17:12:39be uh less than your model input. So
17:12:42once you have created the chunk then you
17:12:45will be using some kinds of embedding
17:12:46model. I think you know about embedding
17:12:48model. What embedding model does?
17:12:49Basically embedding model we use to
17:12:51convert our text to the number because
17:12:53the large language model we are using
17:12:55right it can't take directly the English
17:12:57text as an input. Okay. Okay, internally
17:12:59because this is some kinds of
17:13:00mathematical equation. So we have to
17:13:02convert as a number, right? We'll be
17:13:04using this embedding model and we'll
17:13:05generate some kinds of vector embedding.
17:13:07This is called vector embedding, right?
17:13:09This called vector embedding. Now this
17:13:11vector embedding we have to store
17:13:12somewhere. This is called actually
17:13:14vector database and we call also call it
17:13:15as a vector store. Okay, especially in
17:13:18rag uh you will be using vector database
17:13:20not a traditional normal database. Okay,
17:13:23here you have to use vector database
17:13:24because there's a concept called
17:13:25similarity search or semantic search you
17:13:28have to perform and this is only
17:13:29possible in vector database only right
17:13:31then you'll be storing all of this
17:13:32vector in the vector database okay now
17:13:35this will become your knowledge base
17:13:36this will become your knowledge base
17:13:38guys okay now this knowledge base we
17:13:40have to connect with our large language
17:13:41model right now okay now this part
17:13:43actually we perform the retar operation
17:13:46that means if user is asking about a
17:13:48question about the let's say the paper I
17:13:50have uploaded rainfall measurement so
17:13:52First of all, this question will go to
17:13:54the knowledge base. Okay, because
17:13:56knowledge base has all of the okay all
17:13:59of the uh information about the rainfall
17:14:02measurement because I have uploaded the
17:14:03entire paper. It is available here,
17:14:04right? So then uh this retriever it will
17:14:07go here and it will perform a semantic
17:14:08source operation and it will only
17:14:10extract that part which is required for
17:14:12the query. Let's say here I'm asking
17:14:14about what is rainfall measurement. But
17:14:16if you open the paper instead of
17:14:17rainfall measurement, it it has lots of
17:14:19like uh see topic. It has the related
17:14:22works. It has the methodology. Okay.
17:14:24Then it has some comparison. It has some
17:14:26data set introduction. Okay. It has some
17:14:28diagram pre-processing section. So I
17:14:30don't need all of the information. I
17:14:32only need that part where it covers what
17:14:34is rainfall measurement exactly. Okay.
17:14:36So with the help of the similarity
17:14:37search, it will only found that
17:14:39information. Okay. Which is you are
17:14:41asking in the query and it will give you
17:14:43that particular uh relevant response. So
17:14:46here you can see this question will go
17:14:47to the knowledge base and knowledge base
17:14:49will return some relevant response based
17:14:51on the query you are asking most
17:14:52relevant chunk okay we call it as a most
17:14:54relevant chunk or context then you are
17:14:56combining the query also here you can
17:14:58see the query you are also combining
17:15:00then you are preparing the final prompt
17:15:01that means you can you are combining
17:15:03this query with the prompt let's say uh
17:15:05uh this my query is what is rainfall
17:15:07measurement and you got the rainfall
17:15:09measurement answer now we are combining
17:15:11the prompt uh what is tell me about
17:15:15rainfall measure measurement and here is
17:15:16the context then you are generating a
17:15:19entire prompt and this prompt you are
17:15:20passing to the LLM. Now LM has the query
17:15:23as well as the context. Okay, the
17:15:25question you are asking then LLM will
17:15:27try to read that it will understand and
17:15:29it will refine some kinds of uh final
17:15:32response and it will uh show you this
17:15:35particular response. Okay, so that's how
17:15:36the entire RG system works. Okay, so
17:15:39this is the better version of the in
17:15:41context learning because in context
17:15:43learning we pass the entire documents.
17:15:44Okay, and what is the problem with the
17:15:46entire documents? because it has a input
17:15:48limit. But here uh if you are giving
17:15:51let's say thousands of thousands token
17:15:53input as well, it doesn't matter because
17:15:55it perform the chunking operation. It
17:15:57perform the splitting operation and all
17:15:59of the entire documents would be
17:16:00splitted into different chunk and it
17:16:02will store in the vector database. Then
17:16:04you can perform any kinds of uh ret
17:16:06operation. Okay, similarity search
17:16:08operation and you can perform this kinds
17:16:10of question and answer on top of your
17:16:12private documents. So that's how this RG
17:16:15system works guys. Okay, I hope this
17:16:16part is clear to all of you. Now, we'll
17:16:18try to implement this system guys inside
17:16:21our aentic chatbot. But before that, I
17:16:23want to show you the notebook
17:16:24experiment. Okay, like uh let's say I
17:16:27will uh show you the step-by-step
17:16:29procedure how we can implement this.
17:16:32Okay, with our uh agentic chatbot uh
17:16:35because we are using langraph how we can
17:16:37do it with the help of langraph. I'll
17:16:38show you the entire experiment and once
17:16:40our experiment is working then I'll try
17:16:42to integrate inside our actual code. So
17:16:45guys uh as you can see this is our
17:16:47entire code and this code I have already
17:16:49uploaded in my GitHub and link is given
17:16:51in the description. So here in the
17:16:53notebook folder guys I added another
17:16:55notebook called rag demo. Okay just open
17:16:57this notebook and here I already written
17:16:59all of this code uh required to
17:17:02implement this functionality right
17:17:04instead of writing from scratch because
17:17:05it will take lots of time instead of
17:17:07that maybe I can go through my
17:17:09implementation right. So here just try
17:17:11to select your environment. After that
17:17:13uh first of all you have to import all
17:17:15the necessary libraries. Okay. So here I
17:17:17have already imported all the necessary
17:17:19libraries guys. As you can see open AI
17:17:21open embeddings. Okay. Even I have also
17:17:24um imported this uh Google generate. uh
17:17:27because uh if you don't have openi API
17:17:30key if you don't have openi let's say uh
17:17:33provider that time you can use uh
17:17:35alternative uh way uh for running this
17:17:37project you can use gemini model and
17:17:39gemini model by default you will be
17:17:41getting some free uh free access okay
17:17:43you can use that particular model so
17:17:44that's why I'm importing this uh gemini
17:17:46and if you want to use this gemini you
17:17:48have to import this chat Google generate
17:17:50functionality and I have already
17:17:52installed this in my requirement as you
17:17:54can see this uh this library I have
17:17:55already installed there apart from that
17:17:57you have to also uh import this Google
17:17:59generate API embeddings because I don't
17:18:01have uh open AAI embedding model right I
17:18:04don't have open API key that time I can
17:18:05use uh Gemini embedding model okay so
17:18:08that's why both I have imported let's
17:18:10say whichever you have you can use them
17:18:12okay then load ENB pi PDF loader see if
17:18:15you are implementing RG that time this
17:18:18thing is required if you are uploading
17:18:19the PDF document that time from langen
17:18:22community you can uh import this pi PDF
17:18:25loader this is already available in
17:18:26document loaded and for this you have to
17:18:28install some library like uh langen
17:18:31community uh then you have to install
17:18:34fire CPU fire is a vector database okay
17:18:36apart from fi actually there are some
17:18:38other vector database are available like
17:18:40uh web is there chromad is there pine
17:18:42cone is there okay maybe in future
17:18:44project we'll try to use but uh in this
17:18:46project I'm going to use fires okay fs
17:18:48vector database and fires is a in um in
17:18:51storage database that means uh it will
17:18:53create uh the database inside your uh uh
17:18:56computer. Okay, inside your computer
17:18:58computer um hard drive and uh there are
17:19:01some cloud-based uh uh vector database
17:19:03are available like web 8 is there then
17:19:05pine cone is there you can store all of
17:19:07your vectors in cloud okay this part I
17:19:08will also show you later on then pipe
17:19:10vdf you have to also install because uh
17:19:12we'll be uploading PDF documents here so
17:19:14in this project guys uh only just to
17:19:16show you I I'll be considering the PDF
17:19:18documents but if you want you can also
17:19:20upload docs format you can upload excel
17:19:22format okay this part you can go through
17:19:24the simply length documentation Okay,
17:19:26there you will try to see how to load
17:19:27the documents, how to load the Excel
17:19:29documents. Okay, each and everything
17:19:30they have given. But here I'm going to
17:19:31only consider PDF documents. Then one
17:19:34another uh library you have to install
17:19:36called langent text splitter. And this
17:19:38langent text splitter we'll be using for
17:19:40this uh for this actually chunking
17:19:42operation. Okay. Uh from the entire
17:19:44document will perform different
17:19:45different chunk right and with the help
17:19:46of this langent text splitter will be
17:19:48doing this particular part. And here I
17:19:51have already specified the version.
17:19:52These are the version you have to
17:19:53install. And how to install? Open your
17:19:55terminal and just execute pip installer
17:19:58requirement.txt. Okay, if you do that it
17:20:01will install in your system. Okay, so I
17:20:03have already installed all of the
17:20:04necessary library guys. I don't need to
17:20:06install again.
17:20:09But if you're doing it for the first
17:20:10time, you have to install these other
17:20:12library. Okay, I mean all the comment I
17:20:14have also given in my readmi.mmd file.
17:20:16So once it is done guys, let's import
17:20:18all of the necessary library. You can
17:20:19see I'm importing this uh recursive
17:20:22character text splitter from langent
17:20:24text splitter and with the help of that
17:20:26we'll be performing the chunking. Then
17:20:29uh we are also importing a vector
17:20:30database. It is also available inside
17:20:32langen community vector store. I'm
17:20:34importing fires. Okay. And fires has
17:20:36implemented by meta team. Okay. By
17:20:39Facebook uh this uh vector database has
17:20:42implemented. Then um we are importing
17:20:45tools graph then annotated type dick.
17:20:47These are the things are common add
17:20:49messages, human message based messages.
17:20:51Okay. And from lang graph we are also
17:20:53importing some pre-built uh let's say
17:20:56node like tool node and tool condition.
17:20:58So these are the things are common.
17:21:00Okay. So this is our entire import.
17:21:01Let's import them one by one.
17:21:04So see guys I have imported
17:21:06successfully. Now we have to load the
17:21:08environment variable. So as you can see
17:21:10we already have the environment variable
17:21:11here. And here I have already added all
17:21:14of my API key. Uh I used TA API key. I
17:21:18used open weather API key, Google API
17:21:21key. Okay. And this API key I collected
17:21:22from Google AI studio. If you want to
17:21:24use Gemini model. So in my previous
17:21:26video guys, I showed you showed you this
17:21:28part. Okay. How to collect all the API
17:21:30key. Uh you can go through that
17:21:31recording. Then from Langmith tracing
17:21:34guys, we have added these three uh four
17:21:36things. And here you have to pass the
17:21:38LSmith API key as well from the lang
17:21:40platform. Okay. So these are the
17:21:42credential you need. Now let's load all
17:21:44of them. Now if you're if you are
17:21:46already having this open API key you can
17:21:48uncomment this line and you can use uh
17:21:50open API model open AI model and if you
17:21:53don't have open AIP key if you have only
17:21:55Gemini key that time you can use this
17:21:57definition okay so here we are using
17:21:59Gemini model so let's load the Gemini
17:22:01model now we'll try to uh load my paper
17:22:05okay one of my documents so here I
17:22:07already kept my documents my paper that
17:22:09means this paper I already
17:22:12uh I already copied in the folder Okay,
17:22:14you can use any other documents as well.
17:22:17So this is the name of the PDF. So I
17:22:19have to load this particular PDF. Now
17:22:21for loading it, I'm using PI PDF loader
17:22:23because this is a PDF file. Now let's
17:22:25load that. Okay. So once you do the
17:22:27loaded dotload operation, you will be
17:22:29able to see the entire documents. Now
17:22:30let me show you the entire documents. So
17:22:32this is the documents. Now by default
17:22:34langen loads uh your documents into
17:22:36document format, okay, as a page by
17:22:39page. So how many page this is having? I
17:22:41think this uh PDF is having 15 pages.
17:22:44Okay. 15 pages content I have extracted.
17:22:47Okay. And you can see some metadatas are
17:22:48available but the main part is that the
17:22:50content. So let me show you uh here is
17:22:54the content page content. Okay. And in
17:22:56the past content you will have all of
17:22:57the uh text. Okay. I have in my PDF uh
17:23:01and these are some meta information. Now
17:23:04we'll try to perform this this
17:23:05operation. That means we have extracted
17:23:07the entire document. Now we have to
17:23:08perform the chunking guys. Okay. we have
17:23:10to perform the chunking. Now this part
17:23:12actually performs the chunking
17:23:13operation. We are importing recursive
17:23:15character explainer and here we are
17:23:16defining the chunk size. Okay, that
17:23:18means each of the chunk will have how
17:23:20many token. Okay, here we have defined
17:23:22each of the chunk will have 1,000 token.
17:23:25Okay, uh and there is a um another
17:23:28parameter you have to provide called
17:23:29chunk overlap. This chunk overlap
17:23:31basically uh means that uh there it has
17:23:34to add some overlapping. Okay, over
17:23:36overlappinging means let's say let's say
17:23:39it is uh it is extracting 1,000 token.
17:23:42Okay, let's say till here you have 1,000
17:23:44token. Okay. Now, next again it will
17:23:47create another chunk, right? Uh let's
17:23:48say from here it will start. But if
17:23:50there is a chunk overlap, let's say 200,
17:23:52what it will do? It will go back 200
17:23:55word. Let's say 200 word uh starts here,
17:23:57then it will create uh again uh 1,000
17:24:00tokens from here. Okay, that means from
17:24:02your previous chunk, okay, there is a
17:24:05overlap I am creating so that my model
17:24:07can understand, okay, after this token,
17:24:09after this let's say chunk, this chunk
17:24:11is starting. Okay, so that's why this
17:24:13overlapping is important. And this is
17:24:14the concept of rag. Okay, I already
17:24:16covered in my um YouTube channel. There
17:24:19is a dedicated generative playlist I'm
17:24:21having. You can go through that
17:24:22playlist. There I covered this rank
17:24:25concept in detail. Okay, you can
17:24:26understand these are the concept there.
17:24:28Then after that we are splitting the
17:24:30documents. We are passing the entire
17:24:31documents and you can see we are
17:24:33creating the chunk. Now total I got 44
17:24:37chunks here. Okay, that means I got 44
17:24:39chunks here. Okay. By divide uh by um
17:24:42doing the splitting of my entire
17:24:44content. Okay. And each of the chunk
17:24:47will have 1,000 token because our chunk
17:24:49size was 1,000 token. And this this is
17:24:52completely hyperparameter number. You
17:24:54can also change this number as per your
17:24:56requirement. Now guys, we'll be u
17:24:59defining the embedding model right now.
17:25:00And here if you have openi uh API guys,
17:25:03you can execute this code. uh this code
17:25:06actually loads the openi embedding model
17:25:08and it stores in the files uh vector
17:25:10database but if you don't have openi you
17:25:13can execute this code and this code uses
17:25:15gemini embedding model here we you can
17:25:17see I'm using this gemini importing
17:25:18model and we're storing our vectors okay
17:25:21you are storing our vectors inside my
17:25:23files vector database okay files vector
17:25:25database and for this this is the code
17:25:27files from document and you have to give
17:25:28all of the chunk and your embedding
17:25:30model as well okay now if you execute
17:25:32this code
17:25:34now See here you will be able to see um
17:25:38one uh one database but uh this is only
17:25:43visible if you write this line.
17:25:47Huh? Vector store save local. Okay. And
17:25:50here you have to give the name. Now if I
17:25:52execute
17:25:54again
17:25:58now see it has created the files
17:26:01database here. Okay. In your computer.
17:26:03Okay. Okay, that's why I told you this
17:26:04is a incomputer database. It will store
17:26:06inside your computer storage. Okay, now
17:26:09we'll uh see the vector store. So this
17:26:12is the object of the files vector store.
17:26:14Now we'll just try to create a uh
17:26:16retriever. Okay, retriever means if you
17:26:18want to perform this semantic s
17:26:20operation, you have to create a
17:26:21retriever of the entire database you
17:26:23have created because user will give a
17:26:25question and this question will first of
17:26:27all go to the vector tree. It will uh
17:26:29extract the most relevant chunk and it
17:26:31will combine your query. Then it will
17:26:33prepare a prompt. Okay, for this
17:26:34operation, you have to create this
17:26:35retriever object. How to get the
17:26:36retriever object? You just need to write
17:26:38vector store as ret. Okay, uh then here
17:26:42you have to provide the search type. And
17:26:43here we'll be using similarity search
17:26:45operation. And the search keyword is
17:26:46four. That means it will extract four
17:26:49relevant response at a time. Okay. Let's
17:26:50say if you're asking about what is
17:26:52rainfall measurement, it will go to the
17:26:53vector store and four relevant chunk it
17:26:56will try to extract. Okay. So this is
17:26:58the parameter. If you make it as five,
17:26:59it will extract five chunk. It will if
17:27:01you uh give let's say two it will only
17:27:04extract uh two chunks. Okay, that's how
17:27:05this things works. Now we'll try to
17:27:07create the retr. So once ret is created
17:27:10guys now these things we want to
17:27:13integrate inside of agentic chatbot and
17:27:15agentic chatbot if you're using rag
17:27:17concept you have to uh you have to
17:27:19actually create a tool of your entire
17:27:22rag you have created right but in simple
17:27:24rag we don't create the tool we just
17:27:26directly perform uh the question and
17:27:28answer on my retriever with my large
17:27:30language model okay but here we we have
17:27:32created agentic chatbot and aentic
17:27:34chatbot works with the tool so guys uh
17:27:36as you can see I have uh written this
17:27:38retriever functionality as a tool and
17:27:41this is the function I have created and
17:27:43I made it as a custom tool. So before uh
17:27:46showing you this one first of all I want
17:27:47to show you how retr works. Let's
17:27:49execute retr independently. So I'll copy
17:27:52this one
17:27:54uh retinvoke and here let's pass a
17:27:57query. I'll give uh what is
17:28:01rainfall
17:28:04measurement. Okay. Now see this will uh
17:28:07return you
17:28:09uh this will return you actually four
17:28:13relevant information
17:28:19see four relevant information why
17:28:21because this s keyword you have set it
17:28:23as four this k parameter is four right
17:28:25now that's why four relevant response it
17:28:27is giving you see these are my four
17:28:30relevant chunk I am getting about the
17:28:32rainfall measurement now this will go to
17:28:34the my and this will go to the my uh
17:28:38query uh that means I'll add the query
17:28:39here and we'll prepare a prompt and this
17:28:41will go to the lm now lm has the context
17:28:44as well as the question and lm will able
17:28:46to generate the final response for me
17:28:48okay so that's how this uh uh this
17:28:51system is working okay that's how this
17:28:53ret is working now have to make it as a
17:28:55tool because here we are creating a
17:28:57aentic chatbot and agentic chatbot works
17:28:59with a tool okay now here you can see I
17:29:02have written the same thing just in a
17:29:04function
17:29:04it will take the query. I'm doing the
17:29:06invoke operation. Whatever documents I'm
17:29:08getting, first of all, I'm checking if
17:29:10uh document not found. So no no relevant
17:29:13information was found and if it is found
17:29:15then I'm extracting the u documents. So
17:29:18here you can see some metadata
17:29:19information are available. So from this
17:29:21metadata I'm uh extracting the document
17:29:23sources. Okay, sources means which PDF
17:29:25it is uh referring. You can see here
17:29:28there is a section called source
17:29:32title is there, source is there. You can
17:29:33see source. Okay. So that's how I'm
17:29:35extracting. These are the meta
17:29:36information page and content. So these
17:29:38information I'm extracting and we are
17:29:41joining in this u um like um list and we
17:29:45are returning it. That's it. Okay. So
17:29:47this is the function I have written and
17:29:49we made it as a tool because this is our
17:29:51custom function and if you want to make
17:29:52it as a custom function u as a tool then
17:29:55you have to use this length and tools.
17:29:57Okay. Decorator there. Uh we have
17:29:59already learned it learned this
17:30:00previously right. So this is my tool
17:30:02right now and I named it as a rack tool.
17:30:05Now further step will be same that means
17:30:07we'll be adding the tools inside a list
17:30:10and we'll try to bind that with our
17:30:12large language model. So you can see I'm
17:30:14binding binding my large language model
17:30:16with my tools. Execute. First of all
17:30:19I'll execute this code then execute
17:30:22this. Okay. Now we have to define the
17:30:25state. Now this is our state and see
17:30:27here I haven't added other tools because
17:30:29I want to only show you the rag
17:30:31functionality that's why I'm only using
17:30:32one tool but in my actual code I have
17:30:34also some other tool like calculator web
17:30:36search tool then uh weather tool then
17:30:39stock market tool okay I think remember
17:30:41then this is our nodes so in the node
17:30:43itself I'm using my lm with the tools
17:30:46okay this particular u updated one and
17:30:49here is another node which is tool node
17:30:52now here I am defining my graph
17:30:53structure and we are adding the edges
17:30:55And I think this part you already know
17:30:57how to add the tool nodes and tool
17:30:59conditions there. Now finally this is
17:31:01our graph and this graph we also saw in
17:31:03my previous implementation.
17:31:05Now guys we'll try to invoke our uh
17:31:07chatbot. Now see this is our regular
17:31:09message here. I'm just doing um
17:31:11chatbot.invoke. I'm giving a message
17:31:13hello. And for this it doesn't need any
17:31:15kinds of rack tool. Uh it will generate
17:31:17the answer from the large language model
17:31:19only. Hello. I'm here to uh answer your
17:31:22question about the PDF document. Okay.
17:31:24Now uh here I'm uh passing my uh here
17:31:28I'm passing my prompt as you can see. So
17:31:31here I'll just try to tell um using the
17:31:34PDF u notes explain about the rainfall
17:31:38measurement technique in a conscious
17:31:39way. Okay. Now you'll see that uh it
17:31:42will use the rack tool and it will
17:31:44retrieve the information from the
17:31:45knowledge base and it is giving you the
17:31:47final response. As you can see, the
17:31:48provided documents primarily discuss
17:31:50rainfall prediction techniques using
17:31:51machine learning regression analysis
17:31:53rather than uh detailing specifically uh
17:31:56specific rainfall measurement
17:31:58techniques. Okay. And blah blah blah.
17:32:00Now if I only want to get the text, I'll
17:32:02just extract the text from here. Now see
17:32:04this is now final answer guys I'm
17:32:06getting. Okay. So that's how guys now we
17:32:08can perform any kinds of chat operation
17:32:10on my PDF I have loaded here. Okay. That
17:32:12means this architecture we have
17:32:14implemented in my notebook. Okay. I hope
17:32:17you clear guys. Now we'll try to uh add
17:32:20this functionality okay inside our app.
17:32:22So as you can see this is our app we
17:32:23created so far. Uh this was this was our
17:32:26final app. Uh final app I think last app
17:32:30we created this one app tool. Okay we
17:32:32integrated the tool. Okay. Now what I'm
17:32:34going to do guys I'm going to add this
17:32:37uh rag features with our actual
17:32:39application and we'll try to conclude
17:32:41this particular video. So guys uh we
17:32:43have seen the entire notebook experiment
17:32:45of the rag like how uh how to implement
17:32:48the rag functionality inside our aentic
17:32:50chatbot and main thing we have learned
17:32:52this tool right now we have to create
17:32:54this uh retriever as a tool and uh this
17:32:57tool we'll be using inside our aentic
17:32:59chatbot. So now guys we'll be
17:33:01integrating this features inside our
17:33:03actual agentic chatbot we have created
17:33:05so far. Now this was the last file I
17:33:07created apptools.py. Okay, this was the
17:33:09front end and the back end was uh this
17:33:12one aentic chatbot tools back end. Okay,
17:33:15this was my back end code. Now here what
17:33:18I'm going to do, I'm going to create u
17:33:22create another file. Maybe I can make a
17:33:24copy of this file.
17:33:26Copy.
17:33:29And I'm going to just paste it now. I'll
17:33:32just rename it. Okay, instead of tool
17:33:35back end, I'll give rag back end.
17:33:39Okay, I I'm keeping my old code as well
17:33:41so that you can get a reference. Okay,
17:33:42you can um you will have this code so
17:33:45that in future whenever you are
17:33:46practicing all of the code will remain
17:33:48same. Uh so agentic chatbot rag
17:33:51backend.py.
17:33:53Okay. So this is my updated code.
17:33:55Updated back end I'm going to write
17:33:56here. Okay. And in this code I'll just
17:33:59do the modification. And for front end
17:34:01also uh I'll just create another one
17:34:04this app tool. Right. Instead of app
17:34:07tool, I'll copy
17:34:09and I'll paste it first of all. Then
17:34:12let's rename it. Instead of tool, I'm
17:34:14going to give rag.py.
17:34:22Okay. Now, first of all, let's uh update
17:34:25our back end. So, I'll open my back end.
17:34:29And here update would be
17:34:32first of all we'll uh import all the
17:34:34necessary library
17:34:36whatever we have imported in my
17:34:38notebook. So this is my updated library
17:34:41guys as you can see pipdf loader
17:34:42recursive character splitter google
17:34:44generative uh yeah embedding okay files
17:34:46and all we are importing everything
17:34:48right then after that we'll be
17:34:52uh we'll be just loading our embedding
17:34:54model.
17:34:56So after large language model definition
17:34:58we'll just try to load our embedding
17:35:00model. Okay the embedding model I was
17:35:02using in my notebook. So here I think
17:35:04remember I was using this embedding
17:35:06model.
17:35:08Okay let me close some of the file. This
17:35:11file this file
17:35:13also this file.
17:35:23Now after that we'll just write a
17:35:25function. Uh this function will
17:35:28basically u take a PDF file and it will
17:35:32extract the documents. It will perform
17:35:34the chunking and after chunking it will
17:35:36store all of the chunk in my vector
17:35:38database. Okay that means this step I
17:35:40perform right this step I perform. Okay
17:35:43separately I'll just do inside a
17:35:45function. So let me show you this
17:35:47function I have already written
17:35:52after this embedding model.
17:36:00Just a minute.
17:36:08Uh here I have defined this model two
17:36:10times. Right? Okay. So I have to remove
17:36:20So what I can do I can
17:36:23remove and rewrite again. Okay, now I
17:36:25think it's fine. Now I have imported all
17:36:27the necessary library. This is my model.
17:36:29This is my embedding function. Sorry,
17:36:31this is my embedding model. Now we'll
17:36:33just write this function.
17:36:37So this is the function. I named it in
17:36:39this track document. This will take a
17:36:41file path and we are defining the
17:36:43database path that means it will create
17:36:45a folder called uh files database.
17:36:47Inside that uh all of the vector would
17:36:49be saved. Now we are loading the like
17:36:52file extracting the document performing
17:36:54the chunking operation. You can see
17:36:56chunking operation. After that we're
17:36:58storing everything in the files vector
17:36:59database and then we are saving this
17:37:01database inside our local. Okay. So this
17:37:03is the function we'll be using and this
17:37:05function we have to use from the front
17:37:06end. So whenever I'll upload any file
17:37:08from the front end that time I have to
17:37:10execute this function and this function
17:37:11will create my knowledge base. Okay.
17:37:13This knowledge base should be created.
17:37:16Okay. Now I'll just write another
17:37:17function for the retriever.
17:37:21Okay. So this function what it does
17:37:23basically it loads your uh vector
17:37:26database. Okay. That means the database
17:37:27we are creating knowledge base we are
17:37:28creating. First of all it will load with
17:37:30the help of files.load local we'll be
17:37:31loading this and we'll pass the
17:37:33embedding model. And there is another
17:37:35parameter you have to provide called
17:37:36allow dangerous dialization is equal to
17:37:38true. Then we'll create the ret again.
17:37:40So vector store as retr. We are giving
17:37:42the similarity s and this k parameter
17:37:45like that. Okay. This this part we are
17:37:47doing. Then we are creating the ret
17:37:49object. Now with the help of this retr
17:37:51object I'll be able to perform the
17:37:52inbuck operation. That means I'll be
17:37:54able to do the source operation.
17:37:56Similarity s operation. Okay. Now we'll
17:37:58just write our rag tool. React tool as a
17:38:01function.
17:38:05So this is our act to guys. As you can
17:38:06see we created the same same function.
17:38:09We copy pasted the same function from
17:38:10here. Okay this one. Now this will take
17:38:13the query. We are doing the first of all
17:38:15we're getting the ret. We're calling
17:38:16this function. Get retr. This will give
17:38:19me my ret object. I will do the invoke
17:38:21operation. Whatever document I will get
17:38:22I'll extract all of the content from
17:38:24here. Okay. Then I will return it.
17:38:26That's it.
17:38:32It's coming.
17:38:36Now after that we'll be defining all of
17:38:39our tools as it is. Okay, this will
17:38:41remain same. You don't need to change
17:38:42anything. Our search tool, our
17:38:44calculator tool, then our get stock
17:38:48price tool, then our get current uh
17:38:51current weather information tool.
17:38:53Everything will remain same. Only the
17:38:55change I have to do here.
17:39:00Okay. Here I have to add another tool
17:39:02which is my rag tool
17:39:08rag tool the function I have created
17:39:12okay this one this function I have to
17:39:15pass as a tool
17:39:18then we are doing the bind operations
17:39:20then we are defining the state and one
17:39:23more change we'll be doing inside our
17:39:25chat node uh now this is a simple chat
17:39:27node we created previously it doesn't
17:39:29have any kind of system prompt. Now
17:39:31we'll add a system prompt here. Let me
17:39:33show you my updated notes I have
17:39:35created.
17:39:38So this is my updated notes guys. Okay.
17:39:41So here I added a detail system prompt
17:39:43as you can see. Uh this is my system
17:39:45message. Um has you are a helpful
17:39:47agentic chatbot with access to several
17:39:49tools. Use tools uh you uh tool uses
17:39:52instruction. Use rack tool for a
17:39:54question about uploaded PDF or
17:39:56documents. Always retrieve relevant
17:39:58documents content before answering the
17:39:59PDF related questions. Use search tool
17:40:02for current events, recent information
17:40:04or or informations
17:40:07that requires the internet search. Use
17:40:09calculator uh tools for mathematical
17:40:11calculation. Do not calculate complex
17:40:13expression manually when calculator is
17:40:15available. Then get stock use whenever
17:40:18user asking about any kind of a stock
17:40:20price and get weather whenever user is
17:40:22asking about latest weather informations
17:40:24and answer general questions directly.
17:40:26uh when no tools is required do not
17:40:28invent informations from the uploaded
17:40:30documents. If the user ask about the PDF
17:40:33but no documents is available ask them
17:40:35to upload the PDF. Okay. After receiving
17:40:37a tool result provide a clear and
17:40:39helpful final answer. So that's how guys
17:40:41we defined a clear system message to our
17:40:44chatbot right now. Okay. So every aentic
17:40:47chatbot you will see it has a message.
17:40:49Okay. Okay, it has a prompt system uh
17:40:50system we call it as a system prompt and
17:40:52with the system prompt basically it uh
17:40:54performs all the operation that means
17:40:56whenever you are asking anything uh
17:40:58inside a chatbot okay it uh it works
17:41:01like a step by step how it works because
17:41:03it has a proper system prompt and this
17:41:05thing you have to provide okay so far we
17:41:07haven't given but now we have given a
17:41:09detailed system prompt because now we
17:41:11have made it more advanced now I want my
17:41:13chatbot to be work like a professional
17:41:15way okay that's why we have we have
17:41:17added this entire system prompt Now in
17:41:20the message you will give the system
17:41:21prompt as well as the state message user
17:41:23is giving then we are invoking it and
17:41:26whatever response we are getting just
17:41:27returning it. Okay. So this is a simple
17:41:29modification you have to do inside your
17:41:30chat node and all of the node will
17:41:32remain same your tool node then we are
17:41:34defining my checkpointter SQLite
17:41:36database. Then this is our graph. Okay.
17:41:39All the graph definition everything will
17:41:40remain same. No need to change anything.
17:41:42As well as my helper function for
17:41:44streaml front end this will also remain
17:41:45same. Okay. So this is the change guys
17:41:47you have to do in the back end file.
17:41:49Okay. So this is the change you have to
17:41:51do in the back end file. Let me check
17:41:52whether anything is required or not. I
17:41:55think everything is fine. Okay fine. Now
17:41:58I have to change my front end. Now what
17:42:00I will do? I'll just try to open my
17:42:01front end app rag.py. Now see what I
17:42:05have done guys. I just copied my
17:42:07existing front-end code to chat GPT and
17:42:10I asked I need a document uploader
17:42:13function features on my uh chatbot. So
17:42:17try to create uh streaml uh user
17:42:19interface for that. Okay. So then I got
17:42:22this code. Let me show you.
17:42:25This is the updated code I got.
17:42:31This is the updated code I got. So
17:42:33basically this has the document upload
17:42:36features. Okay. So if you don't know
17:42:37about front end design and all don't
17:42:39need to worry. So this is the work of a
17:42:40front- end developer. So I also took the
17:42:43help from charg uh created this front
17:42:46end. But only the change you have to do
17:42:48here. Okay. First of all you have to
17:42:50change this uh import operation that
17:42:53means right now we are importing from
17:42:54agentic chatbot rag back end. So from
17:42:57aentic
17:42:58chatbot rag back end. Okay, we are
17:43:01importing chatbot. Then get all threads.
17:43:06Uh
17:43:08get all threads. Okay, this one and uh
17:43:11we are also importing ingest rack
17:43:13documents. Okay, that means this
17:43:15function this function I need whenever I
17:43:16will upload any kinds of documents on my
17:43:18streaml. So this function will be
17:43:20executed and my vector store would be
17:43:22ready. Okay, that time then everything
17:43:24will remain same only the change here it
17:43:27has done. Let me show you.
17:43:29See this is the new code it has added.
17:43:31If you if you compare with your previous
17:43:34code so this part has changed. Okay. So
17:43:36here in the uploaded um section that
17:43:39mean in in the user input section it has
17:43:41added another one called uploaded file.
17:43:42So basically here it is taking a PDF
17:43:44file upload and uh we are taking this
17:43:47PDF file we saving as a temporary file.
17:43:50Then we are calling this in just drag
17:43:51documents. We are passing inside this
17:43:53function. Okay. And this function is
17:43:54creating my knowledge base. this
17:43:56knowledge base will be created. That
17:43:57means this uh uh vector store would be
17:44:00created. Once my vector store is
17:44:02created, now you'll be able to perform
17:44:04the chart operation. Again, we are uh
17:44:06taking the user input and doing the
17:44:08chart operation. Okay, that means all
17:44:09the code are common. Only that pass uh
17:44:11that part is changed. Okay, that means
17:44:13upload document part is changed. Now,
17:44:15let me show you my updated uh front end
17:44:17how it look like. So streamllet
17:44:22run
17:44:24app
17:44:26rag.py.
17:44:37So as you can see this is my updated
17:44:39front end. Now we can perform the chat
17:44:42operation. Now let's perform the simple
17:44:44chat initially. So let's say I'll give
17:44:47hello
17:44:50I am BP and this is happen happening in
17:44:53a like new trades. Okay, completely new
17:44:56trades
17:44:59and internally it is also tracing our
17:45:02application. Okay, it is also tracing
17:45:04our application with the help of
17:45:05linesmith.
17:45:07Now I'll give uh tell me about
17:45:12let's say
17:45:15Python. So this is a simple chart.
17:45:20So it is telling you about Python. Okay.
17:45:23Now here I will ask uh what is
17:45:35what is the answer of
17:45:41this equation. Let's say I'll give a
17:45:42mathematical equation.
17:45:54I'll see it will use my calculator tool.
17:45:56See calculator tool it is using and this
17:45:58is the final result I'm getting. Okay.
17:46:00Now I'll ask uh what is the
17:46:06current
17:46:09weather
17:46:13in let's say
17:46:17Dhaka.
17:46:22Now it will use my get current weather
17:46:24tool and this is the current weather in
17:46:26Dhaka right now. Okay. And now I will
17:46:28ask about the latest information. Tell
17:46:30me the
17:46:33latest
17:46:35news.
17:46:40Okay. Latest news
17:46:44of FIFA. FIFA World Cup
17:46:522026.
17:47:01Now see it is using tab search tool
17:47:05and here is the
17:47:08answer I got. Okay about the FIFA World
17:47:10Cup. Okay. Now I will ask uh I will
17:47:13upload a documents. Let's say I'll
17:47:15upload documents
17:47:17the same documents. Let's say I'll
17:47:18upload my paper.
17:47:26My paper got uploaded. Now I'll tell
17:47:29uh tell me about
17:47:33rainfall
17:47:35measurement
17:47:38uh based on
17:47:41the PDF
17:47:44loaded.
17:47:48Now see it is using rack tool and it is
17:47:51giving you the entire response about the
17:47:54rainfall measurement. Okay, this
17:47:55amazing. Now I'll tell her tell me
17:47:59about
17:48:03the
17:48:05abstract
17:48:07paper.
17:48:21Now see again it is using rag tool and
17:48:23this is giving you the inter
17:48:24abstruction. Okay. Now I'll ask uh who
17:48:28is Bier Ahmed Bi
17:48:34mentioned
17:48:37in the paper.
17:48:42Now again it is using react tool and now
17:48:45it is telling Bkt Ahmed Bi is one of the
17:48:48six author of the paper development of
17:48:50multiple combined regression method for
17:48:51reinforce measurement. And uh here is
17:48:54the address and email address. Okay.
17:48:56Amazing, right? So that's how guys our
17:48:58agentic chatbot right now it's working
17:49:00and it has it has lots of advanced
17:49:03feature right now and the current one we
17:49:05have added this rag functionality. Now
17:49:07you can upload any kinds of document and
17:49:09you can perform the conversation on top
17:49:11of that. Okay. Like chat GPT like chat
17:49:13GPT also you can upload any kinds of
17:49:16documents. Okay. And you can start doing
17:49:18the conversation here. Okay. This is
17:49:20also possible. And one more thing I want
17:49:23to show you. So if I go to my langispit
17:49:25right now. So if I go to my trades.
17:49:29So I'll go to this trades
17:49:32and here all the conversation I have
17:49:34done. So the last conversation I did uh
17:49:37this one. Now if I go to the two
17:49:40condition
17:49:44okay I'm happy. I think last
17:49:45conversation was that. Okay. This one.
17:49:48Yeah. Now you can see here uh whenever I
17:49:50did the conversation first of all it it
17:49:52went to the chat node then large
17:49:54language model then um it was redirected
17:49:57to the tool condition tool condition was
17:49:58selected the tool now it selected the
17:50:01rack tool okay and inside rack tool we
17:50:03are using this vector search ret
17:50:05operation okay and with the help of that
17:50:06it is doing the vector search and it
17:50:09found actually four relevant response
17:50:10you can see okay from my knowledge base
17:50:12and this four relevant response went to
17:50:14my chat nodes again that means my llm
17:50:17with the prompt
17:50:18and then uh it was generating the final
17:50:21response. Okay. So that's how this
17:50:22entire system is working and in the
17:50:24Langmith platform itself you can monitor
17:50:26the entire system. Okay. This is the
Implement Human-in-the-Loop (HITL) in Agentic Chatbot using LangGraph
17:50:28best part of this uh of this actually
17:50:30application is. So yes guys uh this is
17:50:33the um like uh chatbot we have created
17:50:37so far. This is our agentic chatbot we
17:50:38have created so far and everything is
17:50:41working fine and all the codes I will be
17:50:42sharing in my description section. from
17:50:44there you can check it out and uh let me
17:50:46know how this uh learning is okay
17:50:49whether you are able to learn uh the
17:50:51agent TKI concept from my playlist or
17:50:52not. So if you found my content useful
17:50:55guys please try to subscribe to my
17:50:56channel and share this with your friends
17:50:58and family okay your support is
17:50:59required. So if you're supporting me
17:51:01guys, I'll get lots of motivation to
17:51:03bring this kinds of content. Okay. In
17:51:05this video, we'll be learning one very
17:51:07interesting concept called human in the
17:51:09loop HIT L inside our agentic chatbot
17:51:13with the help of Langraph. If you are
17:51:15following my entire playlist guys from
17:51:17the beginning, I think you remember uh
17:51:20in my introduction uh video, I already
17:51:22talked about this HITL that means human
17:51:24in the loop concept. uh that means uh
17:51:27this is the uh component of an AI agent.
17:51:30Whenever you are implementing any kinds
17:51:33of AI agents uh whenever you need any
17:51:36sensitive task, you need this HITL
17:51:38concept that means human in the loop
17:51:40concept. Okay. Uh so in this video guys,
17:51:42we'll try to uh learn this entire HITL
17:51:46concept. We'll also see the practical
17:51:48and we'll also try to integrate this
17:51:51functionality inside our agentic
17:51:52chatbot. So before I start this uh
17:51:56implementation guys, first of all I want
17:51:57to show you the demo how this uh hit uh
17:52:01looks like and uh after adding this
17:52:04inside our agentic chatbot how uh it is
17:52:07going to work. Okay, we'll try to see
17:52:09the demo after seeing the demo we'll try
17:52:11to understand this concept in a
17:52:12theoretical manner then we'll see the
17:52:15practical implementation as well. So
17:52:17guys this is our agentic chatbot that's
17:52:19how this chatbot looks like. So right
17:52:21now you can upload any kinds of document
17:52:23and you can start a conversation okay on
17:52:25top of your documents this is possible.
17:52:27So let's try to test our chatbot and I
17:52:30already integrated this hit with this
17:52:33agentic chatbot. I'm first of all going
17:52:35to um show you the demo then after that
17:52:37we'll try to see the practical
17:52:38development. So here uh you can perform
17:52:41the simple chat operation. Let's say if
17:52:43I give hello so your chatbot will return
17:52:45something. See hello can help you today.
17:52:48Now we'll ask uh what is the
17:52:54what is the
17:52:56current weather
17:52:59in Dhaka
17:53:03you will see that it will be using uh
17:53:05different different tools okay that
17:53:07means it will use uh weather tools and
17:53:09it will give me current weather
17:53:10informations okay uh given any kinds of
17:53:12location even you can upload any kinds
17:53:15of documents let's say I will upload one
17:53:17of my documents ments. Let's I will
17:53:19upload these documents.
17:53:21Okay.
17:53:28Okay. Now this is uh one of my resume I
17:53:31have uploaded. Now I'll ask some
17:53:32question on top of this uh PDF. So tell
17:53:35me about Boktier
17:53:40Ahmed
17:53:45By
17:53:47based on
17:53:51the PDF.
17:53:54Okay. Upload it.
17:54:02Now we'll see that it will be using rag
17:54:03tool and it is giving you the entire uh
17:54:07entire actually introduction of bkirhmed
17:54:09bpi is a data scientist over 5 years of
17:54:12uh working experience in the field of
17:54:14generative loops autonomous AI system
17:54:17okay and blah blah blah you can see the
17:54:19entire summary uh of me okay so that's
17:54:22how guys uh you can perform any kinds of
17:54:24conversation uh on any kinds of
17:54:26documents okay now here let me show you
17:54:29this uh hit functionality I have added
17:54:31added in this agentic chatbot. So
17:54:33basically here I have added this hit for
17:54:37one sensitive task. Okay, sensitive task
17:54:39means I think you know that uh with the
17:54:41help of this agentic chatbot I can see
17:54:43any kinds of stock price, right? So
17:54:45let's say if I asking uh let's say what
17:54:48is the
17:54:51stock
17:54:53price
17:54:55of
17:54:57Apple? Okay. So I think you know that it
17:55:00has a tool uh that tool actually real
17:55:02time f the stock prices. Okay. Given any
17:55:05kinds of company. So if I let's say send
17:55:07this prompt you'll see that it will use
17:55:09that tool using get stock price tool.
17:55:11Okay. And this is the current uh stock
17:55:13price we are getting of the Apple. Now I
17:55:16want to perform a sensitive task with
17:55:19this uh aentic chatbot. Basically I want
17:55:21to purchase a stock of Apple. Okay. I
17:55:24want to let's say purchase 10 stock of
17:55:25Apple. Now this task required actually
17:55:28human observation that means human
17:55:30approval. It's not like that you want um
17:55:33you are giving your agents uh the 100%
17:55:36authority to perform all of the task.
17:55:38It's not like that because there are
17:55:39some sensitive things you have to
17:55:41monitor okay manually and this is this
17:55:44needs actually human approval. So here
17:55:45let's see if I am asking to my agents uh
17:55:49purchase
17:55:53okay purchase let's say 10 stock
17:56:00of apple
17:56:05okay let's say I'm asking this question
17:56:07and this is a sensitive task and for
17:56:09this you will see that it will ask for
17:56:11human approval okay now if I send this
17:56:13prompt
17:56:16Now see it is asking for the human
17:56:18approval. Human approval required.
17:56:20Approve buying 10 shares of Apple. Yes
17:56:23or no? Do you want to give me the
17:56:25permission? Um if you want I can buy. So
17:56:28for this you have to provide yes
17:56:30otherwise you can reject this particular
17:56:32uh approval. Okay. So let's see if I am
17:56:35giving yes. I will approach this approve
17:56:36this purchase. Now you'll see that it
17:56:39will use my purchase stock tool and it
17:56:40will purchase the shares of the Apple.
17:56:43Okay. Now if I'm again asking this thing
17:56:46let's say
17:56:49um purchase 10 stock of
17:56:54Google.
17:56:59Now see again it is asking for human
17:57:01approval. Now right now let's say if I'm
17:57:02rejecting the purchase you'll see that
17:57:05it will not purchase that. Okay your
17:57:07request to purchase 10 shares of Google
17:57:09was declined. Okay. So this is called
17:57:11actually HITL that means human in the
17:57:14loop. Uh basically if you have already
17:57:16used any kinds of agentic system guys.
17:57:19Okay. Uh you will see that this kinds of
17:57:21functionality they are having they will
17:57:22ask for human approval. Uh if you are
17:57:25already using any kinds of code editor
17:57:27also like uh um this uh anti-gravity or
17:57:30cursor AI. Okay. There also you will see
17:57:32that whenever you want to generate
17:57:33something generate some code or if you
17:57:36want to create any project you will it
17:57:37will ask for the human permission. Okay.
17:57:39If it required that time you if you are
17:57:41giving the permission okay that time
17:57:44actually it will perform all of the task
17:57:45otherwise it will decline that okay so
17:57:48this functionality guys we have
17:57:49integrated inside our agentic chatbot
17:57:51and now this chatbot is super advanced
17:57:53okay now it can do all of the task and
17:57:56uh uh you can actually integrate this
17:58:00not only in this stock price purchase uh
17:58:04but also you can integrate uh these
17:58:06things in any kinds of let's say task
17:58:08you are performing. I'll show you okay
17:58:10how to do that. And uh you can uh feel
17:58:13free to add uh so many tools here. Okay.
17:58:15Uh so many autonomous tool you can add
17:58:17here. Let's say you want to send
17:58:18automatically email you can add the
17:58:20emailing tool. If you want to uh check
17:58:22uh your Google drive, okay, how many
17:58:24files are present and if you want to
17:58:26upload any file so you can also add
17:58:28these kinds of tools. Okay, I already
17:58:29talked about the tools and this video is
17:58:31already available over my channel. You
17:58:33can see that. Okay, how to add different
17:58:34different tools. So yes guys uh this is
17:58:36the demo of this u u hitl human in the
17:58:39loop. Now we'll try to see this human in
17:58:42the loop u uh what is this human in the
17:58:45loop? Okay why it is required in a
17:58:46theoretical manner then I'm going to
17:58:48show you the practical implementation of
17:58:50that. So guys if you are completely new
17:58:52to my channel and if you haven't
17:58:53subscribed yet please try to subscribe
17:58:55to my channel. Uh if you found my
17:58:57content useful uh please support me if
17:58:59uh if I get your support. So definitely
17:59:02I will get lots of motivation and I will
17:59:04bring this kinds of content more. So
17:59:06please try to subscribe to my channel
17:59:08and hit the like and please try to share
17:59:09this with your friends and family as
17:59:11well. So guys first of all let's try to
17:59:13understand what is this HITL is. As you
17:59:16can see from from the definition itself,
17:59:18HITL that means human in the loop is a
17:59:21design approach in agentic systems where
17:59:23a human actively participates at
17:59:26critical points of the AI workflow uh
17:59:29either to supervise, approve, correct or
17:59:32guide the model's output. Okay. So this
17:59:35is the concept actually it's required
17:59:38whenever you are performing any kinds of
17:59:40uh sensitive task. Whenever you are
17:59:42performing any kinds of let's say very
17:59:44critical task that time this HITL is
17:59:47required and if you are creating this
17:59:49kinds of agentic system I think you know
17:59:51that where you need to exactly add this
17:59:53HITL feature because inside agentic
17:59:57project actually there would be multiple
17:59:58kinds of task let's say uh here uh
18:00:01inside our chatbot we have added
18:00:02different different task let's say our
18:00:04chatbot can perform internet source
18:00:05operation it can give you the weather
18:00:08information okay so for these kinds of
18:00:10task actually I don't need this hit
18:00:12features. Okay. But let's say I showed
18:00:14you one demo. I need to purchase a stock
18:00:17price. This is a critical and sensitive
18:00:20task. Okay. And definitely needs human
18:00:22approval. Otherwise, if I give the full
18:00:24authority to my AI agents, uh it it may
18:00:27actually uh do something wrong. Okay.
18:00:29Let's say uh I will tell uh please
18:00:32purchase 10 shares of Apple. Okay. So,
18:00:35what it can do? It can let's say
18:00:37purchase 20 shares of Apple. Okay. uh it
18:00:40can let's say spend more money okay of
18:00:43me so that's why this human uh uh in the
18:00:46loop is required in this kinds of
18:00:48critical task that's how inside an
18:00:50agentic AI project there would be
18:00:52multiple uh like scenario uh you might
18:00:55need to add this HITL okay it's not
18:00:57necessary to add this HL to all of your
18:01:00features all of your task okay wherever
18:01:03you feel like okay this is required for
18:01:05me you can add add it there okay so
18:01:07that's why you can see this HL L it's a
18:01:10design approach in AI agentic AI system.
18:01:12Okay, where a human actively part
18:01:14participates at a critical point of the
18:01:16AI workflow. Okay, that means this is
18:01:19your completely uh your design uh
18:01:21philosophy here. Okay, you will be
18:01:23designing this kinds of HITL uh
18:01:25functionality inside your project. Now
18:01:28you can see think of a HLTL uh as
18:01:31putting a human checkpoints inside an AI
18:01:33pipeline uh so that important decisions
18:01:36are not made automate autonomously by
18:01:38the model. Okay, that is what I told
18:01:40you. So whenever you need this kinds of
18:01:42uh critical task handling uh you are not
18:01:45going to give the full authority to your
18:01:47uh agent. So that time it will not
18:01:49automatically take the decision okay uh
18:01:52by your agent that time you will be
18:01:54available okay in this particular loop
18:01:56and if you approve that particular task
18:01:58uh this will perform otherwise this will
18:02:00not perform okay this is what actually
18:02:02this definition says now you can see why
18:02:06exist uh as I already told you to help
18:02:08agentic system that means whenever you
18:02:10are creating any kind of agentic system
18:02:12so to help the agentic system you need
18:02:14this kinds of hitl for an example let's
18:02:17say you want to imple element an agent
18:02:18uh that will uh prepare a post okay that
18:02:22will prepare a LinkedIn post and uh it
18:02:24will uh post over the LinkedIn platform
18:02:27okay so here to create the LinkedIn post
18:02:30it doesn't need any kinds of human
18:02:32approval but whenever it will post that
18:02:35uh let's say on the LinkedIn platform
18:02:37that time this human approval is
18:02:38required because human will review the
18:02:41entire post if the post is fine then
18:02:44they will approve this post and this
18:02:46post would be published list over the
18:02:47Ling platform. Okay. So here basically
18:02:50this HITL helping the agentic system.
18:02:53Okay. Uh to perform the complete task.
18:02:56Okay. Uh I think you can understand what
18:02:59I'm trying to say. Then the second to
18:03:01add the accountability. Accountability
18:03:04means let's say I already told you
18:03:06agentic system can make mistake. So
18:03:08let's say if you are telling I need to
18:03:10purchase 20 stock of Apple. Okay. So
18:03:13there is a possibility your agent will
18:03:16uh your agent will uh will try to
18:03:18purchase let's say four 40 stock of
18:03:21Apple. Okay. So there is a problem
18:03:23right? So before purchasing that stock
18:03:26first of all you will try to review that
18:03:28whether uh the amount you want to
18:03:31purchase it is fine or not. The price uh
18:03:33Apple is having for the stock it is fine
18:03:35or not. If everything goes fine then you
18:03:37will try to give the approval otherwise
18:03:39you will try to reject. Okay. So that's
18:03:41why this uh HITL is exist. Uh it will
18:03:44help you to help the agentic system and
18:03:47uh to add the accountability as well.
18:03:49Okay. Now you can see HITL ensures
18:03:53accuracy definitely uh if you are
18:03:55implementing this HITL inside your
18:03:57agents uh there would be uh higher
18:04:00accuracy inside your agentic system. Um
18:04:02otherwise uh there are some problem. I
18:04:04think I have already explained that okay
18:04:06what would be the problem. uh so if you
18:04:08are adding this one so definitely
18:04:09accuracy will increase inside your
18:04:11agentic system that's why in charge GPT
18:04:13Google gemini whatever agentic system
18:04:15you are using all of the applications
18:04:17are having this kinds of hit
18:04:19functionality okay in charge also maybe
18:04:21you have observed uh it will tell you
18:04:23okay uh do I need to perform the uh
18:04:25perform this task or not okay if you
18:04:27give yes then it will perform otherwise
18:04:29it will not perform okay then safety
18:04:31definitely safety is required uh as I
18:04:34already given you one example that stock
18:04:36price uh purchase this demo. So there
18:04:38let's say if I'm not giving this kinds
18:04:39of hits features that that times that is
18:04:42a possibility our agents will purchase
18:04:45more stock which I which I don't need.
18:04:47Okay. So definitely this is one kinds of
18:04:49safety. Then the next thing uh is
18:04:52ethical alignment. Let's say um if you
18:04:55are doing a task that have some kinds of
18:04:58ethical alignment. Let's say we are
18:05:00preparing a post for the LinkedIn and
18:05:02that post should not have any kinds of
18:05:05let's say sexual content or let's say
18:05:08abusive content. Uh so uh that time
18:05:11actually you can have this kinds of
18:05:12ethics. Um you can uh basically review
18:05:15that and uh if you approve that kinds of
18:05:17content
18:05:19uh then your agent uh agent will
18:05:21basically uh post that otherwise it will
18:05:24not post that. That means if your
18:05:25content is having this kinds of uh uh
18:05:27these kinds of uh sexual and abusive
18:05:29content you will reject and uh if if it
18:05:32doesn't have that that time you will try
18:05:34to approve that. Okay. So these kinds of
18:05:35ethical alignment um also ensures this
18:05:38HITL then better user experience as I
18:05:41already told you um if you are adding
18:05:43these kinds of things so definitely
18:05:45there would be better user experience uh
18:05:47as you already observed inside our app
18:05:49right so it was giving some kinds of uh
18:05:52approved uh let's say input and if
18:05:54you're approving that the task was
18:05:56happening if you are not approving the
18:05:57task was not happening so this is kinds
18:05:59of better user experience okay you are
18:06:01providing with the help of this HITL
18:06:03then some common HITL patterns as you
18:06:06can see action approval patterns approve
18:06:08reject before execution uh as I already
18:06:10told uh showed you one demo right so
18:06:12basically whenever you want to perform
18:06:14any task and uh if it needs any kinds of
18:06:16action so here you you can perform with
18:06:19the help of this HITL you can approve or
18:06:21reject uh before the execution then
18:06:23output review and edit pattern so maybe
18:06:25you have seen um any kinds of uh uh
18:06:29block generation let's say agent so what
18:06:31it does basically it generates some
18:06:32kinds of output then it It's for the
18:06:34human review. Okay. Uh human review and
18:06:37edit. So if they review and edit and
18:06:39approve this kinds of output then it
18:06:41will finalize that otherwise it will not
18:06:43finalize that. Then ambiguity
18:06:45clarification pattern. So sometimes your
18:06:47agent is asking let's say uh your your
18:06:51agent is getting confused right. Let's
18:06:52say you are asking your agent schedule a
18:06:54meeting on Friday. So let's say in this
18:06:56week also you have the Friday and next
18:06:58week also you have the Friday. So that
18:07:00time your agent needs a clarification.
18:07:02Now which Friday it needs to schedule
18:07:04the meeting. So again it will ask you uh
18:07:06actually I'm a little bit confused which
18:07:08Friday you are u like talking about this
18:07:11Friday or the next Friday. So this is
18:07:13called ambiguity clarification pattern.
18:07:14Then escalation pattern let's say
18:07:16sometimes what happens in some kinds of
18:07:18chatbot. So it uh talks with the
18:07:20customer and when it feels like okay it
18:07:22cannot handle this kinds of scenario it
18:07:25will redirect to the actual actually um
18:07:29actual owner of that uh company and they
18:07:32will basically handle this kinds of
18:07:33scenario. Okay, this is called
18:07:34escalation pattern and that can be also
18:07:36implemented with the help of this HITL.
18:07:38Okay, so yes uh this is the entire idea
18:07:41of this uh HITL. I think you have
18:07:43understood. Now uh we'll try to see how
18:07:46this HITL works. Okay. Uh in a practical
18:07:49uh way. First of all, I will uh I will
18:07:51show you this uh diagram wise how this
18:07:54hit will work. So for this here I have
18:07:56taken an example. So here I have taken a
18:07:59basic workflow guys. As you can see this
18:08:01workflow you can consider this is a post
18:08:04generation workflow. Let's say uh you
18:08:07can generate any kinds of LinkedIn post.
18:08:09So you can see uh it has the start node.
18:08:12First of all, user will pass a topic and
18:08:14if submits the topic, it will go to the
18:08:16um your langraph workflow. Okay. And it
18:08:19will execute the start node. Then it
18:08:21will uh perform the resource operation
18:08:23of that particular topic. And once it
18:08:25found the content, it will prepare the
18:08:27content. And here it will uh post that
18:08:30particular content over the LinkedIn.
18:08:31But here we'll try to add this hit
18:08:33feature. Okay? Because before posting
18:08:35that definitely it needs the human
18:08:37approval. It will ask me whether I have
18:08:40to post or not. Okay? So if I review
18:08:42that, if I approve that then it will
18:08:44post otherwise it will not post then
18:08:45this workflow is getting ended. So let's
18:08:47try to understand this agit um with this
18:08:50particular example. So see what is
18:08:52happening. Let's say you are passing a
18:08:53topic name here. Let's see what topic uh
18:08:55you are passing a topic name of machine
18:08:58learning. Let's say ML. Let me take this
18:09:00color. Let's giving ML topic. Okay. So
18:09:04this ML topic you are submitting here
18:09:06and it will go to your langraph
18:09:09workflow. So this is the lang graph
18:09:11workflow we have created let's say. So
18:09:13first of all here it will prepare a
18:09:15state. I think you know that we have to
18:09:16prepare a state right. And here what
18:09:18would be the state? State would be the
18:09:19topic and as well as the draft that
18:09:22means draft post it is generating.
18:09:25Okay. So it will uh first of all uh
18:09:28invoke this uh uh workflow and it will
18:09:31go to the research node and research
18:09:33node will perform the research
18:09:34operation. It will try to find ML
18:09:36related uh latest uh let's say
18:09:39information and it will prepare a post.
18:09:41Okay. Once post is prepared then here
18:09:43we'll try to add this HITL feature.
18:09:45Okay. Hi TL feature. Human in the loop
18:09:47features. Okay. Now how human in the
18:09:49loop feature works. Let me give you as a
18:09:51highle uh like uh high level idea. Uh
18:09:55definitely we'll try to see in practical
18:09:56manner how to write in the code. But I
18:09:58will give you this one highle code
18:09:59diagram how it will work. Okay. So see
18:10:02whenever you are implementing this HITL
18:10:05inside any kinds of node right uh that
18:10:08time you will be using one function
18:10:11called interrupt okay this is already
18:10:12available inside langraph uh inside
18:10:14langraph actually this hit
18:10:16implementation is super easy so there is
18:10:18a function called inter in uh interrupt
18:10:20okay interrupt
18:10:23interrupt function okay so once you will
18:10:25use this interrupt function this
18:10:27execution will pause here okay this
18:10:29execution will pause here unless and
18:10:31until you are not giving any kinds of
18:10:32input. So let's say here I I'll take a
18:10:35variable called decision.
18:10:37Decision
18:10:43decision is equal to okay interrupt. Now
18:10:47here user will pass something. Let's say
18:10:49if user pass this decision
18:10:53decision is equal is equal to yes that
18:10:56time post will happen. Okay. Else
18:11:00it will reject.
18:11:02Okay. So this is the highle code diagram
18:11:04you can understand. That's how actually
18:11:06lang graph will work. Okay. So here
18:11:08we'll try to use uh one function called
18:11:10interrupt and this function will
18:11:11basically pause the execution unless and
18:11:14until human not human is not giving any
18:11:16kinds of input. Okay. Now you can define
18:11:19your input like what kinds of input you
18:11:21need from the user. This kinds of
18:11:22functionality also you can add here.
18:11:24Okay. Then after getting the input you
18:11:27can uh execute your workflow. And one
18:11:30more thing which is very important
18:11:32whenever you are implementing this HITL
18:11:35you have to add the checkpointer. Okay,
18:11:37you have to add the persistence memory.
18:11:40Uh we we have already seen the
18:11:41persistence memory. Okay. Uh persistent
18:11:43memory basically saves all of your state
18:11:45right inside a memory whether you can
18:11:47use any uh inmemory saver that means in
18:11:50in your RAM or any kinds of permanent
18:11:52database you have to use that because
18:11:54whenever it will perform the pause
18:11:56operation right uh let's say here it is
18:11:58performing the pause operation so to
18:12:00execute it again let's say whenever user
18:12:02is giving the input okay after getting
18:12:04the input this will execute right so
18:12:07whenever it will execute it's not like
18:12:08that it will execute from the beginning
18:12:10it will execute while it has passed that
18:12:12particular execution and how it will
18:12:14understand by seeing the state because
18:12:16state is saving all of the information
18:12:18and where it is getting loaded it is
18:12:20getting loaded in the database okay in
18:12:22the persistent memory and from the
18:12:24persistent memory it will load that and
18:12:25it will see that okay I stopped in the
18:12:27post uh nodes and now I have to continue
18:12:30from the post node instead of continuing
18:12:32from the beginning okay that's why the
18:12:33checkpointer you have to define the
18:12:36state uh persistence memory you have to
18:12:38define whenever you are implementing
18:12:39this hit concept inside langraph
18:12:43Okay, line graph it is super important.
18:12:46Okay, I hope you clear guys. So that's
18:12:48how this uh HITL will hit will work um
18:12:52in practical and uh you can implement
18:12:55this HITL in any kinds of node. Okay,
18:12:58any kinds of node or any kinds of tool
18:12:59you are using you can define that. We'll
18:13:02try to see that. And one more thing
18:13:03whenever you are uh giving this input
18:13:06right uh let's say this interrupt is
18:13:08waiting for the human input and whatever
18:13:11input you are passing let's say here you
18:13:13are passing this yes input okay so this
18:13:15yes input will consider as a command
18:13:17okay it will consider as a command uh so
18:13:20this command actually will u uh go to
18:13:22the again your uh let's say node that
18:13:26means your chat node and uh if uh your
18:13:29chat node is getting this yes command
18:13:31that time it actually it will uh it will
18:13:33uh feel like okay now user wants to post
18:13:36that okay then your posting will be
18:13:38happening okay so that uh that means
18:13:40this command is required a command
18:13:43keyword is required whenever you are
18:13:45using this interrupt function and
18:13:47whatever let's say user input you are
18:13:49getting uh you have to store in the
18:13:51command okay now this thing I will also
18:13:53show you in the code uh I think by
18:13:55seeing the code I think this concept
18:13:57would be more clear in your mind right
18:13:59but before uh the code uh implementation
18:14:01I have given you high table overview so
18:14:03that whenever I will explain the code
18:14:05you won't be having any kinds of
18:14:06confusion. Now guys, we'll try to
18:14:08implement this hitl with the help of
18:14:11lang graph. Uh for this actually first
18:14:13of all we'll try to see a simple
18:14:15example. Uh I think you remember uh the
18:14:18aentic chatbot uh we are creating so
18:14:20far. Uh from the very beginning I have
18:14:23taken this simple workflow. Okay. So
18:14:26this workflow has one node which is chat
18:14:28node. So if you basically give a input
18:14:30uh it will generate the output of that
18:14:32uh given input and you will be able to
18:14:34see the output of that. Okay. So here uh
18:14:36what I'm going to do guys I'm going to
18:14:38add a simple
18:14:40uh simple actually example of this HITL.
18:14:43So basically here whatever input is
18:14:45coming right in this particular node. So
18:14:48here we'll just try to add a HITL
18:14:50feature. Okay HITL feature. So here
18:14:52we'll try to first of all uh ask the
18:14:55user do you want to really ask the
18:14:57question okay uh do you want to really
18:14:59ask the questions to the model if user
18:15:01sends yes okay I want to perform then
18:15:04the answer would be generated otherwise
18:15:06answer won't be generated okay it it
18:15:08looks like very funny but just to make
18:15:10you understand actually I have taken
18:15:12this example first of all let's try to
18:15:14see the HITL implementation with this
18:15:16very simple example then I'm going to
18:15:18show you with the advanced example as
18:15:19well we'll uh we'll use our agent NTI
18:15:22code the code we have implemented so far
18:15:24and we'll try to integrate this uh
18:15:25things okay there but before that I want
18:15:27to show you the implementation part how
18:15:29it can be done that's why this uh
18:15:31example I'll be taking okay so I think
18:15:33you have understood what I want to do so
18:15:35whatever question is coming first of all
18:15:37here we'll just try to add a hit feature
18:15:41uh it will ask for the human review do
18:15:43you want to really ask the question if
18:15:44user gives yes then um this question
18:15:47would be uh going to the chat node and
18:15:50user will be able to see the output
18:15:51Otherwise user won't be able to see the
18:15:53output. Okay, this is the implementation
18:15:55we'll try to do. Now for this here I
18:15:58already prepared a notebook. So inside
18:16:00notebooks folder I already kept uh kept
18:16:02a notebook as you can see demo. Let's
18:16:04open it up. Okay. So I think uh this
18:16:06code is pretty much common. I have taken
18:16:08the same uh this uh this example. I
18:16:11think you know that I created a simple
18:16:13chat workflow. Okay. I copy pasted the
18:16:15same code and I added this HITL
18:16:17functionality there. Okay. So first of
18:16:18all here we are importing all the
18:16:20necessary library. As you can see here
18:16:22we have taken both model. If you don't
18:16:23have openi you can use uh gemini model.
18:16:25For this we are using this uh this
18:16:27library and uh some other library we're
18:16:30also importing. And uh we are also
18:16:32importing the checkpointter because I I
18:16:34already told you if you are implementing
18:16:36this hil you need this uh persistence
18:16:38memory. Okay. Then uh one new import I
18:16:42have done which is this from langraph
18:16:43types I have imported interrupt function
18:16:46and command. Okay. Because I already
18:16:47told you uh here if you want to add any
18:16:50kinds of HTL HITL functionality you need
18:16:53this interrupt function. Okay. So this
18:16:54should be interrupt sorry there should
18:16:56be a T. Okay interrupt function. So this
18:16:59interrupt function is required. So with
18:17:01the help of this interrupt you will try
18:17:02to pause the execution and you will take
18:17:04the input from the user and this input
18:17:07will basically become your command.
18:17:09Okay. So you can see this command is
18:17:10also required. Then load envirated
18:17:14and the base message. So let's import
18:17:16all of the necessary library
18:17:18and make sure inside your environment
18:17:20variable all of the key are present.
18:17:22Okay, whatever key we're using so far.
18:17:25Now let's load the environment variable
18:17:27and after that here I don't have open
18:17:30API key that's why I'll be using Gemini
18:17:32model and for this I already collected
18:17:33my Google API key. Let's uh initialize
18:17:36my model and here we are preparing the
18:17:38state guys. As you can see this is our
18:17:40state the same state we're using and
18:17:42here you can see in this chat note we
18:17:45have added this interrupt functionality
18:17:47that means HITL functionality okay that
18:17:49means here okay here we have added this
18:17:51HITL functionality so if you want to add
18:17:53this functionality you have to use this
18:17:55interrupt function I already told you
18:17:57you can see inside chat node see this is
18:17:58what this was our previous chat node
18:18:00right now this is the update I have done
18:18:02so here I am I'm using this interrupt
18:18:04function and in this interrupt function
18:18:06you have to give some like uh u metadata
18:18:09That means the first mate you have to
18:18:10give the type. So type should be
18:18:12approval. Reason model is about to
18:18:14answer a question. Okay. Then question
18:18:16whatever question user is asking this
18:18:18question you have to pass in the
18:18:19question section and the instruction.
18:18:21Okay. Approve this question yes or no.
18:18:23That means this instruction user will be
18:18:24able to see. Okay. Once he will execute
18:18:26the node this this message actually
18:18:28would be visible to the user. Do you
18:18:30want to approve this question? Yes or
18:18:32no. Okay. If user pass yes then this
18:18:34question would be going to the chat node
18:18:36and user will able to see the output and
18:18:38if he sends let's say no and that time
18:18:40it will be rejected. Now here we are
18:18:42checking you can see decision
18:18:45okay decision and here we'll try to
18:18:48expect a parameter expect a key called
18:18:51approve okay so if this approve is is
18:18:54equal to is equal to no let's see if
18:18:55user has given no that time I'll simply
18:18:57return the uh message okay that should
18:19:00be the AI message no approved okay not
18:19:02approved if user gives yes that means
18:19:06I'll simply invoke my large name base
18:19:08model I'll pass the message and user
18:19:10will be able to see the output So this
18:19:12is the simple things you have to add and
18:19:14the main thing here the interrupt as
18:19:15well as the command okay command uh
18:19:18functionality I'll show you the command
18:19:19where to add but here we are basically
18:19:22using the interrupt to pause the
18:19:23execution here okay and from the front
18:19:26end size that mean from the front end
18:19:28side that means from the user side we'll
18:19:30get this approved okay approved key I'll
18:19:32show you this part now let's execute
18:19:33this note now here we are building the
18:19:36entire graph guys you can see we're
18:19:38taking the graph we are adding the node
18:19:39we have only have one node
18:19:41We are doing the edge connection and we
18:19:43are preparing the checkpointer. So here
18:19:45just to show you I am using this
18:19:47inmemory server checkpointter and we are
18:19:49building the entire graph. Okay and
18:19:50we're passing the checkpointer and
18:19:52that's how your workflow looks like.
18:19:54Okay. So this is the same workflow. Now
18:19:56to execute the workflow guys you need uh
18:19:58this uh config you need this thread. I
18:20:00think remember if you are using
18:20:02persistence memory you need this thread.
18:20:04So here I created a dummy thread and we
18:20:06are initializing a input explain the
18:20:08gradient descent in a very simple terms.
18:20:10Okay, this is let's say our user input.
18:20:12So this input will uh invoke with this
18:20:16uh workflow we have created and the
18:20:18workflow object is app. So you can see
18:20:20we're invoking this input and we're
18:20:22passing the configuration. Now let's
18:20:24execute. Now see guys here you will uh
18:20:27get one result. Uh this is the result.
18:20:30Okay. Uh you can see this is the result
18:20:32you are getting. So here you can see
18:20:34this is the human message explain the
18:20:36gradient descent in a very simple term.
18:20:39And whenever uh it is going to the chat
18:20:42node there we added that hit. Okay that
18:20:45means here the interruption is
18:20:46happening. It is pausing the execution.
18:20:48Okay you can see you cannot see any
18:20:50kinds of output. Okay the model output
18:20:52you cannot see unless and until you are
18:20:54not providing any kinds of input. Now if
18:20:56you want to provide the input. So first
18:20:58of all let me show you the interrupt
18:21:00message. So this is the interrupt
18:21:01message you can see and this is the
18:21:03interaction uh instruction approve this
18:21:06question yes or no and some other
18:21:08metadata we have provided this is also
18:21:09coming here. Okay now what I'll do guys
18:21:12I'll take the user input. So here I am
18:21:14preparing the user input. I'm showing
18:21:16the same message to the user and here
18:21:18I'm taking yes or no from the user.
18:21:20Okay. So let's say this is my user
18:21:22input. So now user is giving let's say
18:21:24yes. Okay. Uh uh let's say user wants to
18:21:28see the message. Uh that means the
18:21:29output. Now if I give yes. Now inside uh
18:21:32user input what will be present? Yes.
18:21:34Okay. It will present yes. Now how this
18:21:36present uh uh how this uh input we have
18:21:39to return to the uh hit as a command.
18:21:43Okay. Now right now you can see we are
18:21:45again invoking this uh workflow. But
18:21:48right now inside invoke uh functionality
18:21:51we are giving this command keyword.
18:21:52Okay. We are giving this command
18:21:53keyword. Inside that we're telling
18:21:55resume is equal to approved. So you have
18:21:57to pass a dictionary. You can see we're
18:21:59giving approved and user input. Okay, so
18:22:01that means approved should be user
18:22:03input. So that's why here I have written
18:22:05this condition. Uh where is that? Yeah,
18:22:08if decision approved because it uh this
18:22:10approved uh key is getting created
18:22:12newly, right? If approved is equal to is
18:22:13equal to uh no, that means it will
18:22:15reject otherwise it will approve that.
18:22:17So that is what actually we're doing
18:22:18here.
18:22:20Okay, that that is what we are doing
18:22:22here. Then we are again passing the
18:22:24configuration and we are again invoking
18:22:26our workflow.
18:22:29Okay. Now one error I'm getting. Okay.
18:22:32So guys uh we are getting this error
18:22:34because uh inside our env we haven't set
18:22:36our environment variable yet. Okay. Uh
18:22:39so let's try to set all of my
18:22:40environment variable. All of the key. So
18:22:42this is my updated key I have uh added
18:22:46here. Now let me save and let me
18:22:48re-execute this notebook. Okay. So again
18:22:50what I will do I'll just try to execute
18:22:52from the beginning. So let me restart.
18:22:58Now let's execute all of this code.
18:23:05Now interrupt uh interrupt message we're
18:23:07getting. Now we're taking the user.
18:23:08Let's say user is passing yes.
18:23:13Now we'll try to invoke this workflow
18:23:15again.
18:23:24Now see this execution is complete. Now
18:23:27we'll see the final message. You can see
18:23:30this is the final message we're getting
18:23:31about the gradient descent. But let's
18:23:34say if user is giving no that time what
18:23:36will happen. Let's say again I will
18:23:38execute this uh code.
18:23:45user is giving no
18:23:50okay I have to re-execute from beginning
18:23:52because
18:23:55here I have running as a cell by cell
18:23:57right that's why
18:24:03now I'll give no
18:24:05if I execute my final
18:24:09uh final result now you'll see the
18:24:12output now you can see not approved
18:24:14because user has given Okay. So that's
18:24:16how guys you can add this HITL uh
18:24:18features inside any of your node. Okay.
18:24:21It's not necessary to add inside your
18:24:22node. Always you can also add this
18:24:24inside the tools. Okay. This part I will
18:24:26also show you uh after this demo. Okay.
18:24:29So yes guys, this is how we can um add
18:24:32this HITL and we have seen the simple
18:24:35demo. Now let's try to see the advanced
18:24:37example with our agentic chatbot we have
18:24:40created so far. And this is the uh this
18:24:42is the actually workflow we have
18:24:43created. I can remember uh because uh
18:24:45inside our workflow we are using some
18:24:47kinds of tools right and uh this is our
18:24:49workflow final workflow and this code we
18:24:52have already written as you can see this
18:24:53is the code we have written in my
18:24:55previous uh video if you haven't checked
18:24:57that please try to go through the
18:24:58recording so here actually I added the
18:25:00rag functionality and we added uh lots
18:25:02of tool here previously right you can
18:25:04see we have added lots of tool now guys
18:25:06first of all uh I want to show you uh
18:25:09this this uh agentic chatbot execution
18:25:13without using HITL. Okay, let's say if
18:25:16I'm not using HITL, uh what will happen
18:25:18that time? Let's try to see an example.
18:25:21So here I'm going to create a file. I'm
18:25:23going to name it as chatbot.
18:25:26Chatbot without
18:25:33HITL
18:25:36human in the loop. Okay. So after seeing
18:25:38that we'll try to add the HITL and we'll
18:25:40see the benefit of that. Okay. So
18:25:42chatbot without HITL. So what I'll do?
18:25:44So the code I have written the previous
18:25:46code that means the rag back end. Uh I
18:25:49think you have seen my previous video.
18:25:50I'll copy this entire code as it is. And
18:25:53here I'm going to paste it. Okay. So
18:25:55here I'm not going to change anything
18:25:56only the things I have to add um a new
18:26:00tool here. Okay. So here I going to add
18:26:02a new tool. So I think you remember um
18:26:05in this particular in this particular
18:26:07chatbot the sensitive uh the sensitive
18:26:10part is the stock price. Okay let's
18:26:14consider the stock price. So here we are
18:26:16getting the stock price right given any
18:26:18kinds of company. So here we'll try to
18:26:20add a new tool. So that tool will
18:26:23basically uh purchase the stock for me.
18:26:27So here I have written a simple uh dummy
18:26:29let's say uh tool. So uh it will it will
18:26:32only do the print statement that means
18:26:34return statement but in actual chatbot
18:26:37definitely uh here you have to use some
18:26:39kinds of API that API will uh connect
18:26:42the uh Apple let's say stock company and
18:26:46uh it will purchase the stock for you
18:26:48but just to show you here I have taken a
18:26:50dummy function so this function what it
18:26:52does it takes the symbol as well as the
18:26:54quantity like how how much quantity you
18:26:56want to purchase and which company you
18:26:59want to purchase and based on that it
18:27:01will give you some kinds of success
18:27:03statement. Let's say you have
18:27:04successfully purchased this uh stock.
18:27:06Okay. So this thing I have converted as
18:27:08a tool and I named it as a purchase
18:27:10stock. Okay. Purchase stock tool. Now
18:27:12what I have to do uh I have added a new
18:27:15tool and this tool I have to add inside
18:27:17my tool list. So I'll go below and here
18:27:21I have to add this tool. The tool name
18:27:23is par stock. Okay. Then we are binding
18:27:26this tool. Everything will remain
18:27:27common. No need to change anything.
18:27:31Uh
18:27:36just a minute let me check. Huh. So
18:27:38everything is fine.
18:27:42We have added this in the list. Now
18:27:47I will go below to list. Uh this is my
18:27:51checkp pointer. We are using SQLite
18:27:52database and we are creating the entire
18:27:55graph. And this is our helper function.
18:27:58It's completely fine. But here at the
18:28:00last I will add a
18:28:03simple CLI code. Okay, this is my simple
18:28:06CLI code. Basically I want to execute
18:28:09this file. Okay, in my uh terminal.
18:28:11Okay, that's why I have added this code.
18:28:12First of all, I am printing some
18:28:14message. That means this is a chatbot
18:28:16CLA. And here I have taken a demo trade.
18:28:19Okay, because if you know that if I want
18:28:21to uh because you know that if I want to
18:28:23execute my chatbot uh workflow, I need
18:28:26this trade. So that's why I created a
18:28:28demo trade and here I'm running a while
18:28:30loop. Okay, in this while loop I'm
18:28:31taking the user user input from the user
18:28:33and if user is giving let's say exit or
18:28:35quite I'm telling goodbye and breaking
18:28:36the loop otherwise I'm taking the user
18:28:39input. Okay, and preparing inside my
18:28:42state then we are invoking our chatbot.
18:28:44Okay, we are passing the trade ID then
18:28:47whatever response we are getting we are
18:28:48just printing uh in the terminal. So
18:28:50this is a simple CLI code I have
18:28:52written. Okay, just to execute my entire
18:28:54workflow. Now let me show you how this
18:28:56thing will work. So I will open up my
18:28:59terminal and I will execute this file
18:29:01chatbot without HITL. I'll just write
18:29:04Python
18:29:05chatbot
18:29:07without
18:29:09HITL. Okay. Now see if I execute
18:29:14now see it is uh asking for the input.
18:29:18Let's say here I will give hello.
18:29:22It's giving hello, how I can help you?
18:29:24Today I will ask uh what is the
18:29:28stock
18:29:29price
18:29:31of
18:29:33Apple?
18:29:36Now it will use that get stock price
18:29:38tool and it will extract the uh stock
18:29:41price of the Apple. Now see the stock
18:29:43price of Apple is uh okay that much. Now
18:29:46I'll tell uh purchase
18:29:53Okay. Purchase
18:29:5510 stock
18:29:58of
18:30:02Apple.
18:30:05Okay. Now see if I uh if I send this
18:30:09prompt,
18:30:10it will directly purchase the stock. It
18:30:12will use that tool, right? Uh like a
18:30:15purchase stock tool and it will purchase
18:30:17the stock. And here you can see the
18:30:19message. I have successfully placed the
18:30:21order to purchase 10 stock of Apple. Now
18:30:23see here it is not asking any kinds of
18:30:25user input. Right? Although this is a
18:30:27sensitive task we are performing but it
18:30:30is not asking any kinds of input. So
18:30:33there is a possibility it may do some
18:30:35mistake right? Instead of purchasing 10
18:30:37stock maybe it can purchase 20 stock
18:30:39right let's say instead of pinging
18:30:41purchasing um stock in Apple it will
18:30:44purchase the stock in Google. Okay. So
18:30:46these kinds of mistake my agent can
18:30:48perform. I think you know this is
18:30:49completely large language model and it
18:30:51can perform any kinds of wrong uh wrong
18:30:53task. It can do hallucination. I think
18:30:55you know that right? It's not always
18:30:57perfect. So here definitely I need a
18:31:00human approval here. Okay. If I want to
18:31:01perform this kinds of sensitive and
18:31:03critical task. So this is the execution
18:31:06you have seen without HITL and this is
18:31:08the problem here. Okay. Right now I'm
18:31:10going to show you if I add this HITL
18:31:13with this chatbot what will happen right
18:31:15now? Let's try to see. So I will exit
18:31:17this terminal
18:31:20H. Now here I'm going to create another
18:31:22file
18:31:25and I'm going to name it as chatbot.
18:31:30Chatbot uh with
18:31:34HITL.
18:31:40Okay. And here what I'm going to do I'm
18:31:43going to
18:31:45I'm going to copy paste the same code
18:31:50okay from my previous file and I'm going
18:31:51to paste it here and the modification I
18:31:54will do here in this particular tool.
18:31:58Okay in this particular tool
18:32:00uh this
18:32:03um stock price tool. Okay. Yeah. So here
18:32:06I'll do the modification. Why here I
18:32:08will do the modification? Because in
18:32:10this tool only I need the human
18:32:12approval. Okay. Whenever user is asking
18:32:14to purchase a stock right that time here
18:32:17only I need to perform the interrupt
18:32:19operation and whenever user is giving
18:32:21okay you just need to purchase it user
18:32:23is giving yes uh yes command that time
18:32:26this tool will execute otherwise this
18:32:27tool will not execute okay it will not
18:32:29purchase the stock for me. So for this
18:32:32I'll do a simple modification.
18:32:35See instead of this this function I have
18:32:38modified with this function.
18:32:40Now just try to see okay and most of the
18:32:42code I think this is common to you
18:32:44because I already explained previously.
18:32:46Okay in that uh simple demo right here
18:32:48I'm using interrupt function and uh here
18:32:51I just done a check statement here. Okay
18:32:55now I have to import this uh interrupt
18:32:57function as and common function. So
18:33:00let's import it as well.
18:33:07I'll import it here from langraph types.
18:33:10I'm importing interrupt and command. And
18:33:12I will go to my tool again. So this is
18:33:16the tool. Okay. Yeah.
18:33:22So see here I'm not adding this hit
18:33:25inside my chat node. Okay. Here I don't
18:33:27need to add inside my chat node because
18:33:29here I'm using a tool lots of tool okay
18:33:31and inside only get uh sorry purchase
18:33:34stock price in that tool only I need
18:33:36this HITL functionality okay always
18:33:39remember whenever you are using tools
18:33:41and you are creating this kinds of
18:33:43advanc advanc application right in chat
18:33:47node you don't need to add it you will
18:33:49be adding inside the tool that means
18:33:50with the tool you are performing some
18:33:52kinds of task you are performing some
18:33:53kinds of action and there this hit
18:33:56should be integrated okay not in chat
18:33:58node but in my previous example the
18:34:00simple example I have given you just to
18:34:02show you I added the hit in my chat node
18:34:04okay I hope you cleared now inside tools
18:34:07only I will add this functionality so
18:34:09this is the code for that
18:34:12I'll close some of the window
18:34:18chat with htl okay now this is the uh
18:34:21this is the tool guys I have written uh
18:34:23this is the update I have done so here
18:34:26Whenever it will uh use this uh use this
18:34:28tool that means my agent will use this
18:34:30tool that time you will uh it will see
18:34:32the interrupt function here and it will
18:34:34pause the execution here okay and user
18:34:36will able to see one message approve
18:34:38buying uh that means what how much how
18:34:40much quantity user will provide let's
18:34:42say user is provide uh 10 10 stock okay
18:34:44I want to purchase 10 stock of Apple so
18:34:47this 10 will come here so 10 shares of
18:34:49symbol means the company okay that's I'm
18:34:52giving Apple so apple will come here so
18:34:54do you want to purchase it yes or no.
18:34:56Okay, user will see this message. Okay,
18:34:58in interrupt only you can directly show
18:35:00the message. Then once user will pass
18:35:03this yes and no, it will store inside
18:35:05the decision. Okay, and right now I'm
18:35:07not storing inside uh as a dictionary.
18:35:10But previously the previous example I
18:35:11showed you right in the notebook
18:35:14in the notebook here I was storing as a
18:35:16dictionary. Okay, that's why I was uh
18:35:19checking the condition like that because
18:35:21here I was passing as a dictionary.
18:35:23Okay, I was passing as a dictionary but
18:35:25right now here I'm taking as a simple
18:35:27string. Okay, yes or no. So here I'm
18:35:30checking if this decision is a string
18:35:33and I'm doing the lower operation. If it
18:35:35is yes, then I'm returning this
18:35:37statement. Starter should be success
18:35:39message purchased order placed for
18:35:41quantity shares of symbol. Okay, uh
18:35:44symbol uh should be symbol and quantity
18:35:45should be quantity. That means here I'm
18:35:47giving a success message. Your uh order
18:35:49has been placed. Okay, let's see you
18:35:51have successfully purchased the stock.
18:35:53Otherwise if user is giving no. Okay. In
18:35:55the else block you can see purchase of
18:35:57shares of the symbol was declined by the
18:36:00human. Okay. And strategies canled right
18:36:02now. Okay. So this kinds of statement we
18:36:06have written inside our tool. Okay. And
18:36:08this thing you have to follow if you
18:36:10want to implement this HITL in any kinds
18:36:13of tool or any kinds of task you are
18:36:15implementing going forward. Okay. Now I
18:36:17want to give a task. Instead of purchase
18:36:20stock maybe you can add another tool
18:36:23that will perform some kinds of
18:36:24sensitive and critical task. Okay. And
18:36:26in that task you just might need to add
18:36:28this hit functionality. Okay. This
18:36:30should be your task after this
18:36:31implementation. Just try to make this
18:36:33aentic chatboard more advanced. You can
18:36:36u add some more advanced task which
18:36:38needs human approval and you can add
18:36:40this functionality here. Okay. Now this
18:36:43this is the update I have done. Now the
18:36:45next update you have to do
18:36:47next update
18:36:50if I go below
18:36:53already this tool is added inside the
18:36:54tool I don't need to add now your chat
18:36:56node will also remain same no need to
18:36:58add anything
18:37:00uh only this CLI CLI code you have to
18:37:04change okay right now uh user is giving
18:37:07the
18:37:08uh user is giving the interruption
18:37:10message that means the command so this
18:37:12thing you have to add uh take from the
18:37:13user So here
18:37:16this is the CLI code I have written
18:37:24because this this CLI doesn't have any
18:37:27um HITL input right now this has the
18:37:30HITL input so again the same loop I have
18:37:32written print statement demo trade while
18:37:36loop I'm taking the user input if user
18:37:38is giving exit and quite I'm like just
18:37:41breaking the loop then uh I'm preparing
18:37:44my state okay with the help of user
18:37:46input then I'm invoking my workflow okay
18:37:51and I'm passing my trade now we'll check
18:37:54this uh interrupt let's say whenever you
18:37:56are invoking the workflow and user is
18:37:58given let's say hello that time just let
18:38:00me know whether this interrupt interrupt
18:38:03uh interrupt will happen or not
18:38:04definitely there won't be any kinds of
18:38:06interrupt when interrupt will happen
18:38:08whenever you will ask purchase 10 stock
18:38:10or let's say purchase any stock of any
18:38:12company Right? That time that tool will
18:38:14be executed. I can okay uh that means
18:38:16our purchase tool will be executed and
18:38:19whenever that tool will be executed that
18:38:21time this interruption okay you will get
18:38:23the interruption that means you will get
18:38:25something in the interruption variable
18:38:27okay otherwise you will not get anything
18:38:29in the interruption variable that's why
18:38:30we're checking if interruption variable
18:38:32has something that means if interruption
18:38:34happens definitely some message you will
18:38:37get okay in the interrupt interrupt
18:38:39variable if you got the message that
18:38:40time you will feel like okay there right
18:38:43now there is interruption has happen
18:38:45inside my code then it will ask the
18:38:47human okay so what is the interruption
18:38:50okay you will show this prompt you can
18:38:52see I'm showing this prompt as a hit
18:38:54message okay whether uh he has to
18:38:57approved or uh uh approved or not so
18:39:00this thing I will take inside my
18:39:02decision I'm taking the input from the
18:39:04user your decision okay I'm just making
18:39:06it as lower then whatever decision user
18:39:09is giving I'm again reinvoking my ch
18:39:12chatbot okay and right now I'm giving
18:39:14the command and we are giving this
18:39:16resume parameter is equal to our
18:39:17decision okay which we are giving as a
18:39:19command then we are passing the
18:39:20configuration again and whatever result
18:39:22we are getting we are showing the
18:39:23message and we are also printing in the
18:39:26terminal so this is a simple code I have
18:39:27written now let me show you the
18:39:29execution so again I will open up my
18:39:30terminal and right now I'll execute this
18:39:34chatbot with
18:39:37hittl
18:39:40now see here I will give Hello.
18:39:46Hello. How how I can help you today? I
18:39:49will tell what is the
18:39:54stock
18:39:57of Apple?
18:40:00Stock price of Apple.
18:40:08Now see this is the stock price of the
18:40:09Apple as you can see. Now I'll tell
18:40:12purchase
18:40:14okay 20 stock
18:40:19of Apple.
18:40:21Okay purchase uh 20 stock of Apple. Now
18:40:24it will use that purchase tool right and
18:40:27there would be interruption that will uh
18:40:29basically happen the interruption that
18:40:30means hitl will apply uh in that
18:40:33particular tool and it will ask for the
18:40:34human input. Now hi
18:40:37uh TL has been triggered and it is
18:40:39asking for the human improve improved
18:40:42approved buying 20 shares of Apple. Do
18:40:44you want to approve? Yes or no. So here
18:40:46I will tell yes I want to purchase it.
18:40:48Now if I execute this code you'll see
18:40:50that I have successfully purchased an
18:40:52order to purchase 20 shares of Apple.
18:40:54That means uh this tool has been
18:40:57executed and uh this tool has purchased
18:40:59the shares for you. Okay. Of the Apple.
18:41:02Now again if I let's say reexecute this
18:41:04code let's say
18:41:07um
18:41:10purchase
18:41:13let's say purchase
18:41:1820 stock of Google
18:41:24now again it is asking for the human
18:41:26approval approved buying 20 shares of
18:41:28Google yes or no. Now if I let's say
18:41:30give no now it will decline okay
18:41:33declined so you can see I'm sorry your
18:41:35request was purchase 20 shares of Google
18:41:37was declined because you've given no
18:41:40okay right now just tell me which one is
18:41:42better okay for this kinds of sensitive
18:41:44task this kinds of critical task without
18:41:46HITL or with HITL definitely with HITL
18:41:50it is more accurate and more secured
18:41:53okay secured version of our agentic
18:41:55chatbot okay now guys I think you have
18:41:57got it how to integrate this HITL inside
18:42:00our agentic chatbot. Okay. Now guys, uh
18:42:03let's try to add this functionality
18:42:04inside our user interface. So what I
18:42:06have done guys, I just copy pasted the
18:42:09same code. Okay. I just copy pasted the
18:42:11same code and I uh given to the chart
18:42:14GPT and I asked I just need to add this
18:42:17HITL uh uh HITL functionality on my user
18:42:20interface and charge GPT has given me
18:42:23one updated code. Let me show you. Only
18:42:25you just need to uh update inside your
18:42:27front end. So maybe I'll create a
18:42:30separate file of the front end. Let's
18:42:31I'll tell it as app
18:42:34hi ll okay.py
18:42:38and this is the updated code I got from
18:42:40the chgpd guys. Again if you don't know
18:42:42about the front- end design no need to
18:42:44worry there are some front-end developer
18:42:47um uh in your uh would be in your
18:42:49company. So they will handle this kinds
18:42:51of scenario. Okay. But uh again if you
18:42:53don't know you can take the help from
18:42:54chat GPT and this is the updated version
18:42:57of our front end. Okay this has the uh
18:43:00hit u that means approval uh user
18:43:03interface. Okay that means the uh uh
18:43:05first time I showed you a demo right it
18:43:07was asking for a human approval yes or
18:43:09no button. So it has added that
18:43:10particular functionality here. Okay.
18:43:12Otherwise my back end code will remain
18:43:14same. There won't be any kinds of
18:43:15change. So what I'll do again I'll
18:43:17create another file here. Let's say um
18:43:21I'll copy the name
18:43:25and I'll create a new file. I'm going to
18:43:27name it as agentic chatbot hitl backend.
18:43:30Hitl
18:43:32backend. Okay. Backend.py sorry
18:43:37back end.py. Okay. And whatever code I
18:43:39have written inside chatbot with HITL
18:43:41I'll just try to copy paste as it is.
18:43:44Okay. So here from here I just need to
18:43:46copy chatbot with HITL. I'll just try to
18:43:48copy the same code and I'll paste inside
18:43:50my aentic chatbot. HITL backend.py.
18:43:53Okay. And uh no need to change anything
18:43:55only. You just need to remove this line.
18:43:58Okay. This CLA is not required. I'll
18:44:00just uh remove that code and everything
18:44:03will
18:44:05remain as it is.
18:44:07H now uh here in this app hit you just
18:44:12need to change this import. Okay. So now
18:44:14the import is agentic chatbot HITL back
18:44:16end. So agentic
18:44:19chatbot hit back end. Okay. So from here
18:44:21we're importing all the functionality
18:44:23and this is the updated code. Now let me
18:44:25execute and show you this execution. So
18:44:28here I'll stop the execution. Clear and
18:44:31I will run streamlit
18:44:34run
18:44:36uh
18:44:38app
18:44:40hl. Okay.
18:44:43Now this is your interface. Okay. The
18:44:46same interface I think you saw. Now here
18:44:49you can perform any kinds of chat
18:44:51operation. Tell me the
18:44:57latest
18:44:59news
18:45:02uh
18:45:04in AI. You will see that it will use
18:45:07some kinds of search tool.
18:45:10So see it is using tably search tool and
18:45:12it will give you the uh latest news in
18:45:14AI.
18:45:16You can see uh this is the latest new uh
18:45:19news I got and this is the news of
18:45:21Andropics. Okay, latest news. Now here I
18:45:23will ask u um I will try to check my
18:45:27HITL code uh HITL functionality. So here
18:45:30I'll tell uh what is the
18:45:33latest or let's say what is the stock
18:45:39price of Apple.
18:45:47It is using my get stock price and it is
18:45:50giving you the latest uh uh stock price
18:45:52of Apple. Now we tell purchase
18:45:58purchase let's say 20 stock
18:46:02of Apple.
18:46:09Now you'll see that it will ask for the
18:46:11human verification. Now see human
18:46:13approval is required and this is the
18:46:14user interface uh we have added with the
18:46:16help of charge GPT. Now if I approve
18:46:18this purchase now you see it will use
18:46:20purchase tool and it will purchase that
18:46:22uh that shares for me. You can see your
18:46:24order to purchase 20 shares of Apple has
18:46:27been placed successfully. Okay. Now if I
18:46:29let's say give another one
18:46:33uh process 20 stock of let's say Google.
18:46:38Now again it will ask for the human
18:46:39verification.
18:46:41Okay. Now if I reject this purchase now
18:46:44see it will tell your request to
18:46:46purchase 20 shares of Google was
18:46:47declined. Okay. So that's how this
18:46:49system is working right now and we have
18:46:51successfully added this hit
18:46:53functionality inside our agentic chatbot
18:46:56and you can also see the live tracing on
18:46:58the lang lang platform. You can go to
18:47:01the trades and you can open up your
18:47:05trades and you can see all of the
18:47:06execution. Okay. Now you can see guys uh
18:47:08it hit your hit functionality. This is
18:47:12also available here. Okay, you can see
18:47:14that. So guys, our agentic chatbot is
18:47:16ready and we have added all of the
18:47:18functionality. Okay, we have discussed
18:47:20previously in my introduction video in
18:47:22my um theoretical video. Okay, I think
18:47:25remember if you are following this
18:47:26playlist from the beginning, I think you
18:47:27know that we have already explained
18:47:29about all of the core component of
18:47:31agentic application. We have added all
18:47:33of these core component inside our
18:47:35aentic application and now this is like
18:47:36more advanced. Now the only part is left
18:47:40uh the deployment part. Uh in my next
18:47:42video guys I'm going to show you how we
18:47:45can deploy this uh agentic chatbot. Okay
18:47:48over the cloud platform and I'm not
18:47:50going to show you the simple deployment.
18:47:51I'm going to show you the CI/CD
18:47:53deployment. Okay that means continuous
18:47:55integration and continuous uh delivery.
18:47:57So there I will try to set up the entire
18:47:59CI/CD pipeline and we'll try to deploy
18:48:01this project over the um AWS cloud.
18:48:04Okay. Uh I'm going to show you another
18:48:05deployment on the render cloud. Render
18:48:07is another cloud and there you can also
Agentic Chatbot CI/CD Deployment on AWS with Docker & GitHub Actions
18:48:09do the deployment. Uh first of all I'm
18:48:11going to show the AWS deployment. Then
18:48:12I'm going to show you the render
18:48:13deployment as well. Okay means right now
18:48:16this uh bot is running on my local host.
18:48:18This agentic chatbot is running on my
18:48:19local host and it cannot access um by
18:48:23any kinds of people, right? You can only
18:48:24execute this bot. But let's say if you
18:48:26want to make it live right uh if you
18:48:28want to make make it live to the entire
18:48:29world that time you have to deploy this
18:48:31application. So this uh uh deployment
18:48:33part I'm going to show you in my next
18:48:35video guys. So yes guys this is all
18:48:36about and I hope you liked my content
18:48:39guys. If you like my content please try
18:48:40to subscribe to my channel and hit the
18:48:42like and please try to comment in the
18:48:44comment section if you have any
18:48:45question. Uh in this video I'm going to
18:48:48show you the uh final deployment of that
18:48:51identic chatbot. So guys, as I already
18:48:53told you here, we'll be doing something
18:48:54called CI/CD deployment, right? And I
18:48:57already told you what is uh CI/CD full
18:48:59form. It's continuous integration,
18:49:01continuous delivery or deployment,
18:49:02right? So inside continuous integration,
18:49:04continuous delivery, what happens? Let's
18:49:06say you are the developer. Okay, let's
18:49:09say you are the developer.
18:49:11So what is your task? Your task is to
18:49:14develop a project in the development
18:49:17let's say environment. So development
18:49:19environment means like your local
18:49:21system. Let's say you are using your
18:49:22laptop or computer. Let's say local
18:49:24computer. Okay, local
18:49:27computer.
18:49:30Fine. Then what we are doing? I think
18:49:33you remember we are committing this code
18:49:35to the GitHub, right? We are doing the
18:49:36code management. I think remember that
18:49:38means that means whenever I was adding
18:49:39some new feature, I was pushing this
18:49:41code to the GitHub. Yes or no? Okay.
18:49:44With the help of G client, we are
18:49:46pushing the code in the GitHub GitHub
18:49:47server. Now what happens actually let's
18:49:50say after deployment so this is called
18:49:52actually development server or I can
18:49:54write uh this is actually development
18:49:55environment
18:49:59okay development environment so after
18:50:02implementing this project what we have
18:50:04to do we have to deploy this project yes
18:50:06or no let's say um somehow you have
18:50:09deployed this project on the AWS cloud
18:50:11let's say this is your AWS cloud fine so
18:50:14let's say you have deployed this project
18:50:16to the AWS cloud
18:50:19manually manually you just created a
18:50:21let's say instance there you create uh
18:50:23you just took a machine there a KC2
18:50:25machine and you manually deployed this
18:50:27project now it will give you some
18:50:28endpoint okay endpoint so with the help
18:50:33of this endpoint any of the user
18:50:37okay user can access your application
18:50:39now let's say after 4 month or let's say
18:50:426 month you want to add some more
18:50:44features in this let's say uh
18:50:46application Let's say you are deploying
18:50:48medical chatbot. Let's say you want to
18:50:50add some more data. You want to add some
18:50:52more knowledge base and you want to add
18:50:53some more features in this application.
18:50:55Then what you have to do? You have to
18:50:56again develop this let's say features in
18:50:59your code. Then what you will be doing
18:51:00again you'll be deploying this
18:51:02application to the as cloud. Now just
18:51:04try to see whenever you are deploying
18:51:05the project for the second time. Let's
18:51:08say this is the first time you have
18:51:09deployed then you are trying to deploy
18:51:10for the second time. Then what you have
18:51:12to do? First of all, you have to stop
18:51:14this application in the AWS. Okay, stop
18:51:17this application. Then you'll be
18:51:18uploading your updated code. Then this
18:51:20code will reflect to the endpoint. Then
18:51:22user will able to access that. Now let's
18:51:24say in between whenever you stop this
18:51:26AWS server, let's say your uh
18:51:29application, let's say it took 3 hours.
18:51:32It took 3 hours to change the entire
18:51:34source code. That means uh change the
18:51:36entire features, okay, of your
18:51:38application. So what will happen? 3
18:51:40hours user won't be able to access your
18:51:41application. So they will come your
18:51:43website and they will see server error.
18:51:45Okay, server error actually they will
18:51:47get. So if user is getting this kinds of
18:51:50experience so definitely it would be a
18:51:51negative let's say uh effect okay on
18:51:54your application. So next time actually
18:51:55they are not going to use your
18:51:57application yes or no. Let's say if
18:51:58charg is down for the uh let's say 3
18:52:01hours definitely people will move to the
18:52:03Google b or any other let's say software
18:52:06whatever actually we are having. Okay.
18:52:08So now see chart GP is also updating
18:52:10their let's say application day by day.
18:52:13But did you ever observe this server is
18:52:15down? No even not seeing this server is
18:52:17down but still they're able to make the
18:52:18changes in their application. How?
18:52:20Because they are following something
18:52:21called CI/CD approach. Continuous
18:52:22integration, continuous delivery. That
18:52:24means this application is keep on
18:52:26running but in the back end they're
18:52:28pushing their source code. They're
18:52:29pushing their let's say new features and
18:52:31this feature is automatically getting
18:52:32updated. Okay. So this is collected
18:52:34CI/CD that means you are not going to
18:52:36deploy this application manual. Instead
18:52:38of that what you have to do you have to
18:52:39follow the CI/CD. That means what will
18:52:40happen? Let's say you have changed
18:52:42something in your code. You will push
18:52:44the code to the GitHub. Okay. GitHub
18:52:46will automatically uh let's say deploy
18:52:48your code to the AWS cloud. It will
18:52:51automatically push your code to the AWS
18:52:53cloud and your endpoint would be
18:52:55automatically updated. Okay.
18:52:57automatically updated so that if user is
18:52:59using your application okay they won't
18:53:01be filling any kinds of let's say server
18:53:03down issue okay server down issue
18:53:06actually they won't be failing got it so
18:53:08this is what actually uh we have to do
18:53:10that means we'll be creating the entire
18:53:11pipeline entire let's say CI/CD pipeline
18:53:14so we'll be just pushing the code in our
18:53:16GitHub and GitHub will automatically
18:53:18trigger uh this uh action and my code
18:53:21will update it to the AWS cloud and AWS
18:53:23will update the endpoint okay now see
18:53:26the automated process we'll be doing now
18:53:28whenever we we'll let's say push our
18:53:29code to the GitHub GitHub will
18:53:31automatically trigger how it will
18:53:32trigger for this you have to use some
18:53:34CI/CD tool okay CI/CD tool CI/CD
18:53:37automation tool so here there are
18:53:38different kinds of CI/CD tool so the
18:53:40first tool you can use something called
18:53:41GitHub action okay GitHub action you can
18:53:44use then you can use something called
18:53:45genkins okay genkins then you can use
18:53:48something called circleci
18:53:52so these actually three famous tool
18:53:54actually we are having in the market
18:53:55right now so people are using more this
18:53:58GitHub action because GitHub action you
18:53:59don't need to set up anything. It is
18:54:00already set up everything in the GitHub.
18:54:02But if you're using Genkins and CircleCI
18:54:04you have to set up this server manually.
18:54:06Okay. So here we'll be using GitHub
18:54:07action because it is already inbuilt
18:54:08with the GitHub. We don't need to set up
18:54:10anything. Going forward I will also show
18:54:11you how we can uh let's say use Genkins
18:54:13CircleCI. These are the services as
18:54:15well. Fine. So yes guys this is the
18:54:17complete uh highle architecture of our
18:54:19deployment. So guys uh here you can see
18:54:21this is our application code and uh we
18:54:24have written actually so many files but
18:54:27uh if you see the final files here which
18:54:30is this app hittl
18:54:33and this uh agentic chatbot hittl back
18:54:36end okay because this was our last uh
18:54:38last update we have done right so
18:54:40instead of like uh deploying all of
18:54:43these file guys uh what I'm going to do
18:54:45I'm only going to copy the final file
18:54:48okay the final code and I'm going to
18:54:50create a new uh folder and inside that
18:54:52I'm going to keep these are the code
18:54:54okay uh just to explain you all the
18:54:57concept guys I have kept all of my
18:54:59previous code and this is not required
18:55:01actually to run my final uh project so
18:55:04my final project is uh right now this
18:55:06app um app hittl let me show you so
18:55:09let's say if I execute this one
18:55:12streamlit
18:55:15uh run
18:55:17app
18:55:19hittl okay.py Pi. Now you'll see that uh
18:55:22my agentic chatbot uh application will
18:55:25be opening.
18:55:27So guys as you can see this is our
18:55:29application we have u implemented so
18:55:32far. So here uh what I'm going to do uh
18:55:35instead of moving all of these file I'm
18:55:37only going to take my final file which
18:55:40is this uh front end app hit and my back
18:55:43end which is agentic chart. HITL back
18:55:46end. Okay. Apart from that I need this
18:55:48requirement.xt txt file. Uh yeah, so I
18:55:51think if I have these are the file then
18:55:52I'll be able to run my final application
18:55:55and I also need this file because inside
18:55:57that you have all of the credential. So
18:55:59what I can do I can maybe create a new
18:56:01folder here and uh let's create this
18:56:04folder
18:56:07or I'll just create a GitHub repository.
18:56:09Okay, because here we have to do the
18:56:11CI/CD deployment and for this first of
18:56:14all uh you have to create a GitHub repo
18:56:16and you have to uh push all of your
18:56:19code, okay, in that particular
18:56:20repository. So what I'm going to do
18:56:22guys, I'm going to open up my GitHub. So
18:56:24here what I'm going to do, I'm going to
18:56:26create a new repository.
18:56:29Let's name it as uh aentic
18:56:33chatbot.
18:56:36Okay. Aentic chatbot using lang graph
18:56:45lang graph.
18:56:47Okay. Now uh what I'm going to do I'm
18:56:50going to simply add a readmi file.
18:56:55Then I'm going to take this g ignode
18:56:57here. I'm using python programming.
18:56:59Let's select the python. Uh you can also
18:57:01take any kinds of license. Let's take
18:57:03this apache license. You can also take
18:57:04any other license is completely fine.
18:57:07Now let's create the repository.
18:57:13Okay. Once repo is created, uh click on
18:57:15this code and copy this link address and
18:57:18open up your uh local folder. Inside
18:57:20that open up your terminal. Okay. You
18:57:23can also open up your git bash. It's
18:57:24completely fine. Now here simply write
18:57:26get clone
18:57:29and paste your uh URL you have copied
18:57:32from the GitHub and clone this
18:57:34repository here. Okay. Now you can see I
18:57:36have successfully cloned this
18:57:37repository. So now what I'm going to do
18:57:39I'm going to simply redirect this
18:57:40folder. So cd
18:57:43aentic
18:57:47chatbot using lang graph. Okay. Now I'm
18:57:49inside this particular folder. If I show
18:57:51you see I'm inside this particular
18:57:53folder right now. Now here I have to
18:57:55move my code file. Okay, my final code
18:57:57file. So what is my final code file?
18:57:59I'll take this appl
18:58:02then uh this agentic chatbot hit back
18:58:06end as well as this env file and I need
18:58:09this requirement.txt. Okay. Yeah, I
18:58:12think these are the file I need only.
18:58:13Now I'll copy this and I'll try to paste
18:58:16inside this uh new uh folder I have
18:58:19created. Okay. Now if I open up with my
18:58:22uh Visual Code Studio, let me open up.
18:58:25So this is my Okay, this is my old code.
18:58:27Now I'll try to open it with my Visual
18:58:29Code Studio.
18:58:31Yeah. So you can see guys, this is my uh
18:58:34final code. Okay, I have copied from my
18:58:36previous code. Yeah, this is my final
18:58:38version of the code. Now uh what I can
18:58:41do, I can maybe rename these are the
18:58:43file instead of keeping this file name
18:58:45like that, I can rename it. So first of
18:58:47all let's try to change this backend
18:58:49file name. So here let's rename it. So
18:58:53here I'm only going to name this file as
18:58:55backend.py.
18:59:00Okay backend.py
18:59:02and this app hit I'm going to name it as
18:59:07only app.py.
18:59:11Okay app.py. Now make sure uh whenever
18:59:15you uh you have renamed this file you
18:59:18also need to uh change the import. Okay.
18:59:20So it has automatically changed because
18:59:22I'm using one extension that extension
18:59:25automatically will uh like uh trigger uh
18:59:29whenever I'm changing any kinds of file
18:59:31name. It will automatically change that
18:59:32uh input in my other file as well. Now
18:59:35you can see I'm importing all everything
18:59:37and it's coming one warning because I
18:59:40have to select my original environment
18:59:42which is langraph test. Okay, this
18:59:43environment now I think everything is
18:59:45fine. Okay, now here uh what I have to
18:59:47do guys, I have to
18:59:50uh I have to
18:59:52um
18:59:54let me check again. Huh. So everything
18:59:57is fine. Let me show you whether it's
18:59:58working or not. So what I can do I can
19:00:01stop my previous execution and let's
19:00:04open up my new terminal.
19:00:08Now I'll execute this app. So cond
19:00:15list.
19:00:18So this is the name of the environment.
19:00:20I'll copy
19:00:24and I'll just write conduct activate
19:00:29my environment.
19:00:31Now after that let's execute my app.py.
19:00:33So streamllet
19:00:36run
19:00:37app.py Pi.
19:00:42Now see this is the application. Now
19:00:44let's uh test this application. Uh see
19:00:47right now you can't see any uh any of my
19:00:49old trades because completely right now
19:00:52I have copied my uh chatbot in a new uh
19:00:56new actually folder. Okay. And right now
19:00:58all of the execution will be happening
19:00:59from the beginning. So let me test this
19:01:02chatbot whether it's working or not. So
19:01:04here I'll pass hello.
19:01:07See it's working. Okay. Hello, I can uh
19:01:10help you today. That means everything is
19:01:11fine. That means uh this is our final
19:01:13code we can utilize right now for the
19:01:15deployment. Now guys, let me write all
19:01:18the deployment step actually we'll be
19:01:20following for this CI/CD deployment. Um
19:01:24let me write here
19:01:28this is the [clears throat]
19:01:31this is the entire step. Okay, you can
19:01:34see this is this enter step I have
19:01:36already prepared for this deployment. So
19:01:37let me open the preview. Yeah, now you
19:01:40can see here. So see this is a streaml
19:01:43app and uh we have to deploy the
19:01:46streamlit app over the AWS cloud as a
19:01:48CI/CD and for CI/CD tool-wise we'll be
19:01:52using GitHub actions. Okay. And GitHub
19:01:54action is already uh already actually
19:01:57let's say uh built-in CI/CD like uh
19:02:01tool. You don't need to set up this
19:02:03GitHub action server separately. This is
19:02:05already running on the GitHub. Okay, you
19:02:07just need to um you just need to
19:02:09actually configure that GitHub actions
19:02:12by adding some commands. Okay, by adding
19:02:15some commands inside a file. We call it
19:02:17as a CI/CD. ML file. This file I'm also
19:02:20going to show you how you can write
19:02:21that. But as you can see, this is the
19:02:24deployment step we'll be following.
19:02:25First of all, we'll try to build the
19:02:27Docker image of our source code. Okay.
19:02:30uh we'll try to dockerize entire for
19:02:32source code. Then we'll try to push this
19:02:34docker image to the docker hub. Okay.
19:02:36Then I'm going to launch a EC2 machine
19:02:38on AWS server. Uh then I'm going to pull
19:02:41my Docker image. Okay. From the Docker
19:02:44hub to EC2. Then I'm going to launch my
19:02:47um like image. That means I'm going to
19:02:50execute my application as a Docker
19:02:52container inside EC2 machine. Okay. Then
19:02:54I'll do some port mapping. Then you'll
19:02:56be able to access your application.
19:02:58Okay. uh from the remote URL. Now for
19:03:02this Docker knowledge is definitely
19:03:04required and I am expecting you are
19:03:06already familiar with Docker but if you
19:03:08don't know about Docker and all so don't
19:03:10worry I have a complete uh like let's
19:03:13say tutorial on my channel as you can
19:03:15see I have a complete um video ultimate
19:03:18MLOps full course in a one video. So
19:03:20this is around 11 uh almost 12 hours of
19:03:23recording and this course covers
19:03:25everything about the MLOps. uh I have
19:03:27already covered Linux. Okay. Then um
19:03:30some other tools as well. You can see in
19:03:32the description section. See lots of
19:03:34like MLOps tools I have covered. And
19:03:36here we'll be seeing uh one section uh I
19:03:39think from this uh hour itself you can
19:03:42uh start watching uh docker concept.
19:03:44Okay. You can see the docker concept I
19:03:46have also covered in this particular
19:03:47course itself. Now if you are completely
19:03:49new to the docker and if you want to
19:03:50learn the docker okay how do works and
19:03:52why do required I'm going to suggest you
19:03:54go through this recording. I'm going to
19:03:56add this uh video in my description.
19:03:58From there you can check it out. Okay,
19:03:59you don't need to watch from the
19:04:01beginning. Maybe you can only complete
19:04:02the docker part at least so that you can
19:04:05um you can u see the deployment part.
19:04:08Okay, you can um understand like how
19:04:10doer is helping for the CI/CD deployment
19:04:12and all. Okay. So yeah, this is the
19:04:14requirement. Then uh here I have added
19:04:17this step. First of all, we have to
19:04:19login to the AWS console. Then we'll be
19:04:22creating the IM user. Okay. Then after
19:04:24creating the IM user, we'll try to set
19:04:25the policy. Then we'll try to create the
19:04:27EC2 uh machine. Okay, we'll be taking
19:04:30open Ubuntu instance. After that, we'll
19:04:32try to open the EC2 instance and we'll
19:04:34try to set up uh docker there. Okay,
19:04:36because by default in the EC2 there
19:04:38won't be any kinds of docker. You have
19:04:39to set up it. Once the setup is
19:04:41complete, then uh you will be um able to
19:04:44set the port. Okay, that means by
19:04:46default streaml runs on port number
19:04:488501. Okay, so we'll try to do the port
19:04:50mapping. Then we'll try to set up our
19:04:53entire project as a self-hosted runner.
19:04:55That means we'll try to connect our AWS
19:04:58with our GitHub. That means once let's
19:05:00say we will try to push something in the
19:05:02GitHub automatically my CI/CD pipeline
19:05:04will trigger and all of the new changes
19:05:07will be available over my AWS. Okay,
19:05:09that means automatically my deployment
19:05:11will be happening. So these kinds of
19:05:12pipeline we have to create by creating
19:05:14the self-ostraed runner. Okay, I'm going
19:05:16to also show you how to create that.
19:05:17Then once everything is complete then
19:05:19I'll try to uh like set up all of my
19:05:21secret. Okay. So you can see uh if you
19:05:24want to run this project you need these
19:05:25are the secret. Uh apart from that some
19:05:27additional secret is also required like
19:05:29um registry docker username docker
19:05:31password. Okay. Image name AWS access
19:05:34key ID as secret key uh secret access
19:05:36key. Okay as region. So these are the
19:05:39thing additionally you need because if
19:05:40you want to uh authenticate with AWS
19:05:43account uh programmatically you need
19:05:44these are the credential. Okay. I will
19:05:46try to create this credential as well.
19:05:47I'm going to show you okay how to do do
19:05:49that and I am going to push my uh uh
19:05:52docker image uh to the docker hub for
19:05:54this docker credential is also required
19:05:56and you should have also account in the
19:05:58docker hub and uh after that whatever
19:06:00credential I'm having I think you
19:06:02already know that these are the
19:06:03credential I need to execute my entire
19:06:05agents okay like if you're using openi
19:06:07model you can set the open api key tab
19:06:09API key open weather google okay if
19:06:11you're using gemini you can set the
19:06:13google api key lang smmith lang smith
19:06:15endpoint lang smmith API then lang
19:06:17speedit project. Okay. So yeah, this is
19:06:19the step guys we'll be following for uh
19:06:22deployment. Okay, for this CI/CD
19:06:24deployment now first of all guys here
19:06:26I'm going to create a docker file. So
19:06:29let's create a docker file here. So to
19:06:32dockerize your entire application you
19:06:34need this docker file. Okay. And inside
19:06:35this docker file you have to write some
19:06:37docker related command. Now what are the
19:06:40command you have to write. So this is
19:06:41the command guys and this thing you will
19:06:43be able to understand uh from that
19:06:45particular video I suggested you because
19:06:47in that video I have covered like what
19:06:49is this uh uh beige image okay uh what
19:06:52is this environment what is this working
19:06:53directory okay each and everything I
19:06:55have explained there if you are
19:06:57completely new to the docker first of
19:06:58all try to complete that recording I
19:07:00think that would be easy for you okay
19:07:02but if you're already familiar with
19:07:03docker and you know that these are the
19:07:05command we need to create uh the docker
19:07:07image that means to containerize entire
19:07:09our application Right. So yeah, we are
19:07:11setting this um command inside the
19:07:14docker file and here you can see we have
19:07:16to install the requirement.txt. Okay,
19:07:18we're also uh installing in this
19:07:20particular command. Uh and I have
19:07:22already commented out. See now this uh
19:07:24part you need uh to prevent python cache
19:07:27file and enable immediate uh container
19:07:29logs. Okay. Then this code you need to
19:07:32build the essential supports package
19:07:33that required uh compilations. then lib
19:07:38uh gum gum one is a commonly required by
19:07:42fire CPU that means here I am using fire
19:07:45CPU for the vector database right that's
19:07:47why this library you also need to
19:07:50install okay whenever you are upgrading
19:07:51this machine then you need this
19:07:54requirement txt um it has to copy in the
19:07:58root folder then um you can see uh we
19:08:01will be installing this requirement txt
19:08:03and this is the command we are writing
19:08:05then we are copying all of our source
19:08:07code inside the root directory. Then
19:08:08we're exposing the port and by default
19:08:11streamllet runs on port number 8501.
19:08:13We're exposing the port and this is the
19:08:15final command to launch the streamlit
19:08:16server. Okay. So yeah, this is the
19:08:18docker file and with this docker file
19:08:20you need another file which is dot
19:08:22docker ignore
19:08:26ignore. Okay. So inside this dot uh
19:08:28docker ignic node uh you have to write
19:08:30some of the unnecessary files and folder
19:08:33which you don't need to uh integrate
19:08:36inside uh your docker image let's say if
19:08:39you have your virtual environment okay
19:08:41in this particular folder itself that uh
19:08:43you don't need okay whenever you are
19:08:44creating the docker file right so that
19:08:46time you can ignore this one so that
19:08:48means whatever file and folder you will
19:08:50be keeping inside dot docker ignore it
19:08:52will ignore during building the docker
19:08:54image okay like uh this get ignore and
19:08:56you know get ignore what it does it
19:08:58ignores the files and folder whatever
19:08:59you will be adding inside this get
19:09:01ignore okay so that it won't be pushing
19:09:03inside our um github repositories okay
19:09:06so these are the things uh actually I
19:09:08don't need inside my um docker image
19:09:11that's why I'm ignoring inside dot uh do
19:09:13docker ignore so once it is done uh then
19:09:16I'll try to add this cicdl file for the
19:09:20github actions acd deployment so for
19:09:22this you have to create a folder the
19:09:24folder name should be github Okay. So
19:09:27this is the folder name we usually use
19:09:28and this folder name you don't need to
19:09:30change. If you are changing it will not
19:09:32work. So by default if you're using u
19:09:34this uh GitHub actions for this
19:09:37deployment you have to create this dot
19:09:39GitHub folder. Inside that I'm uh you
19:09:41will be creating another folder called
19:09:42workflows.
19:09:44Okay workflows. Make sure you are using
19:09:47the same name otherwise it will not
19:09:49work.
19:09:50Okay workflows. And inside this
19:09:53workflows you will be creating a file
19:09:54called cicd
19:09:56dot
19:09:58yml uh okay yl okay this is a yl file
19:10:03inside that you have to mention all of
19:10:05the command you need for the cicd
19:10:07deployment okay now just verify whether
19:10:11everything is fine or not inside github
19:10:13workflows and cic.ml file is available
19:10:15okay now guys uh what I'm going to do um
19:10:19I'm going to maybe close this file this
19:10:21is not required. Yeah, I'm going to open
19:10:24up my new code. Yeah, now what I'm going
19:10:26to do guys, I'm going to add all of the
19:10:28CI/CD related command and these are the
19:10:31CI/CD related command you will be
19:10:33getting in the internet itself. Okay. Uh
19:10:35you can simply search I want to perform
19:10:38um CI/CD deployment. Okay. Uh on AWS and
19:10:43I have a streaml application for that. I
19:10:45need this uh CI/CD. ML file. So you will
19:10:48be able to see this YML file is
19:10:50available okay over the internet you
19:10:52don't need to memorize it you will be
19:10:53getting this thing in the internet only
19:10:55and if you have the chart GPT gemini
19:10:57simply you can open the chart GP and
19:10:58Gemini you can ask okay I need a CI/CDML
19:11:01file commands uh I have to do this
19:11:03deployment okay streamllet app on the
19:11:05AWS as a CI/CD so I have already
19:11:08prepared the CICDML command so let me
19:11:10show you so this is the
19:11:12uh command and most of the command you
19:11:14can see this is a Linux command uh if
19:11:16you are completely new to the Linux
19:11:17command So again in my MLOps course okay
19:11:21on my YouTube channel I already covered
19:11:23the Linux okay relaxated command you can
19:11:25see uh Linux is also covered okay you
19:11:27can go through the Linux video as well
19:11:29to understand how this command works
19:11:31okay so yes uh this is the like uh uh
19:11:34structured command you need to execute
19:11:37uh whenever you want to perform CI/CD
19:11:38with the help of GitHub actions so first
19:11:40of all you have to define a name of your
19:11:42application so here I have given
19:11:44streamlit AWS CICD you can change the
19:11:46name anytime Then on push okay that
19:11:48means if you're pushing on the main
19:11:50branch that means right now I have the
19:11:53GitHub right this is the GitHub and here
19:11:55I am using main branch that means
19:11:57whatever push I'm going to do on my main
19:11:58branch this pipeline will trigger okay
19:12:02only it will ignore if you're changing
19:12:04the readmi file because readmi is not a
19:12:06feature okay readmi is kinds of file
19:12:08there I just try to write some metadata
19:12:10for my project right so if I'm changing
19:12:12anything in my readmi that time our cd
19:12:14pipeline should not be triggered that's
19:12:16why path not ignore we are writing
19:12:18readmi file otherwise if you're changing
19:12:20in any file this pipeline will start
19:12:22okay this cd pipeline will start and
19:12:24your deployment will be happening then
19:12:27uh we are giving some other like uh
19:12:29parameter as well like workflow dispatch
19:12:32concurrency okay permissions we are
19:12:34giving each and everything and this is
19:12:35already uh I mean uh predefined actually
19:12:39workflows you have to write if you're
19:12:41using this uh GitHub actions for the
19:12:43CI/CD deployment okay this is not our
19:12:45code So CI/CD uh uh with the GitHub
19:12:49actions documentation if you check so
19:12:51they have written these are the commands
19:12:52should be added inside your CIC dol. Now
19:12:56here the main thing is the jobs. So here
19:12:58first of all continuous integration will
19:12:59be happening inside continuous
19:13:01integration we are just only eing the
19:13:02command. Okay we are taking a Ubuntu
19:13:04instance and we are only eing the
19:13:05command. Then the second step we are
19:13:08building and pushing the image to the
19:13:09docker hub. So here first of all we are
19:13:12verifying with the uh docker hub
19:13:14account. So make sure you have the
19:13:15Docker Hub account. So if you don't have
19:13:17you can create. So simply search for
19:13:19DockerHub. Okay, Docker Hub. Go to the
19:13:21first website and make sure you have a
19:13:24account here. Okay, I already have the
19:13:25account that's why it it got login.
19:13:28Okay, but if you don't have account
19:13:29guys, please try to create an account.
19:13:31So let's say I will sign out.
19:13:36So here you can sign up. Okay, sign up.
19:13:38You can fill your information. After
19:13:40filling you will be able to create the
19:13:41account. So I already have the account.
19:13:42I'll just try to sign up.
19:13:45sign in.
19:13:47So this is my email and password. I'm
19:13:48going to sign in with my Docker Hub.
19:13:52Okay. And this is how your Docker Hub
19:13:55will look like. Okay. Previously I
19:13:57already pushed some of the image that's
19:13:58why it's available. But for you it would
19:14:00be completely empty. Okay. So Docker Hub
19:14:02is a service that you can store all of
19:14:03your Docker image. Okay. You are
19:14:05creating. You can also use AWS ECR
19:14:08service but this is fine. Uh I can use
19:14:10Docker Hub also. It's completely fine.
19:14:12Okay. Okay, in AWS also to store your
19:14:14docker image there is a service called
19:14:16AWS ECR elastic container registry.
19:14:18Okay, you can also use that this one but
19:14:20I'm going to use docker hub for this
19:14:21particular project. Maybe in future I'm
19:14:22also going to show you that elastic
19:14:24container registry how to use that
19:14:27because I want to uh minimize my cloud
19:14:29cost that's why I'm using these are the
19:14:31free uh free to use actually hub okay to
19:14:33push my image
19:14:35and uh yeah so here you can see we are
19:14:38authenticating with the docker hub and
19:14:40after that we are building the image
19:14:42okay we are building our docker image
19:14:45then after building we are pushing this
19:14:46image to the docker hub then once my uh
19:14:50second step done Then it will start the
19:14:52third step. There you will try to deploy
19:14:54your image to AWS EC2 instance. Okay. As
19:14:58a self hosted runner. For this this is
19:15:00the command. So it will again
19:15:01authenticate with your docker hub and it
19:15:03will uh take that image and it will run
19:15:06on your EC2 instance. Okay. And to run
19:15:08your app you need some credential. I
19:15:10think you remember you need Google API
19:15:12key API key open a open weather API.
19:15:15Okay. So whatever let's say API you have
19:15:17used right you have to write all of the
19:15:19API here. You can see uh what is that?
19:15:22Yeah, but you are not going to directly
19:15:24give the value. So this value you'll be
19:15:26reading from the secret. Okay, we call
19:15:28it as a GitHub secret. I'm going also
19:15:29going to show you how to add this
19:15:30secret. But make sure whatever API key
19:15:32you are using, you have to write here.
19:15:34Okay, and here we are checking all of
19:15:36the API keys are available or not. If
19:15:38not available, we are uh just uh like
19:15:41launching a message called secret is
19:15:42missing. Okay. Then uh this is the code
19:15:45and finally we are running our docker
19:15:47image and it is starting the server.
19:15:49Okay. And some other necessary command
19:15:52we are also running. Okay. Everything
19:15:54will be running in that docker video I
19:15:56have already given you. Okay. In my
19:15:57MLOps course. Now this is the cicd.
19:16:00Mamel file guys you need for this uh
19:16:02deployment. Now everything is ready. Now
19:16:05let's try to create the server. Okay.
19:16:08Server means I will follow this step.
19:16:10Okay. First of all here what I'm going
19:16:12to do? I'm going to login with my AWS
19:16:14console. So let's try to login. I
19:16:17already logged in with my AWS console.
19:16:18Make sure you have the AWS account. If
19:16:20you don't have the account guys, please
19:16:22try to create one account. I already
19:16:23logged in with my AWS console and that's
19:16:25how your console looks like. Now here
19:16:27the first thing you have to search for
19:16:28the IM user. Okay, IM user that means
19:16:31identity access management. Um then I
19:16:34will go to the IM user section and here
19:16:36you have to create an user. Okay, let's
19:16:38create a user. So I'm going to name it
19:16:40as uh let's say agentic.
19:16:46Okay, agentic user. You can give any
19:16:48name it's up to you. Now I'll click on
19:16:50next. Then you have to add the policies.
19:16:52Okay. And which policies you have to
19:16:53add. So here I think I have already
19:16:55written.
19:16:57Uh yeah. So after login to the console
19:16:59we are creating the IM user and this is
19:17:00the policy you have to add. Okay. AD
19:17:02Amazon EC2 full access. So here uh let
19:17:07me check again. Amazon EC2 full access.
19:17:09Okay. Huh? Because you only need the EC2
19:17:11instance. Okay. So I'll copy this and uh
19:17:14here I'm going to search it here. Okay.
19:17:17Okay. So, Amazon EC2 full access. I'll
19:17:18provide this access and I'll click on
19:17:21next. Okay. See why we are giving this
19:17:23permission because in my AWS account
19:17:25there are lots of services we are having
19:17:27right [snorts] and it's not like that
19:17:29I'm going to give all of the services
19:17:31access to my um like project to my code.
19:17:35Instead of that I'm only going to give
19:17:36the access the service actually I'm
19:17:38using otherwise there is a possibility
19:17:40uh it might use some other service and I
19:17:42will end up with lots of cost right? But
19:17:44I don't need that. So that's why I am
19:17:46only giving the access the services I'm
19:17:48using. So here I'll be using EC2
19:17:50instance. EC2 is a virtual machine
19:17:52inside AWS. Okay. Once it is done, let's
19:17:54create the user.
19:17:58Okay. So some error is coming.
19:18:03The specific username is invalid. Must
19:18:05contain. Okay. So I think the name we
19:18:07have given this is not uh okay. There I
19:18:10have given a space, right? But it should
19:18:11not be having any kind of a space. So
19:18:14I'll give this hyphen sign. Now let's
19:18:16click on next. Now I'll provide this um
19:18:22Amazon EC2 full access. Click on next.
19:18:25Everything is fine. Create the user.
19:18:28Okay. So my user creation is done. Now
19:18:30I'll go inside the user and there is a
19:18:32option called security credential. Just
19:18:34try to click here
19:18:36and uh here you will see this one access
19:18:40keys. Okay. Now I'll click on this
19:18:43create access keys. Now select this
19:18:45command line interface CLI and just do
19:18:47the confirmation. Okay. Once everything
19:18:49is done, now click on the next. Then I
19:18:51will uh click on this create access
19:18:53keys. Okay. Now this is our access keys
19:18:56and secret access keys. Guys, you need
19:18:57to authenticate with your AWS because
19:18:59I'm going to access my AWS account from
19:19:02my Python code, right? Um uh from my
19:19:05actually GitHub actions.
19:19:07Uh that's why this credential is
19:19:09required. Okay. Now you can download as
19:19:12a CSV file as well. Let's try to
19:19:13download this thing. I need later on.
19:19:15Now this service is creation done. Okay.
19:19:18Now this this is creation done. Um we
19:19:21have successfully created the IM user
19:19:24and we have given the policy and we
19:19:26collected our access key and secret
19:19:28access key. Now the next step you have
19:19:29to create the EC2 machine Ubuntu
19:19:31machine. Okay. Now let's do that. I will
19:19:33go to my home and here I will search for
19:19:37uh EC2 instance. Okay. Let's open this
19:19:40EC2 instance. And EC2 instance is a
19:19:43virtual uh virtual computer service.
19:19:46Okay. Inside AWS. Now I'll just try to
19:19:50click on launch instance. Uh launch
19:19:52without a walk through. Okay. Now you
19:19:54have to give a name. So I'll give
19:19:56aentic.
19:19:58Okay. Agentic chatbot
19:20:04machine. Okay. You can give any name.
19:20:06It's up to you. And make sure you select
19:20:08this Ubuntu instance. Okay. There are
19:20:09some other instances available like Mac
19:20:11OS, Windows, Red Hat. But I will take
19:20:13this Ubuntu instance because this is the
19:20:15most used instance whenever you are
19:20:17doing the production grade deployment.
19:20:19Now once it is done you can uh select
19:20:21the instance type that means how much
19:20:23memory how much CPU you need. You can
19:20:26select the configuration here. So for
19:20:27this project at least 4 GB RAM is
19:20:30required. Okay. And I'm going to take 2
19:20:32vcpu. I think this T2 medium is fine for
19:20:35me. Okay. But if you are creating a
19:20:37heavy project that needs lots of
19:20:38computation that time you can also take
19:20:40some bigger instance as well. Some
19:20:42bigger instance are also available like
19:20:4332 GB memory 16 GB memory. Okay you can
19:20:47see everything is available. Now I'll
19:20:48take this T2 medium. Okay this is fine
19:20:50for me. Now here you have to create a
19:20:53key value pair uh key pair. Now you can
19:20:55give the name. I'll give aentic.
19:20:58Let's create the key. And once it is
19:21:01created you can select it from here.
19:21:03Okay. agentic
19:21:05huh this one so this uh key you need
19:21:08whenever let's say you want to access
19:21:10your uh this EC2 machine from any third
19:21:12party tools like putty and mobile
19:21:14extreme that time it is required but for
19:21:16our case we'll try to launch in the uh
19:21:18same uh Google chrome only okay there uh
19:21:20you can launch the uh terminal okay your
19:21:24uh easy to inst terminal this is also
19:21:25possible now here you have to uh check
19:21:29mark these two option allow https and
19:21:31allow http traffic from the internet and
19:21:33here you can take the storage at least
19:21:36try to take 32GB storage and uh
19:21:39everything is fine no need to change
19:21:40anything simply launch the instance
19:21:48okay so I'll go below and click on view
19:21:51all instance now see my instance has
19:21:54created and it is running okay make sure
19:21:55it is running otherwise you can keep on
19:21:56refreshing this page now simply I'll
19:21:59click on my instance ID and here you
19:22:01will get one option call this connect
19:22:03button. Okay, but before connect button
19:22:05I think you remember what I told you. I
19:22:07told you to do the port mapping as you
19:22:09can see. Uh
19:22:13okay, port mapping I think we can also
19:22:15do do later on but you can do the port
19:22:17mapping right now. Uh if you want just
19:22:20do the port mapping otherwise we'll do
19:22:22do it later on. Okay. So simply I'm
19:22:24going to connect my instance. Okay. So
19:22:26there is a connect button. Just try to
19:22:28click on the connect button and uh make
19:22:30sure you select everything as default.
19:22:32If you want to connect this uh this uh
19:22:34let's say EC2 instance from any third
19:22:36partyy tool that time you can use HSS
19:22:37client and you can use mobile extreme
19:22:39putty. These are the tools to connect.
19:22:41Okay. But I'm going to connect from my
19:22:44uh same AWS CLI only. I'm going to
19:22:46simply click on connect. Now see in a
19:22:48different tab it will open up your this
19:22:51uh EC2 instance terminal. Okay. This
19:22:53will be your uh Linux terminal and there
19:22:56you have to execute all the command to
19:22:57set up your entire server. Okay. Now see
19:22:59this is the Linux server we are getting
19:23:01guys that's cleared and for this you
19:23:03need some idea about Linux command
19:23:06Ubuntu Ubuntu operating system and this
19:23:08thing I have already covered in my
19:23:10ultimate MLOps full course okay there I
19:23:12have already covered about the Linux you
19:23:13can study about that okay for the
19:23:15deployment guys you need little bit of
19:23:17understanding MLOps if you know about
19:23:19MLOps it would be easy for you to do the
19:23:21deployment now guys what I'm going to do
19:23:23I'm going to set up all of the
19:23:27uh all of the package I need here So for
19:23:29this I mention all of the command as you
19:23:31can see. Uh first of all you have to
19:23:34upgrade your machine. So for this just
19:23:36copy this command and execute it here.
19:23:42Right click and paste and execute. Then
19:23:45I'll copy the next one. See you just
19:23:47need to copy this command one after one
19:23:50and just execute inside the terminal.
19:23:53Done. Now I'll coph paste this second
19:23:56command. So see this is a completely new
19:23:59create newly created machine and here
19:24:00you have to upgrade the package manager.
19:24:03Okay. So we are upgrading and for this
19:24:04we're using pseudo get upgrade this
19:24:06command. Now I'll give yes permission
19:24:09and upgrade this machine
19:24:15and that's how your production server
19:24:17looks like. Okay. That's why you you may
19:24:19be heard of in production you need to
19:24:22know about Linux. Okay. because every
19:24:24production server they're using Linux
19:24:27especially the Ubuntu instance okay
19:24:28they're using now this is also done I
19:24:31will clear the terminal now let me see
19:24:33the next command next command you have
19:24:35this um
19:24:37you have to install this docker okay now
19:24:39to install the docker this is the
19:24:41command first of all let's download the
19:24:43docker
19:24:44there's a hs file you have to download.
19:24:55Then after that we'll try to install.
19:25:08I'll copy this command one by one.
19:25:23paste the next command.
19:25:26And this is the last command you have to
19:25:28execute.
19:25:33Now see docker successfully got
19:25:35installed inside our Linux instance. You
19:25:37can check it. For this you can run this
19:25:39command docker version. So you'll see
19:25:42that Docker is running right now. Okay.
19:25:43But previously Docker was missing. Okay.
19:25:46I can maybe close my local local host
19:25:49execution.
19:25:51Let's close it.
19:25:53Uh terminal is also running. I'll stop
19:25:55it. H.
19:25:58So fine. Uh we have successfully
19:26:00installed Docker. Now the next step I
19:26:01have to uh configure my EC2 as a
19:26:05self-hosted runner. For this just open
19:26:07up your GitHub and go to the settings.
19:26:10Okay. Make sure you are using your
19:26:11GitHub, okay? Not my GitHub. Go to the
19:26:13settings and uh left hand side you will
19:26:16see one option called uh actions. Now go
19:26:19to the runner.
19:26:23Okay. Here just try to select this new
19:26:25self-hosted runner
19:26:30and you will see this Linux uh operating
19:26:32system. Just try to select that and uh
19:26:35these are the command you have to
19:26:36execute inside your EC2 instance. I'll
19:26:38copy the first command and execute in
19:26:40the terminal.
19:26:43Then I'll copy the second command. I'll
19:26:46execute in my terminal.
19:26:51I'll copy the third command and let's
19:26:53execute it here.
19:26:56That means you are connecting your AWS
19:26:58with your GitHub. Okay, that means
19:27:00whatever change you will uh let's say
19:27:02push in your GitHub automatically uh
19:27:04this will be um uh this will be like
19:27:07let's say available inside your AWS.
19:27:10Uh then I'll copy the last command
19:27:15and execute.
19:27:21Okay, so two more command you have to
19:27:22execute. So inside configure this
19:27:24command.
19:27:29Now see GitHub action is getting
19:27:31initialized and it is it is already
19:27:33connected with my GitHub. Now here it is
19:27:35asking for the internal name of the
19:27:37runner group. I don't need to give any
19:27:39runner group name. I'll simply press
19:27:40enter.
19:27:42Then it is telling enter the name of the
19:27:44runner. So here make sure you give the
19:27:46same name self-enhosted.
19:27:49Okay. That means in this uh YML file I
19:27:53think you remember here you have given
19:27:55this name okay continuous deployment you
19:27:58have given ransom self hosted you have
19:28:00to give the same name here self-en
19:28:02hosted okay so make sure you are giving
19:28:03the same name otherwise it will not work
19:28:05now I'll press enter now it is asking uh
19:28:08there would be any following labels uh I
19:28:11don't need any label I will skip it
19:28:12press enter then it is telling enter the
19:28:14name of the work working folder I'm
19:28:17going to again press enter okay now it's
19:28:19Now simply you have to copy this last
19:28:22command and you have to execute and you
19:28:24will be able to see that uh your u AWS
19:28:27will be connected to your GitHub.
19:28:30See connected to the GitHub and
19:28:32listening for the jobs. Now you can test
19:28:34it here. So simply you can again click
19:28:36on the runners. Now see your self-hosted
19:28:39runner it is already idle. That means
19:28:41your AWS is connected with your GitHub
19:28:43and it is listening for the jobs. Now
19:28:45right now if you push anything in your
19:28:48uh in your let's say repository right if
19:28:50you push any any code automatically it
19:28:52will get deployed over the AWS um AWS
19:28:56cloud okay how because you have written
19:28:58this YML file and inside this YML file
19:29:00all the commands are available for the
19:29:02deployment operations okay but one more
19:29:04thing I have to do which is this secret
19:29:06credential I have to add other without
19:29:08this secret it will it will not work
19:29:09okay so definitely this secret needs to
19:29:11be added so let's add the secret Now if
19:29:15you see the last step uh last step is
19:29:18that you have to add the secret key in
19:29:20the GitHub actions. Okay. So let's do
19:29:23that. I'll go to the GitHub again. Go to
19:29:26the settings.
19:29:28Left hand side you will see one option
19:29:29called secret and variable and go to
19:29:32this action section. Okay.
19:29:35Now here you have to create a new
19:29:37repository secret.
19:29:39So first of all you have to
19:29:42create this registry.
19:29:47Registry should be docker.io because we
19:29:51are using docker hub.
19:29:55So make sure this is the key name and
19:29:56this is the value name. Okay. Inside
19:29:57secret you have to give the value and
19:29:59add the secret.
19:30:01Okay. Done. You can see we have added
19:30:04this uh secret. Now I'll uh create
19:30:07another one new repository secret and
19:30:10I'll do it for the next one. I'll add my
19:30:12docker username.
19:30:18So what is what is my docker username?
19:30:20If you go to my docker hub. So this is
19:30:23my hub. If you just click on my account
19:30:26here, you will be able to see the
19:30:28username. Okay. So make sure you check
19:30:29your username in your docker hub and
19:30:31copy the same name and give it here.
19:30:38Now the next thing I have to add the
19:30:41docker password that means docker hub
19:30:43password. So make sure you are giving
19:30:45your docker hub password. Okay. So let
19:30:47me give my password guys. So this is uh
19:30:49this is like secret password. I don't
19:30:51want to show you. So that's why I'm
19:30:53going to pause the video after adding
19:30:55the password. I'm going to show you the
19:30:56next step.
19:30:59So yeah guys I have successfully set my
19:31:01docker password. Okay. So that's how you
19:31:03have to add all of the secret inside
19:31:05this secret variable. Now let's try to
19:31:07add the next one the image name.
19:31:14So image name I'm going to let's say
19:31:17give the same name like aentic chatbot.
19:31:20So with this name actually your docker
19:31:22image would be created. Okay. You can
19:31:23also change this name as per your
19:31:24requirement. I I have given aentic
19:31:26chatbot. Now let's add this secret.
19:31:29Now next I have
19:31:31this AWS access key ID.
19:31:35Now why you will get this AWS access key
19:31:37ID? I think remember we downloaded one
19:31:40CSV file. Okay, this CSV file. Let's
19:31:42open it up. I'll open in my Notepad++.
19:31:45So this is the secret and secret access
19:31:47key. So first of all, let's copy this
19:31:49access key ID. So before this comma,
19:31:51this is your access key ID. Okay, I'll
19:31:53copy and paste it here. And make sure
19:31:58you don't share this credential with
19:31:59anyone otherwise they will be able to
19:32:00access your account. Okay, I'm going to
19:32:01remove after this recording. Don't use
19:32:04my one. Okay, try to use your one. Now
19:32:06AWS access key is done. Now let next I'm
19:32:09going to add AWS secret access key
19:32:16secret access key. Okay, now where you
19:32:18get the secret address key? So this part
19:32:20is your secret address key. Okay, that
19:32:21means after this comma whatever you have
19:32:24this is your secret access key. Let's
19:32:25copy and paste it here.
19:32:31Done. Now next you have the AWS region.
19:32:39So right now I'm inside you will see
19:32:40that I'm inside US East one region North
19:32:43Virginia US East one. Okay. If you're in
19:32:45other region you can give this name.
19:32:47Okay. But right now I'm inside US East
19:32:49one. I will give the same name here.
19:32:52Why is that? Yeah. Let's copy.
19:32:58So all the command I have given in my
19:33:00readmi file you can check from there
19:33:02guys.
19:33:06Done. Now next I have to add
19:33:09the open API key. If you're using open
19:33:12API key guys you have to add the open
19:33:14API key. Okay. And make sure you add
19:33:17your value here. So I'm using Google
19:33:20Gemini model because I don't have open
19:33:22API key. So that's why I'm not going to
19:33:24pass my open API key. But I just showed
19:33:26you, okay, how to add your open API key.
19:33:27So make sure you pass your open API key
19:33:29here. Okay.
19:33:32Now here I'm using Google API key. That
19:33:35means I'm using Gemini model. I'll be
19:33:37using my Google API key instead of
19:33:38OpenAI. You can also remove this part if
19:33:40you are not using OpenAI. But I have
19:33:42showed you if you're using OpenAI, you
19:33:44can add it. Add this. Now I'm going to
19:33:46add the table API key.
19:33:51Tablely and where is your table API key?
19:33:54It is available inside your environment
19:33:58variable. So this is your table API key.
19:34:00Let's copy
19:34:03and give it here.
19:34:08Then next you have this
19:34:11um
19:34:14open weather API key.
19:34:20Just copy my open open weather API key
19:34:22from this env.
19:34:31Okay. Now next I have to add
19:34:38after open weather Google API key.
19:34:47So here I have my Google Google API key.
19:35:00Now next
19:35:02you have this
19:35:07lang smmith tracing
19:35:09because we're also using lang lang
19:35:11smmith for monitoring our entire
19:35:12application right to trace all of the
19:35:14execution
19:35:16and this secret would be true.
19:35:21You can also verify from your
19:35:23environment. So tracing should be true.
19:35:25Okay. And don't give any quotation.
19:35:28Okay. Quotation you don't need to give.
19:35:31Now next [clears throat] I have this
19:35:36Langmith endpoint.
19:35:44This is the end point.
19:35:52Now next I have this
19:35:58lang API key.
19:36:05And here is your lang API key.
19:36:14Done. Now next you have
19:36:18this
19:36:20lang project name. Okay, that's how
19:36:23whatever API key you are using you have
19:36:25to add inside the secret. Okay, that's
19:36:28how you have to prepare the secret
19:36:30variable. So what is the name? Aentic AI
19:36:34project agentic chatbot project. This is
19:36:37name I think I was using
19:36:39even you can also open up your language
19:36:41platform. You can verify
19:36:46Yeah. So, aentic chatbot project. Okay.
19:36:48If you want to create a new one, you can
19:36:49also create an uh uh it's completely
19:36:51fine. But here I'm tracing all of my
19:36:53execution. All right. So, all of the
19:36:55secret I have added guys. Uh let me
19:36:57check if I'm having anything else. No, I
19:37:01think everything is added. Okay. Now,
19:37:02see all of the secret we have added. So,
19:37:04right now this secret is not visible uh
19:37:06to the public. Okay. So, this is
19:37:09available inside my account inside my
19:37:11secret. Okay. and my application will
19:37:13pick up from this particular secret
19:37:14only. That's why everywhere I have given
19:37:17secret dot your API name or let's say
19:37:20key name. Okay. So that's how you don't
19:37:22need to expose your API key u I mean to
19:37:24the audience. Just try to make sure you
19:37:26are adding inside the secret. Okay. This
19:37:28is super important. Now everything is
19:37:30done. Now we are ready for the
19:37:31deployment. So right now our server is
19:37:33connected. My GitHub is connected. My
19:37:37self-hosted runner runner is running.
19:37:39Everything is done. Now simply I'm going
19:37:41to push the changes. Okay. Now let's try
19:37:42to push the changes. I'll commit the
19:37:44changes. So here I'm going to open up my
19:37:46terminal. I'm going to write g add. So
19:37:49see these are the file I'm going to
19:37:52push.
19:37:56Yeah. So everything is fine. But let's
19:37:58let's delete these are the file. This is
19:38:00actually created uh because I have
19:38:02executed this uh project right. And it
19:38:03has created the persistence memory. But
19:38:05I want to delete it. Okay. I want to
19:38:08like push completely new new project
19:38:10okay to the cloud. So I'll delete this
19:38:13at the file.
19:38:15So everything is fine. [clears throat]
19:38:16Now let me push the changes. So I'll
19:38:18open up my terminal. I'll just write g
19:38:20add space dot then get commit type m
19:38:29uh I'll give let's say updated
19:38:33and I'll just write get push
19:38:40origin
19:38:42main.
19:38:46Now push is done. Now if I go to my
19:38:49GitHub.
19:38:53Okay. Now see everything is updated in
19:38:55my GitHub and your workflows is running.
19:38:58Okay. You can go to the action and you
19:39:00can see your first comet is running.
19:39:02This is your first uh attempt to the
19:39:04CI/CD deployment. Okay. And this is a
19:39:06one-time setup guys. This uh setup you
19:39:08have to do one time and going forward
19:39:10you don't need to do this setup. Okay.
19:39:12Going forward you will only just try to
19:39:13change your upgrade and automatically it
19:39:15will be getting deployed. Now see
19:39:18three-step it is running continuous
19:39:19integration building and pushing image
19:39:21uh push docker image and deploying to
19:39:23the AWS EC2. So continuous integration
19:39:25is already completed. Now building and
19:39:28pushing image is running. Okay. So right
19:39:30now my image is getting builded. Okay.
19:39:32You can see it is setting everything all
19:39:33the package and everything. So this
19:39:35process may take some time. Let's wait.
19:39:38Now see requirement got installed
19:39:39successfully. After that it will push
19:39:41the image to the docker hub. Now you can
19:39:43see in the docker hub I don't have any
19:39:45kinds of image name with the help of
19:39:47agentic chatbot. Okay. Now you'll see
19:39:48that after some times this image would
19:39:50be available.
19:39:52Everything is happening automatically
19:39:54guys. Okay. Because I have set up the
19:39:55entire server. I have written that YL
19:39:57file and all of this command is
19:39:59available. So everything would be
19:40:00automatically. This is the beauty of
19:40:02CI/CD deployment.
19:40:04Only one time effort. Okay. One time
19:40:06configuration, one time setup and rest
19:40:08of the life you can enjoy.
19:40:12And that's how production deployment
19:40:14happens. Um, whatever application you
19:40:17can see, right? Everything is connected
19:40:19with CI/CD pipeline and that's how
19:40:21they're setting up the server. You can
19:40:24also use any other cloud like GCP,
19:40:25Azure. Uh, it's completely fine. The
19:40:28step will remain same. Maybe some
19:40:30functionality would be different. Okay.
19:40:31In that cloud.
19:40:39Now see uh build and push is complete.
19:40:43See the green tick mark that means
19:40:45complete. Now deploying this image to
19:40:47the AWS EC2. Now it is pulling the image
19:40:50and it will run on my EC2 instance.
19:41:17Okay. See all the three steps are
19:41:20complete. All the three steps are
19:41:21getting green tick mark. That means
19:41:23everything is fine. There is no error
19:41:24inside our workflow. Okay. We have
19:41:27successfully uh deployed. Now I will go
19:41:30to my instance and there you will see
19:41:32one option called public DNS. Okay. Just
19:41:34try to copy this URL and paste over the
19:41:38new tab. And if I execute, see uh right
19:41:41now this uh application uh is not going
19:41:44to open because we haven't done the port
19:41:46mapping. Okay, port mapping is required
19:41:48because by default our application is
19:41:50running on port number 8501. Okay, so we
19:41:53have to do the port mapping.
19:41:55So to perform the port mapping, you can
19:41:57go back to your instance and there is a
19:41:59option called security. Just go to the
19:42:02security.
19:42:03There is option called security groups.
19:42:05I'll click on security groups. And here
19:42:07you will see one option called edit
19:42:09inbound rules. Okay. Now here you can
19:42:11see your uh port number is not defined
19:42:14here. That means 850 uh 0 um 8501 is not
19:42:18defined here. So just try to add the
19:42:20rules and port number you have to write
19:42:228501. Okay. This is the port of streaml.
19:42:24You can also verify in the cicd. Mamel
19:42:28at the last whenever you are running
19:42:30your image, right? So there you said
19:42:32that yeah see you are doing the port
19:42:35mapping to 8501. This is the port. Okay.
19:42:38By default stream application runs port
19:42:40uh 8501. Now you have to select this 00.
19:42:43Okay. Uh that means you can access from
19:42:45anywhere and simply save this rules.
19:42:48Done. Now I'll go to this instance
19:42:50again. Instance ID. Now I'll copy this
19:42:52public DNS again.
19:42:55Okay. And make sure after this URL you
19:42:57are you are giving this uh clone port
19:43:01number 8501.
19:43:03Okay 8501. Now if I execute I'll see
19:43:06your application will be running and
19:43:10this is completely live right now. Okay.
19:43:12Now if I share this URL with anyone they
19:43:14will be able to access my agent.
19:43:18See this is running on the AWS server
19:43:21right now and this is completely live.
19:43:22Okay. Now you can purchase any kinds of
19:43:24domain name. Okay. Uh then you can
19:43:27change this name with your domain name.
19:43:28On domain name this is also possible.
19:43:30Okay. But if you know till here I think
19:43:33it's completely fine. Uh the domain uh
19:43:36part I think this will take care by the
19:43:37front- end developer. So right now our
19:43:40chatbot is running live. Okay. We can
19:43:42test whether it's working or not. So
19:43:44let's say I will give hello.
19:43:48See how I can help you today. Then I
19:43:50have given another message. I am BP. Now
19:43:52it is telling nice to meet you bi. Now
19:43:54it'll tell tell me the current
19:43:59weather.
19:44:04Okay. In Dhaka.
19:44:11Now see it is using my get weather uh
19:44:13tool and it is giving you the kind of
19:44:15weather in Dhaka. Now we'll ask uh
19:44:19uh latest
19:44:22news
19:44:25uh in FIFA.
19:44:31Now see it is using tably search tool
19:44:33and this is giving you the latest news
19:44:35on FIFA. Okay. So this is the latest
19:44:38news you're getting. Now you can ask any
19:44:43other thing. Let's say you can ask about
19:44:44the um stock price.
19:44:48Tell me
19:44:51tell me the stock
19:44:55price of
19:44:58Apple.
19:45:02Okay, this is the current stock price of
19:45:04Apple. Now you can also purchase any
19:45:07stock. So you can just write purchase
19:45:13uh let's say 20 stock
19:45:19of Apple.
19:45:30Okay. Now again we have added this HITL
19:45:33features that means that means human in
19:45:34the loop. It will ask for the human
19:45:36verification.
19:45:38Now see asking for the human
19:45:39verification. Now if I approve now my
19:45:43share would be purchased. Okay. Now you
19:45:45can even upload any kinds of document.
19:45:46You can start the conversation. You can
19:45:48also create a new trades. This is also
19:45:50possible. Let's say I have created a new
19:45:52trades. Okay. Now here I will ask upload
19:45:54any kinds of documents. Let's I will
19:45:56upload my resume and I will ask tell me
19:46:00about
19:46:01Bir Ahmed
19:46:04Bi based on
19:46:08the
19:46:09PDF
19:46:11uploaded.
19:46:16Now see it is using rag tool
19:46:19and it is giving you about myself. Okay.
19:46:22Based on the resume I'm having. Okay. So
19:46:25that means everything is working fine
19:46:27and this is completely live right now.
19:46:28You can share this URL with your friends
19:46:30and family. They'll be able to use that.
19:46:33Okay. So amazing guys. We have seen how
19:46:35to perform the deployment. Now the u I
19:46:38mean good part I want to show you about
19:46:40the CI/CD deployment is that now let's
19:46:42see in future if you want to add any new
19:46:44change here. Okay let's say if you want
19:46:45to add any new features you don't need
19:46:47to manually let's say uh set up
19:46:50everything again in the cloud server.
19:46:53Okay, you don't need to manually copy
19:46:54paste your code and set up everything.
19:46:56Only you just need to change and upload
19:46:58inside your GitHub. Automatically this
19:47:00deployment will be happening. Let me
19:47:01show you. Let's say in this app.py
19:47:04um let's say right now let me show you
19:47:06one like a small features. Okay, I'll be
19:47:08adding here. Let's I'll refresh my app.
19:47:12H. So right now you can see it is
19:47:13agentic chat but with langraph. Okay,
19:47:15let's say I want to add a emoji here.
19:47:17Okay, let's say I want to add a emoji.
19:47:19So what I'm going to do, I'll go I'll go
19:47:22to that part that I'm creating this
19:47:24title.
19:47:26I think here I'm creating the title
19:47:28right here. So let's say I'm going to
19:47:29add a emoji. So simply let's add an
19:47:32emoji. So let's say I'm going to add
19:47:34this uh this robotic emoji. Okay. So I'm
19:47:36going to add this robotic emoji.
19:47:38Refresh.
19:47:40And uh yeah, save it. And now we have to
19:47:43commit it again. Okay. You have to
19:47:44commit your change again. So let's
19:47:46commit our change again. So I'll just
19:47:49write
19:47:53get add space dot
19:47:56get commit hyphen m let's say I'll give
19:48:02new feature
19:48:04addit
19:48:06okay and get push
19:48:09origin
19:48:12main
19:48:16now push is done now again I I'll go to
19:48:18the GitHub and I will see that your
19:48:20pipeline will automatically
19:48:23uh get triggered.
19:48:25Now see again action is running. I'll go
19:48:27to the action. Now see new feature
19:48:28added. This pipeline is running again.
19:48:31Okay. And this version is having a new
19:48:33update. Okay. Again it will build the
19:48:34docker image. Push the docker image to
19:48:36the docker hub. So you can see in the
19:48:38docker hub itself you will see your
19:48:40application
19:48:42that is your image. See aentic chatbot.
19:48:45So right now it is having only
19:48:49uh one image. Okay. And it is uploading
19:48:51the next image here. So let's wait.
19:48:58See again all of the execution is
19:49:00happening. And you don't need to do
19:49:01anything. Okay. And still your server is
19:49:03live. See if you refresh here, if you
19:49:05start the conversation, it will run.
19:49:07Okay. It will not uh it will not
19:49:09actually shut down. Okay. But if you're
19:49:11not creating CI/CD pipeline that time
19:49:13there is a possibility it will get shut
19:49:15down. Okay. And user will feel uh this
19:49:18application is not working and then you
19:49:20may lose your user. Right? So that's why
19:49:22CST is required
19:49:25in the back end all of the deployment is
19:49:27happening but you are not going to uh
19:49:29you are not going to see anything right
19:49:31now. If I come here see deployment is uh
19:49:33completed. Now if I come here now if I
19:49:35refresh my application
19:49:37now see that new update has added here.
19:49:41Now see this uh emoji has been added
19:49:44here. Okay. So this is called actually
19:49:46CI/CD deployment and that's how you can
19:49:49continuously add new features without
19:49:51shut down your application. Okay,
19:49:53without let's say stopping your
19:49:54application and this is what actually we
19:49:56use inside the industry inside the
19:49:59production deployment. Okay, I hope
19:50:01everything is clear guys. So if you
19:50:03found this content useful, please try to
19:50:04subscribe to my channel and share this
19:50:06video with your friends friends and
19:50:07family and please try to like on my
19:50:10video guys. Okay. And if you have any
19:50:12question, please try to comment in the
19:50:14comment section. Uh I would like to see
19:50:15your comment and I would like to see
19:50:17your opinion. Okay. Whether um this
19:50:20playlist is helpful or not because I
19:50:22have covered each and everything. I have
19:50:23implemented the project. I showed you
19:50:25the end to end implement uh end to end
19:50:27deployment. Everything I showed you.
19:50:28Okay. And lots of things are coming as
19:50:30well. So guys, yeah, we have seen the
19:50:32deployment. Now we will see that how we
19:50:35can uh terminate all of the server
19:50:37because if you keep on running it, it
19:50:38will charge you. So let's say once uh we
19:50:40have deployed everything, our learning
19:50:42is over. Now I'm going to show you how
19:50:45we can stop the server. Okay, let's say
19:50:47you want to stop the server, how to do
19:50:49that. So for this, okay, one more thing
19:50:50I want to show you that say if I close
19:50:52this terminal, okay, if I close this
19:50:53terminal also, still my application will
19:50:55be working.
19:50:57Okay, see still my application is
19:50:58working. Okay. So now if you want to uh
19:51:02let's let's say delete this instance
19:51:04first of all you have to select it. Then
19:51:06there is a option called instance state
19:51:09and there you will see called terminate
19:51:10and delete instance. Okay. So if you do
19:51:12terminate and delete it will delete uh
19:51:14everything. Okay. But if you stop it it
19:51:16will stop again. You can restart it but
19:51:18I'm going to delete everything because
19:51:19my learning is over. Uh I'm going to
19:51:21terminate and delete. Now after some
19:51:24time it will be uh deleted. Okay. Now
19:51:26you have to delete your IM user as well.
19:51:30So let's go to the IM user. Left hand
19:51:32side IM user is available. Select the IM
19:51:35user and delete it from here. Deactive
19:51:37the keys and just write confirm.
19:51:41So it will be deleted.
19:51:46Okay. If you want you can also delete
19:51:48your uh docker image you have uploaded
19:51:50in your hub. Okay. This is also
19:51:52possible. You can also delete here. But
19:51:53I'll keep this uh uh image. Okay. in my
19:51:56docker repository so that later on I can
19:51:59use it anytime. Okay. So yes guys that's
19:52:01how we can do the CI/CD deployment and
19:52:03we have completed our deployment. Okay.
Deploy Agentic AI Chatbot on Render for FREE with Docker
19:52:05So right now you can see our application
19:52:07will not run because I have deleted all
19:52:09the instance and this is offline right
19:52:11now.
19:52:15So see this is offline right now. Okay.
19:52:17So yeah you can try I will share all the
19:52:19resources all the code in my
19:52:20description. From there you can try and
19:52:22please try to support my channel guys.
19:52:24If you support me definitely I will
19:52:25bring this kinds of content more in
19:52:27future. So yes uh this is all about for
19:52:30this uh deployment I have showed you on
19:52:32the uh AWS cloud. Now in the next video
19:52:34I'm going to show you how we can deploy
19:52:36this project over the render cloud.
19:52:37Okay, render is another cloud there you
19:52:40can also uh deploy this project as a
19:52:42CI/CD. So what is render? Render is a
19:52:44cloud platform. So there you can deploy
19:52:46any kinds of web application. Okay. uh
19:52:49this is the like a very fastest uh and
19:52:53uh very easy to use cloud platform. So
19:52:55here you don't need to do so many
19:52:57configuration. Okay. Uh with some few
19:52:59clicks actually you can do the
19:53:00deployment. I'm going to show you okay
19:53:02how to do that and um definitely for
19:53:04this you have to create one account on
19:53:06render and render is not completely free
19:53:08but they have a free instance. In that
19:53:10free instance you can at least deploy
19:53:12some application. Okay. But if you want
19:53:14to do the production grade deployment
19:53:16okay with some uh higher infrastructure
19:53:19and higher instance that time you have
19:53:21to take the subscription. Okay. But I
19:53:23think uh uh this is fine um as a
19:53:25learning purpose and uh just to uh just
19:53:28to actually live our app okay just to
19:53:31test our app we'll be using the free
19:53:32instance. So free instance is having
19:53:34like very low configuration like machine
19:53:37and I think this is completely fine for
19:53:39us so we can manage that. Okay. So if
19:53:42you found my content useful guys please
19:53:44do uh try to subscribe to my channel and
19:53:46please try to share and please try to
19:53:48hit the like. uh I need your support if
19:53:50you provide the support guys so I can
19:53:52bring this kinds of content more in
19:53:54future. So uh well let's start with the
19:53:56deployment guys. First of all here you
19:53:58have to create an account. If you don't
19:53:59have account guys please try to create
19:54:01an account with your Google um uh Google
19:54:03address. You can create your account. So
19:54:05I already have the account. I'll just
19:54:06try to sign in.
19:54:10So here I'll just try to sign in with my
19:54:12Google.
19:54:15So after sign in guys you will be able
19:54:17to see this kinds of interface. So this
19:54:19is the rendered dashboard and previously
19:54:21I deployed some app that's why it's
19:54:23coming okay like that but for you it
19:54:25would be completely empty. So here uh
19:54:27what I have to do guys uh first of all I
19:54:30have to uh I have to actually commit my
19:54:33code to the GitHub. Okay. And uh in my
19:54:35previous deployment video I already
19:54:37pushed this code in my GitHub. So this
19:54:39is already available in my GitHub repo.
19:54:41As you can see this is the repository we
19:54:42created aentic chatbot using langraph.
19:54:45So we can utilize that and one best part
19:54:47is that if you're using render so render
19:54:50uh it is already having the CI/CD
19:54:52integrated you don't need to set up the
19:54:54CI/CD separately okay like we did in on
19:54:57AWS right here CI/CD uh it is included
19:55:00okay only you just need to connect your
19:55:03repository and automatically this CI/CD
19:55:07uh pipeline would be created you don't
19:55:08need to manually create that that part
19:55:10I'm going to show you so first of all um
19:55:12here just try to copy this URL Okay,
19:55:15copy your GitHub URL and in on render
19:55:18you will see one option called new.
19:55:20Okay, just click on new and here is a
19:55:22service called web service. Okay, just
19:55:23click on web service
19:55:26and uh here you can see G provider is
19:55:28available. Okay, just try to paste your
19:55:30URL. Okay, or you can go to this public
19:55:34uh g repository and you can provide the
19:55:36URL. Okay, and if you want you can also
19:55:38pass your existing let's say docker
19:55:40image. So I think you remember uh in my
19:55:42last video I like pushed my uh docker
19:55:45image in my docker hub. So you can also
19:55:47provide that image URL that uh and with
19:55:50the help of that you can also perform
19:55:51the deployment. You can also use your
19:55:53GitHub to do the deployment. Okay. But
19:55:55make sure you have this docker file
19:55:56here. So I already have the docker file
19:55:58and pre uh in my last video I already
19:56:00created this docker file. So docker file
19:56:02should be available. Okay. So we have
19:56:04the docker file. It's completely fine.
19:56:05Now simply what I'm going to do I'm
19:56:08going to just paste this URL here and
19:56:10I'll just connect this repository. Okay,
19:56:13once you have connected, you can provide
19:56:15the name the name you want to provide uh
19:56:17for this deployment. But I will keep the
19:56:19same name and the language you have to
19:56:21select the docker. Okay, if you don't
19:56:23have the docker, you can also select the
19:56:24simple python. But I have the docker.
19:56:26I'll try to select the docker. Okay,
19:56:28language. Then everything will remain
19:56:30same as it is. No need to change
19:56:31anything. And here in the instance type,
19:56:33see they have some plan. You can take
19:56:36the plan as per your requirement. If you
19:56:38have let's say very high configuration
19:56:41project that needs lots of computation
19:56:42that time you can take these are the
19:56:44like uh plan but uh we'll be using this
19:56:47u free plan for the hobby project. Okay
19:56:50just to show you I'm using this free
19:56:52plan and it is having 512 MB RAM and uh
19:56:560.1 CPU core. Okay, it is uh it would be
19:56:59a little bit slow lagging but uh just to
19:57:01I mean make our project live it's
19:57:03completely fine because nowadays none of
19:57:05the cloud provides the free uh free
19:57:07let's say instance right to uh do the
19:57:10deployment but at least they're
19:57:11providing I think this is fine for us
19:57:12right so I'll select this free instance
19:57:14then here you have to set all of your
19:57:16environment variable uh you have inside
19:57:18your project so I think remember inside
19:57:20our project these are the environment
19:57:21variable is required so try to set one
19:57:23by one so uh I'm not using openi so I
19:57:27will not set the open I'll select set
19:57:30from tably
19:57:31so tably API key here you have to give
19:57:33the value
19:57:40okay then the next one you have
19:57:44this open weather API key
19:57:52that's how I'll try to add all of the
19:57:54environment variable I have here you can
19:57:55also upload your NV file that will also
19:57:58load but let's try to add like that
19:58:02Google API key because I'm using Gemini
19:58:05model.
19:58:14Now next I have this languid tracing
19:58:28Smith endpoint
19:58:40then uh Langmith API
19:58:53then we have Langmith project.
19:59:03So yeah, all of the API key has set
19:59:05successfully. Now uh in adv advanc part,
19:59:09you don't need to do anything. uh just
19:59:10keep it same as it is. Now let's try to
19:59:13deploy our web service.
19:59:18Okay. Now it will start building your
19:59:20docker. Okay. Uh all of the setup
19:59:23everything will uh uh going on here.
19:59:29So we have to wait for some times. Okay.
19:59:31So this will set up and prepare
19:59:33everything and once this starter should
19:59:35be live, you'll be able to access your
19:59:36application.
19:59:39Now let's wait guys. So what I'm going
19:59:41to do, I'm going to pause the video once
19:59:43this u um docker building is complete
19:59:46then I will come back.
19:59:59So as you can see guys our application
20:00:01is live right now and all of the um
20:00:04setup has complete successfully. Now we
20:00:06can access this application. So this is
20:00:08the URL. Just try to copy this URL and
20:00:11open in a new tab. So you'll be able to
20:00:13see that your application will open.
20:00:22Yeah. So it has loaded my application.
20:00:25So this is our agentic chatbot. Now
20:00:28let's test this chatbot. Uh let me zoom
20:00:31out so that you can see the entire
20:00:32screen. Yeah. So now let's uh test this
20:00:35chatbot. So here I will give hi.
20:00:41So see it's giving you hello I can
20:00:43assist you. Now I'll tell um what is the
20:00:50current weather
20:00:55in
20:00:57Bengaluru.
20:01:04So this is the current weather in
20:01:06Bengaluru. Now I will ask
20:01:09tell me
20:01:12the latest
20:01:17score of
20:01:20FIFA. Okay. Today.
20:01:30Yeah. So this is the score it has given.
20:01:33Now you can um you can check about this
20:01:37um stock price. What is the
20:01:42stock
20:01:45price of Google?
20:01:58Okay. So the API I was using uh so the
20:02:01rate rate limit has been uh over. Okay.
20:02:04So I have to create another API key.
20:02:06It's completely fine. Now let me test uh
20:02:08with my documents upload. So I'll just
20:02:11try to
20:02:13provide my resume and ask who is
20:02:18Btier Ahmed
20:02:21Bi
20:02:24based on the
20:02:26PDF uploaded.
20:02:36Now it is giving you the entire uh
20:02:38answer about me, right? So yeah uh it's
20:02:41working perfectly. So only the issue we
20:02:42found uh our uh API key we're using
20:02:45right for this stock price uh this has
20:02:47been I think limit is over. So I have to
20:02:49create an uh another API key and I have
20:02:51to set there uh because we are using the
20:02:53free one right and free one definitely
20:02:55has some limitation that's completely
20:02:57fine. Yeah. So it's working fine. Then
20:02:58you can also create a new trades. Okay.
20:03:01You can create a new trades and you can
20:03:03uh again do the conversation. Let's say
20:03:04hi I am Alex. Okay. See everything is
20:03:08working fine. Okay. Now this application
20:03:10is completely live. You can share this
20:03:12with your friends and family. They will
20:03:14be able to access your application and
20:03:17uh this will not uh charge you. Okay.
20:03:19Because this is running completely on
20:03:21the free instance and uh that's how you
20:03:23can deploy any kinds of project. Okay.
20:03:25Uh just for the uh testing purpose.
20:03:28Okay. But if you want to do the
20:03:29production grade deployment that time
20:03:30just try to make sure you are taking the
20:03:32subscription plan. Now guys uh one best
20:03:35part uh I will show you uh which is this
20:03:37uh CI/CD. Okay. Uh that means if you are
20:03:40changing something inside your code and
20:03:42if you are again committing to the
20:03:44GitHub, so what will happen? So let's
20:03:46say right now uh here I have an emoji.
20:03:49Okay. So I want to remove this emoji. Uh
20:03:51as of now let's try to consider this is
20:03:53our features. Okay. We are adding inside
20:03:54this chatbot. Uh where
20:03:58is that part? Yeah. So here so let's say
20:04:00I will delete this uh emoji. Okay. And I
20:04:03will uh again push my changes to the
20:04:06GitHub. So let's say app file updated.
20:04:13Now I'll push the changes.
20:04:17Done. Now if I go to my GitHub,
20:04:22see this comet is over. Okay. Um have
20:04:25file added. Uh now here if I come to
20:04:28this uh uh I mean render and if I go to
20:04:32this event. So you have to go to this
20:04:34event and there is a option called
20:04:36manual deploy. Just try to click here.
20:04:39Okay. And there is a option called
20:04:40deploy last commit. Okay. So you can
20:04:43also like make it as automated. There is
20:04:45a setting you can turn on that. Uh but
20:04:48if you just click here deploy latest
20:04:50commit. Now if I let's say deploy latest
20:04:52commit.
20:04:57So you'll see that uh automatically um
20:05:00my new features should be added.
20:05:04See still my application is running.
20:05:12See still my application is running and
20:05:14my deployment is going on. Okay. So
20:05:17that's how they have integrated this
20:05:18inbuilt CI/CD uh and all of this. Okay.
20:05:21Whatever we have learned in my previous
20:05:23deployment. So here uh you don't need uh
20:05:25that much of configuration only few
20:05:27clicks you can do the deployment. Okay.
20:05:29So this is the best part uh on this
20:05:31render cloud. Uh let's see.
20:05:41So see our application is live. Now if I
20:05:43go to my application refresh.
20:05:51So see this emoji got removed. Okay. So
20:05:54that's how uh we can add uh our new
20:05:56features. uh and you just need to commit
20:05:58the code on GitHub and you can uh just
20:06:00uh trigger that pipeline. Okay. And you
20:06:02can also make it automated. There is a
20:06:04settings you can run on. So yes guys uh
20:06:06that's how we can do the deployment. Now
20:06:07I'll show you how we can delete the
20:06:09instance. Okay. Let's say this project I
20:06:11have deployed. Now how we can delete
20:06:12this instance. Okay. So for this you
20:06:14just need to go to the settings
20:06:17and go below there is a option called
20:06:20delete web service and you have to copy
20:06:22this command
20:06:26and give it here and delete the web
Project: Build Your Own ChatGPT Agent with LLMs, LangGraph, FastAPI, LangSmith, ChromaDB, SQLAlchemy & AWS
20:06:28service. Okay. So if you delete it so
20:06:30this service would be deleted and your
20:06:31application would be offline. Okay. So
20:06:34yeah that's how we can do that. So if
20:06:35you found my content useful guys please
20:06:37try to support me and this is my
20:06:40LinkedIn profile. Uh if you want to
20:06:41connect me guys, you can connect on my
20:06:43LinkedIn. You can follow me on LinkedIn
20:06:45and uh please let me know how you are
20:06:47enjoying this uh complete list. If you
20:06:49found this useful, so please try to tag
20:06:51me on LinkedIn. Okay, I'll happy to see
20:06:53that and just try to implement uh
20:06:55something from your end and please try
20:06:56to tag me. So if you are tagging me on
20:06:58LinkedIn, I would be happy to see your
20:07:00work and definitely I will put my uh
20:07:02feedback and comments. Okay. So guys, as
20:07:04you know, I started a complete agenti
20:07:07playlist on my YouTube channel and uh I
20:07:11completed our first orchestration
20:07:12framework which is langraph. So we have
20:07:15studied uh about this langraph in depth.
20:07:18We have seen each and every component of
20:07:20langraph. Even I showed you one amazing
20:07:23uh end toend project implementation
20:07:25which is one agentic chatbot. If you
20:07:28haven't uh checked those uh videos guys,
20:07:30this is already available in my playlist
20:07:33guys. It is already available on my
20:07:34YouTube channel uh DS with BP. So all
20:07:37the recordings are available uh you can
20:07:40go through all of these recording. Okay.
20:07:42Uh then I told you uh after completing
20:07:45like our uh first orchestration
20:07:47framework we'll be implementing some
20:07:49amazing project. Okay. And one project
20:07:51we have already developed in this uh
20:07:53playlist itself. Okay. So as you can see
20:07:55uh our first project was around uh uh 8
20:07:59plus hours of recording. uh we have uh
20:08:02implemented the entire agentic chartbot
20:08:04with the help of lang graph database
20:08:06languid tools rag hittl AWS and render.
20:08:10So guys uh in this video what I'm going
20:08:12to do uh I'm going to utilize the same
20:08:15concept we have learned so far inside
20:08:17our agenti playlist and we'll be
20:08:20implementing one very interesting and
20:08:22amazing project in this video. Okay. And
20:08:25in this video, we are not only going to
20:08:27develop this project. Uh we'll also show
20:08:29you how we can uh deploy this project
20:08:32over the cloud platform as a CI/CD.
20:08:34Okay. That means first of all, we'll try
20:08:36to implement the entire project uh
20:08:38completely end to end. Then after
20:08:40implementing, I will also show you how
20:08:42we can deploy this project and we'll be
20:08:44using CI/CD pipeline for that. So the
20:08:46project name is BPGpt.
20:08:49So [gasps] this sounds uh seems to be
20:08:51funny but uh yes actually I'm going to
20:08:53implement uh one uh project here called
20:08:57buppy GPT and this would be kinds of
20:09:00your chart GPT. So basically we'll try
20:09:02to recreate this chat GPT okay uh with
20:09:05our own workflow. So I think you have
20:09:08already used chat GPT right uh chat GPT
20:09:11uh it's an agentic AI chatbot. So here
20:09:14you can perform the chat operation you
20:09:16can upload your documents. Okay. Then
20:09:18you can also activate the voice mode.
20:09:21Then um you can see the conversation
20:09:24trades. Okay. Then it has also connected
20:09:26with different different tools like you
20:09:28can perform realtime source operation.
20:09:30You can uh solve complex math problem.
20:09:33You can generate the codes. Okay. Each
20:09:35and everything you can do here. So yes
20:09:37uh in this video guys we'll be
20:09:39developing our own chat GPT. So I
20:09:42already named it as BPGT. So let me uh
20:09:45show you first of all the application
20:09:46demo how this application uh will work
20:09:49and how this application uh will look
20:09:51like. Then after that we'll start the
20:09:53development guys. So as you can see guys
20:09:55uh this is the application we'll be
20:09:57developing named buppy GPT. You can give
20:09:59any name okay as per your needs. I have
20:10:02given buppy GPT and I think first time
20:10:05someone is creating uh chat GPT with the
20:10:08Gemini model.
20:10:10[laughter] Why I I have used Gemini
20:10:12model because uh I wanted to use free
20:10:15resources. Um I I didn't wanted to use
20:10:18the paid one. Uh I could have used the
20:10:20open AI model here. But for openi model
20:10:23you need open subscription but uh there
20:10:26are many learners they don't have the
20:10:27open key that's why I thought let's try
20:10:29to integrate any free model. Okay, open
20:10:32source model and uh Gemini actually you
20:10:34can use freely. Okay, there are some
20:10:36free limits you can utilize that. But if
20:10:39you want you can also integrate any
20:10:40other model. You can also integrate
20:10:41OpenAI model. It's completely up to you.
20:10:43Okay. But the main things here we have
20:10:45to learn this uh concept like um the way
20:10:48they have created the chart GPT. Okay.
20:10:50You can see all the functionality like
20:10:52tradings the documents uploaded this
20:10:55model selection. Okay. Then uh you can
20:10:57also uh open this V voice mode. You can
20:11:00uh uh give your voice and automatically
20:11:02your voice would be recognized and you
20:11:04can perform the chat operation here.
20:11:06Okay. And it has also connected with
20:11:08different different tools. But here I
20:11:09tried to integrate u actually few tools
20:11:12here um uh because um here I want to uh
20:11:16show you okay uh this uh project
20:11:18implementation. So you can add as much
20:11:21as tool you can okay you can add all
20:11:23kinds of tool. I already um told you
20:11:25about the tool in my playlist. I think
20:11:27you remember right if you go through the
20:11:28playlist I already discussed about the
20:11:30tool. So you can uh integrate as much as
20:11:32tool you can okay whatever tool you need
20:11:34but I added few tools here just to show
20:11:36you the working demo. Now first of all
20:11:39uh let me show you the working demo how
20:11:40this will work and one thing guys I
20:11:42think you have seen uh in charge GPT you
20:11:44can also create the account you can
20:11:45login with different account okay this
20:11:47is a full fully stack application but
20:11:49here we avoided this part we didn't
20:11:52added any kinds of account fun u I mean
20:11:54login functionality here we just uh
20:11:56created the interface okay of the charge
20:11:58apt I think this is fine uh for learning
20:12:00purpose this is completely fine if you
20:12:02want you can also uh use full stack uh
20:12:04let's say framework you can also create
20:12:06uh this kinds of account functionality
20:12:08and all. Okay, this is completely up to
20:12:09you. So yes guys this is the interface
20:12:11as you can see it has the trading
20:12:13features that means you can switch
20:12:14between any of the trades and and you
20:12:16can see the older conversation you have
20:12:17done even you can also create a new
20:12:19conversation you can upload any kinds of
20:12:21documents you can select your model okay
20:12:24then you can also activate the voice
20:12:25mode uh if you want to speak with your
20:12:29chat u GPT okay and here I have also
20:12:32given some suggestion you can also see
20:12:34that okay I think you can't see uh the
20:12:37interface because of my video so what I
20:12:39can do I and turn off my video. Now I
20:12:41think you can see the full uh
20:12:43application. So here is the voice mode
20:12:44and everything, right? So guys, now
20:12:46let's uh test our BPGPT. Okay. Uh I'll
20:12:50provide some prompt. Let's say first of
20:12:51all I'll tell hi
20:12:57um I am
20:13:00BP here.
20:13:04So as you can see it is giving hello BY.
20:13:06It's nice to meet you. How I can assist
20:13:07you today? So tell tell me about
20:13:13gradient
20:13:15descent
20:13:16in simpler
20:13:21word.
20:13:33Now it is telling you about gradient
20:13:35descent. Now I will ask something um
20:13:38something about latest information.
20:13:43So I will give this prompt. What was the
20:13:45score today for Argentina in FIFA World
20:13:47Cup? So let's see. Now you can see it is
20:13:50using realtime web search tool and it
20:13:54will find out the latest information.
20:14:00So you can see based on the website
20:14:01result Argentina defeated uh Austria two
20:14:06by zero in FIFA World Cup match today.
20:14:08Leonel Messi scored both goal making him
20:14:12uh the alltime legend leading scorer in
20:14:16World Cup history. Okay, I think if you
20:14:18have already watched the la last match
20:14:20of Argentina, you'll see that uh um this
20:14:23was happened. Okay, last match. Last
20:14:24match. So yeah, it's working uh fine.
20:14:27You can also switch uh any other model
20:14:28if you want. Okay. Let's say I will take
20:14:30this um pro model. Okay. Now I ask
20:14:34something. Let's say
20:14:36uh I want to do some calculation. Let's
20:14:39say what is the
20:14:42result of
20:14:46so I'll give a complex mathematics here.
20:14:59Now you can see it is using calculated
20:15:00tool and it will solve that.
20:15:04Now you can see this is the result.
20:15:06Okay. Now here what I can do I can
20:15:08upload any kinds of documents. So let's
20:15:10say here I will upload uh any kinds of
20:15:12documents. Let's say I upload my resume
20:15:16and I can do the conversation here. Now
20:15:19see it's getting uploaded. Now you can
20:15:20see you can ask the question about the
20:15:22document and I'll tell
20:15:25uh who is
20:15:31Bier
20:15:36Ahmed Baki
20:15:38based on PDF.
20:15:41Now you can see it is using document
20:15:43search tool and uh this will use my
20:15:46document to give the response. So this
20:15:48is the rag features you have in this
20:15:51kinds of agenti chatbot. Now you can see
20:15:53based on the provided PDF Ber Ahmed B is
20:15:57a data scientist with five years of
20:15:59working experience specializing
20:16:00generative AI. Okay. And it he is um and
20:16:05you can see it is telling each and
20:16:06everything about me. Okay. Now you can
20:16:08also continue the conversation. Uh
20:16:12how
20:16:13many
20:16:15projects he
20:16:17has done?
20:16:20Give me
20:16:25all the name.
20:16:33Okay. Okay, you can see based on the
20:16:34documents uh BP uh has worked with uh uh
20:16:39worked on four main project as you can
20:16:41see these are the project actually I
20:16:43have mentioned in that resume okay
20:16:46amazing it's working great now you can
20:16:48uh see it has also voice mode I can also
20:16:50activate the voice mode and I can um ask
20:16:53something let's say
20:16:57tell me about Python programming and
20:16:59give me the hello world program.
20:17:03See tell me about Python programming and
20:17:05give me the hello world program. Now if
20:17:06I send this prompt
20:17:17see it's giving you the entire response
20:17:20okay with the hello world program as
20:17:22well. Okay. So yes uh that's how guys uh
20:17:25chart GPT works. Uh even in charge GPT
20:17:28also you can give this kinds of prompt
20:17:29and it will be working. But yes u charg
20:17:33is like a very u very actually advanced
20:17:36uh agentic application because u inside
20:17:39that they have added so many
20:17:41functionality okay deep resource and all
20:17:43but again yeah we have just tried to
20:17:46create recreated that um application
20:17:48here okay by focusing on some major
20:17:51component okay whatever we have learned
20:17:54so far I think this is very much
20:17:55interesting okay if you want you can
20:17:57also upgrade uh this project as per your
20:18:00requirement
20:18:01And you can add uh new new features like
20:18:03chart GP okay if you want and uh going
20:18:06forward I'm also going to create some
20:18:08other project as well uh so that you
20:18:10will be learning some more concept okay
20:18:12so yes guys this is the entire demo of
20:18:14the application we have seen and
20:18:16throughout the entire implementation
20:18:17guys we'll try to uh recreate uh this uh
20:18:21application okay I think this would be
20:18:23fun so make sure you watch this video
20:18:24till the end and uh if you found my
20:18:27content useful please try to subscribe
20:18:28to my channel and uh share this video
20:18:30with your friends and family. Now I'm
20:18:32also going to show you the memory
20:18:34features. Uh I also educated the memory
20:18:36here. That means it can remember my
20:18:39previous conversation. So I think you
20:18:40remember uh at the very first I told uh
20:18:43yes uh my name is BP. Okay. Like hi I'm
20:18:46Buppy here. So let's see whether it is
20:18:48able to remember my name or not. So what
20:18:51is my name?
20:19:01So as you can see you introduced
20:19:02yourself as a buppy earlier is it
20:19:04correct? Yes.
20:19:10Okay. Now uh I will remember that uh
20:19:13it's nice to chat with you. That means
20:19:15it has also long-term memory
20:19:17integration. If you uh want your chatbot
20:19:19to remember something, it will remember.
20:19:21Okay. This will save that information in
20:19:23the long-term u memory. Okay. uh this
20:19:26thing will also try to add with a
20:19:27database. So yes guys uh that's how uh
20:19:30you can implement this uh this amazing u
20:19:34agenti chatbot uh named bgptt or you can
20:19:37give any kinds of name if you want like
20:19:39chat gpt and if you go to the homepage
20:19:41here also you can um directly give
20:19:44something let's say I'll give u search
20:19:46the latest uh so if you click here uh it
20:19:48will automatically come search the web
20:19:50uh for latest EI news okay so you can
20:19:54directly send this prompt
20:20:03Okay, that's how I added some prompt
20:20:05here. Summarize the uploaded documents.
20:20:07Save something to the memory. Use
20:20:09calculated tool. Okay, if you want, you
20:20:10can also give some more suggestion here.
20:20:12Okay, it's completely up to you. So
20:20:15guys, now we'll start the development of
20:20:17BGPT. uh before starting the development
20:20:20first of all I want to show you the
20:20:22highle um architecture diagram like what
20:20:24are the component we'll be implementing
20:20:27in this um uh in this project so as you
20:20:30have seen u this has already one front
20:20:33end server um it is running on basically
20:20:36um HTML CSS and JavaScript so the entire
20:20:41front end you can see right I have
20:20:43created with the help of HTML CSS and
20:20:45JavaScript uh if you want you can also
20:20:47use any front- end framework like NexJS,
20:20:50React, okay, it's completely up to you.
20:20:52But again, if you don't know about
20:20:53front- end development, it's completely
20:20:55fine. There would be a separate team for
20:20:56that. They will try to design this front
20:20:58end. But okay, for you and if you don't
20:21:00know about HTML, CSS, Javcape, don't
20:21:02worry. This thing you can easily
20:21:03generate from uh chat GPT even you can
20:21:06also generate from puppy GPT if you
20:21:08want. Um so you just try to ask I need
20:21:10this kinds of interface it will create
20:21:12you can use that readym made template
20:21:13and you can uh edit okay uh as per your
20:21:16requirement uh but chart GPT actually
20:21:19they're using some kinds of front- end
20:21:21framework uh for this kinds of user
20:21:23interface so every application has this
20:21:26kinds of front- end server okay then it
20:21:29is connected uh with a backend uh server
20:21:32and the backend framework wise we're use
20:21:35we'll be using here fast API that means
20:21:37the application we have created it is
20:21:38running on fast API. Okay. And fast API
20:21:41is a production ready uh backend
20:21:43framework you can use. Uh we'll be also
20:21:46using fast API here. Okay. We'll try to
20:21:48handle all of the get request, post
20:21:50request, everything with the help of
20:21:51fast API. Charg also running on some
20:21:53kinds of u backend server. Okay. Maybe
20:21:57they have used fast API. We don't know
20:21:59that. Then uh you can see uh this
20:22:02backend server is connected with a
20:22:04workflow. Okay. That means some agentic
20:22:06workflow. So here we'll be using
20:22:08langraph to implement this entire
20:22:10workflow. Um I think charg they might be
20:22:14using any other agentic framework. Okay.
20:22:17Um I don't know which framework they're
20:22:19using but here we'll be using this
20:22:21langraph because we have completed lang
20:22:23graph so far inside our playlist. Okay.
20:22:24We'll try to use the langraph for the
20:22:27entire aentic workflow. Okay. We'll try
20:22:29to create our entire agents. Um we'll
20:22:32try to create the nodes. We'll try to
20:22:33create the tools. Okay. each and
20:22:34everything we'll try to create with the
20:22:36help of edge uh lang graph. Then this uh
20:22:39workflow will be connected with lots of
20:22:41tools okay like uh we'll be using some
20:22:45separate tools we'll be using rag tools
20:22:47okay for document search we'll be using
20:22:49memory tools as you saw it has also
20:22:52remembered okay my conversation even you
20:22:54can also retrieve the old conversation
20:22:56how it is happening with help of memory
20:22:57tools then some external uh API tools
20:23:00will be using like web search tool okay
20:23:03um then uh if you want you can also
20:23:05integate uh current weather informations
20:23:07okay it's and everything you can
20:23:08integrate here. then it will have one
20:23:10node tools uh tools node then uh it has
20:23:14also database connection that means uh
20:23:16for the I think if you have already
20:23:18understood about this uh langraph it has
20:23:20a concept of state okay the state uh uh
20:23:23checkpointter saving we have to use some
20:23:25kinds of database and here we'll be
20:23:26using SQLite database okay for this
20:23:28state tracking and uh for long-term
20:23:32uh long-term conversation storage we'll
20:23:34be using SQL uh alchemy okay uh this
20:23:37will store basically my um um like
20:23:40long-term conversation in that
20:23:42particular database and whatever state
20:23:45information we are having we'll try to
20:23:46save inside this scale database and for
20:23:49rag pipeline guys we'll be using chromb
20:23:51vector database and we'll try to
20:23:53generate the vector embeddings and here
20:23:55we have used gemini embeddings uh
20:23:57because gemini is free to use uh you can
20:23:59also use any other embedding model it's
20:24:00up to you okay with the help of Gemini
20:24:02embeddings we'll try to generate the
20:24:04embeddings and we'll store in the chrom
20:24:06and it's it's not necessary to use the
20:24:07chrom if you want you can also use fires
20:24:10pine cone but pine cone is a paid one
20:24:12you have to take the subscription then
20:24:13you will be able to use that then web
20:24:15also wit is also there it is also like a
20:24:18paid one so in this project I tried to
20:24:21use all the services as free okay that's
20:24:22why I'm using chromb okay chrom is in
20:24:25storage vector database that you can
20:24:27store all of your vectors then some
20:24:29external APIs we'll be using like tab
20:24:31API okay then Google gemini API for the
20:24:33lm and embeddings and if you want you
20:24:35can also integrate any other API as well
20:24:37here Okay. So yes, this is the highle
20:24:40architecture of this um BPGT. Now we'll
20:24:44try to follow this architecture. We'll
20:24:46try to develop each and every component
20:24:48in detail. So first of all uh we'll be
20:24:51creating a GitHub repository for this
20:24:53project. Uh so here I will open up my
20:24:55GitHub.
20:24:57Let's create a new repository here.
20:25:01I'll create a new repository.
20:25:04Um, I'm going to name it as uh
20:25:07Buppy
20:25:11GPT.
20:25:16Buppy GPT
20:25:19then uh here I will make it as public
20:25:23repo and add the readmi file. I'll also
20:25:28add the git ignore and here we'll be
20:25:30using python and license. You can take
20:25:33any license. I'll take this Apache
20:25:34license. Okay. Now let's create the
20:25:36repository here.
20:25:42Okay. Once you have created uh this
20:25:44repository, now just click on code, copy
20:25:47this link. Make sure you copy the HTTP
20:25:49link and uh open up your local folder.
20:25:51And here let's try to clone that.
20:25:56So get clone
20:26:04paste the URL.
20:26:07Okay. So cloning is complete. Now I'll
20:26:09go inside that. So cd b gpt. Okay. Now
20:26:13I'm inside this folder and here I'm
20:26:16going to open up my um I'm going to open
20:26:19up my uh VS code. So let's open up my VS
20:26:24code.
20:26:27So this is my VS code.
20:26:30Let me zoom
20:26:32everything is fine. Yeah. So here the
20:26:35first thing guys uh what I have to do I
20:26:37have to create a virtual environment and
20:26:40uh after creating we have to um install
20:26:44some of the library for this project
20:26:46then we'll be creating the folder stack
20:26:47set. So let's do it uh quickly and uh if
20:26:51you are uh implementing this project
20:26:53guys um I have implemented uh a similar
20:26:57kinds of agentic chatbot in my previous
20:26:59project. Uh if you go through that
20:27:01recording uh all of the concept I
20:27:03explained in detail like tools rag okay
20:27:06then um memory each and everything I
20:27:10explain in detail. So if you are
20:27:12completing that uh video it would be
20:27:14easy for you to implement this project.
20:27:16Okay, if you're completely new but if
20:27:18you already watch that video, if you
20:27:20already know these are the concept then
20:27:21it will be easy for you. So here I'm not
20:27:23going to focus on the theoretical
20:27:25explanation. Instead of that I'm more
20:27:27going to focus on the practical
20:27:28development because I'm expecting you
20:27:30are already familiar with those concept.
20:27:32Okay. So yeah make sure if you
20:27:34[clears throat] are completely new go
20:27:35through that uh previous recording.
20:27:36Okay. I have on my playlist.
20:27:39Now
20:27:40>> [gasps]
20:27:40>> uh here the first thing we'll be
20:27:41creating the
20:27:44um creating the
20:27:48environment.
20:27:50So let's create the environment. So how
20:27:52to
20:27:56run
20:27:58BPG?
20:28:10Yeah. First of all, you have to clone
20:28:12the repository.
20:28:30Okay. Then after that you have to create
20:28:33the environment.
20:28:40Yeah. So you have to navigate the
20:28:41project directory first. Then you have
20:28:43to create the environment.
20:28:46So all of this step I'm writing so that
20:28:47it would be easy for you uh to set up
20:28:50okay later on
20:28:54create virtual environment.
20:28:59So to create environment you need to run
20:29:01this command. So ponda
20:29:04create
20:29:06hyphen n bgptt python is equal to we'll
20:29:08be using python 3.11 and hyphen y we're
20:29:11giving the yes permission. Then once
20:29:13involvement is created, we have to
20:29:15activate the environment
20:29:18then we have to install the
20:29:20requirements.
20:29:23Okay, once requirement installation done
20:29:25then you'll be running the app.py.
20:29:29Okay, app.py should be our endpoint
20:29:31here. So now let's uh refer this uh file
20:29:36and install everything one by one. Okay.
20:29:38So, first of all, we have already inside
20:29:41my bgptt folder and I'll create the
20:29:42environment here. So, I'll copy this
20:29:44command. Open up my terminal.
20:29:51Let's create the environment.
20:30:02Then we we have to activate that. This
20:30:04is the command.
20:30:13Okay, activation is complete. Now here
20:30:16uh we have to add a requirement file
20:30:25requirement.txt file inside that we'll
20:30:28be mentioning all of the requirement we
20:30:29need here.
20:30:32So I already prepared all of the
20:30:34requirement guys.
20:30:36with the specific version I will be
20:30:38installing here. See these are the
20:30:40requirement I need for this project. I
20:30:42need fast API for the backend server and
20:30:45to run the fast API you need uon then
20:30:47ginga okay and then python multipart. So
20:30:50these are the dependency of fast api
20:30:52then python.enb I need for environment
20:30:55management that means uh whatever api
20:30:57I'm going to mention I'm going to
20:30:58mention inside this dot env file.
20:31:04Okay.
20:31:05Then uh I'll be installing the
20:31:09orchestration framework like lang chain.
20:31:11Then we'll be using gemini model. For
20:31:13this you have to install this langen
20:31:15google ji. Then lang chain core. Then
20:31:18we'll be in uh using lang graph
20:31:19orchestration framework for this agent
20:31:21workflow. Then langent text splitter. I
20:31:23need uh I will be integrating feature
20:31:26rag feature. And to parse our documents
20:31:29we need that. Then lang graph checkp
20:31:30pointer skqli. That means uh to save
20:31:33this uh persistence memory I need SQLite
20:31:36um saber. Okay. Then langent chroma I
20:31:39need uh because for vector database I'll
20:31:41be using chromb. Then chromad you have
20:31:43to install pi pdf. Here we'll be only
20:31:46considering the pdf document. But if you
20:31:48want you can also use uh like docs file.
20:31:51You can also use excel file. Okay. This
20:31:53part you can add simply go to the length
20:31:55documentation. You will able to see
20:31:56that. Then langent tab. So internet
20:31:59search operation will be using tably
20:32:00search. Okay. Then tab python. This is
20:32:03the dependency for langent tab and SQL
20:32:06um alchemy we'll be using for this uh
20:32:10long-term uh conversation storage. Okay.
20:32:13We'll be creating a database and there
20:32:14we'll try to save everything. Okay. So
20:32:16yes uh these are the requirements I
20:32:18need. Now we have to install this
20:32:19requirement and this is the command for
20:32:21that. Let's copy
20:32:23and uh we'll install everything here.
20:32:49Let's wait. This process may take some
20:32:51time.
20:33:21So in between what I can do I can
20:33:23collect all of the API key I need uh for
20:33:26this development.
20:33:29So here
20:33:32uh what I'm going to do I'm going to
20:33:34first of all collect the uh Gemini API.
20:33:36Okay, this is available inside Google
20:33:39AI studio.
20:33:45Go to the Google AI studio
20:33:52and uh here we'll just click on get
20:33:55started and left hand side you will see
20:33:56this API key.
20:34:00And here you have to create an API key.
20:34:02Okay. So I already have my API key. I'll
20:34:04just copy that. If you don't have you
20:34:06just try to create from here. Okay. So
20:34:08after that you just need to add it here.
20:34:11So this is my Google API key.
20:34:15Okay. This is my Google API key I
20:34:17collected. And don't use my API key
20:34:19guys. I'll be removing after this
20:34:20recording. And once it is done then you
20:34:24have to mention the Google model which
20:34:26model you want you want to use as
20:34:28default. Okay. Let's see if user is not
20:34:30selecting the model that means the by
20:34:33default model I'll be using Gemini 2.5
20:34:35flash model. Okay. And this model has
20:34:37some free access limit you can use that.
20:34:39Okay. So we'll be adding this model. If
20:34:42you want to use any other model you can
20:34:44simply do do that. Okay. You can go to
20:34:45the chat GP. You can ask I want to use
20:34:47this model. What should be the model
20:34:48name? You can use that. Then the next uh
20:34:52API key I need for internet search
20:34:55operation because as you see uh we'll be
20:34:57integrating the tools. Okay. And for
20:34:58real time search operation we need a
20:35:02tool called tably search. So tab search
20:35:04uh needs the API key. So let's collect
20:35:06that API key as well. So here what I'm
20:35:09going to do I'm going to search for
20:35:10tably API key.
20:35:18Okay. Now let's
20:35:22open this.
20:35:26Here you have to login with your
20:35:28account. Let's login with my account.
20:35:33And here you have the API key. Okay. So
20:35:35previously I already created the API
20:35:36key. I'll just try to copy. But if you
20:35:38don't have just create from here. So
20:35:40let's add the table API key here.
20:35:46Table API key. Okay.
20:35:48Yes. Now uh tab is also done. Now what I
20:35:52have done guys uh for this development I
20:35:55also integrated lang here
20:35:59that means I can continuously monitor my
20:36:02chatbot the bub pgbt. Okay we are
20:36:05tracing on langsmith platform. Let's log
20:36:08in my lang. So if you don't have the
20:36:10account just create an account in lang.
20:36:12You can continue with your Google.
20:36:18Okay. So here you can see uh we created
20:36:20a aentic chatbot test.
20:36:23So here uh we are tracing everything.
20:36:25Okay. Whatever chat we have done here it
20:36:28is tracing everything. You can monitor
20:36:30from here. Okay. You can monitor from
20:36:32here. Even you can also see the trades.
20:36:36Okay. You can also see the trades
20:36:38different different trades. Okay.
20:36:39Everything is visible. So we'll be
20:36:42integrating the this lang also uh inside
20:36:44this uh project. So for this you need
20:36:46lang langsmith API key. Okay. So where
20:36:49you will get this API key? It is
20:36:51available in settings API key. Okay. Now
20:36:53just create an API key. So I already
20:36:55created my API key. I'll just try to use
20:36:57that. So for langid tracing guys you
20:36:59need to add this four four variable
20:37:02here.
20:37:08Okay. The first thing langid tracing is
20:37:10equal to would be true. Then lang
20:37:14endpoint um this is the endpoint api
20:37:17smith.langjen.com
20:37:19then lang API key. So this is the API
20:37:21key I have given and here you have to
20:37:23give the project name. So here I'll give
20:37:25let's say
20:37:27bpg
20:37:31bgt. So this is the project. Okay you
20:37:33can give any name. Uh so it will
20:37:35basically create that name here uh that
20:37:38name here and it will trace all of the
20:37:40informations there. Okay. So yeah so
20:37:42these are the API key as of now I need
20:37:44uh for this uh project but if you want
20:37:47you can also use uh any other API key
20:37:49you can use realtime weather uh weather
20:37:52let's say API key to get the weather
20:37:53information you want you can also use
20:37:56any kind of stock price u uh stock price
20:37:59API key if you want to get the latest
20:38:01stock okay of any company. So this thing
20:38:03I have already added inside my previous
20:38:05uh uh chatbot. So this part I want to uh
20:38:09I want to leave it to you. I want you to
20:38:11integrate these are the features okay
20:38:13inside this uh puppy GPT. So just try to
20:38:16add realtime weather information s and
20:38:18uh real time stock price. Okay these are
20:38:20the thing just try to add and for this
20:38:22you can use any any other open open
20:38:24source let's say API provider for that.
20:38:27So yes these are my environment
20:38:29variable. Now let me see my installation
20:38:30is complete or not. Yeah. So,
20:38:31installation is completed. There is no
20:38:33error. Okay. It's completely fine.
20:38:36So, yeah. Now, uh what I'm going to do,
20:38:39I'm going to just push the changes.
20:38:42Okay. So, here you can just write
20:38:45requirement
20:38:50requirements
20:38:52and uh
20:38:57API addit.
20:39:05Now if I go to my GitHub
20:39:08refresh
20:39:10see everything is up to date. Now
20:39:14uh what I have to do guys I have to
20:39:15create the uh folder structure
20:39:18um what whatever folders and file you
20:39:21need I'll just try to create then I'll
20:39:23just uh uh implement all of the
20:39:26component one by one. So now let's uh
20:39:28create the files and folder I need. So
20:39:30first of all I need the files here
20:39:33called
20:39:34agent.py.
20:39:36So here I'm going to write my agent
20:39:39workflow. Then I'll be creating another
20:39:42file called tool.py.
20:39:46So here I will be writing all of the
20:39:48tools. Okay tools functionality. Then I
20:39:51need another one called rag.py.
20:39:55So here I'm going to write all of the um
20:39:58rag related code that means document
20:40:00uploader vector store everything. Then
20:40:02I'm going to create another file called
20:40:04database
20:40:06dopy. So here uh we'll just try to write
20:40:10all of the code related database. Okay,
20:40:12database integration.
20:40:14Then I need um
20:40:18anything else. Okay, I need my endpoint
20:40:20which is app.py. Okay, so this is going
20:40:24to be my endpoint, my first API
20:40:26endpoint. And uh for HTML and CSS, I
20:40:31need a folder called template
20:40:34templates. Okay, inside that I'm going
20:40:37to create a file called index
20:40:41html.
20:40:44Okay, so inside that we'll be writing
20:40:46all of the HTML, CSS, JavaScript related
20:40:48code in a single file. Okay. And if you
20:40:51don't know about HTML is completely
20:40:52fine. Even uh I also took the help from
20:40:55chat GPT to generate my user interface.
20:40:57The user interface you have seen. Okay.
20:40:59This user interface.
20:41:02So yes uh as of now this thing is
20:41:05required
20:41:06and uh if I need anything I'll just try
20:41:08to create later on. Okay. Now you can
20:41:11again commit the changes like folders
20:41:17and
20:41:21Why had it
20:41:34so folders and file added? Okay. Now,
20:41:37first of all, guys, uh what I'm going to
20:41:39do, I'm going to create my agent
20:41:42workflow. So, let's create the agent
20:41:44workflow. I'll just try to close this
20:41:45out the file.
20:41:52So I'll open up my agent.py
20:41:55and here we'll be creating our agent
20:41:57workflow with the help of lang graph. So
20:42:00let's import some necessary library.
20:42:07We'll import all the necessary library
20:42:09and here make sure you select your
20:42:10environment which is this one
20:42:14bpg. Okay. And now this error would be
20:42:17removed. Now here we are importing
20:42:19operating system SQLite uh path from
20:42:22path lib then env because we need to
20:42:25load these environment variable then
20:42:27certify you need uh why certify is
20:42:30required because see sometimes if you're
20:42:32using Windows operating system there
20:42:34would be some kinds of path related
20:42:36error. Okay to prevent that this is the
20:42:39safer code you have to add. Let me show
20:42:42you.
20:42:44So this code you have to add okay
20:42:46west.in environment SSL uh cert file
20:42:50okay uh certified wire and request ca
20:42:53bundle certified. You have to add this
20:42:55two line. So if you're using Windows uh
20:42:57operating system uh you won't be getting
20:43:00the error related path issue. So it uh
20:43:03doesn't happen to all the operating
20:43:04system. Sometimes uh in uh in some
20:43:08operating system it happens. Okay.
20:43:09That's why I added this code just for a
20:43:11safer purpose. That means if you are
20:43:13executing my project in future you won't
20:43:15be having any kinds of problem. But if
20:43:16you're using Linux wind u Mac OS I think
20:43:19this line is not required but still if
20:43:21you keep it will not uh h uh make harm
20:43:24okay in your in your project. So I'll
20:43:26just try to add it to prevent the path
20:43:28issue.
20:43:29Then apart from that I need some other
20:43:32um other libraries as well.
20:43:35Yeah.
20:43:37So these are the library I need
20:43:40and I think all the libraries are common
20:43:42guys. Uh here I don't need to explain
20:43:44these are the library again. Uh we are
20:43:46using this chat Google generate API for
20:43:47this Gemini model initialization system
20:43:50uh message we're importing from lang
20:43:52chain. Then from lang graph we importing
20:43:54state graph start message state. Okay
20:43:56then from pre-built we are importing
20:43:58tools node tools condition. Okay. Then
20:44:01checkpoint we're using uh SQLite saber
20:44:04and from um Okay. Okay. So this line I
20:44:07don't need to write as of now because
20:44:09whatever tools I'm going to write I'm
20:44:11going to import here. Okay. So yes uh
20:44:13these are the like uh import I need as
20:44:15of now. Now what I'm going to do guys
20:44:17first of all I'll just create a
20:44:19directory.
20:44:21Okay. Here I'll just create a directory.
20:44:23So why directory is required? Because uh
20:44:26I think you know that uh this uh
20:44:28langraph will have a state right? Uh so
20:44:31for our uh for our let's say this uh
20:44:35workflow what would be the state okay
20:44:37state should be the message state that
20:44:39means whatever user is giving the input
20:44:41message and my chatbot is replying uh
20:44:45whatever response so this should be my
20:44:46state okay that means uh if I create the
20:44:50workflow so how my workflow will look
20:44:52like let's try to understand
20:44:56so for this I created a demo excalider
20:44:58file and here I just uh uh created the
20:45:02architecture. So this is the
20:45:04architecture guys. So this is my
20:45:06langraph workflow. So here uh it will
20:45:09have a chat node and this will have a
20:45:11tool nodes. Okay. So whatever user will
20:45:13give the message it will go to the chat
20:45:15node and chat node will decide uh so
20:45:17here basically we'll be using something
20:45:19called tool condition. This tool
20:45:20condition will decide whether it has to
20:45:22use any kinds of tool for this question
20:45:24or not. If it doesn't need any kinds of
20:45:26tool, it will directly go to the end
20:45:27node. Otherwise, it will use the tool.
20:45:29Now, it will automatically se select the
20:45:31tools like which tools is required to
20:45:33give the answer and um the response will
20:45:35go to the end node. Okay. So, this is my
20:45:38uh this is my actually
20:45:40uh workflow. Okay. And what should be
20:45:42the state for this workflow?
20:45:46So, this should be the state. Okay. This
20:45:48should be the chart chat state. That
20:45:49means whatever input user is giving and
20:45:52whatever response it is uh generating.
20:45:53Okay. this I we have to add in the chat
20:45:56state. So this should be the state.
20:45:57Okay. So yeah. So if you want to save
20:46:00this state in the uh in the actually
20:46:03physical uh database that time we'll be
20:46:05using SQLite database because if I'm
20:46:07saving uh inside my RAM so if you close
20:46:10your application this would be erased.
20:46:12Okay. But I don't want that. I want uh
20:46:14let's say if I close my application also
20:46:16like chart GP still I'll be able to see
20:46:18all of my chart history and message.
20:46:19Right. So for this we'll be using SQLite
20:46:22um SQLite database and to save the
20:46:24SQLite database we'll be creating a data
20:46:28folder here. Okay. So inside data folder
20:46:30we'll try to create the database SQLite
20:46:31database and we'll try to save all of
20:46:33the checkpoint there. Okay. So for this
20:46:35uh this uh data folder is required.
20:46:39So to create the data folder I'm going
20:46:41to use this code. Uh you can see I'm
20:46:44using path library and inside that I'm
20:46:46giving data data folder and I'm using
20:46:49mkdr command to create the data folder.
20:46:52So first of all it will check whether
20:46:54this data folder is available or not. If
20:46:56available it will not create otherwise
20:46:57it will create. That's why I'm giving
20:46:58this parameter exist. Okay is equal to
20:47:00true. Okay. Yeah. Now uh here we'll just
20:47:04try to define the list of the model uh
20:47:06we want to uh we want to show to the
20:47:09user.
20:47:11Um
20:47:13yeah so these are the model guys I have
20:47:16considered for this project allowed
20:47:17model Gemini 2.5 flash Gemini 2.5 Pro
20:47:21and so on. If you want to use any other
20:47:23model, you just need to um rename this
20:47:26this uh dictionary. And the default
20:47:29model uh if user is not giving any kinds
20:47:31of model, the default model I'm taking
20:47:32Jiny 2.5 plus from the environment
20:47:34variable. Okay, here we have already
20:47:36set. Yeah, this is for the safer
20:47:39purpose. Okay, let's say if user is not
20:47:40giving any model by chance, that's why
20:47:43you can take the safer uh I mean default
20:47:45model.
20:47:47Okay.
20:47:49Yeah. So once it is done now we'll try
20:47:51to create a system prompt.
20:47:57So this is the
20:48:00system prompt guys I have prepared. As
20:48:02you can see you are a helpful agent
20:48:05assistant named BGPT similar to chart
20:48:07GPT. You can answer normal question use
20:48:09tools when needed. Okay. Search uploaded
20:48:11documents using rack tool. Search web
20:48:14for the latest current information using
20:48:16tab search. remember important
20:48:18informations using memory tool okay
20:48:20recall any kinds of old conversation
20:48:23using memory and you can also use
20:48:26calculator for mathematical operation
20:48:28and here I have set some rules okay so
20:48:30that's how we can change this prompt as
20:48:31per your requirement I have given this
20:48:33system prompt now the first thing guys
20:48:35uh here what I'm going to do I'm going
20:48:37to
20:48:39build our agent agent workflow
20:48:43um so let's do that I already written
20:48:47that function. Let me show you. So here
20:48:49I'm not going to write from scratch
20:48:51because this code I have already written
20:48:53from scratch in my previous uh previous
20:48:55project implementation. So most of the
20:48:57codes are common. There is no new thing
20:48:59we have added yet. That's why I will try
20:49:01to copy paste.
20:49:03So see this is my
20:49:06um function I have written named build
20:49:08agent. So this will take the model name.
20:49:11Okay. Because to uh to uh create the
20:49:16agent you need the model and uh first of
20:49:19all what I have to do I have to
20:49:20normalize the model and normalize the
20:49:21model name means if user sometimes let's
20:49:25say he is giving um any other name okay
20:49:29let's say it if it is not matching with
20:49:31this name so that type um my code will
20:49:34give me error so make sure whenever you
20:49:36are giving the model ID make sure the ID
20:49:38should be same like that you can go to
20:49:40the Gemini documentation you'll see that
20:49:42they're giving the ID like that. Okay.
20:49:44So, we have to give the same ID. So, if
20:49:46by chance from the front end I'm getting
20:49:48any other different name, I'll just try
20:49:50to normalize that first of all. So, for
20:49:52this we'll return write a function here
20:49:54called normalize model name. It will
20:49:55take the model name and it will do the
20:49:57normalize. First of all, it will check
20:49:58if not model name use the default model
20:50:00otherwise first of all it will do the
20:50:02strip operation then it will check if
20:50:04model name is not not in allowed model
20:50:06return the default model otherwise
20:50:08return the uh same model user is giving.
20:50:10So this function we are applying here
20:50:12just to um just to what just to do the
20:50:17model name verification the model name
20:50:19it is matching here or not. Okay. Yeah.
20:50:21So this kinds of simple simple function
20:50:24you have to write inside your code so
20:50:26that your application would be more
20:50:27robust. Okay. Because user can give
20:50:29anything. So you have to handle in the
20:50:31back end. Now here we are using uh this
20:50:35Gemini model chat Google generative way.
20:50:37We're giving the model temperature
20:50:38streaming is equal to true and we are
20:50:40creating the LM object. Then uh before
20:50:44creating the chat node first of all you
20:50:46remember I think we have to uh bind the
20:50:48tools okay with the lm because here
20:50:50we'll be using the tools right and for
20:50:51this we need list of the tools we'll be
20:50:53creating the tools okay just don't worry
20:50:55I'll create the tools as of now we
20:50:56haven't created so after binding u we'll
20:50:59be using this object lm with tools now
20:51:01here we have written another function
20:51:02called chat node so this is my chat uh
20:51:05chat uh chatbot nodes and here preparing
20:51:08the system message and we are also
20:51:10giving the state Okay. And um um here
20:51:14you can see we are using this uh lm with
20:51:17tools and we are doing the invoking
20:51:19operation and after that we are just
20:51:21returning the message. Okay. Then the
20:51:23second node we are using the tool tool
20:51:25node that means if you see the
20:51:26architecture so this node is created now
20:51:28we are getting this tool this node.
20:51:31Okay tool node. So once tool node is
20:51:33created we are creating the workflow
20:51:34state uh graph. Uh we are giving the
20:51:37message state. Okay. And message state
20:51:41is already available inside this
20:51:43langraph. Okay, you don't need to
20:51:45separately write that. It is already
20:51:46inbuilt inside lang graph. If you are
20:51:48creating this kinds of chatbot, you can
20:51:50directly use this message state. I think
20:51:51previous video I already discussed this
20:51:53part. So message uh state we are taking.
20:51:56Then we are adding the nodes. First of
20:51:57all we have to add the um chat node,
20:52:00right? Then we have to add the tool
20:52:02node. So adding the chat node, then tool
20:52:04nodes. Okay. Then we are doing the edge
20:52:06connection. First of all start to
20:52:08chatbot.
20:52:09Start to chat chat note. Okay. Then uh
20:52:13we are using conditional edges. Okay.
20:52:15Conditional edges that means chatbot to
20:52:17tools condition. Chatbot to tool
20:52:19condition. Okay. That means there would
20:52:21be two condition. Then
20:52:24uh tool condition to chatbot
20:52:27tool condition to chatbot again that
20:52:29means whatever response we'll be getting
20:52:30from the uh tools right this should be
20:52:33refined with my LLM. That means I may
20:52:36again passing to the chat node. So yeah
20:52:38this is the connection and now we have
20:52:40to give the persistence memory which is
20:52:42my
20:52:44uh SQLite. So here we are already
20:52:47creating the data folder. I think
20:52:48remember this data folder. So inside
20:52:51data folder we are creating a database
20:52:53object called langraph checkpoint.sqlite
20:52:56and skqite is a local uh database. You
20:52:58can create inside your storage only.
20:53:00Okay. If you want you can also use any
20:53:02remote database as well. Okay. You can
20:53:04set up this this is on any server and
20:53:06you can use that. But again for this uh
20:53:09you need cloud platform like AWS okay
20:53:12then your GCP. So there you can set up
20:53:15the database server. You can store all
20:53:17of the um uh store all of the uh data
20:53:21but again I'm using the free resources.
20:53:22That's why I'm using the local one. Okay
20:53:25for this you don't need to pay anything.
20:53:27Then same trades is equal to false. So
20:53:30this thing you have to u make and this
20:53:33will become your connection object. Now
20:53:34you will be initializing the escalate
20:53:36server and this connection object you
20:53:38will pass here and this will become your
20:53:39checkpointter and this checkpo pointer
20:53:41you will be using whenever you will do
20:53:42the workflow compilation. Okay done. So
20:53:45this is what you have to just write for
20:53:48this build agent. Okay. So now guys uh
20:53:52it's done. Now the next thing we have to
20:53:54prepare the tools. And again I'm telling
20:53:56you guys all of this concept I have
20:53:59completed in my playlist. Okay, just go
20:54:01through one by one all of the concept.
20:54:03You can see tools, rag, okay, aentic,
20:54:06chatbot, workflow, okay, each and
20:54:08everything I have already discussed in
20:54:09my playlist. Just try to go through
20:54:11that. If you are first time uh in this
20:54:14implementation,
20:54:15uh you might get difficulties for sure.
20:54:17Okay, but if you cover all of this
20:54:19recording, you won't be any kinds of uh
20:54:21you won't be having any kinds of
20:54:22problem. Okay, this is my promise. So
20:54:24that's why I'm telling you I'm not going
20:54:26to focus on the theoretical part. I'm
20:54:28only going to focus on the practical
20:54:29development because theory I have
20:54:31already covered. Okay. Yes. So yes. So
20:54:34now let's work on the tool. Uh so for
20:54:37tool guys what I'm going to use I'm
20:54:38going to use this tools.py and inside
20:54:41that I'm going to mention all of the
20:54:42tools I'll be using in this project. So
20:54:45first of all let's import all of the
20:54:47necessary library.
20:54:49Um
20:54:51yeah.
20:54:53So I'll import math module uh env. Then
20:54:56we'll load the environment variable.
20:55:00Okay. Then here we have imported tools
20:55:05from langen code tools. Then langen tab
20:55:08where importing tab search. Okay. Yeah.
20:55:12So first of all um here what I'm going
20:55:15to do I'm going to initialize some
20:55:17tools.
20:55:24First of all, I'm going to use this
20:55:27web search tool.
20:55:32Okay, web search tool. So, I'm using
20:55:34tably and here we're giving the some
20:55:36parameter like max result, topic. Okay,
20:55:39search depth. These are the parameter
20:55:40we're giving and this will become your
20:55:42tool. And here you don't need to use the
20:55:43tool decorator because table is already
20:55:45a tool. Okay, so you don't need to give
20:55:47that. And uh I need other tool as well
20:55:50like I need calculator tool.
20:55:54So this is my calculator tools. So you
20:55:58can see this is a simple custom function
20:55:59we have written for calculator. It will
20:56:01take any kinds of expression and it will
20:56:03do the um mathematical operation and it
20:56:06will return the result. And if you want
20:56:08to use as a tool I have to use this tool
20:56:10decorator. Okay that means website and
20:56:12calculator we have added. Now we'll be
20:56:14adding some more tools like uh we'll be
20:56:17adding the uh we'll be adding the
20:56:23memory tool that means you can save any
20:56:25kinds of uh uh information if user is
20:56:28giving let's say user is giving remember
20:56:30something okay it will use that memory
20:56:33tool and it will save that information
20:56:35in the long-term memory and for this we
20:56:36have to use the database so we'll be
20:56:38writing that thing as a tool then if you
20:56:41want to search memory that means if you
20:56:42want to get any older conversation which
20:56:44you did long time ago. It will retrieve
20:56:46from the database. Okay. So again for
20:56:48this we will be writing a tool. Okay. So
20:56:50that's how we'll be writing different
20:56:51different tool and one more tool you
20:56:52need which is this uh um rag tool. That
20:56:55means if user wants to search something
20:56:57over the documents you can use the rag
20:56:59tool. So this part we'll just try to
20:57:01write but before that we'll be writing
20:57:03another function called
20:57:06trade.
20:57:07This trade is required because here I
20:57:10think you saw we we'll be using the
20:57:11trade right? different different trades.
20:57:13Okay. Uh user can create different
20:57:15different trades. Okay. And anytime they
20:57:17can switch between another trades. So
20:57:19for this every time we'll be using the
20:57:22trades. So for this here I have written
20:57:23another function called set current
20:57:25trades. And if user gives any kinds of
20:57:27trade ID here it will try to set that
20:57:29particular trades and this trade will be
20:57:31considered in that particular session.
20:57:33And by default if user is not giving any
20:57:35trades it will be using the default
20:57:36trades. Okay. So this trading concept I
20:57:38also discussed in my playlist. You can
20:57:40go through that. Now first of all uh
20:57:43what I'm going to do guys I'm going to
20:57:44use the database related
20:57:48database related tools. So for this
20:57:51there is a file I have written called
20:57:52database.py. Let's open it up and uh let
20:57:56me show you
20:57:59all of the
20:58:02function you need here.
20:58:05I already written this code. Let me show
20:58:07you very simple only the database
20:58:09operation I have written. And here we
20:58:11are using SQL uh alchemy database. Okay,
20:58:13for this you need the knowledge on SQL
20:58:15alchemy. If you don't know, just go
20:58:16through any YouTube video and try to
20:58:18understand SQL alchemy how it works with
20:58:20Python. So here we're importing dead
20:58:22time, path leave, SQL alchemy, you're uh
20:58:24importing create engine, column,
20:58:26integer, string, text, dead time, SQL
20:58:28alchemy, you're importing OM. Okay. Uh
20:58:31declarative base session maker each and
20:58:33everything you will uh see from the
20:58:35tutorial itself. I'm not going to
20:58:36explain this here because again this is
20:58:38a theoretical concept. You can
20:58:40understand this thing from a YouTube
20:58:42tutorial how SQL Alchemy works. But this
20:58:44is a simple code I have written.
20:58:45Basically, this uh code will try to
20:58:47connect with SQL Alchemy server. So here
20:58:50we're creating a local server. You can
20:58:51see okay, we'll be creating a local
20:58:53server. If you want you can also install
20:58:56this SQL Alchemy in the remote server.
20:58:58Uh for this again I told you you need to
20:59:00use AWS, GCP or any other cloud
20:59:02provider. There you can set up that but
20:59:04again uh that would be costly. That's
20:59:06why I'll be using the local one just to
20:59:08show you the free resources. So again uh
20:59:10we are creating the data data folder.
20:59:12Okay data folder why every time we're
20:59:14creating the data folder because if data
20:59:16is not data folder is not there first of
20:59:18all it will create and inside that it
20:59:20will save this uh DB object. Okay. So
20:59:23every time you need to check okay uh and
20:59:26this parameter you have to provide if
20:59:27already available no need to create
20:59:29otherwise just try to create. Okay. So
20:59:31this is my database URL SQLite clone. uh
20:59:35then you have to give / data folder
20:59:37inside that chatbot memory db this
20:59:39object would be created okay inside that
20:59:41we'll try to save all of the information
20:59:43first of all we're getting the engine
20:59:44okay where we providing the database URL
20:59:46and some connection method then we're
20:59:49getting a session okay after getting the
20:59:51session we are creating some class you
20:59:53can see first of all this class will
20:59:54return you the schema like table name ID
20:59:57trade ID title created at updated okay
20:59:59this is called actually uh schema okay
21:00:02uh database schema Then chat message.
21:00:05For chat message, we are returning the
21:00:07schema like ID, trader, ro content,
21:00:09created at. Okay, these are the
21:00:11information we'll try to uh save inside
21:00:13chat message. And for long time uh
21:00:15long-term memory that means if user
21:00:17wants to save any kinds of long-term
21:00:19conversation that time we'll try to set
21:00:21ID, trade ID, memory that means the
21:00:24conversation and the created when it it
21:00:26got created. Okay. And the table name
21:00:28should be long-term memory that time.
21:00:30And for chat message that means the
21:00:31regular message whatever message user
21:00:33will perform it will become as a chat
21:00:35message table. Okay. Now we are
21:00:38initializing the database with this
21:00:39function and this is the function for
21:00:41create or update conversation. So this
21:00:43will take the trade ID and the message.
21:00:45Okay. If you give if you give the
21:00:47message it will update that conversation
21:00:49in the table. Okay. So you can see here
21:00:52we have written the code for that. Okay.
21:00:55And this code will also help you to
21:00:58prepare these traits. Okay, that means
21:01:00every time you can see whenever user is
21:01:01passing any kinds of message, it is
21:01:03taking the message title and it is only
21:01:05taking the 40 character of that. So this
21:01:07part I'm doing here. Okay, so from the
21:01:10user message uh first message, I'm
21:01:12taking the first 40 character and I'm
21:01:14preparing a title and I'm showing you
21:01:17inside the trade message. Okay, so this
21:01:19is what actually we have written here in
21:01:20this function.
21:01:22Then once it is done, we are listing all
21:01:24of the conversation. Okay, listing
21:01:26conversation means uh whatever
21:01:28conversation we have here. Okay, uh we
21:01:31are listing all of the conversation with
21:01:33this with this function. Okay, then save
21:01:38chat messages. Okay, that means if you
21:01:40if user wants to save any kinds of
21:01:43message, so it will be using this
21:01:44function for that. Then if user wants to
21:01:47get any kinds of history, previous
21:01:48history, it will be using this function
21:01:50for that. So it is only doing the
21:01:52database operation. You can see it is uh
21:01:54uh adding adding the data. It is uh
21:01:57retrieving the data. That's how it's
21:01:58working. If user wants to save any
21:02:00memory
21:02:02any kinds of let's say let's say I I'm
21:02:05telling my chatbot I am BP. Okay. Try to
21:02:07remember me that time it will use this
21:02:10function. We'll be using this function
21:02:11as a tool. Okay. As a long-term memory
21:02:14that's why we're using this schema that
21:02:16time. Okay. Now let me go below.
21:02:20And [clears throat] if user wants to
21:02:21search anything uh about the previous uh
21:02:23question that time uh we'll be using
21:02:26this function as a tool that time okay
21:02:27for a long time long-term memory uh
21:02:30concept. So yes uh this is the um
21:02:34database related code guys I have
21:02:35written and we'll be using uh inside our
21:02:38tools right now. Now let me import
21:02:41for these are the functionality first of
21:02:43all. So see from this database I only
21:02:45need to import
21:02:47from database
21:02:50I need to import save memory and search
21:02:53memory. Okay, save memory I'll be using
21:02:54to save my conversation and search
21:02:58memory I need to uh get my previous
21:03:01conversation. Okay, old conversation.
21:03:04Now these two things I'll be defining as
21:03:06a tool. Let me do that.
21:03:10So
21:03:14here I'll just try to add after
21:03:16calculator
21:03:19remember this okay if u user is asking
21:03:22um just to remember anything it will use
21:03:25this tool that time okay and it will uh
21:03:28take the conversation and it will save
21:03:29inside the memory and for this we're
21:03:31using this save memory
21:03:33this function save memory and we are
21:03:36defining as a tool and uh one formatting
21:03:39we need the recall memory.
21:03:44If user wants to let's say
21:03:48uh if user is asking about old old
21:03:50conversation let's say if user asking
21:03:52what is my name or what was my hobby
21:03:54that time it will use the equal memory
21:03:56tool and it will search the memory that
21:03:58means in the database it will search the
21:04:00old conversation and it will return that
21:04:03okay so these two things I have used as
21:04:05a tool I hope you get it and one more uh
21:04:09tool I have to create
21:04:11Um
21:04:14one more tool I'll be creating here
21:04:20called uh this rag tool.
21:04:23Just a minute. Yeah, one more tool I
21:04:25need called rag tool. Okay, rag tool you
21:04:27need. Let's say if user is uploading any
21:04:29kinds of documents. So this document uh
21:04:32um you have stored in the vector
21:04:35database. Okay. And from the vector
21:04:37database you'll be performing the
21:04:38retrieving retrieving operation. That
21:04:39means you will try to retrieve the
21:04:40informations for this. This tools is
21:04:42required. So let's create this rag tool
21:04:45here. I'm going to open this rag.py.
21:04:48Inside that I'm going to write all of
21:04:49the rag related code. And again this rag
21:04:52related code is uh uh common from my
21:04:54previous implementation. First of all
21:04:56let's import the necessary libraries.
21:05:00Okay. I'm importing these necessary
21:05:02libraries. Then again I need that
21:05:07environment related
21:05:09um command that means if you are getting
21:05:12the path issue that time this code will
21:05:14help you to prevent that and uh some
21:05:16other library I need
21:05:20these are the library like from langen
21:05:22we're importing chroma chromadb then
21:05:24google generative embeddings we'll be
21:05:26using google genative embeddings model
21:05:28then documents we're importing from lang
21:05:30langen code then recursive character
21:05:32text splitter for the chunking
21:05:33operation. Okay, what is chunking? What
21:05:36is uh why chunk is required in the lag?
21:05:38Each and everything I have discussed in
21:05:40my rag video. So here, okay, implement
21:05:43rag in aentic chatbot. You can go
21:05:45through that. Yeah. Then pi PDF reader
21:05:48because we'll be considering the PDF
21:05:50document. But if you want you can also
21:05:51upload any other document as well. Txt,
21:05:53docs. Okay, it's completely up to you.
21:05:55Then doc to text. Then here we'll be
21:05:58creating two more directory.
21:06:02one is the uploads. Okay, let's say
21:06:04whatever document user is uploading I'll
21:06:06try to store in the uploads folder.
21:06:08Okay, for this you're creating the
21:06:09directory and one more directory you are
21:06:12creating called chromad. Okay, let's say
21:06:14whenever it is creating the vector
21:06:16store, right? Uh um chromod actually use
21:06:19your local storage to save the
21:06:22information that means the vector store.
21:06:23So that time it will create a chrom
21:06:25directory inside that it will save
21:06:26everything that's two directory we are
21:06:28creating. Then we'll be initializing the
21:06:30embedding model.
21:06:33So this is our embedding model.
21:06:36Okay, we are using Gemini uh Gemini
21:06:38embedding 001 this model. Now we'll be
21:06:41creating the vector store.
21:06:44So this is our vector store. We are
21:06:45using chromad and this is the name of
21:06:48the collection name aentic chatbot docs.
21:06:50We are giving the embedding model and we
21:06:52are providing the chromadb path
21:06:56here. [sighs] You can use any vector
21:06:58database. You can use uh pine cone web
21:07:00whatever you want. You can use any
21:07:01vector database. Okay. It's not like
21:07:04that you have to use chrom always. Now
21:07:06here I have written a function. So this
21:07:09function what it does let me show you
21:07:11this function basically reads the uh
21:07:14reads reads reads a file text okay that
21:07:17means if you provide any file uh it will
21:07:19read read that whether it is a PDF or
21:07:23whether it's it's in a doc format okay
21:07:26so basically uh here uh you can upload
21:07:28txt md pi CSV
21:07:32okay and you can load that but here we
21:07:35are considering the docs and pdf format
21:07:37and uh if you want you can also load
21:07:39these other documents as well. So once
21:07:41it's read everything it will load that
21:07:44like if it is PDF it will use the PDF
21:07:46reader to uh read that documents. Okay.
21:07:49If it is docs it will use the docs uh to
21:07:52text and it will load that. Okay. And if
21:07:55you want to consider like MDI you can
21:07:57write another other condition as well.
21:07:59Okay. So it will use that and it will uh
21:08:01load that. But here by default I have
21:08:03written a code uh I'm using path read.
21:08:06Okay. So what it does if you are
21:08:07providing this txt, MD, PI, CSV, it can
21:08:10still load that documents and it can um
21:08:13extract the content from that. Okay. And
21:08:16uh there is exception I have given
21:08:18unsupported file like upload PDF, docs,
21:08:20txt, MD, py or CSV. Uh if user is
21:08:23passing any other file format let's
21:08:24say.pl or any other file that time I'll
21:08:27raise the exception. Okay. So exception
21:08:29has handling is also required whenever
21:08:31you are doing this kinds of scenario. So
21:08:33yeah this is the function to load the
21:08:35documents. Now uh we'll be writing the
21:08:38final function to create the vector
21:08:41store. So this is the function we'll be
21:08:43using to create the vector store. As you
21:08:45can see
21:08:47add documents to rag. It will use the
21:08:49file path and the trade ID. Then uh we
21:08:52are doing the chunking operation. We're
21:08:55giving the chunk size and chunk overlap.
21:08:57Creating the chunking. Then we are um we
21:08:59are taking the page content. Okay. uh
21:09:02that means uh content from the uh
21:09:04documents and we're storing in the
21:09:06vector store. Okay. And we're returning
21:09:07the path. So this function will
21:09:09basically create the vector store. Okay.
21:09:11Vector database and it will store
21:09:12everything in the vector store. Okay.
21:09:15Now for retrieve operation that means if
21:09:17user is asking anything regarding the
21:09:19documents, it will retrieve the
21:09:21information by using the similarity s. I
21:09:23think you know every vector database
21:09:24having a similarity source okay
21:09:26operation. So in this function we are
21:09:28doing that. Sorry from rag where user is
21:09:30giving the query as well as the trade
21:09:32and the k parameter. So by default k
21:09:34parameter is four that means four
21:09:35relevant information it will extract
21:09:37from the vector database we are doing
21:09:39the similarity source operation that
21:09:40means retrieve operation after that
21:09:42whatever result we are getting we're
21:09:44just loading inside result and we are
21:09:46returning returning it as a string okay
21:09:48so this is what we are doing inside
21:09:50retive from rag and this function will
21:09:52be using as a tool right now. So here
21:09:54what I'm going to do I'm going to open
21:09:56up my agent sorry tool and here I will
21:09:58try to import that function. So let's
21:10:00import
21:10:03um the function name is retrieve from
21:10:06rack. So let's import it here. So from
21:10:09rag
21:10:12import
21:10:14retrieve
21:10:18what's the name?
21:10:21Retrieve from
21:10:25Okay, we will be importing here and now
21:10:28we'll just try to create a tool.
21:10:33So here maybe I can create the tool. So
21:10:36this is the tool name uh search uploaded
21:10:38documents user will give the query and
21:10:40we'll be using retip from rag this
21:10:42function we'll pass the query trade ID
21:10:45and it will give me the relevant answer.
21:10:48Okay, for that query we are using this
21:10:50this code for that. So I think now you
21:10:52have understood like how we have
21:10:54arranged everything how we have prepared
21:10:56all of the tool. Okay, we have created
21:10:58the database tool, we have created the
21:10:59rack tool, we have created the search
21:11:01tool, we have created a calculator tool.
21:11:03Each and every tools are ready. Okay,
21:11:05now in the agents
21:11:08uh we'll be importing the tools right
21:11:10now.
21:11:12Let's import the tools.
21:11:17So here we'll just write
21:11:21from tools
21:11:27import
21:11:28tools.
21:11:37Um, okay. So, we have to create a tool
21:11:39object. So, here at the last what I'm
21:11:41going to do, I'm going to just prepare
21:11:45the list of the tools.
21:11:48So, yeah. So you can see this is a list
21:11:50inside that first of all I'm passing the
21:11:51calculator then search uploaded
21:11:52documents remember this recall and web
21:11:54search all the tools we have created we
21:11:57are just passing one by one here okay
21:11:59now if you want to add any other tools
21:12:01in future you can add it here so I'm
21:12:02going to give you a task guys you just
21:12:04try to add the real time where the
21:12:06weather search tool and uh stock price
21:12:09tool okay this tool two tool you can add
21:12:11at least here okay now this thing we are
21:12:14importing here tools now we are using
21:12:18this tool for the bind operation. Okay.
21:12:20Now we are doing the bind operation and
21:12:22our uh workflow is getting created.
21:12:26Okay. So that means still here
21:12:27everything is fine. Everything is good.
21:12:30Okay. Now uh one thing I will do before
21:12:32the testing see here we are uh building
21:12:35the agent right. So it's not necessary
21:12:37to build the agents every time whenever
21:12:39you are initializing the chatbot. Okay.
21:12:42because uh if you're building from uh
21:12:45scratch so I mean it will take some time
21:12:48right so instead of that maybe we can
21:12:50create a cache agent cache that means we
21:12:53can build one time and save in the cache
21:12:56and every time whenever it will um
21:12:59reinitialize the chatbot instead of
21:13:01building from again we can uh take the
21:13:03agent from the cache okay so for this
21:13:06this code is required
21:13:09so simply you can write this code so
21:13:11here I created create a dictionary
21:13:12called agent cache uh and we had created
21:13:16a function called get agent. So you will
21:13:18only pass the model okay a model name.
21:13:22So what will happen? And this will go to
21:13:24the normalize model name function and
21:13:26you will get the correct model name and
21:13:29you are checking if selected model in
21:13:32agent cache okay not in agent cache then
21:13:36you will try to build the agents okay
21:13:38otherwise what you are doing you are
21:13:40taking the existing agent only so you
21:13:42are not building again the agent again
21:13:44and again okay so this thing you can
21:13:46write now we can test whether this uh
21:13:49workflow is working or not so I can open
21:13:51up my rag dot sorry app.py and here I
21:13:54can test it. So I'll just try to import
21:13:57import um from agent
21:14:08agent
21:14:10input get agent.
21:14:16Now
21:14:18agent is equal to get agent. Here you
21:14:20have to pass the model name.
21:14:23So let's say I'll give the same name.
21:14:27This model name I'll keep.
21:14:39So it will only take the model name I
21:14:41think. Yeah model name. Okay. Now we can
21:14:44do the invoke operation.
21:14:48Yeah. So we have written this code for
21:14:50testing. Okay. So here we are using the
21:14:53streaming right. So that's why instead
21:14:54of invoking I'm just doing agent stream
21:14:57and we are giving the human message here
21:15:00and stream will return a uh generator
21:15:03object and for this we are using this
21:15:04for loop and we're uh getting the answer
21:15:06token by token and we're streaming that
21:15:10and uh here is the code. So let's test
21:15:14it whether it's working or not. I will
21:15:15open up my terminal and uh I'll just
21:15:18execute python.py.
21:15:24Now see all the folders are getting
21:15:26created.
21:15:28Now here we are getting the response as
21:15:29you can see streaming response. So this
21:15:31is the blog about a machine learning we
21:15:33got. See okay that means everything is
21:15:36working fine. And here we are given um
21:15:40like um testing trade just to test the
21:15:44workflow because this workflow needs a
21:15:45trade ID right we we have given a
21:15:47testing trade here in this
21:15:49configuration. Now you can see um all of
21:15:53the folders got created and you can see
21:15:55this is your state uh state actually
21:15:59um state database it is serving inside
21:16:01SQLite and uh this is the chromb um that
21:16:05means the vector database will be
21:16:08creating here and the upload folder as
21:16:11well as of now we haven't uploaded
21:16:12anything that's why it's coming like
21:16:13that now we can ask anything uh that may
21:16:16use any tool let's say I will ask
21:16:21Tell me
21:16:24today's
21:16:30news
21:16:34of AI. So definitely he will use uh the
21:16:37tool that mean search tool. Let's see.
21:16:51Now see it has uh done the internet
21:16:52search operation with the help of tably
21:16:56and uh it found the result. Okay,
21:16:59regarding the today's uh news of AI and
21:17:02you can see it has referred different
21:17:03different website here. Okay, different
21:17:05different website URL are present. Okay.
21:17:07So from this URL it has extracted the
21:17:09news and this is what we got in the
21:17:12answer and one best part is that you can
21:17:16also uh see this uh database that that
21:17:19means whatever methods are available
21:17:20inside that. So for this you have to
21:17:23install one extension called SQLite
21:17:27okay viewer.
21:17:30So this extension you have to install.
21:17:32So this is the like author you can
21:17:35install this extension. I already
21:17:36installed that. Now after installing
21:17:38this, you'll be able to see your data uh
21:17:41data uh sorry database. Now let's double
21:17:44click and you will see that all of the
21:17:47information it has saved here. All of
21:17:48the like checkpoint you can see. Okay.
21:17:51All of the checkpoint it has saved here
21:17:54with a trade ID as well. And trade ID is
21:17:56nothing but test ID as of now we have
21:17:58given.
21:18:00So now let's uh test the long-term
21:18:02memory as well. That means uh it is able
21:18:05to save my um save uh my long-term
21:18:09memory in my uh conversation database or
21:18:11not. I think you remember we used SQL
21:18:14SQL alchemy database for that right. Um
21:18:17so if you are um if you are let's say
21:18:20doing any kinds of conversation with
21:18:22your uh chatbot if you want to remember
21:18:24something okay that means the long-term
21:18:27conversation uh it will also remember
21:18:28with the help of this database. So for
21:18:30this we'll test that uh that's why I
21:18:32have given a prompt my name is BP
21:18:35remember that and uh I think you know
21:18:37that in database
21:18:39uh database.py we created a function
21:18:41called save memory okay save memory and
21:18:44this thing I created as a tool now
21:18:47inside tools.py Pi you'll see that this
21:18:50uh remember this uh tools will be using
21:18:52this save memory save memory function
21:18:54okay that means if user is giving any
21:18:56kinds of conversation it will save
21:18:58inside the memory the SQL alchemy memory
21:19:00right and you it will automatically use
21:19:03that tool if user wants to remember
21:19:05something it will use this tool and it
21:19:07will store that conversation uh in the
21:19:10database itself okay we'll try to test
21:19:11this part so for this we are giving this
21:19:13prompt my name is Bumpy remember that
21:19:16and uh if you want to execute first of
21:19:17All you have to initialize the database.
21:19:19Okay, because if you check the database
21:19:20inside that we created a function called
21:19:23uh init DB. Okay, we have to initialize
21:19:25the database. First of all, database
21:19:26would be created. All the table would be
21:19:27created. Then we'll be able to store
21:19:29that. So let's import it. So in the
21:19:31app.py from database
21:19:35import
21:19:37db then we'll try to initialize the
21:19:39database. Okay, now I think it will
21:19:41work. Let's test it. I'll open up my
21:19:44terminal.
21:19:46Clear. I'll execute my app.py.
21:19:51Now you can see that uh memory saved
21:19:53successfully. Got it. By I remembered
21:19:55your name. Now if I uh go back now
21:19:58you'll see that this database uh
21:20:00database is created. Chatbot memory.
21:20:02This is my SQL alchemy database. Now if
21:20:04I open this okay now you'll be able to
21:20:06see the uh table. Okay. All the three
21:20:08table has created chat message
21:20:09conversations and long-term memory. And
21:20:11it will save in the long-term memory I
21:20:13think remember in the database. So I
21:20:15think remember whenever it will save
21:20:17something right save memory it will use
21:20:20my long-term memory okay long-term table
21:20:24long-term memory table so in the
21:20:25long-term memory table you'll see that
21:20:27it has saved my information my name is
21:20:29puppy okay so that's how uh it will it
21:20:32is working okay so right now if you are
21:20:34asking let's say
21:20:37what is my name now it will use that uh
21:20:42sorry not here I have to ask it here
21:20:49what is my name. Now it will use that um
21:20:56tool that means this tool again
21:21:00recall memory tool and it will search in
21:21:02the memory that means in the database
21:21:04and uh it will get this information and
21:21:06it will reply that. Let me show you.
21:21:18Okay. You can see your name is Baki. So
21:21:22it is using
21:21:24your conversation story. Okay. That
21:21:27means your long-term long-term memory.
21:21:29Yeah. So everything is working fine
21:21:31guys. Uh uh we have already tested and
21:21:33our workflow is working great. Now what
21:21:35we have to do guys? we have to uh we
21:21:38have to uh create the front end that
21:21:41means the user interface we'll be taking
21:21:44all of the message from the user and
21:21:46we'll try to connect with the back end
21:21:47that means we'll create a fast API
21:21:48server and there we'll try to make the
21:21:50communication okay so to for the front
21:21:54end guys uh here we will be using this
21:21:56HTML uh file index html file inside that
21:21:59we'll be writing all of the HTML CSS
21:22:01JavaScript code whatever you need for
21:22:03this user interface okay the user
21:22:04interface we created And again if you
21:22:07are not familiar with these kinds of
21:22:08HTML, CSS, okay, JavaScript, no need to
21:22:12worry. Even I also took the help from
21:22:14ChatgPT. I already uh generated this
21:22:17template from Chad GPT and ChatgPT
21:22:20written that HTML, CSS, JavaScript code
21:22:22for me. Whatever required for this user
21:22:25interface. Okay. But uh in your team
21:22:28there would be some kinds of person they
21:22:29will be working on this front- end
21:22:30design part. You don't need to worry
21:22:32about that. So let me show you. This is
21:22:35the code I have generated from chartg
21:22:37guys. Again you don't need to remember
21:22:39this code. You can take from uh you can
21:22:42generate this code from chartg or gemini
21:22:44whatever you want. So here is the HTML
21:22:47CSS everything I have written in the
21:22:49single file itself. This is the design
21:22:51of that front end. Each and everything
21:22:53you can see color.
21:22:56So this is a big file.
21:23:00See okay all of the front end uh code I
21:23:05have written here and the see this is
21:23:07the JavaScript code okay so in the
21:23:09JavaScript some um um that means uh
21:23:13backend API is getting triggered as well
21:23:15I'll show you these are the part see
21:23:18this is the entire code we have
21:23:20generated from chat GPT
21:23:23okay chat GPT and one more thing I have
21:23:26done uh I think you saw the voice mode
21:23:28right here is the voice mode see this
21:23:30This void mode you can add two way you
21:23:33can use the Python voice API inside
21:23:36Python I think you know there is a
21:23:38library called speech uh speech
21:23:40recognization library you can use that
21:23:42for this voice voice mode either in
21:23:46already this um uh JavaScript okay
21:23:49JavaScript there is a library uh there
21:23:51is a library called let me show you
21:23:56this voice features
21:24:14Yeah. So here is the code part. So in
21:24:16JavaScript uh there is a already inbuilt
21:24:18library called speech recognization. So
21:24:20we're using this speech recognization
21:24:22library here. Okay. You can see we're
21:24:24using this speech recognization library
21:24:26and automatically it will use your uh
21:24:29Windows microphone. Okay. And uh it will
21:24:32uh start uh listening you. Okay. And
21:24:34whatever uh speech you will give and it
21:24:37will try to listen it will try to
21:24:40understand and it will try to convert
21:24:41that speech to text. Okay. So this is
21:24:43already available inside JavaScript. Uh
21:24:45if you have already studied about
21:24:46JavaScript I think you know that this
21:24:48library is available. So you don't need
21:24:50to separately write inside Python. Okay.
21:24:52You can directly use the JavaScript
21:24:54functionality here. So we have already
21:24:55used the JavaScript functionality and we
21:24:57are doing the speech recognization that
21:24:58means this part. Okay. Now if you click
21:25:00here it will start listening. Okay. And
21:25:03uh you can uh like um tell something and
21:25:05it will automatically recognize that. So
21:25:07we're using this part here. Okay. So
21:25:09yes, this is the entire HTML, CSS and
21:25:11JavaScript code we have written inside
21:25:13HTML and uh index.html. And this code
21:25:15you can generate um from chatgi
21:25:19anywhere. Even you can also copy this
21:25:20code and you can give uh give it to the
21:25:22chart GP and you can ask explain this
21:25:24code in a simple manner. You'll see that
21:25:26it will explain like what are the
21:25:27functionality it it has already. Okay.
21:25:30But don't worry this uh front end part
21:25:33um you can implement
21:25:35um uh with any kinds of front- end
21:25:37developer. You can see it with them. You
21:25:39can um just tell your expectation what
21:25:41kinds of front end you need. They will
21:25:43try to develop for that. But uh uh if
21:25:45you're creating production grade uh like
21:25:48uh application better to use any front-
21:25:50end framework for that like nextjs is
21:25:52there okay in market next JS is there
21:25:58next JS is there react is there okay
21:25:59these are the framework you can use for
21:26:01this kinds of front-end development okay
21:26:05but here uh we are creating this front
21:26:08end with the help of HTML CSS and
21:26:09JavaScript
21:26:12now let me show you how this our design
21:26:15uh will look like. For this uh we'll
21:26:17just write our first API code that means
21:26:19our first API server. So for this we can
21:26:22write inside our app.py. Let's open it
21:26:24up. And this part we can maybe keep
21:26:27inside our test.py. Okay. Let's create
21:26:29another file called test.py.
21:26:35I'm not going to delete it. I'm just
21:26:37keeping it just for your reference.
21:26:38Okay. Now in the app.py, I'll just
21:26:40remove everything.
21:26:43Now let's uh import all the necessary
21:26:44library.
21:26:48Yeah. So again I will import this
21:26:53ENB where certify and this is for the uh
21:26:56path issue. Okay. We have to add then
21:26:59we'll be importing the fast API
21:27:02related functionality. So you can see
21:27:04we're importing JSON UI ID. I need for
21:27:08this trading. Okay. every time we need
21:27:10to create a unique trade and for this UI
21:27:11it is required then you click on fast
21:27:14API okay fast API from fast API
21:27:16importing these are the libraries okay
21:27:18and here we'll be showing the streaming
21:27:20response and inside fast API already
21:27:22streaming response function is there you
21:27:24can use that then JSON response then
21:27:26ginger template so these are the things
21:27:28we need and definitely you should have
21:27:30little bit knowledge on fast API okay
21:27:32how fast API works here then um from
21:27:38lang chain we'll be importing these are
21:27:40the functionality so we are importing
21:27:42human message AI message AI message
21:27:44chunk tool message okay so basically
21:27:46we'll be uh doing the verification like
21:27:48what kinds of response we are getting
21:27:50from the workflow whether it is human
21:27:53message AI message okay or AI message
21:27:56some tool message based on that we'll
21:27:57try to filter out the content
21:28:01and uh apart from that I also need to
21:28:04import my agent
21:28:06okay agent
21:28:08From agent we're importing our get agent
21:28:10function. This will return me the agent.
21:28:12Let me close these are the things.
21:28:18Then after that we'll be importing some
21:28:20other functionality from the database.
21:28:27So from database we're importing init
21:28:29database. Init uh DB save chat message.
21:28:33Okay that means this function save chat
21:28:35message. Then we are importing get chat
21:28:38history. Okay, get chat history. Then
21:28:41create or update conversation. This
21:28:44function and list conversation. Okay,
21:28:46these are the functionality I need.
21:28:49Then from rag and tools I'll import.
21:28:55So from rag I'll import this add
21:28:57documents to rag. That means if user is
21:29:00asking any uh uploading any document
21:29:02we'll try to call this function. First
21:29:03of all, it will add the document to the
21:29:06rack. Okay, that means my vector is
21:29:09stored. Then from tools, we are
21:29:11importing send current trade ID because
21:29:13every time I need to create a unique
21:29:15trade ID if user is creating the trades.
21:29:17Okay, so these are the functionality I
21:29:19need to import. Now let's initialize the
21:29:21first API.
21:29:26So we'll initialize the first API.
21:29:28That's how we can initialize the first
21:29:30API. and we can redirect a folder that
21:29:32means the templates inside templates
21:29:34folder I have my HTML CSS and JavaScript
21:29:36code that's why we are giving this
21:29:37directory then we are again creating
21:29:39these two folder if it is not available
21:29:41uploads and data and we'll be
21:29:44initializing the database
21:29:46my SQL alchemy database okay database
21:29:48should be initialized first of all then
21:29:52let's create the default route so this
21:29:54is our default route okay and here we're
21:29:57using uh asynchronous asynchronous
21:29:59programming is uh because uh instead of
21:30:02running my
21:30:04endpoint uh as a sequence I can run in
21:30:06parallel and this concept I have already
21:30:08told you uh I have already discussed in
21:30:10my playlist you can see a synchronous
21:30:12programming is available you can go
21:30:14through that okay why asynchronous
21:30:15programming is required for AI agents
21:30:17okay uh especially it is already
21:30:19integrated in fast API if you're using
21:30:21fast API you can integrate this
21:30:22asynchronous programming so please go
21:30:24through this session you will understand
21:30:25why asynchronous programming is required
21:30:26I'm not going to explain this part okay
21:30:28again so Yeah, that's why I'm using as
21:30:30keyword and this is my home route. That
21:30:33means my default route. If user is
21:30:34visiting our uh let's say uh server, you
21:30:37will be able to see that index.html
21:30:39page. Okay, we are rendering that here.
21:30:41Now, let me show you. Let's um
21:30:45render it.
21:30:52Yeah, we'll try to render. So here we'll
21:30:55uh we'll mention two more things in my
21:30:56environment variable which is the
21:31:02app host and app port or you can also
21:31:04directly write here
21:31:08host should be
21:31:130
21:31:160.0.0 0 this is my local host at port
21:31:20number I'll give
21:31:238 0 8 0 okay now this two part I don't
21:31:27need
21:31:30here it should be app because my file
21:31:32name is app and inside that I'm creating
21:31:34a app app uh object okay now this is my
21:31:38host this is my port and it will reload
21:31:39every time whenever you will change
21:31:41something and with the help of uon we're
21:31:43running the first API server yeah so
21:31:46everything is fine now let me execute
21:31:47and show you. Uh so first of all I'll
21:31:51close my previous application. Okay,
21:31:53previous application is also running.
21:31:58Now let's clear. [clears throat]
21:32:00Now python app.py.
21:32:10Now I'll give the permission.
21:32:12It is running on post uh local host port
21:32:15number 80080. Let's open it up.
21:32:19Local host port number 80080.
21:32:26So this is the interface guys. Okay. We
21:32:28have created uh with the help of chat
21:32:30GPT. Okay. So it has all the button this
21:32:34uh chat input box, document uploader
21:32:36option, this voyage option, then you can
21:32:39select the models from the front end,
21:32:41send the prompt. Okay. So each and
21:32:42everything we have created here. Now we
21:32:44have to make it as functional.
21:32:46So first of all uh here what I'm going
21:32:48to do I'm going to write more route
21:32:51here. So
21:32:54first of all here what I'm going to do
21:32:55I'm going to write a route that route
21:32:57will fetch all of my previous trades I
21:33:00have done the chat operation. Okay that
21:33:02means uh if you saw like uh previously
21:33:05it is you can see all of the trades
21:33:07previously whatever trades I did the
21:33:08conversation right you can switch
21:33:09between any of the trades you can see
21:33:11that. So this thing I have to fetch for
21:33:13this. What I can do? I can write a route
21:33:15here. So this is the route
21:33:22after this home route. I'll add this.
21:33:24Okay. / conversation. Okay. And this /
21:33:27conversation we are calling inside my
21:33:30JavaScript. Let me show you here. This
21:33:34is the function we have written. So this
21:33:36will basically call this route. Okay.
21:33:38and it will load all of the conversation
21:33:40conversation trades and it will show in
21:33:42the front end. Okay, now let me show you
21:33:45if I refresh.
21:33:48No chats is available.
21:33:54Okay, now let me do the chat and let me
21:33:57show you because right now we haven't
21:33:59done any chat operation, right? That's
21:34:00why it's not showing.
21:34:04Okay, this is the first time we are
21:34:06doing right. So first time you won't be
21:34:08able to see the conversation but let
21:34:10let's complete it then I will show you.
21:34:11Okay. Yeah. Then uh the second thing we
21:34:15have to add which is this uh this one
21:34:19actually this features. So let's say now
21:34:21if I switch to any any let's say um uh
21:34:25trades. So let me run this previous app
21:34:27then I think I can explain better.
21:34:33Yeah now this is running. Now see if I
21:34:35click on any of the trades right so
21:34:38you'll see that the previous
21:34:39conversation story today I'm able to see
21:34:40that okay that means each of the trades
21:34:42is having a conversation okay so this
21:34:45conversation uh I have to also load for
21:34:47this I'll be creating another route in
21:34:50my first API server so this is the work
21:34:52of fast API right you can create
21:34:54different different route and you can uh
21:34:56hit that a um route anytime okay from
21:34:58your u javascript code or any other code
21:35:02you can hit
21:35:05So here this is the route I have created
21:35:08called history and it will take the
21:35:10trade ID as well. That means which trade
21:35:12you want to uh see the conversation.
21:35:14Okay. You have to give the trade ID. So
21:35:16trade ID. So basically this will get the
21:35:19story. Okay. How you'll get the history?
21:35:21Because we are using this get history
21:35:24function from the database. Okay. And
21:35:25previously here you can see for
21:35:27conversation we are using list
21:35:29conversation function. Okay. It will
21:35:30list all of the conversation. So this
21:35:32two function we are using here. Okay.
21:35:34And this slash story we are calling
21:35:37inside my
21:35:39uh JavaScript. Let me show you. See here
21:35:42we are calling this / story. Okay. First
21:35:44of all you're getting the um traits then
21:35:46we are getting the story and all of the
21:35:48message you are able to see that. Okay.
21:35:50So this is the function you need here.
21:35:52Done. Now the next functionality I have
21:35:55to write for the upload operation. Let's
21:35:56say if user is uploading any kinds of
21:35:58documents. If they're uploading any
21:36:00kinds of documents, what will happen?
21:36:01Let's try to do that. So for this I have
21:36:04written this function
21:36:07written this route.
21:36:14This is the route. Okay. / upload. So it
21:36:19will uh take the uploaded documents. And
21:36:21after that here we are calling that
21:36:23function. Let me show you. So we are
21:36:25taking the file name. We're taking the
21:36:27file and we are generating the unique ID
21:36:30of the file. Okay. Then here create and
21:36:33upload the conversation. Okay.
21:36:36Uh so here uh basically we are calling
21:36:39this function just to uh just to save
21:36:42the message that the user has uploaded
21:36:43any documents here. It will also save in
21:36:45the story that means the database story.
21:36:48We are using this function and here we
21:36:50are using this add rag uh documents to
21:36:52the rag this function. So this function
21:36:54basically will read that documents,
21:36:56process it and it is stored in the
21:36:57vector database. Okay. Then we are
21:37:00returning the response. So I think you
21:37:01are getting okay what we are doing here.
21:37:03Very simple. Okay. So every time
21:37:05whatever user is doing you have to save
21:37:06in the database. Okay. All the activity
21:37:09you have to save in the database then
21:37:10you are doing the other stuff.
21:37:13Now we'll do the general conversation
21:37:20like um if user is asking anything this
21:37:24will hit my
21:37:26chat route that means I will be able to
21:37:28see my streaming response. So this is
21:37:31for this this is the function I have
21:37:32written.
21:37:34Okay again I'm using asynchronous
21:37:36because I want to run in parallel. So I
21:37:38named it as chat stream. So this is the
21:37:40route / chat/stream
21:37:44and uh this thing also you are calling
21:37:46from this
21:37:49JavaScript.
21:37:53Okay, as you can see so JavaScript is
21:37:56hitting that route and uh we are taking
21:37:59the user message trade. Okay, trade we
21:38:02are taking and every time uh whenever
21:38:05let's say uh user is uh clicking on new.
21:38:09Okay, new that means new button that
21:38:11time what will happen a new trade would
21:38:13be created and here we are setting the
21:38:14trade ID that time. So trade we're
21:38:16taking selected model we're taking. Then
21:38:18we are preparing the user message. We
21:38:21are initializing the agent. As you can
21:38:22see we are calling the get agent
21:38:24function and this will give me the
21:38:25agent. Okay. After that we are updating
21:38:29the conversation in the database. Then
21:38:31we are saving the chat message as well.
21:38:33That means every time it will save the
21:38:34conversation. Okay. Whatever
21:38:36conversation user is doing or it will
21:38:38set in the chat message. That means in
21:38:39the chat message table here in this
21:38:41table. Okay. It will save all the
21:38:43conversation. After that we are setting
21:38:45the current trade id. We are preparing
21:38:47the config that means the trade and we
21:38:50are written we have written another
21:38:52function called event generator. Okay.
21:38:54So here it is using asynchronous.
21:38:56Uh so here basically what we are doing
21:38:58we preparing the human message. Then we
21:39:00are running the stream stream code. You
21:39:02can see we are doing this agent. We are
21:39:05passing all of the input and
21:39:06configuration and we are just showing
21:39:08the answer token by token. And for this
21:39:10we are using some kinds of utility
21:39:12function like should stream chunk. then
21:39:14SSE data. Okay, these are the things you
21:39:16need. Uh because sometimes whenever you
21:39:19are uh calling any kinds of tool, tool
21:39:21will give you the raw response and this
21:39:23raw response you don't want to show in
21:39:25the front end, right? So for this you
21:39:26have to do the some filter operation. So
21:39:28this code I have written here. Let me
21:39:30show you.
21:39:41So this is the code. These are the
21:39:42utility function unit.
21:39:45Yeah. SEC data. Then should stream
21:39:48chunk. So basically it will first of all
21:39:49check whether it a tool to tool
21:39:51response. Okay. Then it is a AI message
21:39:54or not. Okay. These kinds of things
21:39:55verification it will do. Then it will
21:39:57extract the text from the chunk. That
21:40:00means instead of uh getting the raw
21:40:02message it will only take the content
21:40:04and it will return you. Okay. So this is
21:40:06what actually we're using in this
21:40:07function. You can see we're using in
21:40:08this function. should stream extract uh
21:40:12from chunk as a token by token then we
21:40:15are showing it in the console and every
21:40:17time we're doing the yield operation
21:40:19okay so if you're using uh asynchronous
21:40:23I think you know what is yield right uh
21:40:25you can go through that recording okay
21:40:28then we are using u past api streaming
21:40:30response function and we're giving this
21:40:32event generator uh function inside that
21:40:35okay so basically this will show my uh
21:40:38response as a streaming one by one
21:40:40token. Yeah. So, yes, uh this is the uh
21:40:43code you just need to write in the first
21:40:45API server, fast API uh endpoint now. I
21:40:48think everything is ready.
21:40:51Let me see.
21:40:58So, everything is ready. Now, we can
21:40:59test our app. I'll come here. Refresh.
21:41:03Okay. Now, let's do chat operation. Hi,
21:41:07I am Buppy.
21:41:10Let's send it. Okay. If you send it, so
21:41:12what will happen? It will hit that
21:41:16this route. Okay. Chat stream route.
21:41:22So you can see uh hi BP, it's nice to
21:41:24meet you. How I can help you today? And
21:41:26it has also taken the trade. Right now I
21:41:28can create another trade. Again I'll do
21:41:31some message. Let's say
21:41:33my name is
21:41:36Alex.
21:41:41Okay. Okay. Alex, I have saved your
21:41:43memory. Nice to meet you. Okay. This is
21:41:46uh another trade. This is another
21:41:47trades. Okay. And if I click here, you
21:41:49can see the conversation here. Okay. You
21:41:51can see the conversation here. Why it is
21:41:54happening? Because of these two function
21:41:55two um
21:41:58two method. One is uh this last
21:42:00conversation. it is uh it is actually um
21:42:04filtering out all of the trades you have
21:42:06in the database. Now if I show you my
21:42:08database right the chat memory database
21:42:10now see every time whatever conversation
21:42:12you are doing chat message you are doing
21:42:16yeah so I have refreshed now see this
21:42:18conversation is available so whatever
21:42:20conversation you are doing right hi my
21:42:21name is Buffy okay blah blah blah all
21:42:24the conversation you will see with the
21:42:25trade ID here okay trade ID here and uh
21:42:29here is the conversation
21:42:32and here is the long-term memory okay so
21:42:34that's how we are saving inside our
21:42:36database every
21:42:38Now let's uh test uh any other message
21:42:41that say tell tell me
21:42:46the latest
21:42:51news
21:42:53in AI. So basic uh it will uh use the
21:42:56search tool that time. Let's see see it
21:42:58is using web search tool.
21:43:06and see you are getting the response.
21:43:09Now let's ask another question.
21:43:11Calculate
21:43:13this.
21:43:26You'll see that it will use calculator
21:43:28to
21:43:37this is the response. Now you can also
21:43:39upload any documents. So if you are
21:43:40uploading right now so it will hit this
21:43:42route upload route / upload this one.
21:43:45Okay. And it will create the vector
21:43:47store. You can see that vector store
21:43:49would be created and you can perform the
21:43:51chat operation on top of that. Let's
21:43:52upload. Let's have a upload
21:43:55my resume.
21:44:00Done. Now you can see the uploaded
21:44:02documents as well. It is available in
21:44:03the upload folder. See the document you
21:44:05have uploaded. It is available. Now we
21:44:07can perform the chart operation. Who is
21:44:11Bier
21:44:13Ahmed Baki
21:44:17on PDF.
21:44:22Now it will use document search that
21:44:23means the rack tool. Okay. Now you can
21:44:25see that the my vector store is created.
21:44:27So this is my vector store. Okay. So
21:44:30this is the beauty of this um chatbot.
21:44:36Now see it is uh telling about me right?
21:44:39Okay. Everything is working fine. Now
21:44:41let's test the boys mode whether it's
21:44:42working or not. Um
21:44:47I'll give the permission.
21:44:50How many years of experience Bktier
21:44:52Ahmed Bi is having?
21:44:57Okay, it is not able to recognize my
21:44:59name.
21:45:01Okay, let me do it again.
21:45:06How many years of experience he is
21:45:08having
21:45:10now? Good. Now, let's send it.
21:45:20Now see based on the uploaded documents
21:45:21bkhmed bi has five plus years of
21:45:23experience. Amazing. It's working fine.
21:45:25Okay. Even you can do the wise mode as
21:45:28well. Dictate mode as well. Okay. Now
21:45:30you can select different different
21:45:31model. Let's I'll select this model. Now
21:45:33you can ask anything
21:45:35uh tell me about
21:45:38ML.
21:45:43Now see it is telling you about ML. Now
21:45:45you can generate code, you can uh do
21:45:49realtime source operation, you can
21:45:50upload your documents, you can use the
21:45:52voice mode, you can create different
21:45:54different trades. Okay. Anything you can
21:45:56do like chat GPT. Okay. So our
21:45:58application is prepared. Now we have
21:46:00given some suggestion. You can also use
21:46:02this suggestion to prepare a like
21:46:04instance prompt. Okay. Instant prompt.
21:46:06This is also possible. So yes guys uh
21:46:09that's how we have created the entire
21:46:11system and uh this is uh like a chat GPT
21:46:14application we have created our own chat
21:46:16GP we have created now we can deploy
21:46:19this application over the cloud and we
21:46:22can make it live so that other people
21:46:23can use it and uh my request would be to
21:46:26everyone just try to upgrade this uh
21:46:28application as much as you can just try
21:46:30to add integrate more features okay just
21:46:32try to integrate more features more tool
21:46:34see here I have used few tools right I
21:46:37have used very few tools here.
21:46:40Where's the tools?
21:46:42Here is the tools. Okay, I have used
21:46:43very tool few tools here. You can use as
21:46:46much as tool you can. Okay, just try to
21:46:48use as much as tool you can and make it
21:46:50like more powerful. Okay, now you can
21:46:55um also test the memory. My f colors is
21:47:02red.
21:47:13is red. Okay. Now you'll see that
21:47:16it will save this information in the
21:47:18memory.
21:47:20Okay. Now you can ask what is
21:47:25my favorite color.
21:47:33Now it will use the long-term memory to
21:47:36give you the response. Now see your
21:47:37favorite colors is red. Okay. Now you
21:47:39can also see in the long-term memory you
21:47:42can open this memory. You can go to the
21:47:44long-term memory. Refresh. So you'll see
21:47:47that my favorite color is red. Okay.
21:47:50Everything is available. Now in the lang
21:47:53also you'll see that it's tracing your
21:47:56execution. Now see GPT. Now all of the
21:48:00trades you can see even the trades as
21:48:02well in which trades how many
21:48:04conversation you have done each and
21:48:06everything you can see here okay all of
21:48:08this thing you can monitor here
21:48:10everything you can debug here okay see
21:48:12everything is available
21:48:14and this monitoring part also I told you
21:48:16in my playlist
21:48:18like how to monitor your AI agents and I
21:48:22already explained about this lang okay
21:48:24you can go through that so yes guys uh
21:48:26everything is working fine uh we are
21:48:29Uh now we'll try to deploy this project
21:48:31over the AWS cloud as a CI/CD. We'll
21:48:34just try to make it live because right
21:48:36now it's running on local host. Now
21:48:37we'll make it live. We'll try to do the
21:48:39CI/CD deployment here.
21:48:43So guys uh our app is ready. Now we'll
21:48:46be deploying this uh application uh as a
21:48:49CI/CD over the AWS cloud. But before
21:48:52that let me push all the changes uh
21:48:54because we have um updated all of the
21:48:58component one by one. So simply here I'm
21:49:01going to give
21:49:03um updated all component
21:49:14then I will push the changes
21:49:19and apart from that I also added the
21:49:21deployment step here as you can see uh
21:49:23this is the deployment step we'll be
21:49:25following
21:49:26uh let me show
21:49:31So now if I refresh in my GitHub
21:49:37so see all the codes are updated. Okay.
21:49:39And this is the deployment step guys
21:49:41will be following. So here first of all
21:49:43I will be logging with my AWS console.
21:49:45Then there I will be creating IM user
21:49:47that means identity access management.
21:49:49After that u uh there we'll just try to
21:49:53um give some of the permission. Okay.
21:49:56like what are the services we'll be
21:49:57using? So here we'll be using EC2
21:49:59instance and ECR elastic container
21:50:01registry. So in the elastic container
21:50:03registry we'll try to store our docker
21:50:05image. Okay, because we'll be using
21:50:07docker service here to containerize
21:50:09entire our application and uh we'll try
21:50:11to store in the ECR service. CCR is a um
21:50:15um I mean docker uh image storage
21:50:16service. So there you can store any
21:50:18kinds of docker image.
21:50:20Uh so this is the uh description for the
21:50:22deployment. First of all, we'll be
21:50:23building the docker image of our source
21:50:25code. Then we'll try to push this docker
21:50:27image to the ECR elastic container
21:50:29registry of AWS service. Then we'll
21:50:31launch our EC2 machine. Uh it should is
21:50:34a virtual machine. Then we'll try to
21:50:36pull uh our image from ECR to EC2. Then
21:50:40we'll try to run this u docker image as
21:50:42a container. Then we'll do some port
21:50:44mapping. After that uh we'll be able to
21:50:47access the application. And these are
21:50:49the policy we have to provide whenever
21:50:50we'll be creating the im user. Okay. So
21:50:52this is the entire step guys. I have
21:50:54written all of the command everything
21:50:55whatever you required I just mentioned
21:50:57it here. So you just try to follow this
21:50:58readmi file and we'll try to perform the
21:51:00deployment but uh beforeh doing the
21:51:03deployment guys you need some of the
21:51:04file here. Um let me show you what are
21:51:07the files you need. Yeah. So the first
21:51:09uh things you need which is the
21:51:11cic.imml.
21:51:13Uh but before that let's create a
21:51:15dockard file first of all. So docker
21:51:20file.
21:51:21Okay. So we'll be writing this docker
21:51:24file docker file and again uh if you are
21:51:27not familiar with docker uh then if you
21:51:29are not familiar with uh this kinds of
21:51:32mlops concept
21:51:34so on my YouTube channel I already have
21:51:36a complete uh mlops course guys here I
21:51:39have already covered all kinds of mlops
21:51:42tools like docker okay I have also
21:51:44covered linux mlflow dbch and everything
21:51:47but you don't need to cover all of them
21:51:49uh if you are completely new with the
21:51:50docker and all you can go through this
21:51:52recording. I think dockard starts here.
21:51:55Even you will see this u um timing.
21:51:58Okay. Uh this time stamp. So from here
21:52:01you can uh uh see right where is the
21:52:03docker. Simply you can uh click on the
21:52:05time stamp. You'll be able to see the
21:52:07docker. So just try to learn if you
21:52:09don't know about docker and if you want
21:52:11to understand the docker command just
21:52:13try to go through that recording. So
21:52:15here let's try to add all the docker
21:52:17related command. So this is our docker
21:52:21file. Okay. And these are the command
21:52:22you have to mention in the docker file.
21:52:24So first of all we're taking the base
21:52:25image and python 3.11 we are using. Then
21:52:28we're creating the working directory.
21:52:31Then we are setting some environment
21:52:33variable just to prevent some error.
21:52:35Then we are running these are the
21:52:37command and just to upgrade our uh um
21:52:40like Ubuntu instance and u install some
21:52:42tools. Then we're copying the
21:52:44requirement.txt. We are installing the
21:52:46requirement. TXT. After that we are
21:52:48copying all of the source code in the
21:52:49root directory. We are creating the
21:52:51folders like uploads and data. These two
21:52:52folders we're creating. Then after that
21:52:54we're exposing the port. We are running
21:52:56our application on port number 80080. So
21:52:59I think you have seen that this is the
21:53:01port. Okay. We are running our
21:53:02application. Make sure you are giving
21:53:04the same port. If you're changing the
21:53:06port here you have to also change. Then
21:53:08this is the command to run the our
21:53:09app.py server. So you can um app uh so
21:53:13we are um running the app.py. Inside
21:53:15app.py we are having this app object.
21:53:17Okay. We created this app object. So we
21:53:19are running it here. Then we're uh
21:53:21giving the host and as well as the put.
21:53:23So this is the docker we have to write.
21:53:25And if you're writing docker you need
21:53:27another file here called dot
21:53:31docker
21:53:33ignore.
21:53:35Inside that you will just write all of
21:53:37these folders and file you don't need
21:53:39whenever you are building the docker
21:53:40image. Okay. So these are the things I
21:53:42will avoid and that means any kinds of
21:53:44virtual uh environment or these are the
21:53:46file I'll just try to avoid whenever it
21:53:48will build a docker image it's kind of
21:53:50your g ignore. So whenever you are
21:53:51pushing anything in the g github right
21:53:53you are ignoring something in the get
21:53:55ignore these are the files. So same
21:53:56thing you have to write in the docker
21:53:58ignore if you want to ignore anything
21:54:00whenever you are creating the docker
21:54:01image. Okay. Yeah. Then uh docker uh
21:54:05file is done. Now we'll just try to
21:54:07create a folder. I'm going to name it as
21:54:09GitHub.
21:54:11Inside that you have to create another
21:54:13folder.
21:54:15The folder name should be workflows.
21:54:16Okay. Just make sure you are giving the
21:54:18same name otherwise it will not work
21:54:19because uh as a CI/CD tool guys here
21:54:22we'll be using GitHub actions. Okay. Uh
21:54:24I told you we'll be using CI/CD
21:54:26approach. So if you are pushing your
21:54:28code to the GitHub automatically it will
21:54:30get deployed over the cloud. Okay. We'll
21:54:31be creating that pipeline and as a CI/CD
21:54:34tool we'll be using GitHub action and
21:54:35GitHub action it is already available on
21:54:37GitHub. Okay, it is already um um I mean
21:54:40uh pre predefined setup. You don't need
21:54:42to set up the GitHub um um sorry uh this
21:54:45uh GitHub action server separately. It
21:54:47is already running on GitHub. So that's
21:54:49why you need this folder and workflows
21:54:51and inside that you will be creating a
21:54:52file called CICD
21:54:56yiml yml. Okay. So this is the file. So
21:54:59inside that you will you have to write
21:55:01all the CI/CD related command and these
21:55:04are the command you will be getting from
21:55:06the internet only. If you just search uh
21:55:09GitHub action CI/CD deployment um
21:55:11command you will see this kinds of uh
21:55:14code would be available over the
21:55:16internet. Even you can also generate
21:55:17from charge GPT. So this is the uh
21:55:19command I have prepared guys. Here I
21:55:20have mentioned all of these step and
21:55:22command you need to perform whenever you
21:55:24are doing the CI/CD. First of all we are
21:55:26giving the name of this workflow. Then
21:55:28whenever you are pushing your code on
21:55:30the main branch that time what will
21:55:32happen this will trigger. Okay. So in
21:55:35continuous integration what we are doing
21:55:37guys we are authenticating with the AWS
21:55:39account uh with the help of this secret
21:55:41key AWS access keys access uh secret
21:55:44access key and region we are
21:55:46authenticating then we are logging into
21:55:47the Amazon ECR we are building the
21:55:49docker image then we are pushing this
21:55:51docker image to the Amazon ECR. Okay.
21:55:53Then in continuous deployment what what
21:55:55we are doing again we are authenticating
21:55:56with the account our AWS account with
21:55:59this credential then we are logging into
21:56:00the ECR we are pulling that docker image
21:56:03and we are running inside our EC2
21:56:04machine. Okay so these are the commands
21:56:06I have written guys and you know that to
21:56:08run this application you need some
21:56:10environment variable. So these are the
21:56:12environment variable you need and all
21:56:13the environment variable I have
21:56:15mentioned here. Okay you can see I need
21:56:16Google API key, Google model, table API,
21:56:19lang. So whatever key you are using make
21:56:21sure you are adding in as environment
21:56:23variable. Okay. And we'll be write
21:56:24reading it from the GitHub um GitHub
21:56:26secrets. We'll try to add all of this
21:56:28credential in the GitHub secrets because
21:56:30directly I haven't mentioned inside my
21:56:32code. So that's why always secret file
21:56:34should be um written in secrets. Okay,
21:56:36GitHub secrets. So yes uh this is the
21:56:39entire cicd.iml and we'll be using this
21:56:42file for the deployment and uh I'll
21:56:44share all of these resources in the
21:56:45description. From there you can check it
21:56:47out. And if you want to learn more about
21:56:49this CI/CD. ML and again just try to
21:56:51check that uh MLOPS course there I
21:56:54already discussed about the CI/CD. Okay.
21:56:55So inside CI/CD I already explained that
21:56:57concept you can go through that. So yeah
21:57:00now uh let's try to follow the pipeline.
21:57:05So if I go to my GitHub. So this is the
21:57:08pipeline. First of all let's login with
21:57:09the AWS console. Make sure you have the
21:57:12AWS account guys. I already have the
21:57:14account. I'll just try to login.
21:57:17I'll just sign in with my management
21:57:19console.
21:57:34So here you just need to uh give your uh
21:57:39authentication
21:57:43authentication credential that means
21:57:44your email and password. So let's give
21:57:47my email and password and let me login
21:57:48with my AWS console guys.
21:57:52So this is my AWS uh console guys. Uh uh
21:57:56just try to login and you will be able
21:57:57to see this kinds of interface. So here
21:57:59the first thing uh what we have to do we
21:58:02have to create a IM user. Okay, let's
21:58:04create the IM user. So here just search
21:58:06for IM identity access management
21:58:14and uh here I'll just click on IM user
21:58:17create a new user I'll give the name
21:58:19let's say BPI GPT
21:58:23you can give any name you can attach the
21:58:26policies now here you need these are the
21:58:28policies Amazon EC2 full access and ECR
21:58:32sorry ECR and EC2 elastic container
21:58:35study and EC2 machine. So this is the
21:58:37service here. I'll just try to search
21:58:38and select
21:58:40uh then I'll just try to add another
21:58:42one. This one and
21:58:46um this one Amazon EC2 full access.
21:58:54Once we have done I'll just click on
21:58:56next. Now see both uh permission I have
21:58:58given. And why this permission is
21:59:00required? because I want uh I don't want
21:59:02to give the full access to my um to my
21:59:06uh let's say project whenever it will do
21:59:07the deployment uh otherwise um if any
21:59:11mistakes is there it will be using any
21:59:13other services as well okay there is a
21:59:14possibility so to prevent that we're
21:59:16only giving the permission the services
21:59:19we're using from AWS okay now I'll just
21:59:21create the user so user creation is done
21:59:24now I'll click on the user
21:59:26I'll go to the security credential
21:59:29and here you'll see one option call
21:59:31create access key. I'll select the first
21:59:33option command line interface and
21:59:35confirm do the confirmation. Click on
21:59:37next. Now let's create the access key.
21:59:39So this is our access key and secret
21:59:41access key you need to authenticate your
21:59:42AWS uh account from your Python client.
21:59:45Okay. Now I'll just try to download as a
21:59:47CSV file. Done. And make sure you just
21:59:50keep this file. Uh I need it later on
21:59:52whenever uh we just uh create the GitHub
21:59:56secret. Okay. I'll just try to open in a
21:59:58Notepad++. So this is the credential.
22:00:00This is your access key ID. This is your
22:00:02secret access key ID. Okay. Yeah.
22:00:04Perfect. Now let's click on done. Now
22:00:07the next step we have to follow. Uh we
22:00:10have to create the ECR repo to store the
22:00:11docker image. Now let's create the ECR
22:00:13repo. I'll go to the home and I'll
22:00:15search for ECR elastic container
22:00:18registry. Okay. So this is a fully
22:00:20managed docker container registry and
22:00:23this is the alter alternative of docker
22:00:24hub. Okay. The docker hub you used
22:00:26right. In docker hub also you can store
22:00:28the docker image here. Uh this service
22:00:30actually has created. Okay, this is this
22:00:32is the AWS container story. Now I'll
22:00:35just create a new reg. Give the name.
22:00:38I'll give
22:00:41GPT. You can give any name everything
22:00:44just keep it as it is. Now create this
22:00:46repository. Okay, this is the repository
22:00:48and copy this URI and keep it somewhere.
22:00:50Okay, I need it later on. So maybe in
22:00:52readmi file I'll just try to store here.
22:00:54Okay.
22:00:57Perfect.
22:01:00Now uh it is also done. Now I'll again
22:01:01click on home and see the next step.
22:01:04Next step is you have to create a EC2
22:01:06machine Ubuntu instance. Now let's
22:01:08search for EC2 EC2 instance virtual
22:01:12service in cloud.
22:01:16And here I'll just try to launch an
22:01:18instance.
22:01:19Uh click on launch without walk through.
22:01:23Now give the name. I'll give bi GPT
22:01:28machine
22:01:30again you can give uh any kinds of name
22:01:32here then you have to select this Ubuntu
22:01:34instance okay most of the production
22:01:36server would be Ubuntu and there are
22:01:38some other operating system as well but
22:01:39select the Ubuntu one now here you can
22:01:41uh you can select the instance type okay
22:01:46like uh how much memory how much CPU you
22:01:49need you can select from here so at
22:01:51least here I'll just try to select this
22:01:53four um sorry not this one huh uh 8 GB
22:01:59memory okay this 8 GB memory at least
22:02:01I'll be taking for this project and two
22:02:04CPU cores but if you have a very let's
22:02:07say uh I mean heavy project that time
22:02:09you can use some heavy instance here
22:02:11okay and all the instance how how much
22:02:13it will charge per hour it has already
22:02:15given you estimated cost so I'll select
22:02:17this one
22:02:18once it is done now you can create the
22:02:20key value pair
22:02:22this is optional uh optional means you
22:02:24have to create it if you want to access
22:02:26your EC2 instance from any third party
22:02:28tools like mobile extreme and putty that
22:02:29time it's required so I'll give
22:02:33GPT
22:02:34now let's create the key value here now
22:02:37see one p file would be downloaded this
22:02:39p credential you need whenever you want
22:02:41to use any third party tool but I don't
22:02:43want to use any third partyy tool I'll
22:02:44be using uh this um instance in the same
22:02:48AWS console only I'll tell you how to do
22:02:50that now just try to select these two
22:02:53options allow HTTPS and allow HTTP
22:02:55traffic and uh you can also select your
22:02:58storage like how much storage you need.
22:03:00So I'll take uh 8 GB storage as of now
22:03:02you can increase it okay as per your
22:03:04requirement. Let's say you can take 32
22:03:07GB or 16 GB as per your requirement.
22:03:10So here I'll just try to launch the
22:03:12instance
22:03:21now. Click on view instance.
22:03:29Now let's refresh. And you can see our
22:03:32instance is running. Okay. Now I'll
22:03:34click on this instance.
22:03:36And here you will see one option called
22:03:37connect button. Okay. Just click on
22:03:39connect. And if you are using any third
22:03:41party tools like mobile extreme and puty
22:03:44that time you can use SSS client to
22:03:45connect that. Okay. These are the
22:03:46command you have to execute.
22:03:48I'll just launch this uh terminal in the
22:03:50same AWS uh console only. Now let's
22:03:54connect that. Now see it will open a new
22:03:57window and there you will see a Ubuntu
22:03:59terminal and there you have to set up
22:04:01everything.
22:04:13So this is the Ubuntu terminal. Now
22:04:15let's clear. Okay. And if you don't know
22:04:18about Ubuntu again you can refer my
22:04:20course. So there I already discussed
22:04:22about the Linux operating system. Okay.
22:04:24How to run the Linux command each and
22:04:26everything. So first of all here uh I
22:04:28have already given all of the command.
22:04:30First of all you have to upgrade the
22:04:32machine. So these are the command you
22:04:33have to execute. Just try to copy and
22:04:35right click and paste and run.
22:04:39So this is a new launched machine and
22:04:41here I have to upgrade and set up all of
22:04:44the requirement tools I need here.
22:04:48Then I'll copy the second command
22:04:52and I'll execute.
22:04:56So I'll give yes permission.
22:04:59Yeah. So it will upgrade all of the
22:05:00tools. Now here I have to install the
22:05:03docker because initially there is no
22:05:05docker in this instance. So this these
22:05:07are the command you have to execute to
22:05:08install the docker.
22:05:24Okay, let's clear.
22:05:27Paste.
22:05:29Now I'll copy the next one.
22:05:43Then I'll copy the next one.
22:05:57Paste and run.
22:05:58Then the last command this one.
22:06:04Okay. So docker is installed
22:06:06successfully. Now you can check it. So
22:06:07docker
22:06:09version. You can see this is the version
22:06:12is running. Okay. Now the next thing
22:06:15guys uh we have to configure our EC2 as
22:06:17a self-hosted runner. That means we have
22:06:18to connect. Okay. We have to connect our
22:06:20GitHub repo with our AWS uh account.
22:06:23Okay. So that if you are uh committing
22:06:25any changes okay if you're pushing your
22:06:27code it will automatically deployed over
22:06:29the as cloud. So for this this is the
22:06:31connection we have to build. So for this
22:06:33make sure you are using your GitHub repo
22:06:35guys the same repo you are updating your
22:06:36project not my repo. So let's create
22:06:38another um tab here because I want to
22:06:42refer this command okay from this one.
22:06:44So now here you have an option called
22:06:46settings. Click on settings and there
22:06:49you will see an option called action and
22:06:50go to the runners. Okay. Now create a
22:06:53new self-hosted runner.
22:06:56Select this Linux
22:06:59and you have to execute these are the
22:07:00command one by one. Copy and execute in
22:07:02the terminal.
22:07:05So that's how we'll be connecting.
22:07:08Now next command and execute.
22:07:16Then again third command and execute.
22:07:24Done. Now we have this command
22:07:34done. Now I think uh we have executed
22:07:38all of this command. Now we have to run
22:07:39this configure command. Let's copy this
22:07:41and execute.
22:07:45Now see GitHub action initialized and it
22:07:47has connected to my GitHub. Now it is
22:07:49asking enter the name of the runner
22:07:51group. I'll press enter simply. Now it
22:07:53is asking enter the name of the runner.
22:07:55Okay. Now name of the runner is
22:07:58self-hosted.
22:08:00Self-hosted. Okay. Make sure you're
22:08:02giving the same name. I'll copy.
22:08:05And here I'll just try to paste it.
22:08:08Self-hosted. Then it is telling uh this
22:08:11runner will have any following labels.
22:08:13No. I'll press enter. Then it is telling
22:08:15name of the work folder. I'll again
22:08:17press enter. Okay. Done. Now the last
22:08:19command you have to execute this one. So
22:08:22if you execute your GitHub would be
22:08:24connected to the AWS. Now see connected
22:08:27to the GitHub and listening for the
22:08:28jobs. Now if I come to my repo now if I
22:08:32go to the runners again. Now you can see
22:08:35that uh this status is idle. That means
22:08:38my uh AWS is connected with my GitHub.
22:08:40Now if I push anything in my GitHub, it
22:08:43will automatically get triggered that
22:08:46CI/CD pipeline and all of the uh code
22:08:48would be deployed over my as cloud. But
22:08:50before that we have to set this
22:08:53credential. Okay, these are the secret
22:08:55credential in my GitHub uh GitHub
22:08:56secrets. So let's do that. So for this
22:08:59again uh here you will see one option
22:09:01called secret and variable. Click here
22:09:03and click on this action. Now here
22:09:06you'll see this repository secret. Just
22:09:08click on new repository secret and here
22:09:10you have to add all the secret one by
22:09:11one. Now first of all you have to add
22:09:12this Google API key or whatever API key
22:09:14you are using you can add here one by
22:09:16one. So this is my Google API key. Let's
22:09:22copy that.
22:09:26Yeah.
22:09:29A copy and paste it here.
22:09:36Done. Now next I will add my Google
22:09:38model.
22:09:47This the model
22:09:54that's how you have to add all of the
22:09:55secret one by one. Now API key.
22:10:11Now next you have this langid tracing
22:10:20should be true.
22:10:27Now lang speed end point.
22:10:38This is the end point.
22:10:50Now lang spit API key.
22:11:05Now next you have this lang project
22:11:12project name. So this is the project
22:11:14name bpg.
22:11:19Done. Now we have to add the AWS related
22:11:22credential. AWS access key.
22:11:27So why do you have the access key in the
22:11:29CSV file? I think you remember we have
22:11:30already downloaded. Let's copy this
22:11:32access key before the comma till here.
22:11:35I'll copy and paste it.
22:11:38Then next I have AWS secret access key.
22:11:46And in this file only you have the
22:11:48secret access key after this comma.
22:11:50Okay, whatever values you have just try
22:11:52to add in the secret
22:11:55H. Now next you have this head of this
22:11:58region.
22:12:05So right now I'm inside this region
22:12:07called North Virginia US East one. Okay.
22:12:10If you're in other region you can give
22:12:11the name. I'll give US East one.
22:12:17Make sure you are writing in same way.
22:12:23US East one.
22:12:25US East one. Okay. H the secret. Now
22:12:30last I have to add my ECR weapon name.
22:12:37So where do you have the web name? I
22:12:39think remember we copied one URI right
22:12:44here. So here is the name. Just try to
22:12:46copy after this slash and add it here.
22:12:51Done. Okay. All of these secrets we have
22:12:53added one by one. Now let's try uh it's
22:12:55time to commit our changes. I'll go to
22:12:57my repo.
22:12:59Now let's commit the changes here.
22:13:04CICD
22:13:08add it.
22:13:10Now push the changes.
22:13:15Done. Now if I refresh
22:13:18now see my action is running. We
22:13:20workflow is running. Now I'll click on
22:13:21action. Uh I'll open the CI/CD
22:13:25workflow. Now see continuous integration
22:13:27is running. So it is building the docker
22:13:29image and pushing it to the ECR. All of
22:13:30the execution you'll be able to see. So
22:13:32let's wait. This process may take some
22:13:34time.
22:14:13building is done. Now it is
22:14:16uh pushing the image to the uh ECR
22:14:20elastic container registry.
22:14:30You can even check in this year. So
22:14:34let's create a new tab and I'll go to
22:14:37the elastic container registry.
22:14:39So this is my registry. I'll click here.
22:14:41So see the image has been pushed.
22:14:44Okay. Now it is running continuous
22:14:45deployment. Now it will pull that ACR
22:14:49image and it will run on my EC2.
22:14:52Now see pulling is completed.
22:15:02Now see it will run the docker image as
22:15:04a container. Done. See all of the
22:15:06execution are green that means
22:15:08everything is fine. Now I'll come to my
22:15:10instance and there is a option um URL
22:15:13you will get public DNS. Just copy this
22:15:15URL and paste it here and execute. See
22:15:19initially this uh application will not
22:15:21open because right now this is running
22:15:22on port number 8080 but we haven't done
22:15:24the port mapping. So if you want to do
22:15:26the port mapping just come here and
22:15:28there is a option called security. Click
22:15:29on security. Go to the security groups
22:15:33and you have one option called edit
22:15:35inbound rules then add the rules and
22:15:38here just try to add port number 8080
22:15:41okay and just try to okay one more thing
22:15:44you have to add this 0000 that means you
22:15:46can access from anywhere then save the
22:15:47rules then I will go to my instance
22:15:52copy this
22:15:54URL again and at the last I will give
22:15:57port number 80080 okay now if I execute
22:16:00Now see my uh application is running.
22:16:03Okay. See our uh BGP is running and this
22:16:06is completely live right now. You can
22:16:08share this URL with anyone and they will
22:16:11be able to access. Okay. Now you can
22:16:12purchase any kinds of domain name. You
22:16:14can also change the domain here. Now
22:16:15let's test whether it's working or not.
22:16:18Okay. Now here I have given hi. It is
22:16:20giving hello how I can assist you uh how
22:16:22I can help you today. And it has also
22:16:24loaded my previous trades. Uh why?
22:16:26because in my GitHub I already um
22:16:29updated my database right so from
22:16:32database it is loading in the old
22:16:33conversation okay that's why you're able
22:16:35to see that see that now let's uh do the
22:16:37chat operation I'll tell my name is BP
22:16:46see now you can even create a new
22:16:48threads and you can do the conversation
22:16:50but let's continue here now here you can
22:16:54upload your documents
22:16:56your any kinds of documents that I will
22:16:59upload my
22:17:01resume.
22:17:06Okay. Now I'll ask who is book based
22:17:13on
22:17:14PDF.
22:17:17Now it is using my doc search tool and
22:17:19it is giving you the response. Okay. Now
22:17:21you can open search any latest
22:17:23information,
22:17:25latest
22:17:28news in
22:17:31um
22:17:33Bollywood.
22:17:41Now see realtime s operation it is doing
22:17:46and this is the latest news I got. So
22:17:49yes guys, everything is working fine.
22:17:51Okay. Now this is completely live and
22:17:53now if I let's say close my uh this uh
22:17:56this window that means this terminal
22:17:58still my application will be working.
22:18:00See. Okay. Now the best part is that uh
22:18:04if you push anything right if you push
22:18:06anything push any new ch
22:18:08uh automatically this pipeline will
22:18:11trigger and all of the new features
22:18:14would be added in in your um deployment
22:18:17server uh without uh let's say stopping
22:18:19your application. This is the main
22:18:21benefit. Okay. So this is the one time
22:18:24setup and rest of the life you can
22:18:26enjoy. Now here everything is done. Now
22:18:29uh we have seen the deployment. Now
22:18:31let's try to stop all the instance we
22:18:33have created uh because our landing is
22:18:35over. I don't want to keep it running
22:18:37otherwise it will charge me. And one
22:18:39more thing I want to show you this uh
22:18:40langismith monitoring. So if I go to my
22:18:43lang in bpgpt see the last execution.
22:18:47Okay it has done. Okay perfect. Now
22:18:49let's try to um terminate everything.
22:18:54So first of all I'll terminate my EC2
22:18:57instance.
22:18:59So select it and click here instant
22:19:02state and terminate and delete. Okay, if
22:19:04you stop it, it will stop but it will uh
22:19:06it will not delete. Okay, but I will
22:19:08delete it everything.
22:19:10Terminate and delete. Now see after some
22:19:13times it will delete it and shut down.
22:19:16Once it is done I will search for ECR
22:19:20ECR
22:19:22elastic container history and uh
22:19:25whatever history I created I'll select
22:19:26and delete it. I'll give delete message
22:19:35and confirm. Then I will delete my IM
22:19:38user as well.
22:19:45Now delete
22:19:47deactive
22:19:49right confirm and delete.
22:19:57Okay. So everything is deleted. Now this
22:19:59server is down.
22:20:19So see now this uh URL is down because
22:20:21we have deleted everything. So fine guys
22:20:24uh we have done. Um now I'll share this
22:20:27code and everything in the description.
22:20:29Uh from there you can check it out. I
22:20:32will add a beautiful readme here. Readme
22:20:35let's say uh information uh so that uh
22:20:38you can see all of the commands all of
22:20:40the steps in the readme itself. Okay.
22:20:42Now this was uh the as deployment. Now
22:20:45if you don't have the AWS account guys
22:20:47still you want to deploy this
22:20:48application and you want to test uh for
22:20:50this uh you can use render. Okay there
22:20:53is another one called render.com. you
22:20:55can use this uh platform and here you
22:20:57can do the deployment. Okay. So for
22:20:58render I already created a video in my
22:21:01playlist as you can see uh deploy aentk
22:21:03chatbot on render for free with docker.
22:21:06You can simply uh check this video and
22:21:08you will be able to deploy this uh
22:21:10project over the render cloud as well.
22:21:12Okay. So yes uh this is all about guys.
22:21:14I hope you like this uh uh
22:21:16implementation. If you found this uh
Project: Build TripMate AI End-to-End: Multi-Agent Travel Planner with Groq, LangGraph, PostgreSQL & FastAPI
22:21:18this implementation useful guys please
22:21:20try to subscribe to my channel. So this
22:21:22is my channel guys. Please try to
22:21:24subscribe. Uh let's hit uh 100k
22:21:27subscriber as soon as possible and uh I
22:21:30have lots of plan for this channel. I'll
22:21:33bring lots of content related agent MCP
22:21:36okay uh data science. So each and
22:21:39everything would be available in one
22:21:40place and uh if you want to connect me
22:21:42guys this is my LinkedIn profile. So
22:21:44here you can also connect me. You can
22:21:46also follow follow me here. So
22:21:47definitely um we'll try to keep in touch
22:21:50and if you have any kinds of question
22:21:52you can feel free to reach out here. So
22:21:54guys in this video I'll be developing
22:21:56one end to end multi- aent application
22:21:58with the help of Langraph.
22:22:01So in this video the application I'm
22:22:03going to develop the application name
22:22:05would be Tripate AI. So Tripmetate AI is
22:22:08a multi- aent uh application. Uh here uh
22:22:11you only just need to mention your trip
22:22:13location and this will uh give you the
22:22:16entire uh plan uh with respect to the
22:22:18location uh you are planning for the
22:22:20trip and this will also give you some
22:22:23amazing informations like uh your
22:22:26flights, your hotels. Okay. Then it will
22:22:28give you the travel itinerary even it
22:22:31will give you the day-to-day plan you
22:22:33will be making whenever you are on a
22:22:34trip. So this is a very much a cool
22:22:37application we'll be developing. Why?
22:22:39because uh we know that all of the uh
22:22:42people out there they are very much
22:22:45interested uh especially in trip
22:22:47especially about the travel. So let's
22:22:50say whenever we are planning for any
22:22:51travel let's say uh country A to B. So
22:22:55before going to that particular country
22:22:57we just need to make some plans right
22:22:59let's say um if I want to visit that
22:23:02country so which flight I have to take
22:23:05okay after let's say taking the flight
22:23:07um uh in which hotel I have to stay
22:23:10right then uh where I need to visit what
22:23:13are the me uh memorable locations there
22:23:15right even uh what would be my day one
22:23:18plan day two plan let's say I have that
22:23:20much amount of budget so how much money
22:23:22I should spend in day one day two like
22:23:25that. Okay. So this is the major problem
22:23:27um whenever we are planning for any
22:23:29kinds of trips. Okay. So why not we can
22:23:31create a multi- aent system so that
22:23:33agent will prepare the entire plan for
22:23:36us. Okay. Only just need to give the
22:23:38location. Let's say I want to visit uh
22:23:40let's say uh country A to B. Okay. I
22:23:43only just provide that much informations
22:23:45to my agent and my agent will prepare
22:23:47everything for me. Okay. Even I can
22:23:50download that particular plan as a PDF
22:23:52file and I can take it on my smartphone
22:23:54anytime and I can visit anywhere. Okay.
22:23:56So this is the system guys we'll be
22:23:58developing throughout the entire video
22:24:00and for this we'll be using some amazing
22:24:02tools and technologies. Okay. So guys uh
22:24:04first of all I want to show you the
22:24:06application demo how this application
22:24:07looks like and how this application will
22:24:09be uh working. Then after that we'll
22:24:12start the development. Okay. So to
22:24:14implement this uh entire system guys I
22:24:16have used some amazing technology. I
22:24:18have used a fast API. So it is running
22:24:21on fast API back end. Even I have used
22:24:23HTML, CSS and little bit of JavaScript
22:24:26to design the entire front end. Okay. As
22:24:28you can see this is a beautiful front
22:24:30end I have created. Then uh for this
22:24:32agent workflow multi- aent workflow I
22:24:34used langraph. Okay. And uh the large
22:24:37language model wise actually I'm using
22:24:39gro
22:24:41actually playground that means gro
22:24:43platform. So from the gro platform guys
22:24:46I'm using llama model. Okay. metal lama
22:24:48model then uh for the memory persistence
22:24:50memory I'm utilizing postgrace SQL
22:24:54database so if you know postgrace is
22:24:56amazing uh database okay whenever you
22:24:58are implementing this kinds of agentic
22:25:00application so postgrace you can utilize
22:25:03okay uh here uh this postgrace uh
22:25:06supports so many functionality whenever
22:25:09you are implementing this kinds of
22:25:10agents so for our uh persistence memory
22:25:13guys we'll be using postgrace database
22:25:15inside this development and Postgrace
22:25:17I'm not going to use the local Postgress
22:25:19server instead of that I have set up uh
22:25:22this uh Postgress on the render cloud
22:25:24okay my Postgress is running on my
22:25:26render cloud let me show you so this is
22:25:29my Postgress server it is running on
22:25:30render cloud so from here we just
22:25:33connected our application okay so right
22:25:35now this is not local anymore so if you
22:25:38close your local system as well still
22:25:40this uh this application will be running
22:25:43then for the realtime search operation
22:25:45guys uh for finding hotels or for
22:25:47finding uh different different uh
22:25:50itinary for a specific location we'll be
22:25:53using tably okay tably search tool so
22:25:55with the help of that we'll be doing the
22:25:57internet search realtime internet search
22:25:58and we'll try to figure out all of the
22:26:00latest informations about that country
22:26:02okay then uh for the flight information
22:26:05guys we'll be using uh aviation stack uh
22:26:07platform basically they provides a API
22:26:10key with the help of this API key you
22:26:11can get the entire flight informations
22:26:14okay for any kinds of country. So yes,
22:26:16these are my tool to tools and
22:26:18technologies we'll be using for this
22:26:20development and after this development
22:26:22I'm also going to show you how we can
22:26:23deploy this project over the render
22:26:25cloud. Okay. So here we are not only
22:26:28going to develop this project uh even
22:26:30after completing the development I will
22:26:32show you the deployment part as well. So
22:26:34make sure you watch this video till the
22:26:36end and if you found this content useful
22:26:38please try to subscribe to my channel
22:26:40and please try to share this with your
22:26:42friends and family and please guys hit
22:26:43the like and uh I need your support if
22:26:46you are supporting me guys definitely I
22:26:48can bring this kinds of content more and
22:26:50uh yeah it would be amazing okay
22:26:52altogether so please try to subscribe to
22:26:54my channel this should be my request to
22:26:56all of you so yes uh this is how my
22:26:58application interface looks like uh you
22:27:00can see this is a tripmate AI platform a
22:27:02multi- aent Travel planner with
22:27:04Langraph. So here basically you can plan
22:27:06your perfect trip with AI. You can
22:27:08search flight, discover hotels, generate
22:27:10a complete travel itinerary using multi-
22:27:13aent langraph system. Okay. Now for an
22:27:16example here what you have to give. So
22:27:18here you have a input box. So basically
22:27:21you can mention uh where to where you
22:27:23want to let's say go for the trip. You
22:27:25just only need to mention let's say here
22:27:27I have given some example. to plan a
22:27:28complete 7 days trip uh 7 days Japan
22:27:31trip from Bangladesh under one uh two
22:27:33two lakhs. Okay, let's say you have two
22:27:35lakhs budget. You can provide this
22:27:36information. So what I can do? I can
22:27:38copy this information. I can paste it
22:27:40here. Let's say maybe I can tell uh plan
22:27:42a complete 7 days. Let's say here I will
22:27:45give
22:27:48I'll get Nepal tool. Okay, Nepal trip
22:27:51from Bangladesh under two lakhs. Okay,
22:27:53so let's say this is my uh this is my uh
22:27:55let's say plan for the trip. Now simply
22:27:57you just need to click on generate
22:27:59plans.
22:28:00Now see um after some times you will see
22:28:04the entire plan would be ready. Even you
22:28:06can download this uh down download that
22:28:08plan as a PDF file. Let me show you. So
22:28:11guys uh as you can see uh it has
22:28:13successfully generated the 7 days Nepal
22:28:15trip from Bangladesh under u two lakhs
22:28:18taka. So as you can see this is the trip
22:28:21summary. Uh we have planned a 7-day uh
22:28:24Nepal trip from Bangladesh that includes
22:28:26a visit to Kathmandu then Pok uh Pokara
22:28:31then uh Chitwan and others exciting uh
22:28:33destinations and blah blah blah you can
22:28:36see. So first of all it has given the
22:28:37flight informations. Let's say if I want
22:28:39to visit Nepal. First of all, I have to
22:28:42uh I have to go to the Dhaka and Dhaka
22:28:45to Kathmandu. There is a flight and this
22:28:47is the flight information it is giving
22:28:49and the times as well when this flight
22:28:51is available. Okay. Then some hotel
22:28:54suggestion it is giving. So after you
22:28:55reach to Kathmandu so in which hotel you
22:28:58just need to stay and what would be the
22:29:00cost per night even it is also telling
22:29:02you. Apart from that it is giving you
22:29:04the dayby-day uh itinary. Here is the
22:29:06dayby-day itinary. Day one Dhaka to
22:29:08Kathmandu you will be visiting. Okay. Uh
22:29:11so it is giving you the entire step.
22:29:13Okay. See then when you reach the
22:29:16Kathmandu so in day two what should be
22:29:20your visit location? It is giving you
22:29:22the entire visit location. Okay. And
22:29:24what is the entry fee each and
22:29:25everything it is giving you. Then Kmandu
22:29:28to Pokara again it is uh giving you the
22:29:30plan. You have to take a bus or private
22:29:33card. Okay. And this is the estimated
22:29:34cost for that. Okay. So that's how it is
22:29:36giving you the entire summary. So then
22:29:38day four, day five, okay, day six, day
22:29:42seven and the entire estimated budget is
22:29:44also giving you like how much money uh
22:29:47uh I mean it will spend um in 7 days.
22:29:50Okay, if you're visiting Nepal. So it is
22:29:52giving you the estimated cost about
22:29:54flights, accommodations, transportation,
22:29:56food and activities, total budget. Okay.
22:29:59Then the final recommendation it is
22:30:01giving you uh you can see some final
22:30:03recommendation we are also getting. So
22:30:05yes uh if I get these kinds of things
22:30:07guys okay in just one place it would be
22:30:10amazing for us because otherwise what I
22:30:12have to do I have to individually search
22:30:14Google let's say what is the best hotel
22:30:16in Kathmandu okay and how much let's say
22:30:19price they are taking so I have to
22:30:21search individually I have to search the
22:30:23flight uh flight information
22:30:25individually I have to search hotel
22:30:27information individually okay I have to
22:30:29search this dayby-day itinary
22:30:31individually okay so yeah this take uh
22:30:33takes time And it needs lots of
22:30:35exploration, right? I I have to search
22:30:37on Google, go to different different
22:30:38website, just try to see their review.
22:30:40Then after that, I'll try to select this
22:30:42one. Then again, I have to note it,
22:30:44right? I have to take a note. Let's say
22:30:45I will visit uh A to B, B to C, okay?
22:30:48And it will take that much of money.
22:30:50This is the estimated time. I have to
22:30:51note everything. So that much time I
22:30:53don't have. So why not we can bring
22:30:55everything inside of one platform. Okay?
22:30:58One uh one let's say uh one system
22:31:01there. I only just need to give my uh
22:31:03trip plan and it will generate uh the
22:31:06entire plan for me. This is what we have
22:31:08developed guys. Okay. So this is very
22:31:10interesting and realtime application
22:31:12guys because right now these kinds of
22:31:14application you'll be uh seeing okay uh
22:31:16people are using there are some platform
22:31:18they are providing this kinds of let's
22:31:20let's say functionality only you just
22:31:22need to give the location and it will
22:31:23give you the entire trip plan for that.
22:31:25Okay. Now if I go to the cut uh Nepal
22:31:27right so I don't have any kinds of issue
22:31:29because I know what is the estimated
22:31:30cost there what is the best hotels there
22:31:33right what is the best flights there
22:31:35right uh in day 1 day 2 day three where
22:31:38I need to visit which which is the best
22:31:40location to visit there in 7 days all
22:31:42the information I have okay so I don't
22:31:46need anyone to guide me there is what
22:31:48guys will be doing now you can see there
22:31:50is a download PDF option if I click on
22:31:52download PDF so you can see this PDF
22:31:54file would be available Now you can take
22:31:56this PDF file on your smartphone okay or
22:31:58on your laptop anywhere you can take and
22:32:01you can just open it up and you can see
22:32:02okay what you have to do amazing right
22:32:05so yes guys this is the things we'll be
22:32:07developing even you can also copy this
22:32:09information and you can also paste it
22:32:11anywhere even you can also send it uh to
22:32:13your friends and family this is also
22:32:15possible okay so that's how not only uh
22:32:19not only Nepal you can give Japan Dubai
22:32:21Thailand okay global anywhere while You
22:32:24just need to visit just try to mention
22:32:26here you can generate the plan. Okay.
22:32:28With respect to that and uh I already
22:32:31told you this u uh this is also
22:32:33utilizing the postgrace database. All
22:32:35the information it is saving in the
22:32:36postgrace. This is uh already uh um
22:32:40postgress servers we have created on the
22:32:41render render server. Okay. Render is a
22:32:44cloud platform and let me show you I
22:32:47have my PG admin. So in PG admin I
22:32:50connected my remote server that means my
22:32:52render postgress server and here you can
22:32:54see the persistence memory checkpoint.
22:33:09So see these are my persistence memory
22:33:11checkpoint and you can see this is
22:33:13connected with render cloud. See this
22:33:15connected with render cloud. Okay. and
22:33:17all of me all of my persistence memory
22:33:20checkpoint all of my conversation are
22:33:22saved here okay even I'm also using
22:33:25langismith here
22:33:29to monitor my entire application
22:33:37so as you can see I'm using lang lang
22:33:40smmith guys to monitor my entire
22:33:41application it is using this travel
22:33:43agent uh project and it is monitoring
22:33:45the entire
22:33:47entire application. Okay. So yes guys uh
22:33:50that that's how we'll be developing this
22:33:52entire application end to end completely
22:33:54end to end we'll try to develop. So yes
22:33:56guys this is the entire uh application
22:33:59uh this is the entire application demo.
22:34:01Now let's start the development. So guys
22:34:03before starting the development first of
22:34:06all let's try to understand the
22:34:07application uh overview and the
22:34:10application architectures. So as you can
22:34:12see tripate AI this is a langraph
22:34:14multi-agent tribal planet system. So you
22:34:16can see this is a multi- aent travel
22:34:18planner that turns a natural language
22:34:21trip request into a practical travel
22:34:23plan with flight suggestions, hotel
22:34:25ideas and day-to-day uh itinerary. Uh uh
22:34:29the projects uh uses a multi- aent
22:34:31workflow built with langraph and why
22:34:34this project uh as you can see planning
22:34:36a trip usually means jumping between
22:34:39multiple websites, tools and
22:34:41spreadsheets. Okay, as I already told
22:34:42you, let's say if you're planning for a
22:34:44trip, right? Uh you have to visit
22:34:46multiple websites to uh look for the
22:34:48flights information, hotel informations,
22:34:51right? Then uh which location you just
22:34:54need to visit there, right? These are
22:34:56the things you have to uh explore and
22:34:57you have to take a notes on the
22:34:59spreadsheet or anywhere then um uh you
22:35:02will be making the entire plan. So this
22:35:03takes uh lots of time, right? And uh it
22:35:06needs lots of exploration even sometimes
22:35:08you you may miss out anything, right?
22:35:11Uh so this project brings that flow into
22:35:13one experience by combining a flight s
22:35:15agent, a hotel research agent and uh
22:35:19itinerary plan planning agent and a
22:35:22final response agents. Okay. Uh all
22:35:24coordinated through a langraph workflow
22:35:27that means in a single place we'll be
22:35:29combining all of them and each of the
22:35:31task would be mentioned to each of the
22:35:34agent. That means for the flight search
22:35:36operation we will be creating an an
22:35:38agent. For uh hotel uh hotel information
22:35:41we'll be defining another agent. For uh
22:35:44itinerary planning we'll be defining
22:35:46another agents. Okay. For final report
22:35:48generation we'll be defining another
22:35:49agents. That's how we'll be creating
22:35:51multiple agents together and those
22:35:53agents will be uh those those agents
22:35:56will be responsible for generating the
22:35:58entire trip summary for me. Okay. Trip
22:36:01plan for me. So that's why we call it as
22:36:02a multi- aent system. So here we are not
22:36:05utilizing one agent. We are using
22:36:06multiple agents and each of the agents
22:36:08will have some kinds of tools to
22:36:10complete that particular task. Okay. So
22:36:13here is the entire uh like architecture
22:36:15guys. As you can see for this project so
22:36:17first of all I already told you here
22:36:18we'll be utilizing uh multiple agent.
22:36:22As you can see here we'll be utilizing
22:36:24multiple agent. The first agents will be
22:36:25creating the flight agents. Okay. So
22:36:27basically this will search the flight
22:36:28and finds the best option for visiting
22:36:31location A to B. Okay. And for get uh
22:36:34and to get these kinds of flight
22:36:35informations, it needs some tools,
22:36:37right? And here we'll be using aviation
22:36:39stack API. So this aviation stack API uh
22:36:42what it it can do it can search realtime
22:36:44flight informations, right? And it will
22:36:47give you that particular flight
22:36:48informations to the flight agent and
22:36:49flight agent will try to utilize that.
22:36:51Okay. So optionally you can also use
22:36:53tably search here but I feel like uh
22:36:55aviation stack is having all kinds of
22:36:57flight integration in one place. So
22:36:58that's why we'll be using a aviation
22:37:00stack API key here. Then second agents
22:37:03will be developing this hotel agents. So
22:37:06what this hotel agent will it will
22:37:07search hotels and compares options. That
22:37:10means it will only look uh it is not
22:37:12only going to look for the agents. It
22:37:14will all it will look for the best
22:37:16hotels for you. Okay. Best hotels uh
22:37:18with respect to your budget, right? So
22:37:20this hotel information it will try to
22:37:22find and for this we will be using some
22:37:24kinds of tools. Right? And here we'll be
22:37:26using tably search. Okay. So tably
22:37:28search with the help of tably search
22:37:30we'll try to figure out the best hotels
22:37:32uh from that particular location and
22:37:34we'll try to give the suggestion
22:37:36optionally you can use Google place API
22:37:38this is optional but uh I'll be using
22:37:39tably tab search okay because this is
22:37:41completely free to use then the next one
22:37:44uh itinary agent so this basically
22:37:46creates the day wise itinary uh that
22:37:49means where you have to visit okay what
22:37:50are the activities you have to do there
22:37:52what are the best places okay each and
22:37:54everything this particular agents will
22:37:55try to uh get it for for you And again
22:37:58to get these are the information u the
22:38:00best in best visit location activities
22:38:03we'll be using tably API key again.
22:38:05Okay. So with the help of tab will
22:38:06perform the internet search operation
22:38:08and um real time will get the
22:38:11information and it will try to um use
22:38:13this information in my itinary agents.
22:38:16Then uh fourth I'll be using this final
22:38:18response agents that means it will be
22:38:19using all the information and will try
22:38:22to prepare the entire plan for you
22:38:24entire trip plan for you. Okay, that
22:38:26means it it combines all the information
22:38:27and generate a final response. And again
22:38:30for this we'll be using a large language
22:38:32model and the large language model wise
22:38:33we'll be using llama 3. Okay, and we'll
22:38:35be using gro provider. Uh I think you
22:38:38know grock provides some free uh free
22:38:40limits. Okay, you can generate uh API
22:38:43keys and you can access some model.
22:38:44Okay, completely free. You don't need to
22:38:45pay for that. But there is a limitation
22:38:47but it's fine. Okay, for this particular
22:38:49task I will be using this free API key.
22:38:51But if you want you can also take the
22:38:53subscription. You can uh use some
22:38:54premium model. It's completely up to
22:38:56you. Okay. So, yeah, we'll be using this
22:38:58uh hog rock provider here.
22:39:01Uh yeah, then uh you can see uh each of
22:39:04the agents will be connected to a shared
22:39:06state that mean shared memory h and we
22:39:08call it as a state. If you are already
22:39:10working in langraph, I think know there
22:39:12is a concept of state, right? We have to
22:39:14create the state and these are the state
22:39:15I need guys. Okay, I need user query.
22:39:18That means whatever user will pass, I'll
22:39:20save inside the user query. Whatever
22:39:22flight results I'll be getting, I'll try
22:39:24to save in the flight results. Whatever
22:39:25hotel results I'll be getting, I'll try
22:39:27to save in the hotel results. Whatever
22:39:29itinary response I'll be getting, I'll
22:39:31try to say save inside itary results.
22:39:33Whatever final response I'll be getting,
22:39:34I'll save inside final response. Okay?
22:39:36And whatever my agents will try to
22:39:38reply, okay? Uh that entire plan, I'll
22:39:41try to save inside my masses state. And
22:39:44this uh shared state will be uh storing
22:39:46inside one amazing database guys. We
22:39:48call it as a Postgress SQL. Okay. So
22:39:50this uh database we'll be using for my
22:39:53memory. Okay, memory memory purpose
22:39:54we'll be using that means we'll try to
22:39:56store all of the checkpoints all of the
22:39:57conversation here. Okay. So it will
22:39:59basically have the conversation story
22:40:01user preferences agents output and state
22:40:03updates. Okay. So this is the entire
22:40:06architecture guys we'll try to follow
22:40:07and we'll be implementing this entire
22:40:10agents. Okay. I hope you get it. So guys
22:40:13as you can see to develop this entire
22:40:15application I need the four agents here.
22:40:17uh the flight agent, hotel agent, then
22:40:20uh itinary agents and the fin final
22:40:22response agents. Okay. So we'll be
22:40:25developing four agents and we'll try to
22:40:27uh combine them all together and this
22:40:29will become a multi- aent system. Okay.
22:40:31Yeah.
22:40:34So first of all uh to implement uh this
22:40:36entire system guys what I need I need to
22:40:38create my GitHub repository. So uh there
22:40:41I'll try to create a repo and u I'll
22:40:44start uh writing the code.
22:40:51So for this let's open up my GitHub
22:40:53guys. I'll open up my GitHub.
22:40:57I'll go to my repository
22:41:00and let's create a new repo here. I'm
22:41:03going to give the name of this repo. So
22:41:06what I can do maybe I can copy this name
22:41:11and I can give it here. Okay, let's say
22:41:13this is my name
22:41:15and uh simply I'll just try to make it
22:41:18as public. Uh I'll add the readmi file.
22:41:21Get ignore wise I'll be taking python
22:41:25and license. Let's take this um MIT
22:41:28license. Okay, you can take any license.
22:41:30It's up to you. Uh okay, everything is
22:41:32fine. Now simply what I'll do, I'll just
22:41:35try to create this repository.
22:41:44Okay, so my repo is created guys. Okay,
22:41:46next thing I'll just try to clone this
22:41:48repo. I'll just uh click on this code
22:41:51and copy this HTTP URL and I will open
22:41:54up my local folder.
22:41:58So here I'll open up my terminal
22:42:01and let's clone it. So get clone
22:42:07paste that URL.
22:42:11So it has already cloned my repo. So now
22:42:13I'll go inside that. So cd the name of
22:42:15the repo is trip AI. Okay. So now I'm
22:42:18inside this folder. I'm inside this
22:42:21folder. Okay. Now here I'm going to open
22:42:22up my visual code studio.
22:42:32Okay. Perfect.
22:42:35So here I already moved my um
22:42:38architecture file which is
22:42:40demo.excaliraw.
22:42:41So here I'm using excali file format. So
22:42:44for this you have to install one
22:42:45extension called excali draw. Okay xcali
22:42:49draw. So this is the extension you have
22:42:51to install. So if you install you will
22:42:52be able to open this file guys. Okay.
22:42:54And here you will be getting this
22:42:55architecture diagram. So fine. Um yeah.
22:42:59Now next guys what I have to do? I have
22:43:02to first of all uh create the
22:43:03environment and we have to create the
22:43:05folder structure. So to create the
22:43:07environment guys um here uh what I can
22:43:10do I can write this step
22:43:19how to run
22:43:23first um create the environment
22:43:31virtual
22:43:34environment ment.
22:43:40So to get the virtual environment uh you
22:43:42have to use this command
22:43:51p
22:43:55rate
22:43:56hyphen n
22:43:59uh then you have to give the name of the
22:44:01environment. I will give let's say
22:44:06travel
22:44:08then I'll give the python version. So
22:44:11python is equal to 3.11. Okay I'll be
22:44:14using 3.11 and hyphen y that means I
22:44:17want to give the permission. So this is
22:44:18the command you have to use to create
22:44:19the environment. Then second you have to
22:44:22uh activate the environment.
22:44:30activate the environment.
22:44:37So to activate the environment you have
22:44:39to use this command
22:44:41panda activate
22:44:46travel.
22:44:51Then next you have to install the
22:44:53requirement file.
22:45:02Install the requirements.
22:45:07So we'll be using this command. So pip
22:45:09installer
22:45:13requirements
22:45:19txt.
22:45:21Okay. So yeah uh these are the step we
22:45:23have to follow. So first of all let's
22:45:25create the environment. I'll copy this
22:45:27command and I'll open up my terminal.
22:45:32Let's clear.
22:45:34Let's create the environment first of
22:45:35all.
22:45:38Okay. Uh there is a space I have given
22:45:40but uh the space should not be there. It
22:45:43should be hypen only. Okay. Now copy
22:45:45this again and execute it here.
22:46:13Okay, done. Now I have to activate the
22:46:15environment.
22:46:20So this is the command.
22:46:28See I have activated. Now I'll be
22:46:30installing the requirements. But for
22:46:32this I need to create the requirements
22:46:33file
22:46:35requirements.txt.
22:46:37Okay. So here I need to mention all of
22:46:40the requirements I need for this uh
22:46:43agent. So I already uh noted all the
22:46:46requirements I'll be using. So these are
22:46:48the requirements guys I need. I need
22:46:50langraph definitely to create the agent
22:46:52workflow. Langchen you need um because
22:46:55if you want to use langraph so langen is
22:46:58the dependency and uh uh whenever I want
22:47:01to load any large language model and all
22:47:02right I have to use the langen there
22:47:05then we'll be using grock provider uh
22:47:07that means lm provider that's why we'll
22:47:09be installing langen grog then langen
22:47:11community is also required then we'll be
22:47:12using tably search tool we'll be using
22:47:14langen tab and I told you I'll be using
22:47:17postgraql database for this I need this
22:47:19uh ps
22:47:22I cop g binary then uh uh this pull uh
22:47:26the uh these two things I need okay for
22:47:28this u uh database okay uh database and
22:47:32another thing I need this langchen
22:47:34checkpoint postgress okay these are the
22:47:35dependency for the database okay then
22:47:38python env to manage the environment
22:47:40credential so let's create this env file
22:47:44okay here we'll try to mention all of
22:47:46these uh credential secret credential
22:47:48then tavly python unit request library
22:47:50unit I already told you about the
22:47:52postgrace right uh I will save my
22:47:55checkpoints in the postgra database
22:47:57that's why this lang lang graph
22:47:59checkpoint postgrace is required then uh
22:48:02I'll also get the um um um I mean flight
22:48:06information right for this um I'll be
22:48:08using one um package called airports
22:48:11data so inside airports data some
22:48:13informations are available we'll try to
22:48:15utilize that then uh I'll be considering
22:48:17all of the country right whenever I'll
22:48:19try to search for the flights so that's
22:48:21There is another package called PI
22:48:22country. So inside that all of the
22:48:24country informations are available.
22:48:25We'll try to also use that. Then fast
22:48:27API for my entire u uh back end and
22:48:31front end development. Then uh first API
22:48:34dependencies u with help of uicon we'll
22:48:36try to launch the fast API server. Then
22:48:38the ginger ginger two templates. Okay.
22:48:40So these are the requirements guys I
22:48:41need and I already mentioned all of the
22:48:43version. Okay. And you should also
22:48:44mention the version. Uh otherwise what
22:48:46will happen? Let's say uh if you if you
22:48:49not mention the version. So if you're
22:48:51running this project after 2 month there
22:48:53is a possibility uh one of the package
22:48:55will get update and that functionality
22:48:57will be deprecated. Okay that time you
22:48:58will get the error. So that's why it's
22:49:00uh necessary to add the version. Okay
22:49:02this is super important. Now let's
22:49:04install the dependency. So I'll copy
22:49:05this command
22:49:07and I'll try to install the dependency
22:49:09here.
22:49:25Okay, let's wait uh once it is installed
22:49:28then we'll try to
22:49:31uh see the next step.
22:49:42So apart from this uh dependency, I also
22:49:44need to install some other tools as
22:49:46well. Let me show you.
22:50:00So installation is complete and there is
22:50:02no error. Okay, it's completely fine.
22:50:05Now guys, uh what I need I need some
22:50:07more tools. Okay, uh I told you we'll be
22:50:09using this uh PG admin to see my tables,
22:50:13right? My uh conversation checkpoints
22:50:15even you can also see the different
22:50:17different uh conversation it has saved
22:50:18right in in the memory. So you can able
22:50:21to see that because uh I'll be creating
22:50:23this uh postgrace server on my render
22:50:25cloud and to see that I need this uh PG
22:50:28admin. Okay, PG admin um this uh
22:50:31graphical user interface we have to
22:50:33install that. So let me close my PG
22:50:36admin and let me show you how to install
22:50:37this this PG admin. So if you want to
22:50:39install the PG admin guys uh only in
22:50:41just Google just try to search PG admin.
22:50:47Okay, PG admin download
22:50:50for Windows. So this is the website just
22:50:54try to visit
22:51:01uh or you can directly search like
22:51:02postgress download okay post
22:51:08postgra sql download so this is the
22:51:11website
22:51:13h here just try to choose your operating
22:51:16system let's say I'm using windows you
22:51:19can uh also select other operating
22:51:20system as
22:51:23And there is a option called uh download
22:51:25the installer.
22:51:27Okay. Now you have to [snorts] choose
22:51:28which one you will be downloading. So
22:51:30make sure you are installing the latest
22:51:31one. Okay. 18.4. So here is the download
22:51:34option. Just try to click here. It will
22:51:36start downloading that. Okay. So this is
22:51:39the uh file guys you have to download.
22:51:41Okay. This is around uh 400 MB you can
22:51:44download. So for me I already
22:51:45downloaded. I'll just try to cancel it.
22:51:47So once you have downloaded guys in the
22:51:48download folder you will see this uh
22:51:50file this uh uh postsql okay installer
22:51:54now you just need to double click and
22:51:55install this uh software okay inside
22:51:57your system. So I think you know how to
22:51:59install any software. Okay. The way you
22:52:01install any software just try to double
22:52:02click and do next next. Okay. Um it will
22:52:05ask for uh like u um password. Okay. You
22:52:08just need to set the password and you
22:52:11can complete the installation process.
22:52:13Okay. So once you have done the
22:52:14installation now simply you just need to
22:52:16search for PG admin. PG
22:52:20admin on your search bar. Now you'll be
22:52:21able to see this kinds of uh this kinds
22:52:23of application. Now let's open it up.
22:52:26Okay. So this kinds of interface you'll
22:52:27be able to see
22:52:36see this is my PG admin. So for me I
22:52:38already connected with the server that's
22:52:39why it's coming like that but for you it
22:52:42would be completely different. Okay. So
22:52:43maybe I can close this H. See for this
22:52:46you will be getting this [clears throat]
22:52:47kinds of window screen or welcome
22:52:48screen. Okay. So now uh what I have to
22:52:51do guys I have to set up this uh I have
22:52:55to set up this u u u postgress server on
22:52:58my render cloud. Okay, because I told
22:53:00you for this uh persistence memory we'll
22:53:03be using post P postgress, right? So how
22:53:05to install this Postgress server on the
22:53:07render cloud. Let me show you. So here
22:53:09I'll just visit the render.
22:53:12Okay, make sure you have a account on
22:53:14render. If you don't have account,
22:53:15please try to create one account for me.
22:53:17I already have the account. I'll just
22:53:18try to go to my dashboard.
22:53:20Let me close these other tab.
22:53:26So here uh to launch a postgra server
22:53:29guys you just need to click on new and
22:53:32there you will see one option called
22:53:34post grace postgrace okay postgrace
22:53:36database just try to click here so give
22:53:39the name of that uh postgrace
22:53:43I'll give let's say trip
22:53:50agent
22:53:54repagent uh let's say this is the name I
22:53:56have given now you can give the database
22:53:59name so I'll give let's say
22:54:03um
22:54:05I'll give trip memory
22:54:15or let's say agent memory
22:54:21Okay. Now you have to give the user. So
22:54:24I can give my user ID. You can give your
22:54:27any unique user ID. Here I have given
22:54:29ENT buff. Then um everything just keep
22:54:32it default. No need to change anything.
22:54:35Just here in the plan option you just
22:54:37select the free instance. Okay. So uh
22:54:40render provides actually free instance.
22:54:42You can use the free instance to launch
22:54:44this server. Okay. And if you want to
22:54:45take this subscription you can also do
22:54:46do that. But in free instance there is a
22:54:48limitation. I think after
22:54:517 or 14 days I think this instance would
22:54:54be deleted automatically. And here you
22:54:55are getting 200
22:54:5856 MB RAM 0.1 CPU and 1 GB storage.
22:55:02Okay. I think this is enough for our
22:55:04learning. But whenever you are creating
22:55:05any real world application production
22:55:07grade application whichever you will be
22:55:09using right uh that time you can take
22:55:11their subscription plan. Okay. No need
22:55:13to take the free instance that time.
22:55:16So yeah, everything just keep it default
22:55:17and simply just create the database.
22:55:25Okay. Uh it's uh giving one error
22:55:27because uh previously I also created one
22:55:29uh postgress server, right? So first of
22:55:32all I had to delete that one. So maybe I
22:55:35can delete that one.
22:55:39So this is the database I created,
22:55:41right? I'll just try to delete that.
22:55:45So if you're doing for the first time
22:55:46right uh you don't need to do that it
22:55:48will create but uh for me I created
22:55:51previously that's why it's coming like
22:55:52that. So I'll just try to delete it.
22:55:57Done. Now maybe I will be able to create
22:55:59that.
22:56:02All the informations are fine. Let's
22:56:04create the database.
22:56:06Okay. Now it is getting created. Okay.
22:56:08Now let's wait. This starter should be
22:56:10active. Once it is active then we can
22:56:12use this database.
22:56:37Okay guys, now you can see status is
22:56:39available. That means my um Postgress
22:56:42server is running successfully. Okay,
22:56:43you can check there. You can go to the
22:56:46dashboard and you can see it is
22:56:47available and this is running. Okay, now
22:56:49I have to connect this uh Postgress
22:56:51server with my PG admin so that I can
22:56:54see all of the uh table inside that all
22:56:56of the database inside that. Okay,
22:56:58whatever I'm going to create later on.
22:57:00So for this uh what I can do I can go
22:57:03below
22:57:05and there is a URL you have to copy.
22:57:08This is called external database URL.
22:57:10Okay. So render uh tells you if you are
22:57:13connecting this uh server in an external
22:57:16service that that means right now I'm
22:57:18using PG admin. This is the external
22:57:20service. Okay. This is running on on my
22:57:21local machine. So for this I have to use
22:57:24external database URL. Okay. But there
22:57:26is another one called internal database
22:57:28URL. As you can see this is the internal
22:57:29database URL. This is only required
22:57:31whenever you are deploying this project.
22:57:34That means let's say I am deploying the
22:57:36same project in the render cloud. Okay.
22:57:38And I'm using render postgress server
22:57:41that time I will be using internal
22:57:42database. Okay. So if you're only
22:57:45running your application in the same
22:57:47render cloud that time internal database
22:57:49should be used. Okay. Database URL
22:57:51should be used. But if you're running
22:57:52from the external one you have to use uh
22:57:55you have to copy this external database
22:57:56URL. Okay. Now let's try to copy that
22:57:58and make sure you don't share this URL
22:58:00with anyone otherwise they will be able
22:58:02to access your database. Okay. I'm going
22:58:04to remove I'm going to delete the
22:58:05instance after this recording. That's
22:58:07why I'm showing you. So I'll copy this
22:58:10and uh what I can do. Maybe I can save
22:58:13it somewhere.
22:58:16Let's I will save save this inside my
22:58:18readmi file.
22:58:24Okay. So this is the information I have.
22:58:27So this information I need to connect
22:58:30with my PG admin. So now let's open the
22:58:32PG admin. So there is a option called
22:58:34server. Just try to right click and
22:58:36there is a option called register. Okay
22:58:38just click on register and there is a
22:58:41option called server. Now here you just
22:58:43need to uh give the name of the server.
22:58:46So I'll give
22:58:48um
22:58:50tab agent
22:58:54or let's say tripmate
22:58:58server. I'll give my application name
22:59:01trip.
22:59:04So this is the name
22:59:08trip.
22:59:16Okay, I'll give tripmmet and uh just
22:59:19keep it as it is. Okay, then uh there is
22:59:22a option called connection. Just click
22:59:24on the connection and here you have to
22:59:25give the name. Okay, host name and where
22:59:28get get this host name? Host name should
22:59:30be uh this one.
22:59:33This should be the host name. See after
22:59:35add the rate, right? Whatever you have
22:59:37just try to copy till.com render.com.
22:59:39This is your host name. Just try to copy
22:59:42and provide it here.
22:59:46So this is the host name. Okay. Now by
22:59:49default uh this postgress run runs on
22:59:52port number five uh 5432. No need to
22:59:55change change this. Now you have to give
22:59:57the database name. Okay. So what is the
22:59:59database name? So here is the database
23:00:02name agent memory.
23:00:10So just try to copy this.
23:00:13This is the name. You can also verify
23:00:16simply go to the
23:00:19server
23:00:21and here is the database. Okay. So this
23:00:23is the name actually it has taken for
23:00:24the database. So I have given agent
23:00:27memory but it has added this uh 68 K5
23:00:32because it should be unique name. Okay,
23:00:33that's why this information has added.
23:00:35Okay, just try to copy this and add it
23:00:37here.
23:00:39Okay, now it has u it is asking for the
23:00:42username. So what is the username? I
23:00:45think you remember I given the username
23:00:47entpo
23:00:49verify in the postgress
23:00:51server.
23:00:53here. So, username is yenduppy. Let's
23:00:55copy and paste it here. Now, I have to
23:01:00give the password. Okay. Where to get
23:01:01the password?
23:01:03Here is the password.
23:01:05This is the password. Okay. Let's copy.
23:01:08Even it is also available on my URL. So,
23:01:10this is the URL. Okay. This is the
23:01:12password. Just try to copy and paste it
23:01:15here. Okay. Then just try to activate
23:01:18this one. Save password on. And uh yeah,
23:01:22everything is fine. Now simply
23:01:26let me check everything is required or
23:01:28not. No, I think everything is fine. Now
23:01:29I'll just try to save this information.
23:01:36See once you will do that it will be
23:01:39connected to the uh render postgress
23:01:42server. Okay. Now you can expand it. Now
23:01:45you can click on database. Now see this
23:01:47agent memory uh 68 uh 68 K5 agent memory
23:01:5468 K5 okay this database I can see
23:01:57because this is already connected now
23:01:59whatever tables you will be creating
23:02:00inside that it would it would be
23:02:02available inside PG admin okay I can see
23:02:04all the tables so this this table now I
23:02:07can refresh and simply
23:02:09uh see right now there is no table uh we
23:02:11haven't created but once I will try to
23:02:13create the table you'll be able to see
23:02:14all the tables okay all of the
23:02:16conversations be available. So see so
23:02:18far we have connected our uh Postgress
23:02:20server with my PG admin. Now right now
23:02:22you have the graphical user interface
23:02:24and from there you can see all of the
23:02:27tables you will be creating going
23:02:28forward. Okay so that means my Postgress
23:02:31installation is completely done.
23:02:32Postgress setup is completely done and
23:02:34this is running on my render cloud.
23:02:37Okay. I hope you get it.
23:02:39So guys, we have successfully uh set up
23:02:41our postgrad server on the render and we
23:02:44have connected with our PG admin and
23:02:46this is running completely fine. Now I
23:02:49need to set up some additional uh
23:02:51additional let's say keys which is
23:02:53required for this development. So first
23:02:55thing I need the um I need the aviation
23:02:59stack API key. Okay.
23:03:03Um aviation stack API key.
23:03:06Then I need
23:03:09Gro API key. Okay, first of all, let's
23:03:12collect the Gro API key. Okay, our LLM
23:03:15provider API key because here I told you
23:03:17I'll be using a metal lama model. Okay,
23:03:19llama 3 model from the Gro Gro provider.
23:03:23Then um I need
23:03:27table API key.
23:03:33Then I need uh my database URL.
23:03:37Okay, that means my postgress database
23:03:39URL. And we already copied the URL. I
23:03:41think you remember that external URL.
23:03:43I'll just try to copy this as it is.
23:03:45Let's cut it. Okay. And I'll try to save
23:03:48inside this variable.
23:03:52So this is the URL. Okay. So with this
23:03:54URL, my Python client will be able to
23:03:57connect with my Postgress server. It
23:03:59will store all of the conversation
23:04:00there. Okay. So make sure you copied
23:04:03this external URL, the URL we just
23:04:05copied. Okay, external URL this one and
23:04:08try to save here. Okay, then I need um
23:04:12some other things like my lang uh API
23:04:17key and tracing. These are the things I
23:04:19need. Let me show you
23:04:24because uh to monitor to trace the
23:04:27entire application we'll be using lang.
23:04:29So this is the lang. Okay, lang speed
23:04:31tracing it should be true. Lang speed
23:04:33endpoint. So this is the URL you have to
23:04:35provide and lang API key we have to
23:04:37collect. Okay. So let's delete this API
23:04:39and I'll collect my own API and lang
23:04:42project name. So let's say I'll give uh
23:04:45travel agent. Okay. Or let's say I'll
23:04:47give uh my project name which is
23:04:51tripmmeti.
23:04:59Let's say this is my project name. Okay.
23:05:02Now let's collect all of the API key one
23:05:03by one. Okay. One more thing I have to
23:05:05add which is the default origin data.
23:05:09H default origin data [clears throat]
23:05:10means let's say here the things you have
23:05:13to do. You have to give the location A
23:05:16to B. Let's say you want to visit India
23:05:18to Thailand, right? So India is your
23:05:21origin, right? And Thailand you want to
23:05:24visit. So by default if user is not
23:05:26providing origin let's say user is
23:05:28giving the prompt like that uh I want to
23:05:32visit Nepal. Okay. So you are not giving
23:05:35the origin here. So by default uh you
23:05:38can set the origin here. Okay. Let's say
23:05:40which your origin. So let's say I'm from
23:05:42Dhaka right now. So I'll give D A C.
23:05:45Okay. That means Dhaka. So from Dhaka it
23:05:47will plan to the different country.
23:05:50Okay. That means Dhaka is the origin
23:05:51right now for me. Okay. I I hope you get
23:05:54it guys. Okay. So that's how we can add
23:05:57a default origin. If user is missing
23:05:59their origin, you it will automatically
23:06:01take the default origin. Okay, you can
23:06:02change this origin as per your
23:06:03requirement. If you're in let's say
23:06:05Thailand, you can give Thailand. If
23:06:06you're in let's say USA, you can give
23:06:08USA. Okay, it's up to you you. So yes,
23:06:11uh this is how we have to add all of the
23:06:14API key. Now let's collect the Gro API
23:06:15key first of all. So what I will do,
23:06:17I'll just uh go to the Gro platform. So
23:06:21you can search for Gro
23:06:24Gro API key. Okay, simply search for
23:06:26Grock API key and um go to the first
23:06:29website
23:06:36and uh you can create a API key here.
23:06:38Okay, so let's create a API key.
23:06:43So what I can do, I can maybe remove my
23:06:46previous API key.
23:06:52Now I'll create a new one. I'll give the
23:06:55name. Let's say I'll give um
23:06:58my trip agent
23:07:08tripment no expiration just try to keep
23:07:11it here. If you want expiration you can
23:07:12also select. Now let's submit.
23:07:21Now this is your API key. Just try to
23:07:23copy and make sure you are adding inside
23:07:25your environment variable. Okay. Yeah.
23:07:29Now you can ask me I have given double
23:07:30quotation here but in the database URL I
23:07:33haven't given any document uh double
23:07:34quotation. See whenever you are adding
23:07:36the database URL no need to give any
23:07:37double quotation. Okay. Uh because
23:07:40database uh URL is a sensitive
23:07:42information. If you are give quotation
23:07:44sometimes it will also consider as a
23:07:45quotation uh as this u as this URL.
23:07:49Okay. So that's why I'm not giving any
23:07:50kinds of quotation. Perfect. So we have
23:07:52successfully copied the gro grapi key
23:07:55and uh inside gro you will be able to
23:07:57see different different models are
23:07:58available. Let me show you if I go to
23:08:01the dashboard
23:08:04I think playground and here you have
23:08:06different different model. So here I'll
23:08:08be using meta llama model. Okay. You can
23:08:11also use any other model. It's
23:08:12completely up to you. Then the next
23:08:14thing guys I need my aviation stack API
23:08:18key. Okay. So let's search for aviation
23:08:20stack API key. You can simply search on
23:08:23Google aviation stack API key. So this
23:08:26is the first website. Just go to the
23:08:28website.
23:08:30Okay. So this is the website guys. Now
23:08:33here you will see one option get free
23:08:35API key. But for this you have to sign
23:08:36up. Okay. Sign up in their account. So I
23:08:39already have the account. I'll try to
23:08:40login.
23:08:42Let's give my email and password
23:08:45and login.
23:08:50Okay. So I've lo I've logged in. Now
23:08:52here you have the API key. Okay. Just
23:08:53try to copy this API key. Uh this is the
23:08:56API key as you can see. Just try to copy
23:08:59and you paste it here.
23:09:03Okay. This is my aation stack API key.
23:09:05So we need this aation stack API key to
23:09:07get the realtime flight information.
23:09:09Okay. Uh so as you can see this is the
23:09:13interface
23:09:18so free realtime flight status and
23:09:20global aviation data API. Okay. This
23:09:22provides flight tracker airport
23:09:25uh timetable data web service trusted by
23:09:28uh 5,000 plus of smart test company.
23:09:31Okay fine. Now the next thing I need
23:09:34which is uh table API key. Okay. For
23:09:37realtime source operation I think you
23:09:38saw the diagram right? So I have already
23:09:41collected my aviation stack API key and
23:09:43gro API key. Okay, for the large
23:09:45language model provider. Now for
23:09:46realtime source operation I need tably
23:09:48API key. Now let's collect this tably
23:09:50API key. So for this on Google just try
23:09:52to search for tably API key. Go to the
23:09:55tabi
23:10:00and make sure you login with your
23:10:02account.
23:10:04Okay. Now here you have the API key.
23:10:06Okay. So previously I already have some
23:10:08API key. Maybe I can collect or maybe I
23:10:11can create a new one. So let me delete
23:10:13some of the API key.
23:10:19I'll create a new one. I'm going to name
23:10:21it name it as let's say
23:10:24my project name.
23:10:29Now simply create the API key.
23:10:33Okay. Now copy this one and add inside
23:10:37your environment variable
23:10:41H. Now [clears throat] last thing I need
23:10:43my Langismith API key for the tracing.
23:10:46So we'll be using Langismith platform.
23:10:47So you can search for
23:10:48smith.langchen.com.
23:10:50So this is the langismith platform. So
23:10:52if you don't have account guys please
23:10:54try to create one account. Uh so I
23:10:56already logged in with my account. Okay.
23:10:59But for you it will look like that.
23:11:01Okay. So once you have done that uh you
23:11:04have to collect the API key. So left
23:11:07hand side you will see one option called
23:11:08settings. Now here is the API key
23:11:11section. Okay. Just create one API key.
23:11:14So I'll create one API key here.
23:11:20You can give the name.
23:11:30Okay. Just keep it as it is.
23:11:33Now expiration date you can give it as
23:11:36never and create the API key. Now copy
23:11:39this API key and mention it here.
23:11:44Okay. And give the name of the
23:11:47langismith project. I have given uh trip
23:11:49AI. So it will create this project
23:11:51inside that you will perform all the
23:11:52tracing. Okay. So yes uh that's how we
23:11:54have collected all of the API key
23:11:56whichever we needed here. Now uh we what
23:11:59we'll do guys, we'll just try to define
23:12:01the folder structure. Then we'll try to
23:12:03um implement the component one by one.
23:12:08So guys, now let's try to define our
23:12:10folder structure.
23:12:12So first of all here uh what I'm going
23:12:14to do, I'm going to create a folder. I'm
23:12:17going to name it as tools. So inside
23:12:18that I'm going to create all of my tools
23:12:21I need uh for this development. So I
23:12:23think you know I need some tools like uh
23:12:25these aviation stack tools. So this
23:12:28function I'll be writing separately. So
23:12:29it will get the realtime flight
23:12:31informations. Then for hotel agents I
23:12:33need tabby right. So tab will do the
23:12:35realtime source operation. It will get
23:12:37the uh different different uh
23:12:39information let information. For this I
23:12:41will be creating another function. Okay.
23:12:43So that's how I need separate separate
23:12:44tools and this thing I'll try to define
23:12:46inside my tools. So let's uh create some
23:12:48file inside that. So first of all I'm
23:12:50going to
23:12:53define a constructor
23:12:57init_.py.
23:12:59Now inside that let's create a file. I'm
23:13:02going to name it as flight 2.py
23:13:12and I'm going to create another file.
23:13:13I'm going to name it as tabulator.py.
23:13:27Okay. Yeah. Now, uh I need another
23:13:34um
23:13:37another files here.
23:13:42I'm going to name it as back end
23:13:51dotpy.
23:13:53Then I'm going to create another file
23:13:55called app.py.
23:13:57So this is going to be my endpoint.
23:13:59Okay. And uh I'm going to create another
23:14:02folder called templates. So inside that
23:14:05I'll write try to write my front end
23:14:07codes that means HTML codes. write
23:14:10templates inside that I'm going to
23:14:12create a file called index
23:14:14dot HTML. So here we'll try to write all
23:14:17of the HTML code because I told you
23:14:19we'll be using HTML CSS JavaScript with
23:14:22the first API and first API needs this
23:14:24template folder and this uh HTML file
23:14:27and whatever CSS and um uh JavaScript
23:14:30file uh I'll be writing it should be
23:14:32available inside static folder
23:14:35okay static folder inside that I'm going
23:14:37to create two more file one is style
23:14:43dot CSS other this uh script.js.
23:14:56Okay. And if you don't know about HTML,
23:14:58CSS, JavaScript, no need to worry. Uh
23:15:00simply you can take the help from chart
23:15:02GPT and you can create this at the user
23:15:04interface for you. Okay. So yes, these
23:15:06are my folders and file I need for this
23:15:09development. Now let me close this at
23:15:11the one by one.
23:15:17Now let me commit the changes on my
23:15:19GitHub. So simply I'll tell folder
23:15:24structure
23:15:26addit.
23:15:38Now if I go to my GitHub refresh
23:15:41see all of the folder structures are
23:15:43available. Okay. So later on I also need
23:15:46dockard file. Uh I will use that
23:15:47whenever I'll do the deployment. Okay.
23:15:49As of now it's completely fine. Now
23:15:51first of all uh what I can do guys?
23:15:53First of all let's say um here
23:15:57I'm going to define the tool. Okay.
23:15:59First of all let's write this tably
23:16:01tool.
23:16:07H so I already installed the uh
23:16:10environment and the environment name is
23:16:15travel right I think I created travel
23:16:17I'll select this environment okay now
23:16:18let's import some necessary package so
23:16:20I'll import tavly
23:16:23import
23:16:25tavi client okay then I need operating
23:16:28system
23:16:30then I need so from
23:16:34env import
23:16:36load 4 DNB done. Now I'll try to load my
23:16:39environment variable
23:16:42H then let's create a table client first
23:16:44of all. So client
23:16:47is equal to table client.
23:16:52So first of all inside that you have to
23:16:54pass the API key. So why do you have the
23:16:56API key? API key is available inside my
23:16:58environment. I'll just write west dot
23:17:00get env. Okay. get
23:17:04uh
23:17:06env.
23:17:08And what is the name of my key?
23:17:12The key name is
23:17:15Table API key. I'll copy this and paste
23:17:18it here.
23:17:24So this is going to be uh this is going
23:17:26going to give me the client. Okay. So
23:17:28after that here we'll just try to write
23:17:30a function. So div tab search
23:17:39inside that uh it will take a query that
23:17:41means the search query.
23:17:45Okay. And uh it will search over the
23:17:49internet. So for this I'll just try to
23:17:51write response
23:17:53is equal to client
23:17:56dot search. Okay. And inside search I
23:17:59will give my query
23:18:02query is equal to my query and there is
23:18:05another parameter you have to give
23:18:07called max result. Okay that means how
23:18:08many maximum search result you want. So
23:18:11I need five results. Okay five search
23:18:13results I need.
23:18:15Then then whatever results I'll try to
23:18:17get guys I'll try to uh I'll just try to
23:18:20do some refinement operation that means
23:18:22it will also give me some uh some kinds
23:18:24of metadata but I don't need the
23:18:26metadata. I only need the content,
23:18:28right? And to filter out, I have written
23:18:30this code.
23:18:36Let me show you.
23:18:39First of all, let's define the result.
23:18:46So it it is going to be empty list.
23:18:48Okay.
23:18:49So this is the filter code I have
23:18:51written. So it will run a for loop.
23:18:53Okay. So um it will run the for loop on
23:18:56the response result and it will get the
23:18:58title URL snippet. Snippet means the
23:19:01content and uh it will length the
23:19:03snippet if the snippet it is more than
23:19:06300 words. So what I'm going to do I'm
23:19:08going to split it and I'm going to
23:19:11append in my result uh result list.
23:19:13Okay, that means I'm only taking the
23:19:16content uh from my source result instead
23:19:18of some metadata. Okay. So yeah, I think
23:19:22um
23:19:24[clears throat] it's done. Uh even you
23:19:26can also uh I mean remove this if you
23:19:28don't want. So this thing I have added
23:19:30just to keep only the first 300
23:19:32character to avoid wall of text. Okay.
23:19:35So that's why but if you want you can uh
23:19:37take the entire snippet if you want.
23:19:39Okay. Uh it's up to you. Uh because we
23:19:42are using a free large language model
23:19:44and definitely some input output
23:19:46limitations are there. Tken limitation
23:19:47are there. So that's why I've taken like
23:19:50some um some like important first
23:19:53character instead of um I mean the last
23:19:56one but you can uh you can ignore this
23:19:59line. Okay, maybe you can directly take
23:20:01the snippet and you can add inside the
23:20:02results. Okay, this is completely up to
23:20:04you. So this is my uh tably search
23:20:06function. Okay, now let's test whether
23:20:08it's working or not. So what I can do
23:20:10maybe I can create another file here.
23:20:12I'm going to name it as test.py.
23:20:15Let's import this
23:20:18from tools
23:20:22dot tably.
23:20:25import taby source.
23:20:30Now
23:20:31let's define an object. I'm going to
23:20:34call the table s. Inside that I'm going
23:20:36to give a query. So let's say I'll give
23:20:39um best hotels
23:20:46in
23:20:48India
23:20:50and I'm going to print the response.
23:20:56Now let's execute.
23:20:58So python test.py.
23:21:04So you can see this is the information
23:21:05we are getting. Best hotels in India. So
23:21:08it is uh uh see it is referring
23:21:11different different website realtime
23:21:13website. Okay. Uh that means
23:21:15tripadvisor.com [snorts]
23:21:18and it is finding some best website uh
23:21:21hotels. Okay. Then some other YouTube
23:21:23resources also it has u referred some
23:21:26review it has uh seen right and it is
23:21:29giving you some best hotels in India.
23:21:30Okay. So that's how we are getting best
23:21:33out of all of the uh all of the let's
23:21:36say resources out there with the help of
23:21:38this tablely instead of manually
23:21:40exploring. I have the table. I can
23:21:42search like I need best things. It will
23:21:44automatically search over different
23:21:46different website, hotels. Okay. And it
23:21:48will give me those information. Okay.
23:21:50For my agents, this is the idea. See?
23:21:52Okay. It is referring that URL. That
23:21:56means this function is working
23:21:57completely fine. There is no issue with
23:21:58this function. Now, simply I'll just try
23:22:01to
23:22:03open up my code again. Yeah. Now, next
23:22:06guys, I'll be writing my flight tools.
23:22:08Okay. This uh tools I have to write. Now
23:22:10this will give you that realtime flight
23:22:11informations. Okay. So for this let's
23:22:14import some necessary library. So I need
23:22:16hovering system.
23:22:19I need regular expression.
23:22:22I need certify.
23:22:29I need
23:22:34air
23:22:37airports data. I need pi country
23:22:48then I need. So from env
23:22:52import load env.
23:22:57Okay then I'll load the environment
23:23:00variable.
23:23:02After that um see if you're using
23:23:04Windows operating system uh you might
23:23:06get a path issue. So to prevent that we
23:23:08add this two line SSL uh uh sert files
23:23:13and request key bundles. Okay you have
23:23:15to give certified dot wire. So if you're
23:23:18uh getting the path issue that time you
23:23:20can give. Okay. So I have given uh for
23:23:22this sest purpose. Then first of all I
23:23:24have to get my aviation API key. So I'll
23:23:27just write API key is equal to
23:23:35OS dot get env. Okay. And what is the
23:23:40name of that? And the name of that is
23:23:43aviation API key. Aviation stack API
23:23:45key. I'll just try to get this API key.
23:23:49So once you get the API key, you also
23:23:51need to take the origin.
23:23:56See I'm taking the origin as well.
23:23:58Default origin we mentioned Dhaka here
23:24:01but if you want you can also change it
23:24:03as per your requirement. Okay. So here
23:24:05my default origin is dhaka. If user is
23:24:06not giving any default origin it will
23:24:08take the dhaka otherwise uh it will take
23:24:10the default uh uh it will take the
23:24:12origin. Okay. From the user query then
23:24:15uh what is the base URL for aviation
23:24:17flights. So this is the base URL. You
23:24:20can visit the base URL. So here you have
23:24:23to give a API key. If you give the API
23:24:24key, this will give you the this will
23:24:26return you the aviation. Sorry, this
23:24:28will return you the flight information.
23:24:29Okay. So, we are hitting this website
23:24:31API. Okay. Now, uh first of all, I will
23:24:35load the airport's data. So, to load the
23:24:38airports data, you have to use airports
23:24:40data.load. Then you have to give I uh I
23:24:43a
23:24:46give you all the airports. Then I will
23:24:48also mention my country allias
23:24:54because sometimes uh user may pass the
23:24:57allies information right let's say user
23:24:59will give us US means USA okay that's
23:25:01how it it has all the allies name for
23:25:04all the country let's say Korea K R
23:25:06Dhaka uh D AK right I already told you
23:25:09so this is called allies so we are
23:25:11defining the allies then country many
23:25:15airport.
23:25:16So all the country main airport I'll
23:25:18just try to mention here. So these are
23:25:21the airport name. Okay. So B, DA, India,
23:25:25Dell like that. Then city main airport
23:25:32these are my city many airports. Okay we
23:25:35are defining.
23:25:38Then we'll just write a function for
23:25:40cleaning the text. So clean text. So it
23:25:43this will take the text and it will
23:25:44perform the cleaning operation. It will
23:25:45remove some stop words and all. Okay?
23:25:47And it will return return you that.
23:25:51Then I'll write another function. This
23:25:53will return you country name to code.
23:25:56Okay? If you give any text that means
23:25:57the country name, it will return you the
23:25:59country code.
23:26:01Then airports
23:26:03country matches.
23:26:05So if you're um giving give if you're
23:26:09giving any airports and country code it
23:26:11will give you the uh airports. Okay.
23:26:16Then get best airports for the country.
23:26:19For this I have written another
23:26:20function.
23:26:23Okay. So get best airport for the
23:26:25country. So you just need to give the
23:26:27country code. It will give you the best
23:26:28airport for that.
23:26:30Then uh some other things I have also
23:26:32added here. So this is like more robust
23:26:35code I have written. Um
23:26:39if you see over the uh internet right
23:26:43and if you see this uh aviation stack uh
23:26:46API key code uh you will see different
23:26:47different codes are available over the
23:26:49internet people are using to get the
23:26:51realtime information realtime uh flight
23:26:54information with respect to all the
23:26:55country. Okay. So I utilize the internet
23:26:57resources and I prepared the entire uh
23:27:00function for you. Okay. So this is
23:27:02giving you the location.
23:27:05Okay. Then let me show you some other
23:27:08things I have added.
23:27:20So this is the entire code guys. Okay.
23:27:31So one thing I have to import which is
23:27:34request.
23:27:39Now see this is the entire code I have
23:27:41written to get the flight informations.
23:27:43Okay. So see these are some dependency
23:27:45utility function I need to get the
23:27:47airport informations flight
23:27:49informations. See
23:27:54and some of the functionality I
23:27:55generated from chart GPT just to make it
23:27:57more robust. See here my main intention
23:27:59is to handle all of the country user is
23:28:01giving right. So that's why these are
23:28:03the things are required. So see it will
23:28:05return uh these are the thing airlines
23:28:07flight status departure. Okay terminal
23:28:10gate schedule. So these are the
23:28:12information it will return from the
23:28:14aviation stack API. So search flight
23:28:18see we are getting these are the
23:28:20informations. Okay now let's uh test
23:28:23this whether it is working or not. So
23:28:24what I can do? So this is the function
23:28:26search
23:28:28flight. This is my final function. This
23:28:29takes the query and the limit. So by
23:28:31default limit I have given 10. Okay 10
23:28:34information it will give you okay 10
23:28:36flight information it will return you.
23:28:38So let let's test it. So what I can do
23:28:41maybe I can copy this code.
23:28:48I'll go to the test. I'll comment this.
23:28:51Let's import that. So from
23:28:54uh tools
23:28:56dot flight
23:29:01tools import
23:29:07search flights. Okay. Now let's mention
23:29:10the search plate and I'll get the result
23:29:17and I'll print that.
23:29:24Let's say I'll give Nepal trip from
23:29:27Bangladesh.
23:29:29Now if I execute
23:29:39Now see this is giving you all the
23:29:41flight information from Bangladesh to
23:29:44Nepal. See all the flight information it
23:29:46is returning you. Okay. And why this is
23:29:49happening? Because I have written this
23:29:51code. This code okay this is like more
23:29:54robust code and it can handle almost all
23:29:56kinds of entry. Okay. All kinds of
23:29:58flight informations. Okay. So I took the
23:30:01help from JPT. I prepared this entire
23:30:04functionality for you. Even we can also
23:30:06write a small function but a small
23:30:08function has some limitation only if you
23:30:10hit the aviation stack API key that time
23:30:12uh sometimes uh if you are uh giving the
23:30:15wrong let's say location name that times
23:30:18it will uh return you none. Okay. So to
23:30:21handle this kinds of scenario because
23:30:23user can give any anything right in the
23:30:25chat interface they can sometimes uh
23:30:28let's say give the wrong input okay uh
23:30:31of the country that time it can also
23:30:33handle this kinds of scenario okay
23:30:34that's why I have written this code now
23:30:37you can ask me why I'm not using tools
23:30:39decorator here whenever I'm writing the
23:30:41tools um see here I'm not going to use
23:30:45it as a um as a like custom tool instead
23:30:49of Right? I'll be using it inside my
23:30:52agent. Okay, I'll tell you this part how
23:30:54to do that. That's why I'm not using any
23:30:55kinds of tool functionality from langen.
23:30:57Okay, I'll tell you. So yes, uh my table
23:31:01and flight tools functionality are added
23:31:03and this is completely working fine. We
23:31:05have already tested. Now we'll start the
23:31:08uh agent workflow. Okay, but before that
23:31:10let me commit the changes. So here I'll
23:31:12just write flight
23:31:18and
23:31:20davi
23:31:23tools
23:31:25edit.
23:31:34Now go to uh GitHub refresh.
23:31:38This is available. Okay.
23:31:41All right. Now let's work on the um
23:31:44agentic workflow part. That means right
23:31:47now my tools are ready. Okay. Uh all the
23:31:49tools whatever we'll be using aviation
23:31:51stack and tab these are ready. Okay.
23:31:54Then I now I'll be working on the agent
23:31:56part. Okay. We'll try to define all the
23:31:57agents one by one and we'll be creating
23:31:59the langraph workflow. Once all of the
23:32:02agent uh implementation is complete then
23:32:05we'll um also uh define the uh state.
23:32:10Okay. And this state will try to save
23:32:12inside my post SQL database. Okay. So
23:32:16yeah, this is the entire plan. Now let's
23:32:18try to work on the um agent workflow.
23:32:21For this, I'm going to open up my
23:32:22backend.py.
23:32:25And here I'll just try to write all of
23:32:27my code.
23:32:30H. So first of all here, let's import
23:32:32all the necessary library.
23:32:36I need operating system
23:32:39again. I need certify just to prevent
23:32:42that path issue. And I need as well
23:32:53load env. Okay. So I'll load my
23:32:56environment variable
23:32:58and uh this is the code I need to
23:33:02prevent that path issue. Okay. Then I
23:33:05need some other libraries as well. Let
23:33:08me show you. Um these are the libraries
23:33:11I need.
23:33:14So I need uh this typing type dict and
23:33:17why I need I think you know to define
23:33:19the state okay of the graph. then
23:33:21operator I need because here we'll be
23:33:24using the reducer concept because all of
23:33:26the conversation uh we are doing right
23:33:28let's say I'm giving an input my my uh
23:33:32agent is giving a output right and this
23:33:34output I don't want to replace with the
23:33:36previous one I have to add uh add it
23:33:39like a list okay and for this I I can
23:33:42use reducer concept okay I think you
23:33:43know we have already studied about this
23:33:45thing inside our course right inside my
23:33:48aenti course I already told you about
23:33:50that if you haven't checked that please
23:33:51try to check then UI ID I need just to
23:33:54define a shon trade I think you know uh
23:33:58in persistence memory we have to give a
23:34:00trade right trade id so every times uh
23:34:02we can generate a new trades okay for
23:34:04the user then uh this is for the
23:34:06postgress okay database uh then uh we
23:34:09are also importing this uh row uh dict
23:34:11row okay for the postgress database then
23:34:14uh from lang graph we are importing
23:34:15state graph start and end and this is
23:34:17the checkp pointer so from lang graph
23:34:19checkpoint post case we're importing
23:34:21postgress s ser s ser s ser s ser s ser
23:34:22s ser s ser s ser s ser s server okay so
23:34:23we'll try to save my checkpoint in my
23:34:24postgress server apart from that I also
23:34:27need to import these are the libraries
23:34:30like from langen uh messages I need any
23:34:33message human message AI message system
23:34:35message then from grock
23:34:39lang gro I need chat gro because we are
23:34:41using grock API provider to access the
23:34:43large language model and the tools we
23:34:46have created so from tools
23:34:50dot tab
23:34:53I'll import my
23:34:56table search and from tools
23:35:01dot flight tools I'll import the search
23:35:05flight
23:35:06okay these two things I'll try to import
23:35:08okay so yeah these are my imports uh I
23:35:11need as of now first of all here what
23:35:13I'm going to do I'm going to um I'm
23:35:17going going to
23:35:19define a function. Okay. So this
23:35:20function what it returns it returns the
23:35:22database URL. That means I think you
23:35:25remember let me show you. So let me
23:35:27close these are the files.
23:35:30So I think you remember in the viewb we
23:35:33have mentioned the database URL. Okay.
23:35:34So this is the database URL. So this
23:35:36database URL I have to return. Okay just
23:35:39to connect with my Postgress SQL
23:35:41database server. Okay. So for this I'll
23:35:43define a function. So see this is the
23:35:45function only you just need to do a
23:35:47slight modification here which is that
23:35:50at the last okay at the last of this URL
23:35:52you will be adding this SSL mode is
23:35:55equal to required that means if you if
23:35:57this is your database right so here we
23:35:59are adding this line we are adding this
23:36:02line we are adding
23:36:04this
23:36:06this thing okay at the last
23:36:12this thing at the last we'll be adding
23:36:14Okay, this is required. Why this is
23:36:16required? Because here we will be um
23:36:19we'll be connecting with my remote
23:36:21Postgress server, right? And uh for
23:36:24remote postgress server, this is
23:36:25required. So that's why we are checking.
23:36:27First of all, we are getting the
23:36:28database URL. Then we are checking if
23:36:30not database URL, I'll raise the
23:36:32exception database URL is missing.
23:36:34Otherwise, I'll try to check if SSL mode
23:36:36not in database URL, I'll just try to
23:36:38add it and return the database URL.
23:36:40Okay. Now how this uh this will uh look
23:36:43like? So let me show you. So maybe I can
23:36:46call this function. So URL is equal to
23:36:50database URL. So I'll print the URL
23:36:54right now.
23:37:03So I'll
23:37:05come here Python
23:37:08app.py Py
23:37:12okay sorry it's back end.py Pi sorry my
23:37:15mistake so python
23:37:18backend.py apply
23:37:22now see this is what we are getting this
23:37:23is the entire URL add the last see it is
23:37:26adding this this thing okay it is it
23:37:28will give you this uh question mark then
23:37:30this SSL mode is equal to required okay
23:37:33this thing it should add then I will be
23:37:35able to connect with my postgress remote
23:37:38server okay which is running on red okay
23:37:40I hope you get it that's why we are
23:37:41giving this function
23:37:44yeah so now let's delete this code it's
23:37:47not required Okay. Now guys, uh we'll
23:37:50try to get some other things like my
23:37:59let me show you
23:38:05like my Gro
23:38:08Gro API key.
23:38:12So we are loading the GRO API key. Okay.
23:38:14From the environment variable. Then here
23:38:16we'll just try to write a condition
23:38:19if not grock API key found it will raise
23:38:21exception. Okay. Now we'll try to define
23:38:23the large language model.
23:38:28So here we are defining the large
23:38:29language model. As you can see we are
23:38:30using chat gro and model is equal to I'm
23:38:33using llama 3.37 billion versatile
23:38:36model. Okay, this is available on the
23:38:39um rock.
23:38:46See this one. Okay, this model we are
23:38:48using. Okay, now you can use any model
23:38:51only. You just need to give the model
23:38:52ID. Okay, just try to check here. It has
23:38:55the model ID. Just copy this model ID
23:38:57and paste it here. It will use that
23:38:59model and we are giving the um API key.
23:39:03Then we have to define the state. Okay,
23:39:05my
23:39:07graph state.
23:39:09So this is the state I have prepared
23:39:11guys and I think you know what is a
23:39:13state and how to define the state each
23:39:14and everything I have completed in my
23:39:16course. Please try to check guys. Okay.
23:39:17So I named it as table state and
23:39:19inherited with the type dict first of
23:39:21all the message that means you can match
23:39:23with here message okay whatever message
23:39:25uh user is giving I'll try to store here
23:39:27but this should be reducer object. Okay
23:39:30that means we are doing operation dot
23:39:32add that means every time it will add
23:39:33add that message. Okay, instead of
23:39:34replacing then user query whatever query
23:39:37user is passing I'll write save in the
23:39:39user query then flight result hotel
23:39:41result uh then itinary uh result and one
23:39:44additional things I have provided here
23:39:46which is llm calls that means I want to
23:39:48see how many times llm calls we are
23:39:50doing here that means we'll do the lm
23:39:52count as well this thing I also stored
23:39:54inside my state memory okay that is my
23:39:57shared memory now first of all I'll
23:39:59define my flight agent okay the first
23:40:01agent let's define the first agent So
23:40:04this is my first agent. Flight agent.
23:40:09Okay. So I named it as a flight agent.
23:40:10It will take this state. Okay. As a
23:40:12shared memory. Then uh first of all I'm
23:40:15taking the user query from this state.
23:40:16And we are doing the flight search
23:40:18operation with the help of this search
23:40:20flight function we have written inside
23:40:21my flight tools. Okay. That is why I'm
23:40:23not using this function as a tool custom
23:40:26tool. Instead of that I'm using inside
23:40:28my agent. Okay. I think you remember uh
23:40:30I think you get it right. Why I'm not
23:40:32using custom function? Yeah. So I'm
23:40:35using directly inside my agent. So it is
23:40:37doing the search operation. Uh it will
23:40:39get the flight information and I'm
23:40:41returning the flight information as a
23:40:42result and AI message. Okay. The flight
23:40:45result fetched. Then I'm also doing the
23:40:47LM count. That means uh initially my LLM
23:40:50call should be zero. Okay. So I'm just
23:40:53uh getting that particular data and I'm
23:40:55doing the plus one add operation. That
23:40:58means if initially it was zero it will
23:41:00add the plus one that means one LM call
23:41:02I have done that's how many time LLM
23:41:05call I will try to do I'll just try to
23:41:06update this LM calls okay done so this
23:41:09is my first agent we have prepared now
23:41:11let me define the second agent which is
23:41:12nothing but hotel agent okay now let's
23:41:14define the hotel agent now what hotel
23:41:16agent do it will use the tabularly
23:41:18search and it will get the hotel
23:41:20informations see this is my next agent
23:41:22which is hotel agent so again it will
23:41:24take the state and this is the query
23:41:26best hotels for user query that means if
23:41:29user is giving let's say I want to visit
23:41:32uh Japan from Bangladesh so Japan best
23:41:35hotel it will try to find right and for
23:41:37this we're using tably search
23:41:38functionality so this is the tab search
23:41:40functionality it will found best hotels
23:41:42okay from the internet and it will
23:41:45return it here then I'm returning this
23:41:46hotel result as well as the AI message
23:41:48hotel information fetched and again we
23:41:50are updating the lm calls with plus one
23:41:53okay I think you get it so this is my
23:41:55second agent now I'll try to define in
23:41:57my third agent which is itinonary agent.
23:42:00Okay. So basically this will uh do the
23:42:02uh plan it will basically
23:42:05uh create the places to visit activities
23:42:07all of this thing right. So here what
23:42:09I'm going to do I'm going to utilize the
23:42:11large language model here because
23:42:12without large language model I can't
23:42:14generate the plan right so that's why I
23:42:16have to use the large language model. So
23:42:17this is my
23:42:21uh next agent.
23:42:23Okay inside back end.py I have to write
23:42:26this is my uh itinary agent. Okay, as
23:42:29you can see itinary agents this is
23:42:31taking the state and this is the prompt
23:42:33I'm defining. So create a complete
23:42:34travel itinary uh user query. This is
23:42:37the user query. This is the flight
23:42:38result. This is the hotel information.
23:42:40Okay. Make the itinary a practical
23:42:42budget hour and easy to follow. Okay.
23:42:45Now here we are ining the LLM. The LM we
23:42:48have defined. I think remember this is
23:42:49the LM we invoking the LM with this
23:42:52prompt.
23:42:54We are giving the system message you are
23:42:56expert table planner and this is the
23:42:57human message we are giving as a prompt.
23:43:00Okay. Then after that we are returning
23:43:01the itinary response message as well as
23:43:04the LLM call we are also updating. Okay.
23:43:07I hope you get it. So that's how we are
23:43:08completing the third agent which is
23:43:10itinonary agents. Now we'll be creating
23:43:12the final agents which is final response
23:43:14agents. That means it will take all of
23:43:15the results and it will combine
23:43:17everything. It will generate a final
23:43:19response for me. Okay. So let's try
23:43:20write it here. Uh so this is the result
23:43:26for final response.
23:43:36So this is our final agent. It will take
23:43:38this state again and this is the final
23:43:40prompt. Generate the final trial
23:43:42response for the user. This is the user
23:43:43query, flight information, hotel
23:43:45information and this is the uh itinary
23:43:48plan. Format the final answer
23:43:50beautifully using these sections. That
23:43:52means it will have the trip summary,
23:43:54flight information, hotel suggestion,
23:43:55daybyday, itinary, estimated budget,
23:43:57final recommendation and some important
23:43:59note as well. Okay. So yeah, this is my
23:44:02entire prompt and we are again booking
23:44:04the LLM. We are giving the system
23:44:06message. You're a professional AI travel
23:44:07booking assistant and this is the human
23:44:09prompt you're giving and whatever
23:44:10response I'm getting, I'm returning as a
23:44:12response and I'm updating my LM call.
23:44:14Okay, that's how we have completed four
23:44:17agents implementation. Okay, now we'll
23:44:19try to build the graph. So in like graph
23:44:21we have to define the graph. Let's try
23:44:23to define the graph right now. So we'll
23:44:26build the graph. So to build the graph
23:44:28first of all I have defined my state
23:44:30graph. I passed my state and this is
23:44:32going to be my graph. Now we'll try to
23:44:34add all of the nodes one by one. First
23:44:36of all I will add my flight agent then
23:44:39hotel agent then itinerary agent then
23:44:41final respond agents. All the agents
23:44:43I'll try to add one by one.
23:44:47So these are my agents. Okay, I'm adding
23:44:49the nodes. Flight agent, flight agent,
23:44:51hotel agent, hotel agent, itinary
23:44:53agents, itinary agents, flight agents,
23:44:55flight agents, sorry, final agent, final
23:44:57agents. I have added all of the agent
23:44:59node. Now I have to do the age
23:45:01connection. Okay, that means flight
23:45:03agents would be connected to the hotel
23:45:04agent, hotel agent would be connected to
23:45:06the itinary agents, final agents would
23:45:08be connected to the final response
23:45:09agents. Okay, that is the connection we
23:45:11have to build right now. So, let me show
23:45:13you the connection.
23:45:15So, this is the connection. So, you can
23:45:17see start uh start to flight agents.
23:45:20Okay. Then uh flight agents to hotel
23:45:23agents. Flight agent to hotel agents.
23:45:26Then hotel agents to itinary agents.
23:45:28Hotel agents to itinary agents. Okay.
23:45:29Then itary agents to final response
23:45:31agent to final response agents and final
23:45:33respon agents to end. Okay. So this is
23:45:35the connection we had we have done. Now
23:45:38we have to define the postgrace
23:45:41checkpointer. So I think remember we
23:45:43already written a function called
23:45:45database URL. So basically this returns
23:45:47the database URL. Okay. And we are um
23:45:50storing the URL inside a variable called
23:45:53database URL. Now I'll try to do the
23:45:56connection.
23:45:58So we are using uh psyg.
23:46:03We are giving the database URL. Then
23:46:05auto commit is equal to true and row
23:46:07factory is equal to dro. Okay, these are
23:46:08the parameter I have to pass and it will
23:46:10give you the connection and this
23:46:12connection I have to pass inside my
23:46:14checkpointer.
23:46:16So postgress saver I think remember we
23:46:18imported from checkpo pointer here from
23:46:21lang gap checkpointter postgate
23:46:22postgress saver inside that we have to
23:46:24pass this connection and this will
23:46:26return the checkpoint and we have to do
23:46:28the checkpointter uh checkpointer dot
23:46:30setup once it is done then I'll try to
23:46:32pass this checkp pointer inside my graph
23:46:35okay we'll try to compile so travel
23:46:37graph is equal to graph graph dot
23:46:40compile and we are giving the checkpoint
23:46:42now all of this state would be saved
23:46:43inside my memory Okay.
23:46:47Then uh once everything is done, now let
23:46:48me write the function
23:46:52for my first API.
23:46:56So this is the function final function.
23:47:00So run travel agent. So this takes the
23:47:02run user input and the trade ID. Okay.
23:47:05So first of all, if user is uh not given
23:47:07trade ID, so what I'm doing, I'm just uh
23:47:10generating a unique trade ID and uh we
23:47:13are preparing the configuration. Okay,
23:47:14configurable inside trade ID. I'm
23:47:16passing my trade ID. Then I'm invoking
23:47:18my travel graph. Okay, so here we're
23:47:20doing the invoking. So we are giving the
23:47:22human message user input and initially
23:47:25my flight result, hotel result, itinary
23:47:27lm cost would be empty. That's why I'm
23:47:30passing as a empty. Then I'm passing the
23:47:31configuration. Whatever result I'm
23:47:33getting, I'm just checking the content
23:47:35and I'm returning the response. That
23:47:36means my trade ID, answer, flight
23:47:38result, hotel result, it lm cost, each
23:47:40and everything I'm just returning on my
23:47:43front end. Okay. And in from here I'll
23:47:46try to get the informations and uh what
23:47:49I can do I'll just try to show in my
23:47:51front end. Okay. The front end will try
23:47:53to create. Now let me test whether it's
23:47:54working or not. So what I can do I can
23:47:56maybe run this travel agent test. I'll
23:48:00copy this and open my test.py.
23:48:03Let me import here. So from back end
23:48:08uh import
23:48:11run agent. Okay. And then again I'll try
23:48:14to comment out.
23:48:18So
23:48:20response is equal [clears throat] to
23:48:24run table agent
23:48:31and I'll print the response
23:48:38even maybe what I can do I can instead
23:48:40of writing like that I can write a full
23:48:42loop. Okay let me show you
23:48:45I can write a for loop like that.
23:48:54So here I'm taking a user input uh from
23:48:56the user and um
23:49:01um okay instead of for loop maybe I can
23:49:02directly run okay then I'm running the
23:49:04travel agent this uh function and I'm
23:49:07passing the user input and trade ID uh
23:49:11just for testing purpose I've given test
23:49:12user and whatever response I'm getting
23:49:14I'm just u printing the response. Okay,
23:49:16now let me test. So I'll just try to
23:49:19execute.
23:49:35So I'll just run python backend.py.
23:49:39Not backend.py, sorry. It should be
23:49:43um it should be test.py. Pi. Okay, let's
23:49:47execute. Huh? So, Python test.py.
23:49:54Now, it is asking the user input. So,
23:49:56let's give a input.
23:50:12So, this is my user input. uh plan a
23:50:15complete 7 days India trip from
23:50:17Bangladesh including flights, hotel, uh
23:50:20sightseeing under two lakhs. Now let's
23:50:22see
23:50:33now see this is the entire plan I'm
23:50:35getting. So final response, the summary,
23:50:38flight information, hotel suggestions,
23:50:41dayby-day itinerary, then uh estimated
23:50:44budget, final recommendation. Amazing.
23:50:47Okay, it's working fine. Now we have to
23:50:50add uh add this inside my user
23:50:52interface. Okay, right now my back end
23:50:54is ready. Okay, we are able to test it
23:50:56perfectly. Now we'll be creating the
23:50:59uh front end user interface with the
23:51:01help of fast API and we'll be writing
23:51:03the uh fast API uh fast API route. Okay.
23:51:07Uh backend route and so that my front
23:51:09end can communicate with my um like back
23:51:12end. Okay. So for this we'll be using
23:51:14fast API service and fast API is a
23:51:16production grade um uh web framework.
23:51:19Okay. Especially API creation framework
23:51:20you can use. Okay. So let's try to
23:51:24implement my first API code guys right
23:51:26now.
23:51:29And one more thing I want to show you. I
23:51:31already executed my uh workflow and it
23:51:34has executed successfully. I think we
23:51:36have seen that. Now let me see whether
23:51:38it is able to store the checkpoint in my
23:51:40database or not. Now I'll open up my PG
23:51:42admin. And now if I refresh on my table
23:51:45right now if I go inside the table
23:51:48you'll see that all of the checkpoint
23:51:50has created. Okay. Now here is a
23:51:51checkpoint uh checkpointter table is
23:51:53there. Now just try to right click and
23:51:56there's a option called view edit data.
23:51:58Now just click on all rows. Okay. If you
23:52:00do that you'll be able to see that all
23:52:02of the checkpoint it has saved here.
23:52:08See all of the checkpoint it has saved.
23:52:10Okay. This is the state memory and it
23:52:13has also traced on my langid platform.
23:52:16Let me open my lang.
23:52:20done. If I go to my langu so trip AI if
23:52:25I go inside that now see this is the
23:52:27langismith execution even you can see
23:52:29the trade wise okay the test user uh
23:52:32trade we have given initially and this
23:52:34is the execution
23:52:36okay this is the execution it has done
23:52:38okay see amazing right now let's try to
23:52:41add my first API code so for this uh
23:52:44I'll open up my app.py I
23:52:48and here let's define all of the code
23:52:51and I'm expecting guys you are already
23:52:52familiar with fast API here uh first API
23:52:55knowledge is required.
23:52:59So here what I'm going to do I'm going
23:53:01to import some necessary libraries.
23:53:05Yeah. So I'm importing path from path
23:53:07lip pack uvicon from fast API. I'm
23:53:10importing fast API request first API.
23:53:12I'm importing HTML response, JSON
23:53:14response, static file, ginger templates
23:53:16and base model from pientic. So here I
23:53:19need piic just to define my um data
23:53:22structure. I think I already completed
23:53:24pientic videos as well on my um on my uh
23:53:28agenti course and why pyic is required.
23:53:30I already told you please guys to go
23:53:32through that session. Then I need
23:53:34another functionality which is my uh
23:53:37this function run travel agent from my
23:53:39back end. Let me import it as well.
23:53:44So from back end
23:53:48import
23:53:52run agent. Okay. First of all let's
23:53:54create a base directory.
23:53:58Then I'll define my first API app.
23:54:02That's how we can define the first API
23:54:03app. So I have named it as AI travel
23:54:05planning system. Or maybe I can give
23:54:07this name trip AI.
23:54:17Okay, tripate AI.
23:54:20So this is a lang multi- aent travel
23:54:23planner with fast API front end. And
23:54:25this is the version we have given. Okay.
23:54:27Now first of all you have to mount your
23:54:29static folder as well as the template
23:54:32folder. So let's mount
23:54:34because inside static you have
23:54:36JavaScript and CSS and template you have
23:54:38the HTML. So we are doing the app
23:54:39domount static and this is my static
23:54:42fold file uh file directories okay we
23:54:44are giving it and similar wise we have
23:54:46[snorts] to give the templates as well.
23:54:48So you can see ginger templates I am
23:54:50passing my directory which is templates
23:54:52inside that I have my HTML content. Now
23:54:54what I have done guys I have already uh
23:54:57generated HTML CSS code from chart GPT
23:54:59for this uh project. See if you don't
23:55:01know about HTML CSS design it's
23:55:03completely fine that is there would be a
23:55:05separate front-end developer for that.
23:55:07uh they will be using some other front-
23:55:09end framework like NexJS, react okay
23:55:11with the help of that they will be
23:55:12creating the front end server for you
23:55:14and then they will be connecting with
23:55:15your first API back end right so if you
23:55:18don't know about HTML CSS completely
23:55:20fine just try to go through chat GPT and
23:55:22just tell I need this kinds of interface
23:55:24okay just give me the HTML CSS and
23:55:26JavaScript code charge GPT will give you
23:55:28and you just need to copy paste here and
23:55:30you you need to modify with respect to
23:55:31your requirement so I've done the same
23:55:33thing so this is my HTML code I
23:55:35generated from chart GPT
23:55:37uh for my user interface and then I
23:55:40modify it okay as per my requirement. So
23:55:43here title wise I can give my name trip
23:55:46materi.
23:55:56So that's how you can uh modify the data
23:55:59data property with respect to your
23:56:01requirement. Okay. Whatever data you
23:56:02have inside HTML content just try to
23:56:04change. So this is a simple code I have
23:56:06generated from charge JPT and it needs a
23:56:08CSS okay just to load the design. So CSS
23:56:11style. So I'll again try to
23:56:15give this CSS design here in my CSS file
23:56:19static CSS style CSS file.
23:56:22So this is the CSS codes design. Okay. I
23:56:25have added
23:56:27okay again I generated from chat GPT.
23:56:30Then just to communicate with my front
23:56:32end uh the just to communicate with my
23:56:34first API route I need this scriptjs. So
23:56:38again I prepared with the help of charg.
23:56:42So this is my javascript code and hit it
23:56:45hits my first API route. Okay I'll tell
23:56:48you what are the route it will hit just
23:56:50to get the data. So first of all it will
23:56:52hit my API travel. Okay, API travel
23:56:55means it will uh hit that API travel
23:56:57route and it will get the uh it will get
23:57:00the entire plan. Okay, that means
23:57:01whatever execution I showed you right
23:57:03now, these are the information it will
23:57:04try to get and it will try to show in my
23:57:06front end. Okay, this is what it is
23:57:08doing. Now, let me show you. First of
23:57:09all, let me define all the routes one by
23:57:12one. So, first of all, I'll try to
23:57:14define my
23:57:16pantic schema travel request. I'm
23:57:19inheriting with the base model and this
23:57:20has the message and trade ID. Okay. And
23:57:23this is my default route.
23:57:26This is my default route. If you visit
23:57:27my app, first of all, it will launch my
23:57:29HTML page. And this is the final
23:57:33API route.
23:57:38This is my final API route as you can
23:57:40see API/travel.
23:57:42If you hit that and again I'm using
23:57:43asynchronous, okay, asynchronous
23:57:45functionality. Why asynchronous? Because
23:57:47it will run my agent is a asynchronous
23:57:50way. Okay, that means parallel execution
23:57:52it will do. I think I already covered
23:57:54this asynchronous as well in my
23:57:55playlist. Just try to go through that.
23:57:57So asynchronous uh I'm running you can
23:57:59see travel planner it will take the uh
23:58:02information from the user that means the
23:58:04user input whatever user input will pass
23:58:05from the input box. First of all I'm
23:58:07checking if user is not available. I'm
23:58:09returning message can cannot be empty.
23:58:13Then if available I'm running my run
23:58:15travel agent that means this function.
23:58:16Okay, this function I have imported from
23:58:18back end. So this function will return
23:58:20what result okay and from the result
23:58:22we're extracting these are the content
23:58:24and we're returning okay in my front end
23:58:28and if some exception is occurring I'm
23:58:30handling the exception okay and uh some
23:58:33other route I need uh sometimes uh it
23:58:36will check the health condition of my
23:58:38first API server so for this it will hit
23:58:40this route / health and it will if
23:58:43everything is uh working fine it will
23:58:44give uh status is okay and this is
23:58:47running and some icon to load some icon
23:58:50actually you need this one okay now uh
23:58:54finally I'm going to execute my server
23:58:56with the help of uon run so app clone
23:58:59app because this is app file and my
23:59:01object is app my objective app okay then
23:59:05uh host and port number and reload is
23:59:07equal to true so these are the things
23:59:08you have to provide okay now in this uh
23:59:12javascript I'm calling this route if I
23:59:14show you if I do just ctrl f and paste
23:59:18see This is what actually I'm executing.
23:59:19So whenever user is generating the
23:59:21response, it is hitting here. Okay. And
23:59:23it is getting the information. Let me
23:59:25show you. So I'll execute my app right
23:59:27now. So python app.py.
23:59:34See this is running on local host port
23:59:36number 8,000.
23:59:38So I'll come here. Search for local host
23:59:41port number 8,000. See this is your
23:59:44application. Okay. Uh you can see this
23:59:46is your application. Now here you have
23:59:49to give the input. So let's say I'll
23:59:50give this input Dubai trip. Plan a 5
23:59:53days Dubai trip from Dhaka with flights,
23:59:55hotels and sites uh site syncs. Now if I
23:59:59see click on generate plan that time it
24:00:01will hit this route. Okay, hit this
24:00:03route and it will get all of these uh
24:00:05information. It will generate all of the
24:00:06information then it will get and show in
24:00:08the front end. Let me show you. See
24:00:12uh okay uh just terminating. Okay.
24:00:14Because my previous application is
24:00:16running. Okay. I already executed my uh
24:00:18this app previously just to show you. So
24:00:20let me first of all stop this execution.
24:00:23Okay, now it will run.
24:00:26It's running. Now refresh again. Now let
24:00:30me give this prompt and generate the
24:00:32plan.
24:00:41Now see this is the entire plan we are
24:00:44getting. Okay. in a beautiful format.
24:00:47Okay. And there is a download PDF button
24:00:50and how this is coming because of the
24:00:51front- end design we have done. Okay. So
24:00:54this work uh this work is completely uh
24:00:56responsible for front- end designer. So
24:00:59uh you just tell them okay what you
24:01:00need. So if you need this kinds of
24:01:02download PDF or if you need let's say uh
24:01:05any u download any markdown file you
24:01:08just tell them okay they will try to
24:01:09prepare for you and you can um you can
24:01:13just use that as it is. Okay. And this
24:01:15is the trade it has created. Okay. Uh
24:01:18because we haven't passed any trades.
24:01:19That's why it has created a um randomly
24:01:23generated trades. Okay. So that's how we
24:01:25can give any kinds of prompt. Right now
24:01:28let's say instead of Dubai I'll give
24:01:31maybe Thailand.
24:01:42See this is the plan for the Thailand.
24:01:44So this is the summary. This is the
24:01:46flight information. This is the hotel
24:01:48suggestions. This is the dayby-day
24:01:50itinary. Uh first day, second day, third
24:01:53day, fourth day, fifth day, sixth day, 7
24:01:55days. Okay. And estimated budget unit.
24:01:59Then final recommendation. Okay.
24:02:01Amazing. Right? Now I can easily
24:02:03download this file and I can uh I can
24:02:06store in my mobile phone. Okay. And I
24:02:08can use it anytime. So yes guys that's
24:02:11how we can implement this entire system
24:02:13and if I show you my checkpoint right
24:02:16now if I again do let's say refresh see
24:02:19all of the checkpoint would be available
24:02:22all of the conversation me would be
24:02:23available inside my postgress see okay
24:02:26now see initially I executed test user
24:02:28now this is the current user the current
24:02:31trade okay current execution and these
24:02:32are my messages now you can also see the
24:02:38um
24:02:40lang. So if I go to the lang smmith uh
24:02:43if I again refresh
24:02:46now another trade should be created. See
24:02:48this is the trade and two conversation I
24:02:50have done. Now this is the two
24:02:51conversation. Now you can see all of the
24:02:53informations. Okay. Which tools it is
24:02:55using each and everything is visible
24:02:56here. Input and output each and
24:02:58everything. Okay. So amazing guys. We
24:03:00have successfully completed our uh
24:03:02implementation and it is working fine.
24:03:05Now what I want to do guys, I want to
24:03:07deploy it over the render cloud. Okay.
24:03:10So I'll deploy this uh project on my
24:03:13render cloud. But before that let me
24:03:15commit the changes. So here I'll just
24:03:18try to
24:03:21app add it commit and see the changes.
24:03:29Okay. Now if I go to my GitHub refresh
24:03:34now see it's updated. Okay. Now it's
24:03:36ready for the deployment. Now let's do
24:03:38the deployment of this application.
24:03:44Okay. So guys for the deployment uh
24:03:46we'll be using docker. Um so let's
24:03:49create a file here. I'm going to name it
24:03:51as docker file. And inside that you have
24:03:55to mention all of the docker related
24:03:56command. And uh if you don't know about
24:03:58Docker guys u docker is a
24:04:01containerization service and this
24:04:03tutorials uh this tutorial is already
24:04:05available on my YouTube channel. Let me
24:04:07show you. So if I go to my YouTube right
24:04:10deals with BP.
24:04:12So if you go to the video section I
24:04:15already have a full MLOps course. Okay
24:04:18here if you see here uh this is the
24:04:21MLOps course. You can open it up. And
24:04:24this course already covered the docker.
24:04:27Okay.
24:04:30Yeah. So see docker for mlops. You can
24:04:32um at least go through this docker part.
24:04:34Okay. And try to master the docker. And
24:04:37if you're interested learning entire
24:04:38mlops, this is already available. This
24:04:40is around 12 hours of recording. You can
24:04:41go through that. Okay. And if you like
24:04:43the content, please try to subscribe to
24:04:44my channel. So docker is required. I'm
24:04:47expecting you already familiar with
24:04:48docker. So simply I'll try to add all of
24:04:50the docker related command here. So this
24:04:53is these are my docker related command
24:04:54guys. As you can see first of all I'm
24:04:56taking a beige image 3.11 creating
24:04:58working directory uh adding some
24:05:00environment variable then uh running
24:05:02some commands copying the requirement.xt
24:05:05file then installing the requirement.xt
24:05:07file copying all of my source code then
24:05:10uh this thing I don't need. I'll just
24:05:12try to remove
24:05:14this thing I not did. Then I have to
24:05:17expose the port. Okay, port should be uh
24:05:20port number
24:05:228,000 I think. Right, we are using port
24:05:24number 8,000. So I'll try to add port
24:05:26number 8,000 here.
24:05:29And uh we running the command hicon app
24:05:32file uh local host and port number
24:05:358,000.
24:05:37H So this is my docker file. Okay, I
24:05:39need and for this I need to create
24:05:41another file which is dot
24:05:44docker
24:05:46ignore
24:05:48and here you have to mention all of the
24:05:50uh files and folder you you want to
24:05:53ignore during docker dockerization. So
24:05:55these are the thing I'll try to ignore.
24:05:57Okay, during dockerization. So now let
24:06:00me push the changes again and what I'm
24:06:02going to do I'm going to also update the
24:06:04readmi file. Okay, I already created the
24:06:06uh Redmi file update.
24:06:11So I have added a beautiful Redmi
24:06:13content. Let me show you. So this is the
24:06:15Redmi guys I have added. So I have given
24:06:18the entire um project summary features
24:06:21ST project structure prerequisite
24:06:24environment installation running the
24:06:27endpoint. Okay. So each and everything I
24:06:29have added. So your project should have
24:06:30one beautiful readmi file guys. Okay.
24:06:32This is super important. So read me just
24:06:34try to add uh one more thing I want to
24:06:37add which is uh I will give my project
24:06:40name as it is
24:06:48now it looks good I think now it look
24:06:51[clears throat] it looks good so yeah uh
24:06:54I think we are done now let me commit
24:06:55the changes
24:06:58docker
24:07:01addit
24:07:09Now if I go to my GitHub refresh
24:07:12now see beautifully I have added the
24:07:14readme and each and everything. Okay now
24:07:16it is ready for the deployment. Now what
24:07:18I'm going to do guys I'm going to open
24:07:19up my render cloud.
24:07:31Go to the dashboard.
24:07:35Now I'll create a new web service. Okay.
24:07:40Select this public git repo and copy
24:07:43this GitHub rep. Okay.
24:07:46Copy this URL and paste it here and
24:07:49let's connect.
24:07:52Okay. See automatically it has taken and
24:07:54it is using the docker services. Okay.
24:07:57For the deployment. So everything just
24:07:59keep it as it is. No need to change
24:08:00anything. Simply just create uh select
24:08:02this free instance. Okay. So I'll select
24:08:04the free instance. But if you're doing
24:08:05like actual deployment, just try to take
24:08:07the subscription. Okay. Because free
24:08:08instance has having like very low
24:08:11configuration machine and there is some
24:08:12limitation as well. Okay. Now once
24:08:14everything is fine, you have to add the
24:08:15environment variable. Okay. So what I
24:08:17can do maybe I can add it from myv file.
24:08:21So simply I can copy
24:08:23myv as it is.
24:08:30Okay. And add the variables.
24:08:33Now it has added my GO API key.
24:08:39I can delete this one. Grow API key.
24:08:42This is my GO API key. This is my
24:08:44aviation. This is my default origin.
24:08:47This is my table. This is my database
24:08:49URL. Now this database URL, you have to
24:08:51give the internal database URL. Okay. So
24:08:53again I will go to my render. go to my
24:08:56postgress server
24:08:59and go below and copy this internal URL.
24:09:02Okay, this one. Copy this.
24:09:05Okay, I'll copy this and uh add it here.
24:09:14So I've given my internal one. Okay.
24:09:17Then languid tracing endpoint, languid
24:09:20API key and Langmith project name. Okay.
24:09:23So everything is fine. Now simply uh
24:09:26deploy the web service.
24:09:33Now it should take some time. First of
24:09:35all, it will build the docker image.
24:09:42So we'll wait guys. Okay. Once this uh
24:09:44this is complete, this is live, then
24:09:45we'll be able to access that
24:09:58as it is installing the requirements.
24:10:22See um installation done. Now it is
24:10:25exporting my Docker image as a layer.
24:10:52And if you want to see the AWS
24:10:54deployment guys, this is already
24:10:55available on my YouTube uh on this
24:10:58playlist you can see AWS CI/CD
24:10:59deployment. Okay, you can go through the
24:11:00CI/CD deployment. You can learn how to
24:11:02deploy as a CI/CD. Even this project
24:11:04also I have deployed as a CI/CD on AWS.
24:11:06Okay, you can refer it.
24:11:12And this is also CI/CD. If you push your
24:11:14changes, uh it can upgrade your uh
24:11:18features, okay, automatically.
24:11:21Again, I created another tutorial like
24:11:23this one. Uh render deployment. You can
24:11:25go through that.
24:11:43so guys as you can see our application
24:11:45is live now. Let's copy this URL and
24:11:47paste it here and if I hit enter so it
24:11:50should open your application. Now see
24:11:52our TripMate AI is live right now. Now
24:11:54let's uh test it. So I'll give this
24:11:58prompt. Okay. uh 7 days India trip from
24:12:01Bangladesh. Now let's generate the plan.
24:12:05Now it's generating. Let's wait.
24:12:10Now see this is the entire plan we are
24:12:12getting. Amazing. Right now it is live.
24:12:15Now you can share this with your friends
24:12:17and family. They can also access that
24:12:19and you can tell them just use my multi-
24:12:22aent right now just to prepare your
24:12:24trip. So yes guys this is all about from
24:12:26this implementation. I hope you liked
24:12:28it. Okay guys, we have successfully
24:12:30completed our uh agent AI course with
24:12:33the help of Langraph. We have learned
24:12:35each and everything whatever uh are
24:12:38required to implement this kinds of
24:12:39agentic system. Now u I have uh another
24:12:43plan guys uh actually I have designed
24:12:46some more phases okay for the future and
24:12:50this is available on my channel on DS
24:12:52with Buppy YouTube channel. So this is
24:12:54my channel guys DS with BPY. So here I
24:12:57only completed the langraph right lang
24:12:59graph agentic uh AI orchestration
24:13:01framework and uh we have implemented all
24:13:04of the AI agents with the help of
24:13:06langraph but what about the others
24:13:08framework okay there are some other
24:13:09frameworks are also available on the
24:13:11market uh like krui is there right and
24:13:14then Microsoft autogen is there N8 is
24:13:16there right so if you want to learn
24:13:18these are the framework also so you can
24:13:21subscribe to my channel because in my
24:13:23channel I'll try to publish all of the
24:13:25video related these are the framework
24:13:28like crewi we'll try to master the
24:13:30entire crewi in depth we'll also
24:13:32implement some end to end agentic AI
24:13:34application with the help of crewi we'll
24:13:36be also learning about the Microsoft
24:13:37autogen already I have Microsoft autogen
24:13:39playlist okay uh I will upload all of
24:13:42the recording related autogen okay we'll
24:13:44be also implementing some projects end
24:13:46to end projects then I'll be covering
24:13:48the no code platform as well like n okay
24:13:51this would be also available on my
24:13:52YouTube channel then uh one very
24:13:55interesting ing and important concept
24:13:56which is MCP. So this MCP I didn't cover
24:14:00in this course right uh in this my uh
24:14:02agenti with langraph course because this
24:14:05is already like a very long course we
24:14:08have recorded so far it is around uh 25
24:14:11hours of recording okay so that's why uh
24:14:13all of these uh concept like MCP autogen
24:14:17crew AI okay these are the recording
24:14:19would be available on my YouTube channel
24:14:20okay these are the video would be
24:14:21available on my YouTube channel so
24:14:23please try to refer my YouTube channel
24:14:24you can subscribe to my YouTube channel
24:14:26so I think you'll be enjoying a lot the
24:14:29future phases as well. Okay. So, we'll
24:14:31try to master the entire model context
24:14:33protocol in my YouTube channel. Then
24:14:36phase uh 10, we'll try to cover the AI
24:14:39safety and evaluation. Nowadays, if you
24:14:41are creating any kinds of agent
24:14:43application, this is super important uh
24:14:45to know like how we can add the AI
24:14:47safety evaluation pipeline inside your
24:14:49agents. Uh definitely we have to master
24:14:51the guardrails and safety. We'll try to
24:14:53see prompt injection, security tools,
24:14:55restriction, AI safety patterns. Okay,
24:14:57these are the concept we have to cover
24:14:59and everything would be available on my
24:15:00YouTube channel. Okay, that means these
24:15:02are the future phases would be available
24:15:04on my channel DS with Buppy. And if you
24:15:06want to understand, if you want to learn
24:15:08these are the concept, you just need to
24:15:10subscribe to my channel and all of the
24:15:11content would be available on my YouTube
24:15:13channel. Okay. So yes, uh if you found
24:15:15my content useful guys, please try to
24:15:17subscribe to my channel and support me.
24:15:19If you're supporting me, definitely I
24:15:21can bring this kinds of content more in
24:15:22future and uh yeah, I think uh you'll be
24:15:25learning a lot. And if you want to
24:15:27connect me, so this is my LinkedIn
24:15:29profile bulk bi. Simply you can follow
24:15:31me here. You can connect me here. And if
24:15:34you have any kinds of query, you can ask
24:15:35me. If you need any kinds of guidance,
24:15:37you just uh ping me on my l uh LinkedIn.
24:15:40Definitely I'll try to help you with
24:15:42that. So yes guys, this is all about
24:15:44from this course. I hope you enjoyed a
24:15:46lot. So thank you so much for watching
24:15:48and I will see you next time.