AI Agent System Architecture
Comprehensive guide to the three-tier AI agent system (Cursor, Platform, Space)
π§ AI Agent System Architecture
Session: 6/6.8
Last Updated: December 2024
Status: Production-Ready Foundation
Overview
GoGrab Space implements a three-tier AI agent architecture designed for:
- Developer productivity (Cursor Agents)
- Platform learning (Platform Intelligence)
- User assistance (Space Assistants)
Each tier serves a distinct purpose with appropriate isolation and knowledge management.
π Architecture Diagram
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AI AGENT ARCHITECTURE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββββββ βββββββββββββββββββββββ βββββββββββββββββββββββ β
β β CURSOR AGENTS β β PLATFORM INTELLIGENCEβ β SPACE ASSISTANTS β β
β β (Developer-Facing)β β (Background) β β (User-Facing) β β
β βββββββββββββββββββββββ€ βββββββββββββββββββββββ€ βββββββββββββββββββββββ€ β
β β β’ Architecture β β β’ Pattern Learning β β β’ Widget Help β β
β β β’ Angular β β β’ Widget Analysis β β β’ Theme Selection β β
β β β’ Backend β β β’ Theme Patterns β β β’ Flow Building β β
β β β’ Testing β β β’ Module Discovery β β β’ Configuration β β
β β β’ Documentation β β β’ Flow Optimization β β β’ Personalization β β
β βββββββββββ¬ββββββββββββ βββββββββββ¬ββββββββββββ βββββββββββ¬ββββββββββββ β
β β β β β
β ββββββββββββββββββββββββββΌβββββββββββββββββββββββββ β
β β β
β ββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββ β
β β HYBRID STORAGE LAYER β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ β
β β β β
β β Layer 1: autoFlashState (IndexedDB) β β
β β βββ Speed: < 1ms (instant) β β
β β βββ Scope: Per-browser, real-time β β
β β βββ Use: UI state, offline-first β β
β β β β
β β Layer 2: MongoDB Atlas (Cloud) β β
β β βββ Speed: ~50ms β β
β β βββ Scope: Multi-developer, shared β β
β β βββ Use: Vector search, team sync β β
β β β β
β β Layer 3: docs/data/*.json (Git-tracked) β β
β β βββ Speed: N/A (backup) β β
β β βββ Scope: Repository history β β
β β βββ Use: Auditability, fallback β β
β β β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π€ Tier 1: Cursor Agents (Developer-Facing)
Purpose
Help developers write code faster and better by learning from decisions made in the IDE.
Agent Specializations
| Agent ID | Responsibility | Knowledge Domain |
|---|---|---|
cursor-orchestrator |
Routes tasks to specialized agents | All domains |
cursor-architecture |
SOLID, patterns, system design | Architecture decisions |
cursor-angular |
Components, signals, RxJS | Frontend patterns |
cursor-backend |
NestJS, MongoDB, APIs | Backend patterns |
cursor-testing |
Vitest, Playwright, TDD | Testing patterns |
cursor-documentation |
Markdown, ADRs, APIs | Documentation patterns |
How It Works
// MCP Server receives decision from Cursor
{
type: "implementation",
question: "How to handle component state?",
options: ["Signals", "RxJS BehaviorSubject", "NGXS"],
chosen: "Signals",
reasoning: "Angular 20 best practice, simpler than RxJS for local state",
confidence: 0.9,
agentId: "cursor-angular-agent"
}
Knowledge Flow
Developer Action (Cursor IDE)
β
MCP Server logs decision
β
Decision stored in development-memory.json
β
Synced to MongoDB (agent_decisions collection)
β
Patterns mined periodically
β
Future pre-flight retrieves relevant patterns
Configuration
// MCP configuration in .cursor/mcp.json
{
"mcpServers": {
"development-ai": {
"command": "node",
"args": ["tools/mcp-development-ai/dist/server.js"],
"env": {
"WORKSPACE_ROOT": "${workspaceRoot}",
"ENABLE_VECTOR_MEMORY": "true"
}
}
}
}
π‘ Tier 2: Platform Intelligence (Background Learning)
Purpose
Automatically learn patterns from how the platform is used to improve suggestions and automation.
Agent Specializations
| Agent ID | Responsibility | Learns From |
|---|---|---|
platform-pattern |
Extract reusable patterns | Successful implementations |
platform-widget |
Widget best practices | Widget deployments |
platform-theme |
Theme combinations | Theme usage analytics |
platform-module |
Module structures | Module integrations |
platform-flow |
Logic flow patterns | Flow executions |
How It Works
// Platform observes widget deployment
@Injectable()
export class PlatformWidgetAgent extends BasePlatformAgent {
observe(event: WidgetDeploymentEvent): void {
if (event.success && event.metrics.userSatisfaction > 4.0) {
this.learnPattern({
context: event.widgetType,
configuration: event.config,
performance: event.metrics
});
}
}
}
Pattern Extraction
// Automatically mined pattern
{
id: "pattern-virtual-scroll-large-data",
name: "Virtual Scroll for Large Datasets",
context: "DataTable with >1000 rows",
recommendation: "Enable virtual scroll with rowHeight=48",
reasoning: "Reduces DOM nodes, improves FPS by 300%",
supportCount: 15,
successRate: 0.95,
techTags: ["angular", "performance", "data-table"],
agentTypes: ["platform-widget", "cursor-angular"]
}
Knowledge Isolation
- Global Scope: Learns from all tenants
- Anonymized: No tenant-specific data stored
- Aggregated: Patterns require multiple occurrences
π Tier 3: Space Assistants (User-Facing)
Purpose
Help end-users build their spaces through natural language and contextual suggestions.
Capabilities
| Capability | Description |
|---|---|
| Widget Help | Create, configure, and customize widgets |
| Theme Selection | Suggest themes based on preferences |
| Flow Building | Guide users through flow creation |
| Module Configuration | Help configure module settings |
| Troubleshooting | Diagnose and fix issues |
How It Works
// User asks for help
"How do I add a chart to my dashboard?"
// Space Assistant responds with context
{
context: "dashboard-page",
tenantId: "tenant-123",
response: "I'll help you add a chart! Based on your data...",
actions: [
{ type: "suggest-widget", widget: "bar-chart" },
{ type: "open-config", panel: "widget-settings" }
]
}
Tenant Isolation
// Each tenant has completely isolated knowledge
export class SpaceAssistantService {
private knowledgeByTenant = new Map<string, TenantKnowledge>();
getAssistant(tenantId: string): SpaceAssistant {
// Strict isolation - cannot access other tenants
return new SpaceAssistant(this.knowledgeByTenant.get(tenantId));
}
}
Security Model
- β Can access: Own tenant's data, spaces, configurations
- β Cannot access: Other tenants, core code, system settings
- β Can modify: User's widgets, themes, flows
- β Cannot modify: Platform code, other users' data
πΎ Hybrid Storage System
Overview
The AgentMemoryStorageService provides three-layer persistence:
import { AgentMemoryStorageService } from '@libs-ai/agent-orchestrator';
@Injectable()
export class MyService {
private memory = inject(AgentMemoryStorageService);
// Real-time session tracking
currentSession = this.memory.sessionDisplay; // "6/6.8"
// Store decisions by agent type
this.memory.storeDecision({
id: 'dec-123',
type: 'implementation',
question: 'How to handle X?',
chosen: 'Use Y',
reasoning: 'Because Z',
confidence: 0.9,
agentType: 'cursor-angular',
timestamp: new Date().toISOString()
});
// Sync to cloud
this.memory.fullSyncToMongo();
}
Storage Locations
| Location | Purpose | Format |
|---|---|---|
IndexedDB |
Real-time local | autoFlashState |
MongoDB Atlas |
Cloud sync | Documents |
docs/sessionID.json |
Session tracking | JSON |
docs/data/*.json |
Git-tracked backup | JSON |
.cursor/ai-memory/ |
MCP memory | JSON |
Session Management
// Session increments with progress
6.0 β 6.1 β 6.2 β ... β 6.8 β 6.9 β 7.0
// Increment session ID
memory.incrementSessionID(); // 6.8 β 6.9
// Start new major session
memory.startNewSession(); // 6.x β 7.0
ποΈ Knowledge Control
Clearing Agent Knowledge
// Clear a specific agent's learned patterns
memory.clearAgentKnowledge('cursor-angular');
// Remove a specific decision
memory.removeDecision('decision-id-123');
// Deprecate a pattern
memory.updatePatternStatus('pattern-id', 'deprecated');
Knowledge Summary
const summary = memory.getKnowledgeSummary();
// {
// 'cursor-angular': { decisions: 45, patterns: 12 },
// 'cursor-backend': { decisions: 23, patterns: 8 },
// 'platform-widget': { decisions: 15, patterns: 5 }
// }
π API Endpoints
Backend Endpoints (NestJS)
| Endpoint | Method | Purpose |
|---|---|---|
/api/ai-agents/session/current |
GET | Get current session info |
/api/ai-agents/session/increment |
POST | Increment session ID |
/api/ai-agents/session/sync |
POST | Sync session from frontend |
/api/ai-agents/sync/full |
POST | Full MCP β MongoDB sync |
/api/ai-agents/sync/full-frontend |
POST | Full frontend β MongoDB sync |
/api/ai-agents/sync/pull-all |
GET | Pull all data for frontend |
/api/ai-agents/patterns/mine |
POST | Mine patterns from decisions |
/api/ai-agents/storage/stats |
GET | Get comprehensive stats |
π File Structure
libs/libs-ai/
βββ agent-orchestrator/ # Core orchestration
β βββ services/
β βββ agent-api.service.ts
β βββ agent-memory-storage.service.ts # Hybrid storage
β βββ agent-platform-learning.service.ts
βββ agent-mind/ # Visualization components
β βββ components/
β βββ agent-mind-container/
β βββ knowledge-browser/
β βββ memory-clusters/
βββ platform-intelligence/ # Platform learning agents
β βββ agents/
β βββ base-platform-agent.ts
β βββ platform-pattern-agent.ts
β βββ platform-widget-agent.ts
βββ vitto-hub/ # User-facing assistant
β βββ components/
β βββ ai-panel/
βββ gograb-ai/ # Dashboard & UI
βββ components/
βββ ai-dashboard/
βββ ai-agents-dashboard/
π Data Flow Summary
βββββββββββββββ
β Cursor β
β IDE β
ββββββββ¬βββββββ
β MCP Protocol
βΌ
βββββββββββββββ
β MCP Server β
β (Node.js) β
ββββββββ¬βββββββ
β
βββββββββββββββββΌββββββββββββββββ
βΌ βΌ βΌ
ββββββββββββββ ββββββββββββββ ββββββββββββββ
β Local File β β Backend β β User Home β
β (workspace)β β API β β Backup β
βββββββ¬βββββββ βββββββ¬βββββββ ββββββββββββββ
β β
β βΌ
β ββββββββββββββ
βββββββββΊβ MongoDB βββββββββ Frontend
β Atlas β (autoFlash)
βββββββ¬βββββββ
β
βΌ
ββββββββββββββ
β docs/data/ β
β (git sync) β
ββββββββββββββ
π Getting Started
1. Enable MCP in Cursor
Ensure .cursor/mcp.json is configured with the development-ai server.
2. Use the Memory Service
import { AgentMemoryStorageService } from '@libs-ai/agent-orchestrator';
export class MyComponent {
private memory = inject(AgentMemoryStorageService);
}
3. Log Decisions
Use the MCP log_decision tool or the memory service's storeDecision method.
4. Sync Data
Click "Full Sync" in the AI Dashboard or call memory.fullSyncToMongo().
π Metrics & Monitoring
Dashboard Location
http://localhost:5701/ai/dashboard
Key Metrics
- Total decisions per agent
- Pattern count and success rates
- Sync status (MongoDB connected)
- Session progression
π Security Considerations
- Tenant Isolation: Space Assistants are strictly isolated per tenant
- Data Anonymization: Platform Intelligence anonymizes patterns
- Access Control: Backend validates tenant context
- Sensitive Data: Reasoning can be redacted in exports
π Related Documentation
- CLAUDE.md - Main AI instructions
- AGENTS.md - Agent-specific rules
- session-6 - Current session context
- MCP Server - MCP implementation
Last updated: Session 6/6.8