Open-source AI browser agent for Chrome and Firefox (monorepo) π§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Lean mode: an explicit cloud category and the provider's effective model decide Auto
Barack Sokullu261eeacf6a83
diff --git a/docs/lean-mode.md b/docs/lean-mode.mdindex 85e8d0a62..ac2ea9138 100644--- a/docs/lean-mode.md+++ b/docs/lean-mode.md@@ -27,7 +27,7 @@ The resolved mode is recorded:Auto turns lean mode on only when all of these hold (`src/*/src/agent/lean-mode.js`):1. **The run is in Act mode.**-2. **The provider is a cloud or router provider.** A provider whose category is local, and llama.cpp, Ollama, LM Studio and WebGPU in any configuration, never get lean mode under Auto, whatever model they serve. A provider of unknown category does not either.+2. **The provider is a cloud or router provider.** The category WebBrain gives the provider decides, so Ollama Cloud is a cloud provider. A local provider never gets lean mode under Auto, whatever model it serves, and a provider of unknown category does not either. A provider config that names no category is local when it is llama.cpp, Ollama, LM Studio or WebGPU.3. **The provider's prompt tier is Full.** A provider the user set to Compact or Mid keeps its tier's tools and prompt.4. **The model id is on the strong-model list:**- Claude Opus and Sonnet, generation 4 and later, and Claude Fable and Mythos (`claude-sonnet-4-5`, `claude-opus-4-1-β¦`, `claude-fable-5-1`, `anthropic/claude-sonnet-4.5`, Bedrock ids);@@ -36,7 +36,7 @@ Auto turns lean mode on only when all of these hold (`src/*/src/agent/lean-mode.- Gemini 2.5 Pro and newer Pro or Ultra models;- Grok 4 and later.- Ids are matched in lower case anywhere in the string, so router prefixes, regional prefixes and dated snapshots match. Haiku, Flash, GPT-4o, Claude 3.x and the WebBrain Cloud default model are not on the list, so Auto leaves them off.+ The id is the model the provider calls: with the model setting left blank, that is the provider's default (Anthropic's is `claude-sonnet-5`). Ids are matched in lower case anywhere in the string, so router prefixes, regional prefixes and dated snapshots match. Haiku, Flash, GPT-4o, Claude 3.x and the WebBrain Cloud default model are not on the list, so Auto leaves them off.The list is `LEAN_STRONG_MODEL_RULES` in `lean-mode.js`. That file is identical in both builds (a test checks it); add a family there when it has proven itself, and add a case to `test/lean-mode.mjs`.diff --git a/src/chrome/src/agent/lean-mode.js b/src/chrome/src/agent/lean-mode.jsindex c287ef66f..140129794 100644--- a/src/chrome/src/agent/lean-mode.js+++ b/src/chrome/src/agent/lean-mode.js@@ -54,24 +54,46 @@ export function strongModelFamily(modelId) {}// Providers that run on the user's machine or in the browser. Auto never-// turns lean mode on for them, whatever model they serve.+// turns lean mode on for them, whatever model they serve. The type and id+// lists only classify a provider whose config names no category.const LOCAL_PROVIDER_TYPES = Object.freeze(['llamacpp', 'webgpu']);const LOCAL_PROVIDER_ID = /^(?:llamacpp|ollama|lmstudio|webgpu)(?:$|[_-])/;+// The first value that is a non-blank string, read lazily: a provider's+// getters can throw, and a blank configured value (model: '') means "not+// set", so the provider's own default applies.+function firstText(...reads) {+ for (const read of reads) {+ let value;+ try { value = read(); } catch { continue; }+ if (value == null) continue;+ const text = String(value);+ if (text.trim()) return text;+ }+ return '';+}+/*** What Auto needs to know about a provider. Accepts a provider instance (its- * `config` and `promptTier`) or a plain description for tests and tools.+ * `config`, `promptTier` and effective `model`) or a plain description for+ * tests and tools.*/export function leanProviderInfo(provider) {const config = provider?.config && typeof provider.config === 'object' ? provider.config : provider || {};- const category = String(config.category ?? provider?.category ?? '').toLowerCase();- const type = String(config.type ?? provider?.type ?? '').toLowerCase();- const providerId = String(config._providerId ?? provider?.providerId ?? '').toLowerCase();- const model = String(config.model ?? provider?.model ?? '');- let promptTier = '';- try { promptTier = String(provider?.promptTier ?? config.promptTier ?? '').toLowerCase(); } catch {}- const local = category === 'local' || LOCAL_PROVIDER_TYPES.includes(type) || LOCAL_PROVIDER_ID.test(providerId);- const cloud = !local && (category === 'cloud' || category === 'router');+ const category = firstText(() => config.category, () => provider?.category).trim().toLowerCase();+ const type = firstText(() => config.type, () => provider?.type).trim().toLowerCase();+ const providerId = firstText(() => config._providerId, () => provider?.providerId).trim().toLowerCase();+ // A blank configured model is unset: the provider's model getter returns+ // the model it actually calls (AnthropicProvider defaults to its own).+ const model = firstText(() => config.model, () => provider?.model).trim();+ const promptTier = firstText(() => provider?.promptTier, () => config.promptTier).trim().toLowerCase();+ // An explicit category decides, as ProviderManager.categoryFor does: the+ // built-in Ollama Cloud is 'cloud' although its id starts with "ollama-".+ // The type and id lists only classify a config written without one.+ const remote = category === 'cloud' || category === 'router';+ const local = category === 'local'+ || (!remote && (LOCAL_PROVIDER_TYPES.includes(type) || LOCAL_PROVIDER_ID.test(providerId)));+ const cloud = !local && remote;return { category, type, providerId, model, promptTier, local, cloud };}diff --git a/src/firefox/src/agent/lean-mode.js b/src/firefox/src/agent/lean-mode.jsindex c287ef66f..140129794 100644--- a/src/firefox/src/agent/lean-mode.js+++ b/src/firefox/src/agent/lean-mode.js@@ -54,24 +54,46 @@ export function strongModelFamily(modelId) {}// Providers that run on the user's machine or in the browser. Auto never-// turns lean mode on for them, whatever model they serve.+// turns lean mode on for them, whatever model they serve. The type and id+// lists only classify a provider whose config names no category.const LOCAL_PROVIDER_TYPES = Object.freeze(['llamacpp', 'webgpu']);const LOCAL_PROVIDER_ID = /^(?:llamacpp|ollama|lmstudio|webgpu)(?:$|[_-])/;+// The first value that is a non-blank string, read lazily: a provider's+// getters can throw, and a blank configured value (model: '') means "not+// set", so the provider's own default applies.+function firstText(...reads) {+ for (const read of reads) {+ let value;+ try { value = read(); } catch { continue; }+ if (value == null) continue;+ const text = String(value);+ if (text.trim()) return text;+ }+ return '';+}+/*** What Auto needs to know about a provider. Accepts a provider instance (its- * `config` and `promptTier`) or a plain description for tests and tools.+ * `config`, `promptTier` and effective `model`) or a plain description for+ * tests and tools.*/export function leanProviderInfo(provider) {const config = provider?.config && typeof provider.config === 'object' ? provider.config : provider || {};- const category = String(config.category ?? provider?.category ?? '').toLowerCase();- const type = String(config.type ?? provider?.type ?? '').toLowerCase();- const providerId = String(config._providerId ?? provider?.providerId ?? '').toLowerCase();- const model = String(config.model ?? provider?.model ?? '');- let promptTier = '';- try { promptTier = String(provider?.promptTier ?? config.promptTier ?? '').toLowerCase(); } catch {}- const local = category === 'local' || LOCAL_PROVIDER_TYPES.includes(type) || LOCAL_PROVIDER_ID.test(providerId);- const cloud = !local && (category === 'cloud' || category === 'router');+ const category = firstText(() => config.category, () => provider?.category).trim().toLowerCase();+ const type = firstText(() => config.type, () => provider?.type).trim().toLowerCase();+ const providerId = firstText(() => config._providerId, () => provider?.providerId).trim().toLowerCase();+ // A blank configured model is unset: the provider's model getter returns+ // the model it actually calls (AnthropicProvider defaults to its own).+ const model = firstText(() => config.model, () => provider?.model).trim();+ const promptTier = firstText(() => provider?.promptTier, () => config.promptTier).trim().toLowerCase();+ // An explicit category decides, as ProviderManager.categoryFor does: the+ // built-in Ollama Cloud is 'cloud' although its id starts with "ollama-".+ // The type and id lists only classify a config written without one.+ const remote = category === 'cloud' || category === 'router';+ const local = category === 'local'+ || (!remote && (LOCAL_PROVIDER_TYPES.includes(type) || LOCAL_PROVIDER_ID.test(providerId)));+ const cloud = !local && remote;return { category, type, providerId, model, promptTier, local, cloud };}diff --git a/test/lean-mode.mjs b/test/lean-mode.mjsindex 94eb35abe..c181b0ab7 100644--- a/test/lean-mode.mjs+++ b/test/lean-mode.mjs@@ -161,6 +161,15 @@ for (const build of ['chrome', 'firefox']) {[{ category: 'local', type: 'llamacpp', model: 'claude-sonnet-4-5', promptTier: 'full' }, false, 'local_provider'],[{ type: 'webgpu', model: 'gpt-5' }, false, 'local_provider'],[{ providerId: 'lmstudio', model: 'gpt-5' }, false, 'local_provider'],+ [{ providerId: 'ollama', model: 'gpt-5', promptTier: 'full' }, false, 'local_provider'],+ // An explicit category decides before the type and id lists: Ollama+ // Cloud is a cloud provider although its id starts with "ollama-".+ [{ category: 'cloud', type: 'openai', providerId: 'ollama-cloud', model: 'gemini-3-pro-preview', promptTier: 'full' }, true, 'strong_cloud_model'],+ [{ category: 'local', providerId: 'custom-cloud', model: 'gpt-5', promptTier: 'full' }, false, 'local_provider'],+ // A blank configured model is unset: the provider's own model decides.+ [{ config: { category: 'cloud', model: '' }, model: 'claude-sonnet-5' }, true, 'strong_cloud_model'],+ [{ config: { category: 'cloud', model: ' ' }, model: 'gpt-5' }, true, 'strong_cloud_model'],+ [{ category: 'cloud', model: '', promptTier: 'full' }, false, 'model_not_listed'],// A provider of unknown category is not assumed to be a cloud one.[{ model: 'gpt-5', promptTier: 'full' }, false, 'unknown_provider'],];@@ -205,6 +214,35 @@ for (const build of ['chrome', 'firefox']) {assert.equal(agent._leanModeActive(tab, llama), true);});+ test(`${build}: Auto follows the built-in provider's category and the model it actually calls`, async () => {+ const { ProviderManager } = await import(`../src/${build}/src/providers/manager.js`);+ const manager = new ProviderManager();+ const defaults = manager._defaultConfigs();+ // Built the way the extension builds them, from the shipped defaults.+ const built = (id, overrides) => manager._createProvider(id, { ...defaults[id], ...overrides });+ // Ollama Cloud is category 'cloud'; a local Ollama stays local whatever+ // model it serves.+ assert.equal(defaults['ollama-cloud'].category, 'cloud');+ assert.deepEqual(lean.resolveLeanMode('auto', { provider: built('ollama-cloud', { model: 'gemini-3-pro-preview', apiKey: 'test' }) }),+ { active: true, setting: 'auto', reason: 'strong_cloud_model', family: 'gemini' });+ assert.equal(lean.resolveLeanMode('auto', { provider: built('ollama', { model: 'gpt-5' }) }).reason, 'local_provider');+ // A cleared model setting means the provider's default, which for+ // Anthropic is claude-sonnet-5.+ const anthropic = built('anthropic', { model: '', apiKey: 'test' });+ assert.equal(anthropic.model, 'claude-sonnet-5');+ assert.deepEqual(lean.resolveLeanMode('auto', { provider: anthropic }),+ { active: true, setting: 'auto', reason: 'strong_cloud_model', family: 'claude' });+ // Auto agrees with ProviderManager.categoryFor on every built-in, and a+ // built-in whose default URL is on this machine is local.+ for (const [id, config] of Object.entries(defaults)) {+ const category = ProviderManager.categoryFor(id, config);+ const info = lean.leanProviderInfo({ config: { ...config, category, _providerId: id } });+ assert.equal(info.local, category === 'local', `${id} is ${category}`);+ assert.equal(info.cloud, category !== 'local', `${id} is ${category}`);+ if (/^https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\])[:/]/.test(String(config.baseUrl || ''))) assert.ok(info.local, `${id} runs locally`);+ }+ });+// ββ Tool list and prompt ββββββββββββββββββββββββββββββββββββββββββββββββtest(`${build}: a lean Act run gets the thin tool list with unchanged schemas; Ask and Dev keep theirs`, () => {const full = tools.getToolsForMode('act', { tier: 'full' });