From c20020e3fbcbe53010cde2f3229a3e3c017092ba Mon Sep 17 00:00:00 2001 From: Eduardo Chiarotti Date: Mon, 10 Feb 2025 11:04:12 -0300 Subject: [PATCH] feat: fix type checking issues --- src/crewai/flow/flow.py | 5 ++++- src/crewai/llm.py | 4 ++-- src/crewai/tools/tool_usage.py | 4 ++-- src/crewai/traces/unified_trace_controller.py | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/crewai/flow/flow.py b/src/crewai/flow/flow.py index 073ea3483..227857105 100644 --- a/src/crewai/flow/flow.py +++ b/src/crewai/flow/flow.py @@ -752,7 +752,10 @@ class Flow(Generic[T], metaclass=FlowMeta): if inputs is not None and "id" not in inputs: self._initialize_state(inputs) - return asyncio.run(self.kickoff_async()) + async def run_flow(): + return await self.kickoff_async() + + return asyncio.run(run_flow()) @init_flow_main_trace async def kickoff_async(self, inputs: Optional[Dict[str, Any]] = None) -> Any: diff --git a/src/crewai/llm.py b/src/crewai/llm.py index 377b124e6..093fb08d2 100644 --- a/src/crewai/llm.py +++ b/src/crewai/llm.py @@ -189,7 +189,7 @@ class LLM: self.context_window_size = 0 self.reasoning_effort = reasoning_effort self.additional_params = kwargs - self._message_history = [] + self._message_history: List[Dict[str, str]] = [] self.is_anthropic = self._is_anthropic_model(model) litellm.drop_params = True @@ -575,7 +575,7 @@ class LLM: return [] if not hasattr(self, "_tool_results_history"): - self._tool_results_history = [] + self._tool_results_history: List[Dict] = [] new_tool_results = [] diff --git a/src/crewai/tools/tool_usage.py b/src/crewai/tools/tool_usage.py index c918c9dd1..fa821bebd 100644 --- a/src/crewai/tools/tool_usage.py +++ b/src/crewai/tools/tool_usage.py @@ -119,8 +119,8 @@ class ToolUsage: if ( isinstance(tool, CrewStructuredTool) - and tool.name == self._i18n.tools("add_image")["name"] - ): # type: ignore + and tool.name == self._i18n.tools("add_image")["name"] # type: ignore + ): try: result = self._use(tool_string=tool_string, tool=tool, calling=calling) return result diff --git a/src/crewai/traces/unified_trace_controller.py b/src/crewai/traces/unified_trace_controller.py index 21f980399..e2bea0edf 100644 --- a/src/crewai/traces/unified_trace_controller.py +++ b/src/crewai/traces/unified_trace_controller.py @@ -23,6 +23,8 @@ class UnifiedTraceController: and recording of results for various types of operations (LLM calls, tool calls, flow steps). """ + _task_traces: Dict[str, List["UnifiedTraceController"]] = {} + def __init__( self, trace_type: TraceType, @@ -88,8 +90,6 @@ class UnifiedTraceController: Returns: List of traces associated with the task """ - if not hasattr(cls, "_task_traces"): - cls._task_traces = {} return cls._task_traces.get(task_id, []) @classmethod