Shared State in Flowise is Literally Game Changing β
FlowiseAI v3 TutorialRecentπ
2025-06-19
Tutorial Overview β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β LEARNING PATH β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β LEARN β
β βββββ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Watch βββββΊβ Understand βββββΊβ Follow β β
β β Tutorial β β Concepts β β Along β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β
β βΌ β
β PRACTICE β
β ββββββββ β
β βββββββββββββββ βββββββββββββββ β
β β Try It βββββΊβ Experiment β β
β β Yourself β β & Adapt β β
β βββββββββββββββ βββββββββββββββ β
β β β
β βΌ β
β MASTER β
β ββββββ β
β βββββββββββββββ βββββββββββββββ β
β β Build βββββΊβ Share & β β
β β Your Own β β Iterate β β
β βββββββββββββββ βββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββKey Takeaways β
- Core concepts explained
- Step-by-step implementation
- Practical examples
Transcript β
[00:00] So I wanted to create this quick video going over what shared state is in flowwise and when and how to use it. It's an important topic in agent flows and it's actually a super powerful feature for saving on token costs improve performance and improve the results from the LLMs. And you might have seen it being used in some of the more advanced workflows like the supervisor team where if we open the supervisor we can see these references to updating flow state. And if we open
[00:31] up the next note we can see references to state as well. And if we have a look at the software engineer we can see some references to some state variables as well. So you might be wondering what the heck state is and why you would want to use it and what the benefit is. So hopefully I can answer all of these questions in this video. Let's try to explain this with a simple diagram. Let's say our workflow consists of a few agents. So we've got agent one, we've got agent 2, and let's add an LLM node
[01:03] as well. In order for these agents to work together, they need the ability to share data with each other. And Flowwise gives us plenty of ways to do that. And we'll explore all of that in this video. Now our workflows are always flowing from left to right. So agent one will perform some task and provide some output. Then it can pass the output to agent two and agent two can use the output from agent one to perform its task and then pass its responses on to the third node and finally we'll get
[01:34] some output. Now this is basically how deterministic workflows work and this is how platforms like make.com and N8N works. Nodes inherit values from previous nodes in the workflow. Now with flow-wise, we have more options. Nodes and flow wise also have access to shared state. Now there's different types of states. The first one being the conversation history. So agent one could execute and then write its response to this global conversation history. Agent
[02:07] two can then retrieve the conversation history, do its thing and write its response to the conversation history as well. And then of course our third node can also look at the conversation history, retrieve whatever it needs from the history and then write out its response. Now using the conversation history in this way could lead to its own set of issues. The first being that the conversation context keeps growing with each note that is executed. And then when these nodes retrieve the
[02:38] conversation, it's pulling in the entire conversation history each and every time. So the conversation context will greatly increase with each node in the workflow, using up way too many tokens and driving up costs. Furthermore, the quality of each of these models will start to reduce as the context window increases. Another option that's available in agent flows is something called flow state. And what this allows us to do is to create unique containers or variables which we can define at the
[03:10] start of the flow. And then each of these agents will have the ability to access and update those containers or variables. So we could have a variable for a topic. Maybe we've got something for an outline. If we were generating a blog, for example, let's just remove these arrows for a second. And maybe we also have something called post. And finally, maybe we've got a variable for the social media post. So the user's topic could be stored in this topic
[03:42] container. And let's say agent one is responsible for generating the post outline. Agent one could simply grab the topic from this container, generate the outline, and then store the outline in this container. And let's assume agent 2 is responsible for generating the blog post. Now, agent 2 might not need the topic anymore. And hypothetically, it only needs the outline. So, agent 2 can simply grab the outline. In fact, let's draw it like this. So, agent 2 could
[04:14] grab the outline, generate the post, and then store the post in this container. And the benefit here is that this agent is no longer dependent on grabbing the value from an agent before it. And it's not pulling in the entire conversation history either. It simply says grab the outline from this container and generate the post based on whatever is sitting in this container. That's it. The same thing for this final node. Maybe this node is responsible for building the X
[04:45] post. So all this guy is interested in is grabbing the post from this post container and generating the output and then maybe storing it in the social container or variable. And maybe we've got some final LLM in this flow that's responsible for writing some report back to the user. Now this is all very high level. So let's actually jump into flowwise and let's have a look at building all of this out. So from agent flows, let's create a new agent flow and let's call this one blog creation. So
[05:17] let's create a very simple flow that will create that post outline, generate the post and create the expost as well promoting the article. First in the state node, we won't change anything else. We'll have a look at flow state in a minute. But first, let's simply add an LLM node and let's call this outline generator. Then for the model, I am running FlowWise locally at the minute. So I'll just use a free open source model that's running on my own machine. And if you would like to learn how to
[05:48] set this up yourself, then I'll leave a link to my local setup video in the description. For the model name, I'll just use Llama 3.2. And that's it. Then under messages, let's change this to RO. Let's change the RO to system. And for the content, let's say generate a blog post outline based on the user's topic. Respond with the blog outline only. All right. And what we'll do for now is use
[06:18] the conversation history to get this entire flow to work. So let's select enable memory. And that will just pull in the full conversation history into this node. And that's all we have to do. Let's connect our start node. I'm just going to test this real quick. So, let's open the chat and let's enter. I would like to create a blog post on how AI agents can assist developers in being more productive. Let's send this. And there we go. We get our blog outline coming back. And if we open up the
[06:49] process flow, if we expand the start node, we can have a look at our outline generator. And this is giving us our system prompt, the user message, and of course the output that was just generated. And I want you to pay special attention to the execution time as well as the amount of tokens that's being used. So we're already up to about 400 tokens. Let's keep adding to this. I'm actually going to copy this node. Let's connect it. And let's rename this to block post generator. I'll use a llama
[07:21] again. And this time for the system prompt, let's enter generate a blog post based on the user's topic and the blog outline. Respond with a blog post only. And we'll leave enable memory enabled because we want this node to have a view of the entire conversation history. And let's add another node. Let's connect these. And let's call this one x post generator. And for the system message, let's say your role is to generate an X/
[07:51] Twitter post to promote the blog post. Respond with the X/ Twitter post only. Cool. Let's save this. We've got memory enabled. And that should be it. And actually, let's add one more node. Let's connect these. And let's just say summary. And for the system prompt, we can just say, so we'll say create a report containing the following users topic, the blog post, and the X post. Let's save this. I'm going to save the flow, and let's run this again with the
[08:23] exact same prompt. I'm actually going to expand this process flow so we can see exactly what's going on. All right, we are getting our response back from the summary node. So just looking at this, we can see that we got the original user's topic back. We get the complete blog post back as well as the X post. But let's see what actually happened behind the scenes. Each of these nodes were executed in sequence. But what I want to show you is the token usage for each of these. The outline generator
[08:53] used about 325 tokens. All right. Then having a look at the blog post generator, we can see that it's up to 1,63 tokens, which makes sense because generating a blog post will use a lot of tokens. But if we scroll down to the expost generator, we're using 1,120 tokens. And finally, if we look at the summary, it's using nearly 2,000 tokens. So hopefully you can see that each note in this flow is adding to the context window length, which is really not
[09:24] ideal. Some of these nodes only have to use very specific information from the flow in order to perform its task, not the entire conversation history. Now, there are plenty of use cases where using the conversation history might be the best and only option that you have. Now, if one or more of your notes do not require the entire conversation history, then one of these other techniques might be better for you. For example, this expost generator really doesn't need everything before this post generator
[09:57] node. It doesn't care what the topic was. It doesn't care what the outline was. All this node really cares about was the post that was generated over here. So, this takes me to the second technique where these nodes can inherit values from any of the nodes that executed before it. This is very similar to other deterministic workflow tools that you might have seen. In fact, let's change this expost node to no longer use the conversation history. So, I'm going to disable enable memory and instead
[10:28] we'll grab the value that was generated by the blog post node. So, what we can do is add a message. Let's add a user message and in here we can simply say blog post. Now in order to use variables in flow-wise we can type double curly braces and this brings up a lot of different context in this flow. So we get the chat context which includes the chat window or if we scroll down we can see things like session ids and chat ids and scrolling down even further we can
[11:01] see node outputs and in here we can see the outline generator and the block post generator and that's the one we want. So let's simply close this node and let's run this again. I'm going to clear the chat and let's run this plant again. All right. Now let's have a look at this process flow. Now we'll see that the outline generator used about 473 tokens. Then the block post generator which is still using the conversation history used about 1,042 tokens. Now, if we have
[11:33] a look at the expose generator, we can see that this only uses 680 tokens, which is a great reduction. And that's simply because we're not using the entire conversation history this time. We're only giving this note the specific information that it needs. And trust me, giving it specific context can greatly improve the quality of the responses as well. Now, let's have a look at flow state. This is an incredibly powerful feature in Flowwise. If you're familiar with using state in frameworks like lang graph then you'll feel right at home. We
[12:06] start a flow by defining these variables and these variables are accessible throughout the entire workflow. So first I'll show you how we can change this workflow to use flow state and this really is still a very simple example and then I'll show you a few other cool things we can do with flow state as well. So if you're enjoying this video then please hit the like button and subscribe to my channel for more flowwise content. Right. So let's dive into flow state. And don't be scared. I'm just going to delete all of these temporarily so that we can spend the
[12:37] time understanding how flow state works. When we double click on the start node, we can set all these variables or containers that should be available during this flow. So let's add our first one. We know that we want to store the user's topic in some variable. And let's actually add another one. We want to store the outline in a variable. And maybe we also want to store the blog post. And finally, let's store the X post in a variable as well. Now, I've left all of the values blank because
[13:09] initially none of these fields will be populated. Let's close the start node. And in the chat, let's simply say, hey, it really doesn't matter what we enter. I just want to show you what the start note looks like. Of course, we get the user's input, but now we also get the state object which contains all of our variables topic, outline, blog post, and expost with blank values. Now, we can read and set these values using the nodes in Flowwise. So, let's add our first one. I'm going to add this llm
[13:41] node. And this node is responsible for extracting the topic from the user's message. So, let's say grab topic. Let's save this. And I'm going to use chat o llama. And I'll just use llama 3.2 as the model. Then for the system message, I'm going to say extract the topic from the users message. Then let's add a user message. And let's just say user message. And the value that we want to
[14:11] pass into this is the question from the chat window. Now I'm not going to use conversation history. So I'll disable this toggle and then scrolling down I want to store the topic in our state variables. So all we have to do is under update flow state let's click on this button then for the key and when I click on this field I should see all those variables and I don't and that is because I didn't connect my start node to my llm node. All right let's try this
[14:41] again. When I click on the key field I can now see all the variables in our flow state. Let's select topic. And for the value, we'll use the value that was generated by this node. So we can grab any value in our workflow by typing double curly braces and we'll select output. This is the output from the current node. Cool. We can already test this. So in the chat window, so let's enter I would like to create a blog post on how AI agents can assist developers
[15:12] in being more productive. So the reason I'm using this node is the user can enter a lot of different things in this box and we only want to get the topic from this. We don't want to include things like I would like to create that's senseless. We only want to grab something like how AI agents can assist developers in being more productive. Let's do that. Let's send this. And if we have a look at grab topic, we can see the system message, the user message, and the output. We can also see that the
[15:42] topic variable was updated in state and that contains the response from the lln. Now I actually don't want the lln to store things like the topic of the user's blog is that's also a waste of space. So I'm just going to change the system prompt slightly. Let's say respond with the topic only. All right, let's save this flow. Let's send the same prompt again. And now if we look at process flow, we can see the start node starts off with these blank variables.
[16:14] Then the grab topic node runs and it updates this topic variable with the topic. Cool. This means that any other nodes in this workflow can now access and use this value. Let's see that in action. So let's add another node like the LLM node. Let's connect these and then let's rename this to blog outline. and let's select our model. So, I'll just use Llama 3.2. Of course, you're more than welcome to follow along using chat openai or Grock or whatever else. I
[16:47] just found that using these small models locally can actually save a bit of money. Right, let's add our system message and let's say create a blog outline based on the users topic. Respond with the blog outline only. Then let's add a user message and let's say topic. And now what we can do is grab the topic from our state variables. If we scroll down to the bottom, we can see this flow state section. And from here we've got access to all of our
[17:18] variables. So let's grab our topic. All right, we also want to disable the conversation history as we're only relying on the value from state. And then finally, we want to update our state with this block outline. So for the key, let's grab outline and let's store the output from this current node. Awesome. Let's save this. Let's send our prompt. And that was super quick. I'm already getting a response back. All right, let's have a look. So initially
[17:51] our state was empty. Then we ran grab topic and in here we set a topic variable. Then the blog outline note was executed. And if we scroll down, we can see that both the topic variable and the outline is now populated. I hope you see where this is going. And yes, we're going to look at a very interesting example in a minute. So let's rename this one to blog post. Then for the model, we'll just set llama 3.2. And for the system message, we'll enter generate
[18:23] the blog post based on the user's topic and the blog outline. Respond with the blog post only. And then let's add a user message. And what we need is both the topic which we can get from our state. So let's select topic and we also want the outline which we can get from state as well. Then let's disable conversation history. Then under update flow state let's select the block post variable and for the value we'll set it
[18:54] equal to the output of this current node. All right. Let's also go ahead and create the nodes for the expost and the summary. So for this one, sister message, we'll change it to this. Now this node only needs the blog post in order to do its job. So let's say blog post with a value of flow state dot blog post. And we'll disable memory. And then we also want to update flow state. So we'll set xost is equal to the output of
[19:25] this node. And let's also rename this node to expost. And finally, let's add our summary node. So let's rename this one to summary. And for the system message, let's say write a report containing the following user topic, the complete blog post, the x post. Then under the user's message, let's simply add to this. So we'll say topic and this is equal to the state variable topic.
[19:59] We'll also grab the post and we'll also add xost to this which we can also get from state doxost and this one doesn't have to update state at all. So let's remove that and that should be it. Let's save this. Let's pass in our prompt again. All right. So we get this complete report back which means everything is still working. And looking at the process flow, let's expand the summary node. And scrolling down, we can see that all of the state variables were indeed populated. We've got our topic,
[20:30] the outline, the blog post, as well as the expost. Now, let's have a look at a slightly more advanced example of using state. At high level, this example might seem trivial, but it's going to teach you some really cool tricks when dealing with state. In our start node, let's add three state variables. We'll have the name of a person and I'm actually just going to start it off with my name. Then let's add the person's mood which will be initial and then we'll have something like a random number which is initial as
[21:02] well. Now what we want to do is conditionally call nodes based on this random number. Now let's add a note to generate this random number. I'll show you two different approaches. Because we're working in an LLM application, we could probably just use an LLM node. And maybe we could assign a model. Again, I'll just go with llama 3.2. Then we can just send a user message and say, generate a random decimal number between 0 and 1. Respond with the
[21:38] number only. So for this, I'll disable memory. And then let's update state. So we can select the random number variable and we'll simply pass whatever value this llm came up with. So I'll just rename this node to random number. And if we run this in the chat, we get 0.46. And if we have a look at this node, we can see that the random number variable was indeed updated. I'm sure the more technical people among you are swearing at me at the moment because we don't
[22:09] have to use an LLM to generate a random number. So another way to do this is simply to add a custom function node like so. Let's rename this to random number. And now for the JavaScript function, you can either write JavaScript code yourself or let your GPT do the work for you. Let's say create a JavaScript code that I can use in flowwise to return a random number between zero and one. And chatb saying,
[22:43] "Sure, here's a simple JavaScript code snippet that you can use in Flowwise's code node to return a random number." So, all we have to do is copy this code snippet, add it over here, and that's actually it. So, if you don't know how to code, Chad GPT's got you covered. Now what we want to do of course is store this value in state. So let's select random number and we'll store whatever value was generated by this node. Okay, let's run this. So I'll clear the chat and let's run this again and we get this
[23:14] response back and if we look at this node, we can see that state was updated with this number as well. So of course you're welcome to use the LLN node or the code node if you want. Now we want to take the user down different paths depending on what the number is to branch down different paths we can use a condition node. So under flows we can add condition and let's attach these two nodes. And now let's rename this condition node to the site mood. And now we can check for a specific condition.
[23:46] So what we want to do is check if a number is less than a certain amount and then go down that path. Otherwise we'll simply default to a second path. So if a number and now we have to provide a value which we can get from state dot random number is smaller or equal to 0.5. And let me just select that value again. Then we want to take the user down a certain path. This output at the top will take the user down the positive
[24:17] path. So if the value is less than 0.5, we'll go down this path. Otherwise, we'll go down the second path. Now if the mood is less than 0.5, then we'll set the mood as being sad. If it's greater than 0.5, then the user is happy. So what we want to do is set the mood variable, this one over here, to either happy or sad depending on this random number. Now, of course, what you could do is use an LLM node. So, let's
[24:49] call this one set sad. Then, let's select our model to lama 3.2. And for the message, we can simply say respond with the word sad and nothing else. Don't worry, I'll show you the correct way to do this. But if you had to use an LLM, this is what you'd have to do. So, this LLM will simply respond with the word sad. And what we can do then and of course we first have to connect this path and then going down state we can
[25:21] select mood and mood is equal to the output of this LLM. Now of course this LLM could have generated plenty of other things. All we're doing is storing its response in this field. And yes we could simply hardcode the value sad in here as well but just entertain me for a second. Let's copy this node and let's connect the second path to it. Let's set its value to happy. So this becomes happy. And we'll set the mood variable to whatever this node produces. Cool. Let's
[25:53] save this flow. Then let's test it by running hey. And we're getting the response back as sad. So let's see why that was. If we expand this to side mood node, we can see that the random number at this point in time was 0.04, 04 which is of course less than 0.5. Let's run this again to see if we can get a different output. Now it's happy. So if we expand this flow, let's have a look at the site mood. And this time the random number was 0.9. So state can be
[26:25] very useful when dealing with conditional logic and with things like counters and limits. But of course, I promise you I'll show you an even better way of dealing with this. So, let's delete these LLM nodes to save on some tokens. And again, let's add our custom function. And don't worry, we won't be writing any code this time. We'll simply call this one set sad. We won't write any code either. All we'll do is go to add update flow state. Then for the key, of course, I need to connect these two.
[26:57] Then for the key, let's select mood. And we'll just hardcode this to sad. Then we can copy this node. connect it to this alternative path. Let's rename this to happy. And we'll change the mood to happy. And guess what? This works as well. So let's say hey. And we're getting undefined because this is not returning the value like an LLM node would. We're simply setting the value in state. So if we have a look at what set did, we can see that the mood was indeed
[27:29] set to happy. And if we had to run this again, let's have a look at all right, it called set happy again because the value was 0.5. Let's run this again. And this time the mood was set to sad because the random number was less than 0.5. Now we can tie all of this together by adding an LLM. So we'll connect these two nodes to our LLM node. And let's change this to message. And I'll select my model again. I'll go with trusty llama 3.2. two, let's disable memory.
[28:02] And then for the role, let's say provide a friendly response to the user. Use emojis. If the user is sad, try to cheer them up. If the user is happy, ask them about their day. Let's save this. Then let's add a user message. And in here, let's provide everything this note needs to do its job. It needs the name of the person, which we can get from state.name. and it needs the mood which of course we can get from state dot mood. Let's save
[28:33] this and we don't have to store anything in state. Let's simply run this again and it's saying hey Leon I heard you're feeling a bit down today. All right. So I assume then the mood was set to sad and I can see that set sad was actually called. Let's run this again. And now it's saying hey I see you're feeling happy and we can see that the set happy note was indeed called. So this was a crash course in using state in flowwise and we will be using this functionality to build out some very cool agentic flows. If you like this then please hit
[29:05] the like button, subscribe to my channel and let me know down in the comments if you've got any other questions related to state. I'll see you in the next one. Bye-bye.