 Yo Wiz, you heard about Langraph yet, my man? I have, yeah. I've heard something about it. It seems like it's all about cycles and chains, cycles and chains. What's the one sentence description of why we should care? description of why we should care? Well, it lets us build agentic workflows in a way that's agent forward, or agent focused. Agent forward, agent focused. Okay, okay. Okay. So, but then there's also open GPTs that came out super recently, too. And that's related to this Landgraf thing. Yeah, that's right. They leverage and build on top of Landgraf to help build these open gpts okay so it sounds like we're going even another layer more meta today then that's right we're going super meta dude awesome i love every time we abstract and I can't wait to get into this today. I'm gonna take the reins from you for now and introduce everybody to agent forward and agent focused. And this'll help us really understand how open GPTs are powered and how we can build with them super easily at the next layer of abstraction. Hi, everyone. I'm Dr. Greg. That's The Wiz. We're co-founders of AI Makerspace. And thanks for taking the time to join us for today's event. What you'll learn from today's session is exactly how Landgraf was sort of conceptualized, was sort of conceptualized, the problem it aims to solve, as well as how it sort of enables this agent-first, agent-forward, agent-focused application building. I'll cover the concepts, Wiz will be back for the code, and you know the drill. All right, let's get into it. Quick shout out though, Langchain just did some pretty sweet rebranding. So check out this awesome new logo with the old AI chained together. Shout out to Langchain, crushing it on the subtle details there. So let's align our aim for the day. We already mentioned it, but we're going to cover Landgraf. We're also going to understand through our coverage of Landgraf how it actually powers OpenGPTs through MessageGraph. And a lot of the stuff we're going to talk about with Landgraf isn't necessary to understand what MessageGraph is doing, especially if you've built anything with the OpenAI API or open AI assistance. However, it is useful to get the context. And this is what I'm here to provide today. The open GPTs are really sort of a low code solution that you can pick up off the shelf for free. And you can build chatbots, rag applications, as well as more complex assistance. Chris will show how to build all three today. So we'll cover Landgraf, then we'll cover OpenGPTs, and we'll build our own. All right. So Landgraf. Landgraf is all about adding cycles to applications built on Langchain. Okay, what does this mean? Right, what does this mean? Well, let's talk about cycles and chains. Previously, Langchain, before Langraph, sort of lacked this way to easily introduce cycles into chains. When we think of a cycle, we just want to think of sort of a more complex, more dynamic for loop, really. That's kind of what we're thinking about here. And so if you're familiar with agents and line chain already, for example, the agent executor, For example, the agent executor, that capability that's built in to the framework, that's actually been updated to be more agent first, agent forward, more cyclic in nature. Okay. And we'll kind of see that by the end. Because realistically, right, a chain is just a very, very simple one to the next to the next. Whereas if we're dealing with more of a cycle, then we want to be able to do more complex things. Now, you can do a lot with a chain. For instance, a lot of the most popular GPT is out there are just built on simple chains that have been prompted with a great system message. Prompt engineering can get you a very, very far way. For example, in the Langchain blog, they shout out character AI as being a very, very powerful way to leverage simple chains. But of course, as we get into more complex things, cycles become more important. So we want to connect LLMs to other sources of context. We want to sort of be able to add any additional information that we can find into the prompt, in the context that we can learn from. We want to be able to loop through. We want to be able to get an output, decide on a tool, make a decision about exactly what we should be doing next, and continue until we get the best possible output. Now, we've shown some agent stuff before and a way that we can sort of think about this is we kind of have this tool belt and the agent is kind of the brain. And we've shown this legendary meme before. It's still very useful way to sort of think about it as we kind of have this LLM brain pulling from different sort of think about it as we kind of have this LLM brain pulling from different sort of tooling. And this is kind of where we can start our journey today as we try to sort of fill in this space, this kind of wide space that exists between simple LLM calls and fully autonomous agents, because there's a number of distinct ways that we can engage with reasoning and with context between these two. Of course, in the extreme, when you're talking about biological things that actually exist in the real world, this term agents can mean something that sort of has a simple rule associated with it. And when you put many of them together, you can get this sort of emergence of this complex behavior. This is a quote from a book on complexity. Agents, for example, could be neurons, which form a brain, giving this sort of emergent structure at higher and higher levels. So this complexity that kind of emerges from these simple rules, from these sort of simple agentic behaviors is ultimately what we're aiming at. Now, another famous guy in the space that you've probably heard of, if you watch our channel, is Stephen Wolfram. very simple rules producing nothing less than extraordinary complicated behavior is something he's been studying his entire career. And it's really fascinating to kind of see how simple the rules can be and how much complexity can emerge, even within very, very constrained environments. And as we get into AI and agentic thinking, there's many different levels in which we could potentially see some sort of emergent behaviors. And so what are those levels? Well, again, going back to this idea that we have context and we have reasoning, this is where we're gonna have the most interesting LLM applications. And the different ways that we might combine context and reasoning are going to give way to the cognitive architectures. This is sort of a laying chain terminology that we might be able to leverage. OK, so if we sort of break this down, maybe there's five levels. So a single LLM call is the easiest, simplest level. Harrison covered this in a TED Talk that came out in December. I encourage everybody to give that a watch. It's only about eight or nine minutes, maybe 10 minutes or so. And beyond a single call, you can sort of string a few LLMs together, but still be focused on sort of one input, one output, kind of just running through the chain. Now, beyond that, it starts to get more interesting. For instance, using an LLM as a router, where it's going to choose which tool, which retriever, which prompt, you know, maybe even you have a list of prompts you might pick from, which one to use next. Now, if we want to sort of take the idea of just simple routing, right, you're sort of triaging as a 911 operator to this idea of a state machine, then here we can sort of say, you're not just using the LLM to route in some kind of loop, but you're also allowing for a state, a particular state to try to be reached. And this is going to be very, very important for enterprise because a lot of times they don't want fully autonomous AIs doing everything, but they might want to get an alert to the right human when a particular state is achieved from one of their applications now the fully autonomous agentic applications those are going to be fully human out of the loop and the framework that Langchain has sort of introduced here that I really like is kind of this idea that classic code right fully sort of static human operated code, we're deciding which outputs to, we're deciding what the output is of any given step. We're deciding which steps to then take based on that output was just taken. So this is sort of the classic if-else looping AI, right? And so now we're sort of introducing some additional reasoning into this that doesn't necessarily have to be hard-coded, making it a little bit more dynamic. So the simple LLM call, we're just sort of taking one step with the LLM and we're getting some output. When we have sort of a chain of LLMs, we're then sort of coming in and versus the human, we're just taking multiple steps with the large language model these are not very interesting it gets interesting when we start to get to routers and what a router is basically saying is it's saying hey after we get this llm output go over there and proceed to some next output. Go over there and do something and then stop. And that's very useful because you may want to go over there or go over there or go over there. Now, a state machine is sort of taking this to the next level and saying, go over there. And once you achieve this particular state X, then proceed. Okay. So here we're sort of adding an additional layer of complexity, an additional layer now of looping. This is sort of a place where we start to see the cyclic nature start to emerge, right? Before we're kind of doing things linearly, routing is sort of linear, but this idea of a state machine where we're sort of looking for a particular state, this is looping fundamentally. And of course, the fully going to be something that is kind of doing everything for the human. Now, this can be simply viewed by this diagram we've seen earlier, where the LLM is kind of the brain, right? The meme, remember, was simply the LLM being the brain of Batman. So the LLM is making all the decisions. And the easiest way to think about sort of the kind of meta super autonomous level is with this sort of two-step agent loop. And this is the kind of reasoning that is going to be baked into pretty much all the agentic tools you pick up. These steps are going to be just repeated over and over until a final response and output is generated. You're going to call the LLM. You're gonna determine what actions to take. Determine means sort of reason, or what response to give the user. So an action is gonna be associated with a particular tool. Generally, that tool is also gonna be associated with retrieving some information. And then we're going to take an action, retrieve information, send a call to a particular tool, get a response, do some additional reasoning, call the LLM to do that reasoning, and here we are back at step 1. We loop until we get the final output as discussed before. Now, this is the same loop that powers the core agent executor in Langchain. It's also the same loop that it's the same type of logic that we see in projects like AutoGPT. So this sort of agent logic is kind of fundamental. And so we want to think about it in this loop. So this sort of agent logic is kind of fundamental. And so we want to think about it in this loop. We want to think that given a user question, we're going to enter the loop. making an observation, taking action, making an observation, taking action, until we sort of are finished looping through all of the reasoning, action, steps, and we're like, okay, that's enough. I think I have the final answer. Ready to go to the output. The action and the corresponding observation here are each time added back into the prompt of the llm we call this in langchain the agent scratch pad okay and then the loop sort of resets with a different input that's made up of now the input plus the previous output and this sort of forms the basis for how Langraph is going to play with the underlying mechanisms that make OpenGPTs work. Okay. This is not new. These ideas are not new, but they are starting to mature. For instance, the modular reasoning, knowledge, and language system from AI, from AI-21 labs, the Markle aka Miracle paper came out May 2022. And this sort of agent cognitive architecture has been evolving ever since. We saw then the React paper, the reasoning action framework paper come out October 2022. And Langchain has since built in the zero-shot React agents. This is sort of the most general purpose tool where your general purpose agent, where you're selecting tools based on the description that you've given each tool. And you're just asking the LM to reason through based on what it sees from the given current output, which tool it should select next. And so what's currently implemented has kind of been expanded from that particular paper. And then of course, interestingly, auto GPT all about agents and their sort of highest level quote they raised $12 million with in November was to transform AutoGPT into the most significant open source project ever and unlock a new era of work for everyone. Sounds pretty epic. So that helped land them $12 million as well as being a ridiculously huge, popular open source project on agents. But again, Miracle, React, AutoGPT, these are sort of talking about this fully autonomous agent. And the thing that's interesting is that more control than these fully autonomous agent is, is often what's required. Because in practice, when we want to put agents into production, we don't want them to go off and do something crazy. For instance, we might want to hard code some of this stuff in. We might want to force an agent to call one tool always first. We might want to have control over the possible sequences in which tools can be called in general. Of course, we, as I discussed before, might want to have many different prompts for a single tool, and that's going to depend on the factors in our current loop. So when we talk about these more controlled flows, flows this is where the terminology that langchain uses for state machine is important because remember this is sort of that level between router and agent and so this is where we want to sort of go and look for a state before proceeding. All right, so this is this is sort of a way to integrate more control than simply the fully autonomous agent. Okay. All right. So what do we have then? Well, we have this sort of idea of Lang graph where we're simply creating cyclical graphs. simply creating cyclical graphs. Okay. What's another way to say that? Well, Landgraf is a way to create these state machines by specifying them as graphs. Okay. you tracking. So here's the first sort of structural component of Landgraf. Landgraf isn't that complicated, really at all. And what forms the basis of Landgraf is this state graph. It's the class that represents the graph. We can initialize it by passing in a definition of the state. And this definition is the object that we're updating over time, a.k.a. cycles, a.k.a. looping, right? So like at its core, Lang graph is really not all that complex. Now, of course, along with any graph representation, we're going to have nodes and edges. We can add nodes of various types. For instance, an end node is very important because we need to end our cycles at some point. important because we need to end our cycles at some point. And then we can also add edges, so starting edges within nodes. We can add normal edges, where these are sort of always going to be called. And then conditional edges, of course, are going to be a really key factor here because it's going to kind of depend. Well, which one are we going to next? So the interesting thing that's happening here is that with the langchain v0.1 that came out, they actually recreated the entire agent executor using this Lang graph setup. Because while we can still use it for the existing agent setup, the internals of how this thing operates in cycles is much more easily modified. And so what we're saying is we're saying that that internal state is more cyclic in nature less linear as a chain and so the chat agent executor is what connects this all back to open gpts and to things that we've seen in the past. The chat agent executor, of course, everybody's into having models tuned for chat, instruct tuned models also tuned for chat. And when we're doing a chat, we want to essentially use a list of messages, right? That's our state at any given time is the complete list of the conversation, right? All right. So this forms the basis for what we need to know so we can really grok open GPTs. Well, it turns out open GPTs not that hard. Open GPTs, they run on message graph, which is a particular type of graph in Lang graph and message graph uses message passing so check this out it takes in a list of messages and returns messages messages plural to append to the list this is cool because what happens is that at any given point, we just have a big list of messages, the conversation. All that can go back into the context window, right? It's more context for each step, just like chain of thought examples, right? Okay, so what's noteworthy about this besides the message passing? Well, first of all, message passing is sort of a common method for communication and distributed systems in general. Visualization of the work being done is much easier with this message graph and with Landgraf, of course. And this idea of a message list seems really, at least conceptually, extensible to multi-agent systems, right? Because each agent will just then append messages to the list of messages. Right? You know, getting pretty meta here. And it's also super related this message graph thing, by the way, to the chat completions model that we've seen many times from open AI. And then the sort of chat completions model structure is one that we start to see when we interact with a lot of different models, even open source ones on Hugging Face. And it's very, very related to the OpenAI Assistance API as well, which we've covered before and we'll go into real briefly just as an aside. But in the Assistance API, we're appending messages to threads, if you recall, if you've seen our agents and opening assistance API event before. The chat completions model is, of course, just the system user assistant setup, where we have a list of messages and they each have a role. And what we're gonna do is we're going to put in a list of messages on the front end of an LLM. We're gonna get out a single message and we're gonna then append that to the list of messages. So in list of messages, out single message, not many messages. So we're sort of extending this, right? And this is the similar thing to what OpenAI Assistance API did. They said, you know, an assistant is just something that maintains persistent threads and also calls tools. What's a thread? A thread is a conversation between an assistant and a user. So what we get is we get one system level prompt and then assistant user, assistant user, assistant user all the way down, right? So what we're doing is we're sort of storing this message history. And then notice, of course, if it gets too long for the context length, then we're making sure that we're doing something about that. So the assistance flow is to create an assistant, create a thread, add messages, run the assistant to trigger responses. That'll call the tools, that'll be added to the thread. Very similar things are happening in OpenGPT with laying graphs message graph that underlies it all. What we're able to build as a result is we're able to with Lang Graph's message graph that underlies it all. And so what we're able to build as a result is we're able to build assistants, rag bots and chat bots. Chat bots are prompt only. Rags are, of course, used when we want to combine our own data from some source. Now, rag bot on OpenGPT today means one retriever, and we're always going to use it. Assistants are more complex. You'll notice there's a number of different things we can use with assistants, and Chris will walk us through that here in just a moment. But the chatbot, again, it goes back to this very simple architecture. This is the one we're going to be kind of considering. We can mess with the prompt, but that's about it. The ragbot, we're going to use retrieval before we augment the prompt context and put it into the Lm and of course the assistant is going to allow us to be more autonomous and more agentic and it's going to allow us to be again more agent forward agent focused from the ground up architecturally the way the code has been written. We can put lots of tools in from archive to DuckDuckGo and many others that the Wiz will show us right now. Chris, over to you, man. Thank you, Greg. The basic idea here is we're just going to do a quick walkthrough of Langraph is we're just going to do a quick walkthrough of Landgraf to kind of, you know, figure out exactly what's going on here. And then we will move to looking at how those open GPTs will look and how they work. So we're going to start with the, you know, LCL plus cycles, very powerful framework. The idea is exactly as Greg said, right, is that we want to have this idea of, or we need to have this idea of looping, right? We need to have this idea that we can keep going through cycles. We don't have to, you know, just just go through one flow and then be done. Instead, we want to be able to go through one flow multiple times potential this and that, right? The idea basically that this comes from is, you know, loops are kind of naive, we, you know, they're hard to work with or extend or change. And this idea of creating cyclical graphs is a lot easier to understand, it's a lot more intuitive to work with. And we'll see that as we progress through the notebook. So again, why land graph, the big reason here is that, you know, we want that agent forward approach, we want the agent to be kind of at the center of this flow as opposed to kind of like an afterthought, right? When we do this looping strategy, what's really at the center of the experience there is that loop, right? And the agent can act in the loop and that's dope. But when we create these cyclical graphs that our agent can kind of navigate through, it's gonna lead to a more agent-forward solution. So we can think about the systems and create them more straightforwardly. We're going to grab a few dependencies to start today. Of course, we're going to need Langchain. Of course, we're going to need Langchain OpenAI and Langgraph. We're going to use two tools in this example, which is archive and DuckDuckGo search. These are two community tools that will leverage to do different kinds of search. And we'll see an example of how these are leveraged at the end of the notebook. Because we're going to be using open AI today, we need to provide our key and just kind of like tacked on, but not something that we should forget is the Langsmith integration, right. So not only do we have the kind of standard, you know, Langchain ecosystem changes with LCL and kind of async everywhere and all this stuff. We also have that easy Langsmith integration, which is going to help us add to that visibility in order to understand what our systems are doing, why and when. So that's great. The first thing we're gonna do when we're thinking about laying graph is we have to create some kind of tool belt, right? Likely what it is that we want our agent to do is make decisions about the text that receives and then apply certain tools in order to either answer questions better or have a better understanding of the user's query. And the way we create the tool belt should be fairly familiar. We have, you know, just a list of tools. There you go. Can't get more straightforward than that. And this idea is present in, you know, lang chain from before. So nothing new here. We're just going to pass on those tools and those tools are going to be what our agent or our lang graph will eventually leverage. Now, we do need some way to call those tools, right? It's great to have them, but we need some way to call them. And so we're going to use the tool executor to do that. And all we have to do here is use the prebuilt tool executor. here is use the pre-built tool executor. This is just a wrapper, basically. It's going to take a tool invoke class, and that's all we have to do. Next thing we're going to do, now that we have our tool belt, and we've kind of converted this to a format that makes sense, like our tool belt, we're going to set up our model. Now, you can choose any model here, right? It's Langchain. You can do whatever Langchain's got integrations with. You can choose, but you are going to set up our model now you can choose any model here right it's lang chain you can do whatever langchains got integrations with you can choose but you are going to see better results with quote unquote more powerful models or models that are better at reasoning right this is this idea of we want this kind of cognitive uh you know engine and that's going to be kind of our larger models that, that you can access through APIs. Another advantage of the API access is, of course, we can take advantage of the synchronous nature, you know, without worrying about scaling our own architecture. But, you know, that's a tangential benefit. The big idea here is we need something with enough brain power to reason well when it comes to these kinds of graphs. In the following example, we're going to be looking at something that does rely on function calling, which is not exclusive to OpenAI, but certainly is one of the benefits of OpenAI. If you want to use this exact example with a different model, you'll have to ensure that you're either making modifications to your tools to not use the function API, or function calling API, sorry, or you'll have to use a service that provides its own wrapper for that function calling API. Otherwise, we set up the model the same way we always would, right? And because we live in this world of langchain v0.1.x, right, we have the confidence that these are all runnables, right? And that runnables behave in a very specific way that's integrated very well with LCL. So we get some benefits to those, including that Langsmith integration, but also asynchronous capability. So you don't have to fret or worry about weird async errors coming up, which is great. Now, because we're using that function calling, we want to actually modify our tool belt a little bit, right? We want to modify it so that it's converted to an open AI function. All this is really doing is making sure that we have a smooth integration between the function calling API and our existing tool belt. You know, when you create a custom tool, which is a straightforward process, right? You can still use this helper function to convert to that kind of function calling tool. So you don't have to feel like you've got extra work to do. If you're using custom tools, this is still going to work for you, which is dope. Next up, we kind of want to get state involved, right? So Greg mentioned it many times. We're going to mention it many times all the time here. The core idea here is that we want to have potentially stateful applications. They don't have to be, right? But it is useful to have states so that we can understand the current situation of our application. I won't go into the big paragraphs here. You can read them as you go through the notebook. But the idea is that we have this stateful graph which is going to pass around this agent state. And that state is very similar to our scratch pad, but it's a bit more robust and more easily customizable. And all we're going to do is in this case, we're going to set up our agent state to be a dictionary, right, with the key messages and the value is just a sequence of messages. So all our state really is is an ever-growing list of messages that exist between the LLM and the user, right? You can see here just a quick example, right? When we start, we've got no messages. And then when we enter, we add one message. And then when it goes to a tool or it goes to a node, it's going to add some additional messages and on and on. This is all we're doing. And the way this is useful to us will become very clear in the next section here. And the way that we set this up is pretty straightforwardly. We're just going to base it off of type deck. And you'll notice here that we have this operator.add. That's because there's two different versions of state, right? We can have a set state where every time we overwrite our existing state or a parameter our state, and then we have add state, which is just kind of this ever-growing list that we're talking about. So now that we've got state, we've got our model, we've got some tools, we got to talk about graphs a little bit, right? We got your most basic graph here with some nodes and some edges. You know, this is a classic. All this is going to do is serve as a visual representation of what our application looks like. And one of the best parts of Landgraf is that they are easily composed into these visual representations to allow everyone to have clarity, you know, not just you as the engineer, but it makes it easy to describe to people how that system works in this kind of one-to-one flowchart method, which is super dope. When we're talking about nodes, we're talking about, you know, a function or an LCL runnable. So these are things that are going to do stuff. Which is super vague. But the idea is, right, we're going to provide information to these nodes and they're going to in some way transform that information. Or in this case, we're going to provide state, state object, and then it's going to move or modify state. Which is dope uh we also have this idea of edges edges are just kind of like paths we can take between nodes right we have a very special edge that we're going to talk about that greg's already touched on uh in a second but we're just going to start by first making some nodes uh we're going to make a call model node in a call tool node right the call model node we a call tool node, right? The call model node will call the model. That's crazy, I know. And then it will modify the state with the response of the model. And then our call tool is going to invoke our tool, get the response from the LLM, and it's going to modify our state to add the response from that tool call. Now, you'll notice we're using the asynchronous definitions here. This is because we can, right? Why not? I mean, LCL is fully integrated with asynchronous capabilities. So let's just start from the hop using async. So now we've got two nodes, right? Call model, call tool. What we're going to do is we're going to set up this state graph with our agent state. Remember, this is just a dictionary with key messages and then the ability to add messages into a list. So we're going to set up our state graph and then we're going to add two nodes to. Right? We're going to add the call model node as agent and the call tool node as action. And this is our graph right now, we have these two nodes, they're not connected, they don't do anything yet. So we have to we have to kind of, you know, complete the flow. So the first thing we're going to do is we're going to add an entry point. And we're going to set our entry point to be agent, right. And this is going to take our input, and it's going to move our input into our state object, and then it's going to pass that into our agent node. That's it, right? So this is our entry point. Next, we want to have the ability to call a tool when we need it and not call a tool if we don't need it. And so we're going to utilize this conditional edge. The conditional edge is kind of what it sounds like, right? It's an edge that's conditional on something. So in this case, we're going to check our state to see if it has a function call. If it doesn't have a function call, we're going to move to the end node. If it does have a function call, we're going to continue on that edge, right? So this is our conditional edge. And the way we add it is pretty straightforward. We're going to start or our source node or our origin node is going to be agent, right? So we're going to start at this green box. And then we're going to say, hey, move the state object through this function. And then depending on the output of this function, take one of two actions, right? And this is what we provide this mapping for. If we receive the continue response from our should continue conditional, then we're going to move to the action node. And if we receive an end response, we're going to move to the end node. And that's it, right? And the way we can express this is classic flowchart terminology. We can provide this agent. It's going to go to the should continue conditional edge. If we continue, if we get the continue flag from our function, we'll go to the action node. And if we get the end response from a function, we're going to go to the end node. Easy as that. Now, there's one more connection that's missing, right? Because we can get to action, but then when we're at action, how do we escape, right? So we have to add one more edge, and that edge is just always going to take us from action to agent, right? And so this is what we have here. So now we start at our input with our state object with nothing. We add the input message to that. We move it to the agent node based on the agent node's response, which is stored in that state object. We're either going to be done or we're going to move on to a tool. Once we get a response from the tool and we modify the state object to indicate we've got a response from the tool, we go straight back to the agent and we ask the question again. And we keep doing that, right? So this, I mean, you can see this is just a loop, right? We've got a cycle here, but we're able to have this loop or cycle be more expressive and we don't have to actually code a loop in, right? We just go to the next node, make a decision, go to the next node. We don't have any decisions to make here. We just go to this node, get response, make a decision, and then potentially go to end. That's the whole idea of laying graph. We're just constructing these graphs and these graphs are easily visualizable and help us to understand clearly what our system is capable of doing. Once we have it set up, we need to compile it. This is just kind of a classic step. This is going to make sure that all the inputs and outputs match up, that we haven't missed anything obvious, and it will raise alarm bells if you have. And it's going to be what lets us turn this into something that we're used to working with, which we're able to use just like it's a LCEL runnable, right? So we can just call a invoke on it and pass in our messages. This is our state dick, right? This is just the Pythonic representation of this dictionary that has key messages and then a list with a message in it, which is great. And we can call that and we can see, navigate through this whole list, that's great. Our input, we go to the AI message, the AI message is like, ah man, actually we gotta do a function call. Well, we know that this function call means we should continue. So we're gonna continue onto action. And we see that this action is a DuckDuckGoSearch, a function call. We know this function call means we should continue. We're going to continue on to action. We see this action is a DuckDuckGo search, which is huge. We get back this function message with some DuckDuckGo results. Finally, we have enough information to answer and we come to end since there is no additional quarks in this AI message. When we hit this conditional, we simply move to end. And that's it. That's the whole thing. We've got it written out here to make it more clear. And we do one more example. And in this example, you can see, you know, we both query DuckDuckGo and we query archive. We get a response. And then because we've got this response that clarifies information we needed previously, we make another function call to DuckDuckGo for the author's bio. And the query in question here is what is QLORA machine learning? Are there any papers that can help me understand? Once you have the information, can you look up the bio of the first author on the QLORA paper, right? So in order to do this last part, we need information from this previous part, and we can see that our LandGraph is able to navigate that. And again, we didn't set up any loops. We didn't set up any specifics of when it should end and how it should end. We just got it done through LandGraph. We let our agent be the thing that navigates that path for us. And it does a great job. So that's LandGraph. We let our agent be the thing that navigates that path for us. And it does a great job. So that's LandGraph. LandGraph is dope. But it is, I mean, you can see here, we're writing a lot of code. You know, we're having to do this whole, you know, code thing, care about async, all this other stuff. So wouldn't it be easier, right, if we had open GPTs? And we do have open gpt so it is easier uh and this is all all that we're gonna look at for the next few minutes is just you know how we use open gpts to actually spin them up is very straightforward so if you want to kind of go through this uh you know line by line start the back end that's great but they also provide everyone's favorite just docker right so you can just docker compose up as you see here and then you're gonna see this kind of beautiful ui that we see here so you'll notice a couple things about this ui it looks kind of similar to a different ui that we might have seen before. We'll just go to this one here, sorry. And that UI is the custom GPT UI from OpenAI, right? Once we're in here, we're able to do a couple things. First of all, we can start new chats. Second of all, and perhaps more interestingly, we can start new, or we can create new bots. So let's create a new bot. And let's look at the options that we have that Greg was talking to us about earlier. We have a simple chat bot, the simple chat bot. All it does is it's what you think, right? You give a text and it returns text from the LLM and on and on. We can modify its behavior through the use of an instruction, right? So in this case, one of the examples that we have is pirate bot. right? So in this case, one of the examples that we have is pirate bot. Basically, we just ask it to act like a pirate, right? And then it's able to do that. Now, that's obviously a kind of funny or, you know, toy problem. But the idea is that in order to do this, all you have to do is say, you're a helpful assistant, you speak like a pirate, right? Or whatever your use case happens to be. You have the GPT-5 Turbo. Select it as your LLM. You name your open GPT. You hit save. And then you can say, hey, what's up? You know, and we got it right there. And that's all we had to do. Just like OpenAI's custom GPTs, right? Very simple, straightforward process, which is awesome. Now, obviously, we can get a little bit more complex than that, right? So not only can we create simple chatbots, but we can also create a simple RAG chatbot. Basically, what this is going to let us do is it's going to let us add files here. So if we click add files, we can add, say, the book Frankenstein, right? And then we can say you're a helpful assistant. You speak like a Victorian scientist or, you know, whatever you need it to do. But the idea is, right, all we need to do is provide instructions of how we want this thing to behave, provide some data, and then we can select the engine that we want, and then we can just get this going. We click save, and then we can start interacting with it. And this is all we need to do. This is the whole process of creating, say, a simple rag. We can ask questions like, who was the monster in the novel? The monster in the creation of Victor Frankenstein, a being of gigantic blah, blah, blah, blah, blah, blah, blah, blah, blah, go on, man. The idea is that we can build these just like we would through OpenAI's custom GPTs. We get all the bells and whistles that we might expect, right? Where we can give this kind of feedback. And then in the final example, which is going to be our assistance example, we get something even cooler, right? We actually get tool confirmation. Tool confirmation is going to let us sit in the loop and decide if we should or shouldn't use tools, right? So this is super useful when it comes to helping people understand when we're using a tool, letting them be sure that they want to use the tool. And these kinds of, you know, human in the loop processes are going to help people really interact in an intelligent way with our system. Now, this assistant is the kind of closest thing to the actual custom GPT, right? Not only does it have access to a number of tools, including custom tools, which you can incorporate, if you're actually running this thing from the GitHub, and you've made some changes, or you've added some new tools, right, which again, is a is a more code solution, let's say, but it's still possible. But we also have the ability to, you know, have this extra kind of flavor or flair. We can connect all these fun tools and all these fun different cognitive engines. And again, in terms of the time to getting it going, right, we're able to build these tools very quickly. And that's the power of OpenGPTs, right? Beyond just, it's a cool framework. It also lets us build things very quickly in a customizable fashion. And it also helps get our, you know, gets the rest of our kind of stack involved, right? So we can have other people play with these tools and understand uh where they're best used and uh that's that's an incredible uh you know part of the feedback loop when you're creating these applications for a production environment so uh open gpt is super cool powered by our favorite land graph right so, right? So this is the behind the scenes, and this is kind of like the veneer, right? This is the top coat on that, which is pretty awesome. And with that, I'll pass you guys back to Greg, who will close us out for today. Yeah, thanks, Chris. That was an awesome walkthrough. Super detailed on both Landgraf and OpenGBTs. And just to sort of quick review here, Landgraf is all about adding cycles to applications built on Landchain. It allows us to create cyclical graphs and specifically it allows us to create these state machines by specifying them as graphs why state machines state machines because more control is generally desirable when we're actually building these applications in production for real companies than fully autonomous agents. Open GPTs, on the other hand, super easy to set up and use. Definitely highly recommend checking these out, especially if you just need to get a quick prototype with public data up and running. These can run on message graphs that are a special type of graph within Landgraf. They simply take in a list of messages and return a list of messages appended to the list. Now we have a new list of messages. It's not all that complex when you break it down. And so what we see today in the end is that Landgraf allows us to have these cycles, these loops, these states. It's an agent forward approach. And from the bottom up allows us to sort of do these things more intelligently. The message graph is very powerful and very straightforward, aligned with the other things we see in industry. And we can do assistance that are complex. We can do simple rag bots. We can do assistance that are complex. We can do simple rag bots. We can do chat bots. And with that, we'll go ahead and take any questions that you guys have. Wiz, I want to invite you back up here. And I want to kick it off with a question that I've been thinking about, which is like the old agent executor versus the new agent executor. agent executor versus the new agent executor? Like the old one was still able to do agents, right? But it wasn't sort of this agent forward thing. Like, is it a thing where it was kind of operating linearly and therefore was less compute efficient? Like what exactly is the difference between the old one and the new one? And how is it more performant in production environments? Muted. Sorry, I was muted. Sorry about that. I think what I would say is the idea of the old agent executor is great, right? But it's kind of inflexible. And we are stuck in that loop, right? Versus the Lang graph implementation or this new version, right? Where we're able to kind of let that reasoning body into this into this little box that we've created for it, but it can fully explore the paths within that box at its leisure, right? It's not just gonna say, hey, do this. And then, you know, if you're done, you're done, move on, right? Or if you're or if you're doing this, you know, you have to keep doing it until you until I get a response that I'm satisfied with, or whatever like this, right. But the idea is that by giving it that graph that it can navigate through at its own whim, right? If we want to really anthropomorphize the LLM here, we're going to have more flexible, more awesome behaviors. And we're also going to build that, you know, to Wolfram's point, we're also going to build that you know to wolfram's point we're also going to build that playground that we can have more emergent behaviors evolve right because it's going to be able to navigate through paths that uh that could change per iteration right uh or that could change per per call uh that the old style agent executor not necessarily wouldn't be able to do but boy it would be a bigger engineering effort to get it to do it and it would always kind of feel clunky and we're like we're trapped in the confine of that Loop right okay okay yeah yeah yeah so on each iteration we sort of have maximum flexibility to take the path of you know least resistance and optimal potential output, something like that. Okay, cool, cool, cool. So nice clarifying question here. Can you just clarify whether or not not open GPTs are using cycles for the chat bot and the rag bot, or are they only using cycles for the agent part? Great question here. So if we just have a chat bot, right, where all that happens is we provide a response and then the uh you know the the actual llm provides a response and so on and so forth we we view that as a cycle right uh we we have this idea that uh we are going to add state then the then the uh other actor is going to add state then we're going to add state then the other actor is going to add state, then we're gonna add state, then the other actor is gonna add state, right? We're kind of in this loop. Do we want to think of it as a cycle? It could be potentially useful. I think it's better though to abstract that into just turns in a conversation. But the OpenGPT for anything that does hit any kind of tool or has any decision, we would definitely wanna think of that as a potential cycle in our graph, yeah. Okay, okay. Yeah, we got a lot of questions coming in now. Unfortunately, we're gonna have to wrap up here soon. Another sort of clarifying question here. These are great questions from the audience. Can you talk about the difference between reasoning action, the REACT framework and LandGraphs. Is LandGraph also using this thought-action observation or is it just capable of using the thought-action observation? So we are still relying on a kind of observation reaction. This is the idea of the conditional edge kind of imparts that, right? So when we have that conditional edge, we're going to think about what's happened and then we're gonna make a determination on what the thought was, right? So if the LLM determines the, if the LLM determines that we need to use the the tool right we can consider that the thought and then our action will be the tool and that's why when we create the nodes what we do is we we actually you know have our agent node and then our action node uh where we we are trying to emulate this framework. Though it's a little bit more flexible and extendable, I think at the core, we can think of that piece of the system as existing within the React framework. Okay. Let's just rapid fire these three questions here real quick. Jacob asks, with looping through the tools, is it possible to get an infinite loop situation if conditions are continuously not beinging through the tools, is it possible to get an infinite loop situation if conditions are continuously not being met by the tools? Yeah, absolutely. Definitely. Yes. All right. All right. Yeah. Good stuff, Jacob. Forens asks, so is an agent the while loop of the LLM world? You end the loop on a given condition on the state? So with the graph example, it's like less cleanly that used to definitely be that, right? Like, so the old agent executor was, was basically a while loop, right? Just keep looping until you get, you either hit max iterations, right? Or you, you have the answer and we're satisfied and you say, Hey, stop, stop looping, bro. I think think this we can more think of this as like a a a a rat you know in a maze or or or navigating some complex maze right um as opposed to like a loop anyway rat in a maze not a loop for reds okay we'll pick that one up later uh openAI systems don't make use of webhooks. Super annoying. These OpenGPTs, do they make use of webhooks? I don't believe that they do by default, but they sure can be extended to if they don't already. I'd have to look into specifically how the Langsmith interaction works in order to answer that question super precisely. I don't think that out of the box, they do have web books though. If I'm wrong, I'll definitely post in the comments. But the beauty is that we have this ability to extend the OpenGPT framework because it's totally open source, right? It's not locked behind open AI servers. And so if you want to incorporate that, you are, I mean, do it. Right. Submit a PR, I'm sure they'd be happy. Yeah, yeah, yeah, yeah. Love it, love it. Great way to close it up. Yeah, go ahead and contribute if they don't have it. You know, maybe they should have it. Maybe you should build it. So awesome, Wiz. Thanks for the demo. Thanks for the Q and A. And it's about time to wrap up everybody. We're one minute over. So thanks for joining us today. Next week, we're going to be doing direct preference optimization and we've got a special event we're going to announce on Thursday. So definitely like and subscribe on YouTube if you haven't. So you can make sure you get those notifications. If you like this session and you're not in our discord community yet, we'd love to have you check out the AIM community. Come build, ship, and share with us today. And if you want to just tinker around with other stuff that we've done similar to this event, we're on YouTube live every week. You can check out everything in our AIM index. And of course, if you want to actually take a full-fledged certification course with us, we do have our AI engineering bootcamp. The next cohort is going to launch April 2nd, and this is a seven-week endeavor, very, very fast pace, but it's going to get you exactly where you need to be to build, ship, and share production LM applications in 2024. Finally, I want to announce, and we'll throw the link in here in just a moment, that we open sourced our most recent LLM Ops Cohort 1 course materials. So we open sourced our LLM Ops Cohort 1. It's not our most recent cohort, but it's our first ever cohort. That's fully open sourced on YouTube. It's available for everybody, all GitHub repos and everything is completely open. We'd love to get your feedback. So check that out. We'll throw the link in the description as well as on the comments if we don't get it in the live chat. So thanks for joining us today, everybody. Any feedback is always welcome. We love getting the feedback from you. So fill out a feedback form if you're still around. And as always, until next time, keep building, shipping and sharing, and we'll do the same. See you all soon.
