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
34.37k stars 4.14k forks source link

An error occurs when calling flowasTool using ToolCallAagent #3865

Closed alex-ge123 closed 1 month ago

alex-ge123 commented 1 month ago

Bug Description

微信图片_20240920151735 微信图片_20240920151803

Reproduction

An error occurs when calling flowasTool using ToolCallAagent

Expected behavior

An error occurs when calling flowasTool using ToolCallAagent

Who can help?

No response

Operating System

windows

Langflow Version

1.0.18

Python Version

3.11

Screenshot

No response

Flow File

No response

dosubot[bot] commented 1 month ago

I found a similar issue that might help you resolve the error. The issue titled Asyncio Thread error when running Flow as Tool with a Agent was closed by a pull request that refactored FlowTool to use run_until_complete for async flow execution.

Additionally, ensure that your user_prompt contains the 'input' key. The run_agent method in ToolCallingAgentComponent raises a ValueError if the 'input' key is missing from the user_prompt. Here is the relevant code snippet:

async def run_agent(self) -> Message:
    if "input" not in self.user_prompt:
        raise ValueError("Prompt must contain 'input' key.")
    messages = [
        ("system", self.system_prompt),
        ("placeholder", "{chat_history}"),
        ("human", self.user_prompt),
        ("placeholder", "{agent_scratchpad}"),
    ]
    prompt = ChatPromptTemplate.from_messages(messages)
    agent = create_tool_calling_agent(self.llm, self.tools, prompt)

    runnable = AgentExecutor.from_agent_and_tools(
        agent=cast(BaseSingleActionAgent, agent),
        tools=self.tools,
        verbose=True,
        handle_parsing_errors=self.handle_parsing_errors,
    )
    input_dict: dict[str, str | list[Dict[str, str]]] = {"input": self.input_value}
    if hasattr(self, "memory") and self.memory:
        input_dict["chat_history"] = self.convert_chat_history(self.memory)
    result = await runnable.ainvoke(input_dict)
    self.status = result

    if "output" not in result:
        raise ValueError("Output key not found in result. Tried 'output'.")

    result_string = result["output"]

    return Message(text=result_string)

Make sure your user_prompt string includes the 'input' key, like so:

user_prompt = "Please process the following input: {input}"

This should help resolve the error [1][2].

To continue talking to Dosu, mention @dosu.

alex-ge123 commented 1 month ago

I'm sure I added {input} to the ToolCallAgent component promnt

Cristhianzl commented 1 month ago

hi @alex-ge123,

can you please provide the JSON file with your flows (the main flow you want to run and the others you want to use as a Tool).

this way I can debug here to understand what can be causing the error for you.

thanks!

carlosrcoelho commented 1 month ago

@alex-ge123 Thank you for your contribution! This issue will be closed. If you have any questions or encounter another problem, please open a new issue and we will be ready to help you.