Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(agent-runtime): default adaptive thinking for custom Claude model ids

yexisu017bfba4af48
diff --git a/packages/agent-runtime/src/provider-binding.test.ts b/packages/agent-runtime/src/provider-binding.test.ts
index ad755e70a..88dfd9840 100644
--- a/packages/agent-runtime/src/provider-binding.test.ts
+++ b/packages/agent-runtime/src/provider-binding.test.ts
@@ -470,6 +470,50 @@ describe("Anthropic adaptive thinking from models.dev reasoning options", () =>
forceAdaptiveThinking: true,
});
});
+
+ // #926: a custom relay model id has no catalog entry, so reasoning options
+ // cannot derive the adaptive flag. A Claude-shaped id on the Anthropic wire
+ // defaults it on.
+ it("defaults adaptive thinking for a catalog-less Claude id on the Anthropic wire", async () => {
+ const { modelConfig: _omitted, ...custom } = anthropicProvider(
+ "claude-opus-5-5",
+ [],
+ );
+ void _omitted;
+ const request = await thinkingRequest({ ...custom, modelConfig: undefined });
+
+ expect(request?.thinking).toMatchObject({ type: "adaptive" });
+ expect(request?.thinking).not.toHaveProperty("budget_tokens");
+ });
+
+ it("lets a per-model compat record opt a custom Claude id out of adaptive thinking", async () => {
+ const { modelConfig: _omitted, ...custom } = anthropicProvider(
+ "claude-opus-5-5",
+ [],
+ );
+ void _omitted;
+ const model = buildProviderModel({
+ ...custom,
+ modelConfig: {
+ ...genericModelConfig("claude-opus-5-5", "https://gateway.example"),
+ compat: { forceAdaptiveThinking: false },
+ },
+ });
+ expect(model.compat).toMatchObject({ forceAdaptiveThinking: false });
+
+ // Precedence also holds when catalog reasoning options would derive the
+ // flag: the explicit record wins.
+ const derived = buildProviderModel({
+ ...anthropicProvider("claude-opus-5-5", [
+ { type: "effort", values: ["low", "medium", "high"] },
+ ]),
+ modelConfig: {
+ ...anthropicProvider("claude-opus-5-5", []).modelConfig!,
+ compat: { forceAdaptiveThinking: false },
+ },
+ });
+ expect(derived.compat).toMatchObject({ forceAdaptiveThinking: false });
+ });
});
describe("buildProviderModel OpenAI-compatible role compatibility", () => {
diff --git a/packages/agent-runtime/src/provider-binding.ts b/packages/agent-runtime/src/provider-binding.ts
index c42d42b5f..1bb854c2e 100644
--- a/packages/agent-runtime/src/provider-binding.ts
+++ b/packages/agent-runtime/src/provider-binding.ts
@@ -349,6 +349,14 @@ export function buildProviderModel(
: undefined;
const autoAdaptiveThinking =
catalogModel.thinkingProtocol === undefined && requiresAdaptiveThinking(catalogModel);
+ // A custom model id on the Anthropic wire shape has no catalog reasoning
+ // options to derive from (#926): relays rename Claude models, so the id is
+ // the only signal. Default effort-only adaptive thinking on for a Claude id;
+ // a per-model compat record still overrides it for non-Claude backends.
+ const customClaudeId =
+ !provider.modelConfig &&
+ binding.api === "anthropic-messages" &&
+ /claude/i.test(provider.modelId);
// OpenAI-compatible gateways are not guaranteed to implement the newer
// `developer` role, even when the selected model supports reasoning. Keep
// the broadest Chat Completions wire shape as the default; a catalog/model
@@ -365,11 +373,16 @@ export function buildProviderModel(
supportsDeveloperRole: catalogModel.compat?.supportsDeveloperRole === true,
}
: binding.api === "anthropic-messages" &&
- (catalogModel.thinkingProtocol === "adaptive" || autoAdaptiveThinking)
+ (catalogModel.thinkingProtocol === "adaptive" ||
+ autoAdaptiveThinking ||
+ customClaudeId)
? {
...(catalogModel.compat ?? {}),
...(thinkingProtocolCompat ?? {}),
- forceAdaptiveThinking: true,
+ // A per-model compat record keeps precedence over the id-derived
+ // default so a non-Claude backend behind a Claude-shaped id can
+ // opt out explicitly.
+ forceAdaptiveThinking: catalogModel.compat?.forceAdaptiveThinking ?? true,
}
: thinkingProtocolCompat
? { ...(catalogModel.compat ?? {}), ...thinkingProtocolCompat }