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
29.75k stars 3.77k forks source link

Some questions need to be asked #3159

Closed alex-ge123 closed 1 month ago

alex-ge123 commented 1 month ago

Bug Description

I need to use ToolCallAgent components to make a conference reservation system and a station reservation system, and use different processes to complete the two systems respectively. Then I use ToolCallAgent plus Flow as Tool to complete the call, and use AI to determine which system to use. Then when I gave it to Flow as Tool to call, I encountered several problems and hoped to be answered or solved. 1 How to pass parameters when using Flow as Tool to call other programs.

Reproduction

I need to use ToolCallAgent components to make a conference reservation system and a station reservation system, and use different processes to complete the two systems respectively. Then I use ToolCallAgent plus Flow as Tool to complete the call, and use AI to determine which system to use. Then when I gave it to Flow as Tool to call, I encountered several problems and hoped to be answered or solved. 1 How to pass parameters when using Flow as Tool to call other programs.

Expected behavior

I need to use ToolCallAgent components to make a conference reservation system and a station reservation system, and use different processes to complete the two systems respectively. Then I use ToolCallAgent plus Flow as Tool to complete the call, and use AI to determine which system to use. Then when I gave it to Flow as Tool to call, I encountered several problems and hoped to be answered or solved. 1 How to pass parameters when using Flow as Tool to call other programs.

Who can help?

No response

Operating System

windows

Langflow Version

1.0.14

Python Version

None

Screenshot

No response

Flow File

No response

dosubot[bot] commented 1 month ago

To pass parameters when using FlowTool to call other programs, you can use either positional or keyword arguments. Here is how you can do it:

Using Positional Arguments

Ensure the number of positional arguments matches the number of inputs expected by the tool. The tool will map these arguments to the corresponding input names.

# Assuming the tool expects two inputs: "input1" and "input2"
result = flow_tool_instance._run("value1", "value2")

Using Keyword Arguments

You can pass the parameters as keyword arguments, where the keys are the input names.

# Assuming the tool expects two inputs: "input1" and "input2"
result = flow_tool_instance._run(input1="value1", input2="value2")

Code Explanation

The _run method in FlowTool handles the arguments as follows:

Here is the relevant part of the code:

def _run(
    self,
    *args: Any,
    **kwargs: Any,
) -> str:
    """Use the tool."""
    args_names = get_arg_names(self.inputs)
    if len(args_names) == len(args):
        kwargs = {arg["arg_name"]: arg_value for arg, arg_value in zip(args_names, args)}
    elif len(args_names) != len(args) and len(args) != 0:
        raise ToolException(
            "Number of arguments does not match the number of inputs. Pass keyword arguments instead."
        )
    tweaks = {arg["component_name"]: kwargs[arg["arg_name"]] for arg in args_names}

    run_outputs = syncify(run_flow, raise_sync_error=False)(
        tweaks={key: {"input_value": value} for key, value in tweaks.items()},
        flow_id=self.flow_id,
        user_id=self.user_id,
    )
    if not run_outputs:
        return "No output"
    run_output = run_outputs[0]

    data = []
    if run_output is not None:
        for output in run_output.outputs:
            if output:
                data.extend(build_data_from_result_data(output, get_final_results_only=self.get_final_results_only))
    return format_flow_output_data(data)

This method ensures that the parameters are correctly passed and validated before running the flow [1][2].

To continue talking to Dosu, mention @dosu.

vasconceloscezar commented 1 month ago

From my current understanding, Flow as a Tool only works using the Chat Input and Chat Output components in the flow being called, so you can't use the TWEAKS (unless you make some hacky stuff on your own)

What I can recommend is not ideal, but, a solution is to pass more parameters is to make the Chat Input of your flow be a JSON string (LLMs are good with JSON) so you just parse that string and handle each field accordingly.