# ๐ Setup Complete - Redis + Auto-Reload
## โ
What's Been Fixed
### 1. **Conversation Memory Issue** โ
- **Problem:** AI couldn't remember previous messages
- **Cause:** Redis not running, in-memory store recreated each request
- **Solution:** Install and run Redis
### 2. **Auto-Reload for Development** โ
- **Problem:** Had to restart server after every code change
- **Solution:** Enable `WEB_CHAT_RELOAD=true` in `.env`
---
## ๐ Quick Setup (5 Minutes)
### Option 1: Automated Setup (Recommended)
```bash
# Run the setup script
./setup_redis.sh
```
This will:
- โ
Install Redis (if not installed)
- โ
Start Redis as background service
- โ
Update `.env` with correct settings
- โ
Enable auto-reload
### Option 2: Manual Setup
```bash
# 1. Install Redis
brew install redis
# 2. Start Redis
brew services start redis
# 3. Verify
redis-cli ping # Should return: PONG
# 4. Update .env
nano .env
```
Add/update these lines in `.env`:
```bash
REDIS_ENABLED=true
REDIS_URL=redis://localhost:6379/0
WEB_CHAT_RELOAD=true
```
---
## ๐งช Test Everything
### 1. Restart Servers
**Terminal 1:**
```bash
source .venv/bin/activate
python -m src.mcp_server.server
```
**Terminal 2:**
```bash
source .venv/bin/activate
python -m src.web_chat.main
```
**Look for this log in Terminal 2:**
```json
{"backend": "redis", "event": "conversation_store_initialized", ...}
```
### 2. Test Conversation Memory
```bash
# Replace with your token
TOKEN="11836|UAc9YiEKc9zO9MvNHKQqY9WwdkxW7qQyw3mqyNK5"
# First message
curl -X POST http://localhost:8002/chat \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"message": "My name is Sarah"}'
# Second message
curl -X POST http://localhost:8002/chat \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"message": "What is my name?"}'
```
**Expected response:**
```json
{
"success": true,
"response": "Your name is Sarah.",
...
}
```
**If it remembers, Redis is working!** โ
### 3. Test Auto-Reload
1. **Keep Terminal 2 running**
2. **Edit any file** in `src/web_chat/`
3. **Watch Terminal 2** - it should auto-restart!
**Look for:**
```
Detected file change, reloading...
```
---
## ๐ Monitor Redis
### View Stored Conversations
```bash
# List all conversation keys
redis-cli keys "conversation:*"
# View a specific conversation
redis-cli GET "conversation:860:141" | python3 -m json.tool
```
### Watch Redis in Real-Time
```bash
redis-cli monitor
```
Then send a chat message and watch Redis store it!
### Check Memory Usage
```bash
redis-cli info memory | grep used_memory_human
```
---
## ๐ฏ What You Get Now
### โ
Conversation Memory
```
You: "My favorite color is blue"
AI: "Got it, your favorite color is blue!"
You: "What's my favorite color?"
AI: "Your favorite color is blue." โ Remembers! โ
```
### โ
Auto-Reload (Terminal 2 only)
```
Edit code โ Save โ Server auto-restarts โ
No need to Ctrl+C and restart manually!
```
**Note:** Terminal 1 (MCP Server) doesn't auto-reload. Only Terminal 2 (Web Chat).
---
## ๐ง Configuration Details
### Redis Settings (`.env`)
```bash
# Enable Redis
REDIS_ENABLED=true
# Redis connection URL
REDIS_URL=redis://localhost:6379/0
# Conversation TTL (24 hours)
REDIS_TTL_CONVERSATIONS=86400
# Cache TTL (15 minutes)
REDIS_TTL_CACHE=900
```
### Auto-Reload Setting (`.env`)
```bash
# Enable auto-reload for Web Chat API
WEB_CHAT_RELOAD=true
```
**When to use:**
- โ
Development: `true` (auto-restart on changes)
- โ Production: `false` (manual control)
---
## ๐ Troubleshooting
### Issue 1: "Connection refused"
**Symptom:**
```
Error 61 connecting to localhost:6379. Connection refused.
```
**Fix:**
```bash
# Check if Redis is running
brew services list | grep redis
# Start Redis
brew services start redis
# Verify
redis-cli ping
```
### Issue 2: Conversations still not saving
**Check:**
```bash
# 1. Is Redis running?
redis-cli ping
# 2. Is REDIS_ENABLED=true in .env?
grep REDIS_ENABLED .env
# 3. Check logs in Terminal 2
# Should see: "backend": "redis"
# NOT: "backend": "memory"
```
### Issue 3: Auto-reload not working
**Check:**
```bash
# 1. Is WEB_CHAT_RELOAD=true in .env?
grep WEB_CHAT_RELOAD .env
# 2. Did you restart Terminal 2 after changing .env?
# Ctrl+C and restart
# 3. Are you editing files in src/web_chat/?
# Only those trigger reload
```
---
## ๐ Documentation
### Quick Reference
- **`REDIS_SETUP.md`** - Complete Redis guide
- **`BEARER_TOKEN_AUTH.md`** - API documentation
- **`README.md`** - Quick start guide
- **`POSTMAN_GUIDE.md`** - Postman setup
### Test Scripts
- **`setup_redis.sh`** - Automated Redis setup
- **`test_simple.sh`** - Quick API test
- **`test_bearer_auth.sh`** - Full auth test suite
- **`stop_servers.sh`** - Stop all servers
---
## โ
Checklist
Before you start developing:
- [ ] Redis installed: `brew install redis`
- [ ] Redis running: `redis-cli ping` โ `PONG`
- [ ] `.env` updated: `REDIS_ENABLED=true`
- [ ] `.env` updated: `WEB_CHAT_RELOAD=true`
- [ ] Servers restarted
- [ ] Conversation memory tested โ
- [ ] Auto-reload tested โ
---
## ๐ Learning Redis
Since you're new to Redis, here's a quick intro:
### What is Redis?
- **In-memory database** (super fast!)
- **Key-value store** (like Python dict)
- **Persistent** (survives restarts)
- **Used by:** Twitter, GitHub, Stack Overflow, etc.
### Why Use It?
- โ
**Fast:** All data in RAM
- โ
**Simple:** Easy to learn
- โ
**Reliable:** Battle-tested
- โ
**Scalable:** Handles millions of ops/sec
### Basic Commands
```bash
# Store a value
redis-cli SET mykey "Hello"
# Get a value
redis-cli GET mykey
# Delete a key
redis-cli DEL mykey
# List all keys
redis-cli KEYS "*"
# Check if key exists
redis-cli EXISTS mykey
```
### How MCP Uses Redis
```
Key: conversation:860:141
Value: [
{"role": "user", "content": "Hello"},
{"role": "assistant", "content": "Hi!"}
]
TTL: 24 hours
```
---
## ๐ Next Steps
### Now
1. โ
Test conversation memory
2. โ
Test auto-reload
3. โ
Start building your tools!
### Later (Optional)
- Install RedisInsight (GUI for Redis)
- Learn Redis data structures
- Set up Redis monitoring
- Configure Redis persistence
---
## ๐ก Pro Tips
### 1. Monitor Redis While Developing
```bash
# Terminal 3
redis-cli monitor
```
Watch your conversations being stored in real-time!
### 2. Clear Conversations for Testing
```bash
# Clear all conversations
redis-cli --scan --pattern "conversation:*" | xargs redis-cli DEL
# Or clear everything
redis-cli FLUSHALL
```
### 3. Check What's Stored
```bash
# List all keys
redis-cli keys "*"
# Count conversations
redis-cli keys "conversation:*" | wc -l
```
### 4. Auto-Reload Best Practices
- โ
Use for `src/web_chat/` changes
- โ
Use for `src/orchestrator/` changes
- โ Don't use for `src/mcp_server/` (restart manually)
- โ Disable in production
---
## ๐ You're All Set!
**Redis:** โ
Installed and running
**Conversation Memory:** โ
Working
**Auto-Reload:** โ
Enabled
**Documentation:** โ
Complete
**Start building amazing tools!** ๐
---
## ๐ Need Help?
If you run into issues:
1. Check logs in Terminal 2
2. Run `redis-cli ping`
3. Check `.env` settings
4. Read `REDIS_SETUP.md`
5. Ask for help!
**Common issues are documented in `REDIS_SETUP.md`**