Skip to main content
Component: FileSearchToolsMixin Module: gaia.agents.tools.file_tools Import: from gaia.agents.tools.file_tools import FileSearchToolsMixin

Overview

FileSearchToolsMixin provides agent-agnostic file search and management operations shared across multiple agents (Chat, Code). Features intelligent multi-phase search, type-based file analysis, and grep-like content searching. Key Features:
  • 3-phase intelligent file search (workspace → common locations → deep scan)
  • Type-aware file reading (Python AST, Markdown structure, binary detection)
  • Grep-like content search across file systems
  • Directory search with depth control
  • Generic file writing with directory creation
write_file and edit_file share the file-state guard: an existing file the agent has not read, or one whose mtime or size changed since it did, is refused before anything is written or backed up — see Read before edit for what counts as a read. Overwriting an existing file is also refused, and the file left unchanged, when its backup cannot be made. Successful writes become the baseline for later edits. Search Strategy:
  • A named directory is the WHOLE scope: searched to unlimited depth, and never widened — not by Phase 1, not by deep_search (#3576)
  • Phase 0: the agent’s workspace — PathValidator.allowed_paths, most specific first. The most specific root is searched to unlimited depth; the others, which accumulate as the user approves paths, are depth-capped
  • Phase 1: common locations (Documents, Downloads, Desktop) with a depth limit
  • Phase 2: deep drive/root search, only when deep_search=True and no directory was named
  • Early termination on first match for speed
The search root is the declared sandbox, not Path.cwd(). A sidecar is spawned by the daemon in its own package directory, so the working directory says how the process was launched, not where the user’s work is.

API Specification


Implementation Highlights

A zero result reports where it looked: searched_paths, a search_context of "workspace" or "directory", and a suggestion telling the model that zero means zero under those paths, not zero on the machine. A named directory that does not exist is status: "error", not an empty success.

Python File Analysis


Testing Requirements

File: tests/agents/tools/test_file_search_mixin.py Key tests:
  • 3-phase search progression
  • File type detection and analysis
  • Python AST symbol extraction
  • Markdown structure parsing
  • Binary file detection
  • Grep content search
  • Directory creation on write
  • Large file handling

Usage Examples


FileSearchToolsMixin Technical Specification