LangGraph · Lesson 41 of 120
Threads
Separate conversations.
A shop talks to many customers at once. Each needs their own conversation. A thread is one conversation, saved separately. Different thread IDs never share state.

- Many customers
- One thread each
- Never shared
Two customers
Same visit counter graph, imported from a helper. Sam visits twice, on his thread. Priya visits once, on hers. Run it. Sam's count reaches two, while Priya's is one. Their states are completely separate.
threads.pypython
from visits import graph
def visit_as(name):
config = {"configurable": {"thread_id": name}}
return graph.invoke({}, config)["visits"]
print("sam:", visit_as("sam"))
print("sam:", visit_as("sam"))
print("priya:", visit_as("priya"))Output
sam: 1 sam: 2 priya: 1
Also uses visits.py
import operator
from typing import Annotated, TypedDict
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import StateGraph, START
class State(TypedDict):
visits: Annotated[int, operator.add]
def visit(s):
return {"visits": 1}
b = StateGraph(State); b.add_node(visit); b.add_edge(START, "visit")
graph = b.compile(checkpointer=InMemorySaver())Choosing thread IDs
In a real app, use a stable ID per conversation. A chat session ID, or a customer ID plus a date. Never let two customers share one. And a new thread ID gives a fresh start, which is how you offer a new chat button.
| key | value |
|---|---|
| One per conversation | session ID |
| Never shared | between customers |
| New ID | fresh start |
| Same ID | continue |
Summary
Each thread ID is a separate conversation, with its own saved state. Use a stable ID per conversation. Next, a chatbot that remembers.
Key takeaways- thread_id
- Separate state
- New ID, fresh start
Next up: Memory Across Turns — a chatbot that remembers