A hands-on tutorial for building stateful AI chatbots using LangGraph — a powerful framework from LangChain for orchestrating LLM workflows as graphs. This notebook demonstrates how to construct a conversational AI system with proper state management using Groq's ultra-fast inference with the Gemma2-9b model.
LangGraph is a library built on top of LangChain that lets you model your AI agent logic as a stateful graph. Unlike simple LLM chains, LangGraph allows:
- Cyclical flows — agents can loop, retry, and branch based on conditions
- Persistent state — conversation history and context are maintained across turns
- Multi-agent coordination — multiple specialized agents can collaborate within a single graph
- Human-in-the-loop — you can pause execution and inject human feedback at any node
In this notebook, you'll learn the foundational building blocks: StateGraph, nodes, edges, and how to wire them together to create a working chatbot.
User Input
│
▼
┌─────────────────────────────────┐
│ StateGraph │
│ │
│ START ──► chatbot ──► END │
│ │
│ State: { messages: [...] } │
└─────────────────────────────────┘
│
▼
LLM Response (via Groq)
The graph consists of:
- State — a
TypedDictholding the list of messages, updated viaadd_messages(append-only) chatbotnode — calls the Groq LLM with the current message history and returns the response- Edges —
START → chatbot → ENDdefining the flow
| Component | Library | Purpose |
|---|---|---|
| Graph Orchestration | langgraph |
Stateful graph-based agent framework |
| LLM Provider | langchain-groq |
Fast inference via Groq API |
| LLM Model | Gemma2-9b-It |
Google's open-weight instruction-tuned model |
| Observability | langsmith |
Tracing and monitoring LLM calls |
| Environment | Google Colab / Jupyter | Interactive notebook execution |
Click the badge at the top → runs entirely in your browser, no local setup needed.
You'll need to add these secrets in Colab (🔑 Secrets panel in the left sidebar):
groq_api_key— get your free key at console.groq.comLANGSMITH_API_KEY— get your key at smith.langchain.com
1. Clone the repository
git clone https://github.com/senthilece01/chatbots_with_langGraph.git
cd chatbots_with_langGraph2. Install dependencies
pip install langgraph langsmith langchain langchain-groq langchain-community3. Set environment variables
Create a .env file in the project root:
GROQ_API_KEY=your_groq_api_key_here
LANGSMITH_API_KEY=your_langsmith_api_key_here4. Launch the notebook
jupyter notebook chatbot_with_langGraph.ipynbInstalls langgraph, langsmith, langchain, langchain-groq, and langchain-community.
Loads secrets securely from Colab's secret manager (or .env for local use).
Sets up ChatGroq with the Gemma2-9b-It model — one of the fastest open-weight models available via Groq's LPU inference engine.
class State(TypedDict):
messages: Annotated[list, add_messages]The add_messages annotation ensures messages are appended (not overwritten) on each graph invocation — this is what gives the chatbot memory.
graph_builder = StateGraph(State)
graph_builder.add_node("chatbot", chatbot)
graph_builder.add_edge(START, "chatbot")
graph_builder.add_edge("chatbot", END)
graph = graph_builder.compile()Renders a Mermaid diagram showing the graph structure — useful for debugging complex multi-node graphs.
Interactive loop that streams responses from the graph and prints them in real time.
- StateGraph — the core LangGraph class for building stateful graphs
- TypedDict State — how to define and annotate graph state
add_messages— LangGraph's built-in reducer for message lists- Nodes and Edges — how to compose graph logic
graph.stream()— streaming execution of the graph for real-time output- LangSmith Tracing — automatic observability for every LLM call
- Python 3.10+
- A free Groq API key (no credit card required)
- A free LangSmith API key (optional, for tracing)
chatbots_with_langGraph/
│
└── chatbot_with_langGraph.ipynb # Main notebook with full implementation
This notebook covers the foundational single-node chatbot. Future notebooks in this series will cover:
- Chatbot with memory (persistent conversation history using
MemorySaver) - Tool-calling agents (web search, calculator, code execution)
- Multi-agent systems (supervisor + worker pattern)
- Human-in-the-loop flows with interrupt/resume
This project is licensed under the MIT License.