Skip to main content

CloudBaseMemory

Serverless memory storage with Tencent CloudBase integration for Chinese market applications.

Import

import { CloudBaseMemory } from '@ag-kit/agents/storage';
import cloudbase from '@cloudbase/node-sdk';

Constructor

constructor(options: CloudBaseMemoryOptions & IBaseMemoryOptions)

Configuration

options
CloudBaseMemoryOptions & IBaseMemoryOptions
required
CloudBase Memory configuration options extending BaseMemory options

Basic Usage

// Initialize CloudBase app
const app = cloudbase.init({
  env: 'your-env-id',
  secretId: 'your-secret-id',
  secretKey: 'your-secret-key',
  region: 'ap-shanghai'
});

// Create CloudBase memory instance
const memory = new CloudBaseMemory({
  app,
  sessionId: 'user-session-123',
  collectionName: 'conversation_events',
  enableContextManagement: true
});

// Add and retrieve events
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

CloudBaseMemory 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.

CloudBase Integration

// Multi-tenant configuration
const createTenantMemory = (tenantId: string, userId: string) => {
  const app = cloudbase.init({
    env: `tenant-${tenantId}-env`,
    secretId: process.env.CLOUDBASE_SECRET_ID!,
    secretKey: process.env.CLOUDBASE_SECRET_KEY!
  });

  return new CloudBaseMemory({
    app,
    sessionId: `tenant-${tenantId}-user-${userId}`,
    collectionName: `tenant_${tenantId}_events`,
    enableContextManagement: true
  });
};

Unique Features

  • Serverless Architecture: No server management required
  • Automatic Scaling: Scales automatically based on demand
  • Tencent Cloud Integration: Native integration with Tencent Cloud services
  • Chinese Market Optimized: Optimized for Chinese regulatory requirements
  • Cost-effective: Pay-per-use pricing model

Limitations

  • Vendor Lock-in: Tied to Tencent CloudBase platform
  • Regional Restrictions: Primarily optimized for Chinese market
  • Cold Starts: Potential latency from serverless cold starts
  • Quota Limits: Subject to CloudBase usage quotas and limits