The Need for LLM Frameworks
When you start learning about agentic AI frameworks, you come across so many terms that it's easy to get confused. In this video, I will make an attempt to give a very simple explanation of the difference between these three. So let's start with the basics.
When you take any LLM, GPT, etc., it is trained on some huge volume of internet data. So if you ask a general question like this, it will be able to answer. But let's say you have this clothing store called Surma E-commerce for which you're building a chatbot which is powered by LLM, and if you ask a question, "What is a refund policy on t-shirt?" it won't be able to answer it because it doesn't have access to your private organizational data.
To solve this problem you build a RAG chatbot which is retrieval augmented generation where you provide your policy documents to LLM and it will be able to then fetch the answer out of those documents. So here step by step what you're doing is you are first retrieving the documents, then you're splitting it into chunks to take care of the context window for LLM, then you store it in a vector database for semantic search later on. Then you retrieve and call LLM and so on.
Now you can do all of this in Python but LangChain is a beautiful framework that makes these things easier by providing readymade classes. So for this, it will have text loader. These are all the classes from LangChain library.
Workflows vs. Agents
If you categorize LLM powered application into two groups then those two groups as per Anthropic's building effective agent guide are workflows and agents.
LangChain for Simple Workflows
Workflows is basically a software where one of the component is LLM and remaining things are joined by a predefined core path just like any usual software. So let's say you might be loading data from somewhere. Then you're doing some pre-processing and then you use LLM let's say to extract information out of that text or to do something else. Okay.
Then you have one other step. Then you might have another LLM call. So this is like a usual software. It is just that LLM is one or more component in in that software ecosystem.
The Scope of LangChain
This kind of thing is called chain and LangChain is a framework that makes building LLM powered application easy. Especially it is used mainly to build straightforward chains whatever we saw. So there are steps that you follow to build your application and one of the step is LLM. So here LLM is not making any autonomous decision. It is given a predefined task that okay from this text extract this information or summarize this information and remaining thing is all your Python or whatever programming language you're using is just code. Okay.
The Challenge of Complex Chatbots
Now let's say you want to build a complex chatbot where customer is asking I want to exchange my t-shirt for a different item and you will then ask for order ID. Right? This is not something you can just answer in one shot. Then they will provide order ID. Now you'll say okay now with which item you want to replace. So they provide SKU and there is some interaction, there is some kind of a multi-turn approach here.
To summarize the steps, you have to check first the refund policy for the item that they are returning, then you check order details in the database to make sure that you know the item is eligible and what was the price and so on. Then you check availability of the new item, order new item, print shipping label for old item. So this is not like a simple question okay what is my refund policy? 30 days. This requires multiple steps, multiple clarification, it's a complex flow. And in each of the flow for refund policy you might have to access your policy documents for checking order details you might have to hit some database for checking availability of a new item you might be calling some microservice some API and to print label or you might be using some other software and in each of these steps LLM will be involved. Okay.
So, LLM either in all the steps or some of the steps LLM will be there and along with LLM you have documents, database, API etc. which will help you perform all these tasks.
What is an Agentic Chatbot?
So, you are essentially doing goal oriented planning for a return that customer want to perform in the exchange of a new item. You first figure out all these four steps. Then you do multi-step reasoning, multi-step planning. You perform these steps one by one. Now let's say some of the steps might fail. Okay. So check the availability of new item. Let's say it fails. You might have to hit different API, different color, something something like that. You know then you have access to tools, right? These are tools. Knowledge, knowledge is all PDF and database knowledge. API etc. are called tools. All right.
So this is an agentic chatbot. Agentic chatbot works on a complex task. It will divide it into multiple subtasks. Then it will perform them one by one. Let's say second step fails. It will retry it. Okay. So there is a component of retry, feedback, etc. Just like how as humans we do the work. Let's say you are doing coding. You run the code, you find an error, then you fix the error, you know, you again run the code, then you find let's say another issue, then you fix that. So it's an iterative approach. Agentic chatbot has some kind of autonomy and it will do this kind of multi-step iterative approach to accomplish a goal.
Introducing LangGraph for Building Agents
Now one of the popular design for building agentic application is graph based stateful workflow. What I mean by that is let's say you start somewhere and you are making an LLM call. Okay. And then LLM will decide what to do as a next step. So let's say there is some conditional logic and LLM might decide to perform step A or step B or it might decide to make another call to a different LLM and same way when you're here this LLM can also autonomously, I mean there will be some kind of prompt that will be given but the actual decision is made by this LLM in autonomous way it can perform either step C, D, E etc or it can actually call back to the original LLM. So there are four possible core paths. So this is a stateful workflow represented as a graph and LangGraph is a framework to orchestrate multi-step stateful workflows using graph-based structure.
LangGraph in Practice: A Code Example
Here I'm showing you a code of one of the graphs we built in LangGraph. So you import all these libraries. Okay. And then you have this tool. So tool is a dummy python tool. It just gets the latest price of any stock, Microsoft, Apple etc. And then you design the graph like this. So if I show you the graph is nothing but you start, then there's a chatbot and as a tool you have that function, the, you know, get stock price function. Okay.
So when you perform all these steps, eventually when you say I want to buy 20 Amazon stocks, it will be able to call that function, get the price and then, you know, it's performing those steps to kind of call the tool multiple times and then give you a total amount for your entire stock transaction. If you want to learn LangGraph in detail then I have this tutorial. It's like more than 1 hour tutorial which will walk you through the entire framework from the very beginning.
LangChain vs. LangGraph: Key Differences
Let's summarize the difference between these two. So LangChain is a toolkit that allows you to build LLM apps, chains, tools, agents. Whereas LangGraph is a framework that is used mainly for agents. So just remember if you are writing a simple linear workflows you use LangChain but if you want to build complex agents use LangGraph. Style for LangChain is linear and reactive. Reactive means like you give some task it will return the response, okay, input output whereas LangGraph has a graph base supports, it supports loops, retries, you know, it will retry to fix the error and kind of get the thing done. It also has a memory base.
Use case for LangChain is simple chatbot, RAG, etc. LangGraph is as I said multi-step workflows, complex agents, and LangChain is partially stateful where LangGraph has a state in that graph. So if you refer to my LangGraph tutorial, you will get better understanding just in case if you don't know about graphs and states. And here are the example use cases.
LangSmith: Debugging and Observability
Now what is LangSmith? Well, LangSmith is a debugging and observability platform folks. So if you look at the architecture, see this is an entire like ecosystem where you have LangChain and LangGraph, they both are open source. Okay. Then you have LangSmith which is doing the work of debugging, playground, prompt management, monitoring, you know, so let's say if you deploy the agentic system in the production you want to monitor whether it's performing well, you want to monitor your token cost, okay, it's not like you're spending millions of dollars in your token cost. So all of those failures, evaluation, all of those things are done through LangSmith.
So here is a LangSmith UI where there's this demo app and really here you can see all the individual calls right. You called vector database then you called chat GPT, okay, what was the input, what was the output, how many tokens did you use? 390. What was the latency? So you can monitor all of that. This is just tracing but you can do much more than this. If you want to learn these things in detail once again I have complete tutorials. If you have any questions please post in the comment box below. I hope you got some understanding of LangChain, LangGraph and LangSmith. If you like this video, give it a thumbs up and share it with your friends.