Persistent storage and logging system for the AI crew orchestration framework. Provides both database (Supabase) and file-based logging capabilities with comprehensive analytics and querying features.

Example

const memory = new Memory({
supabaseUrl: process.env.SUPABASE_URL,
supabaseKey: process.env.SUPABASE_ANON_KEY,
enableDatabaseLogging: true,
enableFileLogging: false
});

// Log an event
await memory.log({
level: 'info',
message: 'Kata execution started',
context: 'WeatherAnalyst',
kata_id: 'kata-uuid',
metadata: { user_query: 'What is the weather in Paris?' }
});

// Query logs
const recentLogs = await memory.queryLogs({ limit: 10 });

// Get execution statistics
const stats = await memory.getExecutionStats();

Constructors

Methods

  • Log entry using configured destinations. This is the main logging method that handles routing to database and/or file.

    Parameters

    • logEntry: Omit<LogEntry, "id" | "timestamp">

      The log entry data (without id and timestamp)

    Returns Promise<string>

    Promise resolving to the generated log entry ID

    Example

    const logId = await memory.log({
    level: 'info',
    message: 'Shinobi execution completed',
    context: 'TravelExpert',
    shinobi_id: 'shinobi-uuid',
    execution_time: 2500,
    estimated_cost: 0.001234,
    metadata: {
    katas_executed: 3,
    total_tokens: 1500
    }
    });
  • Query logs from database with filtering options.

    Parameters

    • filters: {
          shinobi_id?: string;
          kata_id?: string;
          shuriken_id?: string;
          level?: string;
          start_time?: Date;
          end_time?: Date;
          limit?: number;
      } = {}

      Object containing filter criteria

      • Optional shinobi_id?: string
      • Optional kata_id?: string
      • Optional shuriken_id?: string
      • Optional level?: string
      • Optional start_time?: Date
      • Optional end_time?: Date
      • Optional limit?: number

    Returns Promise<LogEntry[]>

    Promise resolving to array of matching log entries

    Example

    // Get recent errors
    const errors = await memory.queryLogs({
    level: 'error',
    limit: 5
    });

    // Get logs for specific Shinobi
    const shinobiLogs = await memory.queryLogs({
    shinobi_id: 'shinobi-uuid',
    start_time: new Date(Date.now() - 24 * 60 * 60 * 1000) // Last 24 hours
    });
  • Get execution statistics and analytics.

    Parameters

    • filters: {
          shinobi_id?: string;
          kata_id?: string;
          start_time?: Date;
          end_time?: Date;
      } = {}

      Optional filters to scope the statistics

      • Optional shinobi_id?: string
      • Optional kata_id?: string
      • Optional start_time?: Date
      • Optional end_time?: Date

    Returns Promise<{
        total_executions: number;
        total_cost: number;
        total_tokens: number;
        avg_execution_time: number;
    }>

    Promise resolving to aggregated statistics

    Example

    // Get overall statistics
    const stats = await memory.getExecutionStats();
    console.log(`Total executions: ${stats.total_executions}`);
    console.log(`Total cost: $${stats.total_cost.toFixed(6)}`);

    // Get statistics for specific Shinobi
    const shinobiStats = await memory.getExecutionStats({
    shinobi_id: 'shinobi-uuid'
    });