Skip to content

Conversation

@Goldokpa
Copy link

@Goldokpa Goldokpa commented Nov 17, 2025

Add verbose parameter to Flow class to control console output and logging. Previously, flow events were always printed regardless of verbosity settings.

Changes:

  • Add verbose: bool = False parameter to Flow.init
  • Gate _log_flow_event to only print/log when verbose=True
  • Fix print_panel to respect verbose even when is_flow=True
  • Update event listeners to check Flow.verbose flag
  • Add comprehensive tests for verbose functionality
  • Update documentation with verbose parameter usage

Fixes #3826


Note

Adds Flow(verbose=False) to silence flow output by default and centralizes tracing enablement; updates listeners/formatter to respect verbosity, expands tracing utils, and documents/tests the behavior.

  • Flow Core (lib/crewai/src/crewai/flow/flow.py):
    • Add verbose: bool = False to Flow.__init__ and gate _log_flow_event and flow logs by self.verbose.
    • Change tracing default to None; determine via should_enable_tracing() and set context with set_tracing_enabled(); always set up TraceCollectionListener; simplify batch finalization.
  • Event/UI Output:
    • lib/crewai/src/crewai/events/event_listener.py: Flow event handlers temporarily set ConsoleFormatter.verbose from source.verbose.
    • lib/crewai/src/crewai/events/utils/console_formatter.py: All flow/crew/task/method printing functions (e.g., print_panel, start_flow, update_flow_status, update_method_status) now no-op when verbose is false.
  • Tracing Utilities (lib/crewai/src/crewai/events/listeners/tracing/utils.py):
    • Introduce context-based tracing control (ContextVar): set_tracing_enabled, reset_tracing_enabled, is_tracing_enabled_in_context.
    • Add should_enable_tracing() with precedence (override -> env -> user consent); persist consent via updated user data helpers; update first-execution markers to store trace_consent.
    • Refine should_auto_collect_first_time_traces() logic to respect declines/context.
  • Docs (docs/en/concepts/flows.mdx):
    • New "Flow Verbosity Control" section with usage examples; clarify interaction with @persist and difference between verbose and tracing.
  • Tests:
    • Add lib/crewai/tests/test_flow_verbose.py covering defaults, logging behavior, formatter gating, and independence from tracing/persistence.

Written by Cursor Bugbot for commit 1abb455. This will update automatically on new commits. Configure here.

Add verbose parameter to Flow class to control console output and logging.
Previously, flow events were always printed regardless of verbosity settings.

Changes:
- Add verbose: bool = False parameter to Flow.__init__
- Gate _log_flow_event to only print/log when verbose=True
- Fix print_panel to respect verbose even when is_flow=True
- Update event listeners to check Flow.verbose flag
- Add comprehensive tests for verbose functionality
- Update documentation with verbose parameter usage

Fixes crewAIInc#3826
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

tree = self.formatter.create_flow_tree(event.flow_name, str(source.flow_id))
self.formatter.current_flow_tree = tree
finally:
self.formatter.verbose = original_verbose
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Race condition in concurrent flow verbose handling

The flow event handlers temporarily modify the shared singleton self.formatter.verbose without thread synchronization. When multiple flows run concurrently, one handler can save the verbose value while another handler has already modified it, causing the wrong value to be restored. This results in flows incorrectly inheriting verbose settings from other concurrent flows. The EventListener is a singleton with a shared formatter instance, but the verbose flag manipulation lacks the thread safety that _crew_tree_lock provides for other operations.

Additional Locations (2)

Fix in Cursor Fix in Web

- Wrap verbose flag manipulation with _crew_tree_lock in all flow event handlers to prevent race conditions in concurrent flows
- Fix tracing parameter to respect tracing=False and always disable when explicitly False
- Only check environment settings when tracing=None (default behavior)
… tracing approach

- Keep verbose parameter from fix/flow-verbosity-control branch
- Use main branch's tracing approach with should_enable_tracing and set_tracing_enabled
- Add missing tracing utility functions (has_user_declined_tracing, should_enable_tracing, set_tracing_enabled)
- Ensure tracing=False properly disables tracing as documented
…plementation

- Replace global variable approach with ContextVar for thread-safe context-aware tracing
- Add ContextVar-based should_enable_tracing, set_tracing_enabled, reset_tracing_enabled, is_tracing_enabled_in_context
- Update mark_first_execution_done to accept user_consented parameter
- Update mark_first_execution_completed to match main branch signature
- Update is_tracing_enabled to check has_user_declined_tracing first
- Remove duplicate implementations from fix/flow-verbosity-control branch
# If user has explicitly declined tracing, never enable it
if has_user_declined_tracing():
return False

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: User consent not recorded in first execution confirmation

The function calls mark_first_execution_done() before prompting the user and doesn't pass the user's consent response. This means trace_consent is always recorded as False regardless of whether the user confirms or declines tracing. The user's response from click.confirm() needs to be captured and passed to mark_first_execution_done(user_consented=response) after the prompt.

Fix in Cursor Fix in Web

- Move is_tracing_enabled() to after has_user_declined_tracing() to match main branch structure
- Move user data functions (_user_data_file, _load_user_data, _save_user_data, has_user_declined_tracing) to right after is_tracing_enabled_in_context()
- Ensure function order matches main branch exactly to resolve merge conflicts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] the verbose information of flow could not be disabled

1 participant