Skip to content

Commit f987551

Browse files
committed
fix(ollama): advertise adaptive thinking level and surface configured thinkingDefault over ACP
- Add the OpenClaw-only `adaptive` thinking tier to Ollama's reasoning profile (maps to native `think: "high"` via normalizeOllamaThinkValue). - ACP session presentation now falls back to the configured `thinkingDefault` when no explicit `thinkingLevel` is set, instead of forcing "adaptive". - Add ACP presentation tests (honors thinkingDefault; explicit level wins) and an Ollama Cloud live proof (gpt-oss:20b accepts think:"high"). Scope narrowed from the previous revision: the earlier /acp spawn additions were incomplete (did not compile) and overlap the already-merged bridge thinkingDefault handling in #128169, so they are dropped here.
1 parent ea1a547 commit f987551

8 files changed

Lines changed: 162 additions & 10 deletions

‎docs/providers/ollama.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,9 @@ For full setup and behavior, see [Ollama Web Search](/tools/ollama-search).
10211021
OpenClaw forwards thinking as Ollama expects it: top-level `think`, not
10221022
`options.think`. Auto-discovered models whose `/api/show` reports a
10231023
`thinking` capability expose `/think low`, `/think medium`, `/think high`,
1024-
and `/think max`; non-thinking models expose only `/think off`.
1024+
`/think adaptive`, and `/think max`; non-thinking models expose only
1025+
`/think off`. The `/think adaptive` level is an OpenClaw-only tier that
1026+
maps to Ollama's native high effort (`think: "high"`).
10251027

