From eca18b03ab91c9b1754605a290f47a0b4296613a Mon Sep 17 00:00:00 2001 From: lorenzejay Date: Wed, 20 May 2026 16:04:59 -0700 Subject: [PATCH] linted --- .../src/crewai/events/event_listener.py | 8 ++----- .../listeners/tracing/trace_listener.py | 4 +--- lib/crewai/src/crewai/flow/chat.py | 5 +++- lib/crewai/src/crewai/flow/conversation.py | 2 +- lib/crewai/src/crewai/flow/flow.py | 24 ++++++++++--------- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/crewai/src/crewai/events/event_listener.py b/lib/crewai/src/crewai/events/event_listener.py index 959bdd769..c5b19eb2f 100644 --- a/lib/crewai/src/crewai/events/event_listener.py +++ b/lib/crewai/src/crewai/events/event_listener.py @@ -321,12 +321,8 @@ class EventListener(BaseEventListener): event.flow_name, list(source._methods.keys()) ) if not getattr(source, "suppress_flow_events", False): - self.formatter.handle_flow_created( - event.flow_name, str(source.flow_id) - ) - self.formatter.handle_flow_started( - event.flow_name, str(source.flow_id) - ) + self.formatter.handle_flow_created(event.flow_name, str(source.flow_id)) + self.formatter.handle_flow_started(event.flow_name, str(source.flow_id)) @crewai_event_bus.on(FlowFinishedEvent) def on_flow_finished(source: Any, event: FlowFinishedEvent) -> None: diff --git a/lib/crewai/src/crewai/events/listeners/tracing/trace_listener.py b/lib/crewai/src/crewai/events/listeners/tracing/trace_listener.py index 3867ccb4d..663764bcd 100644 --- a/lib/crewai/src/crewai/events/listeners/tracing/trace_listener.py +++ b/lib/crewai/src/crewai/events/listeners/tracing/trace_listener.py @@ -736,9 +736,7 @@ class TraceCollectionListener(BaseEventListener): def _nested_in_flow_execution(self) -> bool: """True when a crew runs inside a flow session (context or batch ownership).""" - return ( - self._is_inside_active_flow_context() or self._flow_owns_trace_batch() - ) + return self._is_inside_active_flow_context() or self._flow_owns_trace_batch() def _initialize_crew_batch(self, source: Any, event: BaseEvent) -> None: """Initialize trace batch. diff --git a/lib/crewai/src/crewai/flow/chat.py b/lib/crewai/src/crewai/flow/chat.py index 044068b5c..f9d1f36e6 100644 --- a/lib/crewai/src/crewai/flow/chat.py +++ b/lib/crewai/src/crewai/flow/chat.py @@ -9,7 +9,10 @@ from uuid import uuid4 from pydantic import BaseModel, Field -from crewai.flow.conversation import get_conversation_messages, get_conversational_config +from crewai.flow.conversation import ( + get_conversation_messages, + get_conversational_config, +) from crewai.utilities.types import LLMMessage diff --git a/lib/crewai/src/crewai/flow/conversation.py b/lib/crewai/src/crewai/flow/conversation.py index 400a0dc12..aa1f211b6 100644 --- a/lib/crewai/src/crewai/flow/conversation.py +++ b/lib/crewai/src/crewai/flow/conversation.py @@ -132,7 +132,7 @@ def append_message( messages = getattr(state, "messages", None) if messages is None: object.__setattr__(state, "messages", []) - messages = getattr(state, "messages") + messages = state.messages if isinstance(messages, list): messages.append(message) return diff --git a/lib/crewai/src/crewai/flow/flow.py b/lib/crewai/src/crewai/flow/flow.py index bf2cc2c18..af342d9b1 100644 --- a/lib/crewai/src/crewai/flow/flow.py +++ b/lib/crewai/src/crewai/flow/flow.py @@ -2320,13 +2320,20 @@ class Flow(BaseModel, Generic[T], metaclass=FlowMeta): restore_from_state_id: str | None, ) -> Any: config = get_conversational_config(self) or self.conversational_config - prompt = interactive_prompt or (config.interactive_prompt if config else "You: ") + prompt = interactive_prompt or ( + config.interactive_prompt if config else "You: " + ) timeout = ( interactive_timeout if interactive_timeout is not None else (config.interactive_timeout if config else None) ) - exits = {c.strip().lower() for c in (exit_commands or (config.exit_commands if config else ("exit", "quit")))} + exits = { + c.strip().lower() + for c in ( + exit_commands or (config.exit_commands if config else ("exit", "quit")) + ) + } sid = session_id if sid is None and inputs and "id" in inputs: sid = str(inputs["id"]) @@ -2585,9 +2592,7 @@ class Flow(BaseModel, Generic[T], metaclass=FlowMeta): try: await asyncio.wrap_future(future) except Exception: - logger.warning( - "FlowStartedEvent handler failed", exc_info=True - ) + logger.warning("FlowStartedEvent handler failed", exc_info=True) if self._should_defer_trace_finalization(): object.__setattr__(self, "_conversation_trace_started", True) object.__setattr__( @@ -2599,9 +2604,7 @@ class Flow(BaseModel, Generic[T], metaclass=FlowMeta): TraceCollectionListener, ) - TraceCollectionListener().batch_manager.defer_session_finalization = ( - True - ) + TraceCollectionListener().batch_manager.defer_session_finalization = True if not self.suppress_flow_events: self._log_flow_event( f"Flow started with ID: {self.flow_id}", color="bold magenta" @@ -3890,9 +3893,8 @@ class Flow(BaseModel, Generic[T], metaclass=FlowMeta): return result = self._method_outputs[-1] if self._method_outputs else None - if ( - self._should_defer_trace_finalization() - and getattr(self, "_conversation_trace_started", False) + if self._should_defer_trace_finalization() and getattr( + self, "_conversation_trace_started", False ): started_id = getattr(self, "_conversation_flow_started_event_id", None) if started_id: