Skip to content

Commit 0d407fc

Browse files
committed
fix duplicate tool execution
1 parent ff8a39c commit 0d407fc

1 file changed

Lines changed: 0 additions & 36 deletions

File tree

  • src/praisonai-agents/praisonaiagents/agent

src/praisonai-agents/praisonaiagents/agent/agent.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,43 +1012,7 @@ def chat(self, prompt, temperature=0.2, tools=None, output_json=None, output_pyd
10121012
if not response:
10131013
return None
10141014

1015-
tool_calls = getattr(response.choices[0].message, 'tool_calls', None)
10161015
response_text = response.choices[0].message.content.strip()
1017-
if tool_calls: ## TODO: Most likely this tool call is already called in _chat_completion, so maybe we can remove this.
1018-
messages.append({
1019-
"role": "assistant",
1020-
"content": response_text,
1021-
"tool_calls": tool_calls
1022-
})
1023-
1024-
for tool_call in tool_calls:
1025-
function_name = tool_call.function.name
1026-
arguments = json.loads(tool_call.function.arguments)
1027-
1028-
if self.verbose:
1029-
display_tool_call(f"Agent {self.name} is calling function '{function_name}' with arguments: {arguments}", console=self.console)
1030-
1031-
tool_result = self.execute_tool(function_name, arguments)
1032-
1033-
if tool_result:
1034-
if self.verbose:
1035-
display_tool_call(f"Function '{function_name}' returned: {tool_result}", console=self.console)
1036-
messages.append({
1037-
"role": "tool",
1038-
"tool_call_id": tool_call.id,
1039-
"content": json.dumps(tool_result)
1040-
})
1041-
else:
1042-
messages.append({
1043-
"role": "tool",
1044-
"tool_call_id": tool_call.id,
1045-
"content": "Function returned an empty output"
1046-
})
1047-
1048-
response = self._chat_completion(messages, temperature=temperature, stream=stream)
1049-
if not response:
1050-
return None
1051-
response_text = response.choices[0].message.content.strip()
10521016

10531017
# Handle output_json or output_pydantic if specified
10541018
if output_json or output_pydantic:

0 commit comments

Comments
 (0)