A low-level orchestration framework for building controllable AI agents with customizable workflows, long-term memory, and human-in-the-loop capabilities
npx @tessl/cli install tessl/npm-langchain--langgraph@0.4.0LangGraph is a low-level orchestration framework for building controllable AI agents using a message-passing graph computation model. It provides reliable, persistent workflows with first-class streaming support, human-in-the-loop capabilities, and multi-agent system architecture for production-scale applications.
npm install @langchain/langgraphimport { StateGraph, Annotation, START, END } from "@langchain/langgraph";
import { MemorySaver } from "@langchain/langgraph-checkpoint";For web environments:
import { StateGraph, Annotation, START, END } from "@langchain/langgraph/web";For CommonJS:
const { StateGraph, Annotation, START, END } = require("@langchain/langgraph");import { StateGraph, Annotation, START, END } from "@langchain/langgraph";
import { MemorySaver } from "@langchain/langgraph-checkpoint";
// Define state structure
const GraphAnnotation = Annotation.Root({
messages: Annotation<string[]>({
reducer: (x: string[], y: string[]) => x.concat(y),
default: () => [],
}),
});
// Define nodes
async function nodeA(state: typeof GraphAnnotation.State) {
return { messages: [`Node A processed: ${state.messages.length} messages`] };
}
async function nodeB(state: typeof GraphAnnotation.State) {
return { messages: [`Node B processed: ${state.messages.length} messages`] };
}
// Build and compile graph
const graph = new StateGraph(GraphAnnotation)
.addNode("nodeA", nodeA)
.addNode("nodeB", nodeB)
.addEdge(START, "nodeA")
.addEdge("nodeA", "nodeB")
.addEdge("nodeB", END)
.compile({
checkpointer: new MemorySaver(), // Enable persistence
});
// Execute graph
const result = await graph.invoke(
{ messages: ["Hello"] },
{ configurable: { thread_id: "1" } }
);
console.log(result.messages);LangGraph is built on several key architectural layers:
Core graph building functionality for creating stateful workflows with typed state management and node orchestration.
class StateGraph<SD extends StateDefinition> {
constructor(stateSchema: SD);
addNode(key: string, action: NodeType<SD>): StateGraph<SD>;
addEdge(start: string, end: string): StateGraph<SD>;
addConditionalEdges(
source: string,
path: (state: StateType<SD>) => string | string[],
pathMap?: Record<string, string>
): StateGraph<SD>;
compile(options?: PregelOptions): CompiledStateGraph;
}
class Annotation {
static Root<T extends StateDefinition>(fields: T): AnnotationRoot<T>;
}Channel system for managing state communication and synchronization between graph nodes with various storage patterns.
class BaseChannel {
update(values: any[]): any;
get(): any;
checkpoint(): any;
}
type LastValue<T> = T; // Channel storing most recent value
type Topic<T> = T[]; // Channel storing message history
type DynamicBarrierValue = any; // Dynamic synchronization barrierCore execution engine providing streaming execution, runtime configuration, and graph processing capabilities.
class Pregel<Nodes, Channels, ContextType, InputType, OutputType> {
invoke(
input: InputType,
config?: LangGraphRunnableConfig
): Promise<OutputType>;
stream(
input: InputType,
config?: LangGraphRunnableConfig
): AsyncIterableIterator<OutputType>;
streamMode: "values" | "updates" | "messages" | "checkpoints" | "debug";
}State persistence system enabling checkpoint-based recovery, state history, and time-travel debugging for long-running workflows.
class BaseCheckpointSaver {
put(
config: RunnableConfig,
checkpoint: Checkpoint,
metadata: CheckpointMetadata,
newVersions: ChannelVersions
): Promise<RunnableConfig>;
getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
list(
config: RunnableConfig,
options?: CheckpointListOptions
): AsyncGenerator<CheckpointTuple>;
}
class MemorySaver extends BaseCheckpointSaver {
constructor();
}Ready-to-use agent implementations and tool integration for common AI agent patterns like ReAct, function calling, and tool execution.
function createReactAgent(params: CreateReactAgentParams): CompiledStateGraph;
function createAgentExecutor(config: AgentExecutorConfig): CompiledStateGraph;
class ToolNode {
constructor(tools: ToolType[], options?: ToolNodeOptions);
}Interactive workflow capabilities with interruption points, approval flows, and dynamic control flow for human oversight.
function interrupt<I, R>(value: I): R;
function isInterrupted<Value>(values: unknown): values is Interrupt<Value>;
class Command<Resume, Update, Nodes> {
resume: Resume;
update: Update;
goto: Nodes;
}
class Send<Node, Args> {
node: Node;
args: Args;
}Human-in-the-Loop & Control Flow
Task-based programming interface providing functional composition patterns and declarative workflow definition.
function task<ArgsT, OutputT>(
optionsOrName: TaskOptions | string,
func: TaskFunc<ArgsT, OutputT>
): (...args: ArgsT) => Promise<OutputT>;
function entrypoint<InputT, OutputT>(
optionsOrName: EntrypointOptions | string,
func: EntrypointFunc<InputT, OutputT>
): Pregel<...>;Distributed graph execution, schema integration, and advanced streaming capabilities for complex multi-system workflows.
class RemoteGraph {
constructor(params: RemoteGraphParams);
invoke(input: any, config?: LangGraphRunnableConfig): Promise<any>;
}
function getStateTypeSchema(graph: unknown): JSONSchema | undefined;
function getUpdateTypeSchema(graph: unknown): JSONSchema | undefined;Remote Execution & Advanced Features
class BaseLangGraphError extends Error {
name: string;
message: string;
}
class GraphInterrupt extends BaseLangGraphError {
constructor(value?: any);
}
class GraphRecursionError extends BaseLangGraphError {}
class GraphValueError extends BaseLangGraphError {}
class NodeInterrupt extends GraphInterrupt {}const START: "__start__"; // Graph entry point
const END: "__end__"; // Graph termination
const INTERRUPT: "__interrupt__"; // Interruption marker