LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
  • Stream
LangGraph SDK
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Server
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
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
WebChannelsPregelPrebuiltRemoteStream
LangGraph SDK
ClientAuthReactLoggingReact UiServer
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
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

Client

Class

FetchStreamTransport

Transport used to stream the thread. Only applicable for custom endpoints using toLangGraphEventStream or toLangGraphEventStreamResponse.

Class

SubagentManager

Manages subagent execution state.

Tracks subagents from the moment they are invoked (AI message with tool calls) through streaming to completion (tool message result).

Functions

Function

isStudioUser

Check if the provided user was provided by LangGraph Studio.

By default, if you add custom authorization on your resources, this will also apply to interactions made from the Studio. If you want, you

Function

getApiKey

Get the API key from the environment. Precedence:

  1. explicit argument (if string)
  2. LANGGRAPH_API_KEY
  3. LANGSMITH_API_KEY
  4. LANGCHAIN_API_KEY
Function

overrideFetchImplementation

Overrides the fetch implementation used for LangSmith calls. You should use this if you need to use an implementation of fetch other than the default global (e.g. for dealing with proxies).

Function

getApiKey

Get the API key from the environment. Precedence:

  1. explicit argument (if string)
  2. LANGGRAPH_API_KEY
  3. LANGSMITH_API_KEY
  4. LANGCHAIN_API_KEY
Function

getLogger

Retrieves the global logger instance for LangGraph Platform.

The logger provides structured logging capabilities with various log levels (error, warn, info, debug, etc.) and extra metadata such as no

Function

calculateDepthFromNamespace

Calculates the depth of a subagent based on its namespace. Counts the number of "tools:" segments in the namespace.

Function

extractParentIdFromNamespace

Extracts the parent tool call ID from a namespace.

For nested subagents, the namespace looks like: ["tools:parent_id", "tools:child_id", ...]

Function

extractToolCallIdFromNamespace

Extracts the tool call ID from a namespace path.

Namespaces follow the pattern: ["tools:call_abc123", "model_request:xyz", ...] This function extracts "call_abc123" from the first "tools:" segment.

Function

isSubagentNamespace

Checks if a namespace indicates a subagent/subgraph message.

Subagent namespaces contain a "tools:" segment indicating they originate from a tool call that spawned a subgraph.

Function

useStream

A React hook that provides seamless integration with LangGraph streaming capabilities.

The useStream hook handles all the complexities of streaming, state management, and branching logic, letting y

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 as type argument to provide type safety. Will also write to the options?.stateKey state.

Function

uiMessageReducer

Exports

Interfaces

Types

Module

auth

Module

client

Module

index

Module

logging

Module

react

Module

react-ui

Module

react-ui/server

Interface

AuthEventValueMap

Interface

ClientConfig

Interface

Assistant

Interface

AssistantBase

Interface

AssistantGraph

Interface

AssistantsSearchResponse

Interface

AssistantVersion

Interface

BaseStream

Base stream interface shared by all stream types.

Contains core properties for state management, messaging, and stream control that are common to CompiledStateGraph, ReactAgent, and DeepAgent streams

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.

Extends UseGraphStream with tool calling capabilities. Tool calls are automatically typed based on the agent's tools configuratio

Interface

UseAgentStreamOptions

Options for configuring an agent stream.

Use this options interface when calling useStream with a ReactAgent created via createAgent.

This interface is subject to change.

Interface

UseDeepAgentStream

Stream interface for DeepAgent instances created with createDeepAgent.

Extends UseAgentStream with subagent streaming capabilities. Subagent streams are automatically typed based on the agent's sub

Interface

UseDeepAgentStreamOptions

Options for configuring a deep agent stream.

Use this options interface when calling useStream with a DeepAgent created via createDeepAgent. Includes all agent options plus subagent-specific conf

Interface

ClientConfig

Interface

AgentTypeConfigLike

Minimal interface matching the structure of AgentTypeConfig from @langchain/langgraph. This allows type inference from ReactAgent without requiring the langchain dependency.

Interface

CompiledSubAgentLike

Minimal interface matching the structure of a CompiledSubAgent from deepagents. Used for structural type matching without importing deepagents.

Interface

DeepAgentTypeConfigLike

Minimal interface matching the structure of DeepAgentTypeConfig from deepagents. Extends AgentTypeConfigLike to include subagent type information.

Interface

SubAgentLike

Minimal interface matching the structure of a SubAgent from deepagents. Used for structural type matching without importing deepagents.

Interface

SubagentStreamInterface

Base interface for a single subagent stream. Tracks the lifecycle of a subagent from invocation to completion.

Extends StreamBase to share common properties with UseStream, allowing subagents to be t

Interface

SubagentToolCall

Represents a tool call that initiated a subagent.

Interface

UseStream

Interface

UseStreamOptions

Interface

UseStreamThread

Interface

UseStreamTransport

Transport used to stream the thread. Only applicable for custom endpoints using toLangGraphEventStream or toLangGraphEventStreamResponse.

Interface

BaseStream

Base stream interface shared by all stream types.

Contains core properties for state management, messaging, and stream control that are common to CompiledStateGraph, ReactAgent, and DeepAgent streams

Interface

UseAgentStream

Stream interface for ReactAgent instances created with createAgent.

Extends UseGraphStream with tool calling capabilities. Tool calls are automatically typed based on the agent's tools configuratio

Interface

UseAgentStreamOptions

Options for configuring an agent stream.

Use this options interface when calling useStream with a ReactAgent created via createAgent.

This interface is subject to change.

Interface

UseDeepAgentStream

Stream interface for DeepAgent instances created with createDeepAgent.

Extends UseAgentStream with subagent streaming capabilities. Subagent streams are automatically typed based on the agent's sub

