LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
  • Stream
LangGraph SDK
  • Ui
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Utils
  • Server
  • Stream
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
WebChannelsPregelPrebuiltRemoteStream
LangGraph SDK
UiClientAuthReactLoggingReact UiUtilsServerStream
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/langgraphindexStateGraphconstructor
Constructor●Since v0.3

constructor

Copy
constructor<
  SD extends unknown,
  S = ExtractStateType<SD>,
  U = ExtractUpdateType
View source on GitHub
<
SD
,
S
>
,
N
extends
string
=
"__start__"
,
I
extends
StateDefinitionInit
=
ExtractStateDefinition
<
SD
>
,
O
extends
StateDefinitionInit
=
ExtractStateDefinition
<
SD
>
,
C
extends
StateDefinitionInit
=
StateDefinition
,
NodeReturnType
=
unknown
,
InterruptType
=
unknown
,
WriterType
=
unknown
>
(
state
:
SD
extends
StateDefinitionInit
SD
<
SD
>
:
never
,
options
:
C
|
AnnotationRoot
<
ToStateDefinition
<
C
>
>
|
StateGraphOptions
<
I
,
O
,
C
,
N
,
InterruptType
,
WriterType
>
)
:
StateGraph
<
SD
,
S
,
U
,
N
,
I
,
O
,
C
,
NodeReturnType
,
InterruptType
,
WriterType
>

Parameters

NameTypeDescription
state*SD extends StateDefinitionInit ? SD<SD> : never
optionsC | AnnotationRoot<ToStateDefinition<C>> | StateGraphOptions<I, O, C, N, InterruptType, WriterType>

Example 1

Example 2

Example 3

Example 4

Create a new StateGraph for building stateful, multi-step workflows.

Accepts state definitions via Annotation.Root, StateSchema, or Zod schemas.

Copy
const StateAnnotation = Annotation.Root({
  messages: Annotation<string[]>({ reducer: (a, b) => [...a, ...b] }),
});
const graph = new StateGraph(StateAnnotation);
Copy
const graph = new StateGraph(StateAnnotation, {
  input: InputSchema,
  output: OutputSchema,
});
Copy
const graph = new StateGraph({
  state: FullStateSchema,
  input: InputSchema,
  output: OutputSchema,
});
Copy
const graph = new StateGraph({
  input: InputAnnotation,
  output: OutputAnnotation,
});