Documentation Query API Agents Building Agents Memory Core Self-Learning Playground
Documentation

Research

AI Agent Platform with persistent memory, self-learning capabilities, and workflow automation.

🧠

Persistent Memory

Agents remember user preferences across sessions

Self-Learning

Automatic knowledge acquisition from conversations

🔍

RAG System

Semantic search over documents using embeddings

System Architecture

The platform follows a layered architecture with clear separation of concerns.

┌─────────────────────────────────────────────────────────────────┐
│                        PRESENTATION LAYER                        │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐             │
│  │  Dashboard  │  │  Chat UI    │  │  Workflow   │             │
│  │  (Admin)    │  │  (Widget)   │  │  Builder    │             │
│  └─────────────┘  └─────────────┘  └─────────────┘             │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                          API LAYER                               │
│   /api/chat    /api/agents    /api/brain    /api/workflows      │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                        SERVICE LAYER                             │
│   ChatService    MemoryService    KnowledgeService    RAGService │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                      REPOSITORY LAYER                            │
│   AgentRepo    ConversationRepo    MemoryRepo    KnowledgeRepo  │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                        DATA LAYER                                │
│          MySQL Database              Cloud Storage               │
└─────────────────────────────────────────────────────────────────┘

Tech Stack

Component Technology Rationale
RuntimeNode.jsNon-blocking I/O for real-time chat
FrameworkExpress.jsLightweight, flexible routing
DatabaseMySQLACID compliance, JSON support
AI ModelGPT-4.1-miniBalance of cost and capability
Embeddingstext-embedding-3-small1536 dimensions, cost-effective

Memory System

The three-tier memory architecture enables agents to maintain context and learn from interactions.

┌─────────────────────────────────────────────────────────────────────────┐
│                         AGENT INTELLIGENCE                               │
├─────────────────────────────────────────────────────────────────────────┤
│                                                                          │
│   ┌─────────────────┐   ┌─────────────────┐   ┌─────────────────┐      │
│   │  SHORT-TERM     │   │   LONG-TERM     │   │   KNOWLEDGE     │      │
│   │  MEMORY         │   │   MEMORY        │   │   BASE          │      │
│   │                 │   │                 │   │                 │      │
│   │  Conversation   │   │  User Profile   │   │  Q&A Pairs      │      │
│   │  History        │   │  Preferences    │   │  Documents      │      │
│   │  (Last N msgs)  │   │  Facts          │   │  (RAG)          │      │
│   │                 │   │                 │   │                 │      │
│   │  Scope: Session │   │  Scope: User    │   │  Scope: Agent   │      │
│   │  TTL: ~30 min   │   │  TTL: Permanent │   │  TTL: Permanent │      │
│   └────────┬────────┘   └────────┬────────┘   └────────┬────────┘      │
│            │                     │                     │               │
│            └─────────────────────┼─────────────────────┘               │
│                                  ▼                                      │
│                     ┌────────────────────────┐                         │
│                     │     CONTEXT BUILDER    │                         │
│                     └────────────────────────┘                         │
│                                  │                                      │
│                                  ▼                                      │
│                     ┌────────────────────────┐                         │
│                     │      OPENAI GPT        │                         │
│                     └────────────────────────┘                         │
└─────────────────────────────────────────────────────────────────────────┘

1. Short-Term Memory

Maintains conversation continuity within a session by storing the last N messages.

How It Works

  1. User sends message
  2. Message saved to messages table with conversation_id
  3. On next request, last N messages retrieved
  4. History included in OpenAI API call

2. Long-Term Memory

Remembers user-specific information across sessions using a key-value store.

User: "Remember that I prefer morning appointments"
                │
                ▼
┌────────────────────────────────────────────────────────────────┐
│                        AI RESPONSE                              │
│  Detects memory request and outputs:                           │
│  {"action":"save", "key":"appointment_preference",             │
│   "value":"prefers morning appointments"}                      │
└───────────────────────────┬────────────────────────────────────┘
                            │
                            ▼
