crewAI
crewAI copied to clipboard
feat: enhance JSON console formatting for tool input (#3474)
โจ Solution
Implemented comprehensive JSON formatting with two approaches:
1. Enhanced ANSI Color Formatting (agent_utils.py)
- 4-space indentation for better readability
- Sorted keys for consistency
- ANSI color syntax highlighting:
- ๐ต Keys: Bright cyan
- ๐ข Strings: Green
- ๐ก Numbers: Yellow
- ๐ฃ Booleans/null: Magenta
- โช Structural chars: White
- String tool_input handling: Attempts JSON parsing or wraps in
{"input": "..."}
2. Rich Integration (console_formatter.py)
- Enhanced panels with syntax highlighting for verbose mode
- Configurable formatting (pretty vs standard modes)
- Improved styling with emoji icons and clean borders
๐ Files Changed (4 files)
src/crewai/utilities/agent_utils.py- ANSI color JSON formattingsrc/crewai/events/utils/console_formatter.py- Rich-based JSON formattingtests/utilities/test_agent_utils.py- Comprehensive tests (22 tests)tests/utilities/test_console_formatter_json.py- Rich formatter tests (14 tests)
๐งช Testing
- โ 36 tests total - all passing
- โ Complete coverage of formatting scenarios
- โ Edge cases tested (large objects, unicode, errors)
- โ Integration tests for both verbose and non-verbose modes
- โ Error handling for non-serializable objects
๐ Before/After Example
Before:
{"search_query": "AI research", "limit": 10}
After:
{
"limit": 10,
"search_query": "AI research"
}
(With beautiful color syntax highlighting in actual console output)
๐ Key Features
- Backward compatible - no breaking changes
- Unicode support - preserves emoji and international characters
- Error resilient - graceful fallback for non-serializable objects
- Performance optimized - minimal overhead
- Configurable - supports both basic and rich formatting modes
Requesting @lorenzejay for review
This PR is stale because it has been open for 45 days with no activity.