fix(agentflow): $flow.state inaccessible inside iteration node execution#6142
Open
manojnaidu619 wants to merge 1 commit intoFlowiseAI:mainfrom
Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the buildAgentflow utility to synchronize the agentflowRuntime state during execution. A review comment identifies a potential issue where state overrides might be lost when an iteration context is present, suggesting that flowConfig.state should be used for merging instead of the local updatedState variable to ensure configuration persistence.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where
$flow.statevariables are inaccessible (returnundefined) inside nodes running within an Iteration block in Agentflow.Problem
Inside an Iteration block, any node that accesses
$flow.state.<variable>(e.g. Custom Function using$flow.state.foo) getsundefinedExpected behavior:
$flow.state.<variable>returns the correct value inside nodes within an iteration block.Actual behavior:
$flow.state.<variable>returnsundefinedbecause the node's runtime state is an empty object{}.This affects all node types inside iteration blocks (Custom Function, Agent, LLM, Condition, HTTP, etc.) — not just custom functions.
Root Cause
When an iteration sub-flow is executed recursively, the sub-flow's
agentflowRuntimeis initialized with an empty state{}. InsideexecuteNode, the parent's state fromiterationContext.agentflowRuntime.stateis correctly merged intoflowConfig.state(used for template resolution like{{ $flow.state.foo }}), but never synced back toagentflowRuntime.state.Since every node's
run()method reads state fromoptions.agentflowRuntime.state, they all receive the empty object instead of the merged state.flowConfig.stateresolveVariables(template{{ }}syntax)agentflowRuntime.state{})node.run()viaoptions.agentflowRuntime.stateSolution
Synced the merged state back to
agentflowRuntime.stateafter the existing iteration context merge inexecuteNode, so that bothflowConfigandagentflowRuntimecarry the same resolved state.How I verified
foowith no value set.$flow.state.foo— before fix it wasundefined, after fix it reads the correct value.Demo
Before
Before-fix.mp4
After
After-fix.mov