LangGraph Crash Course 2026 | LangGraph Tutorial For Beginners | LangGraph Projects | Simplilearn
By Simplilearn
Summary
Topics Covered
- Langraph Ends Stateless AI Forgetting
- Langraph Masters Multi-Step Over Chains
- Visualize Graphs to Pinpoint Failures
- Start Small, Test Units, Subgraph Modularly
- State Checks Prevent Missing Data Crashes
Full Transcript
[music] Welcome to this exciting session on Langraph where we'll dive into how you can build powerful AI systems with memory and context and create intelligent applications that don't
forget the conversation. Langraph allows
you to create stateful workflows, meaning your AI systems can remember user interactions and adjust accordingly. Whether you're working on
accordingly. Whether you're working on chat bots, personal assistants, or any other kind of AI system, Langraph will help you create an intelligent and adaptable framework. In this session,
adaptable framework. In this session, we'll explore how Langraph works, why it's a great tool for AI development, and how you can start using it for your own projects. We will also touch on some
own projects. We will also touch on some real world applications, and share best practices for building efficient AI workflows. By the end of this tutorial,
workflows. By the end of this tutorial, you'll have a solid understanding of how to get started with Langraph and be ready to build your own projects. So,
here is the agenda. Here's what we will cover in this session. What is Langraph?
Where you can learn why it's a gamecher in the world of AI systems. Langraph versus Langchain. You can understand the
versus Langchain. You can understand the differences between Langraph and other popular frameworks like Langchain. How
Langraph works. Discover the core components, nodes, edges, and state, and how they work together to create intelligent AI workflows. Building your
first Langraph. Step-by-step guide to setting up your first Langraph project and creating your first memory enabled assistant. Advanced features. Learn how
assistant. Advanced features. Learn how
to handle decision making, conditional jumps, and multi-round conversations.
Integration with external tools. See how
Langraph works seamlessly with tools like Pine Cone and Hugging Phase to add extra capabilities to your AI projects.
Debugging and optimization, best practices for troubleshooting common errors and optimizing performance for smoother AI workflows. Before we dive into the technical details, I want to highlight an amazing course that will
help you build on these concepts. So,
let's pause for a quick quiz question to test your knowledge so far. Here's a
question. What do you think are the key components that make a Langraph workflow? Is it a nodes, edges, state, b
workflow? Is it a nodes, edges, state, b functions, loops, and variables? C data
process output, or d ar arrays, conditions, and loops. Take a moment to think about it. I'll give you the correct answer in just a bit. Let's kick
things off by understanding what langraph is and why it matters in the world of AI development. Imagine you're
speaking to a chatbot, asking it questions about your day or looking for some help. It responds quickly, but then
some help. It responds quickly, but then suddenly it forgets what you just said.
Sounds familiar, right? This is a common problem. Traditional chat bots or
problem. Traditional chat bots or assistants respond to a single query but lack the ability to maintain context across multiple interactions. This can
lead to confusing disjointed conversations that frustrate users. This
is where Langraph steps in. Graph is a framework designed to give your AI system memory. It's built around
system memory. It's built around stateful workflows meaning it helps your AI remember past interactions and adapt responses based on that information. If
you think of it like a GPS, Langraph helps your AI remember the route that it's taken, making it capable of adjusting its next steps based on what's happened earlier in the conversation. So
why does this matter? Let's look at real world use cases. Imagine an HR assistant that remembers a candidate detail through an interview process or a travel planner that remembers your preferences,
past trips, and budget for better suggestions. These are just a couple of
suggestions. These are just a couple of examples where Langraph's ability to keep track of conversations and adapt is essential. We shall now move on to lang
essential. We shall now move on to lang graph versus langchain. We'll also
mention lang chain briefly because it's another popular framework that's commonly used in AI. But langraph is different. Langraph is all about
different. Langraph is all about stateful interactions like map that tracks your entire journey. Lang chain
on the other hand is more like a set of tools that's chaining together different AI models. It's great for simple tasks,
AI models. It's great for simple tasks, but Langraph gives you more control over multi-step workflows and complex conversations. We shall now move on to
conversations. We shall now move on to debugging langraph applications. As you
dive deeper into Langraph, you will inevitably face challenges and errors.
Debugging is a vital part of software development and it's a skill that helps you understand how applications work, identify where things go wrong and find solutions. In this chapter, we'll
solutions. In this chapter, we'll explore common errors that you might encounter in Landraph and how to solve them and the best practices for troubleshooting and debugging your workflows effectively. So debugging is
workflows effectively. So debugging is the process of figuring out why something isn't working as expected and fixing it. Think of it like a detective
fixing it. Think of it like a detective job. Just like a detective looks for
job. Just like a detective looks for clues to solve a mystery, you need to track the flow of data, pinpoint where things went wrong, and figure out how to correct it. [snorts] This process helps
correct it. [snorts] This process helps you understand your application's behavior, find bugs, and improve its performance. When you're working with
performance. When you're working with Langraph, you may run into a situation where AI might not respond as expected, or a node might not be triggered properly. This is when debugging becomes
properly. This is when debugging becomes essential. Fortunately, Langraph
essential. Fortunately, Langraph provides various tools and strategies that makes this easier. Let's dive into some common errors that you will likely face and how to solve them effectively.
So, here are some of the common errors.
We shall now move on to visualization of your workflows for easier troubleshooting. As your LN graph
troubleshooting. As your LN graph workflows grows in complexity, it becomes increasingly important to visualize how data flows through your graph. Visualization helps you see how
graph. Visualization helps you see how nodes are connected and how data moves between them and where things might be going wrong. Langraph integrates with
going wrong. Langraph integrates with Langmith, a tool that helps you visualize your workflows and trace how data moves through your graph. This
graphical representation of your workflow makes it easier to identify issues and understand why certain nodes aren't executing as expected. Here's how
Langraph's workflow visualizations can help you debug. When you run your Lang graph application with Langsmith, you will be able to see each node and its state at each step. This allows you to track exactly what data is being
processed from one node to another. If a
node isn't executing correctly, you can click on it in the Langsmith visualization and see why. Did the
previous fail to pass the correct data.
This information helps you quickly identify where the problem lies.
Langsmith allows you to see the history of state changes as your graph runs.
This helps you pinpoint when and where the state is being modified and if there are any unexpected behaviors along the way. Here are some of the best practices
way. Here are some of the best practices for troubleshooting. Debugging can be a
for troubleshooting. Debugging can be a challenge, but there are several best practices that you can follow to make it easier and be more effective. So, you
need to start small and build up. When
you begin building a graph workflow, it's best to start with a simple minimal graph. Focus on getting one node or a
graph. Focus on getting one node or a task working perfectly before adding more complexity. Once you have a basic
more complexity. Once you have a basic graph, gradually add more tools and connections. By starting small and
connections. By starting small and building up, you reduce the chances of encountering overwhelming issues that are hard to debug. Secondly, use unit testing. Unit testing is a technique
testing. Unit testing is a technique where you test individual parts of your code in isolation. This means testing each node separately to ensure it behaves as expected before connecting it
to another node. This makes it easier to identify where things go wrong and helps you catch errors early. Then break down complex graphs into subgraphs. As your
workflow grows, it can get difficult to keep track of everything. To avoid
complexity, break down your workflows into subgraphs. Each sub should
into subgraphs. Each sub should represent a smaller, manageable part of your project. This modular approach
your project. This modular approach makes it easier to debug specific sections of your graph without having to sit through the entire workflow. For
example, if you're building a multi-step assistant, you could break it down into subgraphs like user authentication, user preferences, and user questions. This
will allow you to focus on one part at a time and troubleshoot more effectively.
Use logs for tracking data. Next, use
logs for tracing data. Logging in is your best friend when it comes to tracking down issues in your graph. By
adding logging statements in each node, you can track how data moves and what's happening at each step. This will help you spot where things go wrong and fix them quickly. So, finally, debugging
them quickly. So, finally, debugging Langraph applications doesn't have to be a daunting task. By understanding common errors, using tools like Lansmith for visualization workflows, and following
best practices like starting small and using unit tests, you can troubleshoot efficiently and keep your graph running smoothly. Remember, debugging is not
smoothly. Remember, debugging is not just about finding mistakes. It's about
improving your graph, optimizing performance, and making sure your AI is working as expected. The more you practice debugging, the better you will get at finding and solving issues quickly. Keep experimenting, testing,
quickly. Keep experimenting, testing, and refining your Langraph projects, and you'll soon be able to build more complex, reliable AI systems that remember context and interact intelligently with users. Debugging is a
skill that you will continue to refine.
And with these tools and strategies in hand, you're well equipped to handle anything that comes your way. So, we
will now start up with setting up your first LN graph project. In this section, we'll go through the installation process, setting up the environment, and finally creating your first LN graph project. So for the first step, you will
project. So for the first step, you will have to install Python and create a virtual environment. So before we begin,
virtual environment. So before we begin, ensure that you have Python 3.10 or the above installed on your system. If not,
head over to the official Python website and download the latest version. You
will also need to install PyCharm, which is one of the best integrated developments for Python. If you're
comfortable with another IDE, feel free to use that instead, but PyCharm makes the setup easier. So once you have installed Python, open your command line interface and create a new directory. So
yeah, the directory has been created.
Now we will create a virtual environment. Think of a virtual
environment. Think of a virtual environment as a sandbox where you can install Python libraries specific to your project without affecting the rest of your system. So to create a virtual environment, run this command. So with
this, we've activated the virtual environment. Now that's been done. Now
environment. Now that's been done. Now
that that has been completed, we will now activate the virtual environ. So on
Windows, you will use this particular code. So as you can see, we're within
code. So as you can see, we're within the Langraph environment. So this would be the code if you're operating on Mac OS or Linux. So now that we're within the environment and it's activated, you
will see langraph ends right before the command prompt as shown here. So this
indicates that you're working within the virtual environment. Now for the second
virtual environment. Now for the second step, install dependencies. Now we will have to install the necessary libraries.
Langraph relies on a few external libraries such as Langchain and OpenAI API. So in order to install them, run
API. So in order to install them, run the following commands in your terminal.
So I will be doing it here as follows.
The OpenAI API is required for generating AI responses which we will use to create a dynamic conversational system. We shall now move on to creating
system. We shall now move on to creating our first graph. We shall now move on to the third step which is creating your first graph. So here's what you're
first graph. So here's what you're supposed to do. Now that the environment has been set up, it's time to create your first LAN graph project. Let's
start with a simple hello world graph.
First create a file called hello world.
py in your project directory. So this
file will contain all the code for your first langraph. So open it and add the
first langraph. So open it and add the following code.
So finally here we are printing a result. For the last part we have
result. For the last part we have compiled and invoked the code here as seen. So I shall now explain the
seen. So I shall now explain the terminologies behind the code. So the
state class is created using this which is specifying that the state must contain a message key of type str. So
this ensures that the state passed around the graph is always following the structure. So for creating the node
structure. So for creating the node function, so the function hello world here takes the state as an input and returns a new state where the message is updated to hello world. So this function
defines the behavior of a node in the graph. Then for the third part which is
graph. Then for the third part which is creating a graph, a state graph object is instantiated using a state class as a template. This defines the structure of
template. This defines the structure of the graph and how the state flows through different nodes. For the fourth part, we have add nodes and edges. So
the hello world function here is assigned to the hello node in the graph.
The edges are defined to connect the graph's nodes where the process starts from the start node and goes to the hello and then from hello to the end establishing a flow of execution. Lastly
we have compile the graph. So the
compile method prepares the graph for execution ensuring that all nodes and edges are correctly set up. So it
generates an executable graph object that can be invoked. Finally we have invoke the graph. So the invoke method is called on the compile graph object by passing an initial state with an empty
message. So the graph is then executed
message. So the graph is then executed and the hello world node updates the state producing the result which is printed here. So as you can see when you
printed here. So as you can see when you run this file you should see the output hello world. So this is your first
hello world. So this is your first langraph working. We shall now move on
langraph working. We shall now move on to building an AI assistant using langraph. Now that you've set up your
langraph. Now that you've set up your first langraph, let's build a talking AI assistant using langraph. We're going to make a simple assistant that can remember your name and greet you. So the
key feature of any smart assistant is the memory. The assistant should be able
the memory. The assistant should be able to remember your name and refer back to it during a conversation. In Langraph,
memory is handled through state. We'll
modify the hello world function to ask for the user's name and store it in the state. So here we're inputting what is
state. So here we're inputting what is your name. Then we shall return username
your name. Then we shall return username as user name. So in this code, we ask the user for their name and store it in the state under the key username. Now
that we have the user's name stored in the state, let's create a second function that greets the user. So this
function uses the stored name from the state to greet the user by the name. For
the third step, we will link the functions. Now we need to link these two
functions. Now we need to link these two functions together into a workflow.
Langraph makes it easy to link nodes by running them in the sequence. So I have attached a cleaner code over here in place of the previous one. So what you
will have to do is we will go ahead and run the code. So here it asks you what is your name. So let's just say I type
in my name as Alice. Here you get the output as hello Alice. So when you're running the code, the assistant will ask for your name, store it, and then greet you. It's simple, but this forms the
you. It's simple, but this forms the foundation of any conversational AI system that remembers context. So in
order to make our assistant smarter, we need in order to make our assistant smarter, we need to add stateful logic and conditional jumps. These concepts
allow the assistant to make decisions based on user input and maintain memory across different stages of conversation.
So for the first step which is conditional logic for decisions. Let's
say the assistant needs to ask the user if they want to continue the conversation or not. So depending on the user's response, the assistant should either continue chatting or end the conversation. So this is where
conversation. So this is where conditional logic comes in. We'll create
a function that asks the user if they want to continue. So here I will type in do you want continue the converation
and then within brackets yes or no.
Added a fresh code over here. So if the user types yes the function will return true otherwise it will return false. So
let's just say I type my name here as Alice. Wait. So let's start here. We
Alice. Wait. So let's start here. We
have to type in your name again. So here
you get an option where they're asking you do you want to continue the conversation yes or no. So here you can type yes or no. I will go for yes. So as
you can tell when I type the line it return the same conversation again. But
when I type no it says goodbye Alice.
See you later. So by that we can tell if the user types yes the function will return true otherwise it returns. So
once you type Alice it says hello Alice.
Do you want to continue the conversation where I say yes? Let's just say I say no. It says goodbye Alice. See you
no. It says goodbye Alice. See you
later. Okay, that's all. Anyways, for
the next step, we will move on to handle the decision. Now, we will create a
the decision. Now, we will create a function that makes a decision based on the user's input. So, if the user wants to continue, the assistant will greet them again. Otherwise, it will say
them again. Otherwise, it will say goodbye. So, whatever I told just now,
goodbye. So, whatever I told just now, please place it before whatever I executed here. For the third step, link
executed here. For the third step, link everything together. Now that we have
everything together. Now that we have three functions, one to ask for the user's name, one to greet the user, and one to handle the continuation of the conversation, we link them all into the
single graph as shown over here already.
So this simple decision-m capability makes your assistant feel more dynamic and interactive. We shall now move on to
and interactive. We shall now move on to integrating tools like Langraph, Langchain, Pine Cone, and Hugging Face.
At this point, we've built a basic assistant that remembers user input and make decisions based on that input. But
what if you give it more power like searching through documents and providing answers? That's where tools
providing answers? That's where tools like Pine Corn and Hugging Face come into play. Pine is a vector database
into play. Pine is a vector database that allows us to efficiently store and search through large data sets. Hugging
provides state-of-the-art machine learning models that can perform a wide variety of tasks like text generation and question answering. So let's start by integrating Pine Cone into our
project. First, we will need to install
project. First, we will need to install the Pine Cone client. So for that we will have to move into our terminal here and type pip install pine cone client.
Once it's installed we can initialize pine cone and create an index for our documents. So for this move on to your
documents. So for this move on to your IDE again it'll open a new file. So what
you will have to do is now that pine cone has been installed import pine cone. So as you can see we have searched
cone. So as you can see we have searched the documents and for relevant documents based on a user query which I will type it out here. So this function queries the python index and returns the most
relevant document. Then we move on to
relevant document. Then we move on to integrating hugging face. Next we can integrate hugging face to generate intelligent responses. So first you'll
intelligent responses. So first you'll need to install the hugging face transformers library. So I will do that
transformers library. So I will do that over here. Move into your terminal and
over here. Move into your terminal and type pip install transformers. Then we
can use hugging face models to generate answers based on the documents returned from pine cone. So while this is being installed I will just type the code. So
here we have the code. So in this code we will use a question answering model from hugging face to find answers based on the context retrieved from pine cone.
So this enables your assistant to answer the questions by searching through large data sets. We shall now move on to some
data sets. We shall now move on to some common errors that we encounter and how we can solve them. So for the first one we have missing or incorrect states. So
one of the most common errors that you will face in lang graph is a missing state error. So this happens when your
state error. So this happens when your graph tries to access information in the state that hasn't been initialized yet or doesn't exist. So in other words, you're trying to use data that hasn't been provided. For example, imagine that
been provided. For example, imagine that you have a node that's trying to access this particular line of code, but the user hasn't provided their name yet. So
the error will happen because the langraph is expecting a piece of data that isn't in the state. So this results in the application failing unexpectedly.
To prevent this from happening, you should ensure that the state is properly initialized before you attempt to access any data within it. So one way to handle this is by checking whether the state actually contains the required data.
Here's an example of how you can handle this situation effectively. So we have this line of code over here. So in this example, if the state does not contain username, the bot will ask the user to
provide it. This prevents the bot from
provide it. This prevents the bot from breaking and ensures that it operates smoothly even if the data is missing.
For the next part, we have empty or invalid inputs. So another common issue
invalid inputs. So another common issue arises when a node is expecting an input, but the input is either empty or invalid. So for example, you might ask
invalid. So for example, you might ask the user to provide their age or preference, but they enter nothing or it's an invalid value like a negative number. So when the input does not meet
number. So when the input does not meet the expected format or it contains unexpected data, your system can crash or the behavior might not make sense. To
solve this issue, you can validate the input before passing it to the next.
This ensures that the data is both correct and usable. So here's how you can handle invalid input such as asking for the user's age. So this line of code will help you do the same wherein in
this example, if we check the age, it is a positive integer. If not, we prompt the user to enter a valid value. This
validation step helps you ensure that the system doesn't crash or produce incorrect results. Thirdly, we have
incorrect results. Thirdly, we have unreachable nodes. Sometimes when
unreachable nodes. Sometimes when setting up your LAN graph workflow, you might notice that certain nodes never get executed because the flow of the graph is incorrect. So in other words, the edges between the nodes don't work
as expected and some nodes are actually left out of the process entirely. So
here as you can see, if your decision-m logic like if or else statement is set up improperly, it may prevent nodes from being triggered. So if the node is
being triggered. So if the node is unreachable, it means that there is some flaw in the graph or how it is structured or how the flow is controlled. Here's how you can solve it.
controlled. Here's how you can solve it.
To fix this, you need to carefully check your node connections and ensure that the logic controlling the flow is set up properly. So if you're using decision-m
properly. So if you're using decision-m logic, ensure that all potential conditions are covered. So here is an example where we set up a simple decision point in the graph. So it's
mentioned over here. So in this case, the flow depends on the response. So as
you can see in this case, if the response contains yes, the graph proceeds otherwise it stops. So double
check the conditions and the edges to ensure that all nodes are reachable and executed in the correct order. Thank you
so much for joining today's session on Langraph. We've covered a lot of ground
Langraph. We've covered a lot of ground from setting up your first Langraph project to learning how to create intelligent memory powered AI systems. Now it's time to apply what you've learned and start building on your own.
Let us know how you plan to use Langraph in your projects or if you have any questions feel free to ask. And of
course, don't forget to subscribe to our SimplyLearns channel so you can stay uptodate on all our latest content on AI, machine learning, and much more.
Keep experimenting, building, and learning. And I look forward to seeing
learning. And I look forward to seeing what you've created with Langraph. Happy
coding.
Loading video analysis...