Skip to main content
The FileWatcher and FileChangeHandler utilities provide file system monitoring for GAIA agents. Use them to watch directories for changes and trigger callbacks when files are created, modified, deleted, or moved.

Quick Start

Two Approaches

Use FileWatcher for simple directory watching with automatic lifecycle management:

2. FileChangeHandler (Advanced)

Use FileChangeHandler directly when you need more control:

Integration with Agents

FileWatcher works seamlessly with GAIA agents:

API Reference

FileWatcher

Methods

FileChangeHandler

Examples

Watch All Files

Custom Filter

Handle Moves/Renames

Access Telemetry

Default Extensions

When extensions is not specified, FileChangeHandler watches these file types:
  • Documents: .pdf, .txt, .md, .markdown, .rst
  • Data: .csv, .json, .xml, .yaml, .yml
  • Code: .py, .js, .ts, .java, .cpp, .c
  • Web: .html, .css
  • Logs: .log

Best Practices

Use Debouncing

Debouncing prevents duplicate events when files are modified multiple times quickly:

Handle Errors in Callbacks

Callbacks run in the observer thread. Errors are caught and logged:

Clean Up Resources

Always stop the watcher when done:

Requirements

FileWatcher requires the watchdog package:
Check if watchdog is available:

Complete Example

A complete working agent that watches a directory and tracks processed files using FileWatcherMixin:
Usage: