Skip to main content

MySQLMemory

MySQL-optimized memory storage extending TypeORMMemory with MySQL-specific configurations and optimizations.

Import

import { MySQLMemory } from '@ag-kit/agents/storage';

Constructor

constructor(config: MySQLMemoryConfig)

Configuration

config
MySQLMemoryConfig
required
MySQL-specific configuration extending TypeORMMemory and BaseMemory

Basic Usage

// MySQL connection with optimizations
const memory = new MySQLMemory({
  connection: {
    host: 'localhost',
    port: 3306,
    username: 'agkit_user',
    password: 'secure_password',
    database: 'agkit_memory',
    charset: 'utf8mb4',
    timezone: '+00:00',
    extra: {
      supportBigNumbers: true,
      bigNumberStrings: true,
      multipleStatements: false
    }
  },
  sessionId: 'user-session-123',
  eventTableName: 'conversation_events',
  enableContextManagement: true
});

// Inherits all TypeORMMemory functionality
await memory.add({
  message: {
    id: 'msg-1',
    role: 'user',
    content: 'Hello, I need help with my project',
    timestamp: new Date()
  },
  state: { userId: 'user-123' }
});

const events = await memory.list({ limit: 10, maxTokens: 4000 });

Core Interface Methods

MySQLMemory inherits from BaseMemory and implements all standard memory interface methods with full branching support. For complete API documentation including list(), add(), addList(), delete(), retrieve(), clear(), getCount(), isEmpty(), and all branching methods, see the BaseMemory API Reference.

Connection String Support

// Create from connection string
const memory = MySQLMemory.fromConnectionString(
  'mysql://user:pass@localhost:3306/mydb',
  'session-123',
  {
    eventTableName: 'custom_events',
    enableContextManagement: true
  }
);

Unique Features

  • MySQL-Specific Optimizations: Pre-configured MySQL settings (charset, timezone, big numbers)
  • Simplified Setup: Automatic DataSource creation with MySQL best practices
  • Connection String Support: Easy initialization with connection strings
  • Table Customization: Custom table names for events, state, and summaries
  • Security Defaults: Prevents SQL injection with multipleStatements: false
  • UTF-8 Support: Default utf8mb4 charset for international content

Inheritance

MySQLMemory extends TypeORMMemory, inheriting all its capabilities:
  • Session branching and time travel
  • Context engineering and token management
  • Advanced querying and filtering
  • Transaction support

Limitations

  • MySQL Dependency: Requires MySQL server installation and management
  • TypeORM Overhead: Inherits TypeORM complexity and setup requirements