LangGraph Agents

Course Content

LangGraph Agents

7 sections · 49 lessons

What is a thread or session in LangGraph execution, and why does it matter for persistence?


What you need to know

Python
config = {"configurable": {"thread_id": "cust-4471:case-2209"}}graph.invoke({"messages": [{"role": "user", "content": "Internet is slow again"}]}, config)graph.invoke({"messages": [{"role": "user", "content": "Still slow after restart"}]}, config)

The second call sees the first turn because it uses the same thread.

Rules

  • Checkpointer and no thread_id — the call raises a ValueError.
  • No checkpointer — every call is stateless, whatever id you pass.
  • Same id — continue the latest checkpoint of that thread.
  • Add checkpoint_id — start from a specific past checkpoint instead (time travel).

Choosing the id

ProductGood thread_id
Chat assistantOne per conversation
Support deskOne per case: customer:case
Insurance claimOne per claim: claim-88213
Refund workflowOne per refund request

One thread per user "forever" makes state grow without limit; one per request loses context. Pick the natural unit of work.

Security and retention

  • Never accept a raw thread_id from the browser without checking the user owns it. A guessable id is a data leak.
  • Keep user identity in the runtime context and check it in your API layer.
  • Delete finished threads with checkpointer.delete_thread(thread_id) or set a TTL on Agent Server.

A real-life example

A broadband support bot first used thread_id = phone_number. Two problems appeared. A family sharing one phone number saw each other's earlier questions, and one father's thread grew to 1,900 messages. The team switched to f"{customer_id}:{case_id}", checked ownership in the API before every call, and moved lasting facts (router model, language) into the long-term Store keyed by customer. Old cases are deleted after 90 days.

Follow-up questions to expect

  • "Can two requests use the same thread at once?" — They can race. Serialise requests per thread in your API; Agent Server handles this with its run queue and "multitask" strategies such as reject or enqueue.
  • "Is a thread the same as a user?" — No. A user can have many threads; cross-thread facts go in the Store.
  • "How do you list a user's threads?" — Keep your own table mapping user to thread ids, or use Agent Server's threads API with metadata filters.