# MCube AI FastAPI + Gunicorn Migration

## What is deployed
- New ASGI app: `fastapi_app.py`
- Gunicorn config: `gunicorn_fastapi_conf.py`
- Startup script: `start_fastapi_gunicorn.sh`
- Systemd unit template: `deploy/systemd/mcube-ai-fastapi.service`
- Continuous ingestion worker: `rag_ingestion_worker.py`
- Worker systemd template: `deploy/systemd/mcube-rag-ingestion-worker.service`

## Key behavior
- FastAPI serves MCube AI endpoints:
  - `GET /health`
  - `GET /rag/agents`
  - `POST /rag/{bid}/documents`
  - `POST /rag/{bid}/ingest-transcripts`
  - `POST /rag/{bid}/query` (supports `agent_type`)
  - `POST /rag/{bid}/score-call`
  - `GET /rag/{bid}/agent-report`
  - `GET /rag/{bid}/ingestion-progress`
  - `GET /rag/{bid}/conversations/{conversation_id}`
  - `GET /rag/{bid}/profiles/{user_id}`
- FastAPI is the only backend runtime path for API serving.
- Redis is not required for call-sync caching; sync cache is stored in MySQL.

## Multi-agent routing
Supported values in `agent_type`:
- `quality_agent`
- `customer_analysis_agent`
- `agent_analysis_agent`
- `support_agent`
- `general`

## Start command
```bash
cd /home/aiteam/pcaa-dev/dashboard-backend
chmod +x start_fastapi_gunicorn.sh
./start_fastapi_gunicorn.sh
```

## Systemd setup
```bash
sudo cp deploy/systemd/mcube-ai-fastapi.service /etc/systemd/system/
sudo cp deploy/systemd/mcube-rag-ingestion-worker.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable mcube-ai-fastapi
sudo systemctl restart mcube-ai-fastapi
sudo systemctl enable mcube-rag-ingestion-worker
sudo systemctl restart mcube-rag-ingestion-worker
sudo systemctl status mcube-ai-fastapi
sudo systemctl status mcube-rag-ingestion-worker
```