LangGraph and OpenGPTs: Building Agent-Forward Applications with LangChain
GPT-4 Summary: Dive into the groundbreaking world of LangChain v0.1, LangGraph, and OpenGPTs in an event that's essential viewing for anyone interested in the cutting-edge of large language models (LLMs). Discover how LangGraph introduces cycles into applications for enhanced agentic Reasoning-Action frameworks, facilitating a loop of reasoning and action critical for building sophisticated agents. Learn about the power of OpenGPTs, running on the innovative MessageGraph for streamlined chat completions, and explore the creation of Chatbots, RAGBots, and Assistants with increasing complexity. Whether you're a learner eager to craft your own OpenGPTs, an AI Engineer seeking an introduction to LangGraph, or a practitioner passionate about the open-source forefront of LLMs, this event promises to equip you with the knowledge to build, ship, and share advanced AI agents. Don't miss our live code demo for a hands-on look at assembling a complex agentic Assistant!

Event page: https://lu.ma/langraphgpt

Have a question for a speaker? Drop them here: 
https://app.sli.do/event/kf9oC7MgvBb8eUnXfWSJJm

Speakers: 
Dr. Greg, Co-Founder & CEO
https://www.linkedin.com/in/gregloughane

The Wiz, Co-Founder & CTO
https://www.linkedin.com/in/csalexiuk/

Join our community to start building, shipping, and sharing with us today!
https://discord.gg/RzhvYvAwzA

Apply for our new AI Engineering Bootcamp on Maven today! 
https://bit.ly/AIEbootcamp

How'd we do? Share your feedback and suggestions for future events.
https://forms.gle/BHzb2tJL9ZLVP5Va6