File size: 8,924 Bytes
c922f8b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# GAIA Deployment Guide
This guide outlines the procedures for deploying the GAIA agent in various environments, including local development, testing, and production deployments.
## Table of Contents
1. [Prerequisites](#prerequisites)
2. [Environment Configuration](#environment-configuration)
3. [Local Deployment](#local-deployment)
4. [Hugging Face Spaces Deployment](#hugging-face-spaces-deployment)
5. [Custom Server Deployment](#custom-server-deployment)
6. [API-Only Deployment](#api-only-deployment)
7. [Monitoring and Maintenance](#monitoring-and-maintenance)
8. [Troubleshooting](#troubleshooting)
## Prerequisites
Before deploying GAIA, ensure you have the following:
- Python 3.10+
- Git
- Required API keys for external services:
- Supabase (for memory persistence)
- Search providers (Serper, DuckDuckGo, etc.)
- LLM providers (OpenAI, Anthropic, etc.)
- Virtual environment management tools
## Environment Configuration
### Environment Variables
GAIA uses environment variables for configuration. Create a `.env` file based on `.env.example` with the following sections:
```bash
# Core Configuration
GAIA_ENVIRONMENT=production # or development or testing
GAIA_LOG_LEVEL=INFO # DEBUG, INFO, WARNING, ERROR
# API Keys
OPENAI_API_KEY=your_openai_api_key
SERPER_API_KEY=your_serper_api_key
DUCKDUCKGO_API_KEY=your_duckduckgo_api_key
PERPLEXITY_API_KEY=your_perplexity_api_key
# Supabase Configuration
SUPABASE_URL=your_supabase_url
SUPABASE_KEY=your_supabase_key
SUPABASE_TABLE_PREFIX=gaia_
# Web Server Configuration
GAIA_HOST=0.0.0.0
GAIA_PORT=8000
GAIA_WORKERS=4 # Number of worker processes
# Memory Configuration
GAIA_MEMORY_PROVIDER=supabase # or local
GAIA_MEMORY_TTL=86400 # Time to live in seconds (24 hours)
```
### Validating Environment
Before deployment, validate your environment configuration:
```bash
python src/gaia/utils/validate_environment.py
```
This script checks that all required environment variables are set and that API credentials are valid.
## Local Deployment
### Development Environment
For local development and testing:
1. **Clone the repository**
```bash
git clone https://github.com/your-org/gaia.git
cd gaia
```
2. **Create a virtual environment**
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. **Install dependencies**
```bash
pip install -r requirements.txt
```
4. **Set up environment variables**
```bash
cp .env.example .env
# Edit .env with your API keys and configuration
```
5. **Run the development server**
```bash
python app.py
```
The development server will be available at `http://localhost:8000`.
### Running with Docker
For a containerized local deployment:
1. **Build the Docker image**
```bash
docker build -t gaia-agent .
```
2. **Run the container**
```bash
docker run -p 8000:8000 --env-file .env gaia-agent
```
## Hugging Face Spaces Deployment
GAIA can be deployed to Hugging Face Spaces for easy access and sharing.
### Deployment Steps
1. **Prepare your repository**
- Ensure all tests pass: `python src/gaia/tests/real_world/run_all_tests.py`
- Update the README.md with correct Hugging Face metadata
2. **Set up Hugging Face CLI**
```bash
pip install huggingface_hub
huggingface-cli login
```
3. **Deploy to Hugging Face Spaces**
```bash
python src/gaia/deployment/deploy_to_huggingface.py
```
Alternatively, use the deployment script with direct token:
```bash
python src/gaia/deployment/deploy_with_token.py --token your_hf_token
```
4. **Configure environment variables in Hugging Face**
- Go to your Space settings
- Add all required environment variables from your `.env` file
- For secure variables like API keys, use the "Secret" option
5. **Verify deployment**
- Visit your Hugging Face Space URL
- Run the validation script in the space
- Test basic functionality
### Hugging Face-Specific Configuration
The Hugging Face deployment uses additional configuration in the README.md file:
```yaml
---
title: GAIA Agent
emoji: 🤖
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: 5.25.2
app_file: app.py
pinned: false
hf_oauth: true
hf_oauth_expiration_minutes: 480
---
```
## Custom Server Deployment
For deploying GAIA on your own server:
### Gunicorn Deployment (Linux/macOS)
1. **Install Gunicorn**
```bash
pip install gunicorn
```
2. **Create a systemd service file** (for Linux)
```
[Unit]
Description=GAIA Agent
After=network.target
[Service]
User=yourusername
WorkingDirectory=/path/to/gaia
Environment="PATH=/path/to/gaia/venv/bin"
EnvironmentFile=/path/to/gaia/.env
ExecStart=/path/to/gaia/venv/bin/gunicorn -w 4 -b 0.0.0.0:8000 app:app
[Install]
WantedBy=multi-user.target
```
3. **Start the service**
```bash
sudo systemctl start gaia
sudo systemctl enable gaia
```
### Windows Deployment (with waitress)
1. **Install waitress**
```bash
pip install waitress
```
2. **Create a startup script**
```python
# serve.py
from waitress import serve
import app
serve(app.app, host='0.0.0.0', port=8000, threads=4)
```
3. **Run the server**
```bash
python serve.py
```
4. **Create a Windows service** (optional)
- Use NSSM (Non-Sucking Service Manager) to create a Windows service
- Configure the service to run `python serve.py` in the correct directory
## API-Only Deployment
For headless API-only deployments:
1. **Install FastAPI and Uvicorn**
```bash
pip install fastapi uvicorn
```
2. **Create an API server file**
```python
# api.py
from fastapi import FastAPI, HTTPException
from src.gaia.agent import GAIAAgent
app = FastAPI(title="GAIA API")
agent = GAIAAgent()
@app.post("/query")
async def process_query(query: str):
try:
response = agent.process(query)
return {"response": response}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
```
3. **Run the API server**
```bash
uvicorn api:app --host 0.0.0.0 --port 8000
```
## Monitoring and Maintenance
### Logging Configuration
Configure logging to monitor GAIA operation:
1. **Set up log rotation**
```python
# In your startup script
import logging
from logging.handlers import RotatingFileHandler
handler = RotatingFileHandler(
'logs/gaia.log',
maxBytes=10*1024*1024, # 10MB
backupCount=5
)
logging.getLogger('gaia').addHandler(handler)
```
2. **Configure log levels based on environment**
```python
if os.environ.get('GAIA_ENVIRONMENT') == 'production':
logging.getLogger('gaia').setLevel(logging.WARNING)
else:
logging.getLogger('gaia').setLevel(logging.DEBUG)
```
### Health Check Endpoint
Add a health check endpoint for monitoring:
```python
@app.get("/health")
async def health_check():
return {
"status": "ok",
"version": "2.0.0",
"environment": os.environ.get('GAIA_ENVIRONMENT', 'unknown')
}
```
### Backup Procedures
For production deployments, implement regular backups:
1. **Supabase data backup**
- Use the Supabase API to export data
- Schedule regular backups using cron or similar tools
2. **Configuration backup**
- Keep versioned backups of your environment files
- Store sensitive credentials in a secure vault
## Troubleshooting
### Common Deployment Issues
1. **Missing environment variables**
- Run `python src/gaia/utils/validate_environment.py` to check for missing variables
- Check for typos in variable names
2. **API key issues**
- Verify API keys by running `python src/gaia/utils/validate_all_credentials.py`
- Check for rate limiting or access restrictions
3. **Memory persistence problems**
- Verify Supabase connection with `python src/gaia/tests/real_world/verify_supabase_data.py`
- Check Supabase table permissions and structure
4. **Performance issues**
- Run `python src/gaia/tests/real_world/performance/test_response_time.py` to check performance
- Consider increasing worker processes for high-load deployments
### Getting Support
If you encounter issues not covered in this guide:
1. Check the [GitHub issues](https://github.com/your-org/gaia/issues) for similar problems
2. Review the logs in `results/logs/` for error messages
3. Run specific component tests to isolate the issue
4. Create a detailed issue report with environment information and steps to reproduce
## Conclusion
This deployment guide covers the most common deployment scenarios for GAIA. By following these procedures, you can deploy GAIA in various environments while maintaining reliability and performance. Always validate your environment and run tests before deploying to production to ensure a smooth operation. |