From db34516b18af0ff1f5d9f0fabd5703cb7af72c15 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 12 Feb 2025 06:46:27 +0000 Subject: [PATCH] fix: Fix type-checker issues with _finish_execution method Co-Authored-By: Joe Moura --- src/crewai/crew.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/crewai/crew.py b/src/crewai/crew.py index 69dcf0835..c6207d189 100644 --- a/src/crewai/crew.py +++ b/src/crewai/crew.py @@ -602,7 +602,8 @@ class Crew(BaseModel): inputs = before_callback(inputs) """Starts the crew to work on its assigned tasks.""" - self._execution_span = self._telemetry.crew_execution_span(self, inputs) + if self._telemetry: + self._execution_span = self._telemetry.crew_execution_span(self, inputs) self._task_output_handler.reset() self._logging_color = "bold_purple" @@ -1180,16 +1181,22 @@ class Crew(BaseModel): for agent in self.agents: agent.interpolate_inputs(inputs) - def _finish_execution(self, final_string_output: str) -> None: + def _finish_execution(self, final_output: Union[str, CrewOutput]) -> None: + """Finish execution and cleanup. + + Args: + final_output: The final output from crew execution, either as string or CrewOutput + """ if self.max_rpm: self._rpm_controller.stop_rpm_counter() - if agentops: - agentops.end_session( + if self._telemetry: + self._telemetry.end_crew(self, final_output) + if self._agentops: + self._agentops.end_session( end_state="Success", end_state_reason="Finished Execution", is_auto_end=True, ) - self._telemetry.end_crew(self, final_string_output) def calculate_usage_metrics(self) -> UsageMetrics: """Calculates and returns the usage metrics."""