LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
React SDK
Vue SDK
Svelte SDK
Angular SDK
LangGraph SDK
  • Ui
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Utils
  • Server
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
  • Store
LangGraph Checkpoint Redis
  • Shallow
  • Store
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
  • Cli
LangGraph API
LangGraph CLI
LangGraph CUA
  • Utils
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangGraph
WebChannelsPregelPrebuiltRemote
React SDK
Vue SDK
Svelte SDK
Angular SDK
LangGraph SDK
UiClientAuthReactLoggingReact UiUtilsServer
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
Store
LangGraph Checkpoint Redis
ShallowStore
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
Cli
LangGraph API
LangGraph CLI
LangGraph CUA
Utils
LangGraph Supervisor
LangGraph Swarm
Language
Theme
JavaScript@langchain/langgraph-sdk

@langchain/langgraph-sdk

Description

LangGraph JS/TS SDK

This repository contains the JS/TS SDK for interacting with the LangGraph REST API.

Quick Start

To get started with the JS/TS SDK, install the package

pnpm add @langchain/langgraph-sdk

You will need a running LangGraph API server. If you're running a server locally using langgraph-cli, SDK will automatically point at http://localhost:8123, otherwise you would need to specify the server URL when creating a client.

import { Client } from "@langchain/langgraph-sdk";

const client = new Client();

// List all assistants
const assistants = await client.assistants.search({
  metadata: null,
  offset: 0,
  limit: 10,
});

// We auto-create an assistant for each graph you register in config.
const agent = assistants[0];

// Start a new thread
const thread = await client.threads.create();

// Start a streaming run
const messages = [{ role: "human", content: "what's the weather in la" }];

const streamResponse = client.runs.stream(
  thread["thread_id"],
  agent["assistant_id"],
  {
    input: { messages },
  }
);

for await (const chunk of streamResponse) {
  console.log(chunk);
}

Documentation

To generate documentation, run the following commands:

  1. Generate docs.

     pnpm typedoc
    
  2. Consolidate doc files into one markdown file.

     npx concat-md --decrease-title-levels --ignore=js_ts_sdk_ref.md --start-title-level-at 2 docs > docs/js_ts_sdk_ref.md
    
  3. Copy js_ts_sdk_ref.md to MkDocs directory.

     cp docs/js_ts_sdk_ref.md ../../docs/docs/cloud/reference/sdk/js_ts_sdk_ref.md
    

Reference Documentation

The reference documentation is available here.

More usage examples can be found here.

Change Log

The change log for new versions can be found here.

Classes

Class

Auth

Class

HTTPException

Class

AssistantsClient

Class

Client

Class

CronsClient

Class

RunsClient

Class

StoreClient

Class

ThreadsClient

Class

StreamError

Class

Client

Class

FetchStreamTransport

Transport used to stream the thread.

Class

SubagentManager

Manages subagent execution state.

Class

CustomStreamOrchestrator

Framework-agnostic orchestrator for custom transport streams.

Class

FetchStreamTransport

Transport used to stream the thread.

Class

MessageTupleManager

Class

PendingRunsTracker

Tracks pending server-side runs created via multitaskStrategy: "enqueue".

Class

StreamManager

Class

StreamOrchestrator

Framework-agnostic orchestrator for LangGraph Platform streams.

Class

SubagentManager

Manages subagent execution state.

Class

StreamError

Class

IterableReadableStream

Functions

Function

isStudioUser

Check if the provided user was provided by LangGraph Studio.

Function

getApiKey

Get the API key from the environment.

Function

overrideFetchImplementation

Overrides the fetch implementation used for LangSmith calls.

Function

getApiKey

Get the API key from the environment.

Function

getLogger

Retrieves the global logger instance for LangGraph Platform.

Function

useStream

Function

calculateDepthFromNamespace

Calculates the depth of a subagent based on its namespace.

Function

extractParentIdFromNamespace

Extracts the parent tool call ID from a namespace.

Function

extractToolCallIdFromNamespace

Extracts the tool call ID from a namespace path.

Function

isSubagentNamespace

Checks if a namespace indicates a subagent/subgraph message.

Function

experimental_loadShare

Function

isRemoveUIMessage

Function

isUIMessage

Function

LoadExternalComponent

Function

uiMessageReducer

Function

useStreamContext

Function

typedUi

Helper to send and persist UI messages. Accepts a map of component names to React components

Function

uiMessageReducer

Function

calculateDepthFromNamespace

