Objective
Tier-1 tickets ("export failed", "password reset", "where is my invoice") eat 60% of support headcount. Generic RAG bots answer the wrong question because they don't see the customer's actual state. This recipe builds an agent that reads the docs AND the customer's recent activity in one call, then either resolves the ticket or escalates with the full context attached.
Step 1: Create accounts, exports, tickets, docs
CREATE TABLE IF NOT EXISTS recipe_sa_accounts (
account_id INTEGER PRIMARY KEY,
email TEXT,
plan TEXT,
created_at TIMESTAMP,
last_login TIMESTAMP
);
CREATE TABLE IF NOT EXISTS recipe_sa_exports (
export_id INTEGER PRIMARY KEY,
account_id INTEGER,
filename TEXT,
status TEXT, -- 'queued' | 'completed' | 'failed'
bytes BIGINT,
started_at TIMESTAMP,
completed_at TIMESTAMP,
error_msg TEXT
);
CREATE TABLE IF NOT EXISTS recipe_sa_tickets (
ticket_id INTEGER PRIMARY KEY,
account_id INTEGER,
subject TEXT,
body TEXT,
opened_at TIMESTAMP
);
CREATE TABLE IF NOT EXISTS recipe_sa_docs (
doc_id INTEGER PRIMARY KEY,
title TEXT,
body TEXT,
embedding VECTOR(384)
);
Step 2: Seed
INSERT INTO recipe_sa_accounts VALUES
(1,'alice@example.com','pro', '2025-12-01 09:00:00','2026-05-26 14:33:00'),
(2,'bob@example.com', 'starter', '2026-02-15 10:30:00','2026-05-24 09:11:00'),
(3,'carol@example.com','pro', '2025-06-22 16:45:00','2026-05-22 20:02:00');
INSERT INTO recipe_sa_exports VALUES
(9001,1,'q1-data.csv','completed', 1240000,'2026-05-25 09:00:00','2026-05-25 09:00:42',NULL),
(9002,1,'may-data.csv','completed',2510000,'2026-05-26 11:00:00','2026-05-26 11:01:08',NULL),
(9003,1,'audit.csv','completed', 980000,'2026-05-26 14:30:00','2026-05-26 14:30:31',NULL),
(9004,2,'big-extract.csv','failed', 0, '2026-05-24 09:10:00',NULL,'export size exceeds starter plan limit of 100k rows; upgrade or filter your query'),
(9005,3,'monthly.csv','queued', 0, '2026-05-22 22:00:00',NULL,NULL);
INSERT INTO recipe_sa_tickets VALUES
(4521,1,'Export not arriving','I exported some data this morning but never got an email link. Did it fail?','2026-05-26 14:50:00'),
(4522,2,'Export keeps failing','My exports always fail. What is wrong with the platform?','2026-05-24 09:20:00');
INSERT INTO recipe_sa_docs (doc_id, title, body) VALUES
(1,'Export Delivery','Exports are emailed to the account holder upon completion. Delivery typically takes under 2 minutes from the completion timestamp. If you do not see the email, check spam folders and trusted-sender settings before contacting support.'),
(2,'Export Failures','Export jobs may fail when the result set exceeds the plan limit. Starter plan: 100k rows. Pro: 10M rows. Enterprise: unlimited. Failed exports leave a diagnostic message in the export-status report.'),
(3,'Plan Limits','Plan limits cover storage, API calls, and export size. Limits are listed in your account dashboard. Upgrades take effect immediately and are pro-rated.'),
(4,'Password Reset','Customers can reset passwords from the login page. The reset email arrives within 5 minutes. If not received, check spam, then contact support.'),
(5,'Billing Cycle','Invoices are sent on the first of each month. Plan changes mid-cycle are pro-rated to the day.');