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 Search Tool

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

Overview

Performs semantic search across directory contents using RAG (Retrieval-Augmented Generation).

Description

DirectorySearchTool extends RagTool to enable intelligent, meaning-based search through all files within a directory. It registers directory content as DataType.DIRECTORY via the add() method, which indexes the files for semantic retrieval. The tool supports two modes: a dynamic mode where the directory is specified at runtime via DirectorySearchToolSchema, and a fixed mode where a directory is pre-configured at construction using FixedDirectorySearchToolSchema. Search results can be tuned with similarity_threshold and limit parameters.

Usage

Use this tool when a CrewAI agent needs to find relevant information across multiple files in a directory based on semantic meaning rather than exact text matching. Suitable for research agents, documentation assistants, and knowledge retrieval systems.

Code Reference

Source Location

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

Signature

class DirectorySearchTool(RagTool):
    name: str = "Search a directory's content"
    description: str = "A tool that can be used to semantic search a query from a directory's content."
    args_schema: type[BaseModel] = DirectorySearchToolSchema

    def __init__(self, directory: str | None = None, **kwargs): ...
    def add(self, directory: str) -> None: ...
    def _run(self, search_query: str, directory: str | None = None,
             similarity_threshold: float | None = None, limit: int | None = None) -> str: ...

Import

from crewai_tools import DirectorySearchTool

I/O Contract

Inputs

Name Type Required Description
search_query str Yes The semantic search query
directory str Yes (at init or runtime) Path to the directory to search
similarity_threshold float No Minimum similarity score for results
limit int No Maximum number of results to return

Outputs

Name Type Description
_run() returns str Semantically relevant content from the directory matching the query

Usage Examples

Dynamic Directory

from crewai_tools import DirectorySearchTool

tool = DirectorySearchTool()
result = tool.run(search_query="authentication flow", directory="/path/to/docs")

Fixed Directory

from crewai_tools import DirectorySearchTool

tool = DirectorySearchTool(directory="/path/to/docs")
result = tool.run(search_query="authentication flow")

Related Pages

Page Connections

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