Ticket-linked memory with authoritative knowledge policies.
This guide walks through building a customer support agent that uses Spectron for two distinct purposes: authoritative knowledge holds the authoritative product knowledge – FAQs, policies, and the product catalogue – and experiential memory holds per-customer memory accumulated over every interaction. The result is an agent that answers product questions correctly and remembers each customer's history without manual context injection.
What you are building
A Context with an ontology covering Customer, Product, and Ticket entity types.
authoritative knowledge nodes for the product catalogue and policy documents.
Per-customer sessions scoped by user_id, so each customer's memory is isolated.
A conversation loop that retrieves relevant context before each LLM call and extracts new facts after each turn.
Prerequisites
A Spectron Context is created through the management API or the dashboard. The examples below assume you have a context_id and a management API key for ingestion, plus an agent API key for the conversation loop.
Step 1 – Create the Context
Define the entity ontology when creating the Context. This tells the extraction pipeline what entity types to recognise and extract.
mgmt.post("/contexts",json={ "id": "support", "display_name": "Customer Support", "config": { "ontology": { "entities": [ { "type": "Customer", "description": "A person or organisation that has purchased or enquired about a product.", "attributes": ["name","email","plan","account_status","preferred_channel"], }, { "type": "Product", "description": "A product in the catalogue.", "attributes": ["name","sku","category","price","return_window_days"], }, { "type": "Ticket", "description": "A support case or complaint.", "attributes": ["issue_summary","status","resolution","sentiment"], }, ] } }, })
constresponse=awaitfetch("https://spectron.surrealdb.com/api/v1/contexts",{ method:"POST", headers:{ "API-KEY":"mgmt_...", "Content-Type":"application/json", }, body:JSON.stringify({ id:"support", display_name:"Customer Support", config:{ ontology:{ entities:[ { type:"Customer", description:"A person or organisation that has purchased or enquired about a product.", attributes:["name","email","plan","account_status","preferred_channel"], }, { type:"Product", description:"A product in the catalogue.", attributes:["name","sku","category","price","return_window_days"], }, { type:"Ticket", description:"A support case or complaint.", attributes:["issue_summary","status","resolution","sentiment"], }, ], }, }, }), });
Step 2 – Ingest the product catalogue into authoritative knowledge
Upload your product catalogue as a document. Spectron chunks it, extracts keywords, and creates knowledge nodes that agents can query.
Each customer conversation is a session scoped to that customer's user_id. The scope ensures that Customer entity attributes (past tickets, preferences, purchase history) are isolated per customer.
Before generating a response, retrieve relevant memory. The context() call performs hybrid retrieval across authoritative knowledge and experiential memory, returning a ranked summary the agent can use.
asyncdefrespond(session,user_message: str) -> str: # 1. Retrieve relevant context from both layers ctx=awaitsession.context(query=user_message,top_k=8)
# 2. Build the system prompt system=f"""You are a customer support agent for Acme Corp. Use the context below to answer accurately.
{ctx.formatted}"""
# 3. Call your LLM response=your_llm(system=system,user=user_message)
# 4. Record both turns so Spectron extracts memory from the exchange awaitsession.turn(role="user",content=user_message) awaitsession.turn(role="assistant",content=response)
returnresponse
asyncfunctionrespond(session:Session,userMessage:string):Promise<string>{ // 1. Retrieve relevant context from both layers const ctx =awaitsession.context({query:userMessage,topK:8});
// 2. Build the system prompt constsystem=`You are a customer support agent for Acme Corp. Use the context below to answer accurately.
${ctx.formatted}`;
// 3. Call your LLM constresponse=awaityourLlm({system,user:userMessage});
// 4. Record both turns awaitsession.turn({role:"user",content:userMessage}); awaitsession.turn({role:"assistant",content:response});
returnresponse; }
Step 5 – What the agent sees
After a few interactions, the context retrieval for a query like "what is your return policy for AirPods?" will surface:
authoritative knowledge: The return policy knowledge node (authoritative: 30 days, no opened packaging).
authoritative knowledge: The AirPods Pro product node (price, SKU, warranty terms).
experiential memory: The customer entity with attributes – plan tier, previous ticket about a delivery issue, preferred contact channel.
The agent answers the return policy question correctly from authoritative knowledge and can personalise the response ("since you're on the Pro plan, you also have extended phone support") using experiential memory context.
Step 6 – Querying a customer's memory directly
At any point you can inspect what Spectron knows about a specific customer:
This is useful for building agent dashboards, pre-populating ticket forms, or debugging unexpected agent behaviour.
Authoritative and Experiential interaction
When a customer says "your return policy is actually 60 days", Spectron stores their belief under the Experiential pillar and surfaces the conflict with the curated policy under the Authoritative pillar — the document record is not updated.