Skip to content

Commit

Permalink
Update tool_usage.py
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomdmoura authored Jul 3, 2024
1 parent f24753f commit 5d78958
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/crewai/tools/tool_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,16 @@ def use(
self.task.increment_tools_errors()
self._printer.print(content=f"\n\n{error}\n", color="red")
return error
# type: ignore # BUG?: "_use" of "ToolUsage" does not return a value (it only ever returns None)
return f"{self._use(tool_string=tool_string, tool=tool, calling=calling)}"
return f"{self._use(tool_string=tool_string, tool=tool, calling=calling)}" # type: ignore # BUG?: "_use" of "ToolUsage" does not return a value (it only ever returns None)

def _use(
self,
tool_string: str,
tool: BaseTool,
calling: Union[ToolCalling, InstructorToolCalling],
) -> str: # TODO: Fix this return type
tool_event = agentops.ToolEvent(name=calling.tool_name) if agentops else None
# type: ignore # _check_tool_repeated_usage of "ToolUsage" does not return a value (it only ever returns None)
if self._check_tool_repeated_usage(calling=calling):
tool_event = agentops.ToolEvent(name=calling.tool_name) if agentops else None
if self._check_tool_repeated_usage(calling=calling): # type: ignore # _check_tool_repeated_usage of "ToolUsage" does not return a value (it only ever returns None)
try:
result = self._i18n.errors("task_repeated_usage").format(
tool_names=self.tools_names
Expand All @@ -119,15 +117,13 @@ def _use(
tool_name=tool.name,
attempts=self._run_attempts,
)
# type: ignore # "_format_result" of "ToolUsage" does not return a value (it only ever returns None)
result = self._format_result(result=result)
result = self._format_result(result=result) # type: ignore # "_format_result" of "ToolUsage" does not return a value (it only ever returns None)
return result # type: ignore # Fix the reutrn type of this function

except Exception:
self.task.increment_tools_errors()

# type: ignore # Incompatible types in assignment (expression has type "None", variable has type "str")
result = None
result = None # type: ignore # Incompatible types in assignment (expression has type "None", variable has type "str")

if self.tools_handler.cache:
result = self.tools_handler.cache.read( # type: ignore # Incompatible types in assignment (expression has type "str | None", variable has type "str")
Expand All @@ -144,8 +140,7 @@ def _use(

if calling.arguments:
try:
# type: ignore # Item "None" of "type[BaseModel] | None" has no attribute "schema"
acceptable_args = tool.args_schema.schema()["properties"].keys()
acceptable_args = tool.args_schema.schema()["properties"].keys() # type: ignore # Item "None" of "type[BaseModel] | None" has no attribute "schema"
arguments = {
k: v
for k, v in calling.arguments.items()
Expand All @@ -157,8 +152,7 @@ def _use(
arguments = calling.arguments
result = tool._run(**arguments)
else:
# type: ignore # Incompatible types in assignment (expression has type "dict_values[str, Any]", variable has type "dict[str, Any]")
arguments = calling.arguments.values()
arguments = calling.arguments.values() # type: ignore # Incompatible types in assignment (expression has type "dict_values[str, Any]", variable has type "dict[str, Any]")
result = tool._run(*arguments)
else:
result = tool._run()
Expand Down Expand Up @@ -207,16 +201,14 @@ def _use(
llm=self.function_calling_llm,
tool_name=tool.name,
attempts=self._run_attempts,
)
# type: ignore # "_format_result" of "ToolUsage" does not return a value (it only ever returns None)
result = self._format_result(result=result)
)
result = self._format_result(result=result) # type: ignore # "_format_result" of "ToolUsage" does not return a value (it only ever returns None)
return result # type: ignore # No return value expected

def _format_result(self, result: Any) -> None:
self.task.used_tools += 1
if self._should_remember_format(): # type: ignore # "_should_remember_format" of "ToolUsage" does not return a value (it only ever returns None)
# type: ignore # "_remember_format" of "ToolUsage" does not return a value (it only ever returns None)
result = self._remember_format(result=result)
result = self._remember_format(result=result) # type: ignore # "_remember_format" of "ToolUsage" does not return a value (it only ever returns None)
return result

def _should_remember_format(self) -> None:
Expand Down

0 comments on commit 5d78958

Please sign in to comment.