Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Keep Muse Spark classifier reasoning within output budgets

Barack Sokullu2e5925f084dc
diff --git a/src/chrome/src/providers/provider-compatibility.js b/src/chrome/src/providers/provider-compatibility.js
index 5b1be99a5..ada5b5d34 100644
--- a/src/chrome/src/providers/provider-compatibility.js
+++ b/src/chrome/src/providers/provider-compatibility.js
@@ -81,6 +81,18 @@ export function openRouterMuseToolOptions(config = {}, options = {}) {
try { openRouter = new URL(config.baseUrl || '').hostname.toLowerCase() === 'openrouter.ai'; } catch { /* not an OpenRouter endpoint */ }
const model = String(config.model || '').trim().toLowerCase().replace(OPENROUTER_MODEL_VARIANT_SUFFIXES, '');
if (!openRouter || model !== 'meta/muse-spark-1.3-contributor') return options;
+ // Muse cannot disable reasoning. Small classifier budgets otherwise end in
+ // hidden reasoning with no JSON output, even after the portable retry.
+ const disabledReasoning = options.extraBody?.reasoning?.enabled === false;
+ const smallTextCall = (options.toolChoice === 'none' || !options.tools?.length)
+ && Number(options.maxTokens) > 0 && Number(options.maxTokens) <= 2048;
+ if (disabledReasoning || smallTextCall) {
+ options = {
+ ...options,
+ maxTokens: Math.max(2048, Number(options.maxTokens) || 2048),
+ extraBody: { ...options.extraBody, reasoning: { effort: 'minimal' } },
+ };
+ }
if (options.toolChoice === 'none') return { ...options, tools: [], toolChoice: undefined };
const choice = options.toolChoice;
const name = choice && typeof choice === 'object' ? choice.function?.name || choice.name : null;
diff --git a/src/firefox/src/providers/provider-compatibility.js b/src/firefox/src/providers/provider-compatibility.js
index 5b1be99a5..ada5b5d34 100644
--- a/src/firefox/src/providers/provider-compatibility.js
+++ b/src/firefox/src/providers/provider-compatibility.js
@@ -81,6 +81,18 @@ export function openRouterMuseToolOptions(config = {}, options = {}) {
try { openRouter = new URL(config.baseUrl || '').hostname.toLowerCase() === 'openrouter.ai'; } catch { /* not an OpenRouter endpoint */ }
const model = String(config.model || '').trim().toLowerCase().replace(OPENROUTER_MODEL_VARIANT_SUFFIXES, '');
if (!openRouter || model !== 'meta/muse-spark-1.3-contributor') return options;
+ // Muse cannot disable reasoning. Small classifier budgets otherwise end in
+ // hidden reasoning with no JSON output, even after the portable retry.
+ const disabledReasoning = options.extraBody?.reasoning?.enabled === false;
+ const smallTextCall = (options.toolChoice === 'none' || !options.tools?.length)
+ && Number(options.maxTokens) > 0 && Number(options.maxTokens) <= 2048;
+ if (disabledReasoning || smallTextCall) {
+ options = {
+ ...options,
+ maxTokens: Math.max(2048, Number(options.maxTokens) || 2048),
+ extraBody: { ...options.extraBody, reasoning: { effort: 'minimal' } },
+ };
+ }
if (options.toolChoice === 'none') return { ...options, tools: [], toolChoice: undefined };
const choice = options.toolChoice;
const name = choice && typeof choice === 'object' ? choice.function?.name || choice.name : null;
diff --git a/test/muse-tool-choice.mjs b/test/muse-tool-choice.mjs
index f57f3d67c..9adab6513 100644
--- a/test/muse-tool-choice.mjs
+++ b/test/muse-tool-choice.mjs
@@ -39,4 +39,24 @@ for (const browser of ['chrome', 'firefox']) {
assert.equal(body.tools.length, 1);
assert.equal(body.tools[0].name, 'done');
});
+ test(`${browser}: Muse classifiers use minimal reasoning and sufficient output budget`, () => {
+ const provider = new OpenAICompatibleProvider(config);
+ for (const stream of [false, true]) {
+ for (const maxTokens of [24, 64, 2048]) {
+ const body = provider._buildChatCompletionsBody([], { maxTokens, toolChoice: 'none' }, stream);
+ assert.equal(body.max_tokens, 2048);
+ assert.deepEqual(body.reasoning, { effort: 'minimal' });
+ assert.equal(Object.hasOwn(body, 'tool_choice'), false);
+ }
+ const disabled = provider._buildChatCompletionsBody([], { maxTokens: 4096, extraBody: { reasoning: { enabled: false } } }, stream);
+ assert.deepEqual(disabled.reasoning, { effort: 'minimal' });
+ assert.equal(disabled.max_tokens, 4096);
+ const toolCall = provider._buildChatCompletionsBody([], { maxTokens: 64, tools, toolChoice: 'required' }, stream);
+ assert.equal(toolCall.max_tokens, 64);
+ assert.equal(Object.hasOwn(toolCall, 'reasoning'), false);
+ const regular = new OpenAICompatibleProvider({ ...config, model: 'other-model' })._buildChatCompletionsBody([], { maxTokens: 64 });
+ assert.equal(regular.max_tokens, 64);
+ assert.equal(Object.hasOwn(regular, 'reasoning'), false);
+ }
+ });
}