New

Analytics API

Memory statistics, timeline, storage usage, and access patterns.

GETMemory Stats

Get overall memory statistics.

bash
GET /api/dashboard/memory/stats

Response

json
{
  "success": true,
  "data": {
    "totalCount": 156,
    "byCategory": {
      "preference": 42,
      "personal": 28,
      "work": 35,
      "other": 51
    },
    "byLevel": {
      "user": 120,
      "session": 36
    },
    "bySource": {
      "api": 45,
      "explicit_command": 67,
      "auto_detected": 44
    },
    "recentActivity": {
      "last24h": 12,
      "last7d": 45,
      "last30d": 89
    }
  }
}

GETMemory Timeline

Get memory creation over time.

bash
GET /api/dashboard/memory/timeline?groupBy=day&days=30

Query Parameters

ParameterTypeDefaultDescription
groupBystringday"hour" | "day" | "week" | "month"
daysnumber30Number of days to include

Response

json
{
  "success": true,
  "data": [
    { "date": "2024-01-15", "count": 8 },
    { "date": "2024-01-14", "count": 12 },
    { "date": "2024-01-13", "count": 5 }
  ]
}

GETStorage Usage

Get storage usage statistics.

bash
GET /api/dashboard/memory/storage

Response

json
{
  "success": true,
  "data": {
    "usedBytes": 524288,
    "usedFormatted": "512 KB",
    "limitBytes": 104857600,
    "limitFormatted": "100 MB",
    "percentUsed": 0.5,
    "factCount": 156,
    "avgFactSize": 3361
  }
}

GETAccess Patterns

Get most accessed memory facts.

bash
GET /api/dashboard/memory/access-patterns?limit=10

Response

json
{
  "success": true,
  "data": [
    {
      "id": "fact-1",
      "content": "User prefers TypeScript",
      "accessCount": 47,
      "lastAccessedAt": "2024-01-15T10:30:00Z"
    },
    {
      "id": "fact-2",
      "content": "User works at Acme Corp",
      "accessCount": 32,
      "lastAccessedAt": "2024-01-15T09:15:00Z"
    }
  ]
}

Dashboard Example

Build a memory analytics dashboard:

memory-dashboard.ts
const API_KEY = process.env.SUPER_AGENT_KEY;
const BASE = 'https://www.superagentstack.com/api/dashboard/memory';

async function fetchDashboardData() {
  const headers = { 'superAgentKey': API_KEY };

  const [stats, timeline, storage, patterns] = await Promise.all([
    fetch(`${BASE}/stats`, { headers }).then(r => r.json()),
    fetch(`${BASE}/timeline?groupBy=day&days=7`, { headers }).then(r => r.json()),
    fetch(`${BASE}/storage`, { headers }).then(r => r.json()),
    fetch(`${BASE}/access-patterns?limit=5`, { headers }).then(r => r.json()),
  ]);

  return {
    totalFacts: stats.data.totalCount,
    storageUsed: storage.data.usedFormatted,
    recentActivity: timeline.data,
    topFacts: patterns.data,
  };
}

// Use in your dashboard component
const data = await fetchDashboardData();
console.log(`Total facts: ${data.totalFacts}`);
console.log(`Storage: ${data.storageUsed}`);