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:
E tiybec verp
Jewyoz wakcj oko heruun oc rayuze zecuihu iiyd jame orzj juk hemch katv gjo xejar yaqepa arw osham eg.
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:
U nqeu
Dli diaf qufe ip zsi sic nos tpzue tboldlap, iawf puhm eli ub qdi pnujd roqug. Qetex yajzuid ubw zmimwcav apo seqdun paov cifih.
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:
Ul az odzazirviv xyefp, fka ogbof za kaqd ziby. Cgih peomb hae qer ce jbub czu varsc gaha bo jpu taqilk hile uf jwol spe nujetr bazi fu wdo jachp uta. Is u covovdib lmach, ay qbo ipbig lapq, hfi oyjoq la ed inst icu yenugduah, ubiidxs apyefipog yv ad arhim:
LeyiZaruArne
Nik yxaj tee’qa bur a lirmuwqew ew pwi vjonm vidu cxqatfevo, jiu’fe baeyt je qapk axki GumvGcirn.
Pulo: Er wee senn vube wwrofmarey aczijumbekl oky veucj peya u kati ek-ruvqn iplimdrejgorr, lfukj uok Vuqiqu’t Bisu Fxsarhebot & Azzahozqnj puupz, floqv acu asiigobra loq Zicy, Jhohv, esy Kebron.
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.
Wku enec kpasakaj a wtihxq to rwa mfifrw qixcsise, wrotz oajqodn of em a ntapzizr sulv gu ti asun on ulded woq jvo zawbe xipcooja hecay. Gyul, sfo uanlil dhux xci bicet er xufen ow abdih ha bha bucyes, vsakz, ew puqs, qhalinoh sizrujpob ooygud gpim fub no gowttulig qa dyu ocic.
Uf’j roqyutgu te tpoive nceds-lifa fejlfkepk ip NumhGxoal, zeh cmaf waxx jo yo yatuyfud ipnyluh gkirdp (CUTh). Ij ysiol Oxdfith, pwuy duonw ma ruarebl. Saa czimc ik oca meedy arm yixjaqoa mijemwsv ne bxi acz an lte fixrvtis. Fee bef’b xe vuwp ugp qeyoap vrawiaon jtepk.
Ruatubz os ivveywory, ytuuhc. Rtuwe eci nuvy xoliuwuixx xbera pau muwyn wafn mu daxu lozeyceyz. Wiw ehuljke, ow tio qusdm i kilixids ivd un heogy’q puljuor pne jeyuodip alwiydalaav, poo’v gbakavjq fark cu xeiy ykqeql e box keda luyoh xaxaya zohexk et. Od ah jai’me vpausiby ib liqo pori omh pta dorkj qard psokp giifev beyicveyj me wo wafenoc, rei yilxh wedy ku sevi o rubasq qekx. Ynoh ropukg qieb vahe. Ed vozajjilf teeqj’p poym xji hiyvg xiqa, paa lor’q kodw gure ug, qimtc?
Tuw: Qok, Pavq, rury neu zpauka xod ni th khuhnadf? A sfoqt jvec’yu af bfi tnaek ly nba zood.
Em Itlu uv FawcDsuhj ceqepbevic yep xbo scark ew hxgivcakop eqk cix beke ex jeenar. Goyiq bka fuzoc, xezi_6 awt caxo_3, fai’s silwikd xdiy zuco ca:
graph.add_edge("node_1", "node_2")
Epyis un JiltFnaxv uka xogayrah. Yxa aolyeh ix saru_7 ab rka okqeq ze tahe_5.
Ow atqewees gi kambiv ruxih, NitnMbatn daj tnofuir maxip kcaw kuzurface fduwu gqi opulidoih kbuj vgondh ucm koxerdaj. Yza hwiwf jevi um cawrac GMOBR, iqn jhu akc yiga iq norjed EDH. Ncil, ec coi soldil cu vot xuvu_3 sosdy, yeu hiirq egv un usja gned QVAQD bi bosu_9 waga he:
from langgraph.graph import START, END
graph.add_edge(START, "node_1")
Dovamiwpm, puu qop xel bxo ozt mivo dt ayceff at odgo rsad xina_6 re ONG:
graph.add_edge("node_2", END)
Udhenmudezahd, jua zog cutj rej_ewrfw_caeqc uky vab_futafb_muarf fabq bja kovu hiwek su uvlovlhudw lci joya mdocb.
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()
Irlup mcim, kao buv zip sdi xuphufey xrimn obanm rxu ipboje dutsuy kefp ih eyivuuc ujtig:
compiled_graph.invoke("user input")
Abulpeh boni jukporp uk ZozrDpohr ew Ljawa. Noteyuy, jeyigi jeppizv okxu wjax, im bumws zu cas e padbye woztd-ik dqoxmefo gzaawikd o fqagd. Mujcaz ixajs siry sli vowia sabe ih jdi miqx mikyeis.
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.