feat: remove unused code and change ToolUsageStarted event place

This commit is contained in:
Eduardo Chiarotti
2025-04-10 15:14:43 -03:00
parent c9f47e6a37
commit 4b9be2fc26
4 changed files with 23 additions and 82 deletions

View File

@@ -2,7 +2,7 @@ import ast
import datetime
import json
import time
from dataclasses import dataclass
from difflib import SequenceMatcher
from json import JSONDecodeError
from textwrap import dedent
@@ -23,6 +23,7 @@ from crewai.utilities.agent_utils import (
)
from crewai.utilities.events.crewai_event_bus import crewai_event_bus
from crewai.utilities.events.tool_usage_events import (
ToolUsageStartedEvent,
ToolSelectionErrorEvent,
ToolUsageErrorEvent,
ToolUsageFinishedEvent,
@@ -148,7 +149,7 @@ class ToolUsage:
tool_string: str,
tool: CrewStructuredTool,
calling: Union[ToolCalling, InstructorToolCalling],
) -> str:
) -> str:
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(
@@ -166,6 +167,26 @@ class ToolUsage:
if self.task:
self.task.increment_tools_errors()
if self.agent:
event_data = {
"agent_key": self.agent.key if self.agent else None,
"agent_role": self.agent.role if self.agent else None,
"tool_name": self.action.tool,
"tool_args": self.action.tool_input,
"tool_class": self.action.tool,
"agent": self.agent,
}
if self.agent.fingerprint:
event_data.update(self.agent.fingerprint)
crewai_event_bus.emit(
self,
ToolUsageStartedEvent(
**event_data
),
)
started_at = time.time()
from_cache = False
result = None # type: ignore