diff --git a/src/crewai/lite_agent.py b/src/crewai/lite_agent.py index c65c0c155..603823b4d 100644 --- a/src/crewai/lite_agent.py +++ b/src/crewai/lite_agent.py @@ -40,7 +40,7 @@ from crewai.events.types.logging_events import AgentLogsExecutionEvent from crewai.flow.flow_trackable import FlowTrackable from crewai.llm import LLM from crewai.llms.base_llm import BaseLLM -from crewai.task import TaskOutput +from crewai.tasks import TaskOutput from crewai.tools.base_tool import BaseTool from crewai.tools.structured_tool import CrewStructuredTool from crewai.utilities import I18N @@ -217,7 +217,10 @@ class LiteAgent(FlowTrackable, BaseModel): @model_validator(mode="after") def ensure_guardrail_is_callable(self) -> Self: if callable(self.guardrail): - self._guardrail = self.guardrail + self._guardrail = cast( + Callable[[LiteAgentOutput | TaskOutput], tuple[bool, Any]], + self.guardrail, + ) elif isinstance(self.guardrail, str): from crewai.tasks.llm_guardrail import LLMGuardrail @@ -226,7 +229,10 @@ class LiteAgent(FlowTrackable, BaseModel): f"Guardrail requires LLM instance of type BaseLLM, got {type(self.llm).__name__}" ) - self._guardrail = LLMGuardrail(description=self.guardrail, llm=self.llm) + self._guardrail = cast( + Callable[[LiteAgentOutput | TaskOutput], tuple[bool, Any]], + LLMGuardrail(description=self.guardrail, llm=self.llm), + ) return self diff --git a/src/crewai/tools/tool_usage.py b/src/crewai/tools/tool_usage.py index 5f01b0b6d..004766514 100644 --- a/src/crewai/tools/tool_usage.py +++ b/src/crewai/tools/tool_usage.py @@ -165,7 +165,7 @@ class ToolUsage: """ if self._check_tool_repeated_usage(calling=calling): try: - result = self._i18n.errors("task_repeated_usage").format( + repeated_usage_msg = self._i18n.errors("task_repeated_usage").format( tool_names=self.tools_names ) self._telemetry.tool_repeated_usage( @@ -173,8 +173,8 @@ class ToolUsage: tool_name=tool.name, attempts=self._run_attempts, ) - result = self._format_result(result=result) - return result + repeated_usage_result = self._format_result(result=repeated_usage_msg) + return repeated_usage_result except Exception: if self.task: @@ -303,7 +303,7 @@ class ToolUsage: attempts=self._run_attempts, ) result = self._format_result(result=result) - data = { + data: dict[str, Any] = { "result": result, "tool_name": tool.name, "tool_args": calling.arguments,