mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 23:58:34 +00:00
counting for tool retries on the acutal usage
This commit is contained in:
@@ -60,31 +60,40 @@ class ToolUsage:
|
|||||||
self._printer.print(content=f"\n\n{error}\n", color="yellow")
|
self._printer.print(content=f"\n\n{error}\n", color="yellow")
|
||||||
return error
|
return error
|
||||||
tool = self._select_tool(calling.function_name)
|
tool = self._select_tool(calling.function_name)
|
||||||
return self._use(tool=tool, calling=calling)
|
return self._use(tool_string=tool_string, tool=tool, calling=calling)
|
||||||
|
|
||||||
def _use(self, tool: BaseTool, calling: ToolCalling) -> None:
|
def _use(self, tool_string: str, tool: BaseTool, calling: ToolCalling) -> None:
|
||||||
if self._check_tool_repeated_usage(calling=calling):
|
try:
|
||||||
result = self._i18n.errors("task_repeated_usage").format(
|
if self._check_tool_repeated_usage(calling=calling):
|
||||||
tool=calling.function_name, tool_input=calling.arguments
|
result = self._i18n.errors("task_repeated_usage").format(
|
||||||
)
|
tool=calling.function_name, tool_input=calling.arguments
|
||||||
else:
|
)
|
||||||
self.tools_handler.on_tool_start(calling=calling)
|
else:
|
||||||
|
self.tools_handler.on_tool_start(calling=calling)
|
||||||
|
|
||||||
result = self.tools_handler.cache.read(
|
result = self.tools_handler.cache.read(
|
||||||
tool=calling.function_name, input=calling.arguments
|
tool=calling.function_name, input=calling.arguments
|
||||||
|
)
|
||||||
|
|
||||||
|
if not result:
|
||||||
|
result = tool._run(**calling.arguments)
|
||||||
|
self.tools_handler.on_tool_end(calling=calling, output=result)
|
||||||
|
|
||||||
|
self._printer.print(content=f"\n\n{result}\n", color="yellow")
|
||||||
|
self._telemetry.tool_usage(
|
||||||
|
llm=self.llm, tool_name=tool.name, attempts=self._run_attempts
|
||||||
)
|
)
|
||||||
|
|
||||||
if not result:
|
result = self._format_result(result=result)
|
||||||
result = tool._run(**calling.arguments)
|
return result
|
||||||
self.tools_handler.on_tool_end(calling=calling, output=result)
|
except Exception:
|
||||||
|
self._run_attempts += 1
|
||||||
self._printer.print(content=f"\n\n{result}\n", color="yellow")
|
if self._run_attempts > self._max_parsing_attempts:
|
||||||
self._telemetry.tool_usage(
|
self._telemetry.tool_usage_error(llm=self.llm)
|
||||||
llm=self.llm, tool_name=tool.name, attempts=self._run_attempts
|
return ToolUsageErrorException(
|
||||||
)
|
self._i18n.errors("tool_usage_error")
|
||||||
|
).message
|
||||||
result = self._format_result(result=result)
|
return self.use(tool_string=tool_string)
|
||||||
return result
|
|
||||||
|
|
||||||
def _format_result(self, result: Any) -> None:
|
def _format_result(self, result: Any) -> None:
|
||||||
self.task.used_tools += 1
|
self.task.used_tools += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user