DS DevShelfHub Projects · AI tools
Tutorials / CrewAI / Reference / Classes / FileReadTool
Class tools

FileReadTool: Reference Guide

By DevShelfHub

Reads the contents of a local file.

See the CrewAI API reference index, CrewAI introduction, and core concepts for surrounding context.

What is FileReadTool?

FileReadTool exposes read-only filesystem access to agents so they can inspect logs, configuration, or generated artifacts during a kickoff. It is intentionally simple: the model supplies a path and receives text back, which makes it ideal for internal automation where paths are already normalized. The moment you point the same tool at user-provided paths, you inherit path traversal risk — combine with @before_tool_call_crew hooks or a thin subclass that enforces allowlists and size caps.

Encoding is the other sharp edge: UTF-8 text works predictably, but legacy Windows encodings or binary files can yield exceptions or gibberish that the model treats as truth. Pre-convert documents to UTF-8 text or use specialized knowledge sources for PDFs instead of dumping raw bytes through FileReadTool.

Pair with FileWriterTool only when your workflow truly needs round-trips; many crews only need read access plus a final Task output, which keeps blast radius smaller.

When to Use

Local file IO.

Use Cases

  • Log inspection
  • Config reading

Key Features

  • Trivial setup

When NOT to Use

Remote storage — use a dedicated tool.

Notes

Path normalization

Always resolve paths against a trusted base directory. Agents happily concatenate ../ sequences if prompts steer them that way.

Size limits

Reading multi-gigabyte logs into the LLM context will blow token budgets. Truncate or tail files in a hook before the tool returns text.

Concurrency

Multiple agents reading the same hot file is fine, but writing concurrently without coordination corrupts inputs — isolate read-heavy agents from writers.

Container filesystems

Kubernetes pods lose ephemeral disk on restart. Mount persistent volumes or object storage gateways if FileReadTool must see durable artifacts.

Import

python
from crewai_tools import FileReadTool

Code Examples

Minimal agent wiring

python
from crewai import Agent
from crewai_tools import FileReadTool

agent = Agent(role='Debugger', goal='Diagnose logs', backstory='You cite line numbers.', tools=[FileReadTool()])

Subclass with allowlisted roots

python
from pathlib import Path
from crewai_tools import FileReadTool

class SafeFileReadTool(FileReadTool):
    root = Path('/var/crew_jobs/job-42')

    def _run(self, path: str) -> str:
        p = (self.root / path).resolve()
        if self.root not in p.parents and p != self.root:
            raise ValueError('path outside job sandbox')
        return super()._run(str(p))

Pair with CodeInterpreterTool for CSV stats

python
from crewai import Agent
from crewai_tools import FileReadTool, CodeInterpreterTool

analyst = Agent(
    role='Analyst',
    goal='Summarize CSV numerically',
    backstory='Read via FileReadTool then compute in CodeInterpreterTool.',
    tools=[FileReadTool(), CodeInterpreterTool()],
    allow_code_execution=True,
)

Common Mistakes

❌ Letting the agent read arbitrary paths

✅ Filter paths via a custom subclass.

FileReadTool FAQ

What is FileReadTool in CrewAI?

Reads the contents of a local file. FileReadTool exposes read-only filesystem access to agents so they can inspect logs, configuration, or generated artifacts during a kickoff. It is intentionally simple: the model supplies a path and receives text back, which makes it ideal for internal automation where paths are already normalized. The moment you point the same tool at user-provided paths, you inherit path traversal risk — combine with @before_tool_call_crew hooks or a thin subclass that enforces allowlists a…

Which package defines the CrewAI class FileReadTool?

DevShelfHub maps FileReadTool to Python module crewai_tools (package path crewai_tools in this reference). Pin your installed crewai version and match imports to the snippet on this page.

When should I use FileReadTool?

Local file IO.

When should I avoid using FileReadTool?

Remote storage — use a dedicated tool.

How do I import FileReadTool in Python?

from crewai_tools import FileReadTool

Where can I explore more CrewAI API reference pages?

Open the CrewAI API reference index on DevShelfHub to search 58 classes, 30 methods, and 16 decorators, each with runnable examples, parameters, common mistakes, and cross-links.