Skip to content

Commit c29985d

Browse files
steipeteErick Kinnee
andauthored
fix(models): preserve provider-defined reasoning levels across model catalogs (#129623)
* fix(models): preserve provider-owned thinking levels Co-authored-by: Erick Kinnee <[email protected]> * chore: keep provider release notes in pull request metadata --------- Co-authored-by: Erick Kinnee <[email protected]>
1 parent a48675d commit c29985d

14 files changed

Lines changed: 166 additions & 22 deletions

‎src/agents/embedded-agent-runner/compaction-runtime-context.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ describe("resolveEmbeddedCompactionThinkingLevel", () => {
6868
).toBe("high");
6969
});
7070

71+
it("revalidates the compaction default against provider-denied thinking levels", () => {
72+
expect(
73+
resolveEmbeddedCompactionThinkingLevel({
74+
provider: "custom",
75+
modelId: "reasoning-model",
76+
catalog: [
77+
{
78+
provider: "custom",
79+
id: "reasoning-model",
80+
reasoning: true,
81+
thinkingLevelMap: { minimal: null, low: null, medium: null },
82+
},
83+
],
84+
}),
85+
).toBe("high");
86+
});
87+
7188
it("defaults compaction to low without inheriting the session level", () => {
7289
expect(
7390
resolveEmbeddedCompactionThinkingLevel({

‎src/agents/embedded-agent-runner/direct-compaction-preparation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ export async function prepareDirectCompactionAttempt(
292292
id: runtimeModel.id,
293293
api: runtimeModel.api,
294294
reasoning: runtimeModel.reasoning,
295+
...(runtimeModel.thinkingLevelMap ? { thinkingLevelMap: runtimeModel.thinkingLevelMap } : {}),
295296
params: runtimeModel.params,
296297
...(thinkingCompat ? { compat: thinkingCompat } : {}),
297298
} satisfies ThinkingCatalogEntry;

‎src/agents/model-catalog-route.test.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const platformEntry: ModelCatalogEntry = {
3939
contextWindow: 1_000_000,
4040
contextTokens: 272_000,
4141
reasoning: true,
42+
thinkingLevelMap: { off: "none", xhigh: "xhigh", max: "max" },
4243
input: ["text", "image"],
4344
params: { platformOnly: true },
4445
compat: { supportsTools: false },
@@ -53,6 +54,7 @@ const chatGPTEntry: ModelCatalogEntry = {
5354
contextWindow: 400_000,
5455
contextTokens: 300_000,
5556
reasoning: true,
57+
thinkingLevelMap: { off: null, xhigh: null, max: "max" },
5658
input: ["text"],
5759
params: { chatGPTOnly: true },
5860
compat: { supportsTools: true },
@@ -103,6 +105,7 @@ describe("projectModelCatalogEntryForRoute", () => {
103105
contextWindow: 1_000_000,
104106
contextTokens: 272_000,
105107
reasoning: true,
108+
thinkingLevelMap: { off: "none", xhigh: "xhigh", max: "max" },
106109
input: ["text", "image"],
107110
});
108111

@@ -121,6 +124,7 @@ describe("projectModelCatalogEntryForRoute", () => {
121124
contextWindow: 400_000,
122125
contextTokens: 300_000,
123126
reasoning: true,
127+
thinkingLevelMap: { off: null, xhigh: null, max: "max" },
124128
input: ["text"],
125129
});
126130
});
@@ -177,7 +181,13 @@ describe("projectModelCatalogEntryForRoute", () => {
177181
providers: {
178182
openai: {
179183
baseUrl: "https://api.openai.com/v1",
180-
models: [{ id: "gpt-5.5", contextTokens: 160_000 }],
184+
models: [
185+
{
186+
id: "gpt-5.5",
187+
contextTokens: 160_000,
188+
thinkingLevelMap: { off: "none", max: null },
189+
},
190+
],
181191
},
182192
},
183193
},
@@ -198,6 +208,7 @@ describe("projectModelCatalogEntryForRoute", () => {
198208
api: "openai-chatgpt-responses",
199209
baseUrl: "https://chatgpt.com/backend-api/codex",
200210
contextTokens: 160_000,
211+
thinkingLevelMap: { off: "none", max: null },
201212
});
202213
});
203214

‎src/agents/model-catalog-route.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ export type ModelCatalogRouteProjection =
3636
type ModelCatalogLogicalOverrides = Partial<
3737
Pick<
3838
ModelCatalogEntry,
39-
"name" | "contextWindow" | "contextTokens" | "reasoning" | "configuredReasoning" | "input"
39+
| "name"
40+
| "contextWindow"
41+
| "contextTokens"
42+
| "reasoning"
43+
| "configuredReasoning"
44+
| "thinkingLevelMap"
45+
| "input"
4046
>
4147
>;
4248

@@ -69,6 +75,7 @@ export function resolveConfiguredModelCatalogOverrides(params: {
6975
...(model?.contextTokens !== undefined ? { contextTokens: model.contextTokens } : {}),
7076
...(model?.reasoning !== undefined ? { reasoning: model.reasoning } : {}),
7177
...(model?.reasoning !== undefined ? { configuredReasoning: model.reasoning } : {}),
78+
...(model?.thinkingLevelMap ? { thinkingLevelMap: model.thinkingLevelMap } : {}),
7279
...(model?.input !== undefined ? { input: model.input } : {}),
7380
};
7481
return Object.keys(overrides).length > 0 ? overrides : undefined;
@@ -180,6 +187,7 @@ export function projectModelCatalogEntryForRoute(params: {
180187
...(donor?.contextWindow !== undefined ? { contextWindow: donor.contextWindow } : {}),
181188
...(donor?.contextTokens !== undefined ? { contextTokens: donor.contextTokens } : {}),
182189
...(donor?.reasoning !== undefined ? { reasoning: donor.reasoning } : {}),
190+
...(donor?.thinkingLevelMap ? { thinkingLevelMap: donor.thinkingLevelMap } : {}),
183191
...(donor?.input !== undefined ? { input: donor.input } : {}),
184192
},
185193
params.overrides,

‎src/agents/model-catalog.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ describe("prepared model catalog builder", () => {
100100
name: "Alpha",
101101
provider: "alpha",
102102
contextWindow: 64_000,
103+
thinkingLevelMap: { off: null, max: "max" },
103104
input: ["text", "image"],
104105
},
105106
],
@@ -109,6 +110,7 @@ describe("prepared model catalog builder", () => {
109110
"alpha/a",
110111
"beta/z",
111112
]);
113+
expect(snapshot.entries[0]?.thinkingLevelMap).toEqual({ off: null, max: "max" });
112114
expect(snapshot.routeVariants).toEqual(snapshot.entries);
113115
});
114116

@@ -164,6 +166,7 @@ describe("prepared model catalog builder", () => {
164166
{ id: "1m", label: "1M", contextWindow: 1_000_000 },
165167
],
166168
contextWindowDefault: "1m",
169+
thinkingLevelMap: { off: null, xhigh: "xhigh", max: "max" },
167170
},
168171
],
169172
},
@@ -186,6 +189,7 @@ describe("prepared model catalog builder", () => {
186189
{ id: "1m", label: "1M", contextWindow: 1_000_000 },
187190
],
188191
contextWindowDefault: "1m",
192+
thinkingLevelMap: { off: null, xhigh: "xhigh", max: "max" },
189193
});
190194
});
191195

