Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(ai): turn thinking off on small-cap strict-output calls (#6419, #6342, #5331)

time-attackcc6c99ba8d3b
diff --git a/src/core/facts/classify.ts b/src/core/facts/classify.ts
index cd49305149..c8531177f4 100644
--- a/src/core/facts/classify.ts
+++ b/src/core/facts/classify.ts
@@ -119,6 +119,7 @@ export async function classifyAgainstCandidates(
},
],
maxTokens: 200,
+ thinking: 'off',
abortSignal: opts.abortSignal,
});
} catch (err) {
diff --git a/src/core/facts/relink-model.ts b/src/core/facts/relink-model.ts
index 012fbb6c22..ed6cfe9b67 100644
--- a/src/core/facts/relink-model.ts
+++ b/src/core/facts/relink-model.ts
@@ -93,7 +93,7 @@ export async function judgeBatch(engine: BrainEngine, sourceId: string, model: s
const { chat } = await import('../ai/gateway.ts');
const result = await chat({
model, system: SYSTEM, messages: [{ role: 'user', content: render(batch) }],
- maxTokens: 64 + batch.length * 40, temperature: 0, abortSignal: signal, responseSchema: RESPONSE_SCHEMA,
+ maxTokens: 64 + batch.length * 40, temperature: 0, abortSignal: signal, responseSchema: RESPONSE_SCHEMA, thinking: 'off',
});
const subjects = result.stopReason === 'refusal' || result.stopReason === 'content_filter' ? null : parseSubjects(result.text, batch.length);
if (!subjects) return batch.map(f => ({ id: f.id, slug: null, reason: 'model_unparseable' as const }));
diff --git a/src/core/page-summary.ts b/src/core/page-summary.ts
index 7e8ff88d37..ab9809e044 100644
--- a/src/core/page-summary.ts
+++ b/src/core/page-summary.ts
@@ -172,6 +172,7 @@ export async function generatePerChunkSynopsis(
system: SYSTEM_PROMPT,
messages: [{ role: 'user', content: userPrompt }],
maxTokens,
+ thinking: 'off',
abortSignal: args.abortSignal,
cacheSystem: true,
};
diff --git a/src/core/search/llm-intent.ts b/src/core/search/llm-intent.ts
index 66db14e5cd..c45452aa70 100644
--- a/src/core/search/llm-intent.ts
+++ b/src/core/search/llm-intent.ts
@@ -56,6 +56,7 @@ export async function classifyModalityWithLLM(
system: SYSTEM_PROMPT,
messages: [{ role: 'user', content: query.slice(0, 500) }],
maxTokens: 16,
+ thinking: 'off',
abortSignal: controller.signal,
});
return parseModality(result.text, fallback);
diff --git a/test/facts-classify.test.ts b/test/facts-classify.test.ts
index ce889b4376..31a22310f8 100644
--- a/test/facts-classify.test.ts
+++ b/test/facts-classify.test.ts
@@ -14,7 +14,7 @@ import {
cosineSimilarity,
classifyAgainstCandidates,
} from '../src/core/facts/classify.ts';
-import { configureGateway, resetGateway } from '../src/core/ai/gateway.ts';
+import { __setChatTransportForTests, configureGateway, resetGateway, type ChatOpts } from '../src/core/ai/gateway.ts';
import { LEGACY_EMBEDDING_CONFIG } from './helpers/legacy-embedding-config.ts';
import type { FactRow } from '../src/core/engine.ts';
@@ -166,3 +166,28 @@ describe('classify gate — key-aware, engine-free (CX10)', () => {
});
});
});
+
+describe('classifier on a thinking route (#5331)', () => {
+ test('asks with thinking off, so a reasoning model returns its verdict inside the 200-token cap', async () => {
+ configureGateway({ ...LEGACY_EMBEDDING_CONFIG, env: { ANTHROPIC_API_KEY: 'sk-test' } });
+ __setChatTransportForTests(async (o: ChatOpts) => ({
+ text: o.thinking === 'off' ? '{"decision":"supersede","matched_id":7}' : '',
+ blocks: [],
+ stopReason: o.thinking === 'off' ? 'end' : 'length',
+ usage: { input_tokens: 10, output_tokens: 10, cache_read_tokens: 0, cache_creation_tokens: 0 },
+ model: 'anthropic:claude-haiku-5-5',
+ providerId: 'anthropic',
+ }));
+ try {
+ const result = await classifyAgainstCandidates(
+ { fact: 'Alice works at Widget Co now', kind: 'fact', embedding: vec(1, 0) },
+ [makeFact({ id: 7, fact: 'Alice works at Acme Example', embedding: vec(0, 1) })],
+ { model: 'anthropic:claude-haiku-5-5' },
+ );
+ expect(result).toMatchObject({ decision: 'supersede', supersedes_id: 7, reason: 'classifier' });
+ } finally {
+ __setChatTransportForTests(null);
+ configureGateway({ ...LEGACY_EMBEDDING_CONFIG, env: {} });
+ }
+ });
+});
diff --git a/test/facts-relink.test.ts b/test/facts-relink.test.ts
index 929244f44e..80131218a3 100644
--- a/test/facts-relink.test.ts
+++ b/test/facts-relink.test.ts
@@ -285,6 +285,18 @@ describe('relink model tier', () => {
expect(calls.length).toBe(1);
});
+ test('the judge asks with thinking off, so a reasoning model still answers (#6419)', async () => {
+ await importFromContent(engine, 'projects/apollo-example', '---\ntitle: Apollo Example\ntype: project\n---\n\n# Apollo Example\n', { noEmbed: true });
+ const id = await unlinked('the apollo example launch slipped two weeks');
+ __setChatTransportForTests(async (o: ChatOpts) => o.thinking === 'off'
+ ? answer(['apollo example'])
+ : { ...answer([]), text: '', stopReason: 'length' } as ChatResult);
+ const report = await relink({ llm: true });
+ expect(report.skipped.model_unparseable ?? 0).toBe(0);
+ expect(report.linked_by_tier.model).toBe(1);
+ expect((await row(id)).entity_slug).toBe('projects/apollo-example');
+ });
+
test('a provider failure is model_unavailable and not memoized', async () => {
const id = await unlinked('the launch slipped two weeks');
__setChatTransportForTests(async () => { throw new Error('provider down'); });
diff --git a/test/llm-intent-escalation.test.ts b/test/llm-intent-escalation.test.ts
index 33ad461fc6..4a6aac97e0 100644
--- a/test/llm-intent-escalation.test.ts
+++ b/test/llm-intent-escalation.test.ts
@@ -18,6 +18,7 @@ import {
__unconfigureGatewayForTests,
configureGateway,
resetGateway,
+ type ChatOpts,
} from '../src/core/ai/gateway.ts';
beforeEach(() => {
@@ -138,3 +139,21 @@ describe('classifyModalityWithLLM — fail-open', () => {
expect(await classifyModalityWithLLM('q', 'both')).toBe('both');
});
});
+
+function thinkingRoute(answerText: string) {
+ return async (o: ChatOpts) => ({
+ text: o.thinking === 'off' ? answerText : '',
+ blocks: [],
+ stopReason: (o.thinking === 'off' ? 'end' : 'length') as 'end' | 'length',
+ usage: { input_tokens: 10, output_tokens: 10, cache_read_tokens: 0, cache_creation_tokens: 0 },
+ model: 'anthropic:claude-haiku-5-5',
+ providerId: 'anthropic',
+ });
+}
+
+describe('classifyModalityWithLLM — thinking route (#5331)', () => {
+ test('asks with thinking off, so a reasoning model still answers inside the 16-token cap', async () => {
+ __setChatTransportForTests(thinkingRoute('image'));
+ expect(await classifyModalityWithLLM('any pictures from offsite?')).toBe('image');
+ });
+});
diff --git a/test/page-summary-length.serial.test.ts b/test/page-summary-length.serial.test.ts
index 661c2d1d2a..a51fbb2b3b 100644
--- a/test/page-summary-length.serial.test.ts
+++ b/test/page-summary-length.serial.test.ts
@@ -136,3 +136,22 @@ describe('surrogate-safe document truncation (#5316)', () => {
expect(prompt).toContain('chars truncated for synopsis budget');
});
});
+
+function thinkingRoute(answerText: string) {
+ return async (o: ChatOpts) => ({
+ text: o.thinking === 'off' ? answerText : '',
+ blocks: [],
+ stopReason: (o.thinking === 'off' ? 'end' : 'length') as 'end' | 'length',
+ usage: { input_tokens: 10, output_tokens: 10, cache_read_tokens: 0, cache_creation_tokens: 0 },
+ model: 'anthropic:claude-haiku-5-5',
+ providerId: 'anthropic',
+ });
+}
+
+describe('thinking route (#6342)', () => {
+ test('the synopsis call turns thinking off, so a reasoning model keeps its synopsis', async () => {
+ __setChatTransportForTests(thinkingRoute('A one-sentence synopsis about the series A.'));
+ const r = await generatePerChunkSynopsis(baseArgs);
+ expect(r).toMatchObject({ kind: 'success', synopsis: 'A one-sentence synopsis about the series A.' });
+ });
+});