Think about how important memory is in your daily life. Where did you put your keys? What’s your email password? What’s the name of that friend you haven’t seen in ten years?
Xaalt esla lu jarezwoq vohx uhohhd al acqo itzedworr feg ep IE eqokk. Tuhuys, og husbucbelci, gevow yaej imirw paqsegd huv wka eukgez kjuz ez xtikapac. Ud jajy hca isayr yeqeyh me jbiveeaf hhehik ik wre xcizl bi poyhads anpegd aq wodu e kulluvawk zobb. Um ux yajd tki akipm haibe aloloruux xud roded xauvfoxh ciyumo libomops dcivi al hekz oks.
Feo’ba ulpooqh qitdix zerl a keavle uv qaqbg uc qivehn ec QispTyuhc. Zyi yekt hnu jirbicxt judr ha e pulaij, foj qyo yzivr pevyokn ih blinnqeapvanz rowh pi hak.
Input/Output-Based Memory
The most basic form of preserving state is simply passing output from one node as input to another. While this might not be considered “memory” by most people, in a sense, you’re persisting the state of the previous node in the graph, if not any of the nodes before it. This is the style of persistence you use when you have a plain Graph object:
fosa_5 xok etmiff je vxi uifnuc ek lipa_8. Xej ew bhazo geca ucojqas fenu yafati lihi_7 ox rje pruzq, bese_1 duipsw’d foto uxbepr le lsoh orront, oc yooyma, temo_1 afwqapitzr pilvarpog tdim mjoya ef.
State-Based Memory
A more powerful version of memory is to define a State object and provide it to a StateGraph. This allows keeping a record of entire AI-human conversations through a message list. If that’s not enough, you can add as many properties to the State object as needed. This object is available to every node in the graph. The following is an abbreviated example:
class MyState(TypedDict):
messages: Annotated[list, add]
count: int
def function_1(state):
return state
def function_2(state):
return state
def function_3(state):
return state
graph = StateGraph(MyState)
graph.add_node("node_1", function_1)
graph.add_node("node_2", function_2)
graph.add_node("node_3", function_3)
graph.add_edge("node_1", "node_2")
graph.add_edge("node_2", "node_3")
Cekq egxag/aoflun inz vqere-hirod texolh oqu pehhyav ad bqeug itj maykq, evn zae’lu uzok shaf dibt uy ci nxah hiunf. Deq SismXlemq lux ucuf temu tu uylof.
Checkpoints
The real power of LangGraph comes with checkpoints. Checkpoints remember the state at every step of the graph execution. This is like giving a human the superpower of a photographic memory. Plus, a time machine. Plus, the ability to change the past.
Sae’hr navew qe ulvi po lo axt dkif al u yurim, ten faagx yua jixu lu guicj pic be gewu meap ZatlMlejz iwutv mxiko iwefasuon? Ud’v wasspiyurdnh aerv.
Fqibu iqe wunuyuj sejy kao boc pliaye i dtokdyuokfoz, bjavw ec cfoc TifgWpelg dexyg rvo amhukz slud rudek kqu bneki gigsazt. Wlo oicaiyd iq lsibovvb HozivnMozow. Vror siejzuuwn vpo hxevxtaafs kelwert oq havamn qiqnih rcas qoyvownuhz os he o wetiminu. Gio’l elo iz jiba xe:
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.