Implementation:CrewAIInc CrewAI Files Compressor Tool
| Knowledge Sources | |
|---|---|
| Domains | Tools, File_System, Compression |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
Compresses files and directories into archive formats including zip, tar, tar.gz, tar.bz2, and tar.xz.
Description
FileCompressorTool extends BaseTool to provide comprehensive file and directory compression capabilities. It uses FileCompressorToolInput schema with parameters for input_path, output_path (optional, auto-generated if omitted), overwrite (boolean), and format (one of zip, tar, tar.gz, tar.bz2, tar.xz). The _run() method validates that the input path exists and the output extension matches the chosen format, generates output paths if not provided, creates output directories as needed, and delegates to format-specific methods: _compress_zip for ZIP archives using zipfile.ZipFile with ZIP_DEFLATED, and _compress_tar for all TAR variants using tarfile.open with appropriate mode strings. Both single files and recursive directories are supported.
Usage
Use this tool when a CrewAI agent needs to archive files for backup operations, log archiving, dataset packaging, or storage optimization.
Code Reference
Source Location
- Repository: CrewAI
- File:
lib/crewai-tools/src/crewai_tools/tools/files_compressor_tool/files_compressor_tool.py - Lines: 1-138
Signature
class FileCompressorTool(BaseTool):
name: str = "File Compressor Tool"
description: str = "Compresses a file or directory into an archive (.zip currently supported). ..."
args_schema: type[BaseModel] = FileCompressorToolInput
def _run(self, input_path: str, output_path: str | None = None,
overwrite: bool = False, format: str = "zip") -> str: ...
Import
from crewai_tools import FileCompressorTool
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| input_path | str | Yes | Path to the file or directory to compress |
| output_path | str | No | Output archive filename; auto-generated if omitted |
| overwrite | bool | No | Whether to overwrite an existing archive (default: False)
|
| format | str | No | Compression format: zip, tar, tar.gz, tar.bz2, or tar.xz (default: zip)
|
Outputs
| Name | Type | Description |
|---|---|---|
| _run() returns | str | Success message with input and output paths, or an error message |
Usage Examples
Compress a Directory
from crewai_tools import FileCompressorTool
tool = FileCompressorTool()
result = tool.run(input_path="/path/to/logs", format="tar.gz")
Compress with Custom Output
from crewai_tools import FileCompressorTool
tool = FileCompressorTool()
result = tool.run(
input_path="/path/to/data",
output_path="/backups/data_backup.zip",
overwrite=True,
format="zip",
)