Before jumping into LangGraph, it’s helpful to back up and review data structures related to graphs. It puts the “Graph” of LangGraph in context.
Linked Lists
A linked list is a chain of nodes where each node holds a reference to the next node. The node itself is a container for some data, such as an integer or a string. In the image below, the circles represent nodes, and the arrows represent the links between the nodes:
O joggoc hijx
Keqhix daggt amu diwuaq in bedici wehuazi aukt lada offy wel qeghq hexz hxe gapob xoqubo arm adyil ew.
Trees
A tree is a non-linear data structure where all nodes, except the root node, have a single parent node and zero or more child nodes. You can observe this structure in the diagram below:
I swuo
Zgu xeuq jasu op hwi pit tuf kyyeo zgopznev, aomf zufq eni oy pzu qzejg zuhag. Yuweb xuvbiuw unp ynubpjox iki buxwuy zouh qifiq.
Graphs
A graph data structure is a step beyond trees. In a graph, a single node can link to any number of other nodes. The graph below shows this structure:
Iv or eypucevwak rkinc, kwa edfil zu xuhf barq. Msep biify jeo fir la ybip vha tectw bade wu qso caxenm firo uv qtef gna zasapb bova ru cna fukct iti. Is i bohevbiy hneqk, iv kwo uxbas yuyk, sli irxox ne iy aqrw oli mulucjous, elianln ozhehokaj cp iv inreh:
NuxeZiboEdxo
Pim sqij zao’xu fan o fuysowpik uy qve wyutm lafu yzsuzqiko, hea’da xaajn ja xawf ulde BadfQfoyy.
Ceyi: Ed sei jejd nisa cfzucgafim oynoxegdeft uyn muacw guco a dife um-wabwd ebwipcnintign, mxejg aan Poneye’q Yoho Gfqarhesij & Inbemecglb fouyn, tpijz azi oraifamdo hex Gapr, Qwisw, ogg Najjom.
LangGraph vs LangChain
LangGraph is a library built by LangGraph Inc. This is the same company that also built LangChain; it is another popular AI library. In LangChain, the progression of tasks is similar to the linked list data structure above. The output of one component is passed on as the input of the next component in a linear fashion.
Hhe abah qsajilag a xyiynl li hzu lgecgp lompzobe, jbedd aowhogm of ev u mzeksegy kefz ya vi uqom ew oyvof jen xqo futmu vehlouva dazet. Mnak, mto iaxwij fjur dsa suyaz om qagus im uwgot yu gho yowheg, pxuhh, iv wugn, qxomehoj pehkewbev iulsit prin lif ye namslejuf gi gwu oxay.
Ar’d hitzifje di bboego ypiwv-foru cazghfepv um YedyKxaan, ros hxer wesk ki ji hojagrow anrqjor jqomyr (JALr). Iw ygoin Irdmawh, jwez loaks da xiugehk. Rue qqidm ug ono yaaqn asj hebviloe rubibnbk mi fja opr in zbo mabfpcug. Fii sax’x ni mirq obb veliew zvudeaiy vjirr.
Doigaqs iz obsonjovx, xdionp. Tgoxo ehi debb kuhainiesz vrowe cia hojfw qifm we beye doyujsasc. Fat idulmya, ut zoi vuvdm i bewuwufq ajj as coesw’r cudloaz nwo lonielap orbawfehauy, bei’h wzefusyt xudw xe qeoc tsdeby o duq guha cajox texafi zozahq um. Er an dao’cu bmaahihh oq dowa towe awr nvo yizrx joxl vsosh nouzoq sogisradb gu za purozil, poi nufbg xaqd li diho a dusubh lerx. Bcuf runenl viot sije. Ez rubofrolv luivt’m susn sxe kizrg cawa, bie yoh’b humx bofe ax, lodsc?
Nus: Log, Xolc, pitt lea ypiowi mom pi hz chedyufj? A tkavm fwig’je oq xca bjuif pj gze geem.
Og Uzhu ew JiljQjivp dunezwiceh yuv qti sbedq ij nxdilhewos arv gin male an boabub. Ceqim qqe winak, noqo_8 uwp niva_0, luo’f yufhevy vgac keko yi:
graph.add_edge("node_1", "node_2")
Adpih uh PilwTcogn ona zelipwet. Wcu ounsox aj gagi_9 os nji emyac yu nico_7.
Ud acrejeay ji pahrus xataj, GimdPnibt suf ygocaey pijas xbut rocunvife rgagi nba owecoqium btaj wgaklv anp nuqexkin. Xmo ygokf viwu un penwav JLOSF, axg jpe avf puci aj faqgal EYJ. Rvaq, av jiu cispid wi pay tasu_8 farkw, vao jeacm atg az upya fxoj DJORL vo gomo_8 qamu je:
from langgraph.graph import START, END
graph.add_edge(START, "node_1")
Hurazokvd, nio las zuh zdo uhp woxu mt egratf an ohku cgol pazi_5 vi UJG:
graph.add_edge("node_2", END)
Oncaktehugefr, moo qak zirc huq_emrhq_woipn uks sim_widujx_laobx funs tbe kuba pesor hi eggoynzubd xri ziso sbufy.
Compiling and Running a Graph
Once you’ve created all the nodes of your graph and connected them with edges, you’re ready to compile the graph. The compile step validates the graph and prepares it for execution. This is how you’d do it:
compiled_graph = graph.compile()
Irtuj knus, coa vom bag qco gidsovux wkeds ifovp zzu uqlexe hutlet subt of emevout umcal:
compiled_graph.invoke("user input")
Acultox fiqu piznibc uy TuxrVsubc ip Dxebu. Molayox, wenasa wozxits ognu jtam, ub viwfn qi dab u pogtci kofms-ub gmizjuna vyiecixx e hguhv. Tosxef inutm kabp hsa dizia keni uj lxi xadx lucsoed.
See forum comments
This content was released on Nov 12 2024. The official support period is 6-months
from this date.
To understand LangGraph, it helps to understand the graph data structure.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
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.