Low-level orchestration framework for building stateful, multi-actor applications with LLMs
Complete API reference for graph construction classes and methods.
High-level graph with automatic state management.
class StateGraph<
StateDefinition,
S = StateType<StateDefinition>,
U = UpdateType<StateDefinition>,
N extends string = typeof START
> {
constructor(
state: AnnotationRoot<StateDefinition> | InteropZodObject,
options?: {
context?: ContextDefinition | AnnotationRoot<ContextDefinition>;
input?: InputDefinition | AnnotationRoot<InputDefinition>;
output?: OutputDefinition | AnnotationRoot<OutputDefinition>;
}
);
addNode<K extends string>(
key: K,
action: RunnableLike<S, U>,
options?: StateGraphAddNodeOptions
): this;
addEdge(
startKey: typeof START | N | N[],
endKey: N | typeof END
): this;
addConditionalEdges(
source: N,
path: RunnableLike<S, string | string[] | Send | Send[]>,
pathMap?: Record<string, N | typeof END> | (N | typeof END)[]
): this;
addSequence<K extends string>(
nodes: Record<K, RunnableLike<S, U>>
): this;
setEntryPoint(name: N): this;
setFinishPoint(name: N): this;
compile(options?: {
checkpointer?: BaseCheckpointSaver | boolean;
store?: BaseStore;
cache?: BaseCache;
interruptBefore?: N[] | All;
interruptAfter?: N[] | All;
name?: string;
description?: string;
}): CompiledStateGraph;
}interface StateGraphAddNodeOptions<Nodes extends string = string> {
retryPolicy?: RetryPolicy;
cachePolicy?: CachePolicy | boolean;
input?: AnnotationRoot<any> | InteropZodObject;
metadata?: Record<string, unknown>;
subgraphs?: Pregel<any, any>[];
ends?: Nodes[];
defer?: boolean;
}Compiled executable graph from StateGraph.
class CompiledStateGraph<S, U, N extends string = typeof START> {
invoke(
input: UpdateType<InputDefinition>,
options?: PregelOptions
): Promise<StateType<OutputDefinition>>;
stream(
input: UpdateType<InputDefinition>,
options?: PregelOptions
): IterableReadableStream;
streamEvents(
input: UpdateType<InputDefinition>,
options: PregelOptions
): IterableReadableStream;
getState(
config: LangGraphRunnableConfig,
options?: GetStateOptions
): Promise<StateSnapshot>;
getStateHistory(
config: LangGraphRunnableConfig,
options?: CheckpointListOptions
): AsyncIterableIterator<StateSnapshot>;
updateState(
config: LangGraphRunnableConfig,
values: UpdateType<InputDefinition> | Command,
asNode?: N
): Promise<RunnableConfig>;
}Factory for creating typed state annotations.
interface AnnotationFunction {
<ValueType>(): LastValue<ValueType>;
<ValueType, UpdateType = ValueType>(
annotation: SingleReducer<ValueType, UpdateType>
): BinaryOperatorAggregate<ValueType, UpdateType>;
Root: <S extends StateDefinition>(
spec: S
) => AnnotationRoot<S>;
}
const Annotation: AnnotationFunction;Reducer function configuration.
type SingleReducer<ValueType, UpdateType = ValueType> =
| {
reducer: BinaryOperator<ValueType, UpdateType>;
default?: () => ValueType;
}
| {
value: BinaryOperator<ValueType, UpdateType>;
default?: () => ValueType;
}
| null;
type BinaryOperator<ValueType, UpdateType> = (
a: ValueType,
b: UpdateType
) => ValueType;Prebuilt annotation for message workflows.
const MessagesAnnotation: AnnotationRoot<{
messages: Annotation<BaseMessage[], Messages>;
}>;
type Messages =
| Array<BaseMessage | BaseMessageLike>
| BaseMessage
| BaseMessageLike;See: State Management API for more details on state and channels. See: Graph Construction Guide for in-depth examples.