A structured, notebook-driven deep dive into LangGraph — from basic graph concepts to stateful agents, parallel workflows, human-in-the-loop, subgraphs, and fault-tolerant systems.
This repository is my personal learning lab for LangGraph — a low-level framework for building stateful, graph-based AI agents. Each notebook isolates one core concept and pairs it with a real, relatable use case (cricket stats, UPSC essays, X posts, review responses, and more).
The progression covers everything from StateGraph basics through to production patterns like Human-in-the-Loop, subgraphs, persistence, and fault tolerance.
Installation → Simple Graphs → LLM Nodes → Chaining → Parallel → Conditional
→ Iterative Loops → Chatbot → Persistence → HITL → Subgraphs → Fault Tolerance
langgraph/
│
├── 📓 Notebooks (Learning Path)
│ ├── 0_test_installation.ipynb # Sanity check — verify setup
│ ├── 1_bmi_workflow.ipynb # Intro to StateGraph (no LLM)
│ ├── 2_simple_llm_workflow.ipynb # First LLM node in a graph
│ ├── 3_prompt_chaining_workflow.ipynb # Sequential prompt chaining as nodes
│ ├── 4_batsman_parallel_workflow.ipynb # Parallel nodes (fan-out / fan-in)
│ ├── 5_upsc_essay_workflow.ipynb # Multi-step essay generation
│ ├── 6_quad_eq_conditional_workflow.ipynb # Conditional edges (router pattern)
│ ├── 7_review_response_conditional_workflow.ipynb # Sentiment-based routing
│ ├── 8_x_post_generator_iterative_workflow.ipynb # Iterative loop with refinement
│ ├── 9_basic_chatbot.ipynb # Basic LangGraph chatbot
│ ├── 10_persistence.ipynb # State checkpointing & resume
│ ├── 14_hitl.ipynb # Human-in-the-Loop interrupts
│ ├── 15_subgraphs.ipynb # Nested subgraph composition
│ ├── 15_subgraph_shared.ipynb # Subgraphs with shared state
│ └── fault_tolerance.ipynb # Error handling & resilient workflows
│
├── 🐍 Scripts
│ ├── chatbot_with_hitl.py # HITL chatbot (runnable script)
│ └── chatbot_without_hitl.py # Baseline chatbot (runnable script)
│
└── .gitignore
Verifies that LangGraph, LangChain, and OpenAI are correctly installed and your .env is loaded.
Run this first before anything else.
No LLM involved — this is a pure graph to teach the mental model. Takes height/weight as input, calculates BMI, routes to a category node.
Concepts: StateGraph, TypedDict state, add_node, add_edge, START, END, .compile(), .invoke()
Adds an LLM node into a graph for the first time. A minimal graph where one node calls ChatOpenAI and returns the result.
Concepts: LLM node functions, MessagesState, binding a model inside a node
Chains multiple LLM calls as sequential graph nodes — each node's output feeds as context into the next prompt.
Concepts: Sequential edges, passing state between nodes, multi-step reasoning in graphs
Uses a cricket batsman's stats as input, fans out to multiple parallel analysis nodes (batting avg, strike rate, consistency), then merges results.
Concepts: Parallel node execution, fan-out / fan-in pattern, Send API, merging parallel outputs
Generates a structured essay for UPSC (Indian civil services exam) topics using a multi-step pipeline: outline → draft → review → final.
Concepts: Multi-stage LLM pipelines, structured state with multiple fields, prompt engineering within nodes
A routing graph that checks the discriminant of a quadratic equation and routes to different nodes: two real roots, one root, or complex roots.
Concepts: add_conditional_edges, router functions, branching logic in graphs
Takes a product review, classifies sentiment, then routes to a positive-response node or a negative-escalation node.
Concepts: LLM-powered routing, conditional branching, real-world classification use case
Generates an X (Twitter) post, evaluates it, and loops back to refine if it doesn't meet quality criteria — demonstrating cycles in a graph.
Concepts: Cycles / loops in StateGraph, self-correcting agents, iteration counter, loop exit conditions
A simple conversational chatbot built with LangGraph's MessagesState, maintaining full message history across turns.
Concepts: MessagesState, multi-turn conversation, message accumulation, streaming
Adds memory to the chatbot using a checkpointer so conversation state survives between sessions. Demonstrates thread-based state management.
Concepts: MemorySaver, SqliteSaver, thread_id config, state resumption, time-travel debugging
Pauses the graph mid-execution for human review or approval before continuing — the foundation of safe agentic systems.
Concepts: interrupt_before, interrupt_after, graph resumption, approval workflows, NodeInterrupt
Composes complex systems by nesting graphs inside graphs — each subgraph has its own state and logic.
Concepts: Subgraph compilation, parent/child graph communication, modular agent design
Extends subgraph patterns by sharing state keys between parent and child graphs.
Concepts: Shared state schema, state inheritance, cross-graph data flow
Builds resilient workflows that handle node failures gracefully — retry logic, fallback nodes, and error state handling.
Concepts: Try/except in nodes, fallback edges, error state routing, retry patterns
| Script | Description |
|---|---|
chatbot_without_hitl.py |
Clean chatbot — continuous conversation, no interrupts |
chatbot_with_hitl.py |
Same chatbot with HITL interrupt — pauses for human approval before sensitive actions |
Run either with:
python chatbot_without_hitl.py
python chatbot_with_hitl.pygit clone https://github.com/codeantik/langgraph.git
cd langgraphpython -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windowspip install langgraph langchain langchain-openai langchain-community python-dotenv openai jupyterCreate a .env file in the root:
OPENAI_API_KEY=your_openai_api_key_here
LANGCHAIN_API_KEY=your_langsmith_api_key_here # optional, for tracing
LANGCHAIN_TRACING_V2=true
LANGCHAIN_PROJECT=langgraph-learningjupyter notebookThen open notebooks in order, starting with 0_test_installation.ipynb.
| Concept | Notebooks |
|---|---|
StateGraph basics |
1, 2 |
| Sequential chaining | 3 |
| Parallel execution (fan-out/in) | 4 |
| Conditional edges & routing | 6, 7 |
| Iterative loops / cycles | 8 |
| Conversational chatbot | 9 |
| Persistence & checkpointing | 10 |
| Human-in-the-Loop (HITL) | 14, chatbot_with_hitl.py |
| Subgraph composition | 15a, 15b |
| Fault tolerance & resilience | fault_tolerance |
- StateGraph fundamentals
- Sequential & parallel workflows
- Conditional routing
- Iterative / self-correcting loops
- Chatbot with message history
- Persistence & state checkpointing
- Human-in-the-Loop
- Subgraph composition
- Fault tolerance patterns
- Multi-agent systems (supervisor pattern)
- LangGraph Studio integration
- Streaming & real-time output
- Deployment with LangGraph Cloud
Ankit Singh — Full Stack Developer & Agentic AI Specialist
Also check out my LangSmith / LangChain fundamentals repo: codeantik/langsmith
This project is open source and available under the MIT License.