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
52.37k stars 7.64k forks source link

Code block cannot read environment variables when running the code block step only #9905

Open deca-irae opened 3 weeks ago

deca-irae commented 3 weeks ago

Self Checks

Dify version

0.10.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Create an environment variable then set it as the value of an input variable within the code block. Then run the code block step ONLY. image

✔️ Expected Behavior

Code block being able to read the environment variable image

❌ Actual Behavior

Code block cannot read the environment variable image

deca-irae commented 3 weeks ago

Same issue also happens when running tool block step only that uses environment variables as input. Running the entire workflow though works just fine.

dosubot[bot] commented 3 weeks ago

Hey @deca-irae! I'm here to help you with any issues you encounter. Let's tackle this bug together!

The issue you're experiencing with code blocks and tool blocks not being able to read environment variables when running steps individually might be related to how environment variables are loaded and accessed in Dify's self-hosted Docker environment.

In Dify, environment variables are typically configured in a .env file, which is used to set up the environment for the entire workflow. When you run the entire workflow, these variables are likely being loaded correctly. However, when running individual steps, the environment setup might not be fully initialized, leading to the variables not being accessible.

To address this, you might want to ensure that the environment variables are explicitly loaded or passed to the individual steps when executing them separately. This could involve modifying the execution context or script to include the necessary environment setup for standalone step execution.

Unfortunately, there isn't specific documentation on handling environment variables for individual step execution in Dify, so this might require some experimentation or adjustments in your setup. If this is a persistent issue, it might be worth checking for updates or additional documentation from the Dify team that could address this behavior.

To continue talking to Dosu, mention @dosu.