LangGraph SDK
Use the CopilotKit LangGraph SDK for JavaScript to build and run LangGraph workflows with CopilotKit.
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. Open the complete export map.
copilotkitCustomizeConfig
Customize the LangGraph configuration for use in CopilotKit.
To install the CopilotKit SDK, run:
npm install @copilotkit/sdk-jsExamples
Disable emitting messages and tool calls:
import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js/langgraph";
const customConfig = copilotkitCustomizeConfig(config, {
emitMessages: false,
emitToolCalls: false,
});To emit a tool call as streaming LangGraph state, pass the destination key in state, the tool name and optionally the tool argument. (If you don't pass the argument name, all arguments are emitted under the state key.)
import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js/langgraph";
const customConfig = copilotkitCustomizeConfig(config, {
emitIntermediateState: [
{
stateKey: "steps",
tool: "SearchTool",
toolArgument: "steps",
},
],
});Parameters
Prop
Type
copilotkitExit
Exits the current agent after the run completes. Calling copilotkitExit() will not immediately stop the agent. Instead, it signals to CopilotKit to stop the agent after the run completes.
Examples
import type { RunnableConfig } from "@langchain/core/runnables";
import { copilotkitExit } from "@copilotkit/sdk-js/langgraph";
async function myNode(state: AgentState, config: RunnableConfig) {
await copilotkitExit(config);
return state;
}Parameters
Prop
Type
copilotkitEmitState
Emits intermediate state to CopilotKit. Useful if you have a longer running node and you want to update the user with the current state of the node.
Examples
import { copilotkitEmitState } from "@copilotkit/sdk-js/langgraph";
for (let i = 0; i < 10; i++) {
await someLongRunningOperation(i);
await copilotkitEmitState(config, { progress: i });
}Parameters
Prop
Type
copilotkitEmitMessage
Manually emits a message to CopilotKit. Useful in longer running nodes to update the user. Important: You still need to return the messages from the node.
Examples
import { AIMessage } from "@langchain/core/messages";
import { copilotkitEmitMessage } from "@copilotkit/sdk-js/langgraph";
const message = "Step 1 of 10 complete";
await copilotkitEmitMessage(config, message);
// Return the message from the node
return {
messages: [new AIMessage({ content: message })],
};Parameters
Prop
Type
copilotkitEmitToolCall
Manually emits a tool call to CopilotKit.
Examples
import { copilotkitEmitToolCall } from "@copilotkit/sdk-js/langgraph";
const autoId = await copilotkitEmitToolCall(config, "SearchTool", { steps: 10 });
// With a custom ID for correlation/idempotency:
const customId = await copilotkitEmitToolCall(config, "SearchTool", { steps: 10 }, { toolCallId: "my-custom-id" });Parameters
Prop
Type
Returns
The tool call ID used for the emitted call. It equals options.toolCallId
when provided, otherwise a randomly generated ID.
How is this guide?