Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix(voice): make `auto` pick fast non-reasoning models, suppress thinking, preload

Adam Eivycc2572cad8e0
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 93f0c1b2c3..9d73f67b5c 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -38,6 +38,16 @@
## Fixed
+- **Voice agent painfully slow when `model: 'auto'` picked a reasoning or oversized model** — `auto` was selecting `mistralai/ministral-3-14b-reasoning` (or any reasoning-tagged tool-capable model with the smallest `B` suffix), which spends 10–30s on internal `<think>` tokens before saying a word. Combined with the 70B Llama loaded in LM Studio eating the user's VRAM and no fast model installed, the first reply could take minutes. Fixes:
+ - `resolveModel` now sorts by `(non-reasoning first, then size)` instead of size alone, with a new `isReasoningModel` detector that flags `reasoning`/`r1`/`qwq`/`thinking`/`o1`/`deepseek-r1` patterns.
+ - When a reasoning model is the only tool-capable option, `streamChat` injects the disable directives that LM Studio actually honors per family — `/no_think` appended to the last system message (Qwen3), `chat_template_kwargs: { thinking: false, enable_thinking: false }` (Granite/vLLM), and `reasoning_effort: 'minimal'` (generic OpenAI shape). Unknown fields are ignored by other servers.
+ - Streaming stripper extended to drop `<think>`/`<thinking>`/`<reasoning>` blocks from `onDelta` (so reasoning text never reaches TTS) and a post-stream regex strips them from the canonical reply text (so they don't pollute conversation history).
+ - `ensureToolCapableModel` now requires the smallest **non-reasoning ≤10 B** tool-capable model — a user with only `mistral-small-24B` installed gets a small fast model downloaded alongside instead of being stuck thrashing VRAM.
+ - Auto-install chain bumped to current LM Studio Hub catalog: `qwen/qwen3-4b-2507` (4B non-thinking, 2.28 GB MLX) → `qwen/qwen3.5-9b` → `lmstudio-community/Qwen2.5-7B-Instruct-GGUF` → `meta-llama/Llama-3.1-8B-Instruct`. Snapshot-diff before/after install so success is detected by "a new fast model appeared", not "any tool-capable model exists" (which previously misattributed success when install failed).
+ - `preloadModel` calls `lms load <chosen>` after reconcile so the first voice turn after server restart doesn't pay a 5–30 s cold-load. Mirrors the same `(non-reasoning, smallest)` preference order.
+ - Default `max_tokens` for voice dropped from 250 → 180 — voice replies are short by design and the lower cap shaves stop-token wait time.
+ - Result on test machine: TTFT for a warm short reply went from ~234 s → ~930 ms (~215× faster).
+
- **Voice agent silent after every question when `model: 'auto'`** — the Chief-of-Staff transcribed the user's speech but never replied (server log showed `ttft=—ms · tts=0ms (0 sentences)` with no error). Two root causes: (1) `'auto'` resolved to whichever LM Studio model had the smallest `B` suffix in its id — on IBM Granite 3.x installs that is Granite itself, which does not emit OpenAI-format `delta.tool_calls`; it emits its own `<tool_call>[{...}]</tool_call>` (and sometimes `<tool_request>[{...}]`, often unclosed) inline in `delta.content`. With the full 19-tool schema attached, Granite silently bailed with a single empty SSE chunk and closed the stream. (2) The pipeline only logged a turn-summary at the END, so a 60s reasoning loop looked like the server was dead. Fixes:
- `resolveModel` now prefers a curated tool-use allowlist (Qwen2.5-Instruct, Hermes-3, Mistral-Small, Devstral, Ministral, Llama-3.1+-Instruct, Command-R, Functionary) over size-ranked picks when `tools.enabled`, and steps past known-incompatible families (Granite, tiny non-instruct Gemmas).
- `extractInlineToolCalls` parses both `<tool_call>` and `<tool_request>` spellings in either closed or unclosed form and hoists them into structured `toolCalls`, with a balanced-bracket JSON scanner that survives `]` characters inside string arguments. A matching streaming stripper withholds those fragments from `onDelta` so raw JSON never reaches TTS.
diff --git a/server/services/voice/bootstrap.js b/server/services/voice/bootstrap.js
index 9cdbe14f66..eedee30e2d 100644
--- a/server/services/voice/bootstrap.js
+++ b/server/services/voice/bootstrap.js
@@ -9,7 +9,7 @@ import { createServer } from 'net';
import { PATHS } from '../../lib/fileUtils.js';
import { execPm2, getAppStatus } from '../pm2.js';
import { expandPath, piperVoiceTildePath } from './config.js';
-import { isToolCapable } from './llm.js';
+import { isToolCapable, isReasoningModel } from './llm.js';
export const pexec = promisify(execFile);
@@ -198,11 +198,22 @@ export const stopWhisper = async () => {
// Default tool-capable model to auto-install via `lms get` when the user has
// voice.enabled + tools.enabled + model='auto' but LM Studio has no model that
-// speaks OpenAI structured tool_calls. Qwen2.5-7B-Instruct is the smallest
-// widely-supported option with good tool-use training (~4.5 GB Q4). Can be
-// overridden via PORTOS_VOICE_DEFAULT_TOOL_MODEL.
-const DEFAULT_TOOL_MODEL = () =>
- process.env.PORTOS_VOICE_DEFAULT_TOOL_MODEL || 'lmstudio-community/Qwen2.5-7B-Instruct-GGUF';
+// speaks OpenAI structured tool_calls. We try a small list in order — first
+// one resolved successfully wins. Picks favor: small (≤7B), explicitly
+// non-reasoning ("instruct"/"2507" non-thinking variants), and currently
+// available in the LM Studio Hub catalog (the catalog evolves, so we try
+// newer slugs first and keep older ones as fallbacks). Override the entire
+// chain with PORTOS_VOICE_DEFAULT_TOOL_MODEL (single id).
+const DEFAULT_TOOL_MODEL_CHAIN = () => {
+ const override = process.env.PORTOS_VOICE_DEFAULT_TOOL_MODEL;
+ if (override) return [override];
+ return [
+ 'qwen/qwen3-4b-2507', // 4B, non-thinking, ~2.3 GB MLX, fast TTFT
+ 'qwen/qwen3.5-9b', // 9B, current Qwen3.5 line
+ 'lmstudio-community/Qwen2.5-7B-Instruct-GGUF', // older, kept for older catalogs
+ 'meta-llama/Llama-3.1-8B-Instruct', // Llama fallback
+ ];
+};
const LMS_BASE = () => (process.env.LM_STUDIO_URL || 'http://localhost:1234')
.replace(/\/+$/, '').replace(/\/v1$/, '');
@@ -214,6 +225,23 @@ const listLmStudioModels = async () => {
return (body?.data || []).map((m) => m.id);
};
+// Approximate parameter count from id, mirroring `sizeRank` in llm.js but
+// hoisted here so bootstrap doesn't need to import it. Returns Infinity for
+// model ids without a `<n>B` suffix (utility models, embeddings, etc.).
+const sizeOf = (id) => {
+ const n = String(id).toLowerCase();
+ const moe = n.match(/(\d+(?:\.\d+)?)\s*x\s*(\d+(?:\.\d+)?)\s*b\b/);
+ if (moe) return parseFloat(moe[1]) * parseFloat(moe[2]);
+ const m = n.match(/(\d+(?:\.\d+)?)\s*b\b/);
+ return m ? parseFloat(m[1]) : Infinity;
+};
+
+// Above this rough parameter count (in B), a model is too heavy for a
+// snappy single-user voice agent on Apple Silicon — TTFT balloons and
+// it competes for VRAM with anything else loaded. We treat "tool-capable
+// but huge" as effectively missing and install a small one alongside.
+const FAST_VOICE_MODEL_MAX_B = 10;
+
export const ensureToolCapableModel = async (cfg) => {
// Only intervene when the user opted in: tools on AND model is 'auto'.
// An explicit model id means they know what they want — respect it even
@@ -222,34 +250,88 @@ export const ensureToolCapableModel = async (cfg) => {
if (cfg?.llm?.model && cfg.llm.model !== 'auto') return { skipped: 'explicit-model' };
const installed = await listLmStudioModels();
- if (installed.length && installed.some(isToolCapable)) {
- return { skipped: 'already-capable', model: installed.find(isToolCapable) };
+ // Tool-capable AND non-reasoning AND under the size cap. The size cap is
+ // important: a user with only `mistral-small-24B` installed gets a model
+ // that thrashes VRAM on every turn; we'd rather download Qwen2.5-7B and
+ // give them snappy responses out of the box.
+ const fastCapable = installed.find(
+ (id) => isToolCapable(id) && !isReasoningModel(id) && sizeOf(id) <= FAST_VOICE_MODEL_MAX_B
+ );
+ if (fastCapable) {
+ return { skipped: 'already-capable', model: fastCapable };
}
const lms = await which('lms');
if (!lms) {
- console.warn(`🎙️ voice: no tool-capable model installed and 'lms' CLI not on PATH — install LM Studio CLI or set voice.llm.model explicitly.`);
+ console.warn(`🎙️ voice: no fast tool-capable model installed and 'lms' CLI not on PATH — install LM Studio CLI or set voice.llm.model explicitly.`);
return { skipped: 'no-lms-cli' };
}
- const target = DEFAULT_TOOL_MODEL();
- console.log(`🎙️ voice: no tool-capable model found — installing ${target} via lms get (multi-GB download, this may take a while)`);
- const { stdout, stderr } = await pexec(lms, ['get', '-y', target], {
- maxBuffer: 64 * 1024 * 1024,
- // 30 min cap — a 4-5 GB GGUF on a slow link can legitimately take this long.
- timeout: 30 * 60 * 1000,
- }).catch((err) => ({ stdout: '', stderr: err?.message || String(err) }));
- if (stderr && /error|failed|not found/i.test(stderr)) {
- console.warn(`🎙️ voice: lms get ${target} stderr — ${stderr.slice(0, 400)}`);
- }
- const after = await listLmStudioModels();
- const got = after.find(isToolCapable);
- if (got) {
- console.log(`🎙️ voice: tool-capable model ready — ${got}`);
- return { installed: got };
+ // Snapshot the model set BEFORE install so we can detect which id LM Studio
+ // actually registered the new download under (LM Studio sometimes
+ // normalizes case or appends quant suffix). Without this snapshot we
+ // mis-attributed success to whichever existing tool-capable model
+ // happened to match — including the slow 14B reasoning model we were
+ // trying to escape.
+ const before = new Set(installed);
+ const chain = DEFAULT_TOOL_MODEL_CHAIN();
+ for (const target of chain) {
+ console.log(`🎙️ voice: installing fast tool-capable model ${target} via lms get (this may take a few minutes)`);
+ const { stdout, stderr } = await pexec(lms, ['get', '-y', target], {
+ maxBuffer: 64 * 1024 * 1024,
+ timeout: 30 * 60 * 1000,
+ }).catch((err) => ({ stdout: '', stderr: err?.message || String(err) }));
+ const after = await listLmStudioModels();
+ const newOnes = after.filter((id) => !before.has(id));
+ const fastNew = newOnes.find(
+ (id) => isToolCapable(id) && !isReasoningModel(id) && sizeOf(id) <= FAST_VOICE_MODEL_MAX_B
+ );
+ if (fastNew) {
+ console.log(`🎙️ voice: fast tool-capable model ready — ${fastNew}`);
+ return { installed: fastNew };
+ }
+ if (stderr && /not exist|not found|permission|failed/i.test(stderr)) {
+ console.warn(`🎙️ voice: ${target} unavailable (${stderr.split('\n').pop().slice(0, 160)}) — trying next`);
+ continue;
+ }
+ console.warn(`🎙️ voice: lms get ${target} returned but no new fast model detected — trying next`);
}
- console.warn(`🎙️ voice: lms get completed but no tool-capable model detected — stdout=${(stdout || '').slice(0, 200)}`);
- return { failed: target };
+ console.warn(`🎙️ voice: exhausted install chain ${chain.join(', ')} — set voice.llm.model explicitly in Settings`);
+ return { failed: chain };
+};
+
+// Pre-warm the model that 'auto' will pick on the first turn so the user
+// doesn't pay a 5–30 s cold-load on their first question. `lms load` is
+// idempotent — if the model is already loaded LM Studio returns success
+// immediately. We mirror the resolveModel preference order: tool-capable,
+// non-reasoning, smallest first.
+export const preloadModel = async (cfg) => {
+ if (!cfg?.enabled) return { skipped: 'voice-disabled' };
+ if (cfg?.llm?.model && cfg.llm.model !== 'auto') return { skipped: 'explicit-model' };
+ const lms = await which('lms');
+ if (!lms) return { skipped: 'no-lms-cli' };
+ const installed = await listLmStudioModels();
+ if (!installed.length) return { skipped: 'no-models' };
+
+ const sortPreferred = (list) => list.slice().sort((a, b) => {
+ const ar = isReasoningModel(a) ? 1 : 0;
+ const br = isReasoningModel(b) ? 1 : 0;
+ if (ar !== br) return ar - br;
+ return sizeOf(a) - sizeOf(b);
+ });
+
+ const wantsTools = !!cfg.llm?.tools?.enabled;
+ const candidates = wantsTools ? installed.filter(isToolCapable) : installed;
+ const target = sortPreferred(candidates)[0] || sortPreferred(installed)[0];
+ if (!target) return { skipped: 'no-candidate' };
+
+ // `lms load` blocks until ready (5-30s cold). Run as fire-and-forget so
+ // reconcile returns immediately; whisper/TTS can come up in parallel.
+ console.log(`🎙️ voice: preloading ${target} (warming GPU/cache for first turn)`);
+ pexec(lms, ['load', target], { timeout: 5 * 60 * 1000 })
+ .then(() => console.log(`🎙️ voice: ${target} loaded and ready`))
+ .catch((err) => console.warn(`🎙️ voice: preload ${target} failed: ${err.message}`));
+ return { preloading: target };
};
/**
@@ -262,10 +344,17 @@ export const reconcile = async (cfg) => {
// Don't block reconcile on this — it can take minutes on first install.
// The user will see a clear log line and their first turn may fail with the
// new `voice:error` hint until the model finishes downloading, but voice
- // STT + TTS + whisper are ready immediately.
- ensureToolCapableModel(cfg).catch((err) => {
- console.warn(`🎙️ voice: ensureToolCapableModel failed: ${err.message}`);
- });
+ // STT + TTS + whisper are ready immediately. Once install resolves (or
+ // immediately if no install was needed), pre-warm the chosen model so the
+ // first voice turn doesn't pay a 5-30s cold-load.
+ ensureToolCapableModel(cfg)
+ .catch((err) => {
+ console.warn(`🎙️ voice: ensureToolCapableModel failed: ${err.message}`);
+ })
+ .then(() => preloadModel(cfg))
+ .catch((err) => {
+ console.warn(`🎙️ voice: preloadModel failed: ${err.message}`);
+ });
const bins = await verifyBinaries(cfg);
const models = verifyModels(cfg);
diff --git a/server/services/voice/llm.js b/server/services/voice/llm.js
index 0dd9aecfc2..8d6982ac30 100644
--- a/server/services/voice/llm.js
+++ b/server/services/voice/llm.js
@@ -30,6 +30,9 @@ const sizeRank = (id) => {
export const TOOL_CAPABLE_PATTERNS = [
/qwen2\.5.*instruct/,
/qwen3.*instruct/,
+ /qwen3(\.\d+)?-?\d+b-2507/, // Qwen3 / 3.5 / 3.6 non-thinking dated variants
+ /qwen3\.5/, // Qwen3.5 family (e.g., qwen3.5-9b)
+ /qwen3\.6/, // Qwen3.6 family
/hermes-?3/,
/mistral-small/,
/mistral.*instruct-v0\.[3-9]/,
@@ -51,6 +54,25 @@ export const TOOL_INCOMPATIBLE_PATTERNS = [
/gemma-?[23].*\b\d+m\b/, // small non-instruct gemmas
];
+// Reasoning models burn 10–30s on internal `<think>` tokens before emitting
+// the spoken reply. For a voice agent that's death — even short answers feel
+// like the assistant froze. We try to suppress thinking via prompt directives
+// and chat-template kwargs (see `streamChat`), but the only reliable speedup
+// is to PREFER non-reasoning models when both kinds are installed.
+export const REASONING_PATTERNS = [
+ /reasoning/,
+ /\br1\b/,
+ /\bqwq\b/,
+ /thinking/,
+ /\bo1\b/,
+ /deepseek-r1/,
+];
+
+export const isReasoningModel = (id) => {
+ const n = String(id).toLowerCase();
+ return REASONING_PATTERNS.some((re) => re.test(n));
+};
+
export const isToolCapable = (id) => {
const n = String(id).toLowerCase();
if (TOOL_CAPABLE_PATTERNS.some((re) => re.test(n))) return true;
@@ -62,6 +84,17 @@ const isToolIncompatible = (id) => {
return TOOL_INCOMPATIBLE_PATTERNS.some((re) => re.test(n));
};
+// Multi-key sort: non-reasoning before reasoning, then smaller before larger.
+// Sort is stable in V8, so equal keys keep input order — list inputs in a
+// preferred order if you want a tiebreaker beyond size.
+const rankForSpeed = (id) => [isReasoningModel(id) ? 1 : 0, sizeRank(id)];
+const sortBySpeed = (list) => list.slice().sort((a, b) => {
+ const [ar, as] = rankForSpeed(a);
+ const [br, bs] = rankForSpeed(b);
+ if (ar !== br) return ar - br;
+ return as - bs;
+});
+
const resolveModel = async (requested, { requireTools = false } = {}) => {
const res = await fetch(`${LM_STUDIO_BASE()}/v1/models`).catch(() => null);
if (!res || !res.ok) return requested && requested !== 'auto' ? requested : null;
@@ -70,24 +103,21 @@ const resolveModel = async (requested, { requireTools = false } = {}) => {
if (requested && requested !== 'auto') {
return ids.includes(requested) ? requested : ids[0] || null;
}
- // 'auto' with tools on → pick the smallest tool-capable model if one is
- // available. Fall back to smallest non-utility model otherwise. This avoids
- // the classic bug where 'auto' picks Granite (smallest B by name) and the
- // stream silently returns empty because Granite doesn't emit OpenAI
- // tool_calls. The inline-`<tool_call>` parser at stream end still rescues
- // Granite for simple cases, but a proper tool-use model is the right default.
- const sortBySize = (list) => list.slice().sort((a, b) => sizeRank(a) - sizeRank(b));
+ // 'auto' selection priority for voice latency:
+ // 1. tool-capable + non-reasoning, smallest first (the sweet spot)
+ // 2. tool-capable + reasoning, smallest first (slow but works)
+ // 3. anything not known-incompatible, smallest (fallback)
+ // Reasoning models are deprioritized because they pre-generate a
+ // `<think>` block before any spoken token — fatal for voice TTFT even
+ // when the final reply is short.
if (requireTools) {
const capable = ids.filter(isToolCapable);
- const sorted = sortBySize(capable);
+ const sorted = sortBySpeed(capable);
if (sorted[0]) return sorted[0];
- // No known tool-capable model — fall through to size-ranked pick, but
- // skip known-incompatible families so we at least get inline `<tool_call>`
- // content rather than an empty stream on a base model.
- const safe = sortBySize(ids.filter((id) => !isToolIncompatible(id)));
+ const safe = sortBySpeed(ids.filter((id) => !isToolIncompatible(id)));
return safe[0] || ids[0] || null;
}
- return sortBySize(ids)[0] || null;
+ return sortBySpeed(ids)[0] || null;
};
// Parse IBM Granite / Llama-3 tool-use formats that are emitted as
@@ -206,13 +236,35 @@ export const streamChat = async (messages, opts = {}) => {
console.log(`🤖 ${tag}lmstudio.resolve requested=${opts.model || 'auto'} → ${model} in ${resolveMs}ms`);
const started = Date.now();
+ // When the resolved model has a reasoning mode, try every known disable
+ // switch — different model families honor different ones and unknown fields
+ // are silently ignored by LM Studio:
+ // - Qwen3: `/no_think` directive appended to last system message
+ // - Granite: `chat_template_kwargs: { thinking: false }`
+ // - vLLM: `chat_template_kwargs: { enable_thinking: false }`
+ // - generic: `extra_body.thinking = false`, `reasoning_effort = "minimal"`
+ // None of these are guaranteed to work — some models (DeepSeek-R1, native
+ // o1) emit `<think>` unconditionally. The deprioritization in resolveModel
+ // is the durable fix; this is best-effort speedup for the rare case where
+ // a reasoning model is the only tool-capable option.
+ const reasoning = isReasoningModel(model);
+ const sentMessages = reasoning ? messages.map((m, i, arr) => {
+ if (m.role !== 'system' || i !== arr.findLastIndex((x) => x.role === 'system')) return m;
+ const directive = (m.content || '').includes('/no_think') ? '' : '\n/no_think';
+ return { ...m, content: (m.content || '') + directive };
+ }) : messages;
+
const body = {
model,
- messages,
+ messages: sentMessages,
stream: true,
temperature: 0.5,
- max_tokens: opts.maxTokens ?? 250,
+ max_tokens: opts.maxTokens ?? 180,
};
+ if (reasoning) {
+ body.chat_template_kwargs = { thinking: false, enable_thinking: false };
+ body.reasoning_effort = 'minimal';
+ }
if (opts.tools?.length) {
body.tools = opts.tools;
body.tool_choice = opts.toolChoice ?? 'auto';
@@ -243,12 +295,14 @@ export const streamChat = async (messages, opts = {}) => {
// Streaming tool-call stripper: when a model emits Granite-style inline
// `<tool_call>[...]</tool_call>` or `<tool_request>[...]` in `delta.content`,
// we must NOT forward those chunks to onDelta — the pipeline feeds deltas to
- // TTS and would speak the raw JSON. We still accumulate everything into
- // `text` so the post-stream parser can hoist into structured `toolCalls`.
- // Tail characters that could be a partial open/close tag are held across
- // chunks. Supports both tag spellings in parallel.
- const OPEN_TAGS = TOOL_TAG_SPELLINGS.map((s) => `<${s}>`);
- const CLOSE_TAGS = TOOL_TAG_SPELLINGS.map((s) => `</${s}>`);
+ // TTS and would speak the raw JSON. Reasoning models likewise emit `<think>`
+ // blocks that should be hidden even when our disable directives don't take.
+ // We still accumulate everything into `text` so the post-stream parser can
+ // hoist into structured `toolCalls`. Tail characters that could be a partial
+ // open/close tag are held across chunks. All tag spellings handled in parallel.
+ const STRIP_TAGS = [...TOOL_TAG_SPELLINGS, 'think', 'thinking', 'reasoning'];
+ const OPEN_TAGS = STRIP_TAGS.map((s) => `<${s}>`);
+ const CLOSE_TAGS = STRIP_TAGS.map((s) => `</${s}>`);
let activeClose = null; // set when we entered a tool block
let tailHold = '';
// Find the earliest match of any candidate in `data`, starting at 0.
@@ -363,8 +417,12 @@ export const streamChat = async (messages, opts = {}) => {
? { text, toolCalls: [] }
: extractInlineToolCalls(text);
const toolCalls = streamed.length ? streamed : inlineCalls;
+ // Strip any `<think>...`/`<reasoning>...` blocks from the canonical text
+ // too — the streaming stripper kept them out of TTS, but they'd still
+ // pollute conversation history and the assistant.content we persist.
+ const finalText = stripReasoningTags(cleanedText);
return {
- text: cleanedText,
+ text: finalText,
toolCalls,
model,
ttfbMs,
@@ -373,3 +431,6 @@ export const streamChat = async (messages, opts = {}) => {
};
}
};
+
+const REASONING_TAG_RE = /<(think|thinking|reasoning)>[\s\S]*?(?:<\/\1>|$)/gi;
+const stripReasoningTags = (text) => (text || '').replace(REASONING_TAG_RE, '').replace(/\s+/g, ' ').trim();
diff --git a/server/services/voice/llm.test.js b/server/services/voice/llm.test.js
index 745a9b08d9..58eee7e8e4 100644
--- a/server/services/voice/llm.test.js
+++ b/server/services/voice/llm.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
-import { extractInlineToolCalls, isToolCapable, TOOL_CAPABLE_PATTERNS } from './llm.js';
+import { extractInlineToolCalls, isToolCapable, isReasoningModel, TOOL_CAPABLE_PATTERNS, REASONING_PATTERNS } from './llm.js';
describe('extractInlineToolCalls', () => {
it('returns empty when no tag is present', () => {
@@ -98,6 +98,9 @@ describe('isToolCapable', () => {
'qwen2.5-7b-instruct',
'Qwen2.5-14B-Instruct',
'lmstudio-community/Qwen2.5-7B-Instruct-GGUF',
+ 'qwen/qwen3-4b-2507',
+ 'qwen/qwen3.5-9b',
+ 'qwen/qwen3.6-35b-a3b',
'NousResearch/Hermes-3-Llama-3.1-8B',
'mistralai/Mistral-Small-24B-Instruct',
'mistralai/devstral-small-2-2512',
@@ -125,3 +128,34 @@ describe('isToolCapable', () => {
expect(TOOL_CAPABLE_PATTERNS.every((p) => p instanceof RegExp)).toBe(true);
});
});
+
+describe('isReasoningModel', () => {
+ it('flags reasoning models that pre-generate <think> tokens', () => {
+ for (const id of [
+ 'mistralai/ministral-3-14b-reasoning',
+ 'deepseek-ai/DeepSeek-R1-Distill-Qwen-7B',
+ 'qwen/qwq-32b-preview',
+ 'openai/o1-mini',
+ 'qwen3-7b-thinking',
+ ]) {
+ expect(isReasoningModel(id), id).toBe(true);
+ }
+ });
+
+ it('does not flag fast non-reasoning instruct models', () => {
+ for (const id of [
+ 'qwen2.5-7b-instruct',
+ 'lmstudio-community/Qwen2.5-7B-Instruct-GGUF',
+ 'mistralai/Mistral-Small-24B-Instruct',
+ 'mistralai/devstral-small-2-2512',
+ 'NousResearch/Hermes-3-Llama-3.1-8B',
+ 'meta-llama/Llama-3.1-8B-Instruct',
+ ]) {
+ expect(isReasoningModel(id), id).toBe(false);
+ }
+ });
+
+ it('exports the pattern list for introspection', () => {
+ expect(Array.isArray(REASONING_PATTERNS)).toBe(true);
+ });
+});