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:
parent
2eb786cdd9
commit
01ff15f5a3
1 changed files with 6 additions and 3 deletions
|
|
@ -90,13 +90,16 @@ class ToolCallingAgentComponent(Component):
|
||||||
if hasattr(self, "memory") and self.memory:
|
if hasattr(self, "memory") and self.memory:
|
||||||
input_dict["chat_history"] = self.convert_chat_history(self.memory)
|
input_dict["chat_history"] = self.convert_chat_history(self.memory)
|
||||||
result = await runnable.ainvoke(input_dict)
|
result = await runnable.ainvoke(input_dict)
|
||||||
self.status = result
|
|
||||||
|
|
||||||
if "output" not in result:
|
if "output" not in result:
|
||||||
raise ValueError("Output key not found in result. Tried 'output'.")
|
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)
|
return Message(text=result_string)
|
||||||
|
|
||||||
def convert_chat_history(self, chat_history: List[Data]) -> List[Dict[str, str]]:
|
def convert_chat_history(self, chat_history: List[Data]) -> List[Dict[str, str]]:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue