Skip to content

codeantik/langgraph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🕸️ LangGraph Learning Journey

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.

Python LangGraph LangChain Jupyter OpenAI


📚 What This Repo Is

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

🗂️ File Structure

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

🧭 Notebook Breakdown

0️⃣ 0_test_installation.ipynb — Installation Check

Verifies that LangGraph, LangChain, and OpenAI are correctly installed and your .env is loaded. Run this first before anything else.


1️⃣ 1_bmi_workflow.ipynb — BMI Workflow (Intro to StateGraph)

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()


2️⃣ 2_simple_llm_workflow.ipynb — Simple LLM Workflow

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


3️⃣ 3_prompt_chaining_workflow.ipynb — Prompt Chaining Workflow

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


4️⃣ 4_batsman_parallel_workflow.ipynb — Batsman Parallel Workflow

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


5️⃣ 5_upsc_essay_workflow.ipynb — UPSC Essay Workflow

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


6️⃣ 6_quad_eq_conditional_workflow.ipynb — Quadratic Equation Conditional Workflow

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


7️⃣ 7_review_response_conditional_workflow.ipynb — Review Response Conditional Workflow

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


8️⃣ 8_x_post_generator_iterative_workflow.ipynb — X Post Generator (Iterative Workflow)

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


9️⃣ 9_basic_chatbot.ipynb — Basic Chatbot

A simple conversational chatbot built with LangGraph's MessagesState, maintaining full message history across turns.

Concepts: MessagesState, multi-turn conversation, message accumulation, streaming


🔟 10_persistence.ipynb — Persistence & Checkpointing

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


1️⃣4️⃣ 14_hitl.ipynb — Human-in-the-Loop (HITL)

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


1️⃣5️⃣ 15_subgraphs.ipynb — Subgraphs

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


1️⃣5️⃣ 15_subgraph_shared.ipynb — Subgraphs with Shared State

Extends subgraph patterns by sharing state keys between parent and child graphs.

Concepts: Shared state schema, state inheritance, cross-graph data flow


fault_tolerance.ipynb — Fault Tolerance

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


🐍 Runnable Scripts

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.py

⚙️ Setup & Installation

1. Clone the repo

git clone https://github.com/codeantik/langgraph.git
cd langgraph

2. Create a virtual environment

python -m venv venv
source venv/bin/activate        # macOS/Linux
venv\Scripts\activate           # Windows

3. Install dependencies

pip install langgraph langchain langchain-openai langchain-community python-dotenv openai jupyter

4. Set up environment variables

Create 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-learning

5. Launch Jupyter

jupyter notebook

Then open notebooks in order, starting with 0_test_installation.ipynb.


🧠 Core Concepts Covered

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

🗺️ Learning Roadmap

  • 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

👨‍💻 Author

Ankit Singh — Full Stack Developer & Agentic AI Specialist

GitHub LinkedIn

Also check out my LangSmith / LangChain fundamentals repo: codeantik/langsmith


📄 License

This project is open source and available under the MIT License.

About

My langgraph learning journey

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors