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

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

Overview

TXTSearchTool performs RAG-based semantic search over plain text (.txt) file content using vector embeddings.

Description

The TXTSearchTool extends RagTool and uses a dual-schema pattern: TXTSearchToolSchema requires both search_query and txt (file path), while FixedTXTSearchToolSchema requires only search_query (used when a specific file is pre-configured). During model validation via _configure_for_txt, if a txt path is provided at initialization, the tool adds the file content to the RAG index, updates its description to reference the specific file, and switches to the fixed schema. The _run method accepts a search_query and an optional txt path; if a new file path is provided at runtime, it is added to the index before delegating the semantic search to the parent RagTool._run with optional similarity_threshold and limit parameters.

Usage

Use this tool when a CrewAI agent needs to semantically search through text file content, enabling intelligent information extraction from plain text documents rather than simple keyword matching.

Code Reference

Source Location

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

Signature

class FixedTXTSearchToolSchema(BaseModel):
    search_query: str = Field(..., description="Mandatory search query ...")

class TXTSearchToolSchema(FixedTXTSearchToolSchema):
    txt: str = Field(..., description="File path or URL of a TXT file to be searched")

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

    def _run(self, search_query: str, txt: str | None = None,
             similarity_threshold: float | None = None, limit: int | None = None) -> str:
        ...

Import

from crewai_tools import TXTSearchTool

I/O Contract

Inputs

Name Type Required Description
search_query str Yes The semantic search query to run against the TXT content
txt str No File path or URL of a TXT file to search (can be set at init or runtime)
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 text passages from the TXT file

Usage Examples

Basic Usage

from crewai_tools import TXTSearchTool

tool = TXTSearchTool(txt="/path/to/document.txt")
result = tool._run(search_query="key findings")

Dynamic File

from crewai_tools import TXTSearchTool

tool = TXTSearchTool()
result = tool._run(search_query="summary", txt="/path/to/another.txt")

Related Pages

Page Connections

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