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 Directory Read Tool

From Leeroopedia
Revision as of 11:07, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/CrewAIInc_CrewAI_Directory_Read_Tool.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Tools, File_System
Last Updated 2026-02-11 00:00 GMT

Overview

Recursively lists all files within a directory and its subdirectories.

Description

DirectoryReadTool extends BaseTool to provide file system directory listing capabilities. It uses Python's os.walk to traverse the entire directory tree and returns a formatted list of all discovered file paths. The tool supports two operational modes: a dynamic mode where the directory is specified at runtime via DirectoryReadToolSchema, and a fixed mode where a specific directory is pre-configured at construction time using FixedDirectoryReadToolSchema. In fixed mode, the tool description is automatically updated to reference the configured directory.

Usage

Use this tool when a CrewAI agent needs to discover available files before performing operations, validate directory structure, or build context about available resources in a workspace.

Code Reference

Source Location

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

Signature

class DirectoryReadTool(BaseTool):
    name: str = "List files in directory"
    description: str = "A tool that can be used to recursively list a directory's content."
    args_schema: type[BaseModel] = DirectoryReadToolSchema
    directory: str | None = None

    def __init__(self, directory: str | None = None, **kwargs): ...
    def _run(self, **kwargs: Any) -> Any: ...

Import

from crewai_tools import DirectoryReadTool

I/O Contract

Inputs

Name Type Required Description
directory str Yes (at init or runtime) Path to the directory to list

Outputs

Name Type Description
_run() returns str Formatted string of file paths prefixed with File paths:, each on a new line with a dash prefix

Usage Examples

Dynamic Directory

from crewai_tools import DirectoryReadTool

tool = DirectoryReadTool()
result = tool.run(directory="/path/to/project")

Fixed Directory

from crewai_tools import DirectoryReadTool

tool = DirectoryReadTool(directory="/path/to/project")
result = tool.run()

Related Pages

Page Connections

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