Engineering · AI
How Cereby Figures Out Which Tool You Want: Our Intent Classifier
How we replaced an if/else chain with cheap rules first, a small model last, and a score that decides when to ask.
A student types "quiz me on cells". (Every message in this post is synthetic.) Biology, chemistry or computer science? When Cereby launched, its router was an if/else chain: "quiz" meant quiz generation, "explain" meant an explanation, and a keyword cannot tell which cells. For words like that one, we routed to the wrong subject roughly one time in four.
The chain had other blind spots. Given "explain derivatives then quiz me on them", it kept one action and dropped the other. And it never said "I don't know": every message produced an action, however poor the match. About 23% of requests needed clarification, about 15% ended in a correction, and "Cereby doesn't understand me" was a top-three support category.
In February we replaced the chain with the intent classifier, the step that reads each message and decides which of Cereby's tools it is for, or that it is for none. This post is how that first version was built. It is the first of three posts on the classifier; the others are Why Asking for a Test Gave You Flashcards, and How We Fixed It, from April, and When Cereby Should Ask What You Meant: Fixing Our Intent Classifier, from October.
A pinned quiz the chain could not see
Students can pin materials to a conversation with an @-mention: a note, a quiz, a flashcard set. The chain had no concept of them. A student who pinned a quiz and asked how they did got a generic explanation:
Cheap checks first, the model last
We built a pipeline of six phases instead. The early ones were pure functions: no network calls, under a millisecond each. They took the requests whose meaning was plain, and only a message that got past all of them reached a model. Here is the same pinned quiz going through it:
Files came first because a file changes what a message means: a student who uploads a syllabus PDF and says "add to calendar" wants a schedule built from that file. Pins came second: one pinned quiz and a question about how it went meant performance analysis, at 0.9. With two or more pinned, that check stood aside on purpose, so the general performance tool could merge them into one report card. The regex groups (search alone had over 20 forms) each returned an action, its parameters and a fixed confidence of 0.90 to 0.95, and the first to match won.
Every tool lived in one registry, 14 of them in February. The registry wrote the model's list of tools itself, so registering a tool updated the classifier's prompt, and it refused to start if a tool's description and its handler disagreed on an ID.
When the first match wins, the order is policy
The regex groups ran in order and the first match won, so the order was policy. The word "geographic" showed us how much. "Create a podcast on geographic data" matched a visualization guard before the podcast group had a chance to fire:
An explicit order (schedule, search, podcast, resource, learning goal, visualization) fixed a whole class of misroutes, not just this one.
A small model, asked for JSON
When no rule matched, we called a model. It was always a small, fast one, whatever the student had chosen for chat, which answered in roughly 200 ms and kept the cost of classifying fixed. It returned JSON: the action, its parameters, a confidence, up to three alternatives, a clarifying question if it needed one, the subject read from context, and an optional follow-up action. We also asked for log-probabilities (how sure the model was of each word it wrote) and took their mean, as a signal independent of the confidence the model reported. Alongside the tools, it read a summary of the student's weak points, events, recent materials and pins, the last few messages, the date, and about 25 examples of edge cases.
Then the student's own words got the last say. A regex extractor pulled the subject out of the message and overrode the model's reading ("quiz on kubernetes" means Kubernetes). For "quiz on this", the subject the model read from context filled the gap. And a few rules corrected the model's known habits, such as turning a stated fact back into no action at all.
Not every provider played along. Some refused log-probabilities, or structured output, outright. We caught the error, retried without both, and let that factor fall back to a moderate default. If the model call failed entirely, a keyword fallback still returned something usable.
Five factors and the model's word
Models overestimate their certainty, so we did not take the model's number on its own. A scorer weighted five factors and blended them with the model's confidence, giving the five the larger share:
Past accuracy was the success rate of recent classifications of the same action for the same student, lowered by each correction. Context fit asked whether the topics matched the student's weak points and recent quizzes. Below the threshold, an ambiguity detector named the doubt ("this" with nothing to point at, or a subject like "cells", "waves" or "bonds" that belongs to several disciplines), and a generator turned it into a question with up to three alternatives. The app showed them as options; one tap chose the action.
Some of that doubt was not doubt at all: the gate asked questions the pin had already answered. "Quiz on this" with a note pinned could score below the threshold and ask the student which topic they meant. The pin was the topic. From then on, a request for a quiz, notes or flashcards with something pinned skipped the gate, and that one rule removed most of our false clarifications.
Two actions in one message
Students do not think in single actions. From February, a message that chained two was split, and the second rode along as a follow-up:
"explain photosynthesis then quiz me on it" synthetic
sequence word "then" → the second depends on the first
primary action explanation
follow-up action quiz generation → checked against the registered tools
response the explanation, with the quiz attached
→ the app starts the quiz once the explanation is done
In the chat, that is one message and two results: the explanation, then the quiz:
One message, two results, in chat today, on a synthetic conversation.
Before and after
Accuracy, and complex requests with more than one action in them:
And the share of requests that needed a clarifying question or a correction:
Accuracy went from about 77% to about 95%, multi-intent requests from about 45% to about 89%, clarification from about 23% to about 7%, and corrections from about 15% to about 3%. Average confidence came out at 0.87, and tickets saying "Cereby doesn't understand me" fell by roughly 31%. The change students felt was simpler: "quiz on this" with a pinned note worked on the first try, and a low-confidence guess showed its alternatives instead of quietly running the wrong tool.
What this taught us
Self-reported confidence is not enough on its own. Blending the model's number with log-probabilities, pattern strength and past accuracy gave us a score that actually tracked correctness.
Pinned context is the strongest signal we have. When a student attaches material on purpose, the classifier should trust it over everything else, including its own doubt.
When rules run in order, the order is a decision. The guard that caught a podcast request was a good pattern in the wrong place.
What's next
Two things were still under-solved in February. Several actions, flashcard generation in particular, had no deterministic patterns and relied entirely on the model. And follow-ups ran one after another in the app; orchestrating them on the server, with their dependencies tracked, would let independent ones run side by side.