$ show langchain-ai/langgraph
LangGraph is a production-grade Python framework for building stateful, resumable, multi-step LLM agent workflows, distributed as a monorepo of Python packages (core `langgraph`, `langgraph-sdk`, `langgraph-cli`, checkpoint backends, prebuilt agents) plus JS/TS SDK examples. The core is a Pregel-inspired execution engine: `StateGraph` compiles user-defined nodes and conditional edges into a `Pregel` runnable, where typed state channels (`LastValue`, `Topic`, `DeltaChannel`) apply reducer-based updates across supersteps. The engine supports durable checkpointing (in-memory, SQLite, Postgres), interrupts for human-in-the-loop, retry/timeout policies, subgraph composition, and v3 streaming. The CLI can scaffold projects and deploy graphs to LangGraph Cloud or self-hosted runtimes via Docker; the SDK provides sync/async clients that drive remote graphs over HTTP/SSE/WebSocket with typed stream projections (messages, tool calls, lifecycle). This is purely an application/framework repo; the `examples/` notebooks are usage demonstrations, not research pipelines. Primary data flow: user code builds a graph and compiles it; invocation reads channel state from a `BaseCheckpointSaver`, runs eligible nodes (with optional caching/retry), applies channel updates via reducers, writes the new checkpoint per superstep, and emits streamed events through a transformer pipeline (`StreamMux`). The SDK's v3 streaming protocol adds reconnection, subscription fan-out, and scoped subgraph handles over an SSE/WebSocket transport. External dependencies center on `langchain-core` (messages, tools, runnables), Pydantic, `httpx`, `psycopg`, `msgpack`, `orjson`, with optional `redis` and `pycryptodome` for cache/encryption. The codebase exhibits exceptional engineering: extensive unit/integration/conformance tests, a formal conformance suite that pins checkpoint-backend behavior across implementations, security-conscious serialization (strict msgpack/json module allowlists, a patched path-traversal vulnerability in the SDK), and benchmarks. Notable weaknesses are real but contained: heavy sync/async duplication in SDK clients and transports, a fast-moving deprecation path (many renamed APIs, `MessageGraph` slated for removal), and beta features (`DeltaChannel`, `ServerRuntime`) marked unstable. The `@task`/`@entrypoint` functional API, `create_react_agent` prebuilt, and conformance test framework are the most stable and reusable surfaces.
The LLM identified 5 files worth highlighting for reuse:
Defines a formal capability model (PUT, GET_TUPLE, LIST, DELTA_CHANNEL_HISTORY, copy_thread, prune) for checkpoint storage backends, paired with a decorator-driven spec suite and pass/fail report generation. This lets any new checkpointer implementation be validated for behavioral conformance without rewriting tests. It is a genuinely novel pattern for testing pluggable storage ecosystems and is extractable to any project with swappable backends.
An append-only event log supporting multiple independent cursors with efficient replay and bounded memory, plus a deduplication layer for replayed events. It solves the classic N-consumers/single-producer problem for protocol event buses and is well-isolated enough to lift into any async streaming or message-bus project with minimal modification.
Implements a configurable retry engine with exponential backoff, jitter, max-attempt caps, exception matching, and timeout scoping via timed attempt scopes. Also exposes an attempt observer (_AttemptContext/_AttemptEvent) that external runtimes can subscribe to for task-execution telemetry. The retry/timeout logic is decoupled from Pregel internals and could be extracted into any general task-execution system.
A drainable single-consumer async queue with tee/atee fan-out for producing derived streams, push stamps for deterministic arrival ordering, and clean cancellation semantics. It solves a recurring streaming problem (one producer, multiple transient consumers) and is self-contained enough to reuse in any async streaming codebase.
A serializer that round-trips a wide range of Python types (pydantic v1/v2, dataclasses, numpy arrays, datetime, UUID, Decimal, enums, ZoneInfo) while enforcing an explicit module allowlist for deserialization to mitigate untrusted-data attacks, with normalized allowlist handling and warning-cap logic. The allowlist pattern is directly portable to any system that deserializes complex Python objects from untrusted or mixed-trust sources.