langflow-ai / langflow

Langflow is a low-code app builder for RAG and multi-agent AI applications. It’s Python-based and agnostic to any model, API, or database.
http://www.langflow.org
MIT License
26.95k stars 3.57k forks source link

Flows are not visible in any of "Prototype" Components #2752

Closed burakcbdn closed 1 month ago

burakcbdn commented 1 month ago

Bug Description

I am trying to run one of my flows as a tool in my other flow, but when I try to import component, the options of component is empty, I tried all of them (Run Flow, Flow as Tool, Sub Flow.. etc) but in all of them, options to select flow name is empty.

Screenshot 2024-07-17 at 15 36 13 Screenshot 2024-07-17 at 15 36 07

Reproduction

  1. Create a basic flow and save
  2. Create a new flow
  3. Add any prototype component to import other flow
  4. Click on options
  5. Options are empty

Expected behavior

  1. Create a basic flow and save
  2. Create a new flow
  3. Add any prototype component to import other flow
  4. Click on options
  5. Options should show the flow created before

Who can help?

@anovazzi1 @italojohnny @ogabrielluiz

Operating System

Macos Sonoma 14.5

Langflow Version

1.0.9

Python Version

dosubot[bot] commented 1 month ago

Hey @burakcbdn! 👋 I'm here to help you with your issue. I'm a bot that can assist you with bugs, questions, and becoming a contributor while you wait for a human to assist you.

The issue you're experiencing with empty options for selecting a flow name in the "Prototype" components is likely due to the get_flow_names method not being populated correctly. This method relies on the list_flows method to retrieve available flows. If list_flows does not return any flow data, the options will remain empty.

Here's a brief overview of the relevant methods:

  1. get_flow_names Method:

    def get_flow_names(self) -> List[str]:
        flow_datas = self.list_flows()
        return [flow_data.data["name"] for flow_data in flow_datas]
  2. list_flows Method:

    def list_flows(*, user_id: Optional[str] = None) -> List[Data]:
        if not user_id:
            raise ValueError("Session is invalid")
        try:
            with session_scope() as session:
                flows = session.exec(
                    select(Flow).where(Flow.user_id == user_id).where(Flow.is_component == False)  # noqa
                ).all()
    
                flows_data = [flow.to_data() for flow in flows]
                return flows_data
        except Exception as e:
            raise ValueError(f"Error listing flows: {e}")
  3. update_build_config Method:

    def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None):
        logger.debug(f"Updating build config with field value {field_value} and field name {field_name}")
        if field_name == "flow_name":
            build_config["flow_name"]["options"] = self.get_flow_names()
        # Clean up the build config
        for key in list(build_config.keys()):
            if key not in self.field_order + ["code", "_type", "get_final_results_only"]:
                del build_config[key]
        if field_value is not None and field_name == "flow_name":
            try:
                flow_data = self.get_flow(field_value)
                if not flow_data:
                    raise ValueError(f"Flow {field_value} not found.")
                graph = Graph.from_payload(flow_data.data["data"])
                # Get all inputs from the graph
                inputs = get_flow_inputs(graph)
                # Add inputs to the build config
                build_config = self.add_inputs_to_build_config(inputs, build_config)
            except Exception as e:
                logger.error(f"Error getting flow {field_value}: {str(e)}")
    
        return build_config

To resolve this issue, ensure that:

If list_flows is not returning any data, the flow_name options will be empty. Ensure that the flows are correctly defined and accessible in your environment [1][2][3][4].

To continue talking to Dosu, mention @dosu.

burakcbdn commented 1 month ago

Thank you @dosu I checked with editing the component code, and it prints the flows that I created, and stores them in a list, but they are not visible at the ui. it could be because "update_build_config" method is not being called.

dosubot[bot] commented 1 month ago

The issue seems to be that the update_build_config method is not being called, which is necessary to populate the flow names in the UI. To resolve this, you need to ensure that update_build_config is invoked at the appropriate time in your component lifecycle.

Here is the relevant code snippet for the update_build_config method:

def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None):
    if field_name == "flow_name":
        build_config["flow_name"]["options"] = self.get_flow_names()

    return build_config

To ensure that update_build_config is called, you might need to check where and how the build configuration is being initialized and updated in your component lifecycle. If this method is not being called, the flow names will not be populated in the UI.

You should verify that the update_build_config method is invoked when the component is initialized or when the flow names need to be refreshed. This might involve checking the component's initialization code or any event handlers that should trigger the update.

If the method is not being called, you can manually call it after the component is initialized or when the flow names need to be updated:

# Example of manually calling update_build_config
build_config = self.build_config()
self.update_build_config(build_config, None, "flow_name")

Ensure that this call is placed at the appropriate location in your component's lifecycle to update the build configuration with the available flow names.

Additionally, you should ensure that the build_config method is properly defined to include the flow_name field with the necessary options and refresh capabilities:

def build_config(self):
    return {
        "input_value": {
            "display_name": "Input Value",
            "multiline": True,
        },
        "flow_name": {
            "display_name": "Flow Name",
            "info": "The name of the flow to run.",
            "options": [],
            "real_time_refresh": True,
            "refresh_button": True,
        },
        "tweaks": {
            "display_name": "Tweaks",
            "info": "Tweaks to apply to the flow.",
        },
        "get_final_results_only": {
            "display_name": "Get Final Results Only",
            "info": "If False, the output will contain all outputs from the flow.",
            "advanced": True,
        },
    }
}

By ensuring that update_build_config is called appropriately and that the build_config method is correctly defined, the flow names should be populated in the UI as expected. Additionally, the real_time_refresh and refresh_button properties in the build_config method will help ensure that the flow names are updated dynamically [1][2][3][4].

To continue talking to Dosu, mention @dosu.

burakcbdn commented 1 month ago

@dosu Thanks you for update, upon checking I thinks the issue seems to be UI related. It would be great if anyone from team support this. Because for the options of flow name I hardcoded some values like "A", "B", "C" in array, but still they are not visible in the ui.

dosubot[bot] commented 1 month ago

@ogabrielluiz, this one's a bit out of my wheelhouse, could you step in and provide your guidance?

To continue talking to Dosu, mention @dosu.

h-arnold commented 1 month ago

I can confirm I'm experiencing the same bug. I'm getting it on the v.1.0.9 official docker image with frontend and backend included.

Cristhianzl commented 1 month ago

hi @burakcbdn @h-arnold,

Some components inside the Experimental tab aren't updated with the new schemas. Some of them (as in your case) are on standby to receive a new update on the code. We will soon update these faulty components, but unfortunately, for now, I would advise you to be patient.

As a 'workaround', I suggest grouping components of a flow so they look like a single component on the canvas.

burakcbdn commented 1 month ago

Thanks for the answers, but as it is not working on my local development environment, it is working when I use it on datastax deployment.I just wondered, what's the reason behind this?

Cristhianzl commented 1 month ago

@burakcbdn did you checked if datastax environment version is the same as your develop local version?

lucaseduoli commented 1 month ago

Hello!

Flow as Tool and Subflow components are still broken on main. I'm fixing it in issue #2972, so, if you want, you can follow my progress through that issue.

If there is an issue after #2972 is resolved, feel free to open this issue again.