Skip to content

Commit b48fd1b

Browse files
committed
fix(btw): resolve agentRuntime alias models in /btw side questions (fixes #92168)
When the agent primary model is configured as a canonical alias routed via agentRuntime (e.g. anthropic/claude-opus with agentRuntime.id: claude-cli), /btw fails with 'Unknown model' because the model is not in the standard model registry. The same model works for the main turn because the harness selection routes through the configured runtime. Fix: when the model isn't found in the registry, check if it's configured with an agentRuntime in agents.defaults.models and synthesize a minimal model object so the downstream harness selection can route through the configured runtime.
1 parent 9827490 commit b48fd1b

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/agents/btw.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { EmbeddedBlockChunker, type BlockReplyChunking } from "./embedded-agent-
2727
import { resolveModelWithRegistry } from "./embedded-agent-runner/model.js";
2828
import { getActiveEmbeddedRunSnapshot } from "./embedded-agent-runner/runs.js";
2929
import { resolveEmbeddedAgentStreamFn } from "./embedded-agent-runner/stream-resolution.js";
30-
import { applyPreparedRuntimeAuthToModel } from "./provider-request-config.js";
3130
import { resolveAvailableAgentHarnessPolicy, selectAgentHarness } from "./harness/selection.js";
3231
import {
3332
resolveImageSanitizationLimits,
@@ -41,6 +40,7 @@ import {
4140
} from "./model-auth.js";
4241
import { ensureOpenClawModelsJson } from "./models-config.js";
4342
import { listOpenAIAuthProfileProvidersForAgentRuntime } from "./openai-routing.js";
43+
import { applyPreparedRuntimeAuthToModel } from "./provider-request-config.js";
4444
import { registerProviderStreamForModel } from "./provider-stream.js";
4545
import { stripToolResultDetails } from "./session-transcript-repair.js";
4646
import { sanitizeImageBlocks } from "./tool-images.js";
@@ -258,12 +258,23 @@ async function resolveRuntimeModel(params: {
258258
await ensureOpenClawModelsJson(params.cfg, params.agentDir, modelsOptions);
259259
const authStorage = discoverAuthStorage(params.agentDir);
260260
const modelRegistry = discoverModels(authStorage, params.agentDir, modelsOptions);
261-
const model = resolveModelWithRegistry({
261+
let model = resolveModelWithRegistry({
262262
provider: params.provider,
263263
modelId: params.model,
264264
modelRegistry,
265265
cfg: params.cfg,
266266
});
267+
if (!model) {
268+
// When the primary model is configured via agentRuntime (e.g.
269+
// anthropic/claude-opus with agentRuntime.id: claude-cli), the model
270+
// won't be in the standard registry. Synthesize a minimal model so the
271+
// downstream harness selection can route through the configured runtime.
272+
const defaultsModels = params.cfg?.agents?.defaults?.models;
273+
const key = `${params.provider}/${params.model}`;
274+
if (defaultsModels?.[key]?.agentRuntime) {
275+
model = { id: params.model, provider: params.provider };
276+
}
277+
}
267278
if (!model) {
268279
throw new Error(`Unknown model: ${params.provider}/${params.model}`);
269280
}

0 commit comments

Comments
 (0)