Skip to content

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

fix(agent-runtime): handle generic Claude model configs

vastsab13fad50f270
diff --git a/docs/spec/03-runtime/11-provider-model-system.md b/docs/spec/03-runtime/11-provider-model-system.md
index e86d6dbbe..fa5881ff0 100644
--- a/docs/spec/03-runtime/11-provider-model-system.md
+++ b/docs/spec/03-runtime/11-provider-model-system.md
@@ -125,11 +125,15 @@ models.dev record publishes a reasoning `effort` option and no
reject `thinking.type=enabled` with HTTP 400, and the model's published
reasoning options determine that wire shape.
Models that still publish `budget_tokens`, including those that also publish
-`effort`, keep budget thinking by default. The catalog uses this same rule
-for the protocol displayed in model settings. An explicit
-`ModelBinding.thinkingProtocol` selection (`legacy` or `adaptive`) overrides
-the default; an absent field preserves the existing inference. An explicit
-catalog `compat` record is preserved.
+`effort`, keep budget thinking by default. A reasoning-enabled generic model
+config with no `thinkingProtocol` or reasoning options also defaults to
+adaptive thinking when its id contains `claude` and the wire API is Anthropic
+Messages; this covers unpublished Claude relay ids whose metadata is missing.
+An explicit `ModelBinding.thinkingProtocol` selection (`legacy` or `adaptive`)
+takes priority, followed by an explicit per-model
+`compat.forceAdaptiveThinking` value, then catalog metadata or the Claude-id
+fallback. For catalog-published models, model settings display the protocol
+derived from the same effort/budget metadata.
An Anthropic Messages row the catalog cannot identify (for example a custom
gateway URL serving an id several publishers list) still falls back to the
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 2e3b3dc96..9b7f34d19 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -499,19 +499,24 @@
### E2E-PROVIDER-adaptive-thinking-protocol
- **Preconditions:** Isolated provider settings fixture with an Anthropic
- Messages provider and models `claude-opus-5-5` and a legacy Claude model;
+ Messages provider, `claude-opus-5-5`, a legacy Claude model, and a
+ Claude-named relay id whose generic model config has no protocol or
+ reasoning-options metadata;
no live credentials.
- **Steps:** Open a configured model's Advanced settings, inspect the
thinking-protocol row, save an adaptive model with `medium`, then submit a
request through the local Anthropic transport fixture. Repeat with the
- legacy model.
+ legacy model. Submit a request with the protocol unset for the generic relay
+ model, then repeat after selecting its legacy protocol.
- **Expected:** The adaptive model sends `thinking.type=adaptive` and
`output_config.effort=medium`; the legacy model sends the existing
budget-based thinking shape. Omitting the new field on an old binding keeps
the existing inference after reload: effort-only models use adaptive, while
models publishing `budget_tokens` (including effort + budget combinations)
- retain budget thinking. Explicit standard/adaptive selections override
- those defaults.
+ retain budget thinking. The metadata-free generic Claude relay defaults to
+ adaptive, while its explicit legacy selection sends budget thinking. An
+ explicit per-model `compat.forceAdaptiveThinking` value overrides automatic
+ inference when no protocol is selected.
- **Specs:** 03-runtime/11-provider-model-system; 03-runtime/12-provider-config-schema.
- **Acceptance:** Provider/model protocol selection and wire compatibility.
- **Milestone:** Maintenance.
diff --git a/docs/zh-CN/spec/03-runtime/11-provider-model-system.md b/docs/zh-CN/spec/03-runtime/11-provider-model-system.md
index 5e1738dc2..299b84913 100644
--- a/docs/zh-CN/spec/03-runtime/11-provider-model-system.md
+++ b/docs/zh-CN/spec/03-runtime/11-provider-model-system.md
@@ -118,7 +118,12 @@ OpenAI 风格的 Copilot 线路 API 仍将令牌作为请求密钥签名;所
`forceAdaptiveThinking: true`。这些模型会以 HTTP 400 拒绝
`thinking.type=enabled`,而 Pi catalog 不携带 pi-ai 的 compat 记录,缺少该标志时
pi-ai 会回落到 budget 思考。仍发布 `budget_tokens` 的模型保持 budget 思考,显式的
-目录 `compat` 记录会被保留。
+目录 `compat` 记录会被保留。对于已启用推理、但没有 `thinkingProtocol` 或推理选项的
+通用模型配置,如果模型 ID 含有 `claude` 且 wire API 为 Anthropic Messages,也默认使用
+adaptive 思考;这覆盖缺少元数据的未发布 Claude 中继模型 ID。显式的
+`ModelBinding.thinkingProtocol`(`legacy` 或 `adaptive`)优先级最高,其次是显式的
+模型级 `compat.forceAdaptiveThinking`,再之后才根据目录元数据或 Claude ID 回退规则判断。
+对于目录中已发布的模型,模型设置会根据相同的 effort/budget 元数据推导并显示协议。
目录无法识别的 Anthropic Messages 行(例如某个自定义网关 URL 提供多家发布方都列出的
模型 ID)仍回退到通用模型形状,但当 Anthropic 自己的 Pi catalog 记录中存在完全相同的
diff --git a/packages/agent-runtime/src/provider-binding.test.ts b/packages/agent-runtime/src/provider-binding.test.ts
index 88dfd9840..ecc82d845 100644
--- a/packages/agent-runtime/src/provider-binding.test.ts
+++ b/packages/agent-runtime/src/provider-binding.test.ts
@@ -401,6 +401,34 @@ describe("Anthropic adaptive thinking from models.dev reasoning options", () =>
return requests[0];
}
+ function genericAnthropicProvider(
+ modelId: string,
+ overrides: Partial<
+ Pick<ModelConfig, "reasoningOptions" | "thinkingProtocol" | "compat">
+ > = {},
+ ): RuntimeProviderConfig {
+ const baseUrl = "https://gateway.example";
+ const modelConfig = modelConfigWithBinding(
+ {
+ ...genericModelConfig(modelId, baseUrl),
+ ...overrides,
+ },
+ {
+ contextWindow: 200_000,
+ maxTokens: 16_000,
+ thinkingLevels: ["off", "medium"],
+ ...(overrides.thinkingProtocol
+ ? { thinkingProtocol: overrides.thinkingProtocol }
+ : {}),
+ },
+ );
+ return {
+ ...anthropicProvider(modelId, overrides.reasoningOptions ?? []),
+ baseUrl,
+ modelConfig,
+ };
+ }
+
it("sends adaptive thinking to effort-only Claude models such as Opus 5.5", async () => {
const request = await thinkingRequest(
anthropicProvider("claude-opus-5-5", [
@@ -471,44 +499,74 @@ describe("Anthropic adaptive thinking from models.dev reasoning options", () =>
});
});
- // #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.
+ // #926: a catalog miss still arrives as a generic model config in sessions.
+ // Without protocol or reasoning options, a Claude id on the Anthropic wire
+ // defaults to adaptive thinking.
it("defaults adaptive thinking for a catalog-less Claude id on the Anthropic wire", async () => {
- const { modelConfig: _omitted, ...custom } = anthropicProvider(
- "claude-opus-5-5",
- [],
+ const provider = genericAnthropicProvider("claude-opus-5-5");
+ expect(provider.modelConfig?.source).toBe("generic");
+
+ const request = await thinkingRequest(provider);
+
+ expect(request?.thinking).toMatchObject({ type: "adaptive" });
+ expect(request?.thinking).not.toHaveProperty("budget_tokens");
+ });
+
+ it("keeps budget thinking when a generic model carries budget metadata", async () => {
+ const request = await thinkingRequest(
+ genericAnthropicProvider("claude-relay-model", {
+ reasoningOptions: [{ type: "budget_tokens", min: 1024 }],
+ }),
+ );
+
+ expect(request?.thinking).toMatchObject({ type: "enabled" });
+ expect(request?.thinking).toHaveProperty("budget_tokens");
+ });
+
+ it("honors an explicit legacy protocol on a generic Claude model", async () => {
+ const request = await thinkingRequest(
+ genericAnthropicProvider("claude-relay-model", {
+ thinkingProtocol: "legacy",
+ }),
);
- void _omitted;
- const request = await thinkingRequest({ ...custom, modelConfig: undefined });
+
+ expect(request?.thinking).toMatchObject({ type: "enabled" });
+ expect(request?.thinking).toHaveProperty("budget_tokens");
+ });
+
+ it("prioritizes an explicit protocol over a conflicting generic compat value", async () => {
+ const provider = genericAnthropicProvider("claude-relay-model", {
+ thinkingProtocol: "adaptive",
+ });
+ provider.modelConfig = {
+ ...provider.modelConfig!,
+ compat: { forceAdaptiveThinking: false },
+ };
+ const request = await thinkingRequest(provider);
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 },
- },
+ const optedOut = genericAnthropicProvider("claude-opus-5-5", {
+ compat: { forceAdaptiveThinking: false },
});
+ const model = buildProviderModel(optedOut);
expect(model.compat).toMatchObject({ forceAdaptiveThinking: false });
+ const request = await thinkingRequest(optedOut);
+ expect(request?.thinking).toMatchObject({ type: "enabled" });
+ expect(request?.thinking).toHaveProperty("budget_tokens");
// Precedence also holds when catalog reasoning options would derive the
// flag: the explicit record wins.
+ const effortOnly = anthropicProvider("claude-opus-5-5", [
+ { type: "effort", values: ["low", "medium", "high"] },
+ ]);
const derived = buildProviderModel({
- ...anthropicProvider("claude-opus-5-5", [
- { type: "effort", values: ["low", "medium", "high"] },
- ]),
+ ...effortOnly,
modelConfig: {
- ...anthropicProvider("claude-opus-5-5", []).modelConfig!,
+ ...effortOnly.modelConfig!,
compat: { forceAdaptiveThinking: false },
},
});
diff --git a/packages/agent-runtime/src/provider-binding.ts b/packages/agent-runtime/src/provider-binding.ts
index 1bb854c2e..bc3079ef5 100644
--- a/packages/agent-runtime/src/provider-binding.ts
+++ b/packages/agent-runtime/src/provider-binding.ts
@@ -349,12 +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.
+ // A generic model projection can still be present when the catalog misses a
+ // model (#926). With no protocol or reasoning options, a Claude id on the
+ // Anthropic wire is the remaining signal for adaptive thinking.
const customClaudeId =
- !provider.modelConfig &&
+ catalog?.source === "generic" &&
+ catalogModel.reasoning === true &&
+ catalogModel.thinkingProtocol === undefined &&
+ (catalogModel.reasoningOptions?.length ?? 0) === 0 &&
binding.api === "anthropic-messages" &&
/claude/i.test(provider.modelId);
// OpenAI-compatible gateways are not guaranteed to implement the newer
@@ -379,10 +381,12 @@ export function buildProviderModel(
? {
...(catalogModel.compat ?? {}),
...(thinkingProtocolCompat ?? {}),
- // 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,
+ // Explicit protocol selection wins, followed by per-model compat;
+ // the Claude-id heuristic supplies only the missing default.
+ forceAdaptiveThinking:
+ thinkingProtocolCompat?.forceAdaptiveThinking ??
+ catalogModel.compat?.forceAdaptiveThinking ??
+ true,
}
: thinkingProtocolCompat
? { ...(catalogModel.compat ?? {}), ...thinkingProtocolCompat }