Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
evals: a small live tool-choice eval, and why the tool bridge stays off by default
milind-soni8b52dbdbfc7f
diff --git a/docs/agents-tool-bridge.md b/docs/agents-tool-bridge.mdindex 360e0a9bae..6aab7cfaa5 100644--- a/docs/agents-tool-bridge.md+++ b/docs/agents-tool-bridge.md@@ -22,6 +22,22 @@ network. A small window cannot spare the full list, so those bots get the bridgewithout the switch. `OMB_AGENTS_TOOL_BRIDGE=0` turns that off too, and the rulesunder "Which bots and engines get it" still apply.+## Why it stays off by default++A live run of `evals/tool-choice` (6 requests that went wrong in real use, each picking a tool the bridge hides, one real Sonnet+turn each) reached the right tool every time, bridged or not, but did not save money on those turns:++| Tool list | Reached the right tool | Cost of the 6 turns | Looked a tool up first |+|---|---|---|---|+| Full catalog | 6 of 6 | $0.56 | 0 of 6 |+| Bridged | 6 of 6 | $0.58 | 5 of 6, 3 of them through `ToolSearch` as well |++A hidden tool costs one more model call, and `find_tool` brings up to three full schemas into the conversation. A bridged first+request is 13k tokens smaller, which matters most on a turn that uses no hidden tool, but once new threads and new bots+read a shared prompt cache, those 13k tokens cost only about $0.003 a call. By our estimate the saving and the extra calls roughly cancel out on a+busy day, so the small-window case above is the reason to use it, not cost. These are 6 runs on one model, chosen as the bridge's+worst case. Run the eval again before changing this.+## Turning it onIn `~/.openmausbot/config.json`:diff --git a/evals/README.md b/evals/README.mdindex ab841efc00..07c56ca3aa 100644--- a/evals/README.md+++ b/evals/README.md@@ -51,6 +51,18 @@ Turn a real coordination thread into a synthetic fixture, then replay it throughThe redaction step rewrites ids, names, and free text into stable synthetic placeholders and runs a leak scan before writing anything, so a real thread becomes reviewable, committable data. Commit both the redacted scenario and the regenerated baseline under `evals/golden/baselines/`; replay asserts the stable tool traces and outcomes — turn order, tool-call names, dispatch targets, handoff-tree shape — against that baseline.+## Tool choice — does a real model reach the right tool?++`evals/tool-choice` holds requests that went wrong in real use, in the words people used, each with the tools that would have+been right. It runs a real model against the tool list as shipped, one thread per case on one bot, and prints which tool each+case reached, whether it looked it up first, and what the turn cost. Use it before changing the tool list: the agents tool+bridge, a shorter description, a removed built-in.++ OMB_EVAL_LIVE=1 OMB_EVAL_LIVE_INSTANCE='{"instanceId":"claude","driver":"claudeAgent","model":"claude-sonnet-5","config":{"cli":"/path/to/claude"},"environmentFrom":["HOME","USER"]}' \+ node --experimental-strip-types evals/tool-choice/run-tool-choice.ts --only trigger-on-new-mail,what-did-we-decide++Each case is one real turn on your account, so name the cases you need. It is closed unless `OMB_EVAL_LIVE=1`, never runs in CI, and its data folder is temporary. Add `OMB_AGENTS_TOOL_BRIDGE=1 OMB_EVAL_LIVE_PASS_ENV=OMB_AGENTS_TOOL_BRIDGE` to try the bridge. Only the scoring has an offline test.+## Tier 3 — opt-in live-model smokeLive-model runs never execute by default: `pnpm eval --live` prints one skip line and exits 0 unless the gate is open.diff --git a/evals/tool-choice/cases.json b/evals/tool-choice/cases.jsonnew file mode 100644index 0000000000..883a885340--- /dev/null+++ b/evals/tool-choice/cases.json@@ -0,0 +1,14 @@+[+ { "id": "trigger-on-new-mail", "tools": ["trigger", "trigger_info"], "text": "Bitte nicht mehr regelmäßig nachsehen. Starte dich automatisch, sobald eine neue Mail eintrifft.", "why": "Asked for an event trigger in place of polling." },+ { "id": "my-own-computer", "tools": ["ask_for_computer", "list_shared_computers", "select_computer", "shared_computer"], "text": "Mach das bitte über meinen Mac mini.", "why": "Asked for a named computer in two words." },+ { "id": "what-did-we-decide", "tools": ["session_search"], "text": "Was hatten wir letzte Woche mit dem Lieferanten vereinbart?", "why": "Asked about an earlier conversation." },+ { "id": "is-it-still-running", "tools": ["assignment_status", "list_threads", "list_bots"], "text": "Is anything you handed to a teammate still running? Check, don't guess.", "why": "Asked for the state of hand-offs." },+ { "id": "tell-the-team", "tools": ["report_bug"], "text": "Please report this to the OpenMausBot team: the password card never showed up on my desktop.", "why": "Filed a bug with the people who make the app." },+ { "id": "which-triggers", "tools": ["trigger_info", "trigger"], "text": "Which automations do you have set up right now?", "why": "Asked what runs on its own." },+ { "id": "how-close-to-my-limit", "tools": ["usage_limits"], "text": "How close am I to my Claude limit right now?", "why": "Worried about spending his window." },+ { "id": "show-a-chart", "tools": ["show_widget", "show_html"], "text": "Show me a tiny bar chart right here in the chat: Monday 3, Tuesday 5, Wednesday 2.", "why": "Asked for something drawn in the chat." },+ { "id": "ask-the-chief", "tools": ["coordinate_bots"], "text": "Frag MausBot, ob der Zugang zum Postfach schon hinterlegt ist.", "why": "Asked a teammate for a login." },+ { "id": "give-a-password", "tools": ["request_credential"], "text": "I need to give you the mailbox password for [email protected] so you can read mail. How do I hand it over safely?", "why": "Had to hand over a secret." },+ { "id": "log-in-for-me", "tools": ["request_sign_in", "fill_login"], "text": "Log in to bookkeeping.example.com for me and tell me when you're in.", "why": "Asked to sign in at a site." },+ { "id": "remember-this", "tools": ["memory_update"], "text": "Remember that invoices always go to [email protected].", "why": "Asked to remember a fact." }+]diff --git a/evals/tool-choice/run-tool-choice.ts b/evals/tool-choice/run-tool-choice.tsnew file mode 100644index 0000000000..e85ce47e15--- /dev/null+++ b/evals/tool-choice/run-tool-choice.ts@@ -0,0 +1,77 @@+// Which tool does a real model pick, from a tool list as it is shipped? Real requests that went wrong, one thread each on one+// bot, so a change to the list (the agents tool bridge, a shorter description, a removed built-in) is judged on evidence.+//+// OMB_EVAL_LIVE=1 OMB_EVAL_LIVE_INSTANCE='{"instanceId":"claude","driver":"claudeAgent","model":"claude-sonnet-5","config":{"cli":"/path/to/claude"},"environmentFrom":["HOME","USER"]}' \+// node --experimental-strip-types evals/tool-choice/run-tool-choice.ts --only trigger-on-new-mail,what-did-we-decide+//+// Each case is one real model turn on your account: never in CI, closed unless OMB_EVAL_LIVE=1. For the bridge, add+// OMB_AGENTS_TOOL_BRIDGE=1 OMB_EVAL_LIVE_PASS_ENV=OMB_AGENTS_TOOL_BRIDGE. Everything else is a temporary data folder.+import { mkdirSync, readFileSync, writeFileSync } from "node:fs";+import { dirname, join } from "node:path";+import { fileURLToPath } from "node:url";+import { loadLiveInstance } from "../live/run-live.ts";+import { spawnLiveServer } from "../live/live-server.ts";+import { scoreCase, summarize, type CaseScore, type ToolChoiceCase } from "./score.ts";++const HERE = dirname(fileURLToPath(import.meta.url));++interface Row { id: string; score: CaseScore; calls: string[]; reply: string; costUsd?: number; inputTokens?: number; done: boolean }++async function main(): Promise<void> {+ if (process.env.OMB_EVAL_LIVE !== "1") {+ console.log("tool-choice eval: skipped (set OMB_EVAL_LIVE=1; each case is one real model turn)");+ return;+ }+ const argument = (name: string) => { const at = process.argv.indexOf(name); return at === -1 ? undefined : process.argv[at + 1]; };+ const only = argument("--only")?.split(",");+ const cases = (JSON.parse(readFileSync(join(HERE, "cases.json"), "utf8")) as ToolChoiceCase[]).filter((item) => !only || only.includes(item.id));+ const instance = loadLiveInstance(process.env);+ const pass = (process.env.OMB_EVAL_LIVE_PASS_ENV ?? "").split(/[:,]/).map((name) => name.trim()).filter(Boolean);+ const session = await spawnLiveServer(process.env, instance, pass);+ const call = async (method: string, path: string, body?: unknown) => {+ const response = await fetch(session.url + path, { method, ...(body === undefined ? {} : { headers: { "content-type": "application/json" }, body: JSON.stringify(body) }) });+ const parsed = await response.json().catch(() => null) as any;+ if (!response.ok) throw new Error(`${method} ${path}: ${response.status} ${JSON.stringify(parsed)}`);+ return parsed;+ };+ const day = new Date().toISOString().slice(0, 10);+ const spent = async () => {+ const usage = await call("GET", `/api/usage?from=${day}&to=${day}`);+ const totals = usage.total ?? usage.totals ?? {};+ return { cost: Number(totals.costUsd ?? 0), input: Number(totals.input ?? 0) + Number(totals.cachedInput ?? 0) };+ };+ const rows: Row[] = [];+ try {+ const { bot } = await call("POST", "/api/bots", { name: "Helper", modelSelection: { instanceId: instance.instanceId, model: instance.model } });+ for (const item of cases) {+ const before = await spent();+ const { task } = await call("POST", `/api/bots/${bot.id}/tasks`, { title: item.id, select: false });+ await call("POST", `/api/bots/${bot.id}/messages`, { text: item.text, threadId: task.threadId });+ const deadline = Date.now() + 180_000;+ let messages: any[] = [], done = false;+ while (Date.now() < deadline && !done) {+ await new Promise((resolve) => setTimeout(resolve, 1_500));+ messages = (await call("GET", `/api/threads/${task.threadId}/messages`)).messages ?? [];+ const state = (await call("GET", "/api/bots?messages=0")).bots.find((entry: any) => entry.id === bot.id);+ done = !state?.busy && messages.some((message) => message.role === "bot" && message.kind === "text" && (message.text ?? "").trim());+ }+ const calls = messages.filter((message) => message.kind === "activity" && message.tool?.name).map((message) => String(message.tool.name));+ const after = await spent();+ const row: Row = { id: item.id, score: scoreCase(item, calls), calls, done, costUsd: Number((after.cost - before.cost).toFixed(4)), inputTokens: after.input - before.input,+ reply: String(messages.filter((message) => message.role === "bot" && message.kind === "text").at(-1)?.text ?? "").slice(0, 200) };+ rows.push(row);+ console.log(`${row.score.pass ? "pass" : "MISS"} ${item.id}: ${row.score.chosen ?? "no tool"}${row.score.searched ? " (looked up)" : ""} $${row.costUsd} [${calls.join(", ")}]`);+ }+ } finally {+ await session.close();+ }+ const report = { summary: summarize(rows), bridge: process.env.OMB_AGENTS_TOOL_BRIDGE ?? "off", rows };+ console.log(JSON.stringify(report.summary));+ const out = argument("--out");+ if (out) {+ mkdirSync(dirname(out), { recursive: true });+ writeFileSync(out, JSON.stringify(report, null, 1));+ }+}++await main();diff --git a/evals/tool-choice/score.test.ts b/evals/tool-choice/score.test.tsnew file mode 100644index 0000000000..6f3a325875--- /dev/null+++ b/evals/tool-choice/score.test.ts@@ -0,0 +1,33 @@+import { readFileSync } from "node:fs";+import { describe, expect, it } from "vitest";+import { bareToolName, scoreCase, summarize, type ToolChoiceCase } from "./score.ts";++describe("tool-choice scoring", () => {+ it("counts the right tool, direct or looked up first, and nothing else", () => {+ expect(scoreCase({ tools: ["trigger"] }, ["mcp__agents__trigger"])).toEqual({ pass: true, chosen: "trigger", searched: false });+ expect(scoreCase({ tools: ["trigger"] }, ["find_tool", "trigger"])).toEqual({ pass: true, chosen: "trigger", searched: true });+ expect(scoreCase({ tools: ["trigger"] }, ["find_tool", "Bash"])).toEqual({ pass: false, chosen: "Bash", searched: true });+ expect(scoreCase({ tools: ["trigger"] }, [])).toEqual({ pass: false, chosen: undefined, searched: false });+ });++ it("strips the server from a tool name, including one with an underscore", () => {+ expect(bareToolName("mcp__agents__session_search")).toBe("session_search");+ expect(bareToolName("mcp__own_apps__GMAIL_SEND")).toBe("GMAIL_SEND");+ expect(bareToolName("Bash")).toBe("Bash");+ });++ it("adds up a run", () => {+ const pass = { pass: true, chosen: "a", searched: false }, miss = { pass: false, chosen: undefined, searched: true };+ expect(summarize([{ score: pass, costUsd: 0.1, inputTokens: 5 }, { score: miss, costUsd: 0.2, inputTokens: 7 }]))+ .toEqual({ cases: 2, passed: 1, searched: 1, costUsd: 0.3, inputTokens: 12 });+ });++ it("every case names a real failure and at least one tool", () => {+ const cases = JSON.parse(readFileSync(new URL("./cases.json", import.meta.url), "utf8")) as ToolChoiceCase[];+ expect(new Set(cases.map((item) => item.id)).size).toBe(cases.length);+ for (const item of cases) {+ expect(item.tools.length, item.id).toBeGreaterThan(0);+ expect(item.why.length, item.id).toBeGreaterThan(0);+ }+ });+});diff --git a/evals/tool-choice/score.ts b/evals/tool-choice/score.tsnew file mode 100644index 0000000000..b0981321d1--- /dev/null+++ b/evals/tool-choice/score.ts@@ -0,0 +1,40 @@+export interface ToolChoiceCase {+ id: string;+ /** Any of these counts: picking one directly, or reaching it through use_tool. */+ tools: string[];+ text: string;+ /** The real failure this came from, in neutral words. */+ why: string;+}++/** A tool name as a thread's activity row or a stream event gives it, without its server. */+export function bareToolName(name: string): string {+ return name.replace(/^mcp__[^_]+(?:_[^_]+)*?__/, "");+}++export interface CaseScore {+ pass: boolean;+ chosen: string | undefined;+ /** It looked the tool up first. */+ searched: boolean;+}++/** The first of the turn's tool calls that isn't a lookup decides the case; a later right tool still counts, since the tool list is what's on trial. */+export function scoreCase(testCase: Pick<ToolChoiceCase, "tools">, calls: readonly string[]): CaseScore {+ const names = calls.map(bareToolName);+ const lookups = new Set(["find_tool", "ToolSearch"]);+ const chosen = names.find((name) => testCase.tools.includes(name));+ return { pass: chosen !== undefined, chosen: chosen ?? names.find((name) => !lookups.has(name)), searched: names.some((name) => lookups.has(name)) };+}++/** Pass rate, plus what a bridge or a shorter prompt has to beat. */+export function summarize(rows: ReadonlyArray<{ score: CaseScore; costUsd?: number; inputTokens?: number }>) {+ const passed = rows.filter((row) => row.score.pass).length;+ return {+ cases: rows.length,+ passed,+ searched: rows.filter((row) => row.score.searched).length,+ costUsd: Number(rows.reduce((sum, row) => sum + (row.costUsd ?? 0), 0).toFixed(4)),+ inputTokens: rows.reduce((sum, row) => sum + (row.inputTokens ?? 0), 0),+ };+}