From 01ff15f5a306d431d1fdf3ade143e46a3eac9a76 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 2 Jul 2024 18:36:40 -0300 Subject: [PATCH] fix: improve handling of ToolCallingAgent output in ToolCallingAgentComponent (#2494) * fix: improve handling of ToolCallingAgent output in ToolCallingAgentComponent The code changes in `ToolCallingAgent.py` modify the `ToolCallingAgentComponent` class to improve the handling of the output from the `ToolCallingAgent`. The changes include updating the logic to handle both single results and lists of results, extracting the relevant text from the results, and assigning it to the `result_string` variable. This ensures that the `result_string` contains the appropriate output to be returned as a `Message` object. * fix(ToolCallingAgent.py): fix variable name typo from 'result' to 'results' for correct data processing --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../base/langflow/components/agents/ToolCallingAgent.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/backend/base/langflow/components/agents/ToolCallingAgent.py b/src/backend/base/langflow/components/agents/ToolCallingAgent.py index 407ab333d..7f390e8be 100644 --- a/src/backend/base/langflow/components/agents/ToolCallingAgent.py +++ b/src/backend/base/langflow/components/agents/ToolCallingAgent.py @@ -90,13 +90,16 @@ class ToolCallingAgentComponent(Component): 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"] - + results = result["output"] + if isinstance(results, list): + result_string = "\n".join([r["text"] for r in results if "text" in r and r.get("type") == "text"]) + else: + result_string = results + self.status = result_string return Message(text=result_string) def convert_chat_history(self, chat_history: List[Data]) -> List[Dict[str, str]]: