dify icon indicating copy to clipboard operation
dify copied to clipboard

User Response Node Not Executed Before Tool Node and Issue with Select Input Variables

Open pedrotecinf opened this issue 1 year ago • 2 comments

Self Checks

  • [X] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [X] I have searched for existing issues search for existing issues, including closed ones.
  • [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [X] Please do not modify this template :) and fill in all the required fields.

Dify version

0.7.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I am experiencing two issues in Dify:

1.User Response Node Skipped: After a tool call node is executed, the preceding user response node is skipped and does not execute the expected response. This behavior disrupts the workflow and prevents the user from receiving the response before the tool is executed.

2.Select Input Field Issue: When using select input variables in the tool node, after saving the settings, the select field becomes empty as if no option was selected. This prevents proper configuration of the flow and may lead to execution errors.

Steps to Reproduce: Issue 1:

Set up a flow in Dify with a user response node followed by a tool call node. Run the flow until the point where the user response node should be triggered. Notice that the user response node is skipped, and the tool is executed directly. Issue 2:

Set up a tool node with a select input variable. Choose an option in the select field and save the settings. Reopen the tool node and notice that the select field is empty, as if no option was selected.

✔️ Expected Behavior

Issue 1: The user response node should be triggered and send the response before the tool node is executed.

Issue 2: The selected options in the select field should be retained after saving the settings, allowing for correct flow configuration and execution.

❌ Actual Behavior

Issue 1: The user response node is skipped, and the flow continues with the tool execution without the expected response. image

Issue 2: The select field becomes empty after saving the settings, as if no option was selected.

pedrotecinf avatar Aug 29 '24 10:08 pedrotecinf

image

pedrotecinf avatar Aug 29 '24 10:08 pedrotecinf

Hello @pedrotecinf! I'm here to help you with any bugs, questions, or contributions you may have while we wait for a human maintainer. Let's get started!

To resolve the issues you're experiencing in Dify version 0.7.2, follow these steps:

Issue 1: User Response Node Skipped

Ensure that the input variables are correctly set and maintained throughout the workflow. The provided code snippet from use-config.ts shows how the input variables and tool configurations are managed:

  1. Setting Input Variables:

    const setInputVar = useCallback((value: ToolVarInputs) => {
      setInputs({
        ...inputs,
        tool_parameters: value,
      })
    }, [inputs, setInputs])
    
  2. Handling Tool Configurations:

    const setToolSettingValue = useCallback((value: Record<string, any>) => {
      setNotSetDefaultValue(true)
      setInputs({
        ...inputs,
        tool_configurations: value,
      })
    }, [inputs, setInputs])
    
  3. Ensuring Default Values:

    useEffect(() => {
      if (!currTool)
        return
      const inputsWithDefaultValue = produce(inputs, (draft) => {
        if (!draft.tool_configurations || Object.keys(draft.tool_configurations).length === 0)
          draft.tool_configurations = addDefaultValue(tool_configurations, toolSettingSchema)
    
        if (!draft.tool_parameters)
          draft.tool_parameters = {}
      })
      setInputs(inputsWithDefaultValue)
    // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [currTool])
    
  4. Running the Tool Node:

    const handleRun = (submitData: Record<string, any>) => {
      const varTypeInputKeys = Object.keys(inputs.tool_parameters)
        .filter(key => inputs.tool_parameters[key].type === VarType.variable)
      const shouldAdd = varTypeInputKeys.length > 0
      if (!shouldAdd) {
        doHandleRun(submitData)
        return
      }
      const addMissedVarData = { ...submitData }
      Object.keys(submitData).forEach((key) => {
        const value = submitData[key]
        varTypeInputKeys.forEach((inputKey) => {
          const inputValue = inputs.tool_parameters[inputKey].value as ValueSelector
          if (`#${inputValue.join('.')}#` === key)
            addMissedVarData[inputKey] = value
        })
      })
      doHandleRun(addMissedVarData)
    }
    

Ensure that:

  • The setInputVar function is correctly called with the appropriate values.
  • The setToolSettingValue function is used to maintain the tool configurations.
  • The useEffect hook correctly sets default values for tool configurations and parameters.
  • The handleRun function correctly maps and adds missing variable data before executing the tool node.

Issue 2: Select Input Field Issue

The issue with the select input field becoming empty after saving settings can be related to how the input variables are handled. Ensure that the input variables are correctly set and maintained as described above. If the issue persists, further debugging may be required to trace the exact point where the input variables are lost or not set correctly.

By following these steps, you should be able to resolve the issues with the user response node being skipped and the select input variables becoming empty after saving settings [1].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Aug 29 '24 10:08 dosubot[bot]