@@ -524,6 +528,7 @@ describe("prepared model catalog builder", () => {
524528
contextWindow: 32_000,
525529
maxTokens: 4_096,
526530
reasoning: true,
531+
thinkingLevelMap: { off: null, xhigh: "xhigh" },
527532
input: ["text", "image"],
528533
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
529534
},
@@ -551,6 +556,7 @@ describe("prepared model catalog builder", () => {
551556
api: "openai-completions",
552557
contextWindow: 32_000,
553558
reasoning: true,
559+
thinkingLevelMap: { off: null, xhigh: "xhigh" },
554560
input: ["text", "image"],
555561
});
556562
expect(snapshot.routeVariants).toHaveLength(2);
@@ -564,6 +570,7 @@ describe("prepared model catalog builder", () => {
564570
provider: "custom",
565571
api: "openai-completions",
566572
baseUrl: "https://route-b.example.test/v1",
573+
thinkingLevelMap: { xhigh: "xhigh", max: "max" },
567574
compat: { supportsTools: false },
568575
},
569576
]);
@@ -597,6 +604,7 @@ describe("prepared model catalog builder", () => {
597604
provider: "custom",
598605
api: "openai-responses",
599606
baseUrl: "https://route-a.example.test/v1",
607+
thinkingLevelMap: { xhigh: null, max: null },
600608
compat: { supportsTools: true },
601609
},
602610
],
@@ -608,6 +616,7 @@ describe("prepared model catalog builder", () => {
608616
).toMatchObject({
609617
api: "openai-responses",
610618
baseUrl: "https://route-a.example.test/v1",
619+
thinkingLevelMap: { xhigh: null, max: null },
611620
compat: { supportsTools: true },
612621
});
613622
});

