Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available: 6.20.0
Production Deployment Guide
This guide will help you deploy Agentic Defensor in a production environment.
Quick Start
- Using start.sh script:
# 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"
- Using Makefile:
# Install dependencies
make setup
# Start API server
make run
# Or run with agent
make run-agent QUERY="Your query here"
- Using Docker:
# 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:
./start.sh api
2. Docker Deployment
For containerized deployment:
# Build and run
docker-compose up -d
Environment variables can be set in a .env file or passed directly to docker-compose:
OPENAI_API_KEY=your_key docker-compose up -d
3. Server Deployment
Prerequisites
- Python 3.8+
- pip
- Git
- Make (optional)
Steps
- Clone the repository:
git clone https://github.com/yourusername/agentic-defensor.git
cd agentic-defensor
- Set up environment:
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
- Configure environment variables:
echo "OPENAI_API_KEY=your_api_key" > .env
- Setup data directories:
mkdir -p data embeddings pdfs
# Copy your data files into appropriate directories
- 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:
sudo systemctl enable agentic-defensor
sudo systemctl start agentic-defensor
- Use with nginx as reverse proxy:
Install nginx:
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:
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:
- Logging to file:
./start.sh api > /var/log/agentic-defensor.log 2>&1
- Use a process manager like PM2:
npm install -g pm2
pm2 start "python -m uvicorn src.api.app:app --host 0.0.0.0 --port 8000" --name agentic-defensor
- Set up monitoring with Prometheus and Grafana (see documentation for details)
Scaling
For scaling the application:
- Use multiple instances behind a load balancer
- Consider using a proper API gateway
- Implement caching for frequent queries
- Use a production-ready database for storing query history
Security Considerations
- Always use HTTPS in production
- Implement proper authentication for API access
- Regularly update dependencies
- Monitor for unusual query patterns
- Implement rate limiting
- Use API keys for access control
Backup and Maintenance
- Regularly backup your data directories
- Schedule updates during off-peak hours
- Implement a rollback strategy for updates
- Set up monitoring alerts for system health