---
title: "LangChainAdapter"
description: "CopilotKit Adapter for LangChain"
---

{/* GENERATE-DOCS path=packages/runtime/src/service-adapters/langchain/langchain-adapter.ts class=LangChainAdapter */}
 
Use this adapter to use LangChain as a backend.
 
```typescript
return copilotKit.response(
  req,
  new LangChainAdapter({
    chainFn: async ({ messages, tools }) => {
      const model = new ChatOpenAI({ modelName: "gpt-4o" });
      return model.stream(messages, { tools });
    },
  })
);
```
The async handler function can return:
 
- a simple `string` response
- a LangChain stream `IterableReadableStream`
- a LangChain `BaseMessageChunk` object
- a LangChain `AIMessage` object

## Constructor

<ResponseField name="chainFn" type="(parameters: ChainFnParameters) => Promise<LangChainReturnType>" required>

</ResponseField>

## process(request: CopilotRuntimeChatCompletionRequest)



<ResponseField name="request" type="CopilotRuntimeChatCompletionRequest" required>

</ResponseField>

