Understanding LangChain
The current LangChain Python ecosystem is centered around a few important ideas: models, messages, prompts, tools, agents, retrieval/RAG, and orchestration. LangChain also provides a standard interface across model providers, which is one of its main benefits.
Learning path
I recommend this order:
- What LangChain is
- Calling an LLM through LangChain
- Messages
- Prompt templates
- Prompt + model chains
- Output parsing / structured output
- Conversation history
- Tools and tool calling
- Agents
- Retrieval and embeddings
- RAG
- Memory and state
- LangGraph basics
- Build a real project
Lesson 1 — Your first LangChain program
What is LangChain?
Think of it this way:
Without LangChain:
Your Python code → OpenAI API → Model → ResponseWith LangChain:
Your Python code
↓
LangChain
↓
Model
↓
ResponseLangChain gives you reusable abstractions around models and other components so you can later connect prompts, tools, retrieval systems, agents, etc.
For example, today’s LangChain documentation uses ChatOpenAI from the separate langchain-openai integration package for OpenAI chat models.
Step 1: Install LangChain
Create a Python environment and install:
pip install -U langchain langchain-openailangchain-openai is the integration package that provides ChatOpenAI.
You’ll also need an OPENAI_API_KEY environment variable.
For example:
export OPENAI_API_KEY="your_api_key_here"On Windows PowerShell:
$env:OPENAI_API_KEY="your_api_key_here"Step 2: Create your first LangChain model
from langchain_openai import ChatOpenAImodel = ChatOpenAI(model="gpt-5.4-mini")response = model.invoke("What is Python?")print(response.content)
That’s your first LangChain application.
What’s happening?
This line:
from langchain_openai import ChatOpenAIimports LangChain’s OpenAI chat-model integration.
Get md wasim’s stories in your inbox
Join Medium for free to get updates from this writer.
This:
model = ChatOpenAI(model="gpt-5.4-mini")creates a model object.
Think of model as:
model = "an object that knows how to communicate with the LLM"Then:
response = model.invoke("What is Python?")means:
Send this input → model → receive responseAnd:
print(response.content)gets the actual text from the response.
LangChain’s chat models accept messages or simple string input and return message objects rather than just raw strings.
The important concept
For now, remember just this:
Model
↓
invoke()
↓
ResponseFor example:
response = model.invoke("Hello")You can think of .invoke() as:
“Run this model with this input.”
You’ll see .invoke() repeatedly throughout LangChain.
One useful experiment
Change:
response = model.invoke("What is Python?")Your first mental model
Don’t worry about agents, chains, RAG, vectors, or LangGraph yet.
For now:
┌─────────────┐
Input ──────────►│ Model │
└──────┬──────┘
│
▼
ResponseThat’s the foundation.
Tiny exercise
Write a program that asks the model:
Explain ERP in simple terms for a beginner.using ChatOpenAI and .invoke().
Once you understand this, the next lesson will be Messages, where you’ll learn why LangChain has concepts like HumanMessage, SystemMessage, and AIMessage. That is the first concept that really starts making LangChain feel different from simply calling an LLM API.








