r/SQLv2 • u/Alternative_Pin9598 • 13d ago
SQLv2 Lesson 6: your first learning goal. The database tries two sources, checks each answer with SQL, keeps score, and switches when the policy changes (beginner)
Lesson 6 of the beginner series, run on SynapCores 2.3.2 this morning with the output pasted. (This sub is run by the SynapCores team.)
The problem
Your support bot answers "how long do refunds take?" from the FAQ or the policy page. Only one is approved by legal at a time, and which one changes. Hard-code "use the policy page" and the bot breaks the day legal rewrites the FAQ instead.
What you want: try a source, check the answer against the database, keep score, prefer whatever has been passing. That's a learning goal.
Step 1: the data
CREATE TABLE refund_answers (source TEXT PRIMARY KEY, approved INTEGER, answer TEXT);
INSERT INTO refund_answers (source, approved, answer) VALUES
('faq', 0, 'Refunds take 5 business days.'),
('policy_page', 1, 'Refunds reach your card within 10 business days after we receive the item.');Step 2: the goal
A goal = what you want done + ways to try it + a success check, sent as JSON to POST /v1/agents/goals. The important parts:
"task_type": "refund-question", "learn": true, "explore": 0.1,
"guardrails": {"allowed_actions": ["sql"]},
"steps": [{
"action": SELECT approved, answer FROM refund_answers WHERE source = 'faq'
"alternatives": SELECT approved, answer FROM refund_answers WHERE source = 'policy_page'
"acceptance": {"kind": "json_equals", "pointer": "/rows/0/0", "expected": 1}
}]In plain words:
- Two strategies: FAQ first, policy page second.
- Success check: first column of the first row must be
1(approved). The database decides, not a model. - learn = true: keep a score per strategy for this
task_type. Off unless you ask. - explore = 0.1: now and then try the other one anyway, so a change gets noticed.
- guardrails: SQL only.
(Full goal JSON and the 20-line runner are in the first comment.)
Step 3: six customers ask the question
question 1: done tried: faq -> policy_page
question 2: done tried: policy_page
question 3: done tried: policy_page
question 4: done tried: policy_page
question 5: done tried: policy_page
question 6: done tried: policy_pageQuestion 1 tried the FAQ, failed the check (not approved), and fell back. From question 2 on, it goes straight to the policy page.
Step 4: look at what it learned (plain SQL)
SHOW AGENT POLICY;Output for this task type (trimmed):
{"action": "sql:faq", "count": 1, "reward_sum": -1.0, "mean": -1.0}
{"action": "sql:policy_page", "count": 6, "reward_sum": 6.0, "mean": 1.0}Each try scores +1 (passed) or -1 (failed). A tally sheet you can query, not a trained model.
Step 5: legal changes the policy
UPDATE refund_answers SET approved = 0 WHERE source = 'policy_page';
UPDATE refund_answers SET approved = 1,
answer = 'Refunds reach your card within 7 business days after we receive the item (new policy).'
WHERE source = 'faq';Eight more customers ask:
question 7: done tried: policy_page -> faq
question 8: done tried: policy_page -> faq
question 9: done tried: policy_page -> faq
question 10: done tried: faq
question 11: done tried: faq
...
question 14: done tried: faq
{"action": "sql:faq", "count": 9, "reward_sum": 7.0, "mean": 0.78}
{"action": "sql:policy_page", "count": 9, "reward_sum": 3.0, "mean": 0.33}Three fallbacks, then the score flips and the bot prefers the FAQ, with no code change. Every customer still got the approved answer, because the check ran on every try. And "success" is a check on your own data, so it means what you say it means.
Homework
Legal un-approves both sources (UPDATE refund_answers SET approved = 0;). Question 15 comes in.
- Does the bot answer? With what?
- What happens to the two scores?
- Is that the behaviour you want from a support bot, and why?
Reply with your guesses and I'll post the real output.
Free Community Edition, if you want to run this yourself: https://synapcores.com/download?utm_source=reddit&utm_medium=owned&utm_campaign=sqlv2-lesson-6
Where does "which source is the approved one right now" live at your work: a flag in a table, a doc owner, or tribal knowledge?
1
u/Alternative_Pin9598 13d ago
The full goal (one per customer question;
namemust be unique):Allow the persona to run SQL first (goals are off by default; nothing runs until you allow it):
GET /v1/agents/learning/config?database=main, add"lesson6-desk": ["sql"]underpersona_actions, andPUTit back.The runner (Python, standard library only):
Which strategy each attempt used is in
GET /v1/agents/goals/{id}/planundersteps[0].action_attempts(action_index0 = faq, 1 = policy_page).Clean up:
DROP TABLE refund_answers;and remove the persona from the config.Want to run this on the real engine? r/synapcores is the product home: install steps, the 5 recipes to try first, and a new recipe every Monday. Start here: https://www.reddit.com/r/synapcores/comments/1xfxqej/
Missed Lesson 5 (graph hops + meaning search in one database)? https://www.reddit.com/r/SQLv2/comments/1xq8g8l/