Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CrewAIInc CrewAI File Read Tool

From Leeroopedia
Knowledge Sources
Domains Tools, File_System
Last Updated 2026-02-11 00:00 GMT

Overview

Reads file contents with support for partial file reading via line range parameters.

Description

FileReadTool extends BaseTool to provide file reading capabilities with FileReadToolSchema defining parameters for file_path, start_line, and line_count. The tool supports two modes: a dynamic mode where any file path is accepted at runtime, and a fixed mode where a default file path is pre-configured at construction. The _run() method reads files completely when no line parameters are specified, or in chunks based on start_line (1-indexed) and line_count for efficient processing of large files. Comprehensive error handling covers FileNotFoundError, PermissionError, and out-of-bounds line numbers.

Usage

Use this tool when a CrewAI agent needs to read file contents from the local filesystem. The partial reading feature is particularly useful for processing large files without loading the entire content into memory.

Code Reference

Source Location

  • Repository: CrewAI
  • File: lib/crewai-tools/src/crewai_tools/tools/file_read_tool/file_read_tool.py
  • Lines: 1-102

Signature

class FileReadTool(BaseTool):
    name: str = "Read a file's content"
    description: str = "A tool that reads the content of a file. ..."
    args_schema: type[BaseModel] = FileReadToolSchema
    file_path: str | None = None

    def __init__(self, file_path: str | None = None, **kwargs: Any) -> None: ...
    def _run(self, file_path: str | None = None, start_line: int | None = 1,
             line_count: int | None = None) -> str: ...

Import

from crewai_tools import FileReadTool

I/O Contract

Inputs

Name Type Required Description
file_path str Yes (at init or runtime) Full path to the file to read
start_line int No Line number to start reading from (1-indexed, default: 1)
line_count int No Number of lines to read; None reads the entire file

Outputs

Name Type Description
_run() returns str File content as a string, or an error message if the operation fails

Usage Examples

Read Entire File

from crewai_tools import FileReadTool

tool = FileReadTool()
content = tool.run(file_path="/path/to/file.txt")

Read Specific Lines

from crewai_tools import FileReadTool

tool = FileReadTool(file_path="/path/to/large_file.log")
content = tool.run(start_line=100, line_count=50)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment