Module 1: Models and Providers
Introduction: The Modern LangChain Ecosystem
Overview
LangChain is the most widely adopted framework for building LLM applications. But "LangChain" is no longer a single package — it's an ecosystem of tools that spans everything from connecting to a model to orchestrating multi-agent systems in production.
In this capsule you're going to understand how each piece of the ecosystem fits together, which packages you need to install, and how to set up your environment to work with LangChain v1.2+. By the end, you'll have everything ready to start writing code in the next capsule.
Where are we in the guide?
This is Module 1 of the guide LangChain & LangGraph: From Chains to Agents. It's the starting point: before creating agents, tools, or workflows, you need to master the most fundamental piece — connecting to language models and running them.
The guide has 4 progressive blocks:
Block 1: LangChain Core (Modules 1-4) ← YOU ARE HERE
Block 2: LangGraph Fundamentals (Modules 5-7)
Block 3: Advanced LangGraph (Modules 8-10)
Block 4: Production (Modules 11-12)
Everything you build in later modules — tools, agents, workflows, multi-agent — depends on knowing how to initialize models, run them, and get structured responses back. This module gives you that foundation.
The LangChain ecosystem in 2026
LangChain is no longer a single monolithic package. Since version 1.0 (October 2025), the ecosystem reorganized into clear components with defined responsibilities.
The 3 levels of abstraction
┌────────────────────────────────────────────────┐
│ Deep Agents │
│ "Batteries-included" │
│ Planning, subagents, filesystem, memory │
│ → For long-running autonomous agents │
├────────────────────────────────────────────────┤
│ LangChain (create_agent + Middleware) │
│ "High level" │
│ Agents in <10 lines, tools, middleware │
│ → For 80% of use cases │
├────────────────────────────────────────────────┤
│ LangGraph (StateGraph + Functional API) │
│ "Low level" │
│ Graphs, nodes, edges, custom workflows │
│ → For total control of the execution flow │
└────────────────────────────────────────────────┘
LangSmith rounds it out as the observability platform: tracing, debugging and evaluation for everything you build with the levels above.
When do you use each level?
- LangGraph (low level): When you need total control over the flow — deciding exactly which node runs what, when to loop, when to pause. Think of an orchestra conductor controlling every instrument.
- LangChain (high level): When you want a working agent in a handful of lines.
create_agentgives you 80% of what you need without touching graphs. Think of using an app — it works without you understanding the internals. - Deep Agents (batteries-included): When you need an agent that plans its own steps, creates files, and delegates to sub-agents. Think of a senior employee who takes a task and carries it through from start to finish.
You don't need to understand all 3 levels right now — you'll grow into them module by module. But it's useful to know they exist so you have the full mental map.
How do they connect to each other?
Your code
│
▼
init_chat_model("openai:gpt-4.1") ← Module 1: connect to models
│
▼
model.bind_tools([search, calc]) ← Module 2: add tools
│
▼
create_agent(model, tools) ← Module 3: create an autonomous agent
│
▼
@wrap_model_call + middleware ← Module 4: intercept and customize
│
▼
StateGraph / @entrypoint ← Modules 5-7: workflows as graphs
│
▼
Checkpointing + HITL + Multi-Agent ← Modules 8-10: advanced production
│
▼
Deep Agents + LangSmith ← Modules 11-12: autonomy and observability
Each module builds on the previous one. What you learn here — initializing models and running them — is the foundation of everything else.
Package architecture
The modern ecosystem splits into packages with clear responsibilities:
| Package | What it contains | When you use it |
|---|---|---|
langchain-core | Base interfaces (BaseChatModel, BaseMessage, Runnable) | Always — everything depends on it |
langchain | init_chat_model, create_agent, middleware system | When you build agents and applications |
langchain-openai | ChatOpenAI, OpenAIEmbeddings | If you use OpenAI models |
langchain-anthropic | ChatAnthropic | If you use Anthropic models |
langchain-google-genai | ChatGoogleGenerativeAI | If you use Google models |
langchain-ollama | ChatOllama | If you use local models with Ollama |
langgraph | StateGraph, Functional API, checkpointing | When you need workflows as graphs |
langsmith | SDK for tracing and evaluation | When you monitor in production |
The key idea: instead of one giant package that installs everything, you only install what you need. If you use OpenAI and Anthropic, you install langchain, langchain-openai and langchain-anthropic.
Analogy: Think of a LEGO set. langchain-core is the base plate everything else mounts onto. langchain is the main set of building bricks. The provider packages (langchain-openai, etc.) are themed kits you add depending on what you want to build. You don't buy every kit — just the ones you need.
Why v1.2+ and not legacy?
If you search for LangChain tutorials online, you'll find a lot of code using APIs that are no longer recommended:
| Legacy API (pre-v1.0) | Modern API (v1.2+) |
|---|---|
LLMChain | model.invoke() |
SequentialChain | chain1 | chain2 (pipe) |
AgentExecutor | create_agent() |
ConversationChain | Agent + memory |
from langchain.llms import OpenAI | init_chat_model("openai:gpt-4.1") |
This guide teaches modern APIs exclusively — the ones you'll use in production and the ones with active support. In Capsule 07 we include a full legacy → modern mapping so you can translate any older tutorial.
Why does it matter? If you learn with legacy APIs, you'll have to relearn when you move to production. If you learn with modern APIs from the start, your code is production-ready on day one. On top of that, the modern APIs are simpler — init_chat_model("openai:gpt-4.1") replaces 5-10 lines of imports and manual configuration.
What you'll master in this module
By the end of the 8 capsules in this module, you'll be able to:
- ✅ Initialize models from any provider with
init_chat_model - ✅ Configure parameters like temperature, max_tokens, timeout and retries
- ✅ Run models with the 3 fundamental modes: invoke, stream and batch
- ✅ Get structured responses with Pydantic, TypedDict and JSON Schema
- ✅ Process multimodal content (images, audio, video)
- ✅ Set up local models, caching and rate limiting for production
Module map
| Capsule | Topic | What you'll learn |
|---|---|---|
| 02 | init_chat_model and providers | Initialize models from OpenAI, Anthropic, Google and Ollama with a single function |
| 03 | Parameters and configuration | temperature, max_tokens, timeout, retries, models configurable at runtime |
| 04 | Invoke, Stream and Batch | The 3 execution modes: full response, progressive tokens, parallel processing |
| 05 | Structured Output | Get typed responses (Pydantic, TypedDict, JSON Schema) instead of free-form text |
| 06 | Multimodal and Reasoning | Process images/audio/video, surface the model's reasoning steps |
| 07 | Local models, caching and rate limiting | Ollama, prompt caching, InMemoryRateLimiter, legacy → modern API mapping |
| 08 | Project: Multi-provider chat | A chat system with automatic fallback between providers, streaming and metadata |
Learning flow: First you'll learn to connect to models (02). Then to tune them finely (03). Then to run them in 3 different ways (04). With that down, you'll move on to structured responses (05), multimodal content (06), and production optimization (07). At the end, you'll bring it all together in a working mini-project (08).
Connection to the project
This module's mini-project: Multi-Provider Chat with Fallback
In Capsule 08 you'll build a chat system that:
- Connects to 3 providers (OpenAI, Anthropic, Google)
- Implements automatic fallback — if one provider fails, it moves to the next
- Shows responses with streaming (progressive tokens)
- Returns structured metadata (which provider answered, latency, tokens used)
Every concept you learn in capsules 02-07 applies directly to this project.
Connection to the full guide
The models you configure here are the foundation of everything coming next:
- Module 2: You'll add tools to them (functions the model can call)
- Module 3: You'll turn them into autonomous agents with
create_agent - Module 4: You'll intercept their calls with the middleware system
- Modules 5-12: You'll orchestrate them in workflows, graphs and multi-agent systems
Boundaries: what this module does NOT cover
- ❌ Tools and tool calling — Covered in Module 2
- ❌ Agents (create_agent) — Covered in Module 3
- ❌ RAG (Retrieval-Augmented Generation) — Covered in the Advanced RAG Techniques guide
- ❌ Embeddings — Used in RAG; mentioned briefly but not explored in depth
- ❌ Deprecated APIs (LLMChain, AgentExecutor) — Only a mapping table in Capsule 07
Technical setup
Prerequisites
Before moving on, make sure you have:
- ✅ Python 3.11+ installed
- ✅ pip or uv as your package manager
- ✅ At least one API key from an LLM provider (OpenAI or Anthropic recommended)
- ✅ A code editor (VS Code, Cursor, PyCharm)
- ✅ Comfort with the terminal/CLI
Quick check:
python --version
# Should show Python 3.11.x or higher
Installation
# Create a virtual environment
python -m venv langchain-env
source langchain-env/bin/activate # Mac/Linux
# langchain-env\Scripts\activate # Windows
# Install core packages
pip install langchain langchain-core
# Install providers (install the ones you're going to use)
pip install langchain-openai # For OpenAI
pip install langchain-anthropic # For Anthropic
pip install langchain-google-genai # For Google Gemini
pip install langchain-ollama # For local models
# Utilities
pip install python-dotenv # For handling API keys
pip install pydantic # For Structured Output
Configure API keys
Create a .env file at the root of your project:
# .env
OPENAI_API_KEY=sk-proj-your-key-here
ANTHROPIC_API_KEY=sk-ant-your-key-here
GOOGLE_API_KEY=your-key-here
Load them in your code:
from dotenv import load_dotenv
load_dotenv()
# The API keys load automatically as environment variables
# LangChain's packages pick them up with no extra configuration
Never hardcode API keys in your code. Always use .env + python-dotenv.
Add .env to your .gitignore so it never lands in a repository:
# .gitignore
.env
__pycache__/
langchain-env/
Verify everything works
from dotenv import load_dotenv
load_dotenv()
from langchain.chat_models import init_chat_model
model = init_chat_model("openai:gpt-4.1-mini")
response = model.invoke("Say 'hello' in one word")
print(response.content)
# Expected output: Hello
If you see the model's response, your setup is ready.
If something fails, the most common errors are:
| Error | Cause | Fix |
|---|---|---|
ModuleNotFoundError: No module named 'langchain' | Package not installed | pip install langchain |
AuthenticationError | Invalid or missing API key | Check your .env and that load_dotenv() runs first |
ModuleNotFoundError: No module named 'langchain_openai' | Missing provider package | pip install langchain-openai |
RateLimitError | You exceeded your API key's quota | Wait, or set up rate limiting (Capsule 07) |
Versions and compatibility
This guide covers LangChain v1.2+ and LangGraph v1.0+.
Minimum required versions:
| Package | Minimum version |
|---|---|
langchain | 0.3+ |
langchain-core | 0.3+ |
langchain-openai | 0.3+ |
langchain-anthropic | 0.3+ |
langgraph | 0.2+ |
| Python | 3.11+ |
To check your versions:
pip show langchain langchain-core langchain-openai
Why LangChain and not the APIs directly?
You could use openai.chat.completions.create() or anthropic.messages.create() directly. They work fine. So why a framework?
Without LangChain — switching from OpenAI to Anthropic means rewriting code:
# OpenAI directly
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4.1",
messages=[{"role": "user", "content": "Hello"}]
)
print(response.choices[0].message.content)
# Anthropic directly — different API, different structure
from anthropic import Anthropic
client = Anthropic()
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}]
)
print(response.content[0].text)
With LangChain — you change one line:
from langchain.chat_models import init_chat_model
# Switching providers = changing ONE string
model = init_chat_model("openai:gpt-4.1")
# model = init_chat_model("anthropic:claude-sonnet-4-20250514")
# model = init_chat_model("google_genai:gemini-2.0-flash")
response = model.invoke("Hello")
print(response.content)
Same interface, any provider. On top of that, LangChain gives you streaming, batch processing, structured output, tool calling, and middleware — all through the same consistent API. As your applications grow, the framework saves you weeks of boilerplate.
Evidence of success
By the end of this module, you'll know you succeeded if:
- ✅ You can initialize a model from any provider in a single line
- ✅ You understand the difference between invoke, stream and batch, and when to use each
- ✅ You get structured responses (Pydantic) instead of parsing free-form text
- ✅ Your multi-provider chat project works with automatic fallback
- ✅ You can translate legacy LangChain code to modern APIs
Summary
- LangChain in 2026 is an ecosystem of packages with 3 levels of abstraction: LangGraph (low level), LangChain (high level), and Deep Agents (batteries-included)
- You only install the packages you need — there's no monolith
- The framework's main advantage is the unified interface: the same API for any provider
- This guide teaches modern APIs (v1.2+) exclusively, not legacy
- This module covers the most fundamental piece: connecting to models, running them, and getting structured responses
- The mini-project ties it all together: multi-provider chat with fallback, streaming and metadata
- Setup: Python 3.11+, packages installed, API keys in
.env - Everything you learn here is the foundation for the 11 modules that follow
Additional resources
- LangChain Python Documentation - Complete official documentation
- LangChain API Reference - Reference for every class and function
- LangGraph Documentation - LangGraph's official documentation
- LangSmith Documentation - The observability platform
- LangChain Blog - Technical articles and announcements from the team
- LangChain GitHub - Source code and examples
Module 1 — LangChain & LangGraph: From Chains to Agents
Next capsule: init_chat_model and providers — you'll learn to connect to any language model with a single universal function.