10261028
```bash
10271029
openclaw agent --model ollama/gemma4 --thinking off

‎extensions/ollama/index.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2564,7 +2564,14 @@ describe("ollama plugin", () => {
25642564
reasoning: true,
25652565
}),
25662566
).toEqual({
2567-
levels: [{ id: "off" }, { id: "low" }, { id: "medium" }, { id: "high" }, { id: "max" }],
2567+
levels: [
2568+
{ id: "off" },
2569+
{ id: "low" },
2570+
{ id: "medium" },
2571+
{ id: "high" },
2572+
{ id: "adaptive" },
2573+
{ id: "max" },
2574+
],
25682575
defaultLevel: "off",
25692576
});
25702577
});

‎extensions/ollama/provider-policy-api.test.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ function createModel(id: string, name: string): ModelDefinitionConfig {
2525
};
2626
}
2727

28+
// Reasoning-capable Ollama models expose the same native effort tiers, including
29+
// the OpenClaw-only `adaptive` tier mapped to Ollama high effort.
30+
const OLLAMA_FULL_REASONING_LEVELS = [
31+
{ id: "off" },
32+
{ id: "low" },
33+
{ id: "medium" },
34+
{ id: "high" },
35+
{ id: "adaptive" },
36+
{ id: "max" },
37+
] as const;
38+
2839
describe("ollama provider policy public artifact", () => {
2940
it("injects defaults so implicit discovery can run before validation", () => {
3041
expect(
@@ -110,7 +121,7 @@ describe("ollama provider policy public artifact", () => {
110121
expect(
111122
resolveThinkingProfile({ provider: "ollama", modelId: "qwen3:32b", reasoning: true }),
112123
).toEqual({
113-
levels: [{ id: "off" }, { id: "low" }, { id: "medium" }, { id: "high" }, { id: "max" }],
124+
levels: [...OLLAMA_FULL_REASONING_LEVELS],
114125
defaultLevel: "off",
115126
});
116127
expect(
@@ -125,11 +136,7 @@ describe("ollama provider policy public artifact", () => {
125136
"exposes full native effort for cloud model %s when lightweight projections omit metadata",
126137
(modelId) => {
127138
expect(resolveThinkingProfile({ provider: "ollama-cloud", modelId }).levels).toEqual([
128-
{ id: "off" },
129-
{ id: "low" },
130-
{ id: "medium" },
131-
{ id: "high" },
132-
{ id: "max" },
139+
...OLLAMA_FULL_REASONING_LEVELS,
133140
]);
134141
},
135142
);

‎extensions/ollama/provider-policy-api.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ import { supportsOllamaCloudFullThinkingEffort } from "./src/model-reasoning.js"
1313
type OllamaProviderConfigDraft = Partial<ModelProviderConfig>;
1414

1515
const OLLAMA_REASONING_THINKING_PROFILE = {
16-
levels: [{ id: "off" }, { id: "low" }, { id: "medium" }, { id: "high" }, { id: "max" }],
16+
levels: [
17+
{ id: "off" },
18+
{ id: "low" },
19+
{ id: "medium" },
20+
{ id: "high" },
21+
{ id: "adaptive" },
22+
{ id: "max" },
23+
],
1724
defaultLevel: "off",
1825
} satisfies ProviderThinkingProfile;
1926

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { isLiveTestEnabled } from "openclaw/plugin-sdk/test-live";
2+
import { describe, expect, it } from "vitest";
3+
4+
const ollamaApiKey = process.env.OLLAMA_API_KEY?.trim() ?? "";
5+
const LIVE =
6+
isLiveTestEnabled(["OPENCLAW_LIVE_TEST", "OLLAMA_LIVE_TEST"]) && ollamaApiKey.length > 0;
7+
const describeLive = LIVE ? describe : describe.skip;
8+
9+
// Live proof for the `adaptive` thinking tier added in #128757:
10+
// 1. the OpenClaw-only `adaptive` tier maps to native Ollama high effort, and
11+
// 2. a real Ollama Cloud thinking-capable model accepts the mapped `think: "high"` payload.
12+
describeLive("ollama adaptive thinking (live proof)", () => {
13+
it("maps the OpenClaw-only adaptive tier to native Ollama high effort", async () => {
14+
const { resolveOllamaThinkParamValue } = await import("./src/stream-compat.js");
15+
expect(resolveOllamaThinkParamValue({ think: "adaptive" }, true)).toBe("high");
16+
});
17+
18+
it("ollama-cloud gpt-oss:20b accepts the adaptive-mapped think:high payload", async () => {
19+
const res = await fetch("https://ollama.com/api/chat", {
20+
method: "POST",
21+
headers: {
22+
"content-type": "application/json",
23+
authorization: `Bearer ${ollamaApiKey}`,
24+
},
25+
body: JSON.stringify({
26+
model: "gpt-oss:20b",
27+
messages: [{ role: "user", content: "Reply with exactly the word: hi" }],
28+
think: "high",
29+
stream: false,
30+
}),
31+
});
32+
expect(res.status).toBe(200);
33+
const data = (await res.json()) as { message?: { content?: string } };
34+
expect(data.message?.content?.toLowerCase().includes("hi")).toBe(true);
35+
}, 60_000);
36+
});

‎src/acp/translator.presentation.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export type GatewaySessionPresentationRow = Pick<
4141
| "derivedTitle"
4242
| "updatedAt"
4343
| "thinkingLevel"
44+
| "thinkingDefault"
4445
| "fastMode"
4546
| "effectiveFastMode"
4647
| "modelProvider"
@@ -141,7 +142,13 @@ export function buildSessionPresentation(params: {
141142
const availableLevelIds: string[] = row.thinkingLevels?.map((level) => level.id) ?? [
142143
...BASE_THINKING_LEVELS,
143144
];
144-
const currentModeId = normalizeOptionalString(row.thinkingLevel) || "adaptive";
145+
// Prefer the gateway's recorded thinking level; if absent, honor the
146+
// configured thinking default so ACP sessions reflect user-configured
147+
// defaults instead of being forced to "adaptive".
148+
const currentModeId =
149+
normalizeOptionalString(row.thinkingLevel) ||
150+
normalizeOptionalString(row.thinkingDefault) ||
151+
"adaptive";
145152
const currentFastMode = normalizeFastMode(row.effectiveFastMode ?? row.fastMode) ?? false;
146153
if (!availableLevelIds.includes(currentModeId)) {
147154
availableLevelIds.push(currentModeId);

‎src/acp/translator.session-setup.test.ts‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,91 @@ describe("acp session UX bridge behavior", () => {
9999
expectConfigOption(result.configOptions, "elevated_level", { currentValue: "off" });
100100
});
101101

102+
it("honors configured thinkingDefault when gateway session has no explicit thinkingLevel", async () => {
103+
const sessionStore = createInMemorySessionStore();
104+
const request = vi.fn(async (method: string) => {
105+
if (method === "sessions.list") {
106+
return {
107+
ts: Date.now(),
108+
path: "/tmp/sessions.json",
109+
count: 1,
110+
defaults: {
111+
modelProvider: null,
112+
model: null,
113+
contextTokens: null,
114+
},
115+
sessions: [
116+
{
117+
key: "agent:main:thinking-default",
118+
displayName: "Thinking Default",
119+
kind: "direct",
120+
updatedAt: 1_710_000_000_000,
121+
thinkingDefault: "off",
122+
modelProvider: "openai",
123+
model: "gpt-5.4",
124+
},
125+
],
126+
};
127+
}
128+
return { ok: true };
129+
}) as GatewayClient["request"];
130+
const agent = new AcpGatewayAgent(createAcpConnection(), createAcpGateway(request), {
131+
sessionStore,
132+
});
133+
134+
const result = await agent.loadSession(createLoadSessionRequest("agent:main:thinking-default"));
135+
136+
// thinkingLevel is absent on the row, so thinkingDefault should be used.
137+
expect(result.modes?.currentModeId).toBe("off");
138+
expectConfigOption(result.configOptions, "thought_level", {
139+
currentValue: "off",
140+
});
141+
});
142+
143+
it("prefers explicit thinkingLevel over thinkingDefault", async () => {
144+
const sessionStore = createInMemorySessionStore();
145+
const request = vi.fn(async (method: string) => {
146+
if (method === "sessions.list") {
147+
return {
148+
ts: Date.now(),
149+
path: "/tmp/sessions.json",
150+
count: 1,
151+
defaults: {
152+
modelProvider: null,
153+
model: null,
154+
contextTokens: null,
155+
},
156+
sessions: [
157+
{
158+
key: "agent:main:explicit-thinking",
159+
displayName: "Explicit Thinking",
160+
kind: "direct",
161+
updatedAt: 1_710_000_000_000,
162+
thinkingLevel: "high",
163+
thinkingDefault: "off",
164+
modelProvider: "openai",
165+
model: "gpt-5.4",
166+
},
167+
],
168+
};
169+
}
170+
return { ok: true };
171+
}) as GatewayClient["request"];
172+
const agent = new AcpGatewayAgent(createAcpConnection(), createAcpGateway(request), {
173+
sessionStore,
174+
});
175+
176+
const result = await agent.loadSession(
177+
createLoadSessionRequest("agent:main:explicit-thinking"),
178+
);
179+
180+
// thinkingLevel takes precedence over thinkingDefault.
181+
expect(result.modes?.currentModeId).toBe("high");
182+
expectConfigOption(result.configOptions, "thought_level", {
183+
currentValue: "high",
184+
});
185+
});
186+
102187
it("replays user text, assistant text, and hidden assistant thinking on loadSession", async () => {
103188
const sessionStore = createInMemorySessionStore();
104189
const connection = createAcpConnection();

‎src/acp/translator.session-state.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ export class AcpTranslatorSessionState {
234234
derivedTitle: session.derivedTitle,
235235
updatedAt: session.updatedAt,
236236
thinkingLevel: session.thinkingLevel,
237+
thinkingDefault: session.thinkingDefault,
237238
thinkingLevels: session.thinkingLevels,
238239
modelProvider: session.modelProvider,
239240
model: session.model,

0 commit comments

Comments
 (0)