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
35.77k stars 4.24k forks source link

[Component Bug] Conditional Router(If-Else in 1.1.0) Cannot Stop Correctly #4590

Open ChunJen opened 1 week ago

ChunJen commented 1 week ago

Bug Description

I change the conditional Router with self.stop('method_name'), but the components of the subsequent process will still be executed. It happened in both of version 1.0.17 and 1.1.0

    def true_response(self) -> Message:
        result = self.evaluate_condition(self.input_text, self.match_text, self.operator, self.case_sensitive)
        if result:
            return self.message
        else:
            self.stop('true_response')

With the workflow:

[python 3.12.3, langflow 1.0.17]

20241114_debug_conditional_router.json 20241114_debug_conditional_router_v2.json

Test Case

1.input=A, expected_output=A, real_output=A None None

image

2.input=B, expected_output=B, real_output=None B None

image

[python 3.12.3, langflow 1.1.0]

Still not work in this version: 20241114_debug_conditional_router_v2_使用langflow1.1.0版本.json

Reproduction

  1. upload the json
  2. try the input with playground

Expected behavior

Just like in Bug Description

Who can help?

No response

Operating System

Windows 11

Langflow Version

1.0.17

Python Version

3.12

Screenshot

No response

Flow File

20241114_debug_conditional_router_v2.json 20241114_debug_conditional_router.json 20241114_debug_conditional_router_v2_使用langflow1.1.0版本.json

dosubot[bot] commented 1 week ago

The issue you're experiencing with the Conditional Router component not stopping correctly when using self.stop('method_name') might be related to how the stop function is implemented and how it interacts with the workflow execution. The stop function is supposed to halt a specific branch of the workflow by marking it as "INACTIVE" in the graph. However, if subsequent components are still being executed, it suggests that the stop command might not be effectively preventing further execution in the workflow.

Here are a few things you might want to check or try:

  1. Ensure Correct Output Name: Make sure that the output_name you are passing to self.stop() matches the actual output name in your workflow. If the name is incorrect, the stop command might not be applied to the intended branch.

  2. Check Workflow Configuration: Verify that the workflow configuration correctly reflects the intended logic and that there are no additional paths or conditions that might lead to the execution of subsequent components.

  3. Debugging: Add logging or print statements before and after the self.stop() call to ensure that the function is being executed and to check the state of the workflow at that point.

  4. Review Changes Between Versions: Since the issue persists across versions 1.0.17 and 1.1.0, review any changes in the implementation of the Conditional Router or related components that might affect the stop functionality.

If these steps do not resolve the issue, it might require a deeper investigation into the codebase to understand how the stop command is processed and why it might not be affecting the workflow as expected.

To continue talking to Dosu, mention @dosu.

irshadmb commented 1 week ago

Following changes will help you. def true_response(self) -> Message: result = self.evaluate_condition(self.input_text, self.match_text, self.operator, self.case_sensitive) if result: return self.message else: self.stop('true_response') return ""

image 20241114_debug_conditional_router_v3.json

ChunJen commented 1 week ago

@irshadmb Hi thanks for respones! It is kinda a way to make it return nothing with "".

However, it is just a simplified flow here, so i still need one solution to make this happend. Because the prompt here, it represented a whole SubFlow.

image

Is it possible in Langflow?

20241114_debug_conditional_router_v4_needsolution.json

edwinjosechittilappilly commented 1 week ago

PR #3904
https://github.com/langflow-ai/langflow/pull/3904

Please review this PR and test the multi-conditional router, see if it fits your scenario.

Let us know if it resolves the issue. If it does, we will consider adding an enhanced version of the multi-conditional router to the components in the upcoming release.

cc. @carlosrcoelho @jordanrfrazier ref: Multiconditional router