From c44c2b68085a929abaec403dfbf6bb84e80d0613 Mon Sep 17 00:00:00 2001 From: Braelyn Boynton Date: Fri, 29 Mar 2024 14:28:33 -0700 Subject: [PATCH] track tool usage time --- src/crewai/tools/tool_usage.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/crewai/tools/tool_usage.py b/src/crewai/tools/tool_usage.py index 98f280a5f..28847b9c5 100644 --- a/src/crewai/tools/tool_usage.py +++ b/src/crewai/tools/tool_usage.py @@ -9,7 +9,7 @@ from crewai.agents.tools_handler import ToolsHandler from crewai.telemetry import Telemetry from crewai.tools.tool_calling import InstructorToolCalling, ToolCalling from crewai.utilities import I18N, Converter, ConverterError, Printer -from agentops import ToolEvent, ErrorEvent, record +import agentops OPENAI_BIGGER_MODELS = ["gpt-4"] @@ -80,15 +80,12 @@ class ToolUsage: self.task.increment_tools_errors() return error - event = ToolEvent(name=calling.tool_name) - record(event) try: tool = self._select_tool(calling.tool_name) except Exception as e: error = getattr(e, "message", str(e)) self.task.increment_tools_errors() self._printer.print(content=f"\n\n{error}\n", color="red") - record(ErrorEvent(details=error, trigger_event=event)) return error return f"{self._use(tool_string=tool_string, tool=tool, calling=calling)}" @@ -98,6 +95,7 @@ class ToolUsage: tool: BaseTool, calling: Union[ToolCalling, InstructorToolCalling], ) -> None: + tool_event = agentops.ToolEvent(name=calling.tool_name) if self._check_tool_repeated_usage(calling=calling): try: result = self._i18n.errors("task_repeated_usage").format( @@ -158,11 +156,13 @@ class ToolUsage: self._printer.print(content=f"\n\n{error_message}\n", color="red") return error self.task.increment_tools_errors() + agentops.record(agentops.ErrorEvent(details=error, trigger_event=tool_event)) return self.use(calling=calling, tool_string=tool_string) self.tools_handler.on_tool_use(calling=calling, output=result) self._printer.print(content=f"\n\n{result}\n", color="yellow") + agentops.record(tool_event) self._telemetry.tool_usage( llm=self.function_calling_llm, tool_name=tool.name,