The LangGraph Architect – Module 1: The Skeleton

Welcome to the first installment of The LangGraph Architect.

If you are coming from standard Python programming, LangGraph requires a shift in mental models. You are no longer writing a linear script; you are designing a machine with distinct parts.

In this module, we will strip away the AI, the LLMs, and the complex loops. We are going to build the “Skeleton” of a graph—the rigid structure that defines how data moves from point A to point B.

What you will learn:

  1. The State: The “shared brain” of your application.

  2. The Nodes: The functions that do the work.

  3. The Edges: The roads that connect the workers

Here is the deep dive into the fundamental anatomy of a LangGraph. This section bridges the gap between the code you just saw and the mental model you need to build complex agents.


The Anatomy of a Graph

To understand LangGraph, stop thinking about “writing a script” and start thinking about designing a workflow.

The best analogy is a Processing Plant or a Corporate Office.

1. The State (The “File Folder”)

In a normal Python script, variables live inside functions. In LangGraph, variables live in a shared “container” that moves between functions.

  • Analogy: Imagine a physical Manila Folder containing a few sheets of paper (The Project).

  • Function: It is the Single Source of Truth. No node holds private information; everything must be written into the folder if other nodes need to see it.

  • Technical: This is your TypedDict or Pydantic model. It acts as the API Schema for your entire application.

    • If it’s not in the State, it doesn’t exist.

2. The Node (The “Worker”)

A Node is where the actual work happens.

  • Analogy: A Worker at a Desk. The worker sits and waits. When the “File Folder” (State) is dropped on their desk, they open it, do a specific task (e.g., “Write a summary”), add their result to the folder, and close it.

  • Function: Nodes are purely functional. They receive the current state, perform an action (call an LLM, search Google, run math), and return a diff (an update) to the state.

  • Technical: A standard Python function.

3. The Edge (The “Hallway”)

Edges define the routing logic. They tell the graph where to send the folder next.

  • Analogy: The Office Floor Plan. A standard edge is a direct hallway: “When Desk A finishes, the intern always walks the folder to Desk B.”

  • Function: They define the Control Flow.

  • Types:

    • Normal Edge: Deterministic ($A \to B$). Always happens.

    • Conditional Edge: Logic-based ($A \to B$ OR $A \to C$). The “intern” checks a sticky note on the folder (“Is the summary good?”) to decide which desk to go to next.

4. The Graph (The “Manager”)

The Graph is the orchestration engine that enforces the rules.

  • Analogy: The Office Manager. The manager doesn’t write the summary or do the math. The manager ensures the folder goes to the right desks in the right order and stops the process when the job is done.

  • Function: It compiles your Nodes and Edges into a runnable application (Runnable).


How They Work Together: The Execution Loop

When you run graph.invoke(inputs), a specific cycle begins. This is the heartbeat of LangGraph:

  1. Initialization: The Graph creates a fresh “File Folder” (State) using your inputs.

  2. Routing: The Graph looks at the Entry Point to see which Node goes first.

  3. Execution (The Step):

    • The Graph passes the State to Node A.

    • Node A runs its code and returns an update (e.g., {"draft": "Hi there"}).

    • The Graph updates the State with this new data.

  4. Transition:

    • The Graph looks at the Edges connected to Node A.

    • If it’s a conditional edge, it runs the logic function to decide the path.

    • It moves the State to the next Node (Node B).

  5. Termination: This cycle repeats until the Graph hits the special END node.

Summary Table

ConceptThe AnalogyThe Code RoleKey Characteristic
StateThe File FolderTypedDictShared. Accessible by everyone.
NodeThe Workerdef func(state):Isolated. Doesn’t know who comes next.
EdgeThe Hallwayadd_edge()Fixed. The structure doesn’t change.
Conditional EdgeThe Junctionadd_conditional_edges()Dynamic. Changes path based on data.