Help assistant setup (operator)
This article is for the operator: how to switch the help assistant on, what it records, what it costs, who can use it, and what to do when it does not answer. What users see is in the article The help assistant.
What is the help assistant?
A small chat panel in the web app that answers questions about KolorIQ from the help articles in
docs/help/en/kb/, and only from them. It never reads a user's studies, results or account.
How an answer is made:
- The question is scrubbed: email addresses, phone numbers and runs of 6 or more digits are
replaced with
[email],[phone]and[number]. Only the scrubbed text is stored, logged or sent to the model. - A word index over the help articles finds the best sections. Each article is split at its
##and###headings. Words in titles and headings count extra. There are no embeddings and no second AI provider. - If nothing matches well enough, the user gets a fixed sentence and no model is called. The question is kept as a gap for you to read.
- Otherwise the best sections (at most 4, about 6,000 characters in all) go to the model with instructions to answer only from them. The answer links to those sections; each link is named "Article title: Section heading".
- The answer is cleaned: no HTML, no links and no bare web addresses. An answer that comes back
empty or refused, or that uses one of the phrases
marketsim/wording.pyflags (a negation of such a phrase is allowed), is replaced with the fixed sentence and kept as a gap.
Operator articles (title ending "(operator)", like this one) are used only for operators.
Who can use it?
An account can use the assistant when it is signed in and has been let in: not on the waiting list and not held. No purchase is needed: the free survey is enough. Operators can always use it.
Listing, opening and deleting one's own saved chats need only the sign-in: they work while the assistant is off and while the account is held. Asking, saving, renaming and emailing need the rule above.
An account on the waiting list or on hold sees the "opens when your account does" refusal below.
Getting started (operator, in this order)
Apply the migrations
supabase/migrations/0014_help_assistant.sqlafter0013, and0015_limits_server_only.sqlafter it, then run the verification queries in their headers. All four tables must show row-level security on,anonandauthenticatedmust hold nothing onhelp_usageandhelp_gaps, andauthenticatedmay only readhelp_chatsandhelp_messages: every write goes through the API.Make sure the API can read the help articles. By default it reads
docs/help/en/kbin the repository. If the API runs from a container or a folder without thedocsfolder, copy the articles there and setHELP_DIRto that folder.Set the model provider. The assistant uses the same provider as the rest of the API:
MARKETSIM_PROVIDER=anthropicwithANTHROPIC_API_KEYset. Withfake, answers are canned test sentences: use that only to check the routes.Set the assistant's settings on the API server, by name:
Name Default Meaning HELP_ASSISTANToff 1switches the assistant onHELP_ASSISTANT_MODELclaude-haiku-5-5The model that writes the answers HELP_DAILY_BUDGET_USD2When today's assistant cost reaches it, the assistant rests until tomorrow HELP_QUESTIONS_PER_DAY30Questions per account in 24 hours HELP_DIRdocs/help/en/kbWhere the articles are. A relative path is read from the repository root Restart the API. The index is built once per process, the first time someone asks.
Check it works:
- Signed in as an operator, open any page except the console. The round help button appears.
- Ask "How do I read my result?". The answer links to the help article it came from.
- Ask something the help does not cover, such as "What is the capital of France?". You get "The help does not cover that yet. We have noted the question. You can also reply to any email from us."
- Open the console's Help tab. Today shows 2 questions, 1 answered, 1 gap, and the gap is listed with the page you asked from.
What is recorded, and for how long?
| What | Where | Holds | Kept |
|---|---|---|---|
| Chats | help_chats, help_messages |
The account's own chat: the scrubbed questions, the answers, the links. Row-level security: a user reads own rows only and writes nothing directly; the API writes with the caller's verified id | Unsaved: 24 hours without use (gone at once, removed at the next prune). Saved: 180 days without use. Removed with the account |
| Cost | help_usage |
Time, answered or not, model, tokens, cost in USD. No account id | 400 days |
| Gaps | help_gaps |
The day (not the time), the scrubbed question, the route it was asked from (such as /studies/[id] or /r/[slug]; a help article keeps its slug; any other page only its first part), the best-matching article. No account id |
180 days |
| Question count | account_actions, action help_ask |
One row per question, for the per-account limit | 24 hours |
Old rows are removed by the API whenever someone asks a question or lists their saved chats, and by each running worker about once an hour, in its regular pass. An unsaved chat that has gone 24 hours without use cannot be opened, saved, renamed, emailed or deleted from then on ("Chat not found."), even before it is removed.
The links stored with an answer are never trusted as links: the page and the email rebuild each one from the article's slug and the heading's anchor, and drop any that are not lower-case letters, digits and hyphens.
You, as the operator, can read stored chats in the database if you must investigate a fault. The console shows only the gaps, and those carry no account.
A chat that is emailed is sent only to the account's own address, as a service email. It is
logged in email_log as help-chat, by kind only.
What does it cost, and what are the two limits?
Each answer records its cost from the token counts and the price list in marketsim/cost.py. A
question the help does not cover costs nothing: no model is called. With the default model, one
answer is a fraction of a cent.
- Daily budget. When today's total reaches
HELP_DAILY_BUDGET_USD, every user gets the "resting until tomorrow" message until midnight, as the database counts the day (UTC on Supabase). - Per account. Each account may ask
HELP_QUESTIONS_PER_DAYquestions in any 24 hours. The refusal says when the next question can be asked. A question is given back only when the call to the model fails (the provider raises an error). One the help does not cover, or whose answer comes back empty, refused or with flagged wording, counts. - A failed call still costs. It is recorded with an estimated cost: every character sent counted as a third of a token, and a full-length answer. The budget is checked before each call and the cost added after it, so a day can end slightly over the budget by the answers being written at that moment.
A model not in the price list is costed as the dearest model on the list, so the budget errs on the
safe side. Add the model to marketsim/cost.py before you use it.
How do I read the Help tab in the console?
- The last 14 days: for each day, the questions asked, how many were answered from the help, the gaps, and the cost.
- Today's spend against the daily budget, and whether the assistant is switched on.
- The latest 50 unanswered questions, each with its day, the kind of page it was asked from
(such as
/studies/[id]) and the article that came closest. No time of day and no account.
Use the gaps list to write help: a question that keeps coming back needs a section whose heading uses the user's own words. After you add or change an article, restart the API so the index is built again.
The same figures come from GET /admin/ops/help?days=14 (operators only).
Limits
- It answers from the help articles only, in English. It cannot see a user's studies, results, payments or account.
- It is only as good as the help. A question whose words are not in any article is a gap.
- A follow-up question in the same chat is sent with the last few messages, so "and how long does that take?" works. When the follow-up alone matches nothing, it is looked up together with the previous question, but only if it shares at least one word with the help; otherwise it is a gap.
- A question that becomes longer than 1,000 characters when it is scrubbed is cut to 1,000.
- Questions are up to 1,000 characters.
- The links point at the section headings. The anchor of a heading is its text in lower case,
with anything but letters, digits, spaces and hyphens removed and spaces turned into hyphens. A
repeated heading in one article gets
-1,-2. The text before an article's first##heading links to the article itself. - The index is built once per process. A new or changed article is used after the next restart.
Troubleshooting
| Message or symptom | Cause | Fix |
|---|---|---|
| The help button does not appear | HELP_ASSISTANT is not 1, or the API was not restarted |
Set it and restart. The button is never shown in the console itself |
| "The help assistant is switched off at the moment. The help pages are open: choose Help in the menu." (409) | HELP_ASSISTANT is off |
Step 4 |
| "The help assistant opens when your account does. Until then the help pages are open: choose Help in the menu." (403) | The account is on the waiting list or held | Admit or release it in the console, if that is right |
| "The help assistant is resting until tomorrow. The help pages are open: choose Help in the menu." (503) | Today's cost reached HELP_DAILY_BUDGET_USD |
Wait for tomorrow, or raise the setting and restart. Check the Help tab for unusual use first |
| "You have asked 30 questions in 24 hours, which is the limit. You can ask again in about H h M min. The help pages are open in the meantime." (429; the numbers are the real ones) | The account reached HELP_QUESTIONS_PER_DAY |
Wait for the time shown, or raise the setting |
| "Type a question of up to 1,000 characters." (422) | The question was empty or too long | Shorten it |
| "The help assistant could not answer just now. Please try again in a moment." (502) | The model call failed: no key, a wrong model name, or the provider is down | Check MARKETSIM_PROVIDER, ANTHROPIC_API_KEY and HELP_ASSISTANT_MODEL. The API log has "help assistant provider failed:" and the error's class name only, never the question. The question was not counted; an estimated cost was recorded |
| "The help does not cover that yet. We have noted the question. You can also reply to any email from us." | No help section matched the question well enough (no model was called), or the model's answer was empty, refused or used flagged wording. The question counts | Read the gap in the Help tab and add or reword a section |
| Every question gets "The help does not cover that yet." | The API cannot find the articles: HELP_DIR is wrong or the folder is not in the container |
Step 2, then restart |
| "Chat not found." (404) | The chat belongs to another account, was deleted, or was an unsaved chat unused for 24 hours (removed or not) | Start a new chat |
| "help_prune failed:" in a worker's log | Migration 0014 is not applied on the worker's database |
Apply it (step 1). The worker tries again an hour later |
| "Give the chat a title of up to 80 characters." (422) | Save or rename with an empty title, or one over 80 characters | Give a shorter title |
| "This account has no email address to send to." (409) | The profile has no email address | Check the account in the console |
| "You have reached the limit of 10 chat emails in 24 hours. You can continue in about H h M min." (429) | More than 10 chats emailed in 24 hours by one account | Wait for the time shown |
| "The email could not be sent just now. Please try again in a moment." (502) | The mail provider did not accept the email | See Email setup |
"Operators only." (403) on GET /admin/ops/help |
The account is not an operator | See Run the API, step 5 |
| Answers read as test sentences that make no sense | MARKETSIM_PROVIDER is fake |
Step 3 |
| A new article is not used | The index was built before it was added | Restart the API |
| A link opens the article but not the section | The help page does not give that heading an id | Tell the developer: the ids must follow the rule under Limits |