┌────────────────────────────────────────────────────────────────┐
│                     MEMORY REPOSITORY                           │
│  INSERT INTO memories (agent_id, session_id, key, value)       │
└────────────────────────────────────────────────────────────────┘
                            │
                            ▼
┌────────────────────────────────────────────────────────────────┐
│                     FUTURE CONVERSATIONS                        │
│  Context includes:                                             │
│  - appointment_preference: prefers morning appointments        │
└────────────────────────────────────────────────────────────────┘

3. Knowledge Base (Self-Learning)

Builds institutional knowledge from conversations through a training loop.

Step 1: User Asks Unknown Question
───────────────────────────────────
User: "What are your business hours?"
        │
        ▼
┌───────────────┐
│ Agent doesn't │────► Log to unanswered_questions
│ know answer   │
└───────────────┘

Step 2: Owner Trains Agent
──────────────────────────
┌─────────────────────────────┐
│     TRAINING DASHBOARD      │
│                             │
│  Pending Questions:         │
│  "What are your hours?"     │
│  Asked: 15 times            │
│                             │
│  Owner provides answer:     │
│  "Mon-Fri, 9 AM to 5 PM"   │
└──────────────┬──────────────┘
               ▼
┌─────────────────────────────┐
│  Add to knowledge base      │
└─────────────────────────────┘

Step 3: Agent Uses Knowledge
────────────────────────────
Future questions get accurate answers automatically

RAG Pipeline

Retrieval Augmented Generation enables semantic search over uploaded documents.

                    INGESTION PHASE
                    ───────────────

Document Upload              Chunking                    Embedding
     │                          │                            │
     ▼                          ▼                            ▼
┌─────────┐            ┌─────────────────┐           ┌─────────────────┐
│  PDF    │            │  Split into     │           │   OpenAI API    │
│  CSV    │ ────────►  │  800-char       │ ───────►  │   Embeddings    │
│  TXT    │            │  chunks         │           │   (1536 dims)   │
└─────────┘            └─────────────────┘           └────────┬────────┘
                                                              ▼
                                                  ┌───────────────────┐
                                                  │  Store in MySQL   │
                                                  └───────────────────┘


                    RETRIEVAL PHASE
                    ────────────────

User Query              Query Embedding              Similarity Search
     │                        │                            │
     ▼                        ▼                            ▼
┌─────────────┐       ┌─────────────────┐         ┌─────────────────┐
│ "What is    │       │   Embed query   │         │ Cosine          │
│ the refund  │ ────► │   using same    │ ─────►  │ similarity      │
│ policy?"    │       │   model         │         │ search          │
└─────────────┘       └─────────────────┘         └────────┬────────┘
                                                           ▼
                                                  ┌─────────────────┐
                                                  │ Inject into     │
                                                  │ AI context      │
                                                  └─────────────────┘

Document Chunking

Documents are split into overlapping chunks to preserve context across boundaries.

800
Chunk Size (chars)
200
Overlap (chars)
1536
Embedding Dims

Vector Embeddings

Text is converted to 1536-dimensional vectors that capture semantic meaning.

Input Text:
"We offer a 30-day money-back guarantee on all products"
                              │
                              ▼
                   ┌──────────────────┐
                   │  OpenAI API      │
                   │  text-embedding- │
                   │  3-small         │
                   └────────┬─────────┘
                            │
                            ▼

Output Vector (1536 dimensions):
[0.0234, -0.0891, 0.0123, 0.0567, -0.0345, ..., 0.0456]

Similar texts will have similar vectors (high cosine similarity)

Cosine Similarity Search

Queries are matched against stored chunks using cosine similarity.

Query: "What is your refund policy?"

  • Chunk about refunds and returns 0.92
  • Chunk about shipping policies 0.45
  • Chunk about contact information 0.38

API Reference

Chat Endpoints

POST /api/chat/:agentSlug/message

Send a message to an agent

{
  "session_id": "user_abc123",
  "message": "What are your business hours?"
}

Agent Management

GET /api/agents

List all agents

POST /api/agents

Create a new agent

PUT /api/agents/:id

Update an agent

Workflows

POST /api/workflows/ai-build

Build workflows from natural language

{
  "message": "When someone submits a form, send me an email"
}