Skip to content

Fix: Add CREWAI_DISABLE_EMOJIS environment variable to disable emojis in logs #3063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Fix: Add CREWAI_DISABLE_EMOJIS environment variable to disable emojis in logs

Summary

This PR implements a solution to disable emojis in CrewAI logs for runtime environments like Azure Functions that have issues with emoji output. It adds a flexible configuration mechanism through the CREWAI_DISABLE_EMOJIS environment variable.

Fixes #3062

Problem

Runtime environments like Azure Functions have issues with emoji output in logs, causing display problems and potential encoding issues. Users needed a way to disable emojis while maintaining all logging functionality.

Solution

  • Added CREWAI_DISABLE_EMOJIS environment variable to control emoji usage
  • Created comprehensive emoji-to-text mapping for all emojis used in the logging system
  • Implemented _get_icon() helper method in ConsoleFormatter for dynamic icon selection
  • Replaced all hardcoded emoji usage with calls to the helper method
  • Maintains full backward compatibility (emojis enabled by default)

Usage Examples

Default Behavior (Emojis Enabled)

from crewai import Crew, Agent, Task

# Normal usage - emojis will be displayed in logs
crew = Crew(agents=[agent], tasks=[task])
result = crew.kickoff()
# Output: "🚀 Crew: My Crew"

Disable Emojis for Azure Functions

import os
os.environ['CREWAI_DISABLE_EMOJIS'] = 'true'

from crewai import Crew, Agent, Task

# Emojis will be replaced with text alternatives
crew = Crew(agents=[agent], tasks=[task])
result = crew.kickoff()
# Output: "[CREW] Crew: My Crew"

Environment Variable Options

The environment variable accepts various truthy values:

  • CREWAI_DISABLE_EMOJIS=true
  • CREWAI_DISABLE_EMOJIS=1
  • CREWAI_DISABLE_EMOJIS=yes

Any other value (including empty string) keeps emojis enabled.

Emoji Mapping

All emojis are mapped to clear, descriptive text alternatives:

  • ✅ → [DONE]
  • ❌ → [FAILED]
  • 🚀 → [CREW]
  • 📋 → [TASK]
  • 🔧 → [TOOL]
  • 🧠 → [THINKING]
  • And many more...

Testing

What I Actually Checked

  • ✅ All 21 new tests pass covering emoji disable functionality
  • ✅ Full test suite passes (933 tests) - no regressions introduced
  • ✅ Manual testing confirms emojis are properly disabled/enabled
  • ✅ Environment variable parsing works for all expected values
  • ✅ Tree creation and all logging scenarios work in both modes
  • ✅ Backward compatibility maintained (default behavior unchanged)

What I Did Not Check

  • Performance impact of the additional environment variable check (expected to be negligible)
  • Integration with external logging systems beyond the console formatter
  • Behavior with custom emoji characters not in the mapping (falls back to ASCII)

Files Changed

  • src/crewai/utilities/events/utils/console_formatter.py - Core implementation
  • tests/utilities/events/utils/test_console_formatter_emoji_disable.py - Comprehensive test suite
  • tests/utilities/events/utils/__init__.py - Test directory initialization

Reviewer Checklist

Please verify:

  • Environment variable CREWAI_DISABLE_EMOJIS=true properly disables emojis in logs
  • Default behavior (emojis enabled) remains unchanged
  • All text alternatives are clear and descriptive
  • No performance regression in logging operations

Link to Devin run: https://app.devin.ai/sessions/88c27c9e7bfa4f51b790cf037ece8418

Requested by: João (joao@crewai.com)

…s in logs

- Add environment variable CREWAI_DISABLE_EMOJIS to control emoji usage
- Create comprehensive emoji-to-text mapping for runtime compatibility
- Implement _get_icon() helper method in ConsoleFormatter
- Replace all hardcoded emojis with dynamic icon selection
- Add comprehensive test suite covering all emoji disable scenarios
- Maintain backward compatibility (emojis enabled by default)
- Fixes issue #3062 for Azure Functions and similar runtime environments

Co-Authored-By: João <joao@crewai.com>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@joaomdmoura
Copy link
Collaborator

Disclaimer: This review was made by a crew of AI Agents.

Code Review Comment: Emoji Handling Enhancement

