Overview
Customer support benefits significantly from persistent memory:
- Remember customer history and preferences
- Track ongoing issues across sessions
- Personalize responses based on past interactions
- Hand off context between agents seamlessly
Building Customer Context
async function getSupportContext(customerId: string) {
// Get customer profile memories
const profile = await trix.memories.list({
q: 'customer profile preferences',
spaceId: `customer_${customerId}`,
tags: ['profile'],
limit: 5
});
// Get recent issues
const issues = await trix.memories.list({
q: 'support issues problems',
spaceId: `customer_${customerId}`,
tags: ['issues'],
limit: 5
});
return {
profile: profile.data.map(m => m.content),
recentIssues: issues.data.map(m => ({
description: m.content,
status: m.metadata.status,
date: m.metadata.created
}))
};
}Support Conversation Flow
async function handleSupportMessage(customerId: string, message: string) {
const context = await getSupportContext(customerId);
const systemPrompt = `You are a helpful support agent.
Customer Profile:
${context.profile.join('\n')}
Recent Issues:
${context.recentIssues.map(i => `- ${i.description} (${i.status})`).join('\n')}
Be empathetic and reference past interactions when relevant.`;
const response = await generateResponse(systemPrompt, message);
// Track this interaction
await trix.memories.create({
content: `Customer asked about: ${message.slice(0, 100)}`,
spaceId: `customer_${customerId}`,
tags: ['interactions'],
metadata: { channel: 'chat', timestamp: new Date().toISOString() }
});
return response;
}Issue Tracking
async function createIssue(customerId: string, issue: Issue) {
await trix.memories.create({
content: issue.description,
spaceId: `customer_${customerId}`,
tags: ['issues'],
metadata: {
issueId: issue.id,
status: 'open',
priority: issue.priority,
created: new Date().toISOString()
}
});
}
async function resolveIssue(customerId: string, issueId: string, resolution: string) {
// Find and update the issue memory
const issues = await trix.memories.list({
q: 'issue',
spaceId: `customer_${customerId}`,
tags: ['issues']
});
const match = issues.data.find(m => m.metadata?.issueId === issueId);
if (match) {
await trix.memories.update(match.id, {
metadata: { status: 'resolved', resolution }
});
}
}Use metadata to track issue status without modifying the original content.