Source Code:
src/gaia/agents/code/tools/file_io.pyComponent: FileIOToolsMixin
Module:
gaia.agents.code.tools.file_io
Import: from gaia.agents.code.tools.file_io import FileIOToolsMixinOverview
FileIOToolsMixin provides comprehensive file I/O operations with intelligent file type detection, syntax validation, and security controls. It handles Python files with full AST analysis, markdown with structure extraction, and generic text files with appropriate encoding. Key Features:- Read files with automatic type detection and analysis
- Write Python files with syntax validation
- Edit files with diff generation
- Search code across directories
- Generate diffs for changes
- Markdown file operations
- Generic file operations without validation
- Security through path validation
Tool Specifications
1. read_file
Read any file and intelligently analyze based on file type. Parameters:file_path(str, required): Path to the file to read
2. write_python_file
Write Python code to a file with syntax validation. Parameters:file_path(str, required): Path where to write the filecontent(str, required): Python code contentvalidate(bool, optional): Validate syntax before writing (default: True)create_dirs(bool, optional): Create parent directories (default: True)
3. edit_python_file
Edit a Python file by replacing content with validation. Parameters:file_path(str, required): Path to the fileold_content(str, required): Content to find and replacenew_content(str, required): New content to insertbackup(bool, optional): Create backup (default: True)dry_run(bool, optional): Only simulate (default: False)
4. search_code
Search for patterns in code files. Parameters:directory(str, optional): Directory to search (default: ”.”)pattern(str, optional): Pattern to search forfile_extension(str, optional): File extension filter (default: “.py”)max_results(int, optional): Maximum results (default: 100)
5. generate_diff
Generate a unified diff for a file. Parameters:file_path(str, required): Path to original filenew_content(str, required): New content to comparecontext_lines(int, optional): Context lines in diff (default: 3)
6. write_file
Write content to any file without syntax validation. Parameters:file_path(str, required): Path where to writecontent(str, required): Content to writecreate_dirs(bool, optional): Create parent directories (default: True)project_dir(str, optional): Project root for resolving relative paths
7. edit_file
Edit any file by replacing content without validation. Parameters:file_path(str, required): Path to fileold_content(str, required): Exact content to find and replacenew_content(str, required): New content to replace withproject_dir(str, optional): Project root for resolving paths
8. replace_function
Replace a specific function in a Python file. Parameters:file_path(str, required): Path to Python filefunction_name(str, required): Name of function to replacenew_implementation(str, required): New function implementationbackup(bool, optional): Create backup (default: True)
9. write_markdown_file
Write (or overwrite) a Markdown file, optionally creating parent directories. Used by the code agent when generating READMEs, spec documents, or reports. Parameters:file_path(str, required): Destination pathcontent(str, required): Markdown content to writecreate_dirs(bool, optional): Create parent directories if missing (default: True)
10. update_gaia_md
Refresh the project’sGAIA.md (or another project-level index file) with
generated metadata — used by the code agent to keep project docs in sync with
what it’s building.
Parameters:
project_root(str, optional): Project root directory (default:".")project_name(str, optional): Display name to write into the filedescription(str, optional): Short project descriptionstructure(str or dict, optional): Formatted directory structureinstructions(str, optional): Agent-facing instructions section
Usage Examples
Example 1: Read and Analyze Python File
Example 2: Write Validated Python Code
Example 3: Edit File with Diff
Example 4: Search Codebase
Example 5: TypeScript/Generic File Operations
Security Model
Path Validation
All file operations check paths against allowed directories:Allowed Paths Configuration
File Type Detection
Python Files (.py)
- Full AST parsing
- Syntax validation
- Symbol extraction (functions, classes)
- Error reporting with line numbers
Markdown Files (.md)
- Header extraction (# patterns)
- Code block extraction with language tags
- Link extraction (text patterns)
Binary Files
- Detected via UnicodeDecodeError
- Returns size and binary flag
- No content parsing
Text Files
- Raw content reading
- Line count and size reporting
- No special analysis
Dependencies
Testing Requirements
File:tests/agents/code/test_file_io.py
FileIOToolsMixin Technical Specification