# LangGraph SDK

> Use the CopilotKit LangGraph SDK for JavaScript to build and run LangGraph workflows with CopilotKit.

## 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/sdk-js/src/langgraph/utils.ts
  */
}
## copilotkitCustomizeConfig [#copilotkitcustomizeconfig]

Customize the LangGraph configuration for use in CopilotKit.

To install the CopilotKit SDK, run:

```bash
npm install @copilotkit/sdk-js
```

### Examples [#examples]

Disable emitting messages and tool calls:

```typescript
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.)

```typescript
import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js/langgraph";

const customConfig = copilotkitCustomizeConfig(config, {
  emitIntermediateState: [
    {
      stateKey: "steps",
      tool: "SearchTool",
      toolArgument: "steps",
    },
  ],
});
```

### Parameters [#parameters]

<PropertyReference name="baseConfig" type="RunnableConfig" required > 
The LangChain/LangGraph configuration to customize.
</PropertyReference>

<PropertyReference name="options" type="OptionsConfig"  > 
Configuration options:
- `emitMessages: boolean?`
  Configure how messages are emitted. By default, all messages are emitted. Pass false to
  disable emitting messages.
- `emitToolCalls: boolean | string | string[]?`
  Configure how tool calls are emitted. By default, all tool calls are emitted. Pass false to
  disable emitting tool calls. Pass a string or list of strings to emit only specific tool calls.
- `emitIntermediateState: IntermediateStateConfig[]?`
  Lets you emit tool calls as streaming LangGraph state.
</PropertyReference>

## copilotkitExit [#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 [#examples-1]

```typescript
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 [#parameters-1]

<PropertyReference name="config" type="RunnableConfig" required > 
The LangChain/LangGraph configuration.
</PropertyReference>

## copilotkitEmitState [#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 [#examples-2]

```typescript
import { copilotkitEmitState } from "@copilotkit/sdk-js/langgraph";

for (let i = 0; i < 10; i++) {
  await someLongRunningOperation(i);
  await copilotkitEmitState(config, { progress: i });
}
```

### Parameters [#parameters-2]

<PropertyReference name="config" type="RunnableConfig" required > 
The LangChain/LangGraph configuration.
</PropertyReference>

<PropertyReference name="state" type="any" required > 
The state to emit.
</PropertyReference>

## copilotkitEmitMessage [#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 [#examples-3]

```typescript
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 [#parameters-3]

<PropertyReference name="config" type="RunnableConfig" required > 
The LangChain/LangGraph configuration.
</PropertyReference>

<PropertyReference name="message" type="string" required > 
The message to emit.
</PropertyReference>

## copilotkitEmitToolCall [#copilotkitemittoolcall]

Manually emits a tool call to CopilotKit.

### Examples [#examples-4]

```typescript
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 [#parameters-4]

<PropertyReference name="config" type="RunnableConfig" required > 
The LangChain/LangGraph configuration.
</PropertyReference>

<PropertyReference name="name" type="string" required > 
The name of the tool to emit.
</PropertyReference>

<PropertyReference name="args" type="any" required > 
The arguments to emit.
</PropertyReference>

<PropertyReference name="options" type="{ toolCallId?: string; }"  > 
Options for the tool call emission.
</PropertyReference>

### Returns [#returns]

The tool call ID used for the emitted call. It equals `options.toolCallId`
when provided, otherwise a randomly generated ID.
