LangChain/YouTube/LangGraph Builder
Properties
- logseq-entity
- Logseq/Entity/YouTube
- created-by
- Person/Harrison Chase
LangGraph Builder - YouTube - intro to langgraph/Builder
My Notes
Video
- 00:00 building agents is actually quite a visual Engineering Process you want to see the whole flow of the agent how it goes from one state to the next when it might respond to the user Etc stuff like that and so we've always gotten pushed
- 00:16 in kind of like a no code low code direction for Lang graph and we're not going all the way there but we are going part of the way there and building a no code interface for generating the scaffold of your graph application so I
- 00:32 want to show that off today and then show how you can use this and code on top of it to generate a full Lang graph application so let's go through it so here I've got Lang graph Builder it's at build. Ling chain.com and it's basically
- 00:46 a canvas where I can start sketching out the architecture of my agent so I can see the instructions here um and so in order to create a node I just command click so I'm going to do that so I'll create a few nodes here I can then
01:00 rename them so let me rename this agent let me rame this tools and let's do this like retrieval and then let's say I always want to go to retrieval first and then after that I can go to agent and then agent can go to tools or it can go
- 01:17 to end and tools Loops back to agent as well all right so I've got this type of graph and so we often work with teams and we whiteboard this or we use fig Jam or something and and then the next step from this is they go write a bunch of L
- 01:33 graph code for the outline of what we just sketched out here and then they get to the good stuff they get to the business logic and they start implementing what exactly retrieval means what exactly the agent logic is
- 01:42 what exactly is in the tools and so this tool is designed to make that process easier and how does it do that well if you click this generate code button here you'll see that it generates three different files so this is for python
- 01:56 but you can also do it for typescript so it generates a spec. EML this is just a yaml representation of the agent and so we can see the nodes and the edges here it also generates stub. Pi so this is an automatically generated file you are not
- 02:09 intended to modify it and this contains a lot of the actual L graph code so it's got State graph start end and then it basically creates this graph by adding nodes and adding edges but it expects that certain things are passed in and so
- 02:25 then this is the third file and this is the one you are supposed to edit so this is implementation. this Imports the stubs from stub. and then basically you just Define the state which is a dictionary the the nodes any edges and then you pass this
- 02:42 in to custom agent and this does all of the Lang graph boiler plate behind the scenes so then basically this removes all the boiler plate into something that's automatically generated and you can just focus on writing the nodes and
- 02:54 edges so let's see how to use this I'm going to download this I'm then going to go over to my terminal I'm going to create a directory to work in I'm going to copy the files that I just downloaded into this directory I'm going to unzip
- 03:22 it and so now if I look at my directory I can see that I have this spec. yml this stub. py and this implementation file locally let's open them up great so here I can see the spec here's the stub and here's the implementation okay so now there's a few
- 03:43 things that I need to do before my agent actually starts to work so I need to add the attributes that I want any kind of like State update logic here these are all the nodes and then I need to add in kind of like the conditional Edge stuff
- 03:57 here so now I'm just going to make this really simple I'm just going to say from here we're always going to go to the end the rest I'm going to leave as just blank because I just want to show this in Ling graph studio now so I'm just
- 04:09 doing the bare minimum to get it running so let's save it there then I'm going to go back here I'm going to create a python environment and then start working on it so I'm going to do Pym virtual M this create this P
- 04:33 activate L graph stubs 2 I'm going to pip install L graph and then in order to run the studio I'm going to install the Lang graph CLI so pip install Lang graph CLI with the inm component so this is going to use the inmemory server to run L
- 04:56 graph studio and then in order to run L graph Studio the last thing I have to do is just create a l graph. Json so let's do this I'm going to make it super simple I need to Define dependencies this is dead simple and
- 05:16 then graphs let's do this agent is just simple implementation and then I'm going to go here it's called compiled agent so that's what I'm going to use I'm going to delete that line there so it doesn't run let's save this file let's go back
- 05:34 here implementation compiled agent let's try this out line graph Dev great we can see it's running it opens it up great so this is the agent that I just sketched out and so all the boiler plays here again in order to
- 05:50 actually run this I'm going to have to go in and Implement some of the nodes but that's fine we'll we'll we'll do that so this is great we've got our agent set up but what if I want to modify this so let's shut down our
- 06:02 server let's go back to our UI and let's say we now want to add like a guard rail here so let's do guard rail let's delete this Edge Let's have this coming over here and then let's have this going here okay so we modified our graph so we
- 06:19 could regenerate the code and we could just download everything again and do the same exact thing but by this point I've probably I've probably already implemented things in implementation. and I don't just want to override those
- 06:31 so what I'm going to do is I'm going to copy the spec. EML I'm going to go into to my editor I'm going to put the new spec here so now this has kind of like the guard rails in it so I can see it here and I'm going to save that then I'm
- 06:46 going to use this nice handy package to generate the stub file as I need so I'm going to install it with Pip install lingraph gen so let's do that then I'm going to copy this line I'm going to go here so I want to put the spec in
- 07:10 the I want to put this in stub. piy so let's do this into stub. piy and then implementation I don't really care about implementation because again in this scenario I've already worked with my existing implementation I've implemented a bunch
- 07:24 of the nodes I don't want to overwrite it so I'm just going to send it to a random file so let's do that let's go check out this if we go to stub. piy we should now see that yeah we have guardrail mentioned here we have this random custom implementation
- 07:37 implementation hasn't changed so if I try to run the agent now it's actually going to throw an error because I if you look at implementation here I don't pass in guardrail so let's try that and see what happens great so we run this look
- 07:54 missing implementations for guard rail okay awesome so now what I would need to do is I'd want go in I'd want to do something like def guard rail State some State and I would just do uh you know pass or something like that in real
- 08:12 world I'd Implement my implementation but I'm just going to do this then I'm going to go in here I'm going to add guard rail guard rail let's save this and let's now run it again great so now we have our new modif graph so this is how I can kind of like
- 08:32 set up this process of sketching out the graph in the UI using it to generate some stubs not having to worry about boiler plate Lan graph code modifying it update the spec regenerate the code but not override my implementation and this
- 08:46 is how I can quickly kind of like go from this cognitive architecture with I which I sketch out in the UI to Stubs which I can then Implement and so this is a great place for product managers and subject matter experts to
- 09:00 collaborate with Engineers this canvas is right here and then Engineers can go in and kind of like implement it the only other thing that I want to call out is this template section so here we have a few kind of like predetermined
- 09:10 templates they're pretty simple we've got a rag template we've got agent with tools but these are common patterns we're going to add more here so let us know what ones You' like to see and I also want to point out that this is all
- 09:21 open source so we've got Lang graph Builder here which is open source and then we've got L graph gen uh the python version but again this can also generate t script ones um this is open source as well so please try this out let us know
- 09:35 what you think we're really excited about figuring out what The Sweet Spot of this subject matter expert and engineer collaboration is and so we hope that this is a step in that direction let us know what you think