Calculates the depth of a subagent based on its namespace.

Function

ensureHistoryMessageInstances

Converts plain message objects within each history state's values

Function

ensureMessageInstances

Ensures all messages in an array are BaseMessage class instances.

Function

extractInterrupts

Function

extractParentIdFromNamespace

Extracts the parent tool call ID from a namespace.

Function

extractToolCallIdFromNamespace

Extracts the tool call ID from a namespace path.

Function

filterStream

Function

findLast

Function

getBranchContext

Function

getMessagesMetadataMap

Function

isSubagentNamespace

Checks if a namespace indicates a subagent/subgraph message.

Function

normalizeHitlInterruptPayload

If value looks like a HITL request object from the Python API, rewrite

Function

normalizeInterruptForClient

Rewrites Python/API snake_case on interrupt value to JS camelCase for HITL.

Function

normalizeInterruptsList

Applies normalizeInterruptForClient to each interrupt.

Function

onFinishRequiresThreadState

Returns true when onFinish declares at least one parameter and therefore

Function

toMessageClass

Identity converter that keeps @langchain/core class instances.

Function

toMessageDict

Function

unique

Function

BytesLineDecoder

Function

getToolCallsWithResults

Function

SSEDecoder

Exports

Module

auth

Module

client

Module

index

Module

logging

Module

react

Module

react-ui

Module

react-ui/server

Module

ui

Module

utils

Interfaces

Interface

AuthEventValueMap

Interface

ClientConfig

Interface

Assistant

Interface

AssistantBase

Interface

AssistantGraph

Interface

AssistantsSearchResponse

Interface

AssistantVersion

Interface

BaseStream

Base stream interface shared by all stream types.

Interface

Command

Interface

Cron

Interface

CronCreateForThreadResponse

Interface

CronCreateResponse

Interface

GraphSchema

Interface

Interrupt

An interrupt thrown inside a thread.

Interface

Item

Interface

ListNamespaceResponse

Interface

Run

Interface

RunsInvokePayload

Interface

SearchItem

Interface

SearchItemsResponse

Interface

Thread

Interface

ThreadState

Interface

ThreadTask

Interface

UseAgentStream

Stream interface for ReactAgent instances created with createAgent.

Interface

UseAgentStreamOptions

Options for configuring an agent stream.

Interface

UseDeepAgentStream

Stream interface for DeepAgent instances created with createDeepAgent.

Interface

UseDeepAgentStreamOptions

Options for configuring a deep agent stream.

Interface

ClientConfig

Interface

UseStream

Base interface for stream-like objects.

Interface

AgentTypeConfigLike

Minimal interface matching the structure of AgentTypeConfig from @langchain/langgraph.

Interface

BaseStream

Base stream interface shared by all stream types.

Interface

CompiledSubAgentLike

Minimal interface matching the structure of a CompiledSubAgent from deepagents.

Interface

DeepAgentTypeConfigLike

Minimal interface matching the structure of DeepAgentTypeConfig from deepagents.

Interface

SubAgentLike

Minimal interface matching the structure of a SubAgent from deepagents.

Interface

SubagentStreamInterface

Base interface for a single subagent stream.

Interface

SubagentToolCall

Represents a tool call that initiated a subagent.

Interface

UseAgentStream

Stream interface for ReactAgent instances created with createAgent.

Interface

UseAgentStreamOptions

Options for configuring an agent stream.

Interface

UseDeepAgentStream

Stream interface for DeepAgent instances created with createDeepAgent.

Interface

UseDeepAgentStreamOptions

Options for configuring a deep agent stream.

Interface

UseStreamOptions

Interface

UseStreamThread

Interface

UseStreamTransport

Transport used to stream the thread.

Interface

RemoveUIMessage

Interface

UIMessage

Interface

RemoveUIMessage

Interface

UIMessage

Interface

AgentMiddlewareLike

Minimal interface to structurally match AgentMiddleware from langchain.

Interface

AgentTypeConfigLike

Minimal interface matching the structure of AgentTypeConfig from @langchain/langgraph.

Interface

CompiledSubAgentLike

Minimal interface matching the structure of a CompiledSubAgent from deepagents.

Interface

DeepAgentTypeConfigLike

Minimal interface matching the structure of DeepAgentTypeConfig from deepagents.

Interface

OrchestratorAccessors

Callbacks for resolving dynamic/reactive option values.

Interface

QueueEntry

A single queued submission entry representing a server-side pending run.

Interface

