Skip to main content

Customer Support Bot

Build a support bot that remembers customer history and provides personalized help.

The Problem

Traditional support bots ask the same questions every time:

  • "What's your email?"
  • "Can you describe the issue again?"
  • "Have you tried restarting?"

This frustrates customers and wastes time.

The Solution

A memory-enabled support bot that:

  • Remembers customer details and past interactions
  • Recalls previous issues and solutions
  • Provides personalized, context-aware support

Architecture

┌─────────────────────────────────────────────────────────┐
│ Support Bot Architecture │
│ │
│ Customer Memory LLM Actions │
│ Message ─▶ Lookup ─▶ Response ─▶ (if any) │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────┐ ┌──────────────┐ │
│ │ Memory │ │ Ticket │ │
│ │ Store │ │ System │ │
│ └─────────────┘ └──────────────┘ │
│ │
│ Memories: Customer info, past tickets, preferences │
└─────────────────────────────────────────────────────────┘

Implementation

Step 1: Store Customer Information

When customers interact, store relevant details:

import requests

MEMORY_API = "https://api.memory.tensorheart.com/v1"
API_KEY = "mem_live_..."

def store_customer_info(customer_id: str, info: str, category: str):
"""Store information about a customer."""
requests.post(
f"{MEMORY_API}/memories",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
"text": info,
"space_id": f"customer_{customer_id}",
"metadata": {
"category": category,
"timestamp": "2024-01-15"
}
}
)

# Example usage
store_customer_info("cust_123", "Customer email is john@acme.com", "contact")
store_customer_info("cust_123", "Customer is on the Pro plan", "subscription")
store_customer_info("cust_123", "Had billing issue resolved in December", "history")

Step 2: Retrieve Context Before Responding

def get_customer_context(customer_id: str, query: str) -> list[str]:
"""Get relevant memories for this customer and query."""
response = requests.post(
f"{MEMORY_API}/query",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
"context": query,
"space_id": f"customer_{customer_id}",
"max_memories": 10
}
)
data = response.json()
return [m["text"] for m in data.get("data", {}).get("memories", [])]

Step 3: Build the Support Bot

from openai import OpenAI

openai = OpenAI()

def support_bot(customer_id: str, message: str) -> str:
"""Handle a customer support message."""

# Get relevant customer context
memories = get_customer_context(customer_id, message)

memory_context = "\n".join(f"- {m}" for m in memories) if memories else "No prior history."

system_prompt = f"""You are a helpful customer support agent.

Customer Context:
{memory_context}

Guidelines:
- Be friendly and empathetic
- Reference past interactions naturally (don't list everything)
- If you learn new information, mention it for record-keeping
- Offer specific solutions based on their history"""

response = openai.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": message}
]
)

return response.choices[0].message.content

Step 4: Auto-Learn from Conversations

def save_ticket_to_memory(customer_id: str, ticket: dict):
"""Store ticket information for future reference."""

summary = f"Ticket #{ticket['id']}: {ticket['subject']} - {ticket['resolution']}"

requests.post(
f"{MEMORY_API}/memories",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
"text": summary,
"space_id": f"customer_{customer_id}",
"metadata": {
"category": "ticket",
"ticket_id": ticket["id"],
"status": ticket["status"]
}
}
)

# After resolving a ticket
save_ticket_to_memory("cust_123", {
"id": "TKT-456",
"subject": "Payment not processing",
"resolution": "Updated expired credit card",
"status": "resolved"
})

Example Conversation

Without Memory:

Customer: My payment isn't going through
Bot: I'm sorry to hear that. Can you tell me your email address?
Customer: john@acme.com
Bot: What plan are you on?
Customer: Pro plan
Bot: Have you had this issue before?
Customer: Yes, last month
Bot: Can you describe what happened?
... (frustrating loop continues)

With Memory:

Customer: My payment isn't going through

Bot: Hi John! I see you're on the Pro plan. Looking at your history,
you had a similar billing issue in December that was resolved by
updating your credit card.

Has your card expired again, or is this a different issue?

Advanced Features

Priority Detection

Use metadata to flag important customers:

def get_customer_priority(customer_id: str) -> str:
"""Determine customer priority from memory."""
memories = get_customer_context(customer_id, "subscription plan tier VIP")

# Check for high-value indicators
for memory in memories:
if "enterprise" in memory.lower() or "vip" in memory.lower():
return "high"
if "pro plan" in memory.lower():
return "medium"

return "standard"

Issue Pattern Detection

Identify recurring issues:

def detect_recurring_issue(customer_id: str, current_issue: str) -> bool:
"""Check if this customer has had similar issues."""
memories = get_customer_context(customer_id, current_issue)

# Look for pattern matches
similar_count = sum(1 for m in memories if "ticket" in m.lower())
return similar_count >= 2

Sentiment-Aware Responses

Adjust tone based on customer history:

def get_customer_sentiment_context(customer_id: str) -> str:
"""Get sentiment-related context for this customer."""
memories = get_customer_context(customer_id, "frustrated upset happy satisfied")

if any("frustrated" in m.lower() or "upset" in m.lower() for m in memories):
return "Customer has shown frustration in past interactions. Be extra empathetic."
elif any("happy" in m.lower() or "satisfied" in m.lower() for m in memories):
return "Customer has been positive in past interactions."

return "No strong sentiment history."

Results

Companies using memory-enabled support bots see:

MetricImprovement
First-response resolution+35%
Customer satisfaction+28%
Average handle time-40%
Repeat contacts-50%

Next Steps