This repository contains the JS/TS SDK for interacting with the LangGraph REST API.
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);
}
To generate documentation, run the following commands:
Generate docs.
pnpm typedoc
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
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
The reference documentation is available here.
More usage examples can be found here.
The change log for new versions can be found here.
Transport used to stream the thread.
Manages subagent execution state.
Framework-agnostic orchestrator for custom transport streams.
Transport used to stream the thread.
Tracks pending server-side runs created via multitaskStrategy: "enqueue".
Framework-agnostic orchestrator for LangGraph Platform streams.
Manages subagent execution state.
Check if the provided user was provided by LangGraph Studio.
Get the API key from the environment.
Overrides the fetch implementation used for LangSmith calls.
Get the API key from the environment.
Retrieves the global logger instance for LangGraph Platform.
Calculates the depth of a subagent based on its namespace.
Extracts the parent tool call ID from a namespace.
Extracts the tool call ID from a namespace path.
Checks if a namespace indicates a subagent/subgraph message.
Helper to send and persist UI messages. Accepts a map of component names to React components
Calculates the depth of a subagent based on its namespace.
Converts plain message objects within each history state's values
Ensures all messages in an array are BaseMessage class instances.
Extracts the parent tool call ID from a namespace.
Extracts the tool call ID from a namespace path.
Checks if a namespace indicates a subagent/subgraph message.
If value looks like a HITL request object from the Python API, rewrite
Rewrites Python/API snake_case on interrupt value to JS camelCase for HITL.
Applies normalizeInterruptForClient to each interrupt.
Returns true when onFinish declares at least one parameter and therefore
Identity converter that keeps @langchain/core class instances.
Base stream interface shared by all stream types.
An interrupt thrown inside a thread.
Stream interface for ReactAgent instances created with createAgent.
Options for configuring an agent stream.
Stream interface for DeepAgent instances created with createDeepAgent.
Options for configuring a deep agent stream.
Base interface for stream-like objects.
Minimal interface matching the structure of AgentTypeConfig from @langchain/langgraph.
Base stream interface shared by all stream types.
Minimal interface matching the structure of a CompiledSubAgent from deepagents.
Minimal interface matching the structure of DeepAgentTypeConfig from deepagents.
Minimal interface matching the structure of a SubAgent from deepagents.
Base interface for a single subagent stream.
Represents a tool call that initiated a subagent.
Stream interface for ReactAgent instances created with createAgent.
Options for configuring an agent stream.
Stream interface for DeepAgent instances created with createDeepAgent.
Options for configuring a deep agent stream.
Transport used to stream the thread.
Minimal interface to structurally match AgentMiddleware from langchain.
Minimal interface matching the structure of AgentTypeConfig from @langchain/langgraph.
Minimal interface matching the structure of a CompiledSubAgent from deepagents.
Minimal interface matching the structure of DeepAgentTypeConfig from deepagents.
Callbacks for resolving dynamic/reactive option values.
A single queued submission entry representing a server-side pending run.
Reactive interface exposed to framework consumers for observing
Base interface for stream-like objects.
Subagent API surface parameterised by the subagent interface type.
Minimal interface matching the structure of a SubAgent from deepagents.
Base interface for a single subagent stream.
Represents a tool call that initiated a subagent.
Transport used to stream the thread.
Payload for the stream method of the UseStreamTransport interface.
Base stream interface shared by all stream types.
Stream interface for ReactAgent instances created with createAgent.
Options for configuring an agent stream.
Stream interface for DeepAgent instances created with createDeepAgent.
Options for configuring a deep agent stream.
AI message type that can be parameterized with custom tool call types.
Template for the bag type.
Streaming custom data from inside the nodes.
Stream event with detailed debug information.
Default tool call type when no specific tool definitions are provided.
Stream event with error information.
Stream event with events occurring during execution.
Stream event with a feedback key to signed URL map. Set feedbackKeys in
Infer the Bag type from an agent, defaulting to the provided Bag.
Infer the node names from a compiled graph.
Infer the per-node return types from a compiled graph.
Infer the state type from an agent, graph, or direct state type.
Infer subagent state map from a DeepAgent.
Infer tool call types from an agent.
Union of all message types.
Stream event with message chunks coming from LLM invocations inside nodes.
Metadata stream event with information about the run and thread
Resolves the appropriate stream interface based on the agent/graph type.
Resolves the appropriate options interface based on the agent/graph type.
import type { SubgraphCheckpointsStreamEvent } from "./types.stream.subgraph.js";
Infer a tool call type from a single tool.
Infer a union of tool call types from an array of tools.
The lifecycle state of a tool call.
Represents a tool call paired with its result.
Stream event with updates to the state after each step.
Stream event with values after completion of each step.
Base state type for subagents.
Default subagent state map used when no specific subagent types are provided.
Default tool call type when no specific tool definitions are provided.
Extract the AgentTypeConfig from an agent-like type.
Extract the DeepAgentTypeConfig from a DeepAgent-like type.
Helper type to extract middleware from a SubAgent definition.
Extract the tool call type from a StateType's messages property.
Extract tool calls type from an agent's tools.
Infer the Bag type from an agent, defaulting to the provided Bag.
Extract the Subagents array type from a DeepAgent.
Infer the node names from a compiled graph.
Infer the state type from an agent, graph, or direct state type.
Helper type to extract a subagent by name from a DeepAgent.
Extract all subagent names as a string union from a DeepAgent.
Infer the state type for a specific subagent by extracting and merging
Infer subagent state map from a DeepAgent.
Infer tool call types from an agent.
Check if a type is agent-like (has ~agentTypes phantom property).
Check if a type is a DeepAgent (has ~deepAgentTypes phantom property).
Resolves the appropriate stream interface based on the agent/graph type.
Resolves the appropriate options interface based on the agent/graph type.
Create a map of subagent names to their state types.
The execution status of a subagent.
Represents a single subagent stream.
Infer a tool call type from a single tool.
Infer a union of tool call types from an array of tools.
The lifecycle state of a tool call.
Represents a tool call paired with its result.
Widens an update type so that its messages field also accepts
Base state type for subagents.
Subagent stream interface with messages typed as BaseMessage[]
Remaps an SDK ToolCallWithResult so that the toolMessage and
Default subagent state map used when no specific subagent types are provided.
Extract the AgentTypeConfig from an agent-like type.
Extract the DeepAgentTypeConfig from a DeepAgent-like type.
Helper type to extract middleware from a SubAgent definition.
Extract the tool call type from a StateType's messages property.
Extract the tool call type from a StateType's messages property.
Maps a ThreadState<StateType>[] so that the messages field inside
Extract tool calls type from an agent's tools.
Extract the Subagents array type from a DeepAgent.
Helper type to extract and merge states from an array of middleware.
Helper type to extract a subagent by name from a DeepAgent.
Extract all subagent names as a string union from a DeepAgent.
Infer the state type for a specific subagent by extracting and merging
Check if a type is agent-like (has ~agentTypes phantom property).
Check if a type is a DeepAgent (has ~deepAgentTypes phantom property).
Create a map of subagent names to their state types.
The execution status of a subagent.
Represents a single subagent stream.
Maps a stream interface to use @langchain/core BaseMessage
Infer the Bag type from an agent, defaulting to the provided Bag.
Infer the node names from a compiled graph.
Infer the per-node return types from a compiled graph.
Infer the state type from an agent, graph, or direct state type.
Infer subagent state map from a DeepAgent.
Infer tool call types from an agent.
Resolves the appropriate stream interface based on the agent/graph type.
Resolves the appropriate options interface based on the agent/graph type.
Message stream event specific to LangGraph Server.