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:

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


πŸš€ 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


πŸ’Ύ 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


πŸ” Security Considerations

  1. Tenant Isolation: Space Assistants are strictly isolated per tenant
  2. Data Anonymization: Platform Intelligence anonymizes patterns
  3. Access Control: Backend validates tenant context
  4. Sensitive Data: Reasoning can be redacted in exports

πŸ“š Related Documentation


Last updated: Session 6/6.8