[0:00] Your company needs a chatbot on their [0:01] site where customers can ask questions. [0:04] The chatbot needs to store and retrieve [0:06] all chat history as well as company [0:08] knowledge base so that the agent can [0:10] help your customer. And you might be [0:11] wondering, how am I going to make this [0:12] happen? Maybe your first instinct is to [0:14] use OpenAI's SDK to write up a quick [0:16] software and create and simulate a chat. [0:19] But you soon realize that there's a huge [0:21] missing piece which is context. You [0:23] realize that you need to store these [0:24] chat messages somewhere and maintain [0:26] conversation history. And most [0:28] importantly, you need the agent to base [0:30] their answer from company's internal [0:32] knowledge base to answer questions [0:34] accordingly. Also, you're not so sure [0:36] that the company will later change from [0:38] OpenAI to a different model like [0:39] Anthropic or Gemini. And now all of a [0:42] sudden, this all seems like a massive [0:44] undertaking. Lang Chain is an [0:45] abstraction layer that helps you build [0:47] agents with minimal code. In other [0:49] words, all the pain points that we [0:51] identified earlier, Langchain gives you [0:52] the tools to address them using their [0:54] library. And you might be wondering at [0:56] this point, what's the difference [0:57] between an agent and an LLM? [0:59] Understanding agent is a critical piece [1:01] in knowing why Langchain is a necessary [1:04] tool for you to learn. When you use LLMs [1:06] like OpenAI GPT, Anthropex Claude, or [1:08] even Google's Gemini, you're using these [1:10] models out of the box, meaning the model [1:12] is rather like a static brain that [1:14] answers questions based on what it [1:16] learned during training. On the other [1:18] hand, an agent has full autonomy with [1:20] memory and tools to do whatever it [1:22] thinks it needs to get the job done. So [1:24] in the earlier case, let's say the [1:26] customer asked this question. What's [1:27] your company's policy on refunding my [1:29] product that arrived damaged? Now, [1:31] traditionally, you might code something [1:32] custom for this specific need. Now, with [1:34] agents, things look a little bit [1:36] different. An agent will have these [1:37] capabilities for them to perform. First, [1:40] ability to understand your intent using [1:42] an LLM. Two, ability to store a [1:44] company's knowledge base in a vector [1:45] database. Three, ability to perform [1:47] retrieval from vector database to find [1:49] relevant data. Four, ability to search [1:51] internal database to find what product [1:54] the customer actually ordered. Five, [1:56] ability to generate an answer based on [1:57] the product they ordered according to [1:59] the company's policy that we gathered. [2:01] And lastly, ability to know the chat [2:03] history with the memory. The biggest [2:05] difference between traditional software [2:07] and agentic software that you build [2:09] using lang chain is this. In traditional [2:11] software, these are typically programmed [2:13] to run sequentially or conditionally [2:15] based on code that determines how it's [2:17] run. In the case of Langchain, these are [2:19] rather developed in components and [2:21] provided to an agent for it to decide [2:23] how best to use its ability to deliver [2:25] the task. Thankfully, Langchain comes [2:27] with a large set of pre-built [2:29] components. In our earlier example, to [2:31] set up lane chain for your company's [2:33] chatbot, Langchain allows you to use [2:35] their existing tool that gives you [2:36] direct access to LLM providers like [2:39] OpenAI and Enthropic. This means that [2:41] setting up an API to OpenAI can easily [2:43] be done using a single line of code that [2:45] says LLM equals chat openAI instead of [2:48] writing your own implementation of API [2:50] connection or even using the provider [2:52] SDK tools which keeps you locked in and [2:54] difficult to switch in the future. So [2:56] later if the requirements change to use [2:58] anthropic instead of OpenAI, you simply [3:00] need to change the code to say LLM [3:02] equals chatanthropic open bracket quote [3:05] model equals cla 3 sonnet. A similar [3:08] process just like this applies to all [3:10] other abilities that we laid out [3:11] earlier. Meaning components that we [3:13] identified in what typically goes into [3:15] chatbots like memory, tools, MCP, vector [3:18] databases, rag, all of these can be set [3:20] up and configured using Langchain's [3:22] pre-built libraries. Now, there's an [3:24] extension of Langchain that helps you do [3:26] more workflow automation called [3:27] Langraph. And Langraph can interoperate [3:30] with Langchain, which is covered in the [3:32] next video just dedicated towards [3:33] Langraph for you to check out. So [3:35] similar to earlier when we had to write [3:37] code to manage API calls to LLM without [3:39] lang chain you would have to write your [3:41] own logic to convert your company's [3:43] document into semantic meaning through [3:44] text embedding store these embedding [3:46] into a vector database like pine cone or [3:48] chroma using their SDK implement your [3:50] own semantic search and then inject [3:52] these results into prompt at runtime and [3:54] on top of that managing state managing [3:56] memory managing tool writing logic as [3:58] you can see the scope of writing and [4:00] maintaining these can get out of hand [4:01] really fast thankfully for lang chain [4:04] inside lang chain's library. You can [4:06] import modules like Chroma for [4:07] components related to vector database, [4:09] OpenAI embedding for components related [4:11] to text embedding, conversation buffer [4:13] memory for components related to keeping [4:15] memory in chat. And there are so many [4:17] more components like this that help [4:19] alleviate development efforts that go [4:21] into building agentic software like [4:23] company chatbots that assist customer [4:25] with return policy. With agents becoming [4:27] the new way of building software, [4:29] learning how to develop agentic software [4:31] is becoming a critical skill set to have [4:33] and libraries like Langchain can help [4:34] your team drastically reduce development [4:37] time and accelerate your path to market [4:39] by using pre-built modules instead of [4:41] reinventing the wheel on tasks related [4:43] to building agentic software. Now that [4:45] we covered the conceptual elements of [4:47] Langchain, let's look at how it looks [4:49] like on a practical level. We can look [4:51] over at this lab specifically geared [4:53] towards how to use lang. All right, [4:55] let's start with the labs. In this lab, [4:57] we'll build our way up from installing [4:58] Langchain to deploying a fully [5:00] functional chatbot that combines memory, [5:03] knowledge retrieval, and multiple AI [5:05] models. Use the link in the description [5:07] below to access the lab environment to [5:09] follow along with me. The first question [5:11] presents us with this scenario. Our [5:12] company needs a chatbot, but we're [5:14] realizing that it's more complex than [5:16] just calling an API. We need to install [5:18] the complete langchain ecosystem. We [5:21] start by creating a workspace called [5:23] Langchain-lab. and setting up a Python [5:25] virtual environment to keep everything [5:27] isolated and clean. After upgrading our [5:29] package tools, we installed a core [5:31] langchain libraries that form the [5:33] backbone for building AI powered apps [5:35] along with LLM provider integrations [5:37] like OpenAI, Enthropic, and Google so we [5:40] can plug in different models easily. For [5:42] storage and retrieval, we'll use FISS or [5:45] Fias, which is the vector database used [5:47] for semantic search and embeddings. [5:49] We'll also install Python-Env [5:51] to manage environment variables [5:53] securely. And finally, Graddio to [5:55] quickly build interactive demos and user [5:57] interfaces. Next, we dive into prompt [6:00] templates, which are really the [6:01] foundation of Langchain. This shows how [6:03] prompt techniques work. You start with [6:05] templates like tell me about a certain [6:06] topic, fill in variables like topic [6:09] equals lang chain, and get the final [6:10] prompt, tell me about lang chain, ready [6:12] to send to the LLM. We have four example [6:15] templates here. We start with basic [6:16] templates that use variable [6:18] substitution. Think of them like Python [6:20] fst strings but for AI prompts. This [6:22] code shows how to use Langchain's prompt [6:24] template. First, we create a template [6:26] with placeholders for product and [6:28] feature. Then, we fill it with values [6:30] like lang chain and AI orchestration to [6:33] generate a marketing slogan prompt. [6:35] After that, we test it with different [6:36] examples, smartphone, electric car, AI [6:39] assistant. Each time replacing the [6:41] placeholders to produce new prompts. [6:43] Finally, it saves a small progress flag [6:45] in the file called basic-templates.txt. [6:49] Then we move to chat templates that [6:50] structure entire conversations with [6:52] system, human, and assistant messages. [6:55] This is how we maintain context and flow [6:57] in our chatbot conversations. The fshot [6:59] learning section is particularly [7:01] interesting. Here we're teaching the AI [7:03] through examples. We show it patterns [7:05] like happy to sad and tall to short and [7:08] it learns to apply this to new inputs. [7:10] The code demonstrates this beautifully [7:12] with a template that learns from [7:14] examples and applies the patterns to new [7:16] words. Take some time to explore the [7:18] advanced templates sections yourself. It [7:20] covers validation and structured outputs [7:23] that are essentially for production [7:24] applications. Make sure to create the [7:27] files and execute them using the given [7:29] commands before checking your work. [7:32] Now, we connect to multiple LLMs through [7:34] a unified interface. What's clever here [7:36] is we're using a proxy server that gives [7:39] us access to various models like OpenAI [7:41] compatible APIs. It's an API that looks [7:44] and behaves like OpenAI's API, but it [7:46] doesn't have to come directly from [7:47] OpenAI. This is where proxy server comes [7:50] in. It makes the other models like [7:52] Enthropic, Google, open source LLMs and [7:55] etc behave as if it was from OpenAI. We [7:58] start with a simple connection, then [8:00] explore how messages work in Langchain [8:02] using system message and human message [8:04] objects to structure our conversations. [8:06] The code shows us building conversation [8:08] history that the AI can reference. The [8:10] model configuration section demonstrates [8:12] something crucial which is temperature [8:14] control. Set it to zero for precise [8:16] consistent answers or higher for [8:19] creative responses. We create different [8:21] models instances for different purposes. [8:23] a fast model for simple tasks, a [8:26] reasoning model for complex logic, a [8:28] coding expert for programming questions. [8:30] The code even shows us how to enable [8:32] streaming for real-time responses. [8:34] Create the script files and execute [8:36] them. Once done, check your work and [8:38] move on to the next question. Here's [8:40] where it gets powerful. LCEL, the lang [8:43] chain expression language. It's a new [8:45] way of building and chaining components [8:47] in Langchain. Instead of writing long [8:49] complex code, LCAL lets you create [8:51] simple composable pipelines using pipe [8:54] operators. We chain components together [8:56] elegantly. With streaming first, you [8:58] don't have to wait for the whole answer. [9:00] The response starts flowing in [9:02] immediately. Async native means [9:04] everything runs without blocking, giving [9:05] you smoother and faster performance. [9:07] With batch processing, you can handle [9:09] multiple inputs at the same time, making [9:12] things more efficient. And type safety [9:14] ensures that all your inputs and outputs [9:16] follow the right structure so nothing [9:18] breaks unexpectedly. The code literally [9:20] shows prompt piping into model piping [9:22] into parser. It's clean, readable, and [9:25] makes complex workflows manageable. We [9:27] build a chain that takes a question, [9:29] formats it into a template, sends it to [9:31] a model, and parses the output allin-one [9:34] flowing pipeline. Here's what's [9:35] happening with LCL in that snippet. We [9:38] first define a model chat openai that [9:40] connects to GPT through a proxy. Then we [9:42] create a prompt template with a [9:44] placeholder question so that we can [9:45] reuse it for different inputs. Next, we [9:48] add a parser that converts the model's [9:50] output into plain string. Finally, using [9:52] LCL's pipe operator, we link these [9:55] components together. Prompt to model to [9:57] parser. There are other chains such as [9:59] parallel execution, dynamic routing, and [10:01] advanced LCL that I'll let you explore [10:03] by yourself. Create and execute the [10:05] script and check your work and proceed [10:07] to the next question. In lane chain, [10:09] memory is the system that keeps track of [10:11] conversation history, the context. It [10:13] stores past user inputs and AI responses [10:16] so that the model can give you answers [10:18] that feel natural, coherent, and [10:20] contextual just like a human would in an [10:22] ongoing conversation. For memory [10:23] systems, we implement in-memory chat [10:26] message history wrapped with runnable [10:28] with message history that maintains [10:30] context across interfaces. The example [10:32] demonstrates this perfectly. The AI [10:34] remembers that the user introduced [10:36] themselves as Alice and loves Python and [10:38] can recall this information later in the [10:40] conversation. This persistent context is [10:43] what makes conversations feel natural. [10:45] The rag implementation is where we [10:46] connect our chatbot to actual knowledge. [10:49] We load a document about lang chain [10:51] itself, split it into chunks, create [10:53] embeddings and store them in a vector [10:54] database. When user asks question, the [10:57] system retrieves relevant information [10:59] and generates informed responses. The [11:01] code shows the complete pipeline from [11:03] document loading to question answering. [11:05] By the way, if you haven't learned Rag [11:07] yet, check out the video we launched [11:09] last week on our YouTube channel. Okay, [11:11] finally, everything culminates in [11:12] deploying our chatbot. The lab has [11:14] prepared a complete application that [11:16] combines all these elements. When we run [11:18] it, it launches on port 7860 as a fully [11:22] functional chatbot with memory, [11:23] knowledge retrieval, and multimodel [11:26] support. What makes this powerful isn't [11:28] just the individual components. It's how [11:30] lang chain provides a coherent framework [11:32] for productionready AI application. [11:34] Without it, you'd be writing custom [11:36] implementation for custom memory, [11:38] building semantic search from scratch, [11:40] and managing complex model switching [11:42] logic. The beauty of Langchain is vendor [11:44] independence. If your company decides to [11:46] switch from OpenAI to Enthropic, it's a [11:48] oneline change instead of rewriting [11:50] everything. As you work through the lab, [11:52] experiment with different temperature [11:53] settings and model configurations. [11:55] You'll quickly develop an intuition for [11:57] when to use precise versus creative [11:59] models. For more in-depth courses and [12:01] hands-on labs, check out our AI learning [12:03] path on CodeCloud. Let us know what [12:05] you'd like to learn from us in the [12:06] comments below. And don't forget to [12:08] subscribe to our channel and to be [12:09] notified when we release new content.