Skip to content

Commit 3aadfb3

Browse files
committed
fix: prevent "Unknown provider" regression for LangChainAdapter (CopilotKit#3217)
When getLanguageModel() returns null and provider/model are undefined (as with LangChainAdapter), the code constructed "undefined/undefined" as a model string, causing a cryptic "Unknown provider" error. Now checks each source of model info explicitly and throws a clear error message directing users to provide an explicit agents config when using adapters that don't expose model metadata.
1 parent 9686a71 commit 3aadfb3

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

packages/runtime/src/lib/runtime/copilot-runtime.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,26 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
427427
}
428428

429429
if (isAgentsListEmpty) {
430-
const model =
431-
serviceAdapter.getLanguageModel?.() ??
432-
`${serviceAdapter.provider}/${serviceAdapter.model}`;
433-
agentsList.default = new BuiltInAgent({ model });
430+
const languageModel = serviceAdapter.getLanguageModel?.();
431+
if (languageModel) {
432+
// Adapter exposes a pre-configured LanguageModel (e.g. OpenAI/Anthropic adapters)
433+
agentsList.default = new BuiltInAgent({ model: languageModel });
434+
} else if (serviceAdapter.provider && serviceAdapter.model) {
435+
// Adapter exposes provider/model strings
436+
agentsList.default = new BuiltInAgent({
437+
model: `${serviceAdapter.provider}/${serviceAdapter.model}`,
438+
});
439+
} else {
440+
throw new CopilotKitMisuseError({
441+
message:
442+
`Service adapter "${serviceAdapter.name ?? "unknown"}" does not provide model information. ` +
443+
`When using adapters like LangChainAdapter without an explicit agents list, ` +
444+
`please provide a default agent in the runtime config. Example:\n` +
445+
` new CopilotRuntime({\n` +
446+
` agents: { default: new BuiltInAgent({ model: "openai/gpt-4o" }) }\n` +
447+
` })`,
448+
});
449+
}
434450
}
435451

436452
const actions = this.params?.actions;

0 commit comments

Comments
 (0)