workflow as a tool raise error variable not found #4137

Closed
opened 2026-02-21 18:04:54 -05:00 by yindo · 1 comment
Owner

Originally created by @yuhp-zts on GitHub (Jun 17, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.10

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

When I publish the successfully running workflow as a tool, it reports an error 'variable not found'.

微信图片_20240617172557

✔️ Expected Behavior

How can I resolve this issue?

Actual Behavior

No response

Originally created by @yuhp-zts on GitHub (Jun 17, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.10 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce When I publish the successfully running workflow as a tool, it reports an error 'variable not found'. ![微信图片_20240617172557](https://github.com/langgenius/dify/assets/150892078/a249331b-01c7-4fdd-9964-f04cd452911a) ### ✔️ Expected Behavior How can I resolve this issue? ### ❌ Actual Behavior _No response_
yindo added the 🌊 feat:workflow label 2026-02-21 18:04:54 -05:00
yindo closed this issue 2026-02-21 18:04:54 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 17, 2024):

Hello @yuhp-zts! I'm here to help you with any bugs, questions, or contributions you have for the repository. Let's get this issue sorted out together!

To resolve the 'variable not found' error when publishing a successfully running workflow as a tool in Dify version 0.6.10, self-hosted on Docker, ensure that all required variables are correctly set and passed. Here are the key steps:

  1. Check Tool Parameters and Configurations:
    Ensure that tool_parameters and tool_configurations are correctly set and include all necessary variables. The WorkflowToolProviderController class in workflow_tool_provider.py handles the initialization and fetching of these parameters.

  2. Fetch Workflow Variables:
    Use the fetch_workflow_variable function to retrieve variables from the workflow graph. This function ensures that the variables are correctly fetched based on their names.

  3. Handle Variable Types:
    Ensure that variable types are correctly handled, especially for boolean, number-input, and select types. The WorkflowToolProviderController class maps these types to the appropriate ToolParameterType.

  4. Set Default Values:
    Ensure that default values are set for tool configurations if they are not already provided. This is managed within the WorkflowToolProviderController class.

  5. Update Node Variables:
    Use the updateNodeVars function to ensure that variables are correctly updated across different nodes. This function handles various node types and ensures that variables are correctly replaced.

Here is a relevant code snippet that shows how to fetch and handle workflow variables:

def fetch_workflow_variable(variable_name: str) -> VariableEntity:
    return next(filter(lambda x: x.variable == variable_name, variables), None)

workflow_tool_parameters = []
for parameter in parameters:
    variable = fetch_workflow_variable(parameter.name)
    if variable:
        parameter_type = None
        options = None
        if variable.type in [
            VariableEntity.Type.TEXT_INPUT, 
            VariableEntity.Type.PARAGRAPH, 
        ]:
            parameter_type = ToolParameter.ToolParameterType.STRING
        elif variable.type in [
            VariableEntity.Type.SELECT
        ]:
            parameter_type = ToolParameter.ToolParameterType.SELECT
        elif variable.type in [
            VariableEntity.Type.NUMBER
        ]:
            parameter_type = ToolParameter.ToolParameterType.NUMBER
        else:
            raise ValueError(f'unsupported variable type {variable.type}')
        
        if variable.type == VariableEntity.Type.SELECT and variable.options:
            options = [
                ToolParameterOption(
                    value=option,
                    label=I18nObject(
                        en_US=option,
                        zh_Hans=option
                    )
                ) for option in variable.options
            ]
        workflow_tool_parameters.append(
            ToolParameter(
                name=parameter.name,
                label=I18nObject(
                    en_US=variable.label,
                    zh_Hans=variable.label
                ),
                human_description=I18nObject(
                    en_US=parameter.description,
                    zh_Hans=parameter.description
                ),
                type=parameter_type,
                form=parameter.form,
                llm_description=parameter.description,
                required=variable.required,
                options=options,
                default=variable.default
            )
        )
    else:
        raise ValueError('variable not found')

Ensure that the tool_parameters and tool_configurations are correctly set and that all necessary variables are included and correctly typed. This should help resolve the 'variable not found' error when publishing the workflow as a tool [1][2][3].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jun 17, 2024): <!-- Greeting --> Hello @yuhp-zts! I'm here to help you with any bugs, questions, or contributions you have for the repository. Let's get this issue sorted out together! <!-- Answer --> To resolve the 'variable not found' error when publishing a successfully running workflow as a tool in Dify version 0.6.10, self-hosted on Docker, ensure that all required variables are correctly set and passed. Here are the key steps: 1. **Check Tool Parameters and Configurations**: Ensure that `tool_parameters` and `tool_configurations` are correctly set and include all necessary variables. The `WorkflowToolProviderController` class in `workflow_tool_provider.py` handles the initialization and fetching of these parameters. 2. **Fetch Workflow Variables**: Use the `fetch_workflow_variable` function to retrieve variables from the workflow graph. This function ensures that the variables are correctly fetched based on their names. 3. **Handle Variable Types**: Ensure that variable types are correctly handled, especially for `boolean`, `number-input`, and `select` types. The `WorkflowToolProviderController` class maps these types to the appropriate `ToolParameterType`. 4. **Set Default Values**: Ensure that default values are set for tool configurations if they are not already provided. This is managed within the `WorkflowToolProviderController` class. 5. **Update Node Variables**: Use the `updateNodeVars` function to ensure that variables are correctly updated across different nodes. This function handles various node types and ensures that variables are correctly replaced. Here is a relevant code snippet that shows how to fetch and handle workflow variables: ```py def fetch_workflow_variable(variable_name: str) -> VariableEntity: return next(filter(lambda x: x.variable == variable_name, variables), None) workflow_tool_parameters = [] for parameter in parameters: variable = fetch_workflow_variable(parameter.name) if variable: parameter_type = None options = None if variable.type in [ VariableEntity.Type.TEXT_INPUT, VariableEntity.Type.PARAGRAPH, ]: parameter_type = ToolParameter.ToolParameterType.STRING elif variable.type in [ VariableEntity.Type.SELECT ]: parameter_type = ToolParameter.ToolParameterType.SELECT elif variable.type in [ VariableEntity.Type.NUMBER ]: parameter_type = ToolParameter.ToolParameterType.NUMBER else: raise ValueError(f'unsupported variable type {variable.type}') if variable.type == VariableEntity.Type.SELECT and variable.options: options = [ ToolParameterOption( value=option, label=I18nObject( en_US=option, zh_Hans=option ) ) for option in variable.options ] workflow_tool_parameters.append( ToolParameter( name=parameter.name, label=I18nObject( en_US=variable.label, zh_Hans=variable.label ), human_description=I18nObject( en_US=parameter.description, zh_Hans=parameter.description ), type=parameter_type, form=parameter.form, llm_description=parameter.description, required=variable.required, options=options, default=variable.default ) ) else: raise ValueError('variable not found') ``` Ensure that the `tool_parameters` and `tool_configurations` are correctly set and that all necessary variables are included and correctly typed. This should help resolve the 'variable not found' error when publishing the workflow as a tool <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/tools/provider/workflow_tool_provider.py)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/web/app/components/workflow/nodes/tool/use-config.ts)</sup><sup>[[3]](https://github.com/langgenius/dify/blob/main/web/app/components/workflow/nodes/_base/components/variable/utils.ts)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4137