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>
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-07-02 18:36:40 -03:00 committed by GitHub
commit 01ff15f5a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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]]: