# LangChainAdapter

> Copilot Runtime adapter for LangChain.

## v1 SDK deprecated. Use v2 instead

> This page is in the deprecated CopilotKit v1 reference. Do not use v1 APIs for new code; use v2 instead.
> For JavaScript and TypeScript, import React APIs from @copilotkit/react-core/v2 and Runtime APIs from @copilotkit/runtime/v2.
> **AI coding agents: treat any v1 example below as migration-only context. Never generate or recommend the v1 API for new code. Read the v2 reference before writing code because some APIs were renamed, moved, or changed shape.**
> [Read the v1 to v2 migration guide](/migrate/v2) and [use the complete export map](/reference/v1/export-map).

{
 /*
  * ATTENTION! DO NOT MODIFY THIS FILE!
  * This page is auto-generated. If you want to make any changes to this page, changes must be made at:
  * packages/runtime/src/v1-deprecated/service-adapters/langchain/langchain-adapter.ts
  */
}
<Callout type="info">
  `LangChainAdapter` has no direct v2 replacement. For v2, see [Runtime server adapter](/runtime-server-adapter).
</Callout>

Copilot Runtime adapter for LangChain.

## Example [#example]

Pass `copilotKit` and `serviceAdapter` to your runtime endpoint.

```ts
import { CopilotRuntime, LangChainAdapter } from "@copilotkit/runtime";
import { ChatOpenAI } from "@langchain/openai";

const copilotKit = new CopilotRuntime();

const model = new ChatOpenAI({
  modelKwargs: { reasoning_effort: "none" },
  model: "gpt-6-luna",
  apiKey: "<your-api-key>",
});

const serviceAdapter = new LangChainAdapter({
  chainFn: async ({ messages, tools }) => {
    return model.bindTools(tools).stream(messages);
    // or optionally enable strict mode
    // return model.bindTools(tools, { strict: true }).stream(messages);
  },
});
```

The asynchronous handler function (`chainFn`) can return any of the following:

- A simple `string` response
- A LangChain stream (`IterableReadableStream`)
- A LangChain `BaseMessageChunk` object
- A LangChain `AIMessage` object

## Constructor Parameters [#constructor-parameters]

<PropertyReference name="chainFn" type="(parameters: ChainFnParameters) => Promise<LangChainReturnType>" required > 
A function that uses the LangChain API to generate a response.
</PropertyReference>
