langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
46.37k stars 6.55k forks source link

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

Open pedrotecinf opened 3 weeks ago

pedrotecinf commented 3 weeks ago

Self Checks

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 commented 3 weeks ago

image

dosubot[bot] commented 3 weeks ago

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:

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.