agentic-defensor / run_production.md
vichudo's picture
add first approach
b840b29
|
Raw
History Blame Contribute Delete
3.9 kB

A newer version of the Gradio SDK is available: 6.20.0

Upgrade

Production Deployment Guide

This guide will help you deploy Agentic Defensor in a production environment.

Quick Start

  1. 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"
  1. Using Makefile:
# Install dependencies
make setup

# Start API server
make run

# Or run with agent
make run-agent QUERY="Your query here"
  1. 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

  1. Clone the repository:
git clone https://github.com/yourusername/agentic-defensor.git
cd agentic-defensor
  1. Set up environment:
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
  1. Configure environment variables:
echo "OPENAI_API_KEY=your_api_key" > .env
  1. Setup data directories:
mkdir -p data embeddings pdfs
# Copy your data files into appropriate directories
  1. 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
  1. 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:

  1. Logging to file:
./start.sh api > /var/log/agentic-defensor.log 2>&1
  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
  1. 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