Skip to main content
This is Part 3 of 3. Complete Part 1 and Part 2 first: Part 1 | Part 2
  • Time to complete: 15-20 minutes
  • What you’ll learn: Agent intelligence, advanced patterns, production deployment, and performance optimization

Understanding the Agent’s Intelligence

How the Agent “Thinks”

When you ask a question, the agent goes through a reasoning loop. Here’s a real example: User: “Find the oil manual on my drive and tell me the vision statement” Agent’s Internal Reasoning (this is what the LLM decides):
Note: This orchestration is handled by the LLM at runtime based on:
  1. System prompt (defines agent behavior)
  2. Tool schemas (available functions and their parameters)
  3. User input (the query to process)

Search Key Generation (Smart Retrieval)

The agent generates multiple variations of your query to improve retrieval. User asks: “What is the vision of the oil & gas regulator?” Agent generates multiple search keys:
  1. Original: “What is the vision of the oil & gas regulator?”
  2. Keywords: “vision oil gas regulator”
  3. Reformulated: “oil gas regulator vision definition”
  4. Alternate: “oil gas regulator vision explanation”
Then searches with ALL of them and combines results!
Impact on retrieval:
  • Increases recall by matching different phrasings
  • Compensates for keyword mismatches
  • Trade-off: More compute (multiple searches) for better coverage

Advanced Patterns

Pattern 1: Multi-Document Synthesis


Pattern 2: Contextual Follow-ups


Pattern 3: Progressive Discovery


Deployment Options

As a Web API

The OpenAI-compatible API server exposes a static AGENT_MODELS dict; there is no runtime registry.register() API. To add your agent, append an entry to src/gaia/api/agent_registry.py and restart the server:
src/gaia/api/agent_registry.py (excerpt)
Then run the server as usual:
See API Server for the full workflow.

As a CLI Tool

cli.py

Troubleshooting

Symptom: Agent responds with “No documents indexed”Debugging:
Common causes:
  • Missing RAG dependencies (uv pip install -e ".[rag]")
  • Incorrect file path
  • File not readable
Symptom: Agent returns irrelevant informationTuning options:
Check retrieval scores:
Symptom: New files not auto-indexedSolution:
Verify:
Symptom: Indexing takes excessive timeOptimizations:
Benchmark:
Typical performance on AI PC with Ryzen AI:
  • Small PDF (10 pages): ~2-3 seconds
  • Medium PDF (50 pages): ~8-12 seconds
  • Large PDF (200 pages): ~30-45 seconds
  • Embedding generation: ~50-100 chunks/second on NPU

Best Practices

Start Small

Index a few representative documents first, then scale. Full drive indexing is rarely necessary.

Tune for Document Type

Technical docs need larger chunks (600-800 tokens). FAQs work well with smaller chunks (300-400 tokens).

Use Sessions

Session persistence avoids re-indexing on every restart. Critical for large document sets.

Monitor Selectively

Watch only actively changing directories. Static archives don’t benefit from monitoring.

Security

Set allowed_paths in production. Prevents path traversal and unauthorized access.

Incremental Development

Build step-by-step. Test each component before combining them.

Performance Tuning


What You’ve Learned

Agent Architecture

The reasoning loop pattern: query → tool selection → execution → synthesis

Tool System

Using @tool decorator to register Python functions as LLM-invocable capabilities

RAG Integration

Vector embeddings, FAISS indexing, and semantic retrieval

Mixin Pattern

Composing agent functionality via multiple inheritance

File Monitoring

Watchdog-based reactive indexing with debouncing

Session Management

JSON serialization for state persistence

Security

Path validation, symlink detection, and access control

Performance

Tuning chunk size, retrieval count, and chunking strategies

Next Steps

Extend with Voice

Add Whisper (ASR) and Kokoro (TTS) for voice interaction.See: Voice Interaction Guide

Build Code Agent

Create an agent with code generation and debugging capabilities.See: Code Generation Agent

Build More Agents

Explore all available agent guides and playbooks.See: User Guides

Package for Distribution

Package as Electron app for desktop deployment.See: UI Documentation

Source Code Reference

ChatAgent

Main agent implementation with session management and file monitoring

RAGToolsMixin

Document indexing and query tools

FileToolsMixin

Directory monitoring implementation

FileSearchToolsMixin

Multi-phase file discovery across drives

Resources

GitHub

Source code, issues, and discussions

Discord

Developer community chat