A2UI Launched: Full CopilotKit support at launch!

A2UI Launched: CopilotKit has partnered with Google to deliver full support in both CopilotKit and AG-UI!

Check it out
LogoLogo
  • Overview
  • Integrations
  • API Reference
  • Copilot Cloud
Slanted end borderSlanted end border
Slanted start borderSlanted start border
  • API Reference
  • UI Components
  • CopilotTextarea
  • CopilotKit
  • Hooks
  • useAgent
  • useDefaultTool
  • useFrontendTool
  • useRenderToolCall
  • useHumanInTheLoop
  • useCopilotReadable
  • useCopilotAdditionalInstructions
  • useCopilotChat
  • useCopilotChatHeadless_c
  • useCopilotChatSuggestions
  • useCoAgent
  • useCoAgentStateRender
  • useLangGraphInterrupt
  • useCopilotAction
  • Classes
  • CopilotRuntime
  • CopilotTask
  • SDKs
LLM Adapters

LangChainAdapter

Copilot Runtime adapter for LangChain.

Copilot Runtime adapter for LangChain.

Example

import { CopilotRuntime, LangChainAdapter } from "@copilotkit/runtime";
import { ChatOpenAI } from "@langchain/openai";
 
const copilotKit = new CopilotRuntime();
 
const model = new ChatOpenAI({
  model: "gpt-4o",
  apiKey: "<your-api-key>",
});
 
return 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

chainFn(parameters: ChainFnParameters) => Promise<LangChainReturnType>required

A function that uses the LangChain API to generate a response.

PREV
AnthropicAdapter
Slanted end borderSlanted end border
Slanted start borderSlanted start border
NEXT
GroqAdapter

On this page

Example
Constructor Parameters