QueueInterface

Reactive interface exposed to framework consumers for observing

Interface

RunCallbackMeta

Interface

Sequence

Interface

StreamBase

Base interface for stream-like objects.

Interface

SubagentApi

Subagent API surface parameterised by the subagent interface type.

Interface

SubAgentLike

Minimal interface matching the structure of a SubAgent from deepagents.

Interface

SubagentStreamInterface

Base interface for a single subagent stream.

Interface

SubagentToolCall

Represents a tool call that initiated a subagent.

Interface

SubmitOptions

Interface

UseStreamOptions

Interface

UseStreamThread

Interface

UseStreamTransport

Transport used to stream the thread.

Interface

UseStreamTransportPayload

Payload for the stream method of the UseStreamTransport interface.

Interface

BaseStream

Base stream interface shared by all stream types.

Interface

UseAgentStream

Stream interface for ReactAgent instances created with createAgent.

Interface

UseAgentStreamOptions

Options for configuring an agent stream.

Interface

UseDeepAgentStream

Stream interface for DeepAgent instances created with createDeepAgent.

Interface

UseDeepAgentStreamOptions

Options for configuring a deep agent stream.

Types

Type

AuthFilters

Type

RequestHook

Type

AIMessage

AI message type that can be parameterized with custom tool call types.

Type

BagTemplate

Template for the bag type.

Type

Checkpoint

Type

Config

Type

CustomStreamEvent

Streaming custom data from inside the nodes.

Type

DebugStreamEvent

Stream event with detailed debug information.

Type

DefaultToolCall

Default tool call type when no specific tool definitions are provided.

Type

DefaultValues

Type

ErrorStreamEvent

Stream event with error information.

Type

EventsStreamEvent

Stream event with events occurring during execution.

Type

FeedbackStreamEvent

Stream event with a feedback key to signed URL map. Set feedbackKeys in

Type

FunctionMessage

Type

HumanMessage

Type

InferBag

Infer the Bag type from an agent, defaulting to the provided Bag.

Type

InferNodeNames

Infer the node names from a compiled graph.

Type

InferNodeReturnTypes

Infer the per-node return types from a compiled graph.

Type

InferStateType

Infer the state type from an agent, graph, or direct state type.

Type

InferSubagentStates

Infer subagent state map from a DeepAgent.

Type

InferToolCalls

Infer tool call types from an agent.

Type

Message

Union of all message types.

Type

MessagesTupleStreamEvent

Stream event with message chunks coming from LLM invocations inside nodes.

Type

Metadata

Type

MetadataStreamEvent

Metadata stream event with information about the run and thread

Type

OnConflictBehavior

Type

RemoveMessage

Type

ResolveStreamInterface

Resolves the appropriate stream interface based on the agent/graph type.

Type

ResolveStreamOptions

Resolves the appropriate options interface based on the agent/graph type.

Type

StreamEvent

Type

StreamMode

import type { SubgraphCheckpointsStreamEvent } from "./types.stream.subgraph.js";

Type

SystemMessage

Type

ThreadStatus

Type

ToolCallFromTool

Infer a tool call type from a single tool.

Type

ToolCallsFromTools

Infer a union of tool call types from an array of tools.

Type

ToolCallState

The lifecycle state of a tool call.

Type

ToolCallWithResult

Represents a tool call paired with its result.

Type

ToolMessage

Type

ToolProgress

Type

ToolsStreamEvent

Type

UpdatesStreamEvent

Stream event with updates to the state after each step.

Type

ValuesStreamEvent

Stream event with values after completion of each step.

Type

RequestHook

Type

UseStreamCustom

Type

BaseSubagentState

Base state type for subagents.

Type

DefaultSubagentStates

Default subagent state map used when no specific subagent types are provided.

Type

DefaultToolCall

Default tool call type when no specific tool definitions are provided.

Type

ExtractAgentConfig

Extract the AgentTypeConfig from an agent-like type.

Type

ExtractDeepAgentConfig

Extract the DeepAgentTypeConfig from a DeepAgent-like type.

Type

ExtractSubAgentMiddleware

Helper type to extract middleware from a SubAgent definition.

Type

GetToolCallsType

Extract the tool call type from a StateType's messages property.

Type

InferAgentToolCalls

Extract tool calls type from an agent's tools.

Type

InferBag

Infer the Bag type from an agent, defaulting to the provided Bag.

Type

InferDeepAgentSubagents

Extract the Subagents array type from a DeepAgent.

