Skip to content

Commit

Permalink
Revert "true dependency"
Browse files Browse the repository at this point in the history
This reverts commit e52e8e9.
  • Loading branch information
bboynton97 committed Apr 20, 2024
1 parent 216cc83 commit 4d1b460
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ click = "^8.1.7"
python-dotenv = "1.0.0"
embedchain = "^0.1.98"
appdirs = "^1.4.4"
agentops = "^0.1.1"
agentops = { version = "^0.1.1", optional = true }

[tool.poetry.extras]
tools = ["crewai-tools"]
agentops = ["agentops"]

[tool.poetry.group.dev.dependencies]
isort = "^5.13.2"
Expand Down
8 changes: 6 additions & 2 deletions src/crewai/crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
from crewai.telemetry import Telemetry
from crewai.tools.agent_tools import AgentTools
from crewai.utilities import I18N, FileHandler, Logger, RPMController
import agentops
try:
import agentops
except ImportError:
agentops = None


class Crew(BaseModel):
Expand Down Expand Up @@ -376,7 +379,8 @@ def _format_output(self, output: str) -> str:
def _finish_execution(self, output) -> None:
if self.max_rpm:
self._rpm_controller.stop_rpm_counter()
agentops.end_session(end_state="Success", end_state_reason="Finished Execution")
if agentops:
agentops.end_session(end_state="Success", end_state_reason="Finished Execution")
self._telemetry.end_crew(self, output)

def __repr__(self):
Expand Down
8 changes: 5 additions & 3 deletions src/crewai/tools/tool_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _use(
tool: BaseTool,
calling: Union[ToolCalling, InstructorToolCalling],
) -> None:
tool_event = agentops.ToolEvent(name=calling.tool_name)
tool_event = agentops.ToolEvent(name=calling.tool_name) if agentops else None
if self._check_tool_repeated_usage(calling=calling):
try:
result = self._i18n.errors("task_repeated_usage").format(
Expand Down Expand Up @@ -161,7 +161,8 @@ def _use(
self._printer.print(content=f"\n\n{error_message}\n", color="red")
return error
self.task.increment_tools_errors()
agentops.record(agentops.ErrorEvent(details=e, trigger_event=tool_event))
if agentops:
agentops.record(agentops.ErrorEvent(details=e, trigger_event=tool_event))
return self.use(calling=calling, tool_string=tool_string)

if self.tools_handler:
Expand All @@ -182,7 +183,8 @@ def _use(
)

self._printer.print(content=f"\n\n{result}\n", color="purple")
agentops.record(tool_event)
if agentops:
agentops.record(tool_event)
self._telemetry.tool_usage(
llm=self.function_calling_llm,
tool_name=tool.name,
Expand Down

0 comments on commit 4d1b460

Please sign in to comment.