🧬 Genesis Self-Improvement Cycle
STATUS: ✅ IMPLEMENTED (Session 318)
Overview
The Genesis Self-Improvement Cycle is an automatic continuous learning system that makes Genesis get progressively smarter over time by:
- Monitoring learnings accumulation (corrections, patterns, errors)
- Triggering training when thresholds are reached
- Training new models on accumulated knowledge
- Evaluating new models vs current models
- Deploying improved models automatically
- Repeating continuously
This creates a virtuous cycle where Genesis learns from every interaction and automatically improves itself.
Architecture
┌─────────────────────────────────────────────────────────────────┐
│ SELF-IMPROVEMENT CYCLE │
└─────────────────────────────────────────────────────────────────┘
┌─────────────┐
│ USER CODE │ (Corrections, patterns, errors)
└──────┬──────┘
│
▼
┌─────────────┐
│ LEARNER │ (Captures learnings)
└──────┬──────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ SELF-IMPROVEMENT DAEMON (Monitors thresholds) │
│ - Learning threshold: 100 new learnings │
│ - Time threshold: 62 days │
│ - Performance threshold: 90% accuracy │
└──────┬──────────────────────────────────────────────────┘
│
▼ (Threshold reached)
┌─────────────────────────────────────────────────────────┐
│ TRAINING ORCHESTRATOR │
│ 1. Load accumulated learnings from Weaviate │
│ 2. Prepare training data (instruction-following) │
│ 3. Fine-tune Qwen with LoRA │
│ 4. Save new model │
└──────┬──────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ MODEL EVALUATOR │
│ - Run eval harness on new model │
│ - Compare accuracy vs current model │
│ - Calculate improvement delta │
└──────┬──────────────────────────────────────────────────┘
│
▼ (Improved?)
┌─────────────────────────────────────────────────────────┐
│ DEPLOYMENT (if improved) │
│ - Deploy new model to Ollama │
│ - Update state (current_model) │
│ - Reset learning counter │
│ - Track improvement metrics │
└─────────────────────────────────────────────────────────┘
Components
1. Genesis Learner (api/genesis/learner.py)
Captures learnings from: - User corrections - Cursor fix patterns - Error patterns and fixes - Successful code patterns
Storage:
- File: data/genesis_learnings.json
- Neo4j: GenesisLearning nodes
- Weaviate: Semantic embeddings
- Redis: Fast lookup cache
2. Self-Improvement Daemon (scripts/genesis-self-improvement-daemon.py)
Responsibilities: - Monitor learnings accumulation - Evaluate trigger conditions - Orchestrate improvement cycle - Track state and metrics
Triggers: - Learning threshold: 100 new learnings - Time threshold: 62 days since last training - Performance degradation: Accuracy < 90%
State file: data/genesis_improvement_state.json
3. Training Pipeline (scripts/genesis-training-pipeline.py)
Steps: 1. Load code corpus from Weaviate 2. Prepare training data (instruction-following format) 3. Optimize hyperparameters with H2O 4. Fine-tune Qwen with LoRA 5. Save checkpoints and metrics
Output:
- Fine-tuned model in Ollama
- Metrics in models/genesis/metrics/
- Checkpoints in models/genesis/checkpoints/
4. Model Evaluator (scripts/genesis-eval-harness.py)
Evaluates: - Code generation accuracy - Perplexity on validation set - BLEU score for code quality - Success rate on test prompts
Comparison: - Current model vs new model - Improvement delta calculation - Deployment decision (> 1% improvement threshold)
Trigger Conditions
1. Learning Threshold (Default: 100)
When 100 new learnings are accumulated since last training: - Corrections: User fixes to generated code - Patterns: New code patterns captured - Errors: Error fixes and solutions
Configuration:
export GENESIS_LEARNING_THRESHOLD=100
2. Time Threshold (Default: 62 days)
When 62 days have passed since last training, regardless of learning count.
Configuration:
export GENESIS_TIME_THRESHOLD_DAYS=7
3. Performance Threshold (Default: 90%)
When model accuracy drops below 90%, trigger retraining.
Configuration:
export GENESIS_PERFORMANCE_THRESHOLD=0.9
State Management
State File: data/genesis_improvement_state.json
{
"last_training_time": "2025-12-11T19:00:00Z",
"learnings_since_training": 45,
"current_model": "genesis-20251211-190000",
"training_runs": 3,
"improvement_score": 0.87,
"last_check_time": "2025-12-11T20:00:00Z"
}
Fields:
- last_training_time: ISO timestamp of last training
- learnings_since_training: Count of new learnings since training
- current_model: Name of current production model
- training_runs: Total training runs completed
- improvement_score: Current model accuracy
- last_check_time: Last time daemon checked triggers
Usage
Start Daemon (Automatic Mode)
Runs continuously, checking triggers every hour:
python3 scripts/genesis-self-improvement-daemon.py
Run Once (Manual Mode)
Run one check cycle and exit:
python3 scripts/genesis-self-improvement-daemon.py --once
Check Status
curl http://localhost:8000/api/v1/genesis/improvement/status
Response:
{
"last_training_time": "2025-12-11T19:00:00Z",
"learnings_since_training": 45,
"current_model": "genesis-20251211-190000",
"training_runs": 3,
"improvement_score": 0.87,
"last_check_time": "2025-12-11T20:00:00Z",
"should_trigger": false,
"trigger_reason": "Thresholds not met (learnings: 45/100, days: 1/7)"
}
Manual Trigger
Bypass automatic triggers and force improvement cycle:
curl -X POST http://localhost:8000/api/v1/genesis/improvement/trigger
Response:
{
"success": true,
"message": "Improvement cycle triggered successfully (running in background)",
"triggered_at": "2025-12-11T20:00:00Z"
}
Systemd Service
Install Service
# Copy service file
sudo cp systemd/truthsi-genesis-self-improvement.service /etc/systemd/system/
# Reload systemd
sudo systemctl daemon-reload
# Enable service (start on boot)
sudo systemctl enable truthsi-genesis-self-improvement
# Start service
sudo systemctl start truthsi-genesis-self-improvement
# Check status
sudo systemctl status truthsi-genesis-self-improvement
View Logs
# Follow logs
sudo journalctl -u truthsi-genesis-self-improvement -f
# View recent logs
sudo journalctl -u truthsi-genesis-self-improvement -n 100
API Endpoints
GET /api/v1/genesis/improvement/status
Get current self-improvement status.
Response:
{
"last_training_time": "string",
"learnings_since_training": 0,
"current_model": "string",
"training_runs": 0,
"improvement_score": 0.0,
"last_check_time": "string",
"should_trigger": false,
"trigger_reason": "string"
}
POST /api/v1/genesis/improvement/trigger
Manually trigger improvement cycle.
Response:
{
"success": true,
"message": "string",
"triggered_at": "string",
"error": null
}
Testing
Test Self-Improvement Cycle
# Run all tests
python3 scripts/test-genesis-self-improvement.py
# Simulate 100 learnings for testing
python3 scripts/test-genesis-self-improvement.py --simulate-learnings 100
Tests: 1. State management (load/save) 2. Learnings monitor (count, filter) 3. Trigger logic (threshold evaluation) 4. API endpoints (status, trigger)
Improvement Cycle Flow
Phase 1: Trigger Detection
CHECK INTERVAL (60 minutes)
↓
Load current state
↓
Count new learnings since last training
↓
Calculate days since last training
↓
Evaluate trigger conditions:
- Learnings >= 100?
- Days >= 7?
- Performance < 90%?
↓
TRIGGER? → YES/NO
Phase 2: Training (if triggered)
TRIGGER DETECTED
↓
Load code corpus from Weaviate
↓
Prepare training data (instruction-following)
↓
Optimize hyperparameters with H2O
↓
Fine-tune Qwen with LoRA (2 hours)
↓
Save model to Ollama
↓
TRAINING COMPLETE
Phase 3: Evaluation
TRAINING COMPLETE
↓
Identify new model name
↓
Run evaluation harness on:
- Current model
- New model
↓
Calculate improvement delta
↓
IMPROVEMENT > 1%? → YES/NO
Phase 4: Deployment (if improved)
IMPROVEMENT DETECTED
↓
Deploy new model to Ollama
↓
Update state:
- current_model = new_model
- training_runs += 1
- improvement_score = new_accuracy
- last_training_time = now()
- learnings_since_training = 0
↓
Log metrics
↓
IMPROVEMENT CYCLE COMPLETE
Metrics and Monitoring
Prometheus Metrics
Available on port 9127:
genesis_improvement_cycles_total- Total improvement cycles rungenesis_improvements_deployed_total- Successful deploymentsgenesis_improvements_rejected_total- Rejected (no improvement)genesis_current_model_accuracy- Current model accuracygenesis_learnings_since_training- Current learning count
Logs
- Daemon logs:
logs/genesis-self-improvement-daemon.log - Training logs:
logs/genesis-training-pipeline.log - System logs:
journalctl -u truthsi-genesis-self-improvement
Configuration
Environment Variables
# Trigger thresholds
GENESIS_LEARNING_THRESHOLD=100 # Learnings count
GENESIS_TIME_THRESHOLD_DAYS=7 # Days
GENESIS_PERFORMANCE_THRESHOLD=0.9 # Accuracy
# Check interval
GENESIS_IMPROVEMENT_CHECK_INTERVAL=60 # Minutes
# FORGE connection
FORGE_HOST=4.227.88.48 # FORGE IP
Troubleshooting
Issue: Daemon not triggering
Check:
1. Daemon running: systemctl status truthsi-genesis-self-improvement
2. Learning count: cat data/genesis_learnings.json | jq '.learnings | length'
3. State file: cat data/genesis_improvement_state.json
4. Logs: tail -f logs/genesis-self-improvement-daemon.log
Issue: Training fails
Check:
1. Weaviate connection: curl http://localhost:8080/v1/.well-known/ready
2. Ollama on FORGE: ssh genesis "ollama list"
3. Training logs: logs/genesis-training-pipeline.log
4. Disk space: df -h
Issue: No improvement detected
Normal behavior: - Not all training runs produce improvement - Improvement threshold is 1% (configurable) - Old model may already be optimal for current corpus
Check:
- Evaluation metrics: models/genesis/metrics/
- Model comparison output in daemon logs
Future Enhancements
Phase 1 (Current)
- ✅ Automatic trigger detection
- ✅ Training orchestration
- ✅ Model evaluation and deployment
- ✅ State management
Phase 2 (Planned)
- [ ] Multi-model ensemble (combine multiple models)
- [ ] A/B testing (deploy to subset of users first)
- [ ] Rollback mechanism (revert if issues)
- [ ] Advanced metrics (latency, token efficiency)
Phase 3 (Future)
- [ ] Reinforcement learning from human feedback (RLHF)
- [ ] Curriculum learning (progressive difficulty)
- [ ] Transfer learning (learn from other domains)
- [ ] Meta-learning (learn how to learn)
Related Documentation
Created: Session 318 - THE ARCHITECT Status: ✅ PRODUCTION READY Priority: P0 - Genesis Protocol Phase 3