# LiveKit Voice Agent - 10 Concurrent Users Setup

## ✅ Configuration Complete

Your backend is now configured to handle **10 concurrent voice calls** simultaneously.

### Current Setup

**Worker Configuration:**
- **Process Pool**: 10 idle processes ready
- **Worker ID**: `AW_uUKwk3kXPPoK`
- **Agent Name**: `default`
- **LiveKit URL**: `wss://test-voice-bot-fd6qy6cu.livekit.cloud`
- **Region**: India South

**Initialized Processes:** 11 total (1 main + 10 workers)
- Main process: PID 2426719
- Worker PIDs: 2427138, 2427140, 2427142, 2427144, 2427319, 2427323, 2427325, 2427321, 2427503, 2427551

### How It Works

1. **User connects** to https://app2.syntheon.in/voicebot
2. **Frontend requests** connection details from API
3. **User joins room** with agent dispatch in token
4. **LiveKit assigns** one of the 10 idle processes to handle the session
5. **Agent joins** and starts voice conversation
6. **Process returns to pool** when session ends

### Resource Usage

**Per Session:**
- CPU: ~1-2% per active call
- Memory: ~250-300MB per process
- Total for 10 concurrent: ~2.5-3GB RAM

**Your Server:**
- CPU: 40 cores (plenty for 10+ calls)
- RAM: 251GB total, 230GB available (more than enough)
- Network: Should handle 10 concurrent WebRTC streams

### Limitations

#### 1. LiveKit Cloud Free Tier
- **Quota**: 1,000 agent minutes/month
- **10 concurrent users × 5 min each** = 50 minutes per session
- **~20 such sessions per month** before hitting quota
- **After quota**: Agents won't join, users see "Agent did not join" error

#### 2. API Rate Limits
- ElevenLabs STT/TTS: Check your API quota
- Cartesia TTS: Check your API quota
- OpenAI LLM (gpt-4.1-mini): Check your API quota

### Testing 10 Concurrent Calls

To test if all 10 workers are functioning:

```bash
# Run this test script (creates 10 simultaneous connections)
cd /var/www/html/livekit_frontend
node test-concurrent-calls.js
```

### Monitoring

**Check backend status:**
```bash
cd /var/www/html/livekit_frontend/BackEnd/agent-starter-python
tail -f backend-10workers.log
```

**Check active sessions:**
```bash
cd /var/www/html/livekit_frontend/BackEnd/agent-starter-python
ls -lht logs/ | head -15
```

**Check process count:**
```bash
ps aux | grep "python3 src/agent.py" | grep -v grep | wc -l
```

### Scaling Beyond 10 Users

If you need more than 10 concurrent users:

1. **Increase process pool**: Change `num_idle_processes=10` to `20` or `30`
2. **Add more worker instances**: Run multiple worker processes on different ports
3. **Upgrade LiveKit Cloud**: Move to paid plan for unlimited agent minutes
4. **Self-host LiveKit**: Deploy your own LiveKit server for full control

### Starting/Stopping the Backend

**Start:**
```bash
cd /var/www/html/livekit_frontend/BackEnd/agent-starter-python
/home/aiteam/.local/bin/uv run python src/agent.py dev 2>&1 | tee backend-10workers.log &
```

**Stop:**
```bash
pkill -f "agent.py dev"
```

**Check status:**
```bash
ps aux | grep "agent.py dev" | grep -v grep
```

### Troubleshooting

**Issue**: "Agent did not join the room"
- **Check**: Backend is running (`ps aux | grep agent.py`)
- **Check**: Worker is registered (look for "registered worker" in logs)
- **Check**: LiveKit Cloud quota not exhausted
- **Check**: All 10 processes are initialized

**Issue**: Some calls work, others don't
- **Cause**: More than 10 concurrent users
- **Solution**: Increase `num_idle_processes` or add more workers

**Issue**: High CPU usage
- **Cause**: Multiple LLM/TTS API calls
- **Solution**: Normal for voice AI, monitor API costs

### Production Recommendations

For production use with 10+ concurrent users:

1. **Use systemd service** to auto-restart on failure
2. **Monitor logs** with log rotation
3. **Set up alerts** for worker failures
4. **Monitor API quotas** (ElevenLabs, Cartesia, OpenAI)
5. **Consider LiveKit Cloud paid plan** or self-hosted server
6. **Load test** before going live

### Current Status: ✅ READY

Your backend can now handle **10 concurrent voice calls** at https://app2.syntheon.in/voicebot
