AI Hints
Home›LangGraph Tutorial›Good Design
LangGraph · Lesson 109 of 120

Designing State

Keep it small.

⏱ 2 min read▶ Video at 1:57:44🎓 Free
Watch this lesson in the LangGraph courseWatch on YouTube ↗Full LangGraph course

Most messy graphs have messy state. Too many keys, unclear names, and data that's stored twice. A few simple rules keep state clean, and the whole graph easier to understand.

Designing State
From the video: Designing State
  • Messy graphs, messy state
  • Too many keys
  • A few simple rules

State rules

Store facts, not things you can work out. A total can be calculated from the lines. Use clear names, like refund amount, not amt. Pick the right reducer for each key. And keep large data, like documents, out of the state, storing only IDs or summaries.

keyvalue
Factsnot derived values
Namesclear, specific
Reducerschosen per key
Large datastore IDs instead

Messy vs clean

Here's a messy state, with vague names, duplicated data, and whole documents. And a clean one, with clear names, one place for each fact, and only the document IDs.

Messy

  • data, data2, tmptotal AND linesfull documents

Clean

  • refund_amount, categorylines onlydocument IDs

Summary

Good state stores facts, uses clear names, picks the right reducers, and keeps large data out. Next, designing the graph itself.

Key takeaways
  • Facts only
  • Clear names
  • Small state
Next up: Designing Graphs — small nodes