langflow icon indicating copy to clipboard operation
langflow copied to clipboard

An error occurs when calling flowasTool using ToolCallAagent

Open alex-ge123 opened this issue 1 year ago • 3 comments

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

alex-ge123 avatar Sep 20 '24 07:09 alex-ge123

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.

dosubot[bot] avatar Sep 20 '24 07:09 dosubot[bot]

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

alex-ge123 avatar Sep 20 '24 07:09 alex-ge123

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!

Cristhianzl avatar Sep 30 '24 16:09 Cristhianzl

@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.

carlosrcoelho avatar Oct 10 '24 12:10 carlosrcoelho