Abstract / Overview
LangGraph is a framework built on top of LangChain that enables developers to design and execute agentic workflows as structured graphs. Instead of chaining language models linearly, LangGraph uses nodes (representing functions or agents) and edges (representing logic flow) to manage multi-agent reasoning, memory, and state transitions in complex AI applications.
This article provides a full, step-by-step tutorial for building LangGraph applications.

Conceptual Background
LangGraph extends LangChain’s composability model by allowing developers to define directed graphs that describe how agents and tools interact dynamically.
Key concepts:
Node: Represents a unit of computation, such as a model call or a tool.
Edge: Defines how outputs flow between nodes.
GraphState: The evolving memory of the system during execution.
Supervision: Nodes can modify future execution paths based on results.
Concurrency: Multiple nodes can run in parallel when independent.
Compared to sequential LangChain chains, LangGraph supports adaptive, non-linear workflows, ideal for applications like dialogue systems, planning agents, and retrieval-augmented generation (RAG).
Step-by-Step Walkthrough
Step 1. Install Dependencies
pip install langgraph langchain openaiSet up your environment key:
export OPENAI_API_KEY=YOUR_API_KEYStep 2. Import Core Components
from langgraph.graph import StateGraph, END, START
from langchain.chat_models import ChatOpenAIStep 3. Define Graph State
Each node can read from and write to a shared state.
class GraphState:
def __init__(self, query, context=None):
self.query = query
self.context = context or []Step 4. Create Nodes
Define two example nodes — one for answering questions and another for summarizing.
llm = ChatOpenAI(model="gpt-4o-mini")
def answer_node(state):
response = llm.invoke(f"Answer the query: {state.query}")
state.context.append({"answer": response})
return state
def summary_node(state):
summary = llm.invoke(f"Summarize the conversation: {state.context}")
state.context.append({"summary": summary})
return stateStep 5. Construct the Graph
graph = StateGraph(GraphState)
graph.add_node("answer", answer_node)
graph.add_node("summary", summary_node)
graph.add_edge(START, "answer")
graph.add_edge("answer", "summary")
graph.add_edge("summary", END)Step 6. Compile and Run
app = graph.compile()
result = app.invoke(GraphState("What is LangGraph?"))
print(result.context[-1]["summary"])Mermaid Diagram: LangGraph Flow


Join the conversation! Your thoughts help the community grow.