Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add $flow to Variable Resolution in Flow Building Process #3075

Merged

Conversation

raffareis
Copy link
Contributor

Changes Overview

This PR enhances the variable resolution process in the flow building mechanism, particularly focusing on the buildFlow and getVariableValue functions.

Key Updates

  1. Flow Options Enhancement

    • Added a new options object in the buildFlow function:
      const options: ICommonObject = {
          chatflowid,
          chatId,
          sessionId,
          chatHistory
      }
  2. Variable Resolution Improvements

    • Updated resolveVariables and getVariableValue functions to accept and utilize the new options parameter.
  3. Flow-specific Variable Support

    • Implemented handling for variables starting with $flow. in the getVariableValue function:
      if (variableFullPath.startsWith('$flow.') && options) {
          const variableValue = get(options, variableFullPath.replace('$flow.', ''))
          if (variableValue) {
              variableDict[`{{${variableFullPath}}}`] = variableValue
              returnVal = returnVal.split(`{{${variableFullPath}}}`).join(variableValue)
          }
      }

Rationale

These changes allow for more flexible and context-aware variable resolution within the flow building process. By introducing the options object and supporting $flow. prefixed variables, we enable access to flow-specific data like chatflowid, chatId, sessionId, and chatHistory during variable resolution.

Also it can be used to enhance filtering and logic in any flow input:
image

Testing

image
image
image

Notes for Reviewers

  • Pay special attention to the variable resolution logic in getVariableValue.
  • Consider if there are any edge cases in flow-specific variable usage that should be addressed.

@HenryHengZJ
Copy link
Contributor

@raffareis I tried something like this:

image

but somehow the $flow is not getting replaced with value:
image

@raffareis
Copy link
Contributor Author

@HenryHengZJ nice catch. Here we go.
bbf8cee

image
image

@raffareis
Copy link
Contributor Author

Also did a little refactor. Instead of an additional parameter, I merged overrideConfig and options into flowData. Bonus that it will work for agent flows as well because of that.

d3662bc

Copy link
Contributor

@HenryHengZJ HenryHengZJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @raffareis !

@HenryHengZJ HenryHengZJ merged commit 455fb14 into FlowiseAI:main Aug 28, 2024
2 checks passed
@raffareis raffareis deleted the feat/replace-flow-data-as-variables branch August 28, 2024 19:01
patrickreinan pushed a commit to patrickreinan/Flowise that referenced this pull request Sep 3, 2024
…3075)

* Add $flow to Variable Resolution in Flow Building Process

* add overrideConfig values to $flow....

* fix for replacement of $flow values inside text.

* refactor and compatibilize with agent flow
patrickreinan pushed a commit to patrickreinan/Flowise that referenced this pull request Sep 3, 2024
…3075)

* Add $flow to Variable Resolution in Flow Building Process

* add overrideConfig values to $flow....

* fix for replacement of $flow values inside text.

* refactor and compatibilize with agent flow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants