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
53.24k stars 7.77k forks source link

Error in Conditional Workflow When Code Executor Handles Different Knowledge Base Parameters #11137

Closed Angelxiaotao closed 3 days ago

Angelxiaotao commented 3 days ago

Self Checks

Dify version

0.11.0

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

In a conditional workflow setup, the code executor is configured to set the retrieval results of two knowledge bases as two parameters. Since our business logic requires selecting different knowledge bases based on conditions, when the if condition chooses only the A knowledge base (i.e., the code executor uses only the A parameter), the B parameter does not exist. This causes the code executor to throw an error. I have already tried implementing default values in Node.js to handle the missing parameters, but the issue persists with the same error

  1. Create a conditional workflow where the retrieval results of two knowledge bases are assigned as parameters A and B.
  2. Configure an if condition in the workflow to select only the A knowledge base result.
  3. During execution, the code executor attempts to access parameter B.
  4. The code executor throws an error because parameter B does not exist.

✔️ Expected Behavior

When the conditional logic selects only the A knowledge base, the B parameter should not be required. The code executor should execute normally, using only the available parameter.

❌ Actual Behavior

The code executor throws an error when parameter B is not present, causing the entire workflow to fail. image image

dosubot[bot] commented 3 days ago

The issue you're encountering seems to be related to how the code executor in Dify handles missing parameters in a conditional workflow. Currently, it appears that the code executor expects all defined parameters to be present, which leads to errors when a parameter is missing due to conditional logic.

To address this, you might consider implementing a check within your code to verify the existence of parameters before attempting to use them. This can be done by checking if the parameter exists in the VariablePool before accessing it. If the parameter is not present, you can set a default value or skip the logic that requires it.

Unfortunately, there isn't specific documentation or configuration in Dify that allows the code executor to ignore missing parameters automatically. You may need to handle this within your workflow logic or code execution to ensure that missing parameters do not cause errors.

If this is a common requirement, you might want to suggest a feature enhancement to allow optional parameters in workflows, which could help prevent such issues in the future.

To continue talking to Dosu, mention @dosu.

crazywoola commented 3 days ago

This has been fixed in later version.