Introduction to LangChain
LangChain is a Python toolkit for building apps with AI models.
An AI model, like ChatGPT, is very smart but it only knows how to read text and write text.
LangChain gives that model hands.
With LangChain, the model can read your files, search the web, call your functions, and remember your chat.
A simple picture
Think of the AI model as a brilliant new employee who just walked in the door.
They can think and talk, but they do not know your company, your files, or your tools.
LangChain is the desk, the phone, the filing cabinet and the to-do list you give them.
It connects the brain to the real world.
What LangChain does for you
Talks to many AI providers (OpenAI, Anthropic, Google, free local models) with one style of code
Builds prompts from templates so you never glue strings by hand
Chains small steps together, like a recipe
Lets the model call tools and functions you write
Reads documents and finds the right part to answer a question (this is called RAG)
Remembers the conversation so the model does not forget what you said
Your first look at LangChain code
Here is the smallest possible LangChain program.
Do not worry about every word yet. Just see the shape.
Line 1 imports a helper.
Line 3 picks a model.
Line 5 sends a question and waits for the answer.
Line 6 prints the words the model wrote.
Why not just call the OpenAI API directly?
You can. For one question, that is fine.
Real apps are bigger. They need templates, memory, files, tools and error handling.
LangChain gives you those pieces ready made, and they all fit together.
Swapping models is one line. Change gpt-4o-mini to a free local model and the rest of your app stays the same.
What you will build in this course
You start by talking to a model.
Then you build prompts, chains and streaming answers.
Then you give the model tools and turn it into an agent.
Then you teach it to read your documents with RAG.
At the end you build a small tutor bot, like the Fox AI on this very website.
What you need to know first
You should know basic Python: variables, functions, lists and dictionaries.
If you do not, take the Python course first. It is short and friendly.
Tip: You do not need to pay to learn. Lesson 21 shows how to use free models on your own computer with Ollama.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.