{
  "schema_version": 1,
  "diagram_type": "architecture",
  "meta": {
    "title": "LangGraph Pregel Runtime, StateGraph Engine & Cyclic Checkpointing",
    "quality_profile": "showcase",
    "repository": {
      "url": "https://github.com/langchain-ai/langgraph",
      "revision": "38031739e551638e373fb553453256c23feeb41f"
    },
    "views": [
      {
        "id": "superstep-loop",
        "label": "Pregel Superstep Execution Loop",
        "focus": ["app-driver", "stategraph", "pregel-loop", "tool-node", "llm-node"],
        "note": "Follow cyclic superstep iteration and barrier synchronization across nodes."
      },
      {
        "id": "channel-sync",
        "label": "Channel Reducer Synchronization",
        "focus": ["pregel-loop", "channel-engine", "memory-saver"],
        "note": "Trace state delta accumulation and reducer consolidation per superstep."
      },
      {
        "id": "persistence-hitl",
        "label": "Durable Checkpointing & HITL Gate",
        "focus": ["pregel-loop", "hitl-gate", "memory-saver", "postgres-saver"],
        "note": "Inspect state snapshots enabling time-travel and human approval gates."
      }
    ]
  },
  "components": [
    {
      "id": "app-driver",
      "type": "external",
      "label": "Application Driver",
      "sublabel": "invoke / stream / astream",
      "pos": [50, 270],
      "size": [140, 60],
      "tag": "Entry"
    },
    {
      "id": "stategraph",
      "type": "backend",
      "label": "StateGraph Compiler",
      "sublabel": "Schema & Reducers",
      "pos": [260, 270],
      "size": [140, 60],
      "tag": "libs/langgraph",
      "sources": [
        {
          "path": "libs/langgraph/langgraph/graph/state.py",
          "line": 40,
          "end_line": 95,
          "label": "StateGraph Compilation"
        }
      ]
    },
    {
      "id": "pregel-loop",
      "type": "backend",
      "label": "Pregel Superstep Loop",
      "sublabel": "Barrier Synchronizer",
      "pos": [470, 270],
      "size": [150, 60],
      "tag": "pregel/loop.py",
      "sources": [
        {
          "path": "libs/langgraph/langgraph/pregel/_loop.py",
          "line": 50,
          "end_line": 120,
          "label": "Pregel Loop"
        }
      ]
    },
    {
      "id": "channel-engine",
      "type": "database",
      "label": "Channel Reducers",
      "sublabel": "DeltaChannel / BinaryOp",
      "pos": [470, 110],
      "size": [150, 60],
      "tag": "State Channels"
    },
    {
      "id": "tool-node",
      "type": "backend",
      "label": "ToolNode Executor",
      "sublabel": "Asyncio Parallelism",
      "pos": [690, 270],
      "size": [150, 60],
      "tag": "Tool Execution",
      "sources": [
        {
          "path": "libs/prebuilt/langgraph/prebuilt/tool_node.py",
          "line": 30,
          "end_line": 85,
          "label": "ToolNode"
        }
      ]
    },
    {
      "id": "hitl-gate",
      "type": "security",
      "label": "HITL Interrupt Gate",
      "sublabel": "interrupt_before",
      "pos": [470, 430],
      "size": [150, 60],
      "tag": "Approval Boundary"
    },
    {
      "id": "memory-saver",
      "type": "database",
      "label": "MemorySaver",
      "sublabel": "In-Memory Checkpoint",
      "pos": [690, 110],
      "size": [150, 60],
      "tag": "libs/checkpoint",
      "sources": [
        {
          "path": "libs/checkpoint/langgraph/checkpoint/base/__init__.py",
          "line": 20,
          "end_line": 60,
          "label": "BaseCheckpointer"
        }
      ]
    },
    {
      "id": "postgres-saver",
      "type": "database",
      "label": "PostgresSaver",
      "sublabel": "Durable Thread Storage",
      "pos": [910, 110],
      "size": [140, 60],
      "tag": "ACID Store"
    },
    {
      "id": "llm-node",
      "type": "backend",
      "label": "Model Node",
      "sublabel": "ChatModel Dispatch",
      "pos": [690, 430],
      "size": [150, 60],
      "tag": "LLM Step"
    }
  ],
  "boundaries": [
    {
      "kind": "region",
      "label": "Pregel Orchestration Control Plane",
      "wraps": ["stategraph", "pregel-loop", "channel-engine", "hitl-gate"]
    },
    {
      "kind": "security-group",
      "label": "State Persistence Plane",
      "wraps": ["memory-saver", "postgres-saver"]
    }
  ],
  "connections": [
    {
      "id": "driver-to-stategraph",
      "from": "app-driver",
      "to": "stategraph",
      "label": "compile",
      "variant": "emphasis"
    },
    {
      "id": "stategraph-to-pregel",
      "from": "stategraph",
      "to": "pregel-loop",
      "label": "run step"
    },
    {
      "id": "pregel-to-channels",
      "from": "pregel-loop",
      "to": "channel-engine",
      "label": "reducers",
      "fromSide": "top",
      "toSide": "bottom"
    },
    {
      "id": "channels-to-memory",
      "from": "channel-engine",
      "to": "memory-saver",
      "label": "snapshot"
    },
    {
      "id": "memory-to-postgres",
      "from": "memory-saver",
      "to": "postgres-saver",
      "label": "persist"
    },
    {
      "id": "pregel-to-toolnode",
      "from": "pregel-loop",
      "to": "tool-node",
      "label": "tool call",
      "variant": "emphasis"
    },
    {
      "id": "pregel-to-hitl",
      "from": "pregel-loop",
      "to": "hitl-gate",
      "label": "freeze",
      "fromSide": "bottom",
      "toSide": "top",
      "labelDy": 50
    },
    {
      "id": "hitl-to-llm",
      "from": "hitl-gate",
      "to": "llm-node",
      "label": "resume"
    }
  ],
  "cards": [
    {
      "dot": "cyan",
      "title": "Pregel Superstep Barrier",
      "items": [
        "Iterates state machine through synchronized parallel node turns",
        "Enforces deterministic channel reducer aggregation at superstep boundaries"
      ]
    },
    {
      "dot": "emerald",
      "title": "Incremental Delta Persistence",
      "items": [
        "Records differential channel writes to eliminate state serialization bottlenecks",
        "Flushes consolidated checkpoints to Postgres for fault-tolerant recovery"
      ]
    },
    {
      "dot": "violet",
      "title": "Human-in-the-Loop Interruption",
      "items": [
        "Freezes thread execution before sensitive tool nodes execute",
        "Supports dynamic state inspection and branch editing before resume"
      ]
    }
  ]
}
