Files
Guido.Tech/ai_intelligence_layer/FAST_MODE.md
2025-10-18 23:56:53 -05:00

208 lines
4.9 KiB
Markdown

# ⚡ SIMPLIFIED & FAST AI Layer
## What Changed
Simplified the entire AI flow for **ultra-fast testing and development**:
### Before (Slow)
- Generate 20 strategies (~45-60 seconds)
- Analyze all 20 and select top 3 (~40-60 seconds)
- **Total: ~2 minutes per request** ❌
### After (Fast)
- Generate **1 strategy** (~5-10 seconds)
- **Skip analysis** completely
- **Total: ~10 seconds per request** ✅
## Configuration
### Current Settings (`.env`)
```bash
FAST_MODE=true
STRATEGY_COUNT=1 # ⚡ Set to 1 for testing, 20 for production
```
### How to Adjust
**For ultra-fast testing (current):**
```bash
STRATEGY_COUNT=1
```
**For demo/showcase:**
```bash
STRATEGY_COUNT=5
```
**For production:**
```bash
STRATEGY_COUNT=20
```
## Simplified Workflow
```
┌──────────────────┐
│ Enrichment │
│ Service POSTs │
│ telemetry │
└────────┬─────────┘
┌──────────────────┐
│ Webhook Buffer │
│ (stores data) │
└────────┬─────────┘
┌──────────────────┐
│ Brainstorm │ ⚡ 1 strategy only!
│ (Gemini API) │ ~10 seconds
└────────┬─────────┘
┌──────────────────┐
│ Return Strategy │
│ No analysis! │
└──────────────────┘
```
## Quick Test
### 1. Push telemetry via webhook
```bash
python3 test_webhook_push.py --loop 5
```
### 2. Generate strategy (fast!)
```bash
python3 test_buffer_usage.py
```
**Output:**
```
Testing FAST brainstorm with buffered telemetry...
(Configured for 1 strategy only - ultra fast!)
✓ Brainstorm succeeded!
Generated 1 strategy
Strategy:
1. Medium-to-Hard Standard (1-stop)
Tires: medium → hard
Optimal 1-stop at lap 32 when tire degradation reaches cliff
✓ SUCCESS: AI layer is using webhook buffer!
```
**Time: ~10 seconds** instead of 2 minutes!
## API Response Format
### Brainstorm Response (Simplified)
```json
{
"strategies": [
{
"strategy_id": 1,
"strategy_name": "Medium-to-Hard Standard",
"stop_count": 1,
"pit_laps": [32],
"tire_sequence": ["medium", "hard"],
"brief_description": "Optimal 1-stop at lap 32 when tire degradation reaches cliff",
"risk_level": "medium",
"key_assumption": "No safety car interventions"
}
]
}
```
**No analysis object!** Just the strategy/strategies.
## What Was Removed
**Analysis endpoint** - Skipped entirely for speed
**Top 3 selection** - Only 1 strategy generated
**Detailed rationale** - Simple description only
**Risk assessment details** - Basic risk level only
**Engineer briefs** - Not generated
**Radio scripts** - Not generated
**ECU commands** - Not generated
## What Remains
**Webhook push** - Still works perfectly
**Buffer storage** - Still stores telemetry
**Strategy generation** - Just faster (1 instead of 20)
**F1 rule validation** - Still validates tire compounds
**Telemetry analysis** - Still calculates tire cliff, degradation
## Re-enabling Full Mode
When you need the complete system (for demos/production):
### 1. Update `.env`
```bash
STRATEGY_COUNT=20
```
### 2. Restart service
```bash
# Service will auto-reload if running with uvicorn --reload
# Or manually restart:
python main.py
```
### 3. Use analysis endpoint
```bash
# After brainstorm, call analyze with the 20 strategies
POST /api/strategy/analyze
{
"race_context": {...},
"strategies": [...], # 20 strategies from brainstorm
"enriched_telemetry": [...] # optional
}
```
## Performance Comparison
| Mode | Strategies | Time | Use Case |
|------|-----------|------|----------|
| **Ultra Fast** | 1 | ~10s | Testing, development |
| **Fast** | 5 | ~20s | Quick demos |
| **Standard** | 10 | ~35s | Demos with variety |
| **Full** | 20 | ~60s | Production, full analysis |
## Benefits of Simplified Flow
**Faster iteration** - Test webhook integration quickly
**Lower API costs** - Fewer Gemini API calls
**Easier debugging** - Simpler responses to inspect
**Better dev experience** - No waiting 2 minutes per test
**Still validates** - All core logic still works
## Migration Path
### Phase 1: Testing (Now)
- Use `STRATEGY_COUNT=1`
- Test webhook integration
- Verify telemetry flow
- Debug any issues
### Phase 2: Demo
- Set `STRATEGY_COUNT=5`
- Show variety of strategies
- Still fast enough for live demos
### Phase 3: Production
- Set `STRATEGY_COUNT=20`
- Enable analysis endpoint
- Full feature set
---
**Current Status:** ⚡ Ultra-fast mode enabled!
**Response Time:** ~10 seconds (was ~2 minutes)
**Ready for:** Rapid testing and webhook integration validation