constructor<
SD extends unknown,
S = ExtractStateType<SD>,
U = ExtractUpdateType| Name | Type | Description |
|---|---|---|
state* | SD extends StateDefinitionInit ? SD<SD> : never | |
options | C | AnnotationRoot<ToStateDefinition<C>> | StateGraphOptions<I, O, C, N, InterruptType, WriterType> |
Create a new StateGraph for building stateful, multi-step workflows.
Accepts state definitions via Annotation.Root, StateSchema, or Zod schemas.
const StateAnnotation = Annotation.Root({
messages: Annotation<string[]>({ reducer: (a, b) => [...a, ...b] }),
});
const graph = new StateGraph(StateAnnotation);const graph = new StateGraph(StateAnnotation, {
input: InputSchema,
output: OutputSchema,
});const graph = new StateGraph({
state: FullStateSchema,
input: InputSchema,
output: OutputSchema,
});const graph = new StateGraph({
input: InputAnnotation,
output: OutputAnnotation,
});