Summary

This pull request successfully implements an environment variable-controlled emoji disable feature for the CrewAI console formatter, effectively addressing compatibility issues in environments that lack support for emoji display. The changes are well documented and maintain backward compatibility, which is commendable.

Positive Aspects

  • Extensive Test Coverage: The addition of 272 new test lines assures that features are thoroughly validated.
  • Clear Documentation: The emoji mapping system is well-documented, facilitating easy understanding and potential extensions in the future.
  • Backward Compatibility: Existing functionality is preserved, ensuring that current users do not face disruptions.

Issues and Recommendations

1. Environment Variable Naming

Issue: The naming of the environment variable is somewhat ambiguous.
Recommendation: Consider renaming to either:

  • CREWAI_NO_EMOJI (more concise)
  • CREWAI_USE_ASCII (provides clarity on the variable's purpose)

2. Simplification of Boolean Conversion

Issue: The boolean conversion logic can be streamlined for better readability.
Recommendation:

def _parse_bool_env(val: str) -> bool:
    return val.lower() in ("true", "1", "yes") if val else False
self.disable_emojis = _parse_bool_env(os.getenv("CREWAI_DISABLE_EMOJIS", ""))

3. EMOJI_MAP Placement

Issue: The emoji map is currently defined within the class, consuming memory unnecessarily for each instance.
Recommendation: Move to a module level:

DEFAULT_EMOJI_MAP = {...}
class ConsoleFormatter:
    def __init__(self):
        self.emoji_map = DEFAULT_EMOJI_MAP.copy()

4. Type Hinting

Issue: Several methods lack type hints which could enhance clarity.
Recommendation: Add detailed type hints to methods, such as:

def _get_icon(self, emoji: str) -> str:

5. Error Handling for Invalid Emojis

Issue: The fallback for unrecognized emojis can result in empty strings or unclear responses.
Recommendation:

if emoji not in self.EMOJI_MAP:
    return f"[ICON:{emoji.encode('ascii', 'ignore').decode('ascii') or 'UNKNOWN'}]"

6. Configuration Validation

Issue: There is currently no validation checking the completeness of the emoji mapping.
Recommendation: Introduce a validation check in the initializer to ensure all used emojis have corresponding text alternatives.

7. Performance Optimization

Issue: String operations in frequently called methods could be optimized.
Recommendation: Implement caching for icon transformations if emojis are disabled:

self.icon_cache = {emoji: text for emoji, text in self.EMOJI_MAP.items()}

Security Considerations

  1. The implementation correctly manages ASCII character handling.
  2. The code is safe from potential command injection attacks through environmental variables.
  3. Proper handling of Unicode characters has been maintained.

Testing Suggestions

  • Add tests for edge cases, especially mixed emoji/text strings.
  • Conduct tests for memory usage with multiple formatter instances.
  • Implement performance benchmarks comparing emoji and non-emoji modes.

Documentation Enhancements

  1. Clarify the usage of the environment variable in the documentation.
  2. Provide a full list of supported emoji alternatives.
  3. Include usage examples for environments that cannot display emojis.

Conclusion

Overall, the implementation is well-executed and extensively tested. Only minor improvements related to code organization and error handling are recommended. Addressing these suggestions will enhance the maintainability and robustness of the feature, ensuring it remains functional across different environments.

Thank you for your effort in enhancing the usability of the console formatter!

devin-ai-integration bot and others added 2 commits June 25, 2025 13:02
- Move EMOJI_MAP to module level as DEFAULT_EMOJI_MAP for memory efficiency
- Add _parse_bool_env() helper function for cleaner boolean conversion
- Implement performance optimization with icon caching
- Improve error handling for unknown emojis with better fallback format
- Update tests to work with new module structure
- All functionality preserved and tests passing

Addresses feedback from PR review #3063

Co-Authored-By: João <joao@crewai.com>
- Remove unused typing.Union import from console_formatter.py
- Remove unused pytest and rich.text.Text imports from test file
- All emoji disable functionality preserved and tests passing
- Addresses CI lint failures in PR #3063

Co-Authored-By: João <joao@crewai.com>
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] Emojis in print logs completely blocks crewai running in specific runtime environments such as Azure Functions.
1 participant