Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Evals: a turn-routing baseline for classifyTurn, with short decisions, unlisted tool verbs and other languages

Divya Jyoti7126e8fb0123
diff --git a/evals/README.md b/evals/README.md
index 7dde2997fa..3436dbbda6 100644
--- a/evals/README.md
+++ b/evals/README.md
@@ -94,3 +94,9 @@ The skill bench measures one fixture skill against its own prompts through the s
node --experimental-strip-types evals/runners/run-skill-bench.ts [--fixture bench-triage-handoff] [--replicates 2]
The alpha report gives per-arm pass rates, duration and estimated tokens (chars/4 over evidence turns; the scripted provider makes no API calls) with mean and standard deviation, a delta-per-assertion table, and two flags: non-discriminating assertions (identical verdicts in both arms — controls, not effects) and high-variance assertions (verdicts that flip across replicates of the same prompt and arm, assessable from two replicates on). `evals/skill-bench/fixtures/` holds bench fixtures; `evals/skill-bench/triggers/` holds the trigger-eval sets (should-trigger / should-not-trigger with train and held-out splits, plus near misses) that a later router slice validates against — data only, no router code.
+
+## Turn routing — which turns can a quick model take
+
+`evals/turn-routing` runs `classifyTurn` (`server/turn-route.ts`) over labelled messages. Each case says the tier a person would pick: `simple` when a quick model answers as well as the full one. A miss is `cautious` (the full model for a simple turn, which costs only money) or `eager` (the quick model for a turn that needed the full one, which costs the answer). The cases lean towards the hard ones: short weighty decisions, tool requests whose verb is not in the action list, and other languages. So the counts are a baseline for a router to beat, not an accuracy rate. The test pins today's misses; a router change updates them in the same PR.
+
+ npx vitest run --config evals/vitest.config.ts evals/turn-routing
diff --git a/evals/turn-routing/cases.json b/evals/turn-routing/cases.json
new file mode 100644
index 0000000000..f748a851c5
--- /dev/null
+++ b/evals/turn-routing/cases.json
@@ -0,0 +1,45 @@
+[
+ { "id": "greeting", "lang": "en", "text": "hi!", "want": "simple", "why": "Small talk." },
+ { "id": "thanks", "lang": "en", "text": "thanks, that's perfect", "want": "simple", "why": "An acknowledgement." },
+ { "id": "capital", "lang": "en", "text": "What's the capital of Peru?", "want": "simple", "why": "One well-known fact." },
+ { "id": "how-are-you", "lang": "en", "text": "how's your day going?", "want": "simple", "why": "Small talk." },
+ { "id": "define-word", "lang": "en", "text": "what does 'ephemeral' mean?", "want": "simple", "why": "A definition." },
+ { "id": "joke", "lang": "en", "text": "tell me a joke about cats", "want": "simple", "why": "Light, no stakes." },
+ { "id": "thanks-after-tools", "lang": "en", "text": "great, thank you", "priorTurnUsedTools": true, "want": "simple", "why": "An acknowledgement after tool work." },
+
+ { "id": "haiku", "lang": "en", "text": "write me a haiku about rain", "want": "simple", "why": "Short creative line; a quick model writes it as well." },
+ { "id": "translate-phrase", "lang": "en", "text": "translate 'good morning' into French", "want": "simple", "why": "A two-word phrase." },
+ { "id": "synonym", "lang": "en", "text": "find a synonym for happy", "want": "simple", "why": "One word back." },
+ { "id": "stuck-jar", "lang": "en", "text": "how do I open a jar that's stuck?", "want": "simple", "why": "Everyday tip." },
+ { "id": "run-in-rain", "lang": "en", "text": "is it ok to run in the rain?", "want": "simple", "why": "Everyday question; 'run' is not an action for the bot." },
+ { "id": "percent", "lang": "en", "text": "what's 15% of 80?", "want": "simple", "why": "Simple arithmetic." },
+ { "id": "word-test", "lang": "en", "text": "test", "want": "simple", "why": "The person checking the bot answers." },
+
+ { "id": "fix-test", "lang": "en", "text": "fix the failing test in server/turn-route.ts", "want": "complex", "why": "Code work with tools." },
+ { "id": "research-compare", "lang": "en", "text": "research the top 5 note-taking apps and compare their pricing", "want": "complex", "why": "Multi-step research." },
+ { "id": "summarise-url", "lang": "en", "text": "summarise https://example.com/report", "want": "complex", "why": "Reads a page with a tool." },
+ { "id": "go-ahead", "lang": "en", "text": "yes, go ahead", "priorTurnUsedTools": true, "want": "complex", "why": "Continues tool work already planned." },
+ { "id": "follow-up-after-tools", "lang": "en", "text": "and the second one?", "priorTurnUsedTools": true, "want": "complex", "why": "Continues tool work." },
+ { "id": "photo", "lang": "en", "text": "what is this?", "attachments": 1, "want": "complex", "why": "Reads an image." },
+
+ { "id": "remind-me", "lang": "en", "text": "remind me to call mom at 5", "want": "complex", "why": "Sets a reminder with a tool; 'remind' is not in the action words." },
+ { "id": "calendar", "lang": "en", "text": "what's on my calendar tomorrow?", "want": "complex", "why": "Reads a connected app." },
+ { "id": "check-inbox", "lang": "en", "text": "check my inbox for anything from Priya", "want": "complex", "why": "Reads email with a tool; 'check' is not in the action words." },
+ { "id": "tell-team", "lang": "en", "text": "tell the team the launch moved to Friday", "want": "complex", "why": "Sends a message to people." },
+ { "id": "order-food", "lang": "en", "text": "order me a margherita from the usual place", "want": "complex", "why": "Acts and spends money." },
+
+ { "id": "job-offer", "lang": "en", "text": "should I take the Stripe offer or stay at my startup?", "want": "complex", "why": "A weighty personal decision that needs careful reasoning." },
+ { "id": "offers-after-tax", "lang": "en", "text": "which pays more after tax, 140k in SF or 120k in Austin?", "want": "complex", "why": "Multi-step reasoning with numbers that matter." },
+ { "id": "mole", "lang": "en", "text": "is this mole on my arm worth seeing a doctor about?", "want": "complex", "why": "Health: a wrong quick answer is costly." },
+ { "id": "lease-clause", "lang": "en", "text": "my landlord wants to keep my deposit for normal wear, is that legal in California?", "want": "complex", "why": "Legal question with real stakes." },
+ { "id": "fire-cofounder", "lang": "en", "text": "how do I tell my cofounder I want them to step down?", "want": "complex", "why": "A high-stakes conversation to plan." },
+
+ { "id": "es-greeting", "lang": "es", "text": "hola, ¿qué tal?", "want": "simple", "why": "Small talk." },
+ { "id": "es-search-flights", "lang": "es", "text": "busca vuelos a Madrid para el viernes", "want": "complex", "why": "A search with tools, in Spanish." },
+ { "id": "de-thanks", "lang": "de", "text": "danke!", "want": "simple", "why": "An acknowledgement." },
+ { "id": "de-write-email", "lang": "de", "text": "schreib eine E-Mail an meinen Chef, dass ich morgen später komme", "want": "complex", "why": "Writes and sends email, in German." },
+ { "id": "hi-reminder", "lang": "hi", "text": "कल सुबह 9 बजे का रिमाइंडर लगा दो", "want": "complex", "why": "Sets a reminder, in Hindi." },
+ { "id": "hi-greeting", "lang": "hi", "text": "नमस्ते, कैसे हो?", "want": "simple", "why": "Small talk." },
+ { "id": "ja-summarise", "lang": "ja", "text": "明日の会議の資料をまとめて", "want": "complex", "why": "Summarises tomorrow's meeting documents, in Japanese." },
+ { "id": "ja-decision", "lang": "ja", "text": "転職すべきか迷っています", "want": "complex", "why": "A weighty decision (whether to change jobs), in Japanese." }
+]
diff --git a/evals/turn-routing/score.test.ts b/evals/turn-routing/score.test.ts
new file mode 100644
index 0000000000..f485426bb0
--- /dev/null
+++ b/evals/turn-routing/score.test.ts
@@ -0,0 +1,56 @@
+import { readFileSync } from "node:fs";
+import { describe, expect, it } from "vitest";
+import { routeCase, summarize, type RoutingCase } from "./score.ts";
+
+const cases = JSON.parse(readFileSync(new URL("./cases.json", import.meta.url), "utf8")) as RoutingCase[];
+
+describe("turn-routing scoring", () => {
+ const item: RoutingCase = { id: "x", lang: "en", text: "hi", want: "simple", why: "w" };
+
+ it("names which way a miss goes", () => {
+ expect(routeCase(item, () => "simple").verdict).toBe("right");
+ expect(routeCase(item, () => "complex").verdict).toBe("cautious");
+ expect(routeCase({ ...item, want: "complex" }, () => "simple").verdict).toBe("eager");
+ });
+
+ it("passes the case's signals to the classifier, with plain defaults", () => {
+ const seen: unknown[] = [];
+ routeCase(item, (signals) => (seen.push(signals), "simple"));
+ routeCase({ ...item, attachments: 2, priorTurnUsedTools: true }, (signals) => (seen.push(signals), "simple"));
+ expect(seen).toEqual([
+ { text: "hi", attachments: 0, priorTurnUsedTools: false },
+ { text: "hi", attachments: 2, priorTurnUsedTools: true },
+ ]);
+ });
+
+ it("adds up a run, in total and per language", () => {
+ const rows = [routeCase(item, () => "simple"), routeCase({ ...item, lang: "es" }, () => "complex")];
+ expect(summarize(rows)).toEqual({
+ cases: 2, right: 1, cautious: 1, eager: 0,
+ byLang: { en: { cases: 1, right: 1, cautious: 0, eager: 0 }, es: { cases: 1, right: 0, cautious: 1, eager: 0 } },
+ });
+ });
+});
+
+describe("turn-routing cases", () => {
+ it("each case is well formed", () => {
+ expect(new Set(cases.map((c) => c.id)).size).toBe(cases.length);
+ for (const c of cases) {
+ expect(["simple", "complex"], c.id).toContain(c.want);
+ expect(c.text.trim().length, c.id).toBeGreaterThan(0);
+ expect(c.why.length, c.id).toBeGreaterThan(0);
+ }
+ });
+
+ it("pins today's classifyTurn on these cases, so a router change shows what it moved", () => {
+ const rows = cases.map((c) => routeCase(c));
+ const misses = (verdict: string) => rows.filter((row) => row.verdict === verdict).map((row) => row.id);
+ expect(summarize(rows)).toMatchObject({ cases: 38, right: 16, cautious: 7, eager: 15 });
+ expect(misses("eager")).toEqual([
+ "remind-me", "calendar", "check-inbox", "tell-team", "order-food",
+ "job-offer", "offers-after-tax", "mole", "lease-clause", "fire-cofounder",
+ "es-search-flights", "de-write-email", "hi-reminder", "ja-summarise", "ja-decision",
+ ]);
+ expect(misses("cautious")).toEqual(["thanks-after-tools", "haiku", "translate-phrase", "synonym", "stuck-jar", "run-in-rain", "word-test"]);
+ });
+});
diff --git a/evals/turn-routing/score.ts b/evals/turn-routing/score.ts
new file mode 100644
index 0000000000..54af39c3ae
--- /dev/null
+++ b/evals/turn-routing/score.ts
@@ -0,0 +1,44 @@
+import { classifyTurn, type TurnTier } from "../../server/turn-route.ts";
+
+export interface RoutingCase {
+ id: string;
+ lang: string;
+ text: string;
+ attachments?: number;
+ priorTurnUsedTools?: boolean;
+ /** The tier a person would pick: simple when a quick model answers as well as the full one. */
+ want: TurnTier;
+ why: string;
+}
+
+/** `cautious`: the full model for a simple turn, which only costs money. `eager`: the quick model for a turn that needed the full one, which costs the answer. */
+export type Verdict = "right" | "cautious" | "eager";
+
+export interface RoutingRow {
+ id: string;
+ lang: string;
+ want: TurnTier;
+ got: TurnTier;
+ verdict: Verdict;
+}
+
+export function routeCase(testCase: RoutingCase, classify: typeof classifyTurn = classifyTurn): RoutingRow {
+ const got = classify({ text: testCase.text, attachments: testCase.attachments ?? 0, priorTurnUsedTools: testCase.priorTurnUsedTools ?? false });
+ const verdict: Verdict = got === testCase.want ? "right" : got === "complex" ? "cautious" : "eager";
+ return { id: testCase.id, lang: testCase.lang, want: testCase.want, got, verdict };
+}
+
+export function summarize(rows: readonly RoutingRow[]) {
+ const count = (verdict: Verdict, of: readonly RoutingRow[] = rows) => of.filter((row) => row.verdict === verdict).length;
+ const langs = [...new Set(rows.map((row) => row.lang))].sort();
+ return {
+ cases: rows.length,
+ right: count("right"),
+ cautious: count("cautious"),
+ eager: count("eager"),
+ byLang: Object.fromEntries(langs.map((lang) => {
+ const of = rows.filter((row) => row.lang === lang);
+ return [lang, { cases: of.length, right: count("right", of), cautious: count("cautious", of), eager: count("eager", of) }];
+ })),
+ };
+}