Real Time Learning
Comprehensive guidelines for AI-assisted development within the Editor platform
🔥 Real-Time AI Learning System
Overview
The AI Learning System has been upgraded to be truly intelligent with real-time MongoDB synchronization. Everything auto-records to MongoDB - no manual recording needed!
Architecture
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ MCP Agent │────>│ backend-ai-api │────>│ MongoDB │
│ (Cursor IDE) │ │ │ │ │
└─────────────────┘ └────────┬────────┘ └────────┬────────┘
│ │
│ WebSocket │ Change Streams
│ │
┌────────▼────────┐ ┌────────▼────────┐
│ Command Center │<────│ AIChangeStream │
│ (Angular UI) │ │ Service │
└─────────────────┘ └─────────────────┘
MongoDB Collections
| Collection | Database | Purpose |
|---|---|---|
decisions |
ai-agents | All agent decisions (9,968+) |
golden_decisions |
ai-agents | Curated best decisions (200+) |
agent_routed_knowledge |
ai-agents | Per-agent specialized learning |
agent_embeddings |
ai-memory | Vector embeddings for semantic search |
Key Services
1. AIChangeStreamService
Watches MongoDB collections in real-time and broadcasts changes via WebSocket.
// Location: apis/backend-ai-api/src/app/command-center/ai-change-stream.service.ts
// Watches:
- ai-agents/decisions → decision.changed event
- ai-agents/golden_decisions → golden.changed event
- ai-memory/agent_embeddings → embedding.changed event
2. LearningRouterService (MongoDB Persistent)
Routes decisions to specialized agents and persists to MongoDB.
// Location: apis/backend-ai-api/src/app/command-center/learning-router.service.ts
// Now persists to: ai-agents/agent_routed_knowledge
// Survives backend restarts!
3. GoldenDecisionService
Manages curated golden decisions with manual curation support.
// Location: apis/backend-ai-api/src/app/infrastructure/services/golden-decision.service.ts
// Operations:
- create() → Promote a decision
- delete() → Demote from golden
- findAll() → List golden decisions
Decision Management API
All endpoints at: /ai-api/command-center/
Decisions
| Method | Endpoint | Description |
|---|---|---|
| GET | /decisions |
List all decisions (paginated) |
| GET | /decisions/:id |
Get single decision |
| PATCH | /decisions/:id |
Edit decision |
| DELETE | /decisions/:id |
Delete decision |
| POST | /decisions/:id/promote |
Promote to golden |
Golden Decisions
| Method | Endpoint | Description |
|---|---|---|
| GET | /golden-decisions |
List golden decisions |
| DELETE | /golden-decisions/:id |
Demote (remove from golden) |
Statistics
| Method | Endpoint | Description |
|---|---|---|
| GET | /stats/comprehensive |
Total decisions, golden, embeddings, agent knowledge |
Real-Time Events (WebSocket)
The Command Center receives these events in real-time:
// New decision created
socket.on('decision.changed', { type: 'insert', decision, timestamp })
// Decision deleted
socket.on('decision.changed', { type: 'delete', decisionId, timestamp })
// Golden decision promoted
socket.on('golden.changed', { type: 'insert', decision, originalDecisionId })
// Golden decision demoted
socket.on('golden.changed', { type: 'delete', decisionId })
// New embedding created
socket.on('embedding.changed', { type: 'insert', embeddingId, question })
// Learning stats update
socket.on('learning.stats', { totalDecisions, goldenDecisions, embeddings })
How It Works
1. Decision Created (MCP → MongoDB → UI)
1. MCP calls log_decision({ question, chosen, reasoning })
2. DecisionService.create() saves to MongoDB
3. AIChangeStreamService detects insert via Change Stream
4. CommandCenterGateway broadcasts to WebSocket
5. Angular Command Center updates live feed
2. Decision Demoted (UI → MongoDB → All Clients)
1. User clicks "Demote" in UI
2. API call DELETE /golden-decisions/:id
3. GoldenDecisionService.delete() removes from MongoDB
4. AIChangeStreamService detects delete
5. All connected clients receive golden.changed event
Testing
# Get decisions
curl "http://localhost:3001/ai-api/command-center/decisions?limit=5"
# Get golden decisions
curl "http://localhost:3001/ai-api/command-center/golden-decisions?limit=5"
# Get comprehensive stats
curl "http://localhost:3001/ai-api/command-center/stats/comprehensive"
# Delete a decision (replace ID)
curl -X DELETE "http://localhost:3001/ai-api/command-center/decisions/YOUR_ID"
# Demote a golden decision (replace ID)
curl -X DELETE "http://localhost:3001/ai-api/command-center/golden-decisions/YOUR_ID"
# Promote a decision to golden (replace ID)
curl -X POST "http://localhost:3001/ai-api/command-center/decisions/YOUR_ID/promote" \
-H "Content-Type: application/json" \
-d '{"reason": "Excellent reasoning"}'
Command Center UI
Navigate to: http://localhost:5200/gograb/ai/command-center
Features:
- Live MongoDB Sync Indicator - Shows sync status
- Learning Stats - Total decisions, golden count
- Live Decision Feed - Real-time updates from MongoDB
- Decision Management - View, edit, delete, demote
Migration Notes
Removed
- Manual recording buttons
- Session recording/replay functionality
Why?
Everything now auto-syncs to MongoDB via Change Streams. No need to manually record - all decisions are automatically persisted and can be:
- Viewed anytime
- Edited for clarity
- Deleted if incorrect
- Demoted from golden status
Created: Session 10.5
Last Updated: December 17, 2025