Type

InferNodeNames

Infer the node names from a compiled graph.

Type

InferStateType

Infer the state type from an agent, graph, or direct state type.

Type

InferSubagentByName

Helper type to extract a subagent by name from a DeepAgent.

Type

InferSubagentNames

Extract all subagent names as a string union from a DeepAgent.

Type

InferSubagentState

Infer the state type for a specific subagent by extracting and merging

Type

InferSubagentStates

Infer subagent state map from a DeepAgent.

Type

InferToolCalls

Infer tool call types from an agent.

Type

IsAgentLike

Check if a type is agent-like (has ~agentTypes phantom property).

Type

IsDeepAgentLike

Check if a type is a DeepAgent (has ~deepAgentTypes phantom property).

Type

MessageMetadata

Type

ResolveStreamInterface

Resolves the appropriate stream interface based on the agent/graph type.

Type

ResolveStreamOptions

Resolves the appropriate options interface based on the agent/graph type.

Type

SubagentStateMap

Create a map of subagent names to their state types.

Type

SubagentStatus

The execution status of a subagent.

Type

SubagentStream

Represents a single subagent stream.

Type

ToolCallFromTool

Infer a tool call type from a single tool.

Type

ToolCallsFromTools

Infer a union of tool call types from an array of tools.

Type

ToolCallState

The lifecycle state of a tool call.

Type

ToolCallWithResult

Represents a tool call paired with its result.

Type

UseStreamCustomOptions

Type

AcceptBaseMessages

Widens an update type so that its messages field also accepts

Type

BaseSubagentState

Base state type for subagents.

Type

ClassSubagentStreamInterface

Subagent stream interface with messages typed as BaseMessage[]

Type

ClassToolCallWithResult

Remaps an SDK ToolCallWithResult so that the toolMessage and

Type

CustomSubmitOptions

Type

DefaultSubagentStates

Default subagent state map used when no specific subagent types are provided.

Type

EventStreamEvent

Type

ExtractAgentConfig

Extract the AgentTypeConfig from an agent-like type.

Type

ExtractDeepAgentConfig

Extract the DeepAgentTypeConfig from a DeepAgent-like type.

Type

ExtractSubAgentMiddleware

Helper type to extract middleware from a SubAgent definition.

Type

ExtractToolCallsFromState

Extract the tool call type from a StateType's messages property.

Type

GetConfigurableType

Type

GetCustomEventType

Type

GetInterruptType

Type

GetToolCallsType

Extract the tool call type from a StateType's messages property.

Type

GetUpdateType

Type

HistoryWithBaseMessages

Maps a ThreadState<StateType>[] so that the messages field inside

Type

InferAgentState

Type

InferAgentToolCalls

Extract tool calls type from an agent's tools.

Type

InferDeepAgentSubagents

Extract the Subagents array type from a DeepAgent.

Type

InferMiddlewareStatesFromArray

Helper type to extract and merge states from an array of middleware.

Type

InferSubagentByName

Helper type to extract a subagent by name from a DeepAgent.

Type

InferSubagentNames

Extract all subagent names as a string union from a DeepAgent.

Type

InferSubagentState

Infer the state type for a specific subagent by extracting and merging

Type

IsAgentLike

Check if a type is agent-like (has ~agentTypes phantom property).

Type

IsDeepAgentLike

Check if a type is a DeepAgent (has ~deepAgentTypes phantom property).

Type

MessageMetadata

Type

SubagentStateMap

Create a map of subagent names to their state types.

Type

SubagentStatus

The execution status of a subagent.

Type

SubagentStream

Represents a single subagent stream.

Type

UseStreamCustomOptions

Type

WithClassMessages

Maps a stream interface to use @langchain/core BaseMessage

Type

InferBag

Infer the Bag type from an agent, defaulting to the provided Bag.

Type

InferNodeNames

Infer the node names from a compiled graph.

Type

InferNodeReturnTypes

Infer the per-node return types from a compiled graph.

Type

InferStateType

Infer the state type from an agent, graph, or direct state type.

Type

InferSubagentStates

Infer subagent state map from a DeepAgent.

Type

InferToolCalls

Infer tool call types from an agent.

Type

ResolveStreamInterface

Resolves the appropriate stream interface based on the agent/graph type.

Type

ResolveStreamOptions

Resolves the appropriate options interface based on the agent/graph type.

Type

MessagesStreamEvent

deprecated

Message stream event specific to LangGraph Server.