CopilotKit / CopilotKit/CopilotKit

🐛 Bug: LangChainAdapter Regression in v1.50.0+ (Unknown provider "undefined")

Open
#3,217 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
37.4k
Forks
4.6k
Avg merge
1d 6h
Merged PRs (30d)
444

Description

Summary

In @copilotkit/runtime versions 1.50.0 and later, using LangChainAdapter (or any custom CopilotServiceAdapter that doesn't define provider/model properties) causes the runtime to crash with an Unknown provider "undefined" error.

Furthermore, the new architecture attempts to wrap the adapter in a BuiltInAgent, which completely bypasses the adapter's process() method. This means custom chainFn logic in LangChainAdapter is ignored, breaking all custom LangChain/LangGraph integrations that rely on the v1 adapter pattern.

♻️ Reproduction Steps
  1. Initialize CopilotRuntime with a LangChainAdapter.
    const serviceAdapter = new LangChainAdapter({
      chainFn: async ({ messages, tools }) => {
        // Custom LangChain logic
        return model.stream(messages);
      }
    });
    
    const runtime = new CopilotRuntime();
    
    // Mount endpoint
    const handler = copilotRuntimeNodeExpressEndpoint({
      endpoint: "/copilotkit",
      runtime,
      serviceAdapter,
    });
    
  2. Send a message to the chat endpoint.
✅ Expected Behavior

The runtime should delegate execution to serviceAdapter.process(), allowing the LangChainAdapter to execute its chainFn and stream the response back to the client.

❌ Actual Behavior

The runtime crashes immediately with the following error:

Agent execution failed: Error: Unknown provider "undefined" in "undefined/undefined". Supported: openai, anthropic, google (gemini).
    at resolveModel (.../node_modules/@copilotkitnext/agent/src/index.ts:208:13)
    ...
𝌚 CopilotKit Version
## Environment
- **Package:** `@copilotkit/runtime`
- **Version:** `1.50.0` - `1.51.4` (Current)
- **Adapter:** `LangChainAdapter` (or any custom adapter)
- **Framework:** Node.js / Express / Hono
📄 Logs (Optional)

Root Cause Analysis

1. Invalid Model Resolution

In packages/v1/runtime/src/lib/runtime/copilot-runtime.ts, the handleServiceAdapter method attempts to convert legacy adapters into the new BuiltInAgent architecture. It constructs a model string by reading properties that do not exist on LangChainAdapter:

// copilot-runtime.ts
agentsList.default = new BuiltInAgent({
// LangChainAdapter does not have .provider or .model properties
model: ${serviceAdapter.provider}/${serviceAdapter.model},
});

This results in the string "undefined/undefined", which causes resolveModel in @copilotkitnext/agent to throw.

2. Execution Logic Bypass (Critical)

Even if the model string were valid (e.g., by patching the adapter), BuiltInAgent uses the Vercel AI SDK's streamText directly. It does not call serviceAdapter.process().

This means the core functionality of LangChainAdapter—executing the user-defined chainFn—is completely unreachable in the new architecture. The runtime effectively discards the custom logic provided in the adapter.

Impact

  • Blocker: Users cannot upgrade to v1.50+ if they use LangChainAdapter or custom adapters.
  • Functionality Loss: Custom chains, RAG pipelines, and LangGraph workflows defined via chainFn are non-functional.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/v1/runtime/src/lib/runtime/copilot-runtime.ts at handleServiceAdapter and trace how the adapter becomes a BuiltInAgent; compare this with the LangChainAdapter process() path and the model resolution failure in @copilotkitnext/agent. Reproduce the chat request from the issue and verify that custom chainFn execution is reached through serviceAdapter.process() without an undefined provider or model error.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, node.js, typescript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.