Skip to content

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

Description

@jellespijker

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions