This tutorial offers a pragmatic blueprint for mastering state-driven orchestration, effectively demystifying how LangGraph transforms chaotic LLM outputs into structured, linear pipelines. It is an essential primer for developers moving beyond simple prompts toward building reliable, multi-step AI workflows.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
9. Build Sequential Workflows in LangGraph | Complete Agentic AI CourseAdded:
Hi guys, my name is BPI and you are welcome to my YouTube channel. So guys, so far we have uh discussed about the theoretical aspect of agentic AI uh as well as I have already given you the in-depth understanding about the uh langraph components and all. Now it's time to start the practical uh exploration. So from this video onward guys uh we'll be working on the uh practical part of the langraph. So uh first of all we'll be starting with the very uh basic workflow uh inside langraph which is uh sequential workflow. I think I have already told you about that. So if you haven't uh check my playlist guys. So this is the playlist uh just try to check all of the video previously whatever I have done.
So there I have already discussed about each and everything right and uh if you want to understand all the workflow inside langraph uh you just need to go with this um these two tutorials. Okay.
So uh in this video guys what we'll be doing uh we'll be creating our first um first actually workflow. The workflow name is sequential workflow. Okay.
Sequential means uh this will run um uh in a step-by-step uh let's say manner.
Okay. This is called sequent sequential workflow. So it doesn't have any kinds of looping. It doesn't have any kinds of conditional branching. Okay. It doesn't have anything only uh it will be working as a sequence manner. Uh so we call it as a sequential workflow. Okay. So for this guys uh first of all uh we'll be installing the langraph okay inside our system. So to install the langraph guys you can visit this langraph documentation. So there uh you will be getting uh all kinds of actually tutorial how to install okay how to create your first agent. So each and everything they have already given. So see if you want to install this langraph you can use the pip command either you can use uv okay so let's use pep as of now maybe in future I will also show you how to use the uv package manager as well. So you just need to run pip install lang graph. So this lang graph would be installed inside your system.
So for this, let's open up our local folder. And here I'm going to just open up my Visual Code Studio H.
And I will also open up my terminal here.
Okay. So the first thing guys uh here I'm going to create a file called readme.
inside that I'm going to mention um all of the command you need to execute uh to install this langraph to create your virtual environment and everything. So if you want to create the virtual environment you have to execute this command called condrreten n okay then you can give the name of the environment I will give let's say lang graph test okay python you can specify the python version python is equal to 3.11 and hyphen y okay so this is the command first of all you have to execute this command to create a virtual environment then you'll be installing this line graph. Okay. Now you have to activate this environment. After that you'll be installing the requirements. We have to install pipener requirement.txt.
Okay. So these are the command guys you have to uh follow first of all. So let's create this requirement.xt here.
H. So inside that let's mention our line graph package.
Okay, lang graph. So apart from lang graph uh you need to install some other library as well like you need this lang chain open ai. Okay. So we are using this langchain openai because uh I'll be using my openi uh large language model but if you want you can also use any other model um from any other provider.
Let's say you can use open router, you can use grock API. Okay, you can use Gemini API, anything you can use. It's completely up to you. It's a very easy things. You just need to uh change this model provide at that time. Okay. So with me, I am having my open API key.
That's why I'll be using this one. Okay.
And if you want to use OpenAI API, so that time you have to install this langai because I told you langraph uh doesn't work actually independently internally it is uses langen. Okay. And uh for all the model uh let's say loading creating the prompt template we need the langen okay still langen is required then uh I also need pythonb for the environment management okay now guys uh you have to install this requirement txt file but before that I told you you have to create the environment so try to copy the first command and execute from your terminal so this will create the environment okay for you but for me this environment is already available I will activate the environment. So can't activate langraph test. Yeah. So you can see this is already available. But if you don't have just try to create it first of all then just execute this requirement command.
It will install everything. So for me it is already satisfied because I installed previously. Okay. Now once it is done now what I'm going to do guys um let me just tell you about the sequential workflow. Okay. Uh what is the workflow we'll be creating here? See here I'm going to create a very simple uh workflow without using any kinds of LLM.
Uh I'll also show you how to use uh LLM um how to create the LM workflow as well. Don't worry but this is our first workflow we are creating inside Lang graph and we don't know how to code inside Lang graph. Right. So to understand the workflow first of all we'll be creating a very simple workflow without using any kinds of LLM. Then I'm also going to show you how to use the LLM as well. Okay. So guys uh now let's see uh what workflow we'll be creating first of all. So here you can see uh we'll be creating a sequential workflow uh and the workflow is temperature conversion workflow. Okay. So here it doesn't have any kinds of LLM. As you can see this is a simple workflow we have created without using any kinds of LLM. So basically this workflow what it will do it will convert actually Celsius temperature to Fahrenheit. Okay. This is the only work this workflow will do. And if we convert this workflow in a graph. So this will look like that. So as you can see we have taken the start node then convert temperature node and the end node. So start and end would be common for all the workflow you'll be creating uh with the help of this langraph. This is a dummy nodes you can say because langraph understands okay workflow starts from here and it it uh ends actually here.
Okay. And basically it takes the input u to the like other nodes as well. And this will also have a state right state is a shared memory and this is a mutable u let's say object you can create this uh state with the help of pentic either you can use type dict okay anything you can um uh use it. So basically the state I have to share to all of the node so that it can take the data and it can update the data as well in real time. So you can see uh in this particular uh workflow the only function I have to write this conversion function temperature conversion function. So user will give Celsius uh temperature and I'll try to convert it to the Fahrenheit. Then this uh uh this Fahrenheit output would be show uh shows shows as an output. Okay. So you can see for this we have created we have taken a node convert temperature and this node would be a simple Python function. in that particular Python function what I will do I'll just try to I'll just try to uh write u um the uh code related conversion uh temperature conversion and whatever output we'll try to get we'll try to update in this particular state so here in this particular variable we'll try to update that let's say whatever uh temperature user will give this is in Celsius so this will save inside this particular state uh let's object and whatever I'll try to convert right uh in the Fahrenheit this one I'll try to save it here. Okay. Then whenever I'll try to show the output. So from here I'll try to read and I'll show the output here. So this is a simple workflow guys. Uh we have to create and this state is a shared memory. So this will go to the all of the uh all of the nodes. Okay. One by one and the complete you can see this diagram this workflow this is called actually graph. Okay I hope you cleared. Now let's try to code inside langraph. So what I'm going to do, I'm going to open up my uh So let's create a file here.
I'm going to create a file.
I'm going to name it as one temperature conversion workflow NB. Okay. So here I have taken the Jupyter notebook file guys because here I'm not creating any kinds of end to end project. I'm just explaining the concept. Uh that's why I think this notebook uh format would be uh great fit for that because I will also show you the uh workflow in a diagram. Okay. And this diagram I can't uh I can't actually uh show you inside Py file that's why I have taken this windyb file notebook file. So let's select our environment graph test. Yeah. So first of all uh what you have to do guys you have to uh import some library.
So here let me comment. First of all you have to import some library. Okay. So you have to import uh this line graph. So from line graph dot graph.
Okay. You have to import state graph.
Okay. You have to import state graph. If you check the documentation as well. So here also they are doing the same thing from lang graph they're importing state graph then start and end. Okay this is a dummy nodes I already told you this will be common for all the uh workflow you'll be creating with the help of this line graph. Okay. So let's try to import them.
H so state graph then I need start I need start then I need end.
So here state graph is the function with the help of that we create the graph.
Okay, entire graph it will be creating basically uh this helps to create the graph as well as uh to add the state uh inside our graph. Okay, now let me import them. Yeah, so import is successful. Uh that means we have already installed this langraph and we are able to import uh everything. Okay, then I also need to import this type dict from typing. So from typing.
So first of all I'm going to show you how we can create the state with the help of this type dict uh typed dict actually module u from python then later on I'm also going to show you how we can create this uh state with the help of piantic okay pientic is another uh python framework with the help of that you can also create the state so let's import typed dict this one now let me import all of them now the first thing Guys, I have to uh initialize the state uh state object.
Okay, state is important. Uh without state actually we can't uh create the graph. Then after creating the state, we'll be creating the entire graph.
First of all, we'll be um uh creating the nodes all the nodes. Then after that uh we'll be uh we'll be creating the ages as well. Okay. So this is called ages. Ages means this is the connection.
Let's say after uh which node uh which node would be executed. Okay. This is the connection. So this edges should be also created. Okay. And if we uh create all of them uh this will be uh this will become a graph. Okay. So now let's try to define the state here. Uh so here maybe I can comment define state h. So for this problem I told you state would be uh two state. Okay. uh one is temperature Celsius and temperature Fahrenheit. So let's try to define that.
So for this I'll write a class.
Okay, I'll write a class.
I'm I'm going to name this class as a temperature state.
Okay. And I'm going to inherit uh this uh class with this type dict uh function we have imported. Okay. Now basically you are telling this class uh um like this class right now can store uh any kinds of data as a key value pair. Okay.
Now the first key should be the temperature temp Celsius.
Okay. And uh you can mention the data type as well. What should be the data type for this particular u uh variable.
So basically uh Celsius should be in a float uh data type. I think you know that it can't be integer. It should be float. That's why I told uh it is a float. Okay, float data type. Then you have to write another variable called temperature Fahrenheit. So this should be also a float type data. Okay. So this will become our state. Okay. This will become our state and this state we'll be using inside our nodes. Okay. All of the nodes we'll be creating. Yeah. Now this state is also ready. Now let's work on this graph. So here what I'm going to do uh here let's say I'm going to comment define okay define and compile graph I think you know after defining the graph you have to compile I told you the graph execution process right in my previous video as well so to define the graph I told you first of all you have to use this state graph of uh function you have to create a object of that. So let's uh create a object called graph. Then I'm going to initialize state graph and inside that you have to pass the state. The state you have created this is the state temperature state. Okay. So basically this will take the state. Now see what is happening if you're using the state graph object right state graph functionality and if you're passing the state inside that uh so basically this particular function will try to provide the state to all of the nodes. Okay.
automatically one by one. You don't need to manually provide that. Okay. So this is the main benefit here. So that's why we're using the state graph. State graph uh basically takes this uh state object and it provides to all of the nodes.
Okay. One by one. Now uh we have defined our graph here.
So this is called definition of the graph. Define your graph.
define your graph. Now next I have to add the nodes nodes to your graph to the graph. So to add the nodes guys you just need to write graph dot add nodes.
Okay add nodes. Then you have to provide the nodes name. Okay nodes name. At the very first time you have to give the nodes name. Let's say if you see my nodes here. Okay. If you see my nodes here. So I have only one nodes which is this uh convert temperature. Right? I have only one nodes which is convert temperature. Now you can ask me start and end ends is also a node right? But this is a dummy node. This thing you don't need to create it separately.
Okay. So whenever you are uh defining the ages okay that time you will mention that let's say uh after start u after start this convert temperature node would be connected okay this is called actually connection that's why we call it as a um like uh dummy nodes we don't need to create separately here okay we don't need to add separately here so by default your uh lang graph adds that and we just need to uh we just need to connect this particular nodes to our actual nodes Okay, this is the fun here.
Now, let me first of all create none.
I'm going to explain okay how it works.
So, first of all, here I have to add our nodes. So, here I only have one nodes which is convert temperature. So, maybe I can just give a name. I'll give let's say convert.
Okay, convert temp. You can give any name. It's up to you. But make sure uh the name you are giving here the same name you use for creating that particular function. Okay.
Now this will take that uh convert temperature function object. Okay, this will take this convert temperature function object and I told you every node takes a function and this function is nothing but it's a python simple function. Okay, now let's try to create this convert temperature function individually here. So what I'm going to do I'm going to uh simply um come here. So basically this is our first node.
So now let's write the function. So def convert temperature. So this will take a state.
Okay, this will take a state. What is this state? This temperature state and this will return uh also the state.
I told you every time this state would be the input and each and every nodes will return some kinds of output. This output should be also state. Okay, the updated state. So that's why I have to uh I have to give this um blueprint that uh this function takes uh state uh state as an input and it also returns the state. Okay, this temperature state only. So that's how you can give the blueprint of a function. Okay. Now inside that first of all I'll take the Celsius data whatever data user will provide. So here I'll just write Celsius.
Celsius. Okay. Is equal to this Celsius would be available inside state. Okay.
So we are calling state and we are extracting the Celsius only because this is a dictionary right now and you know how to work with the dictionary right?
Uh so we are working in a sim. Then after that we'll try to convert uh we'll try to convert this to the Fahrenheit.
So I've already written the code. Let me show you.
So here we are converting to the Fahrenheit. Okay you can see Celsius to Fahrenheit. And if you want to see how to convert Celsius to Fahrenheit, you can go to Google and you can search here. So you will see the formula. Okay. So this is the formula. So we are replicating the same formula here. You can see we are replicating the self formula. We are first of all multiplying this Celsius uh with uh 9 out of five. Then we are adding 32 with that. So once we get this Fahrenheit, we have to also we have to also update the state memory, right? We have to also update the state memory because we have taken a variable called temperature Fahrenheit. Now whatever Fahrenheit we got, we have to update inside this particular state, right? So for this uh that's how we can update because this is a dictionary, right? This is a dictionary. So I'm uh just adding this particular new value to this variable to this key. Right? So here we're using round function because if it is a float type uh data so after point there would be too many number but I'm not taking too too many number. I'm only taking last two uh digit. Okay after after the point now once it is done I'm going to simply return this state. So return this state. Okay that's it. So this is our simple Python function we have created.
Okay. Now this function can convert any kinds of Celsius data to Fahrenheit and we are updating the state here. Okay, that's it. Now this particular function will object will come here. So that's how guys we have created our first node.
We have added our first node. Now see this node has added. Okay. Now you have to create this edges. Okay, you have to create this edges that that means the connection the flow of execution. So for this let's do that. So here I'm going to comment add edges to the graph. So first of all you have to add the first edges. Now see this start node will come here. Okay. Now see so here I'll just write start and convert them. Just try to see this uh graph. See now I'm telling this start node would be connected to the convert them. Okay, that means this is the connection we are making right now because from here it will start and it will go go to the convert temperature. See here we're doing start to convert temperature.
Okay, now I will add the second graph sorry second ed is now convert them to end. Now you can see uh so basically let me just show you. See first of all we connect it here right that means this connection this connection we have built start to convert temperature now convert temperature to end okay that means this particular edge we are getting right now this edge is already created start to convert them now convert them to end okay particular uh this this edge we are getting uh this edge is already created now we are doing it here so you can see convert them to end okay I hope you clear guys now once this is done then you We'll be compiling the graph. So compile the graph. So you just need to write uh graph dot compile.
Okay. And this returns you the workflow.
So maybe I can store inside a variable workflow. Okay. Now let's compile.
So compilation is also done. Now we'll simply execute the graph.
Execute the graph.
Now guys, we'll try to execute the graph. So to execute the graph uh first of all you have to take the initial state that means the input uh which is the uh Celsius okay Celsius uh um temperature. So here what I can do I can create a variable I'm going to name it as you can also call it as input state or initial state okay it's up to you but I've named it as initial state because this this will become my initial state.
Okay, the first state which is nothing but the uh temperature Celsius, right?
So, initial state. So, temperature Celsius I'm giving let's say 28.5.
Now this thing will try to provide to the workflow. So, I have created my workflow.
Workflow dot invoke. Now you can perform the invoke operation because this is a lang graph object. Inside that I'm going to pass my initial state and this will uh return you the final state. Okay, final state that means the output final state and this final state I'm going to simply print it here. Okay, done. Now let's uh see whether it is working or not. Now see if I execute.
Now see initially we have given 28.5.
This is the Celsius temperature. Now the final state is uh temp temperature Fahrenheit 83 uh 3. Okay, you can also try with Google.
Let's say if I'm giving Celsius now see Celsius is 28.5 and you are getting 83.3 you can see 83.3 that means it's working fine right so we are able to execute our first graph guys okay we are able to create our first graph and this is completely working fine see there is no problem now if you want to see this graph as a uh image you can also do that that means you can visualize this particular graph this is very interesting things I found in langraph.
So let me just comment here. Okay.
Visualize graph.
So I found this code inside this langraph documentation.
Yeah. So here we are using this ipython display um and we are importing this image function. Inside that we are just giving workflow.get graph. Okay.
Basically this will get the graph and we are drawing this particular graph as a mar mermaid png. Okay. So mermaid is a kinds of uh you can talk about it's a flowchart okay flowchart style you can search on Google mermaid flowchart or simply search for mermaid you will see that uh okay mermaid flowchart yeah see so this will give you this kinds of flowchart okay now let me show you if I execute see guys you are getting the flowchart now see this flowchart And this coart just try to tell me whether you are able to see this is same or not. Okay, this is same right. So you can see start then it is going to the convert temperature then it is uh giving you the final output that means the end nodes. Okay, amazing. So guys congratulation we have created our first workflow first uh langraph graph and this is completely working fine. So guys, now what we'll do, we'll just try to uh update uh the workflow we have created. Let's say this is our workflow. Uh so here we are only converting the temperature to the Fahrenheit. Now what I have done, I created another workflow. So this is the sim similar workflow only I have added a new node here. You can see. So the node name is label weather. So what this label weather will do? Let's say the Fahrenheit temperature we are getting.
uh we'll just try to label that. Label means let's say if this Fahrenheit temperature is less than 50 that time weather starters is cold. Okay. If let's say Fahrenheit temperature is it is uh less than equal 50 and less than equal uh 77 that time it is mild. Okay. If it is less than 95 uh then that time it is hot and if it is not all of them that means it is extreme heat. Okay. So this kinds of labeling I want to do. So for this I have created another node here.
I'll I'll be writing another node here.
This particular node will try to um try to uh figure out the weather status.
Okay, it will try to figure out the weather status whether the weather is hot, cold, mild, okay or extreme hot etc. Right? And uh to create this particular uh graph guys I need another state called weather status because uh this nodes will return the label right whether it is hot, cold, mild or anything. So this particular data I have to also save in the state that's why I have taken another variable called weather status here. But previously this was missing here. Okay. Now let's try to update this. So what I'm going to do I'm going to open up my code again. So see here I'll add another nodes. Okay. Okay, I'll add another nodes here.
Yeah, let's say the node name is uh label weather. Okay, and it will take a function, Python function called label weather. So now let's write this function. So after this function, maybe I can write it here.
So def label weather. So this will take this state as an input.
Okay. And it will also return this state as an output.
State as an output. Okay. So already I got the suggestion code from my uh from my co-pilot. But let me show you the code I have written.
So this is the code. Okay. Now let me also comment here.
Let's say this is for label weather condition. This is our second note.
Okay. So now what what we are doing the Fahrenheit temperature we are getting we're taking it from the state. Okay. We are pulling the Fahrenheit from the state instead of Celsius. Uh because I want to check with respect to the Fahrenheit. Okay. I want to check with respect to Fahrenheit. You can also do it with the help of Celsius as well.
Celsius temperature as well. You can also label that. But I want to do it with the help of Finite. I want to I want to only show you the output we are getting whether we can use it inside this particular node or not. Okay, that's why I'm using this uh temperature um Fahrenheit. Then after that I'm checking if Fahrenheit is less than 50 that time uh weather status should be cold. We are updating this state. Okay, there should be another variable called weather status and right now this status should be hot, cold, mild. So I can consider this should be a string type data. Okay, now let me execute this node. Yeah, now you can see this weather starter should be cold. If it is uh less than and equal 50 or less than 73 uh 77 that time the weather status should be mild. If it is uh less than 77 and less than 95 this should be hot otherwise it should be extreme heat.
Okay. So this is our uh uh this is our logic we have written inside this label weather function and we are returning this state. Okay. Now let me execute.
Now what I'm going to do just execute from the beginning one one more time just to show you the output.
H. So the node add is done. Now we'll try to add the edges. Okay. Now we'll add the edges. That means after convert temperature, this will go to the label weather. Okay. So here I'm going to write um see uh start start uh convert temperature. Okay, that means this part is done. Now I have to work on this part. Convert temperature to level weather. So here I have to write convert temperature to level weather.
Okay. Now level weather to end. Now here I just need to light write label weather to end. Okay, now I think you have understood this particular edge connection. Okay, this is like very amazing right and if you understand this edge connection just trust me you can create any kinds of workflow inside lang graph. Okay, that's why I'm showing you this easy workflow at the very beginning. Now once it is done now let's try to compile the graph again. Then I will execute the graph. This only takes the uh temperature Celsius input.
Uh so you can see temperature Celsius this 28.5 we are getting the Fahrenheit and based on the Fahrenheit result we are seeing that weather status is hot right now. You can check if it is 83 right 83 that means here this condition is missing here. Okay that means this particular condition is hot right now.
Okay. Now if I visualize this graph now see another node is added which is level weather. Now this uh this graph and this graph I think you can match. Okay great guys. So yes uh this was the first uh sequential uh sequential actually workflow we have created without using any kinds of large language model. So now I'm going to show you how we can create sequential workflow uh with the help of large language model as well. So guys uh now we'll be creating a LLM workflow. Uh previously the workflow I showed you uh this workflow I have created this is a nonLM based workflow.
Uh here I'm not using any kinds of LLM.
Okay. Uh with the help of simple Python function simple Python logic I was handling everything. Now let's say you want to use LLM. Okay. LLM inside the workflow. So how to create the workflow for that? Let's try to understand and see here our main goal is to learn the langraph uh like workflow creation. The problem statement I'm taking uh it might be very simple. Uh you can think about okay this this thing I can create with the help of simple python function only but uh why we are writing that much line of code. Okay. So our intention is to learn the um langraph workflow. Okay.
How we can use the langraph? How we can create the workflow? how we can create the node edges okay each and everything this idea I'm giving you okay so problem statement doesn't matter you can use any kinds of problem statement so after learning this simple concept so later on whenever we'll be creating the actual agents or big project so this concept will help us a lot right so that's why we are um uh explaining this concept with the help of simple workflow now here I'm going to take another uh very simple workflow guys for the LA workflow so here what I'm going to do uh here this is the uh workflow this is the graph you can see so basically this will have the start and end nodes definitely because this is common so the only one nodes I'll be creating here the lmqa nodes okay so lmqa means what it will perform so basically user will give some of the question and this lm will uh answer that particular question and this will return you the answer only this simple operation will be doing okay in this particular workflow so for this what should be the state the state should Definitely the question whatever question user is giving and whatever answer we are getting from the LLM this should be another state okay so this state should be passed to all of the nodes and it will real time update that and our uh uh workflow would be ended so this is the simple uh graph guys now let's try to implement this graph with the help of lang graph so for this I have already prepared a notebook as you can see simple keyway lm workflow so let me open it up and uh to run this um um code guys you need this file because in the env I have mentioned my openi API key because here we are using large language model and I'm using openi large language model but if you want to use any other large language model you can use it completely fine for this you can change the API key here so this is the uh code guys this is the notebook I have prepared now this is this looks same as per your previous uh notebook only the things I have added the llm functionality here now first of all you have to import some necessary library.
So see you can see we are importing the same uh state graph start ends from the lang graph graph. Then one additional package we're importing langchen peni chat opi I told you if I want to use any kinds of uh let's say large language model or whatever I have to still use langen because langraph doesn't have direct functionality so that functionality can load any kinds of llm okay so it has to use this langen to load the large language model. So here one more thing you are also learning how we can use langen along with the lang graph. Okay. So this is the concept. So we are importing chat open a let's say if you're using any other other provider if you're using grock or open router inside lang it is available you simply you can open it up. Then we are also importing type dict just to create the state and the load envoirment variable.
Now the first step we are loading the environment variable this env. For this we are calling this load env. So if it is returns two okay first of all I have to import this now I'll execute now if it if it returns two that means this env file is present and inside that we have the uh key right it has loaded successfully now we'll try to define the large language model okay so here we are creating a model object and we are calling the chat openai so by default I think it loads a model okay uh I think GPT 3.5 tuba model it will load you can also change the model parameter if you want to use any other model like GPT5 five or four you can easily do that but I will take the default model it's completely fine for me okay so I got my model object now here you can change with any model object either you are using grock uh either you can using open router Gemini anything you can use now we have to create this state okay this state we have to create and I told you to create this workflow I need u this these two state question and answer so this thing I'll be creating right now you can see I have written a class I named it as lm state and again I'm inheriting with the help of type dict.
Now we can store the data as a question uh key value pair. Now the first state you can see this is the question and the data type should be string because usually uh whatever question we are writing this is kinds of string type data and answer also this is string type data. Okay, we are preferring the state.
Now once uh state preparation is done now we'll be creating the nodes. But before uh showing you the nodes u logic I will show you the graph definition. So you can see guys uh we are creating the state graph and we are passing the state the state we have created this state then after that we are adding the nodes okay the first node we have added the lm QA okay now this lmqa we have to write okay this lmqa we have to write so this this is this should be a simple python function inside that we'll perform the lm call so see lm qa this is the function we are writing this will take this state as an input and return the state as an output now whatever question user is giving I am taking it from the state. Then I'm preparing a prompt. Answer the following questions. We're giving the questions.
Then this particular prompt I'm just giving to the model. We're just doing model.info. Giving the prompt. And whatever content it is giving me, I'm just extracting in the answer. And this answer I'm updating in the state memory again. Okay. So you can see it is having the answer key. I'm updating the value there. And we're returning the state.
Okay. Now let's execute.
Now once our node is added now we'll be working on the edges. We'll try to connect the edges. Now if you see the graph so see first of all start node will connect to the lm QA. So we are connecting that start to lm QA. Then lmqa will be connected to the end. You can see then add lmqa to end. Okay. And I told you start and end is a default node inside langraph. You don't need to manually add that. This is a dummy node.
Okay, so only we'll be calling whenever we'll be adding the edges. So once it is done, we'll try to compile the graph.
Let's compile. Okay, now everything is ready. Now we can execute the graph. So we are preparing the initial state which is nothing but the question. Let's say here I'm giving a question who is the creator of Python and uh the workflow we have created, we are just doing the inbing operation. We are giving the initial state and we are getting the final state output. Then we are just returning the answer. So I'm asking a question who is the creator of Python.
Now let's see.
So see the Python was created by Guido Vandrom in the late '90s80s. Okay, 1980s. So it's working fine. Okay, you can give any other question as well. It will work. Now let's try to visualize the graph. So here I will execute this code. This code is common. Now see this is uh the graph. You can see start, LM, QA and ends. Okay, amazing. So this is the actually LM workflow we have created. So previously we created without uh nonLM workflow. Now we have created LM based workflow. Okay, I hope you get it. So that's how guys if you want to use any kinds of large name based model inside the workflow, you can uh define it like that. Okay, now we'll be learning another amazing concept. I I think I told you in my previous video as well called promchaining. Promching means you can use multiple LM calls. See here I'm using only one LM call, right?
One LM call. But if you want to use multiple lm call that is also possible.
So we'll be learning in the pom uh we'll be learning this concept in the prom chaining. Okay. So I'm going to create another notebook. There I'm going to show you how we can perform the promching operation. That means one uh llm answer you are getting you can pass this answer to another lm to get another response. Okay. This is also possible here. Let me show you that part as well.
So guys now I'll explain about this prom chaining. Uh this is another sequential workflow. So in our previous uh workflow we did the single LM call that means uh user was giving any kinds of question and it was generating the answer but let's say you want to do multiple LM call that means uh after one LM call that output you want to use for another LM okay as an input this is called prompt chaining so for an example let me just uh tell you see here what I'm going to do I'm going to let's say uh create a blog generator okay blog generator from a topic. So here let's see user will give a topic name. Okay. So this will generate a blog. Okay. Block for that.
But this blog I'm not going to generate directly. Instead of that what I'm going to do first of all I'm going to take this topic name. Then I'm going to pass to LLM. Okay. I'm going to pass to LLM.
And this LLM will try to generate the outline. Okay. Outline for the block. So let's say this will generate the outline. Okay. outline of the block from this LLM and whatever outline I will give uh get from this LLM I'll pass to another LLM okay and this LLM will try to take this topic as well as this outline and it will generate the block okay and we'll be getting the final block as an output okay at the last so this is the workflow and this is called actually prompt chaining concept okay prompt chaining concept basically whatever output we are ing from a first large lang based model we are passing it to the second LLM as an input and we are getting a final output that means we are calling multiple LM call here this is called prompt shading concept okay so this workflow we'll try to create right now now see guys I have already created this uh graph okay uh I have already created this workflow as you can see so start and end would be common so here I have to create two nodes one is the create outline that means whatever input I'll be getting that means uh the topic so first of all I'll generate outline and this outline as well as the topic I'll send to another nodes which is create block. This will generate the block and I'll be getting the final block as an output. Okay. And what should be the state for this particular uh workflow? First of all the title that means the blog title. Okay. Then whatever outline it will generate this outline as well and whatever content that means the blog will be getting this should be another state. Okay. So that means three state will be available for this particular uh workflow for this particular graph. Okay. Now let's try to represent in the uh lang graph code. So for this I have created another notebook as you can see prompt chaining workflow.
So let's open it up. So this is the notebook. So again this is the same uh as per your previous notebook I created.
First of all we have to import all the necessary libraries. You can see we are importing state graph start ends chat openi. Okay. Then type d lo env. Then we'll be loading the env uh env file to load the openi key. Then we'll be defining the large language model. Then we'll be creating the state and uh this state name I have uh named it as blog state. And again I'm doing the inheritant inheritance operation with the help of this type dict. Now we are preparing the state. The state state means the title, outline and the content. Okay. Three state we are taking h. Now before creating the nodes first of all let me show you the graph. Okay.
See here we are creating the graph state graph and we are passing the state and first of all we are adding the nodes.
Okay. So the first nodes we are adding for the create outline. Now let me show you this create outline function. So this is the create outline function. So this will take this state as an uh input and uh return you the state as an output. Okay. So whatever title user is giving first of all I'm taking the title and here I'm preparing a prompt generate a detailed outline for the blog uh for a blog on the topic. So then we are passing it to the LLM. LM is giving the outline. This outline we are saving inside the state. Okay, inside outline variable then we are returning the state. Then after that if you show uh if you see I'm adding another nodes okay called generate blog. Now whatever outline I got and title I got I will pass to this particular function. You can see uh it will take from this state the title as well as the outline. Then I'm preparing another prompt. This prompt is telling write a detailed blog on the title. Okay, using the following outline. The outline we are getting as well as the title we are using here.
Then we're passing it to the LLM. Okay, again we're doing the LM call. Whatever LM is generating, I'm just storing in the content. That means this is the final block. Okay, I'm storing inside this content uh content state. Okay, so it is done. Now you can see we are adding both of the nodes one by one. So this uh nodes is added create outline and uh create blocks. Now I have to create the edges. Now to create the edges guys here you can see I'm creating the edges first of all age would be created start to create outline you can see start to create outline then create outline to create block create outline to create block okay then create block to end create block to end okay then we are doing the compile operation then now we'll execute the graph so here as initial state we are giving the title okay we are giving uh title let's say raise of AI in India let's say this is our uh title and I want to generate outline and then blog now we are giving into the workflow we are doing the invoking operation and we are getting the final state as an output so it is doing multiple lm call that's why it's taking some time first of all it will invoke first LM then the second LM Now see here we are getting the output. So this is the title. Based on the title we are getting the outline and also we have a content final content I think somewhere content is also there.
Uh we can see uh here. So final state uh first of all I want to see the outline.
So this is the outline. Okay it has prepared. Now if I want to show you the content that means the blog. So this is the blog guys. Okay I'm getting. So this is called prompt trading concept. Now if I want to show you the graph. So this is the graph. You start create outline then it will go to the generate block create block then hands.
Okay I hope you got it guys. Okay. So that's how guys we can create any kinds of sequential workflow either you can create a nonLM based either you can create LLM based either you can create prompt chaining based anything you can create only you just need to know how to uh how to define these uh nodes and this particular connection. Okay. edge connection. If you can understand this concept, you can just trust me, you can create any kinds of workflow, okay, inside lang graph. Now, I think by end of this video, it is uh very much clear how we can create any kinds of sequential workflow inside langraph.
Okay, don't worry. I'm also going to show you uh like complex workflow as well like parallel workflow. Okay, there are lots of workflow we saw, right?
We'll be learning each of them. Don't need to worry. But before starting that complex workflow, first of all, I've given you the sequential workflow uh I think uh now you have enough understanding how to code inside langraph at least. Right now I think these are the syntax won't be confusion to you. Right? Like what is a node? What is AJS? Okay. So so far we have learned so many theoretical concept. Now we have seen the practical implementation and all of this code and everything would be available in the description.
From there you can uh download and you can uh try in your system. And one more exercise you can perform let's say this proming u we have done maybe you can add another node for the evalu evaluation for this block. Let's say the blog you are generating whether this is good or bad. You can uh take another LLM, you can take another nodes and you can evaluate that and you can also uh print the evaluation result. Let's say it needs the feedback or not or it is completely fine. This kinds of result you can also uh print. Okay, that means you you have to take another state here and whatever result you are getting you can also show the result here. Okay, after you can see uh content maybe you can u print another result which is evaluator result. Okay. Now the best part is of this state is you you can access all of the output. Okay. All of the output input anytime. Let's say we have generated uh these three uh three things right? Uh title, outline and content and it is accessible anytime.
Okay. This is the final state. From the fin from the final state you can access um any kinds of state. Let's you can access title, outline, content or if you're adding the evaluator you can access it anytime. Okay. So yes that's it guys. So yes uh this is all about from this video. I hope you got it. Now in the next video guys we'll be uh we'll be learning uh some other workflow as well. Okay like uh parallel workflow.
We'll be also learning conditional workflow, iterative workflow. Okay, all the workflow we'll try to cover one by one. So yes guys, this is all about it and uh if you found this content useful, please try to subscribe to my channel and hit the like and uh please try to share this uh video with your friends and family. So, thank you so much guys for watching this video and I will see you next time.
Related Videos
OpenHuman VS Hermes AI: Who Wins?
JulianGoldieSEO
285 views•2026-05-29
Long-Running Agents — Build an Agent That Never Forgets with Google ADK
suryakunju
142 views•2026-05-30
5 Mind Blowing Omni Uses Cases
PaulJLipsky
1K views•2026-06-02
This computer is made from real human brain cells. And you can buy it.
Talktmsmedia
3K views•2026-05-28
BREAKING: Microsoft’s New Image Generating Model Beat Out GPT 1.5 and Nano Banana 2
aimmediahouse
122 views•2026-06-03
I Made the Same Anime Fight Scene in Every AI Video Generator
NobleGooseAnime
295 views•2026-05-30
Nvidia Bets Big On AI PCs | New Chip To Power Windows Laptops | Technology | AI Updates | N18S
cnnnews18
3K views•2026-06-01
I Tested NEW Opus 4.8 on Four Projects (Updated LLM Leaderboard)
AICodingDaily
298 views•2026-05-29











