This is Part 2 of 3. If you haven’t completed Part 1, start there: Part 1: Getting Started
- Time to complete: 15-20 minutes
- What you’ll build: Agent with monitoring, sessions, and custom capabilities
- What you’ll learn: Tool mixins, file watching, persistence, and extensibility patterns
Building It: The Step-by-Step Journey (Continued)
Step 4: Add Tool Mixins
Use GAIA’s built-in mixins instead of implementing tools from scratch.Mixin Tool Reference
Mixin Tool Reference
- RAGToolsMixin
- FileSearchToolsMixin
- FileToolsMixin
- Registration
Document operations:
query_documents(query)- Semantic search across all indexed docsquery_specific_file(file_path, query)- Search specific documentindex_document(file_path)- Add document to indexindex_directory(directory_path)- Index all files in directorylist_indexed_documents()- List currently indexed filesrag_status()- Get index statistics
from gaia.agents.tools import RAGToolsMixinStep 5: Add File Monitoring (Auto-Indexing)
Add file system monitoring to automatically reindex documents when they change.Under the Hood: File Watching
Under the Hood: File Watching
Watchdog library implementation:Implementation details:
- File events are async (non-blocking)
- Detection latency: ~1 second
- Runs in dedicated thread
- Debouncing: 2-second window per file
- Memory: LRU eviction at 1000 tracked files
- Supported types: .pdf, .txt, .md, .py, .json, etc.
What you have: Reactive file monitoring. The index automatically updates when documents are created or modified.
Step 6: Add Session Persistence
Implement session persistence to avoid re-indexing on every restart.Under the Hood: Session Persistence
Under the Hood: Session Persistence
Data structure:Save process:Load process:Use cases:
- Avoid re-indexing large document collections
- Maintain conversation context across restarts
- Share pre-indexed state with team (requires file permissions)
- Support long-running research sessions
What you have: Persistent sessions via JSON serialization. State (indexed docs, conversation) survives restarts.
The Complete Agent
TheChatAgent class combines all components. Here’s how to configure and use it:
- Full Configuration
- Usage
- Configuration Reference
complete_agent.py
Under the Hood: Complete System Flow
Under the Hood: Complete System Flow
Full execution sequence:
-
Initialization (Startup):
-
First Query: “What documents are indexed?”
-
Second Query: “Find safety manual…”
-
Background: File Added to ./documents/
Making It Your Own (Extensibility)
The agent uses Python class inheritance, so you can override methods or add new tools.Add Custom Tools
Extend the agent by adding domain-specific tools.- Custom Tools
- Usage
- Tool Registry
custom_tools.py
Customize RAG Behavior
- By Document Type
- Advanced Config
- Trade-offs
Create Specialized Agents
Override system prompts to create domain-specific behavior.- Research Agent
- Support Agent
- Pattern
research_agent.py
Real-World Examples
Example 1: Research Assistant
Use case: Searching across multiple academic papers for common themes.- Implementation
- Configuration Rationale
research_assistant.py
Example 2: Company Knowledge Base
Use case: Shared document search across organizational documentation.- Setup
- Team Usage
- Security Note
knowledge_base.py
Example 3: Personal Document Assistant
Use case: Interactive CLI for querying personal documents.- Implementation
- Usage
- Configuration
personal_assistant.py
Next Steps
You’ve built an agent with monitoring, sessions, and customization! Continue with Part 3 to learn deployment and optimization:Part 3: Deployment & Optimization
Master the agent’s intelligence, learn advanced patterns, deploy as API/CLI, and optimize performance.