From da92412225a8b6e9c9b8a7a66beb1a576bd34799 Mon Sep 17 00:00:00 2001 From: Lorenze Jay Date: Tue, 11 Mar 2025 11:46:08 -0700 Subject: [PATCH] Fix EventListener tool branch removal and type hinting --- src/crewai/utilities/events/event_listener.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/crewai/utilities/events/event_listener.py b/src/crewai/utilities/events/event_listener.py index 44434a944..82ac5d016 100644 --- a/src/crewai/utilities/events/event_listener.py +++ b/src/crewai/utilities/events/event_listener.py @@ -61,7 +61,7 @@ class EventListener(BaseEventListener): current_tool_branch = None current_flow_tree = None current_method_branch = None - tool_usage_counts = {} + tool_usage_counts: Dict[str, int] = {} def __new__(cls): if cls._instance is None: @@ -553,7 +553,6 @@ class EventListener(BaseEventListener): @crewai_event_bus.on(LLMCallStartedEvent) def on_llm_call_started(source, event: LLMCallStartedEvent): if self.verbose and self.current_agent_branch: - # Only show thinking state if no previous LLM calls are shown if not any( "Thinking" in str(child.label) for child in self.current_agent_branch.children @@ -570,7 +569,10 @@ class EventListener(BaseEventListener): if self.verbose and self.current_tool_branch: # Remove the thinking status node when complete if "Thinking" in str(self.current_tool_branch.label): - self.current_agent_branch.children.remove(self.current_tool_branch) + if self.current_agent_branch: + self.current_agent_branch.children.remove( + self.current_tool_branch + ) self.console.print(self.current_crew_tree) self.console.print()