LangChain Tutorial
Learn LangChain step by step: 32 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is LangChain? Learn what LangChain is, which problems it solves for LLM applications, how its packages fit together, and what this course runs live versus shows read-only.
- Installing LangChain and Setting Up Keys Install LangChain in a virtual environment, add a provider package, keep API keys in environment variables and run your first model call safely, step by step.
- Messages and Your First Chat Understand LangChain chat messages (system, human, AI, tool), build a conversation as a list, read content and metadata from replies, and practice with a stand-in.
- The Runnable Interface: invoke, stream, batch Learn the Runnable interface that every LangChain component shares: invoke, batch, stream and their async versions, plus config, with a runnable stand-in class.
Models, Prompts and Parsers
- Chat Models in Depth Work with LangChain chat models in depth: init_chat_model, temperature and other parameters, streaming, token usage, timeouts, retries and switching providers safely.
- Prompt Templates Build reusable prompts with LangChain PromptTemplate and ChatPromptTemplate: variables, system and human messages, partial variables, validation and a runnable template engine stand-in.
- Few-Shot Prompts and Message Placeholders Teach a model by example with few-shot prompts, select the most relevant examples dynamically, and use MessagesPlaceholder to inject chat history into LangChain prompts.
- Output Parsers Turn model replies into usable data with LangChain output parsers: StrOutputParser, JsonOutputParser, PydanticOutputParser and list parsers, with format instructions and error handling.
- Structured Output Get reliable typed data from a model with with_structured_output: Pydantic schemas, TypedDict and JSON Schema, extraction patterns, enums, nested data and validation failures.
Chains and LCEL
- LCEL and the Pipe Operator Learn the LangChain Expression Language: compose prompts, models and parsers with the | pipe operator, see how RunnableSequence works, and build your own pipe in Python.
- RunnableParallel and RunnablePassthrough Run steps side by side with RunnableParallel, carry input forward with RunnablePassthrough and assign, reshape dictionaries and shape chain inputs with runnable stand-ins.
- Branching, Routing and RunnableLambda Route a request to different chains with RunnableLambda and RunnableBranch, classify the input first, and build a runnable stand-in router with fallbacks.
- Retries, Fallbacks and Config Make chains reliable with with_retry and with_fallbacks, adjust behavior per call with configurable fields and bind, and observe runs with callbacks and tags, plus stand-ins.
Retrieval and Vector Stores
- Retrieval-Augmented Generation: The Big Picture Understand retrieval-augmented generation (RAG): why models need your data, the two phases of indexing and answering, the LangChain components involved and typical failure points.
- Document Loaders and Text Splitters Load text, PDFs and web pages into LangChain Document objects with metadata, then split them into well-sized overlapping chunks with RecursiveCharacterTextSplitter, plus a runnable splitter.
Agents and Tools
- What Is an Agent? Learn what a LangChain agent is: a model that chooses tools in a loop until it can answer. Compare chains and agents, and run a stand-in agent loop in Python.
- Defining Tools Define LangChain tools with the @tool decorator, type hints and docstrings. See how a schema is built for the model and run a stand-in tool registry in Python.
- The Tool-Calling Loop Understand tool calling in LangChain: bind_tools, AIMessage.tool_calls, ToolMessage and tool_call_id, parallel calls. Run a stand-in message loop in Python.
- ReAct Agents and create_agent Learn the ReAct pattern (reason, act, observe) and how LangChain's create_agent implements it with tools, prompts, streaming and structured output. Includes Python stand-ins.
- Agent Errors and Guardrails Make LangChain agents safe and reliable: step and call limits, tool error handling, retries, input validation and prompt injection defenses, with runnable Python stand-ins.
Memory and State
- Conversation Memory Basics Language models are stateless. Learn how LangChain adds conversation memory with message history, thread ids and checkpointers, with a runnable Python stand-in.
- Trimming and Summarizing History Keep long conversations inside the context window: window and token trimming, trim_messages, rolling summaries and deleting messages. Runnable Python stand-ins included.
- Persistent Checkpoints and Long-Term Memory Persist agent state with SQLite or Postgres checkpointers, replay and fork threads, and add long-term memory with a store. Stand-ins run in Python with sqlite3.
LangGraph Workflows
- LangGraph: State, Nodes and Edges Learn the LangGraph model: a typed state, nodes that return updates, edges that route, and reducers that merge. Run a mini StateGraph stand-in in Python.
- Conditional Edges and Loops Route a LangGraph with add_conditional_edges, build loops with a back edge, set recursion limits and rebuild a ReAct agent by hand. Runnable Python stand-ins included.
- Human in the Loop Pause a LangGraph run for human approval with interrupt(), resume with Command, and approve, edit or reject tool calls. Runnable Python stand-ins with generators.
- Multi-Agent Systems and Supervisors Split work across specialist agents: the supervisor pattern, agents as tools, handoffs and subgraphs in LangGraph. Includes a runnable supervisor stand-in in Python.
Evaluation and Deployment
- Evaluating LLM Applications Test LLM apps like software: build a dataset, write evaluators, use LLM-as-judge, check agent trajectories and catch regressions. Runnable Python eval harness included.
- Tracing and Observability See inside LLM apps: traces, runs, spans, metadata, tags, latency and token usage. Enable LangSmith tracing, add callbacks and build a tiny tracer in Python.
- Serving with FastAPI and Streaming Serve a LangChain agent as an API with FastAPI: async endpoints, token streaming with server-sent events, thread ids, auth and rate limits. Runnable asyncio stand-ins.
- Caching, Cost and Latency Cut LLM cost and latency: response caching, prompt caching, smaller prompts, model routing, batching and parallel calls. Runnable Python stand-ins with a cost calculator.