Interface

UseDeepAgentStreamOptions

Options for configuring a deep agent stream.

Use this options interface when calling useStream with a DeepAgent created via createDeepAgent. Includes all agent options plus subagent-specific conf

Interface

RemoveUIMessage

Interface

UIMessage

Interface

RemoveUIMessage

Interface

UIMessage

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

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 the RunsStreamPayload to receive this event.

Type

FunctionMessage

Type

HumanMessage

Type

InferBag

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

Currently returns the provided Bag for all types. Can be extended in the future to extract Bag from agent types.

Type

InferNodeNames

Infer the node names from a compiled graph.

Extracts the ~NodeType phantom property from CompiledGraph instances, providing a union of all node names defined in the graph.

Type

InferNodeReturnTypes

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

Extracts the ~NodeReturnType phantom property from CompiledGraph instances, which is a mapped type of { [nodeName]: ReturnType } for each no

Type

InferStateType

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

Detection order:

  1. Agent-like (~agentTypes) → InferAgentState
  2. CompiledGraph (~RunOutput) → Extract RunOutput
  3. Pregel (`~Outp
Type

InferSubagentStates

Infer subagent state map from a DeepAgent.

For DeepAgent, creates a map of subagent names to their state types. For non-DeepAgent, returns DefaultSubagentStates.

Type

InferToolCalls

Infer tool call types from an agent.

For agents, extracts typed tool calls from the agent's tools. For non-agents, returns DefaultToolCall.

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.

This type automatically selects the correct stream interface based on the type of agent or graph passed to useStream:

  1. **
Type

ResolveStreamOptions

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

This type automatically selects the correct options interface based on the type of agent or graph:

  1. DeepAgent → UseDee
Type

StreamMode

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

  • Stream modes
    • "values": Stream only the state values.
    • "messages": Stream complete messages.
    • "messages
Type

SystemMessage

Type

ThreadStatus

Type

ToolMessage

Type

UpdatesStreamEvent

Stream event with updates to the state after each step. The streamed outputs include the name of the node that produced the update as well as the update.

Type

ValuesStreamEvent

Stream event with values after completion of each step.

Type

RequestHook

Type

BaseSubagentState

Base state type for subagents. All subagents have at least a messages array, similar to the main agent.

Type

DefaultSubagentStates

Default subagent state map used when no specific subagent types are provided. Maps any string key to Record<string, unknown>.

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. Handles both mutable and readonly middleware arrays.

Type

GetToolCallsType

Extract the tool call type from a StateType's messages property. This is the canonical way to get typed tool calls in useStream.

Tool call types are now extracted from the messages property of StateT

Type

InferAgentToolCalls

Extract tool calls type from an agent's tools. Converts the tools array to a discriminated union of tool calls.

This handles both tuple types (e.g., readonly [Tool1, Tool2]) and array-of-union type

Type

InferDeepAgentSubagents

Extract the Subagents array type from a DeepAgent.

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 its middleware state schemas, plus the base agent state (messages).

Type

IsAgentLike

Check if a type is agent-like (has ~agentTypes phantom property). This property is present on ReactAgent instances created with createAgent.

Type

IsDeepAgentLike

Check if a type is a DeepAgent (has ~deepAgentTypes phantom property). This property is present on DeepAgent instances created with createDeepAgent.

Type

MessageMetadata

Type

SubagentStateMap

Create a map of subagent names to their state types. This is useful for type-safe getSubagentsByType calls.

Type

SubagentStatus

The execution status of a subagent.

  • "pending" - The subagent has been invoked but hasn't started processing yet. This is the initial state when a tool call is detected but before any streamin
Type

SubagentStream

Represents a single subagent stream.

Supports two usage patterns:

  1. Agent type inference (recommended): Pass a DeepAgent type directly and let TypeScript infer the correct state and tool cal
Type

ToolCallFromTool

Infer a tool call type from a single tool. Works with tools created via tool() from @langchain/core/tools.

For DynamicStructuredTool, this extracts the input type from the _call method, which is

Type

ToolCallsFromTools

Infer a union of tool call types from an array of tools. Works with tools created via tool() from @langchain/core/tools.

Type

ToolCallState

The lifecycle state of a tool call.

  • pending: Tool call received, awaiting result
  • completed: Tool execution finished successfully
  • error: Tool execution failed (result.status === "error")
Type

ToolCallWithResult

Represents a tool call paired with its result. Useful for rendering tool invocations and their outputs together.

Type

UseStreamCustom

Type

UseStreamCustomOptions

Type

InferBag

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

Currently returns the provided Bag for all types. Can be extended in the future to extract Bag from agent types.

Type

InferNodeNames

Infer the node names from a compiled graph.

Extracts the ~NodeType phantom property from CompiledGraph instances, providing a union of all node names defined in the graph.

Type

InferStateType

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

Detection order:

  1. Agent-like (~agentTypes) → InferAgentState
  2. CompiledGraph (~RunOutput) → Extract RunOutput
  3. Pregel (`~Outp
Type

InferSubagentStates

Infer subagent state map from a DeepAgent.

For DeepAgent, creates a map of subagent names to their state types. For non-DeepAgent, returns DefaultSubagentStates.

Type

InferToolCalls

Infer tool call types from an agent.

For agents, extracts typed tool calls from the agent's tools. For non-agents, returns DefaultToolCall.

Type

ResolveStreamInterface

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

This type automatically selects the correct stream interface based on the type of agent or graph passed to useStream:

  1. **
Type

ResolveStreamOptions

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

This type automatically selects the correct options interface based on the type of agent or graph:

  1. DeepAgent → UseDee
Type

MessagesStreamEvent

deprecated

Message stream event specific to LangGraph Server.