import os
from memoryos import Memory
mem = Memory(api_key=os.environ["MEMORYOS_API_KEY"])
BASE_SUPPORT_PROMPT = """
You are a careful customer support assistant.
Rules:
- Use MemoryOS context as remembered customer context only.
- Use live tool results as the source of truth for current status and actions.
- Do not claim you checked, changed, refunded, cancelled, verified, located, or triggered anything unless a tool result confirms it.
- If live system data is needed and no tool result is available, say you need to check the relevant system.
- Ask for only one missing identifier at a time.
- Never ask for OTPs, passwords, full account numbers, full card numbers, Aadhaar, PAN, passport numbers, or full IMEI.
"""
def answer_support_message(customer_id, ticket_id, user_message, conversation_history):
"""
customer_id: your stable customer/user/account ID, for example "cust_8a72"
ticket_id: your support ticket or conversation ID, for example "TCK-1842"
conversation_history: previous messages in this ticket
"""
memories = mem.get(
query=user_message,
external_user_id=customer_id,
agent_id="support-bot",
limit=8,
context_max_tokens=700,
)
# Replace these with your real backend tools.
# Examples: get_order(), get_invoice(), get_ticket_status(), get_customer_account().
tool_results = lookup_live_support_data(
customer_id=customer_id,
ticket_id=ticket_id,
user_message=user_message,
)
system_prompt = BASE_SUPPORT_PROMPT
if memories.has_context:
system_prompt += "\n\nRemembered customer context from MemoryOS:\n"
system_prompt += memories.system_prompt_addition
system_prompt += "\n\nLive support tool results:\n"
system_prompt += str(tool_results)
assistant_reply = call_your_llm(
system_prompt=system_prompt,
messages=[
*conversation_history,
{"role": "user", "content": user_message},
],
)
mem.add(
external_user_id=customer_id,
agent_id="support-bot",
messages=[
*conversation_history,
{"role": "user", "content": user_message},
{"role": "assistant", "content": assistant_reply},
],
metadata={
"source": "support_chat",
"ticket_id": ticket_id,
},
)
return assistant_reply