From 7c46dce2f7d05c2351c40bcac29f70eb2e78e768 Mon Sep 17 00:00:00 2001 From: Lorenze Jay Date: Tue, 11 Mar 2025 08:43:56 -0700 Subject: [PATCH] Add verbose flag to EventListener for controlled logging --- src/crewai/crew.py | 3 + .../utilities/events/base_event_listener.py | 2 + src/crewai/utilities/events/event_listener.py | 698 +++++++++--------- 3 files changed, 365 insertions(+), 338 deletions(-) diff --git a/src/crewai/crew.py b/src/crewai/crew.py index 9cecfed3a..574848284 100644 --- a/src/crewai/crew.py +++ b/src/crewai/crew.py @@ -248,7 +248,10 @@ class Crew(BaseModel): @model_validator(mode="after") def set_private_attrs(self) -> "Crew": """Set private attributes.""" + from crewai.utilities.events.event_listener import EventListener + self._cache_handler = CacheHandler() + EventListener().verbose = self.verbose self._logger = Logger(verbose=self.verbose) if self.output_log_file: self._file_handler = FileHandler(self.output_log_file) diff --git a/src/crewai/utilities/events/base_event_listener.py b/src/crewai/utilities/events/base_event_listener.py index 37763dcc1..f08b70025 100644 --- a/src/crewai/utilities/events/base_event_listener.py +++ b/src/crewai/utilities/events/base_event_listener.py @@ -5,6 +5,8 @@ from crewai.utilities.events.crewai_event_bus import CrewAIEventsBus, crewai_eve class BaseEventListener(ABC): + verbose: bool = False + def __init__(self): super().__init__() self.setup_listeners(crewai_event_bus) diff --git a/src/crewai/utilities/events/event_listener.py b/src/crewai/utilities/events/event_listener.py index b455c65a0..5d7e3d427 100644 --- a/src/crewai/utilities/events/event_listener.py +++ b/src/crewai/utilities/events/event_listener.py @@ -1,6 +1,6 @@ from datetime import datetime from io import StringIO -from typing import Any, Dict +from typing import Any, Dict, Optional from pydantic import Field, PrivateAttr from rich.console import Console @@ -112,7 +112,7 @@ class EventListener(BaseEventListener): prefix: str, name: str, style: str = "blue", - status: str = None, + status: Optional[str] = None, ) -> None: """Update tree label with consistent formatting.""" label = Text() @@ -130,19 +130,23 @@ class EventListener(BaseEventListener): # ----------- METHODS ----------- def on_crew_start(self, source: Any, event: Any) -> None: - # Create the crew tree that will hold tasks - self.current_crew_tree = Tree( - Text("๐Ÿš€ Crew: ", style="cyan bold") + Text(event.crew_name, style="cyan") - ) + if self.verbose: + self.current_crew_tree = Tree( + Text("๐Ÿš€ Crew: ", style="cyan bold") + + Text(event.crew_name, style="cyan") + ) - content = Text() - content.append(f"NAME: {event.crew_name}", style="white") - content.append(f"\nID: {source.id}", style="blue") + content = self._create_status_content( + "Crew Execution Started", + event.crew_name, + "cyan", + ID=source.id, + ) - panel = self._create_panel(content, "Crew Execution Started", "cyan") + panel = self._create_panel(content, "Crew Execution Started", "cyan") + self.console.print(panel) + self.console.print() - self.console.print(panel) - self.console.print() # Add spacing self._telemetry.crew_execution_span(source, event.inputs) # ----------- CREW EVENTS ----------- @@ -157,70 +161,67 @@ class EventListener(BaseEventListener): # Handle telemetry final_string_output = event.output.raw self._telemetry.end_crew(source, final_string_output) + if self.verbose: + if self.current_crew_tree: + self._update_tree_label( + self.current_crew_tree, + "โœ… Crew:", + event.crew_name or "Crew", + "green", + ) - if self.current_crew_tree: - # Update crew tree label to show completion - crew_content = Text() - crew_content.append("โœ… Crew: ", style="green bold") - crew_content.append(event.crew_name or "Crew", style="green") - self.current_crew_tree.label = crew_content + completion_content = self._create_status_content( + "Crew Execution Completed", + event.crew_name or "Crew", + "green", + ID=source.id, + ) - # Create completion panel - completion_content = Text() - completion_content.append( - "Crew Execution Completed\n", style="green bold" - ) - completion_content.append("Name: ", style="white") - completion_content.append(f"{event.crew_name}\n", style="green") - completion_content.append("ID: ", style="white") - completion_content.append(str(source.id), style="blue") - - # Show final tree and completion panel - self.console.print(self.current_crew_tree) - self.console.print() - - panel = self._create_panel( - completion_content, "Crew Completion", "green" - ) - self.console.print(panel) - self.console.print() + self.console.print(self.current_crew_tree) + self.console.print() + panel = self._create_panel( + completion_content, "Crew Completion", "green" + ) + self.console.print(panel) + self.console.print() @crewai_event_bus.on(CrewKickoffFailedEvent) def on_crew_failed(source, event: CrewKickoffFailedEvent): - if self.current_crew_tree: - # Update crew tree label to show failure - crew_content = Text() - crew_content.append("โŒ Crew: ", style="red bold") - crew_content.append(event.crew_name or "Crew", style="red") - self.current_crew_tree.label = crew_content + if self.verbose: + if self.current_crew_tree: + # Update crew tree label to show failure + crew_content = Text() + crew_content.append("โŒ Crew: ", style="red bold") + crew_content.append(event.crew_name or "Crew", style="red") + self.current_crew_tree.label = crew_content - # Create failure panel - failure_content = Text() - failure_content.append("Crew Execution Failed\n", style="red bold") - failure_content.append("Name: ", style="white") - failure_content.append(f"{event.crew_name}\n", style="red") - failure_content.append("ID: ", style="white") - failure_content.append(str(source.id), style="blue") + # Create failure panel + failure_content = Text() + failure_content.append("Crew Execution Failed\n", style="red bold") + failure_content.append("Name: ", style="white") + failure_content.append(f"{event.crew_name}\n", style="red") + failure_content.append("ID: ", style="white") + failure_content.append(str(source.id), style="blue") - # Show final tree and failure panel - self.console.print(self.current_crew_tree) - self.console.print() + # Show final tree and failure panel + self.console.print(self.current_crew_tree) + self.console.print() - panel = self._create_panel(failure_content, "Crew Failure", "red") - self.console.print(panel) - self.console.print() + panel = self._create_panel(failure_content, "Crew Failure", "red") + self.console.print(panel) + self.console.print() @crewai_event_bus.on(CrewTestFailedEvent) def on_crew_test_failed(source, event: CrewTestFailedEvent): - # Create test failure content - failure_content = Text() - failure_content.append("โŒ Crew Test Failed\n", style="red bold") - failure_content.append("Crew: ", style="white") - failure_content.append(event.crew_name or "Crew", style="red") + if self.verbose: + failure_content = Text() + failure_content.append("โŒ Crew Test Failed\n", style="red bold") + failure_content.append("Crew: ", style="white") + failure_content.append(event.crew_name or "Crew", style="red") - panel = self._create_panel(failure_content, "Test Failure", "red") - self.console.print(panel) - self.console.print() + panel = self._create_panel(failure_content, "Test Failure", "red") + self.console.print(panel) + self.console.print() @crewai_event_bus.on(CrewTrainStartedEvent) def on_crew_train_started(source, event: CrewTrainStartedEvent): @@ -238,15 +239,15 @@ class EventListener(BaseEventListener): @crewai_event_bus.on(CrewTrainFailedEvent) def on_crew_train_failed(source, event: CrewTrainFailedEvent): - # Create training failure content - failure_content = Text() - failure_content.append("โŒ Crew Training Failed\n", style="red bold") - failure_content.append("Crew: ", style="white") - failure_content.append(event.crew_name or "Crew", style="red") + if self.verbose: + failure_content = Text() + failure_content.append("โŒ Crew Training Failed\n", style="red bold") + failure_content.append("Crew: ", style="white") + failure_content.append(event.crew_name or "Crew", style="red") - panel = self._create_panel(failure_content, "Training Failure", "red") - self.console.print(panel) - self.console.print() + panel = self._create_panel(failure_content, "Training Failure", "red") + self.console.print(panel) + self.console.print() # ----------- TASK EVENTS ----------- @@ -255,23 +256,23 @@ class EventListener(BaseEventListener): span = self._telemetry.task_started(crew=source.agent.crew, task=source) self.execution_spans[source] = span - # Create task content - task_content = Text() - task_content.append("๐Ÿ“‹ Task: ", style="yellow bold") - task_content.append("\n Assigned to: ", style="white") - task_content.append(source.agent.role, style="green") - task_content.append("\n Status: ", style="white") - task_content.append("Waiting for agent...", style="yellow dim") + if self.verbose: + task_content = Text() + task_content.append("๐Ÿ“‹ Task: ", style="yellow bold") + task_content.append("\n Assigned to: ", style="white") + task_content.append(source.agent.role, style="green") + task_content.append("\n Status: ", style="white") + task_content.append("Waiting for agent...", style="yellow dim") - # Add task to the crew tree - if self.current_crew_tree: - self.current_task_branch = self.current_crew_tree.add(task_content) - self.console.print(self.current_crew_tree) - else: - panel = self._create_panel(task_content, "Task Started", "yellow") - self.console.print(panel) + # Add task to the crew tree + if self.current_crew_tree: + self.current_task_branch = self.current_crew_tree.add(task_content) + self.console.print(self.current_crew_tree) + else: + panel = self._create_panel(task_content, "Task Started", "yellow") + self.console.print(panel) - self.console.print() + self.console.print() @crewai_event_bus.on(TaskCompletedEvent) def on_task_completed(source, event: TaskCompletedEvent): @@ -281,27 +282,29 @@ class EventListener(BaseEventListener): self._telemetry.task_ended(span, source, source.agent.crew) self.execution_spans[source] = None - # Create completion content - completion_content = Text() - completion_content.append("โœ… Task Completed\n", style="green bold") - completion_content.append(f"Task: {str(source.id)}", style="white") - completion_content.append("\nAgent: ", style="white") - completion_content.append(source.agent.role, style="green") + if self.verbose: + completion_content = Text() + completion_content.append("โœ… Task Completed\n", style="green bold") + completion_content.append(f"Task: {str(source.id)}", style="white") + completion_content.append("\nAgent: ", style="white") + completion_content.append(source.agent.role, style="green") - # Update the tree if it exists - if self.current_crew_tree: - # Find the task branch and update it with completion status - for branch in self.current_crew_tree.children: - if source.description in branch.label: - branch.label = Text("โœ… ", style="green bold") + branch.label - self.console.print(self.current_crew_tree) - break + # Update the tree if it exists + if self.current_crew_tree: + for branch in self.current_crew_tree.children: + if source.description in branch.label: + branch.label = ( + Text("โœ… ", style="green bold") + branch.label + ) + self.console.print(self.current_crew_tree) + break - # Always show completion panel - panel = self._create_panel(completion_content, "Task Completion", "green") + panel = self._create_panel( + completion_content, "Task Completion", "green" + ) - self.console.print(panel) - self.console.print() # Add spacing + self.console.print(panel) + self.console.print() @crewai_event_bus.on(TaskFailedEvent) def on_task_failed(source, event: TaskFailedEvent): @@ -311,60 +314,62 @@ class EventListener(BaseEventListener): self._telemetry.task_ended(span, source, source.agent.crew) self.execution_spans[source] = None - # Create failure content - failure_content = Text() - failure_content.append("โŒ Task Failed\n", style="red bold") - failure_content.append("Task: ", style="white") - failure_content.append(source.description, style="red") - if source.agent: - failure_content.append("\nAgent: ", style="white") - failure_content.append(source.agent.role, style="red") + if self.verbose: + failure_content = Text() + failure_content.append("โŒ Task Failed\n", style="red bold") + failure_content.append("Task: ", style="white") + failure_content.append(source.description, style="red") + if source.agent: + failure_content.append("\nAgent: ", style="white") + failure_content.append(source.agent.role, style="red") - # Update the tree if it exists - if self.current_crew_tree: - # Find the task branch and update it with failure status - for branch in self.current_crew_tree.children: - if source.description in branch.label: - branch.label = Text("โŒ ", style="red bold") + branch.label - self.console.print(self.current_crew_tree) - break + # Update the tree if it exists + if self.current_crew_tree: + # Find the task branch and update it with failure status + for branch in self.current_crew_tree.children: + if source.description in branch.label: + branch.label = Text("โŒ ", style="red bold") + branch.label + self.console.print(self.current_crew_tree) + break - # Show failure panel - panel = self._create_panel(failure_content, "Task Failure", "red") - self.console.print(panel) - self.console.print() + # Show failure panel + panel = self._create_panel(failure_content, "Task Failure", "red") + self.console.print(panel) + self.console.print() # ----------- AGENT EVENTS ----------- @crewai_event_bus.on(AgentExecutionStartedEvent) def on_agent_execution_started(source, event: AgentExecutionStartedEvent): - if self.current_task_branch: - # Create agent execution branch - agent_content = Text() - agent_content.append("๐Ÿค– Agent: ", style="green bold") - agent_content.append(event.agent.role, style="green") - agent_content.append("\n Status: ", style="white") - agent_content.append("In Progress", style="blue bold") + if self.verbose: + if self.current_task_branch: + # Create agent execution branch with empty label + self.current_agent_branch = self.current_task_branch.add("") + self._update_tree_label( + self.current_agent_branch, + "๐Ÿค– Agent:", + event.agent.role, + "green", + "In Progress", + ) - # Create a branch for the agent's activities - self.current_agent_branch = self.current_task_branch.add(agent_content) - self.console.print(self.current_crew_tree) - self.console.print() + self.console.print(self.current_crew_tree) + self.console.print() @crewai_event_bus.on(AgentExecutionCompletedEvent) def on_agent_execution_completed(source, event: AgentExecutionCompletedEvent): - if self.current_agent_branch: - # Update agent branch to show completion - agent_content = Text() - agent_content.append("๐Ÿค– Agent: ", style="green bold") - agent_content.append(event.agent.role, style="green") - agent_content.append("\n Status: ", style="white") - agent_content.append("โœ… Completed", style="green bold") + if self.verbose: + if self.current_agent_branch: + self._update_tree_label( + self.current_agent_branch, + "๐Ÿค– Agent:", + event.agent.role, + "green", + "โœ… Completed", + ) - # Update the agent branch label - self.current_agent_branch.label = agent_content - self.console.print(self.current_crew_tree) - self.console.print() + self.console.print(self.current_crew_tree) + self.console.print() # ----------- FLOW EVENTS ----------- @@ -372,33 +377,32 @@ class EventListener(BaseEventListener): def on_flow_created(source, event: FlowCreatedEvent): self._telemetry.flow_creation_span(event.flow_name) - # Create flow content for panel - content = Text() - content.append("๐ŸŒŠ Starting Flow Execution\n\n", style="blue bold") - content.append("Name: ", style="white") - content.append(event.flow_name, style="blue") + if self.verbose: + content = self._create_status_content( + "Starting Flow Execution", event.flow_name, "blue" + ) - panel = self._create_panel(content, "Flow Execution", "blue") + panel = self._create_panel(content, "Flow Execution", "blue") - self.console.print() - self.console.print(panel) - self.console.print() + self.console.print() + self.console.print(panel) + self.console.print() - # Create and display the initial tree - flow_label = Text() - flow_label.append("๐ŸŒŠ Flow: ", style="blue bold") - flow_label.append(event.flow_name, style="blue") + # Create and display the initial tree + flow_label = Text() + flow_label.append("๐ŸŒŠ Flow: ", style="blue bold") + flow_label.append(event.flow_name, style="blue") - self.current_flow_tree = Tree(flow_label) + self.current_flow_tree = Tree(flow_label) - # Add both creation steps to show progression - self.current_flow_tree.add(Text("โœจ Created", style="blue")) - self.current_flow_tree.add( - Text("โœ… Initialization Complete", style="green") - ) + # Add both creation steps to show progression + self.current_flow_tree.add(Text("โœจ Created", style="blue")) + self.current_flow_tree.add( + Text("โœ… Initialization Complete", style="green") + ) - self.console.print(self.current_flow_tree) - self.console.print() + self.console.print(self.current_flow_tree) + self.console.print() @crewai_event_bus.on(FlowStartedEvent) def on_flow_started(source, event: FlowStartedEvent): @@ -406,174 +410,187 @@ class EventListener(BaseEventListener): event.flow_name, list(source._methods.keys()) ) - # Create flow tree with status - flow_label = Text() - flow_label.append("๐ŸŒŠ Flow: ", style="blue bold") - flow_label.append(event.flow_name, style="blue") - flow_label.append("\n Status: ", style="white") - flow_label.append("In Progress", style="yellow") + if self.verbose: + self.current_flow_tree = Tree("") + self._update_tree_label( + self.current_flow_tree, + "๐ŸŒŠ Flow:", + event.flow_name, + "blue", + "In Progress", + ) - self.current_flow_tree = Tree(flow_label) + # Add initial thinking state + self.current_flow_tree.add(Text("๐Ÿง  Initializing...", style="yellow")) - # Add initial thinking state - self.current_flow_tree.add(Text("๐Ÿง  Initializing...", style="yellow")) - - self.console.print() - self.console.print(self.current_flow_tree) - self.console.print() + self.console.print() + self.console.print(self.current_flow_tree) + self.console.print() @crewai_event_bus.on(FlowFinishedEvent) def on_flow_finished(source, event: FlowFinishedEvent): - if self.current_flow_tree: - # Update flow tree label to show completion - self.current_flow_tree.label = Text( - "โœ… Flow Finished: ", style="green bold" - ) + Text(event.flow_name, style="green") + if self.verbose: + if self.current_flow_tree: + self._update_tree_label( + self.current_flow_tree, + "โœ… Flow Finished:", + event.flow_name, + "green", + ) - # Create completion content - content = Text() - content.append("Flow Execution Completed\n", style="green bold") - content.append("Name: ", style="white") - content.append(f"{event.flow_name}\n", style="green") - content.append("ID: ", style="white") - content.append(source.flow_id, style="blue") + content = self._create_status_content( + "Flow Execution Completed", + event.flow_name, + "green", + ID=source.flow_id, + ) - panel = self._create_panel(content, "Flow Completion", "green") - self.console.print(panel) - self.console.print() + panel = self._create_panel(content, "Flow Completion", "green") + self.console.print(panel) + self.console.print() @crewai_event_bus.on(MethodExecutionStartedEvent) def on_method_execution_started(source, event: MethodExecutionStartedEvent): - if self.current_flow_tree: - # Find and update the method branch - for branch in self.current_flow_tree.children: - if event.method_name in branch.label: - self.current_method_branch = branch - branch.label = Text("๐Ÿ”„ Running: ", style="yellow bold") + Text( - event.method_name, style="yellow" - ) - break + if self.verbose: + if self.current_flow_tree: + # Find and update the method branch + for branch in self.current_flow_tree.children: + if event.method_name in branch.label: + self.current_method_branch = branch + branch.label = Text( + "๐Ÿ”„ Running: ", style="yellow bold" + ) + Text(event.method_name, style="yellow") + break - self.console.print(self.current_flow_tree) - self.console.print() + self.console.print(self.current_flow_tree) + self.console.print() @crewai_event_bus.on(MethodExecutionFinishedEvent) def on_method_execution_finished(source, event: MethodExecutionFinishedEvent): - if self.current_method_branch: - # Update method status - self.current_method_branch.label = Text( - "โœ… Completed: ", style="green bold" - ) + Text(event.method_name, style="green") - self.console.print(self.current_flow_tree) - self.console.print() + if self.verbose: + if self.current_method_branch: + # Update method status + self.current_method_branch.label = Text( + "โœ… Completed: ", style="green bold" + ) + Text(event.method_name, style="green") + self.console.print(self.current_flow_tree) + self.console.print() @crewai_event_bus.on(MethodExecutionFailedEvent) def on_method_execution_failed(source, event: MethodExecutionFailedEvent): - if self.current_method_branch: - # Update method status to show failure - self.current_method_branch.label = Text( - "โŒ Failed: ", style="red bold" - ) + Text(event.method_name, style="red") - self.console.print(self.current_flow_tree) - self.console.print() + if self.verbose: + if self.current_method_branch: + self.current_method_branch.label = Text( + "โŒ Failed: ", style="red bold" + ) + Text(event.method_name, style="red") + self.console.print(self.current_flow_tree) + self.console.print() # ----------- TOOL USAGE EVENTS ----------- @crewai_event_bus.on(ToolUsageStartedEvent) def on_tool_usage_started(source, event: ToolUsageStartedEvent): - # Create tool usage content - tool_content = Text() - tool_content.append("๐Ÿ”ง Using ", style="yellow bold") - tool_content.append(event.tool_name, style="yellow") + if self.verbose: + # Create tool usage content + tool_content = Text() + tool_content.append("๐Ÿ”ง Using ", style="yellow bold") + tool_content.append(event.tool_name, style="yellow") - # Add to tree under the agent branch - if self.current_agent_branch: - self.current_tool_branch = self.current_agent_branch.add(tool_content) - self.console.print(self.current_crew_tree) - self.console.print() + # Add to tree under the agent branch + if self.current_agent_branch: + self.current_tool_branch = self.current_agent_branch.add( + tool_content + ) + self.console.print(self.current_crew_tree) + self.console.print() @crewai_event_bus.on(ToolUsageFinishedEvent) def on_tool_usage_finished(source, event: ToolUsageFinishedEvent): - # Create completion content - completion_content = Text() - completion_content.append("๐Ÿ”ง Used ", style="green bold") - completion_content.append(event.tool_name, style="green") + if self.verbose: + completion_content = Text() + completion_content.append("๐Ÿ”ง Used ", style="green bold") + completion_content.append(event.tool_name, style="green") - # Update under the agent branch - if self.current_tool_branch: - self.current_tool_branch.label = completion_content - self.console.print(self.current_crew_tree) - self.console.print() + # Update under the agent branch + if self.current_tool_branch: + self.current_tool_branch.label = completion_content + self.console.print(self.current_crew_tree) + self.console.print() @crewai_event_bus.on(ToolUsageErrorEvent) def on_tool_usage_error(source, event: ToolUsageErrorEvent): - # Create tool error content - error_content = Text() - error_content.append("๐Ÿ”ง Tool Failed: ", style="red bold") - error_content.append(event.tool_name, style="red") + if self.verbose: + error_content = Text() + error_content.append("๐Ÿ”ง Tool Failed: ", style="red bold") + error_content.append(event.tool_name, style="red") - # Update under the agent branch - if self.current_tool_branch: - self.current_tool_branch.label = error_content - self.console.print(self.current_crew_tree) + # Update under the agent branch + if self.current_tool_branch: + self.current_tool_branch.label = error_content + self.console.print(self.current_crew_tree) + self.console.print() + + # Show error panel + panel = self._create_panel( + Text( + f"Tool usage failed: {event.tool_name}: {event.error}", + style="red", + ), + "Tool Error", + "red", + ) + self.console.print(panel) self.console.print() - # Show error panel - panel = self._create_panel( - Text( - f"Tool usage failed: {event.tool_name}: {event.error}", style="red" - ), - "Tool Error", - "red", - ) - self.console.print(panel) - self.console.print() - # ----------- LLM EVENTS ----------- @crewai_event_bus.on(LLMCallStartedEvent) def on_llm_call_started(source, event: LLMCallStartedEvent): - # Create simple LLM call content - llm_content = Text() - llm_content.append("๐Ÿง  Thinking...", style="blue bold") + if self.verbose: + llm_content = Text() + llm_content.append("๐Ÿง  Thinking...", style="blue bold") - # Add to tree under the agent branch - if self.current_agent_branch: - self.current_tool_branch = self.current_agent_branch.add(llm_content) - self.console.print(self.current_crew_tree) - self.console.print() + # Add to tree under the agent branch + if self.current_agent_branch: + self.current_tool_branch = self.current_agent_branch.add( + llm_content + ) + self.console.print(self.current_crew_tree) + self.console.print() @crewai_event_bus.on(LLMCallCompletedEvent) def on_llm_call_completed(source, event: LLMCallCompletedEvent): - # Create simple completion content - completion_content = Text() - completion_content.append("โœจ Done", style="green bold") + if self.verbose: + completion_content = Text() + completion_content.append("โœจ Done", style="green bold") - # Update under the agent branch - if self.current_tool_branch: - self.current_tool_branch.label = completion_content - self.console.print(self.current_crew_tree) - self.console.print() + # Update under the agent branch + if self.current_tool_branch: + self.current_tool_branch.label = completion_content + self.console.print(self.current_crew_tree) + self.console.print() @crewai_event_bus.on(LLMCallFailedEvent) def on_llm_call_failed(source, event: LLMCallFailedEvent): - # Create LLM error content - error_content = Text() - error_content.append("โŒ LLM Call Failed\n", style="red bold") - error_content.append("Error: ", style="white") - error_content.append(str(event.error), style="red") + if self.verbose: + error_content = Text() + error_content.append("โŒ LLM Call Failed\n", style="red bold") + error_content.append("Error: ", style="white") + error_content.append(str(event.error), style="red") - # Update under the agent branch if it exists - if self.current_tool_branch: - self.current_tool_branch.label = Text("โŒ LLM Failed", style="red bold") - self.console.print(self.current_crew_tree) + # Update under the agent branch if it exists + if self.current_tool_branch: + self.current_tool_branch.label = Text( + "โŒ LLM Failed", style="red bold" + ) + self.console.print(self.current_crew_tree) + self.console.print() + + # Show error panel + panel = self._create_panel(error_content, "LLM Error", "red") + self.console.print(panel) self.console.print() - # Show error panel - panel = self._create_panel(error_content, "LLM Error", "red") - self.console.print(panel) - self.console.print() - @crewai_event_bus.on(LLMStreamChunkEvent) def on_llm_stream_chunk(source, event: LLMStreamChunkEvent): self.text_stream.write(event.chunk) @@ -595,67 +612,72 @@ class EventListener(BaseEventListener): event.eval_llm or "", ) - # Create test content for panel - content = Text() - content.append("๐Ÿงช Starting Crew Test\n\n", style="blue bold") - content.append("Crew: ", style="white") - content.append(f"{event.crew_name}\n", style="blue") - content.append("ID: ", style="white") - content.append(str(source.id), style="blue") - content.append("\nIterations: ", style="white") - content.append(str(event.n_iterations), style="yellow") + if self.verbose: + content = Text() + content.append("๐Ÿงช Starting Crew Test\n\n", style="blue bold") + content.append("Crew: ", style="white") + content.append(f"{event.crew_name}\n", style="blue") + content.append("ID: ", style="white") + content.append(str(source.id), style="blue") + content.append("\nIterations: ", style="white") + content.append(str(event.n_iterations), style="yellow") - panel = self._create_panel(content, "Test Execution", "blue") + panel = self._create_panel(content, "Test Execution", "blue") - self.console.print() - self.console.print(panel) - self.console.print() + self.console.print() + self.console.print(panel) + self.console.print() - # Create and display the test tree - test_label = Text() - test_label.append("๐Ÿงช Test: ", style="blue bold") - test_label.append(event.crew_name or "Crew", style="blue") - test_label.append("\n Status: ", style="white") - test_label.append("In Progress", style="yellow") - - self.current_flow_tree = Tree(test_label) - self.current_flow_tree.add(Text("๐Ÿ”„ Running tests...", style="yellow")) - - self.console.print(self.current_flow_tree) - self.console.print() - - @crewai_event_bus.on(CrewTestCompletedEvent) - def on_crew_test_completed(source, event: CrewTestCompletedEvent): - if self.current_flow_tree: - # Update test tree label to show completion + # Create and display the test tree test_label = Text() - test_label.append("โœ… Test: ", style="green bold") - test_label.append(event.crew_name or "Crew", style="green") + test_label.append("๐Ÿงช Test: ", style="blue bold") + test_label.append(event.crew_name or "Crew", style="blue") test_label.append("\n Status: ", style="white") - test_label.append("Completed", style="green bold") - self.current_flow_tree.label = test_label + test_label.append("In Progress", style="yellow") - # Update the running tests node - for child in self.current_flow_tree.children: - if "Running tests" in str(child.label): - child.label = Text( - "โœ… Tests completed successfully", style="green" - ) + self.current_flow_tree = Tree(test_label) + self.current_flow_tree.add(Text("๐Ÿ”„ Running tests...", style="yellow")) self.console.print(self.current_flow_tree) self.console.print() - # Create completion panel - completion_content = Text() - completion_content.append("Test Execution Completed\n", style="green bold") - completion_content.append("Crew: ", style="white") - completion_content.append(f"{event.crew_name}\n", style="green") - completion_content.append("Status: ", style="white") - completion_content.append("All tests passed", style="green") + @crewai_event_bus.on(CrewTestCompletedEvent) + def on_crew_test_completed(source, event: CrewTestCompletedEvent): + if self.verbose: + if self.current_flow_tree: + # Update test tree label to show completion + test_label = Text() + test_label.append("โœ… Test: ", style="green bold") + test_label.append(event.crew_name or "Crew", style="green") + test_label.append("\n Status: ", style="white") + test_label.append("Completed", style="green bold") + self.current_flow_tree.label = test_label - panel = self._create_panel(completion_content, "Test Completion", "green") - self.console.print(panel) - self.console.print() + # Update the running tests node + for child in self.current_flow_tree.children: + if "Running tests" in str(child.label): + child.label = Text( + "โœ… Tests completed successfully", style="green" + ) + + self.console.print(self.current_flow_tree) + self.console.print() + + # Create completion panel + completion_content = Text() + completion_content.append( + "Test Execution Completed\n", style="green bold" + ) + completion_content.append("Crew: ", style="white") + completion_content.append(f"{event.crew_name}\n", style="green") + completion_content.append("Status: ", style="white") + completion_content.append("All tests passed", style="green") + + panel = self._create_panel( + completion_content, "Test Completion", "green" + ) + self.console.print(panel) + self.console.print() event_listener = EventListener()