[BUG] - State Variable Set by LLM Node Is Lost in Subsequent Messages
🐞 Bug Report: LLM Node does not persist state after update
Bug Description
The LLM Node correctly updates the flow state with the key isConsultor as configured, but in subsequent user interactions the state is empty, which breaks the routing logic that depends on this value.
Steps to Reproduce
- Create an
LLM Nodewith instructions to classify the user as "SIM", "NÃO", or "INSUFICIENTE" based on the conversation history. - Define the structured output as:
{ "isConsultor": "INSUFICIENTE" } - Update the state using:
- Key:
isConsultor - Value:
{{ output.isConsultor }}
- Key:
- Connect this node to a
Conditional NodeorSwitchthat uses{{ state.isConsultor }}for routing. - Run the flow.
- Observe that the state is updated correctly after the LLM Node, but is empty in the following messages, breaking the routing logic.
Expected Behavior
The value of isConsultor should persist in memory and be available in subsequent steps, allowing the flow to route correctly based on the stored state.
Actual Behavior
The isConsultor state is set correctly but is not retained in session memory, resulting in {{ state.isConsultor }} being empty in the next interaction and routing conditions failing.
Screenshots
- LLM instructions and output confirmed as
"isConsultor": "INSUFICIENTE" - State update set with
{{ output.isConsultor }} - State shows as empty on subsequent steps, causing routing to break
Setup
- Installation: Cloud
- Browser: Chrome
Additional Context
The flow uses an LLM Node to classify user type (consultant or not), and then conditionally routes to different agents. Without persistent state, the routing fails and the conversation logic is broken.
We believe the bug is related to how the state is applied or cached after being updated dynamically via LLM output.
🔄 State Behavior Detail
The LLM Node successfully sets the flow state using the structured output — as shown in the example where the key isConsultor is correctly set to "SIM" based on the user’s input ("sou sim").
However, after this interaction, when the next user message is sent, the state value isConsultor is no longer present in the session. As a result, downstream nodes that rely on {{ state.isConsultor }} receive undefined or an empty value, which breaks conditional logic and routing.
This behavior suggests that the state update via LLM Node does not persist across user interactions, even though it is displayed correctly in the node output.
This issue can be consistently reproduced even when the state is properly configured using:
Key: isConsultor
Value: {{ output.isConsultor }}
Expected behavior: once the state is set, it should persist for the duration of the session until explicitly changed or cleared.
yes, this is a major issue that breaks all routing operations!
Once LLM Node updated the state, the values are available to downstream nodes as well.
Try this template:
1.) An LLM Node update the state.query:
2.) A Retriever Node pick it up, and do the RAG:
@HenryHengZJ yes, the values available in downstream nodes, the state values appear to get wiped after all nodes are executed, making it impossible to access them on the next turn.
state is only runtime, if you want persisted value, use variables
https://docs.flowiseai.com/using-flowise/agentflowv2#understanding-flow-state
https://docs.flowiseai.com/using-flowise/variables
Thanks for the explanation, Henry.
I'm still trying to fully grasp the paradigm shift between V1 and V2, especially regarding how state is handled. In V1, the concept of state felt more persistent and suitable for modeling sequential agents with memory—where each step in the flow could share and update a common context.
From your explanation, it seems like V2 is leaning more toward a stateless architecture, which makes it harder (or at least very different) to implement flows with multiple agents interacting sequentially and sharing a consistent history or memory.
Could you clarify how to best model this kind of sequential agent behavior in V2? Is there a recommended approach to simulate memory—such as manually passing context between agents through inputs/outputs? Or are there any upcoming features planned to address this use case?
Thanks again, and congrats on the great work with Flowise!
@HenryHengZJ , Is it possible to update the variables in the flow, like we update the state. ?
@HenryHengZJ , Also, Is it possible to make this state available for a session and not for a single question ?
Hi everyone,
I'm also encountering this issue where the state isn't preserved across sessions in Flowise, which complicates maintaining user context in multi-turn conversations.
To address this, I'm considering implementing a mechanism to save and restore the flow state per session using Flowise's native database. This approach would involve :
- Saving the $flow.state at the end of each session, associating it with a unique sessionId.
- Restoring the $flow.state at the beginning of a session by retrieving it using the sessionId.
This method would allow for persistent context across sessions without relying on external storage solutions.
Has anyone implemented a similar solution or is there an existing feature in Flowise that facilitates this kind of state persistence? I'd appreciate any insights or suggestions on this matter.
Thanks for your work !
@eberfelipe are you able to export the agentflowv1 so I can try replicate it? We wanted to match the experience similar to V1
Hi @HenryHengZJ!
Sure, I’ll export two flows to help illustrate the behavior difference:
- A simple sequential flow from AgentFlow V1
- My understanding of how the same flow would be built in AgentFlow V2
The idea is that by importing both, you’ll be able to clearly see how the experience differs between versions.
In the V1 flow, once the fallback agent asks “Are you a customer?” and receives a response, the state is immediately updated, and the next question is sent automatically by the correct conditional agent. This sequential logic works smoothly in V1.
However, in V2, this doesn’t happen the same way — after receiving the response, the state doesn’t update in time or propagate as expected, so the follow-up conditional node doesn't trigger as intended.
I’ll share both exports here so you can replicate and observe the behavior side by side.
[Example V1 Agents.json] (https://github.com/user-attachments/files/20444743/Example.V1.Agents.json)
[Example Agents V2 - State Problem.json] (https://github.com/user-attachments/files/20444746/Example.Agents.V2.-.State.Problem.json)
@eberfelipe the V2 flow makes little sense since you are updating the flow state after the condition node and this never going to work as you want to, you need a decision-maker agent before the condition node.
Working Flow
It can be done like this: LLM + Condition Node or using the Condition Agent Node (via scenarios). In this example, the decision-maker agent (what you called lmm_falback) will keep routing to the agent_isClient as soon as the client says they are a client, and this becomes part of the chat history.
Flow: fixed-flow Agents.json
Thanks for sharing @toi500 — your workaround works well for simple flows! However, I believe it introduces a limitation in more complex scenarios.
The issue with that approach is that the LLMNode must rewrite the state on every request. While it’s functional for linear flows (like asking "Are you a customer?"), it becomes unscalable for composite logic flows.
For example, in a second stage of the flow, we may no longer need to ask whether the user is a customer — we now want to know whether the customer has an order. In the current V2 architecture, this forces each conditional node to be paired with a dedicated LLM that re-evaluates the context and updates the state accordingly.
This means that:
- Each logic branch requires a dedicated LLMNode.
- The state has to be constantly rewritten using context.
- The flow becomes harder to manage and maintain as complexity grows.
In contrast, the V1 architecture behaves differently:
- Once the fallback agent gets a response ("Are you a customer?"), the state is persisted and reused across subsequent nodes.
- The Conditional Node acts as a router, and the state is evaluated directly, without invoking an LLM again.
- This supports sequential agent chains where state is preserved across multiple sessions — enabling a more modular and scalable design.
This behavior is critical for sequential agent models, especially when the context is managed externally (e.g., passed in via API).
In these cases, the decision logic often relies on overriding or appending to the state via the API input JSON. For example:
- The first request might set
{ "is_customer": true }. - The second request needs to come with all previous states merged, e.g.:
{ "is_customer": true, "has_order": false }.
Because AgentFlow V2 does not persist state across sessions, this design requires the client to manage memory, which becomes impractical and error-prone in complex use cases.
In V1, once a state is overridden, it remains in memory until another request explicitly changes it. This means it can act like a composite key, progressively accumulating logical decisions (e.g. is_customer, has_order, order_type, etc.) as the user progresses through the flow — enabling dynamic branching with very clean logic.
This persistent-state capability is essential when building agent flows where:
- Context comes from outside Flowise (via API).
- You need conditional branching without invoking a new LLM at every step.
- You want to reuse context through multiple stages without duplicating logic or input data.
Without that persistence layer, it’s virtually impossible to scale complex sequential agent architectures using AgentFlow V2, since every request needs to carry the entire state snapshot manually — defeating the purpose of modular logic.
First of all, let me tell you I am not against the developer @HenryHengZJ adding a new feature to make the flow state permanent (quite the opposite, it would be a good option to have), and that I totally understand your good points. But what I showed you is not just a workaround, it's fundamentally how AgentFlow V2 flow state is designed to operate. I just used the flow you provided.
V2 is not a graph where every step is automatically checkpointed at any given time, it is all about chat history management. So in short, V2 prioritizes chat history and explicit inputs for each interaction, rather than automatically checkpointing state between runs, so what you lose in automation you gain in flexibility.
EDIT: In this flow, you keep using V1 logic in the V2 architecture. You don't even need flow state to make this in V2.
Thanks again for the respectful and insightful discussion.
I’d like to raise a broader point that I believe is crucial when considering the design direction of AgentFlow — especially in light of the potential deprecation of V1.
In my view, AgentFlow V2 introduced a significant philosophical shift by prioritizing flexibility, fluidity, and a chat-history-driven model. This works well for certain use cases, especially dynamic, open-ended interactions. However, with all due respect, I feel that this shift has — in some ways — lowered the ceiling for developers who need precision and control, especially when building robust systems for production environments.
V1 allowed us to create sequential agents with persistent state, offering fine-grained control over logic flows and acting as a system of checks and balances. This empowered more advanced developers to:
- Build complex decision funnels;
- Integrate BI metrics, business variables, and external data;
- Implement conditional logic for cross-sell, up-sell, cart behavior, etc.;
- Manage state across steps without redundant context rewriting.
That model gave developers control over the flow, not just a fluid chat interface. And in production systems, control is often more valuable than flexibility.
V2’s reliance on ephemeral state and chat history makes it very difficult — or even impossible — to model such logic cleanly, especially in API-driven systems with multiple agents and deterministic flows. The lack of a persistent state layer shifts too much responsibility to the LLM and removes the composability that made V1 so powerful.
Initially, I reported this as a bug because I didn’t realize there had been a paradigm shift from V1 to V2. I now understand the purpose of the new approach — and I’m truly grateful for the opportunity to learn so much from the shared insights and experiences here.
That said, I remain genuinely concerned about V1 being deprecated. What it offered wasn’t just a legacy implementation — it was a fundamentally different architecture that many real-world applications depend on to function reliably.
I say all of this with deep respect for the incredible work that’s gone into V2. But I believe these architectural differences deserve further consideration, because for many of us, this transition doesn’t feel like progress — it feels like a step sideways, or even backwards.
Perhaps there’s room for a hybrid or parallel model — where sequential logic with persistent state remains a first-class feature, alongside V2’s more flexible, conversational flows.
Once again, thank you for fostering such an open and thoughtful space for this kind of discussion.
I 100% agree with you in that one. Just note that I just talked under the premise that this is labeled as a bug, so I just wanted to clarify how the flow state currently works, but I 100% acknowledge that there is room for a better, coexisting, persistent state management.
I know for a fact that the developer wanted to mimic V1 as much as possible to allow developers to have a peaceful transition :), so, pretty sure they would take note of this.
Totally understand the importance of this!
We will add a toggle button at the Start node that allow users to specify if they want the state to persists across same session/chat ID.