Skip to content

Commit 54dacaa

Browse files
committed
fix: explain missing provider model registration
1 parent aac9ebd commit 54dacaa

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

src/agents/pi-embedded-runner/model.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,26 @@ describe("resolveModel", () => {
918918
});
919919
});
920920

921+
it("explains when a provider plugin model is only configured in agent defaults", () => {
922+
const cfg = {
923+
agents: {
924+
defaults: {
925+
models: {
926+
"microsoft-foundry/Kimi-K2.6-1": {
927+
params: { deployment: "Kimi-K2.6-1" },
928+
},
929+
},
930+
},
931+
},
932+
} as unknown as OpenClawConfig;
933+
934+
const result = resolveModelForTest("microsoft-foundry", "Kimi-K2.6-1", "/tmp/agent", cfg);
935+
936+
expect(result.error).toBe(
937+
"Unknown model: microsoft-foundry/Kimi-K2.6-1. Found in agents.defaults.models but not in models.providers['microsoft-foundry'].models[]. Both blocks are required to register a model with a provider plugin.",
938+
);
939+
});
940+
921941
it("propagates reasoning from matching configured fallback model", () => {
922942
const cfg = {
923943
models: {

src/agents/pi-embedded-runner/model.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,62 @@ function findConfiguredAgentModelParams(params: {
488488
return undefined;
489489
}
490490

491+
function findConfiguredAgentModelEntry(params: {
492+
cfg?: OpenClawConfig;
493+
provider: string;
494+
modelId: string;
495+
}) {
496+
const configuredModels = params.cfg?.agents?.defaults?.models;
497+
if (!configuredModels) {
498+
return undefined;
499+
}
500+
const directKeys = [
501+
modelKey(params.provider, params.modelId),
502+
`${params.provider}/${params.modelId}`,
503+
];
504+
for (const key of directKeys) {
505+
if (Object.prototype.hasOwnProperty.call(configuredModels, key)) {
506+
return configuredModels[key];
507+
}
508+
}
509+
510+
const normalizedProvider = normalizeProviderId(params.provider);
511+
const normalizedModelId = normalizeStaticProviderModelId(normalizedProvider, params.modelId)
512+
.trim()
513+
.toLowerCase();
514+
for (const [rawKey, entry] of Object.entries(configuredModels)) {
515+
const slashIndex = rawKey.indexOf("/");
516+
if (slashIndex <= 0) {
517+
continue;
518+
}
519+
const candidateProvider = rawKey.slice(0, slashIndex);
520+
const candidateModelId = rawKey.slice(slashIndex + 1);
521+
if (
522+
normalizeProviderId(candidateProvider) === normalizedProvider &&
523+
normalizeStaticProviderModelId(normalizedProvider, candidateModelId).trim().toLowerCase() ===
524+
normalizedModelId
525+
) {
526+
return entry;
527+
}
528+
}
529+
return undefined;
530+
}
531+
532+
function buildMissingProviderModelRegistrationHint(params: {
533+
cfg?: OpenClawConfig;
534+
provider: string;
535+
modelId: string;
536+
}): string | undefined {
537+
if (!findConfiguredAgentModelEntry(params)) {
538+
return undefined;
539+
}
540+
const providerConfig = resolveConfiguredProviderConfig(params.cfg, params.provider);
541+
if (findConfiguredProviderModel(providerConfig, params.provider, params.modelId)) {
542+
return undefined;
543+
}
544+
return `Found in agents.defaults.models but not in models.providers['${params.provider}'].models[]. Both blocks are required to register a model with a provider plugin.`;
545+
}
546+
491547
function mergeConfiguredRuntimeModelParams(params: {
492548
cfg?: OpenClawConfig;
493549
provider: string;
@@ -1223,6 +1279,10 @@ function buildUnknownModelError(params: {
12231279
return suppressed;
12241280
}
12251281
const base = `Unknown model: ${params.provider}/${params.modelId}`;
1282+
const configHint = buildMissingProviderModelRegistrationHint(params);
1283+
if (configHint) {
1284+
return `${base}. ${configHint}`;
1285+
}
12261286
const runtimeHooks = params.runtimeHooks ?? DEFAULT_PROVIDER_RUNTIME_HOOKS;
12271287
const hint = runtimeHooks.buildProviderUnknownModelHintWithPlugin({
12281288
provider: params.provider,

0 commit comments

Comments
 (0)