Long Term Memory
Convai can remember things about your users across sessions. When you provide an `endUserId`, the character automatically builds and recalls long-term memories.
Last updated
Was this helpful?
Was this helpful?
const client = useConvaiClient({
apiKey: 'YOUR_API_KEY',
characterId: 'YOUR_CHARACTER_ID',
endUserId: 'a1b2c3d4-...', // any string — (UUID or email) preferred, e.g. 'user@example.com'
});const memory = client.memoryManager;
if (!memory) {
// endUserId was not provided, or client is not yet connected
return;
}const result = await memory.listMemories({ page: 1, pageSize: 50 });
console.log(`Total: ${result.total_count}`);
console.log(`Has more: ${result.has_more}`);
result.memories.forEach(m => {
console.log(`[${m.id}] ${m.memory}`);
// m.created_at, m.updated_at (ISO timestamps)
});
// Paginate if needed
if (result.has_more) {
const page2 = await memory.listMemories({ page: 2, pageSize: 50 });
}const result = await memory.addMemories([
'User prefers dark mode UI.',
'User is learning Spanish.',
'User plays guitar as a hobby.',
]);
result.memories.forEach(m => {
console.log(`Added: ${m.id} → ${m.memory}`);
});const m = await memory.getMemory('f4cbdb08-7062-4f3e-8eb2-9f5c80dfe64c');
console.log(m.memory); // "User prefers dark mode UI."
console.log(m.created_at); // ISO timestamp
console.log(m.updated_at); // ISO timestampconst result = await memory.deleteMemory('f4cbdb08-7062-4f3e-8eb2-9f5c80dfe64c');
if (result.deleted) {
console.log('Deleted:', result.memory_id);
}const result = await memory.deleteAllMemories();
console.log(result.message); // "Memory deletion in progress..."
// Wait briefly and verify
await new Promise(r => setTimeout(r, 2000));
const check = await memory.listMemories();
console.log('Remaining:', check.total_count);import { MemoryManager } from '@convai/web-sdk/core';
const manager = new MemoryManager(
'YOUR_API_KEY', // or auth token
'CHARACTER_ID',
'END_USER_ID',
);
const memories = await manager.listMemories();interface Memory {
id: string; // UUID
memory: string; // Text content
created_at: string; // ISO 8601 timestamp
updated_at: string; // ISO 8601 timestamp
}