Spaces:
Sleeping
Sleeping
| # Production Deployment Guide | |
| This guide will help you deploy Agentic Defensor in a production environment. | |
| ## Quick Start | |
| 1. **Using start.sh script:** | |
| ```bash | |
| # Setup permissions | |
| chmod +x start.sh | |
| # Start API server | |
| ./start.sh api | |
| # Or run interactive mode | |
| ./start.sh interactive | |
| # Or run a specific query | |
| ./start.sh agent "Your query here" | |
| ``` | |
| 2. **Using Makefile:** | |
| ```bash | |
| # Install dependencies | |
| make setup | |
| # Start API server | |
| make run | |
| # Or run with agent | |
| make run-agent QUERY="Your query here" | |
| ``` | |
| 3. **Using Docker:** | |
| ```bash | |
| # Build and run | |
| make build-docker | |
| make run-docker | |
| # Or directly with docker-compose | |
| docker-compose up -d | |
| ``` | |
| ## Deployment Options | |
| ### 1. Local Deployment | |
| For local deployment, simply use the provided start.sh script: | |
| ```bash | |
| ./start.sh api | |
| ``` | |
| ### 2. Docker Deployment | |
| For containerized deployment: | |
| ```bash | |
| # Build and run | |
| docker-compose up -d | |
| ``` | |
| Environment variables can be set in a `.env` file or passed directly to docker-compose: | |
| ```bash | |
| OPENAI_API_KEY=your_key docker-compose up -d | |
| ``` | |
| ### 3. Server Deployment | |
| #### Prerequisites | |
| - Python 3.8+ | |
| - pip | |
| - Git | |
| - Make (optional) | |
| #### Steps | |
| 1. Clone the repository: | |
| ```bash | |
| git clone https://github.com/yourusername/agentic-defensor.git | |
| cd agentic-defensor | |
| ``` | |
| 2. Set up environment: | |
| ```bash | |
| python -m venv venv | |
| source venv/bin/activate | |
| pip install -r requirements.txt | |
| ``` | |
| 3. Configure environment variables: | |
| ```bash | |
| echo "OPENAI_API_KEY=your_api_key" > .env | |
| ``` | |
| 4. Setup data directories: | |
| ```bash | |
| mkdir -p data embeddings pdfs | |
| # Copy your data files into appropriate directories | |
| ``` | |
| 5. Run with systemd (for Linux servers): | |
| Create a systemd service file at `/etc/systemd/system/agentic-defensor.service`: | |
| ``` | |
| [Unit] | |
| Description=Agentic Defensor API | |
| After=network.target | |
| [Service] | |
| User=your_username | |
| WorkingDirectory=/path/to/agentic-defensor | |
| ExecStart=/path/to/agentic-defensor/start.sh api | |
| Restart=on-failure | |
| RestartSec=5 | |
| Environment=PYTHONUNBUFFERED=1 | |
| [Install] | |
| WantedBy=multi-user.target | |
| ``` | |
| Then enable and start the service: | |
| ```bash | |
| sudo systemctl enable agentic-defensor | |
| sudo systemctl start agentic-defensor | |
| ``` | |
| 6. Use with nginx as reverse proxy: | |
| Install nginx: | |
| ```bash | |
| sudo apt-get install nginx | |
| ``` | |
| Configure nginx site: | |
| ``` | |
| server { | |
| listen 80; | |
| server_name your_domain.com; | |
| location / { | |
| proxy_pass http://localhost:8000; | |
| proxy_set_header Host $host; | |
| proxy_set_header X-Real-IP $remote_addr; | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| proxy_set_header X-Forwarded-Proto $scheme; | |
| } | |
| } | |
| ``` | |
| Save to `/etc/nginx/sites-available/agentic-defensor` then enable it: | |
| ```bash | |
| sudo ln -s /etc/nginx/sites-available/agentic-defensor /etc/nginx/sites-enabled/ | |
| sudo nginx -t | |
| sudo systemctl restart nginx | |
| ``` | |
| ## Monitoring and Logging | |
| For production deployments, consider adding: | |
| 1. Logging to file: | |
| ```bash | |
| ./start.sh api > /var/log/agentic-defensor.log 2>&1 | |
| ``` | |
| 2. Use a process manager like PM2: | |
| ```bash | |
| npm install -g pm2 | |
| pm2 start "python -m uvicorn src.api.app:app --host 0.0.0.0 --port 8000" --name agentic-defensor | |
| ``` | |
| 3. Set up monitoring with Prometheus and Grafana (see documentation for details) | |
| ## Scaling | |
| For scaling the application: | |
| 1. Use multiple instances behind a load balancer | |
| 2. Consider using a proper API gateway | |
| 3. Implement caching for frequent queries | |
| 4. Use a production-ready database for storing query history | |
| ## Security Considerations | |
| 1. Always use HTTPS in production | |
| 2. Implement proper authentication for API access | |
| 3. Regularly update dependencies | |
| 4. Monitor for unusual query patterns | |
| 5. Implement rate limiting | |
| 6. Use API keys for access control | |
| ## Backup and Maintenance | |
| 1. Regularly backup your data directories | |
| 2. Schedule updates during off-peak hours | |
| 3. Implement a rollback strategy for updates | |
| 4. Set up monitoring alerts for system health |