Skip to content

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

Bots on local models get the short tool list without a setting (#4182)

Milind Soni4776d25b0798
diff --git a/docs/agents-tool-bridge.md b/docs/agents-tool-bridge.md
index ed36b162c3..360e0a9bae 100644
--- a/docs/agents-tool-bridge.md
+++ b/docs/agents-tool-bridge.md
@@ -16,7 +16,11 @@ The list is then 14.5 to 15.4 KB, 65 to 74% smaller. What a turn may call does
not change: the tools behind `use_tool` are exactly the ones the turn would
have been listed.
-It is off by default.
+It is off by default, except for a bot on a local model: one picked from a local
+server, or one on an OpenAI-compatible engine whose URL is on this machine or
+network. A small window cannot spare the full list, so those bots get the bridge
+without the switch. `OMB_AGENTS_TOOL_BRIDGE=0` turns that off too, and the rules
+under "Which bots and engines get it" still apply.
## Turning it on
diff --git a/server/agents-bridge-switch.test.ts b/server/agents-bridge-switch.test.ts
index 6c46662b62..39c7f09012 100644
--- a/server/agents-bridge-switch.test.ts
+++ b/server/agents-bridge-switch.test.ts
@@ -500,6 +500,34 @@ describe("which engines a turn is bridged on", () => {
});
});
+describe("a bot on a local model gets the bridge without the switch", () => {
+ const onOllama = { modelSelection: { model: "ollama::qwen3.5:4b" } };
+ const onServer = (url: string) => ({ driverKind: "openai-compat", config: { url } });
+
+ it.each(["http://127.0.0.1:1234/v1", "http://192.168.1.20:8080/v1", "http://mac-studio.local:11434/v1"])("on a server at %s", (url) => {
+ expect(agentsToolBridgeRefusal({}, {}, onServer(url), {})).toBeNull();
+ });
+
+ it("picked from a local server, on the chat engine", () => {
+ expect(agentsToolBridgeRefusal({}, onOllama, onServer("https://openrouter.ai/api/v1"), {})).toBeNull();
+ });
+
+ it("not on a hosted model", () => {
+ expect(agentsToolBridgeRefusal({}, { modelSelection: { model: "gpt-5" } }, onServer("https://openrouter.ai/api/v1"), {})).toBe("the switch is off");
+ expect(agentsToolBridgeRefusal({}, {}, { driverKind: "grok", config: { url: "http://127.0.0.1:1/v1" } }, {})).toBe("the switch is off");
+ });
+
+ it("not when the operator's variable says no", () => {
+ expect(agentsToolBridgeRefusal({}, onOllama, onServer("http://127.0.0.1:1234/v1"), { OMB_AGENTS_TOOL_BRIDGE: "0" })).toBe("the switch is off");
+ });
+
+ it("not past the rules everyone else keeps: a tool selection, or an engine that judges tools by name", () => {
+ expect(agentsToolBridgeRefusal({}, { ...onOllama, toolScope: { allow: ["native:read"] } }, onServer("http://127.0.0.1:1234/v1"), {})).toBe("the bot has a tool selection");
+ expect(agentsToolBridgeRefusal({}, onOllama, { driverKind: "codex" }, {})).toContain("Codex");
+ expect(agentsToolBridgeRefusal({}, onOllama, { driverKind: "piAgent" }, {})).toContain("Pi");
+ });
+});
+
describe("which bots a turn is bridged for", () => {
it("writes the switch on every turn, so a value inherited from the server's own environment cannot stand in", () => {
expect(agentsToolBridgeEnv({}, bot, CLAUDE, {})).toEqual(off);
diff --git a/server/agents-bridge-switch.ts b/server/agents-bridge-switch.ts
index a375559aa9..d1282665b8 100644
--- a/server/agents-bridge-switch.ts
+++ b/server/agents-bridge-switch.ts
@@ -10,6 +10,8 @@ import { parseToolScope } from "../shared/tool-scope.ts";
import { bridgedCallName } from "./agents-bridge-names.ts";
import { TOOL_BRIDGE_ENV } from "./drivers/agents-bridge.ts";
+import { decodeInjectId } from "./drivers/local-inject.ts";
+import { onThisNetwork } from "./drivers/openai-compat.ts";
import { claudeCliSupports, parseClaudeCliVersion } from "./drivers/claude.ts";
import { AGENTS_NODE_FLAG, SPAWNED_PROXIES } from "./proxy-paths.ts";
@@ -33,6 +35,15 @@ export function agentsToolBridgeEnabled(cfg: BridgeConfig, env: NodeJS.ProcessEn
return cfg.features?.agentsToolBridge === true;
}
+/** A model on this machine or network reads the whole list on every turn, out of a small window and at laptop speed:
+ * about 15,000 tokens before the person has said anything. OMB_AGENTS_TOOL_BRIDGE=0 still wins. */
+function runsLocalModel(bot: { modelSelection?: { model?: unknown } } | null | undefined, engine: BridgeEngine | null | undefined): boolean {
+ const model = bot?.modelSelection?.model;
+ if (typeof model === "string" && decodeInjectId(model)) return true;
+ const url = (engine?.config as { url?: unknown } | undefined)?.url;
+ return engine?.driverKind === "openai-compat" && typeof url === "string" && onThisNetwork(url);
+}
+
/** The engine a turn runs on, as far as the decision reads it. */
export interface BridgeEngine {
driverKind: string;
@@ -265,13 +276,13 @@ export function engineBridgeRefusal(
* path or file content). */
export function agentsToolBridgeRefusal(
cfg: BridgeConfig,
- bot: { toolScope?: unknown } | null | undefined,
+ bot: { toolScope?: unknown; modelSelection?: { model?: unknown } } | null | undefined,
engine: BridgeEngine | null | undefined,
env: NodeJS.ProcessEnv = process.env,
host?: EngineHost,
): string | null {
try {
- if (!agentsToolBridgeEnabled(cfg, env)) return "the switch is off";
+ if (!agentsToolBridgeEnabled(cfg, env) && (env[TOOL_BRIDGE_ENV] === "0" || !runsLocalModel(bot, engine))) return "the switch is off";
// Security: selection gates match the name in the call, so any selection, even one that permits
// everything or cannot be read, means no bridge.
const selection = bot ? parseToolScope(bot.toolScope) : undefined;
@@ -299,7 +310,7 @@ function logWord(read: () => unknown, absent = false): string | null {
/** The decision as the agents proxy's environment entry: "1" or "0", never left out. */
export function agentsToolBridgeEnv(
cfg: BridgeConfig,
- bot: { toolScope?: unknown } | null | undefined,
+ bot: { toolScope?: unknown; modelSelection?: { model?: unknown } } | null | undefined,
engine: BridgeEngine | null | undefined,
env: NodeJS.ProcessEnv = process.env,
host?: EngineHost,
@@ -319,7 +330,7 @@ export function bridgedAgents<Agents extends { env: Record<string, string> }>(
threadId: string,
agents: Agents | undefined,
cfg: BridgeConfig,
- bot: { toolScope?: unknown } | null | undefined,
+ bot: { toolScope?: unknown; modelSelection?: { model?: unknown } } | null | undefined,
engine: BridgeEngine | null | undefined,
env?: NodeJS.ProcessEnv,
host?: EngineHost,
@@ -340,7 +351,7 @@ export function applyAgentsBridge<Agents extends { env: Record<string, string> }
threadId: string,
integrations: { agents?: Agents },
cfg: BridgeConfig,
- bot: { toolScope?: unknown } | null | undefined,
+ bot: { toolScope?: unknown; modelSelection?: { model?: unknown } } | null | undefined,
engine: BridgeEngine | null | undefined,
env?: NodeJS.ProcessEnv,
host?: EngineHost,