‎src/agents/model-catalog.ts‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type DiscoveredModel = {
5757
contextWindow?: number;
5858
contextTokens?: number;
5959
reasoning?: boolean;
60+
thinkingLevelMap?: ModelCatalogEntry["thinkingLevelMap"];
6061
input?: ModelInputType[];
6162
params?: ModelCatalogEntry["params"];
6263
compat?: ModelCatalogEntry["compat"];
@@ -183,6 +184,7 @@ function clearRouteBoundCatalogMetadata(entry: ModelCatalogEntry): ModelCatalogE
183184
contextWindowDefault: _contextWindowDefault,
184185
contextTokens: _contextTokens,
185186
reasoning: _reasoning,
187+
thinkingLevelMap: _thinkingLevelMap,
186188
input: _input,
187189
params: _params,
188190
compat: _compat,
@@ -196,7 +198,7 @@ function overlayCatalogMetadata(
196198
base: ModelCatalogEntry,
197199
overlay: ModelCatalogEntry,
198200
options?: {
199-
catalogCompatRoute?: ModelCatalogEntry;
201+
catalogRoute?: ModelCatalogEntry;
200202
preserveBaseCompat?: boolean;
201203
preserveBaseName?: boolean;
202204
},
@@ -207,6 +209,7 @@ function overlayCatalogMetadata(
207209
const routeChanged = catalogRouteChanges(base, overlay);
208210
const routeBase = routeChanged ? clearRouteBoundCatalogMetadata(base) : base;
209211
const params = mergeCatalogParams(routeBase.params, overlay.params);
212+
const thinkingLevelMap = overlay.thinkingLevelMap ?? options?.catalogRoute?.thinkingLevelMap;
210213
// Options + default are one normalized unit (default ∈ options): an overlay
211214
// that replaces the options list must also own the default, or a base default
212215
// absent from the new list would leak through the field-by-field merge.
@@ -243,6 +246,7 @@ function overlayCatalogMetadata(
243246
...(overlay.contextWindow !== undefined ? { contextWindow: overlay.contextWindow } : {}),
244247
...(overlay.contextTokens !== undefined ? { contextTokens: overlay.contextTokens } : {}),
245248
...(overlay.reasoning !== undefined ? { reasoning: overlay.reasoning } : {}),
249+
...(thinkingLevelMap ? { thinkingLevelMap } : {}),
246250
...(overlay.input !== undefined ? { input: overlay.input } : {}),
247251
...(params ? { params } : {}),
248252
...(overlay.mediaInput !== undefined ? { mediaInput: overlay.mediaInput } : {}),
@@ -253,8 +257,8 @@ function overlayCatalogMetadata(
253257
...(overlay.replacedBy !== undefined ? { replacedBy: overlay.replacedBy } : {}),
254258
compat: options?.preserveBaseCompat
255259
? resolveCatalogOwnedModelCompat({
256-
catalogRoute: options.catalogCompatRoute ?? base,
257-
catalogCompat: (options.catalogCompatRoute ?? base).compat,
260+
catalogRoute: options.catalogRoute ?? base,
261+
catalogCompat: (options.catalogRoute ?? base).compat,
258262
configuredRoute: {
259263
api: overlay.api ?? base.api,
260264
baseUrl: overlay.baseUrl ?? base.baseUrl,
@@ -279,7 +283,7 @@ function mergeCatalogEntries(
279283
models: ModelCatalogEntry[],
280284
entries: ModelCatalogEntry[],
281285
options?: {
282-
catalogCompatRoutes?: readonly ModelCatalogEntry[];
286+
catalogRoutes?: readonly ModelCatalogEntry[];
283287
preserveBaseCompat?: boolean;
284288
preserveBaseName?: boolean;
285289
},
@@ -297,16 +301,16 @@ function mergeCatalogEntries(
297301
}
298302
const existing = models.at(existingIndex);
299303
if (existing) {
300-
// The logical row may currently represent a sibling physical route. Compat
301-
// must come from the catalog variant selected by config, not that sibling.
302-
const catalogCompatRoute = options?.preserveBaseCompat
303-
? options.catalogCompatRoutes?.find(
304+
// Logical rows can represent a sibling route; capabilities must come
305+
// from the exact catalog variant selected by config, not that sibling.
306+
const catalogRoute = options?.preserveBaseCompat
307+
? options.catalogRoutes?.find(
304308
(candidate) => catalogRouteVariantKey(candidate) === catalogRouteVariantKey(entry),
305309
)
306310
: undefined;
307311
models[existingIndex] = overlayCatalogMetadata(existing, entry, {
308312
...options,
309-
catalogCompatRoute,
313+
catalogRoute,
310314
});
311315
}
312316
}
@@ -454,6 +458,9 @@ export function loadManifestModelCatalog(params: {
454458
if (typeof row.reasoning === "boolean") {
455459
entry.reasoning = row.reasoning;
456460
}
461+
if (row.thinkingLevelMap) {
462+
entry.thinkingLevelMap = { ...row.thinkingLevelMap };
463+
}
457464
if (row.input?.length) {
458465
entry.input = [...row.input];
459466
}
@@ -561,6 +568,7 @@ export async function buildPreparedModelCatalogSnapshot(
561568
contextWindow,
562569
...(contextTokens !== undefined ? { contextTokens } : {}),
563570
reasoning,
571+
...(entry.thinkingLevelMap ? { thinkingLevelMap: entry.thinkingLevelMap } : {}),
564572
input,
565573
...(modelParams ? { params: modelParams } : {}),
566574
compat,
@@ -606,7 +614,7 @@ export async function buildPreparedModelCatalogSnapshot(
606614
if (configuredModels.length > 0) {
607615
const entriesForAugment = [...models];
608616
mergeCatalogEntries(entriesForAugment, configuredModels, {
609-
catalogCompatRoutes: routeVariants.entries,
617+
catalogRoutes: routeVariants.entries,
610618
preserveBaseCompat: true,
611619
preserveBaseName: true,
612620
});
@@ -692,7 +700,7 @@ export async function buildPreparedModelCatalogSnapshot(
692700
if (configuredModels.length > 0) {
693701
mergeCatalogRouteVariants(routeVariants, configuredModels, { preserveBaseCompat: true });
694702
mergeCatalogEntries(models, configuredModels, {
695-
catalogCompatRoutes: routeVariants.entries,
703+
catalogRoutes: routeVariants.entries,
696704
preserveBaseCompat: true,
697705
preserveBaseName: true,
698706
});

‎src/agents/model-catalog.types.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
import type { ModelCatalogStatus } from "@openclaw/model-catalog-core/model-catalog-types";
77
import type { ModelApi, ModelCompatConfig, ModelMediaInputConfig } from "../config/types.models.js";
8+
import type { ThinkingLevelMap } from "../llm/types.js";
89
import type { ProviderCatalogOutcome } from "../plugins/provider-catalog-outcome.js";
910

1011
/** Input modalities a catalog entry can advertise. */
@@ -36,6 +37,8 @@ export type ModelCatalogEntry = {
3637
configuredReasoning?: boolean;
3738
/** Concrete runtime owner of thinking policy; internal and never project to clients. */
3839
thinkingPolicyProvider?: string;
40+
/** Provider-owned effort support for this exact physical model route. */
41+
thinkingLevelMap?: ThinkingLevelMap;
3942
input?: ModelInputType[];
4043
params?: Record<string, unknown>;
4144
compat?: ModelCompatConfig;

‎src/agents/model-selection-shared.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,7 @@ export function buildConfiguredModelCatalog(params: {
14581458
contextTokens,
14591459
reasoning,
14601460
...(typeof model?.reasoning === "boolean" ? { configuredReasoning: model.reasoning } : {}),
1461+
...(model.thinkingLevelMap ? { thinkingLevelMap: model.thinkingLevelMap } : {}),
14611462
input,
14621463
...(modelParams ? { params: modelParams } : {}),
14631464
compat,

‎src/agents/model-selection.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,7 @@ describe("model-selection", () => {
827827
id: "Qwen/Qwen3-8B",
828828
name: "Qwen 3 8B",
829829
reasoning: true,
830+
thinkingLevelMap: { off: null, max: "max" },
830831
compat: {
831832
thinkingFormat: "qwen-chat-template",
832833
},
@@ -843,6 +844,7 @@ describe("model-selection", () => {
843844
expect(model?.compat).toEqual({ thinkingFormat: "qwen-chat-template" });
844845
expect(model?.reasoning).toBe(true);
845846
expect(model?.configuredReasoning).toBe(true);
847+
expect(model?.thinkingLevelMap).toEqual({ off: null, max: "max" });
846848
});
847849

848850
it("carries configured model params into catalog entries for provider policy", () => {

‎src/agents/prepared-model-runtime.configured.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export function toStaticCatalogEntry(model: ProviderRuntimeModel): ModelCatalogE
7575
...(model.contextWindowDefault ? { contextWindowDefault: model.contextWindowDefault } : {}),
7676
...(model.contextTokens ? { contextTokens: model.contextTokens } : {}),
7777
...(model.reasoning !== undefined ? { reasoning: model.reasoning } : {}),
78+
...(model.thinkingLevelMap ? { thinkingLevelMap: model.thinkingLevelMap } : {}),
7879
...(model.input ? { input: model.input } : {}),
7980
...(model.params ? { params: model.params } : {}),
8081
...(model.compat ? { compat: model.compat } : {}),

0 commit comments

Comments
 (0)