@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-sdkYou 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:
-
Generate docs.
pnpm typedocCopy -
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.mdCopy -
Copy
js_ts_sdk_ref.mdto MkDocs directory.cp docs/js_ts_sdk_ref.md ../../docs/docs/cloud/reference/sdk/js_ts_sdk_ref.mdCopy
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
Functions
isStudioUser
Check if the provided user was provided by LangGraph Studio.
getApiKey
Get the API key from the environment.
overrideFetchImplementation
Overrides the fetch implementation used for LangSmith calls.
getApiKey
Get the API key from the environment.
getLogger
Retrieves the global logger instance for LangGraph Platform.
calculateDepthFromNamespace
Calculates the depth of a subagent based on its namespace.
extractParentIdFromNamespace
Extracts the parent tool call ID from a namespace.
extractToolCallIdFromNamespace
Extracts the tool call ID from a namespace path.
isSubagentNamespace
Checks if a namespace indicates a subagent/subgraph message.
useStream
A React hook that provides seamless integration with LangGraph streaming capabilities.
experimental_loadShare
isRemoveUIMessage
isUIMessage
LoadExternalComponent
uiMessageReducer
useStreamContext
typedUi
Helper to send and persist UI messages. Accepts a map of component names to React components
uiMessageReducer
Exports
Interfaces
AuthEventValueMap
ClientConfig
Assistant
AssistantBase
AssistantGraph
AssistantsSearchResponse
AssistantVersion
BaseStream
Base stream interface shared by all stream types.
Command
Cron
CronCreateForThreadResponse
CronCreateResponse
GraphSchema
Interrupt
An interrupt thrown inside a thread.
Item
ListNamespaceResponse
Run
RunsInvokePayload
SearchItem
SearchItemsResponse
Thread
ThreadState
ThreadTask
UseAgentStream
Stream interface for ReactAgent instances created with createAgent.
UseAgentStreamOptions
Options for configuring an agent stream.
UseDeepAgentStream
Stream interface for DeepAgent instances created with createDeepAgent.
UseDeepAgentStreamOptions
Options for configuring a deep agent stream.
ClientConfig
AgentTypeConfigLike
Minimal interface matching the structure of AgentTypeConfig from @langchain/langgraph.
CompiledSubAgentLike
Minimal interface matching the structure of a CompiledSubAgent from deepagents.
DeepAgentTypeConfigLike
Minimal interface matching the structure of DeepAgentTypeConfig from deepagents.
SubAgentLike
Minimal interface matching the structure of a SubAgent from deepagents.
SubagentStreamInterface
Base interface for a single subagent stream.
SubagentToolCall
Represents a tool call that initiated a subagent.
UseStream
UseStreamOptions
UseStreamThread
UseStreamTransport
Transport used to stream the thread.
BaseStream
Base stream interface shared by all stream types.
UseAgentStream
Stream interface for ReactAgent instances created with createAgent.
UseAgentStreamOptions
Options for configuring an agent stream.
UseDeepAgentStream
Stream interface for DeepAgent instances created with createDeepAgent.
UseDeepAgentStreamOptions
Options for configuring a deep agent stream.
RemoveUIMessage
UIMessage
RemoveUIMessage
UIMessage
Types
AuthFilters
RequestHook
AIMessage
AI message type that can be parameterized with custom tool call types.
BagTemplate
Template for the bag type.
Checkpoint
Config
CustomStreamEvent
Streaming custom data from inside the nodes.
DebugStreamEvent
Stream event with detailed debug information.
DefaultValues
ErrorStreamEvent
Stream event with error information.
EventsStreamEvent
Stream event with events occurring during execution.
FeedbackStreamEvent
Stream event with a feedback key to signed URL map. Set feedbackKeys in
FunctionMessage
HumanMessage
InferBag
Infer the Bag type from an agent, defaulting to the provided Bag.
InferNodeNames
Infer the node names from a compiled graph.
InferNodeReturnTypes
Infer the per-node return types from a compiled graph.
InferStateType
Infer the state type from an agent, graph, or direct state type.
InferSubagentStates
Infer subagent state map from a DeepAgent.
InferToolCalls
Infer tool call types from an agent.
Message
Union of all message types.
MessagesTupleStreamEvent
Stream event with message chunks coming from LLM invocations inside nodes.
Metadata
MetadataStreamEvent
Metadata stream event with information about the run and thread
OnConflictBehavior
RemoveMessage
ResolveStreamInterface
Resolves the appropriate stream interface based on the agent/graph type.
ResolveStreamOptions
Resolves the appropriate options interface based on the agent/graph type.
StreamMode
import type { SubgraphCheckpointsStreamEvent } from "./types.stream.subgraph.js";
SystemMessage
ThreadStatus
ToolMessage
ToolProgress
UpdatesStreamEvent
Stream event with updates to the state after each step.
ValuesStreamEvent
Stream event with values after completion of each step.
RequestHook
BaseSubagentState
Base state type for subagents.
DefaultSubagentStates
Default subagent state map used when no specific subagent types are provided.
DefaultToolCall
Default tool call type when no specific tool definitions are provided.
ExtractAgentConfig
Extract the AgentTypeConfig from an agent-like type.
ExtractDeepAgentConfig
Extract the DeepAgentTypeConfig from a DeepAgent-like type.
ExtractSubAgentMiddleware
Helper type to extract middleware from a SubAgent definition.
GetToolCallsType
Extract the tool call type from a StateType's messages property.
InferAgentToolCalls
Extract tool calls type from an agent's tools.
InferDeepAgentSubagents
Extract the Subagents array type from a DeepAgent.
InferSubagentByName
Helper type to extract a subagent by name from a DeepAgent.
InferSubagentNames
Extract all subagent names as a string union from a DeepAgent.
InferSubagentState
Infer the state type for a specific subagent by extracting and merging
IsAgentLike
Check if a type is agent-like (has ~agentTypes phantom property).
IsDeepAgentLike
Check if a type is a DeepAgent (has ~deepAgentTypes phantom property).
MessageMetadata
SubagentStateMap
Create a map of subagent names to their state types.
SubagentStatus
The execution status of a subagent.
SubagentStream
Represents a single subagent stream.
ToolCallFromTool
Infer a tool call type from a single tool.
ToolCallsFromTools
Infer a union of tool call types from an array of tools.
ToolCallState
The lifecycle state of a tool call.
ToolCallWithResult
Represents a tool call paired with its result.
UseStreamCustom
UseStreamCustomOptions
InferBag
Infer the Bag type from an agent, defaulting to the provided Bag.
InferNodeNames
Infer the node names from a compiled graph.
InferStateType
Infer the state type from an agent, graph, or direct state type.
InferSubagentStates
Infer subagent state map from a DeepAgent.
InferToolCalls
Infer tool call types from an agent.
ResolveStreamInterface
Resolves the appropriate stream interface based on the agent/graph type.
ResolveStreamOptions
Resolves the appropriate options interface based on the agent/graph type.
MessagesStreamEvent
deprecatedMessage stream event specific to LangGraph Server.