Skip to content

CustomFunction nodes fail to reliably update $flow.state variables in AgentFlow V2 #5142

@Sofia-Happy-Wibes

Description

@Sofia-Happy-Wibes

Describe the bug

CustomFunction nodes in Flowise AgentFlow V2 are unable to reliably update $flow.state variables. Multiple syntaxes have been tested, but state modifications either don't persist or cause errors.

To Reproduce

Direct assignment to $flow.state variables doesn't persist
The return { state: { ... } } syntax works inconsistently
Boolean values are sometimes converted to strings unexpectedly
No clear documentation on the correct way to update state from CustomFunction

Create an AgentFlow V2 with Start node containing:

javascriptdialogue_finished: false
counter: 0

Add CustomFunction node with code:

javascript// Attempt 1: Direct assignment
$flow.state.dialogue_finished = "true";
$flow.state.counter = parseInt($flow.state.counter) + 1;
return "done";

Add another node that reads $flow.state.dialogue_finished
Run the flow and observe that state changes don't persist

Expected behavior

CustomFunction should be able to:

Read values from $flow.state
Modify values in $flow.state
Have those modifications persist for subsequent nodes

Screenshots

No response

Flow

Code Examples Tested
Attempt 1: Direct Assignment (Doesn't work)
javascript$flow.state.dialogue_finished = "true";
return "continue";
Attempt 2: Return State Object (Inconsistent)
javascriptreturn {
state: {
dialogue_finished: "true"
}
};
Attempt 3: Boolean Values (Type confusion)
javascript$flow.state.dialogue_finished = true; // Gets converted to string sometimes
return "continue";
Attempt 4: Complex Operations (Fails)
javascript$flow.state.counter = parseInt($flow.state.counter || 0) + 1;
// Calculation doesn't work in Update Flow State fields
Current Workaround
Instead of updating state in CustomFunction, we:

Store raw JSON in state from LLM nodes
Use Condition node with "contains" operator to check string content
Avoid CustomFunction for state modifications entirely

Example:
// Instead of parsing JSON and setting boolean
// We check if JSON string contains "end_session": true
Condition: {{$flow.state.dialogue_parser}} contains "end_session": true
Impact

Unable to implement complex flow logic requiring state manipulation
Forces use of inefficient workarounds
Makes flows harder to maintain and debug
Limits the utility of CustomFunction nodes

Suggested Solution

Document the correct way to update $flow.state from CustomFunction
Provide consistent behavior for state updates
Support both string and boolean types consistently
Allow nested object access: $flow.state.object.property

Additional Context
This issue significantly impacts complex flows that need to:

Track conversation state
Increment counters
Parse JSON responses from LLMs
Maintain complex state machines

Related Issues

Nested object access in Update Flow State doesn't work
Calculations in Update Flow State fields fail
Type coercion between string/boolean is inconsistent

Use Method

None

Flowise Version

3.0.5

Operating System

macOS

Browser

Chrome

Additional context

Questions for Maintainers

What is the officially supported way to update $flow.state from CustomFunction?
Is the return { state: { ... } } syntax deprecated?
How should boolean values be handled in state variables?
Is there a plan to support nested object access in flow state?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingin-workIssue in work

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions