fix(agents): honor disabled reasoning in thinking policy (#81454)

* fix(agents): honor disabled reasoning in thinking policy

* test: refresh thinking policy CI fixtures

* test: align thinking policy CI guardrails

---------

Co-authored-by: Gio Della-Libera <giodl@microsoft.com>
This commit is contained in:
Gio Della-Libera
2026-05-15 22:33:43 -07:00
committed by GitHub
parent 9aec9200f1
commit 8c9ec0724e
10 changed files with 150 additions and 8 deletions

View File

@@ -675,6 +675,7 @@ Docs: https://docs.openclaw.ai
- Codex app-server: keep per-agent `CODEX_HOME` isolation without rewriting `HOME` by default, so Codex-run subprocesses can still find normal user-home config, tokens, and CLI state unless the launch explicitly overrides `HOME`. Thanks @pashpashpash.
- iMessage: stop sending visible `<media:image>` placeholder text for media-only native image sends while preserving the internal echo key that prevents self-echo duplicate replies. (#81209) Thanks @homer-byte.
- Agents/sessions: create configured agent main sessions before first `sessions_send` or gateway send, so agent-to-agent messages no longer fail when the target agent has not started yet.
- Google models: honor configured `reasoning: false` when resolving thinking policy, preventing non-thinking Google/Gemma models from advertising `thinking=medium`. Fixes #81424.
- gateway: pass Talk session scope to resolver [AI]. (#81379) Thanks @pgondhi987.
- Gateway protocol: require v4 clients and stream explicit chat `deltaText`/`replace` frames so SDK clients can consume assistant updates without local diffing. (#80725) Thanks @samzong.
- GitHub Copilot: exchange OAuth tokens for Copilot API tokens on image understanding requests and route Gemini image payloads through Chat Completions, fixing Copilot Gemini image descriptions. (#80393, #80442) Thanks @afunnyhy.

View File

@@ -830,6 +830,23 @@ describe("google transport stream", () => {
expect(thinkingConfig).not.toHaveProperty("thinkingBudget");
});
it("does not send thinkingConfig when the resolved Google model disables reasoning", () => {
const params = buildGoogleGenerativeAiParams(
buildGeminiModel({
id: "gemma-4-26b-a4b-it",
reasoning: false,
}),
{
messages: [{ role: "user", content: "hello", timestamp: 0 }],
} as never,
{
reasoning: "medium",
},
);
expect(params.generationConfig ?? {}).not.toHaveProperty("thinkingConfig");
});
it("omits disabled thinkingBudget=0 for Gemini 2.5 Pro direct payloads", () => {
const params = buildGoogleGenerativeAiParams(
buildGeminiModel(),

View File

@@ -2128,6 +2128,38 @@ describe("model-selection", () => {
}),
).toBe("medium");
});
it("honors configured provider models that disable reasoning", () => {
const cfg = {
models: {
providers: {
google: {
api: "google-generative-ai",
baseUrl: "https://generativelanguage.googleapis.com/v1beta",
models: [
{
id: "gemma-4-26b-a4b-it",
name: "Gemma 4 26B",
reasoning: false,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 32_000,
maxTokens: 8_192,
},
],
},
},
},
} as OpenClawConfig;
expect(
resolveThinkingDefault({
cfg,
provider: "google",
model: "gemma-4-26b-a4b-it",
}),
).toBe("off");
});
});
});

View File

@@ -19,11 +19,12 @@ export function resolveThinkingDefault(params: {
}): ThinkLevel {
const normalizedProvider = normalizeProviderId(params.provider);
const normalizedModel = normalizeLowercaseStringOrEmpty(params.model).replace(/\./g, "-");
const catalogCandidate = Array.isArray(params.catalog)
? params.catalog.find(
(entry) => entry.provider === params.provider && entry.id === params.model,
)
: undefined;
const catalog = Array.isArray(params.catalog)
? params.catalog
: buildConfiguredModelCatalog({ cfg: params.cfg });
const catalogCandidate = catalog.find(
(entry) => entry.provider === params.provider && entry.id === params.model,
);
const configuredModels = params.cfg.agents?.defaults?.models;
const canonicalKey = modelKey(params.provider, params.model);
const legacyKey = legacyModelKey(params.provider, params.model);
@@ -75,7 +76,7 @@ export function resolveThinkingDefault(params: {
return resolveThinkingDefaultForModel({
provider: params.provider,
model: params.model,
catalog: params.catalog,
catalog,
});
}

View File

@@ -160,6 +160,38 @@ describe("listThinkingLevels", () => {
expect(listThinkingLevelLabels("demo", "demo-model")).toEqual(["off", "on"]);
});
it("treats catalog reasoning=false as an explicit thinking opt-out", () => {
providerRuntimeMocks.resolveProviderThinkingProfile.mockReturnValue({
levels: [{ id: "off" }, { id: "low" }, { id: "medium" }, { id: "high" }],
defaultLevel: "medium",
});
const catalog = [
{
provider: "google",
id: "gemma-4-26b-a4b-it",
name: "Gemma 4 26B",
reasoning: false,
},
];
expect(listThinkingLevels("google", "gemma-4-26b-a4b-it", catalog)).toEqual(["off"]);
expect(
isThinkingLevelSupported({
provider: "google",
model: "gemma-4-26b-a4b-it",
level: "medium",
catalog,
}),
).toBe(false);
expect(
resolveThinkingDefaultForModel({
provider: "google",
model: "gemma-4-26b-a4b-it",
catalog,
}),
).toBe("off");
});
it("passes catalog reasoning into provider thinking profiles for support checks", () => {
providerRuntimeMocks.resolveProviderThinkingProfile.mockImplementation(({ context }) => ({
levels:

View File

@@ -127,6 +127,13 @@ function buildBaseThinkingProfile(defaultLevel?: ThinkLevel | null): ResolvedThi
};
}
function buildOffOnlyThinkingProfile(): ResolvedThinkingProfile {
return {
levels: [{ id: "off", label: "off", rank: THINKING_LEVEL_RANKS.off }],
defaultLevel: "off",
};
}
function buildBinaryThinkingProfile(defaultLevel?: ThinkLevel | null): ResolvedThinkingProfile {
return {
levels: [
@@ -159,6 +166,9 @@ export function resolveThinkingProfile(params: {
modelId: context.modelId,
reasoning: context.reasoning,
};
if (context.reasoning === false) {
return buildOffOnlyThinkingProfile();
}
const pluginProfile = resolveProviderThinkingProfile({
provider: context.normalizedProvider,
context: providerContext,

View File

@@ -119,6 +119,36 @@ describe("gateway startup log", () => {
).toBe("thinking=off, fast=on");
});
it("shows thinking off for configured provider models with reasoning disabled", () => {
expect(
formatAgentModelStartupDetails({
cfg: {
models: {
providers: {
google: {
api: "google-generative-ai",
baseUrl: "https://generativelanguage.googleapis.com/v1beta",
models: [
{
id: "gemma-4-26b-a4b-it",
name: "Gemma 4 26B",
reasoning: false,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 32_000,
maxTokens: 8_192,
},
],
},
},
},
},
provider: "google",
model: "gemma-4-26b-a4b-it",
}),
).toBe("thinking=off, fast=off");
});
it("uses default agent mode overrides in the startup model details", () => {
expect(
formatAgentModelStartupDetails({

View File

@@ -3,6 +3,7 @@ import { resolveDefaultAgentId, resolveAgentConfig } from "../agents/agent-scope
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "../agents/defaults.js";
import { resolveFastModeState } from "../agents/fast-mode.js";
import {
buildConfiguredModelCatalog,
resolveConfiguredModelRef,
resolveThinkingDefault,
legacyModelKey,
@@ -98,6 +99,17 @@ function resolveExplicitStartupThinking(params: {
);
}
function isConfiguredReasoningDisabled(params: {
cfg: OpenClawConfig;
provider: string;
model: string;
}): boolean {
return buildConfiguredModelCatalog({ cfg: params.cfg }).some(
(entry) =>
entry.provider === params.provider && entry.id === params.model && entry.reasoning === false,
);
}
export function formatAgentModelStartupDetails(params: {
cfg: OpenClawConfig;
provider: string;
@@ -118,7 +130,13 @@ export function formatAgentModelStartupDetails(params: {
provider: params.provider,
model: params.model,
});
const thinking = explicitThinking ?? (resolvedThinking === "off" ? "medium" : resolvedThinking);
const thinking =
explicitThinking ??
(isConfiguredReasoningDisabled(params)
? "off"
: resolvedThinking === "off"
? "medium"
: resolvedThinking);
const fast = resolveFastModeState({
cfg: params.cfg,
provider: params.provider,

View File

@@ -304,6 +304,7 @@ function isExtensionTestOrSupportPath(repoRelativePath: string): boolean {
/(?:^|\/)test-support\.[cm]?tsx?$/.test(repoRelativePath) ||
/(?:^|\/)test-helpers\.[cm]?tsx?$/.test(repoRelativePath) ||
/(?:^|\/)test-harness\.[cm]?tsx?$/.test(repoRelativePath) ||
/(?:^|\/)test-runtime\.[cm]?tsx?$/.test(repoRelativePath) ||
/\.test-support\.[cm]?tsx?$/.test(repoRelativePath) ||
/\.test-helpers\.[cm]?tsx?$/.test(repoRelativePath) ||
/\.test-harness\.[cm]?tsx?$/.test(repoRelativePath) ||

View File

@@ -2411,7 +2411,7 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
} satisfies PluginRuntime["state"];
}
if (prop === "config") {
const config = Reflect.get(target, prop, receiver);
const config: PluginRuntime["config"] = Reflect.get(target, prop, receiver);
return {
...config,
current: () => runWithPluginScope(() => config.current()),